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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 int function_token_position, FunctionLiteral::FunctionType type, | 729 int function_token_position, FunctionLiteral::FunctionType type, |
730 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { | 730 FunctionLiteral::ArityRestriction arity_restriction, bool* ok) { |
731 return parser_->ParseFunctionLiteral( | 731 return parser_->ParseFunctionLiteral( |
732 name, function_name_location, name_is_strict_reserved, kind, | 732 name, function_name_location, name_is_strict_reserved, kind, |
733 function_token_position, type, arity_restriction, ok); | 733 function_token_position, type, arity_restriction, ok); |
734 } | 734 } |
735 | 735 |
736 | 736 |
737 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) | 737 Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) |
738 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, | 738 : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, |
739 info->extension(), NULL, info->zone(), this), | 739 info->extension(), NULL, info->zone(), |
| 740 info->ast_node_id_gen(), this), |
740 scanner_(parse_info->unicode_cache), | 741 scanner_(parse_info->unicode_cache), |
741 reusable_preparser_(NULL), | 742 reusable_preparser_(NULL), |
742 original_scope_(NULL), | 743 original_scope_(NULL), |
743 target_stack_(NULL), | 744 target_stack_(NULL), |
744 cached_parse_data_(NULL), | 745 cached_parse_data_(NULL), |
745 info_(info), | 746 info_(info), |
746 has_pending_error_(false), | 747 has_pending_error_(false), |
747 pending_error_message_(NULL), | 748 pending_error_message_(NULL), |
748 pending_error_arg_(NULL), | 749 pending_error_arg_(NULL), |
749 pending_error_char_arg_(NULL), | 750 pending_error_char_arg_(NULL), |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 // Compute the parsing mode. | 872 // Compute the parsing mode. |
872 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 873 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
873 if (allow_natives_syntax() || extension_ != NULL || | 874 if (allow_natives_syntax() || extension_ != NULL || |
874 (*scope)->is_eval_scope()) { | 875 (*scope)->is_eval_scope()) { |
875 mode = PARSE_EAGERLY; | 876 mode = PARSE_EAGERLY; |
876 } | 877 } |
877 ParsingModeScope parsing_mode(this, mode); | 878 ParsingModeScope parsing_mode(this, mode); |
878 | 879 |
879 // Enters 'scope'. | 880 // Enters 'scope'. |
880 AstNodeFactory<AstConstructionVisitor> function_factory( | 881 AstNodeFactory<AstConstructionVisitor> function_factory( |
881 ast_value_factory()); | 882 zone(), ast_value_factory(), info->ast_node_id_gen()); |
882 FunctionState function_state(&function_state_, &scope_, *scope, | 883 FunctionState function_state(&function_state_, &scope_, *scope, |
883 &function_factory); | 884 &function_factory); |
884 | 885 |
885 scope_->SetStrictMode(info->strict_mode()); | 886 scope_->SetStrictMode(info->strict_mode()); |
886 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 887 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
887 bool ok = true; | 888 bool ok = true; |
888 int beg_pos = scanner()->location().beg_pos; | 889 int beg_pos = scanner()->location().beg_pos; |
889 ParseSourceElements(body, Token::EOS, info->is_eval(), true, eval_scope, | 890 ParseSourceElements(body, Token::EOS, info->is_eval(), true, eval_scope, |
890 &ok); | 891 &ok); |
891 | 892 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 { | 987 { |
987 // Parse the function literal. | 988 // Parse the function literal. |
988 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 989 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
989 info()->SetGlobalScope(scope); | 990 info()->SetGlobalScope(scope); |
990 if (!info()->closure().is_null()) { | 991 if (!info()->closure().is_null()) { |
991 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, | 992 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, |
992 zone()); | 993 zone()); |
993 } | 994 } |
994 original_scope_ = scope; | 995 original_scope_ = scope; |
995 AstNodeFactory<AstConstructionVisitor> function_factory( | 996 AstNodeFactory<AstConstructionVisitor> function_factory( |
996 ast_value_factory()); | 997 zone(), ast_value_factory(), info()->ast_node_id_gen()); |
997 FunctionState function_state(&function_state_, &scope_, scope, | 998 FunctionState function_state(&function_state_, &scope_, scope, |
998 &function_factory); | 999 &function_factory); |
999 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); | 1000 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
1000 DCHECK(info()->strict_mode() == shared_info->strict_mode()); | 1001 DCHECK(info()->strict_mode() == shared_info->strict_mode()); |
1001 scope->SetStrictMode(shared_info->strict_mode()); | 1002 scope->SetStrictMode(shared_info->strict_mode()); |
1002 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 1003 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
1003 ? (shared_info->is_anonymous() | 1004 ? (shared_info->is_anonymous() |
1004 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 1005 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
1005 : FunctionLiteral::NAMED_EXPRESSION) | 1006 : FunctionLiteral::NAMED_EXPRESSION) |
1006 : FunctionLiteral::DECLARATION; | 1007 : FunctionLiteral::DECLARATION; |
(...skipping 2481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3488 FunctionLiteral::ParameterFlag duplicate_parameters = | 3489 FunctionLiteral::ParameterFlag duplicate_parameters = |
3489 FunctionLiteral::kNoDuplicateParameters; | 3490 FunctionLiteral::kNoDuplicateParameters; |
3490 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ | 3491 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ |
3491 ? FunctionLiteral::kIsParenthesized | 3492 ? FunctionLiteral::kIsParenthesized |
3492 : FunctionLiteral::kNotParenthesized; | 3493 : FunctionLiteral::kNotParenthesized; |
3493 AstProperties ast_properties; | 3494 AstProperties ast_properties; |
3494 BailoutReason dont_optimize_reason = kNoReason; | 3495 BailoutReason dont_optimize_reason = kNoReason; |
3495 // Parse function body. | 3496 // Parse function body. |
3496 { | 3497 { |
3497 AstNodeFactory<AstConstructionVisitor> function_factory( | 3498 AstNodeFactory<AstConstructionVisitor> function_factory( |
3498 ast_value_factory()); | 3499 zone(), ast_value_factory(), info()->ast_node_id_gen()); |
3499 FunctionState function_state(&function_state_, &scope_, scope, | 3500 FunctionState function_state(&function_state_, &scope_, scope, |
3500 &function_factory); | 3501 &function_factory); |
3501 scope_->SetScopeName(function_name); | 3502 scope_->SetScopeName(function_name); |
3502 | 3503 |
3503 if (is_generator) { | 3504 if (is_generator) { |
3504 // For generators, allocating variables in contexts is currently a win | 3505 // For generators, allocating variables in contexts is currently a win |
3505 // because it minimizes the work needed to suspend and resume an | 3506 // because it minimizes the work needed to suspend and resume an |
3506 // activation. | 3507 // activation. |
3507 scope_->ForceContextAllocation(); | 3508 scope_->ForceContextAllocation(); |
3508 | 3509 |
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4950 | 4951 |
4951 // We cannot internalize on a background thread; a foreground task will take | 4952 // We cannot internalize on a background thread; a foreground task will take |
4952 // care of calling Parser::Internalize just before compilation. | 4953 // care of calling Parser::Internalize just before compilation. |
4953 | 4954 |
4954 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 4955 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
4955 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 4956 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
4956 log_ = NULL; | 4957 log_ = NULL; |
4957 } | 4958 } |
4958 } | 4959 } |
4959 } } // namespace v8::internal | 4960 } } // namespace v8::internal |
OLD | NEW |