Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: src/parser.cc

Issue 490173002: Take ast node id counting away from Isolate. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 #define DUMMY ) // to make indentation work 338 #define DUMMY ) // to make indentation work
339 #undef DUMMY 339 #undef DUMMY
340 340
341 // ---------------------------------------------------------------------------- 341 // ----------------------------------------------------------------------------
342 // Implementation of Parser 342 // Implementation of Parser
343 343
344 class ParserTraits::Checkpoint 344 class ParserTraits::Checkpoint
345 : public ParserBase<ParserTraits>::CheckpointBase { 345 : public ParserBase<ParserTraits>::CheckpointBase {
346 public: 346 public:
347 explicit Checkpoint(ParserBase<ParserTraits>* parser) 347 explicit Checkpoint(ParserBase<ParserTraits>* parser)
348 : CheckpointBase(parser) { 348 : CheckpointBase(parser), parser_(parser) {
349 isolate_ = parser->zone()->isolate(); 349 saved_ast_node_id_gen_ = *parser_->ast_node_id_gen_;
350 saved_ast_node_id_ = isolate_->ast_node_id();
351 } 350 }
352 351
353 void Restore() { 352 void Restore() {
354 CheckpointBase::Restore(); 353 CheckpointBase::Restore();
355 isolate_->set_ast_node_id(saved_ast_node_id_); 354 *parser_->ast_node_id_gen_ = saved_ast_node_id_gen_;
356 } 355 }
357 356
358 private: 357 private:
359 Isolate* isolate_; 358 ParserBase<ParserTraits>* parser_;
360 int saved_ast_node_id_; 359 AstNode::IdGen saved_ast_node_id_gen_;
361 }; 360 };
362 361
363 362
364 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { 363 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
365 return identifier == parser_->ast_value_factory_->eval_string() || 364 return identifier == parser_->ast_value_factory_->eval_string() ||
366 identifier == parser_->ast_value_factory_->arguments_string(); 365 identifier == parser_->ast_value_factory_->arguments_string();
367 } 366 }
368 367
369 368
370 bool ParserTraits::IsThisProperty(Expression* expression) { 369 bool ParserTraits::IsThisProperty(Expression* expression) {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 FunctionLiteral::ArityRestriction arity_restriction, 724 FunctionLiteral::ArityRestriction arity_restriction,
726 bool* ok) { 725 bool* ok) {
727 return parser_->ParseFunctionLiteral(name, function_name_location, 726 return parser_->ParseFunctionLiteral(name, function_name_location,
728 name_is_strict_reserved, is_generator, 727 name_is_strict_reserved, is_generator,
729 function_token_position, type, 728 function_token_position, type,
730 arity_restriction, ok); 729 arity_restriction, ok);
731 } 730 }
732 731
733 732
734 Parser::Parser(CompilationInfo* info) 733 Parser::Parser(CompilationInfo* info)
735 : ParserBase<ParserTraits>(&scanner_, 734 : ParserBase<ParserTraits>(
736 info->isolate()->stack_guard()->real_climit(), 735 &scanner_, info->isolate()->stack_guard()->real_climit(),
737 info->extension(), NULL, info->zone(), this), 736 info->extension(), NULL, info->zone(), info->ast_node_id_gen(), this),
738 isolate_(info->isolate()), 737 isolate_(info->isolate()),
739 script_(info->script()), 738 script_(info->script()),
740 scanner_(isolate_->unicode_cache()), 739 scanner_(isolate_->unicode_cache()),
741 reusable_preparser_(NULL), 740 reusable_preparser_(NULL),
742 original_scope_(NULL), 741 original_scope_(NULL),
743 target_stack_(NULL), 742 target_stack_(NULL),
744 cached_parse_data_(NULL), 743 cached_parse_data_(NULL),
745 ast_value_factory_(NULL), 744 ast_value_factory_(NULL),
746 info_(info), 745 info_(info),
747 has_pending_error_(false), 746 has_pending_error_(false),
748 pending_error_message_(NULL), 747 pending_error_message_(NULL),
749 pending_error_arg_(NULL), 748 pending_error_arg_(NULL),
750 pending_error_char_arg_(NULL) { 749 pending_error_char_arg_(NULL) {
751 DCHECK(!script_.is_null()); 750 DCHECK(!script_.is_null());
752 isolate_->set_ast_node_id(0);
753 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 751 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
754 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 752 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
755 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 753 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
756 set_allow_lazy(false); // Must be explicitly enabled. 754 set_allow_lazy(false); // Must be explicitly enabled.
757 set_allow_generators(FLAG_harmony_generators); 755 set_allow_generators(FLAG_harmony_generators);
758 set_allow_arrow_functions(FLAG_harmony_arrow_functions); 756 set_allow_arrow_functions(FLAG_harmony_arrow_functions);
759 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 757 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
760 set_allow_classes(FLAG_harmony_classes); 758 set_allow_classes(FLAG_harmony_classes);
761 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 759 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
762 ++feature) { 760 ++feature) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; 852 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
855 if (allow_natives_syntax() || 853 if (allow_natives_syntax() ||
856 extension_ != NULL || 854 extension_ != NULL ||
857 scope->is_eval_scope()) { 855 scope->is_eval_scope()) {
858 mode = PARSE_EAGERLY; 856 mode = PARSE_EAGERLY;
859 } 857 }
860 ParsingModeScope parsing_mode(this, mode); 858 ParsingModeScope parsing_mode(this, mode);
861 859
862 // Enters 'scope'. 860 // Enters 'scope'.
863 FunctionState function_state(&function_state_, &scope_, scope, zone(), 861 FunctionState function_state(&function_state_, &scope_, scope, zone(),
864 ast_value_factory_); 862 ast_value_factory_, info->ast_node_id_gen());
865 863
866 scope_->SetStrictMode(info->strict_mode()); 864 scope_->SetStrictMode(info->strict_mode());
867 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 865 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
868 bool ok = true; 866 bool ok = true;
869 int beg_pos = scanner()->location().beg_pos; 867 int beg_pos = scanner()->location().beg_pos;
870 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); 868 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
871 869
872 HandleSourceURLComments(); 870 HandleSourceURLComments();
873 871
874 if (ok && strict_mode() == STRICT) { 872 if (ok && strict_mode() == STRICT) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 { 970 {
973 // Parse the function literal. 971 // Parse the function literal.
974 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 972 Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
975 info()->SetGlobalScope(scope); 973 info()->SetGlobalScope(scope);
976 if (!info()->closure().is_null()) { 974 if (!info()->closure().is_null()) {
977 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, 975 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
978 zone()); 976 zone());
979 } 977 }
980 original_scope_ = scope; 978 original_scope_ = scope;
981 FunctionState function_state(&function_state_, &scope_, scope, zone(), 979 FunctionState function_state(&function_state_, &scope_, scope, zone(),
982 ast_value_factory_); 980 ast_value_factory_, info()->ast_node_id_gen());
983 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); 981 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
984 DCHECK(info()->strict_mode() == shared_info->strict_mode()); 982 DCHECK(info()->strict_mode() == shared_info->strict_mode());
985 scope->SetStrictMode(shared_info->strict_mode()); 983 scope->SetStrictMode(shared_info->strict_mode());
986 FunctionLiteral::FunctionType function_type = shared_info->is_expression() 984 FunctionLiteral::FunctionType function_type = shared_info->is_expression()
987 ? (shared_info->is_anonymous() 985 ? (shared_info->is_anonymous()
988 ? FunctionLiteral::ANONYMOUS_EXPRESSION 986 ? FunctionLiteral::ANONYMOUS_EXPRESSION
989 : FunctionLiteral::NAMED_EXPRESSION) 987 : FunctionLiteral::NAMED_EXPRESSION)
990 : FunctionLiteral::DECLARATION; 988 : FunctionLiteral::DECLARATION;
991 bool is_generator = shared_info->is_generator(); 989 bool is_generator = shared_info->is_generator();
992 bool ok = true; 990 bool ok = true;
(...skipping 2442 matching lines...) Expand 10 before | Expand all | Expand 10 after
3435 FunctionLiteral::ParameterFlag duplicate_parameters = 3433 FunctionLiteral::ParameterFlag duplicate_parameters =
3436 FunctionLiteral::kNoDuplicateParameters; 3434 FunctionLiteral::kNoDuplicateParameters;
3437 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3435 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3438 ? FunctionLiteral::kIsParenthesized 3436 ? FunctionLiteral::kIsParenthesized
3439 : FunctionLiteral::kNotParenthesized; 3437 : FunctionLiteral::kNotParenthesized;
3440 AstProperties ast_properties; 3438 AstProperties ast_properties;
3441 BailoutReason dont_optimize_reason = kNoReason; 3439 BailoutReason dont_optimize_reason = kNoReason;
3442 // Parse function body. 3440 // Parse function body.
3443 { 3441 {
3444 FunctionState function_state(&function_state_, &scope_, scope, zone(), 3442 FunctionState function_state(&function_state_, &scope_, scope, zone(),
3445 ast_value_factory_); 3443 ast_value_factory_, info()->ast_node_id_gen());
3446 scope_->SetScopeName(function_name); 3444 scope_->SetScopeName(function_name);
3447 3445
3448 if (is_generator) { 3446 if (is_generator) {
3449 // For generators, allocating variables in contexts is currently a win 3447 // For generators, allocating variables in contexts is currently a win
3450 // because it minimizes the work needed to suspend and resume an 3448 // because it minimizes the work needed to suspend and resume an
3451 // activation. 3449 // activation.
3452 scope_->ForceContextAllocation(); 3450 scope_->ForceContextAllocation();
3453 3451
3454 // Calling a generator returns a generator object. That object is stored 3452 // Calling a generator returns a generator object. That object is stored
3455 // in a temporary variable, a definition that is used by "yield" 3453 // in a temporary variable, a definition that is used by "yield"
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
4830 info()->SetAstValueFactory(ast_value_factory_); 4828 info()->SetAstValueFactory(ast_value_factory_);
4831 } 4829 }
4832 ast_value_factory_ = NULL; 4830 ast_value_factory_ = NULL;
4833 4831
4834 InternalizeUseCounts(); 4832 InternalizeUseCounts();
4835 4833
4836 return (result != NULL); 4834 return (result != NULL);
4837 } 4835 }
4838 4836
4839 } } // namespace v8::internal 4837 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698