| 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 #ifndef V8_PARSING_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
| 6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 PreParserLogger* logger() { return &log_; } | 879 PreParserLogger* logger() { return &log_; } |
| 880 | 880 |
| 881 // Pre-parse the program from the character stream; returns true on | 881 // Pre-parse the program from the character stream; returns true on |
| 882 // success (even if parsing failed, the pre-parse data successfully | 882 // success (even if parsing failed, the pre-parse data successfully |
| 883 // captured the syntax error), and false if a stack-overflow happened | 883 // captured the syntax error), and false if a stack-overflow happened |
| 884 // during parsing. | 884 // during parsing. |
| 885 PreParseResult PreParseProgram(int* materialized_literals = 0, | 885 PreParseResult PreParseProgram(int* materialized_literals = 0, |
| 886 bool is_module = false) { | 886 bool is_module = false) { |
| 887 DCHECK_NULL(scope_state_); | 887 DCHECK_NULL(scope_state_); |
| 888 DeclarationScope* scope = NewScriptScope(); | 888 DeclarationScope* scope = NewScriptScope(); |
| 889 #ifdef DEBUG |
| 890 scope->set_is_being_lazily_parsed(true); |
| 891 #endif |
| 889 | 892 |
| 890 // ModuleDeclarationInstantiation for Source Text Module Records creates a | 893 // ModuleDeclarationInstantiation for Source Text Module Records creates a |
| 891 // new Module Environment Record whose outer lexical environment record is | 894 // new Module Environment Record whose outer lexical environment record is |
| 892 // the global scope. | 895 // the global scope. |
| 893 if (is_module) scope = NewModuleScope(scope); | 896 if (is_module) scope = NewModuleScope(scope); |
| 894 | 897 |
| 895 FunctionState top_scope(&function_state_, &scope_state_, scope); | 898 FunctionState top_scope(&function_state_, &scope_state_, scope); |
| 896 bool ok = true; | 899 bool ok = true; |
| 897 int start_position = scanner()->peek_location().beg_pos; | 900 int start_position = scanner()->peek_location().beg_pos; |
| 898 parsing_module_ = is_module; | 901 parsing_module_ = is_module; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, | 1085 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, |
| 1083 bool* ok) { | 1086 bool* ok) { |
| 1084 return PreParserStatement::Default(); | 1087 return PreParserStatement::Default(); |
| 1085 } | 1088 } |
| 1086 V8_INLINE PreParserStatement LookupContinueTarget(PreParserIdentifier label, | 1089 V8_INLINE PreParserStatement LookupContinueTarget(PreParserIdentifier label, |
| 1087 bool* ok) { | 1090 bool* ok) { |
| 1088 return PreParserStatement::Default(); | 1091 return PreParserStatement::Default(); |
| 1089 } | 1092 } |
| 1090 | 1093 |
| 1091 V8_INLINE PreParserStatement DeclareFunction( | 1094 V8_INLINE PreParserStatement DeclareFunction( |
| 1092 PreParserIdentifier variable_name, PreParserExpression function, int pos, | 1095 PreParserIdentifier variable_name, PreParserExpression function, |
| 1093 bool is_generator, bool is_async, ZoneList<const AstRawString*>* names, | 1096 VariableMode mode, int pos, bool is_generator, bool is_async, |
| 1097 bool is_sloppy_block_function, ZoneList<const AstRawString*>* names, |
| 1094 bool* ok) { | 1098 bool* ok) { |
| 1099 DCHECK_NULL(names); |
| 1100 if (variable_name.string_ != nullptr) { |
| 1101 DCHECK(track_unresolved_variables_); |
| 1102 scope()->DeclareVariableName(variable_name.string_, mode); |
| 1103 if (is_sloppy_block_function) { |
| 1104 GetDeclarationScope()->DeclareSloppyBlockFunction(variable_name.string_, |
| 1105 scope()); |
| 1106 } |
| 1107 } |
| 1095 return Statement::Default(); | 1108 return Statement::Default(); |
| 1096 } | 1109 } |
| 1097 | 1110 |
| 1098 V8_INLINE PreParserStatement | 1111 V8_INLINE PreParserStatement |
| 1099 DeclareClass(PreParserIdentifier variable_name, PreParserExpression value, | 1112 DeclareClass(PreParserIdentifier variable_name, PreParserExpression value, |
| 1100 ZoneList<const AstRawString*>* names, int class_token_pos, | 1113 ZoneList<const AstRawString*>* names, int class_token_pos, |
| 1101 int end_pos, bool* ok) { | 1114 int end_pos, bool* ok) { |
| 1102 // Preparser shouldn't be used in contexts where we need to track the names. | 1115 // Preparser shouldn't be used in contexts where we need to track the names. |
| 1103 DCHECK_NULL(names); | 1116 DCHECK_NULL(names); |
| 1104 if (variable_name.string_ != nullptr) { | 1117 if (variable_name.string_ != nullptr) { |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1609 int pos) { | 1622 int pos) { |
| 1610 return factory()->NewCallNew(function, args, pos); | 1623 return factory()->NewCallNew(function, args, pos); |
| 1611 } | 1624 } |
| 1612 | 1625 |
| 1613 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1626 PreParserStatementList PreParser::ParseEagerFunctionBody( |
| 1614 PreParserIdentifier function_name, int pos, | 1627 PreParserIdentifier function_name, int pos, |
| 1615 const PreParserFormalParameters& parameters, FunctionKind kind, | 1628 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1616 FunctionLiteral::FunctionType function_type, bool* ok) { | 1629 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1617 PreParserStatementList result; | 1630 PreParserStatementList result; |
| 1618 | 1631 |
| 1619 Scope* inner_scope = scope(); | 1632 DeclarationScope* inner_scope = scope()->AsDeclarationScope(); |
| 1620 if (!parameters.is_simple) inner_scope = NewScope(BLOCK_SCOPE); | 1633 if (!parameters.is_simple) inner_scope = NewVarblockScope(); |
| 1621 | 1634 |
| 1622 { | 1635 { |
| 1623 BlockState block_state(&scope_state_, inner_scope); | 1636 BlockState block_state(&scope_state_, inner_scope); |
| 1624 ParseStatementList(result, Token::RBRACE, ok); | 1637 ParseStatementList(result, Token::RBRACE, ok); |
| 1625 if (!*ok) return PreParserStatementList(); | 1638 if (!*ok) return PreParserStatementList(); |
| 1626 } | 1639 } |
| 1627 | 1640 |
| 1628 Expect(Token::RBRACE, ok); | 1641 Expect(Token::RBRACE, ok); |
| 1642 |
| 1643 if (is_sloppy(inner_scope->language_mode())) { |
| 1644 inner_scope->HoistSloppyBlockFunctions(nullptr); |
| 1645 } |
| 1629 return result; | 1646 return result; |
| 1630 } | 1647 } |
| 1631 | 1648 |
| 1632 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state, | 1649 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state, |
| 1633 int start, | 1650 int start, |
| 1634 PreParserExpression tag) { | 1651 PreParserExpression tag) { |
| 1635 if (IsTaggedTemplate(tag)) { | 1652 if (IsTaggedTemplate(tag)) { |
| 1636 // Emulate generation of array literals for tag callsite | 1653 // Emulate generation of array literals for tag callsite |
| 1637 // 1st is array of cooked strings, second is array of raw strings | 1654 // 1st is array of cooked strings, second is array of raw strings |
| 1638 function_state_->NextMaterializedLiteralIndex(); | 1655 function_state_->NextMaterializedLiteralIndex(); |
| 1639 function_state_->NextMaterializedLiteralIndex(); | 1656 function_state_->NextMaterializedLiteralIndex(); |
| 1640 } | 1657 } |
| 1641 return EmptyExpression(); | 1658 return EmptyExpression(); |
| 1642 } | 1659 } |
| 1643 | 1660 |
| 1644 } // namespace internal | 1661 } // namespace internal |
| 1645 } // namespace v8 | 1662 } // namespace v8 |
| 1646 | 1663 |
| 1647 #endif // V8_PARSING_PREPARSER_H | 1664 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |