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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 &RuntimeCallStats::ParseFunction); | 852 &RuntimeCallStats::ParseFunction); |
853 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); | 853 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseFunction"); |
854 Handle<String> source(String::cast(info->script()->source())); | 854 Handle<String> source(String::cast(info->script()->source())); |
855 isolate->counters()->total_parse_size()->Increment(source->length()); | 855 isolate->counters()->total_parse_size()->Increment(source->length()); |
856 base::ElapsedTimer timer; | 856 base::ElapsedTimer timer; |
857 if (FLAG_trace_parse) { | 857 if (FLAG_trace_parse) { |
858 timer.Start(); | 858 timer.Start(); |
859 } | 859 } |
860 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 860 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
861 DeserializeScopeChain(info, info->maybe_outer_scope_info()); | 861 DeserializeScopeChain(info, info->maybe_outer_scope_info()); |
862 if (info->asm_function_scope()) { | |
863 original_scope_ = info->asm_function_scope(); | |
864 factory()->set_zone(info->zone()); | |
marja
2016/11/29 10:20:04
I was debating with myself whether the set_zone sh
bradn
2016/11/29 10:43:36
Done.
| |
865 } | |
862 | 866 |
863 // Initialize parser state. | 867 // Initialize parser state. |
864 source = String::Flatten(source); | 868 source = String::Flatten(source); |
865 FunctionLiteral* result; | 869 FunctionLiteral* result; |
866 { | 870 { |
867 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( | 871 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( |
868 source, shared_info->start_position(), shared_info->end_position())); | 872 source, shared_info->start_position(), shared_info->end_position())); |
869 Handle<String> name(String::cast(shared_info->name())); | 873 Handle<String> name(String::cast(shared_info->name())); |
870 result = DoParseFunction(info, ast_value_factory()->GetString(name), | 874 result = DoParseFunction(info, ast_value_factory()->GetString(name), |
871 stream.get()); | 875 stream.get()); |
(...skipping 29 matching lines...) Expand all Loading... | |
901 const AstRawString* raw_name, | 905 const AstRawString* raw_name, |
902 Utf16CharacterStream* source) { | 906 Utf16CharacterStream* source) { |
903 scanner_.Initialize(source); | 907 scanner_.Initialize(source); |
904 DCHECK_NULL(scope_state_); | 908 DCHECK_NULL(scope_state_); |
905 DCHECK_NULL(target_stack_); | 909 DCHECK_NULL(target_stack_); |
906 | 910 |
907 DCHECK(ast_value_factory()); | 911 DCHECK(ast_value_factory()); |
908 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 912 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
909 fni_->PushEnclosingName(raw_name); | 913 fni_->PushEnclosingName(raw_name); |
910 | 914 |
911 ResetFunctionLiteralId(); | 915 // Asm functions don't get IDs. |
marja
2016/11/29 10:20:04
Why? Is it bad if we assign IDs to them? And what
bradn
2016/11/29 10:43:36
Fair point.
Setting an id for them instead of this
| |
912 DCHECK_LT(0, info->function_literal_id()); | 916 if (!info->asm_function_scope()) { |
913 SkipFunctionLiterals(info->function_literal_id() - 1); | 917 ResetFunctionLiteralId(); |
918 DCHECK_LT(0, info->function_literal_id()); | |
919 SkipFunctionLiterals(info->function_literal_id() - 1); | |
920 } | |
914 | 921 |
915 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 922 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
916 | 923 |
917 // Place holder for the result. | 924 // Place holder for the result. |
918 FunctionLiteral* result = nullptr; | 925 FunctionLiteral* result = nullptr; |
919 | 926 |
920 { | 927 { |
921 // Parse the function literal. | 928 // Parse the function literal. |
922 Scope* outer = original_scope_; | 929 Scope* outer = original_scope_; |
923 DeclarationScope* outer_function = outer->GetClosureScope(); | 930 DeclarationScope* outer_function = outer->GetClosureScope(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1036 raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind, | 1043 raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind, |
1037 kNoSourcePosition, function_type, info->language_mode(), &ok); | 1044 kNoSourcePosition, function_type, info->language_mode(), &ok); |
1038 if (info->requires_class_field_init()) { | 1045 if (info->requires_class_field_init()) { |
1039 result = InsertClassFieldInitializer(result); | 1046 result = InsertClassFieldInitializer(result); |
1040 } | 1047 } |
1041 } | 1048 } |
1042 // Make sure the results agree. | 1049 // Make sure the results agree. |
1043 DCHECK(ok == (result != nullptr)); | 1050 DCHECK(ok == (result != nullptr)); |
1044 } | 1051 } |
1045 | 1052 |
1046 // Make sure the target stack is empty. | 1053 // Asm functions don't get IDs. |
1047 DCHECK_NULL(target_stack_); | 1054 if (!info->asm_function_scope()) { |
1048 DCHECK_IMPLIES(result, | 1055 // Make sure the target stack is empty. |
1049 info->function_literal_id() == result->function_literal_id()); | 1056 DCHECK_NULL(target_stack_); |
1057 DCHECK_IMPLIES( | |
1058 result, info->function_literal_id() == result->function_literal_id()); | |
1059 } | |
1050 return result; | 1060 return result; |
1051 } | 1061 } |
1052 | 1062 |
1053 Statement* Parser::ParseModuleItem(bool* ok) { | 1063 Statement* Parser::ParseModuleItem(bool* ok) { |
1054 // ecma262/#prod-ModuleItem | 1064 // ecma262/#prod-ModuleItem |
1055 // ModuleItem : | 1065 // ModuleItem : |
1056 // ImportDeclaration | 1066 // ImportDeclaration |
1057 // ExportDeclaration | 1067 // ExportDeclaration |
1058 // StatementListItem | 1068 // StatementListItem |
1059 | 1069 |
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2624 // - Neither V8 natives nor native function declarations can be allowed, | 2634 // - Neither V8 natives nor native function declarations can be allowed, |
2625 // since parsing one would retroactively force the function to be | 2635 // since parsing one would retroactively force the function to be |
2626 // eagerly compiled. | 2636 // eagerly compiled. |
2627 // - The invoker of this parser can't depend on the AST being eagerly | 2637 // - The invoker of this parser can't depend on the AST being eagerly |
2628 // built (either because the function is about to be compiled, or | 2638 // built (either because the function is about to be compiled, or |
2629 // because the AST is going to be inspected for some reason). | 2639 // because the AST is going to be inspected for some reason). |
2630 // - Because of the above, we can't be attempting to parse a | 2640 // - Because of the above, we can't be attempting to parse a |
2631 // FunctionExpression; even without enclosing parentheses it might be | 2641 // FunctionExpression; even without enclosing parentheses it might be |
2632 // immediately invoked. | 2642 // immediately invoked. |
2633 // - The function literal shouldn't be hinted to eagerly compile. | 2643 // - The function literal shouldn't be hinted to eagerly compile. |
2634 // - For asm.js functions the body needs to be available when module | |
2635 // validation is active, because we examine the entire module at once. | |
2636 | 2644 |
2637 // Inner functions will be parsed using a temporary Zone. After parsing, we | 2645 // Inner functions will be parsed using a temporary Zone. After parsing, we |
2638 // will migrate unresolved variable into a Scope in the main Zone. | 2646 // will migrate unresolved variable into a Scope in the main Zone. |
2639 // TODO(marja): Refactor parsing modes: simplify this. | 2647 // TODO(marja): Refactor parsing modes: simplify this. |
2640 bool use_temp_zone = | 2648 bool use_temp_zone = |
2641 (FLAG_lazy_inner_functions | 2649 (FLAG_lazy_inner_functions |
2642 ? can_preparse | 2650 ? can_preparse |
2643 : (is_lazy_top_level_function || | 2651 : (is_lazy_top_level_function || |
2644 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration && | 2652 (allow_lazy_ && function_type == FunctionLiteral::kDeclaration && |
2645 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))) && | 2653 eager_compile_hint == FunctionLiteral::kShouldLazyCompile))); |
2646 !(FLAG_validate_asm && scope()->IsAsmModule()); | |
2647 bool is_lazy_inner_function = | 2654 bool is_lazy_inner_function = |
2648 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; | 2655 use_temp_zone && FLAG_lazy_inner_functions && !is_lazy_top_level_function; |
2649 | 2656 |
2650 ZoneList<Statement*>* body = nullptr; | 2657 ZoneList<Statement*>* body = nullptr; |
2651 int materialized_literal_count = -1; | 2658 int materialized_literal_count = -1; |
2652 int expected_property_count = -1; | 2659 int expected_property_count = -1; |
2653 bool should_be_used_once_hint = false; | 2660 bool should_be_used_once_hint = false; |
2654 int num_parameters = -1; | 2661 int num_parameters = -1; |
2655 int function_length = -1; | 2662 int function_length = -1; |
2656 bool has_duplicate_parameters = false; | 2663 bool has_duplicate_parameters = false; |
(...skipping 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5497 | 5504 |
5498 return final_loop; | 5505 return final_loop; |
5499 } | 5506 } |
5500 | 5507 |
5501 #undef CHECK_OK | 5508 #undef CHECK_OK |
5502 #undef CHECK_OK_VOID | 5509 #undef CHECK_OK_VOID |
5503 #undef CHECK_FAILED | 5510 #undef CHECK_FAILED |
5504 | 5511 |
5505 } // namespace internal | 5512 } // namespace internal |
5506 } // namespace v8 | 5513 } // namespace v8 |
OLD | NEW |