OLD | NEW |
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...) Loading... |
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_ = *(parser_->ast_node_id_counter_); |
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_counter_) = saved_ast_node_id_; |
356 } | 355 } |
357 | 356 |
358 private: | 357 private: |
359 Isolate* isolate_; | 358 ParserBase<ParserTraits>* parser_; |
360 int saved_ast_node_id_; | 359 int saved_ast_node_id_; |
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 |
(...skipping 357 matching lines...) Loading... |
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>(&scanner_, |
736 info->isolate()->stack_guard()->real_climit(), | 735 info->isolate()->stack_guard()->real_climit(), |
737 info->extension(), NULL, info->zone(), this), | 736 info->extension(), NULL, info->zone(), |
| 737 info->ast_node_id_counter(), this), |
738 isolate_(info->isolate()), | 738 isolate_(info->isolate()), |
739 script_(info->script()), | 739 script_(info->script()), |
740 scanner_(isolate_->unicode_cache()), | 740 scanner_(isolate_->unicode_cache()), |
741 reusable_preparser_(NULL), | 741 reusable_preparser_(NULL), |
742 original_scope_(NULL), | 742 original_scope_(NULL), |
743 target_stack_(NULL), | 743 target_stack_(NULL), |
744 cached_parse_data_(NULL), | 744 cached_parse_data_(NULL), |
745 ast_value_factory_(NULL), | 745 ast_value_factory_(NULL), |
746 info_(info), | 746 info_(info), |
747 has_pending_error_(false), | 747 has_pending_error_(false), |
748 pending_error_message_(NULL), | 748 pending_error_message_(NULL), |
749 pending_error_arg_(NULL), | 749 pending_error_arg_(NULL), |
750 pending_error_char_arg_(NULL) { | 750 pending_error_char_arg_(NULL) { |
751 DCHECK(!script_.is_null()); | 751 DCHECK(!script_.is_null()); |
752 isolate_->set_ast_node_id(0); | 752 *(info->ast_node_id_counter()) = 0; |
753 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 753 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
754 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 754 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
755 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 755 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
756 set_allow_lazy(false); // Must be explicitly enabled. | 756 set_allow_lazy(false); // Must be explicitly enabled. |
757 set_allow_generators(FLAG_harmony_generators); | 757 set_allow_generators(FLAG_harmony_generators); |
758 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 758 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
759 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 759 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
760 set_allow_classes(FLAG_harmony_classes); | 760 set_allow_classes(FLAG_harmony_classes); |
761 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 761 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
762 ++feature) { | 762 ++feature) { |
(...skipping 91 matching lines...) Loading... |
854 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 854 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
855 if (allow_natives_syntax() || | 855 if (allow_natives_syntax() || |
856 extension_ != NULL || | 856 extension_ != NULL || |
857 scope->is_eval_scope()) { | 857 scope->is_eval_scope()) { |
858 mode = PARSE_EAGERLY; | 858 mode = PARSE_EAGERLY; |
859 } | 859 } |
860 ParsingModeScope parsing_mode(this, mode); | 860 ParsingModeScope parsing_mode(this, mode); |
861 | 861 |
862 // Enters 'scope'. | 862 // Enters 'scope'. |
863 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 863 FunctionState function_state(&function_state_, &scope_, scope, zone(), |
864 ast_value_factory_); | 864 ast_value_factory_, |
| 865 info->ast_node_id_counter()); |
865 | 866 |
866 scope_->SetStrictMode(info->strict_mode()); | 867 scope_->SetStrictMode(info->strict_mode()); |
867 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 868 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
868 bool ok = true; | 869 bool ok = true; |
869 int beg_pos = scanner()->location().beg_pos; | 870 int beg_pos = scanner()->location().beg_pos; |
870 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 871 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); |
871 | 872 |
872 HandleSourceURLComments(); | 873 HandleSourceURLComments(); |
873 | 874 |
874 if (ok && strict_mode() == STRICT) { | 875 if (ok && strict_mode() == STRICT) { |
(...skipping 97 matching lines...) Loading... |
972 { | 973 { |
973 // Parse the function literal. | 974 // Parse the function literal. |
974 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 975 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
975 info()->SetGlobalScope(scope); | 976 info()->SetGlobalScope(scope); |
976 if (!info()->closure().is_null()) { | 977 if (!info()->closure().is_null()) { |
977 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, | 978 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, |
978 zone()); | 979 zone()); |
979 } | 980 } |
980 original_scope_ = scope; | 981 original_scope_ = scope; |
981 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 982 FunctionState function_state(&function_state_, &scope_, scope, zone(), |
982 ast_value_factory_); | 983 ast_value_factory_, |
| 984 info()->ast_node_id_counter()); |
983 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); | 985 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
984 DCHECK(info()->strict_mode() == shared_info->strict_mode()); | 986 DCHECK(info()->strict_mode() == shared_info->strict_mode()); |
985 scope->SetStrictMode(shared_info->strict_mode()); | 987 scope->SetStrictMode(shared_info->strict_mode()); |
986 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 988 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
987 ? (shared_info->is_anonymous() | 989 ? (shared_info->is_anonymous() |
988 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 990 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
989 : FunctionLiteral::NAMED_EXPRESSION) | 991 : FunctionLiteral::NAMED_EXPRESSION) |
990 : FunctionLiteral::DECLARATION; | 992 : FunctionLiteral::DECLARATION; |
991 bool is_generator = shared_info->is_generator(); | 993 bool is_generator = shared_info->is_generator(); |
992 bool ok = true; | 994 bool ok = true; |
(...skipping 2442 matching lines...) Loading... |
3435 FunctionLiteral::ParameterFlag duplicate_parameters = | 3437 FunctionLiteral::ParameterFlag duplicate_parameters = |
3436 FunctionLiteral::kNoDuplicateParameters; | 3438 FunctionLiteral::kNoDuplicateParameters; |
3437 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ | 3439 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ |
3438 ? FunctionLiteral::kIsParenthesized | 3440 ? FunctionLiteral::kIsParenthesized |
3439 : FunctionLiteral::kNotParenthesized; | 3441 : FunctionLiteral::kNotParenthesized; |
3440 AstProperties ast_properties; | 3442 AstProperties ast_properties; |
3441 BailoutReason dont_optimize_reason = kNoReason; | 3443 BailoutReason dont_optimize_reason = kNoReason; |
3442 // Parse function body. | 3444 // Parse function body. |
3443 { | 3445 { |
3444 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 3446 FunctionState function_state(&function_state_, &scope_, scope, zone(), |
3445 ast_value_factory_); | 3447 ast_value_factory_, |
| 3448 info()->ast_node_id_counter()); |
3446 scope_->SetScopeName(function_name); | 3449 scope_->SetScopeName(function_name); |
3447 | 3450 |
3448 if (is_generator) { | 3451 if (is_generator) { |
3449 // For generators, allocating variables in contexts is currently a win | 3452 // For generators, allocating variables in contexts is currently a win |
3450 // because it minimizes the work needed to suspend and resume an | 3453 // because it minimizes the work needed to suspend and resume an |
3451 // activation. | 3454 // activation. |
3452 scope_->ForceContextAllocation(); | 3455 scope_->ForceContextAllocation(); |
3453 | 3456 |
3454 // Calling a generator returns a generator object. That object is stored | 3457 // Calling a generator returns a generator object. That object is stored |
3455 // in a temporary variable, a definition that is used by "yield" | 3458 // in a temporary variable, a definition that is used by "yield" |
(...skipping 1374 matching lines...) Loading... |
4830 info()->SetAstValueFactory(ast_value_factory_); | 4833 info()->SetAstValueFactory(ast_value_factory_); |
4831 } | 4834 } |
4832 ast_value_factory_ = NULL; | 4835 ast_value_factory_ = NULL; |
4833 | 4836 |
4834 InternalizeUseCounts(); | 4837 InternalizeUseCounts(); |
4835 | 4838 |
4836 return (result != NULL); | 4839 return (result != NULL); |
4837 } | 4840 } |
4838 | 4841 |
4839 } } // namespace v8::internal | 4842 } } // namespace v8::internal |
OLD | NEW |