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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 explicit PreParserIdentifier(Type type) : type_(type), string_(nullptr) {} | 117 explicit PreParserIdentifier(Type type) : type_(type), string_(nullptr) {} |
118 Type type_; | 118 Type type_; |
119 // Only non-nullptr when PreParser.track_unresolved_variables_ is true. | 119 // Only non-nullptr when PreParser.track_unresolved_variables_ is true. |
120 const AstRawString* string_; | 120 const AstRawString* string_; |
121 friend class PreParserExpression; | 121 friend class PreParserExpression; |
122 friend class PreParser; | 122 friend class PreParser; |
123 friend class PreParserFactory; | 123 friend class PreParserFactory; |
124 }; | 124 }; |
125 | 125 |
126 | 126 class PreParserStatement; |
127 class PreParserExpression { | 127 class PreParserExpression { |
128 public: | 128 public: |
129 PreParserExpression() | 129 PreParserExpression() |
130 : code_(TypeField::encode(kEmpty)), variables_(nullptr) {} | 130 : code_(TypeField::encode(kEmpty)), variables_(nullptr) {} |
131 | 131 |
132 static PreParserExpression Empty() { return PreParserExpression(); } | 132 static PreParserExpression Empty() { return PreParserExpression(); } |
133 | 133 |
134 static PreParserExpression Default( | 134 static PreParserExpression Default( |
135 ZoneList<VariableProxy*>* variables = nullptr) { | 135 ZoneList<VariableProxy*>* variables = nullptr) { |
136 return PreParserExpression(TypeField::encode(kExpression), variables); | 136 return PreParserExpression(TypeField::encode(kExpression), variables); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // and PreParser. | 330 // and PreParser. |
331 PreParserExpression* operator->() { return this; } | 331 PreParserExpression* operator->() { return this; } |
332 | 332 |
333 // More dummy implementations of things PreParser doesn't need to track: | 333 // More dummy implementations of things PreParser doesn't need to track: |
334 void set_index(int index) {} // For YieldExpressions | 334 void set_index(int index) {} // For YieldExpressions |
335 void SetShouldEagerCompile() {} | 335 void SetShouldEagerCompile() {} |
336 void set_should_be_used_once_hint() {} | 336 void set_should_be_used_once_hint() {} |
337 | 337 |
338 int position() const { return kNoSourcePosition; } | 338 int position() const { return kNoSourcePosition; } |
339 void set_function_token_position(int position) {} | 339 void set_function_token_position(int position) {} |
| 340 void set_parameter_init_block(PreParserStatement block); |
340 | 341 |
341 private: | 342 private: |
342 enum Type { | 343 enum Type { |
343 kEmpty, | 344 kEmpty, |
344 kExpression, | 345 kExpression, |
345 kIdentifierExpression, | 346 kIdentifierExpression, |
346 kStringLiteralExpression, | 347 kStringLiteralExpression, |
347 kSpreadExpression, | 348 kSpreadExpression, |
348 kObjectLiteralExpression, | 349 kObjectLiteralExpression, |
349 kArrayLiteralExpression | 350 kArrayLiteralExpression |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 kJumpStatement, | 528 kJumpStatement, |
528 kStringLiteralExpressionStatement, | 529 kStringLiteralExpressionStatement, |
529 kUseStrictExpressionStatement, | 530 kUseStrictExpressionStatement, |
530 kUseAsmExpressionStatement, | 531 kUseAsmExpressionStatement, |
531 }; | 532 }; |
532 | 533 |
533 explicit PreParserStatement(Type code) : code_(code) {} | 534 explicit PreParserStatement(Type code) : code_(code) {} |
534 Type code_; | 535 Type code_; |
535 }; | 536 }; |
536 | 537 |
| 538 V8_INLINE void PreParserExpression::set_parameter_init_block( |
| 539 PreParserStatement block) {} |
537 | 540 |
538 class PreParserFactory { | 541 class PreParserFactory { |
539 public: | 542 public: |
540 explicit PreParserFactory(AstValueFactory* ast_value_factory) | 543 explicit PreParserFactory(AstValueFactory* ast_value_factory) |
541 : ast_value_factory_(ast_value_factory), | 544 : ast_value_factory_(ast_value_factory), |
542 zone_(ast_value_factory->zone()) {} | 545 zone_(ast_value_factory->zone()) {} |
543 | 546 |
544 void set_zone(Zone* zone) { zone_ = zone; } | 547 void set_zone(Zone* zone) { zone_ = zone; } |
545 | 548 |
546 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 549 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 return expression; | 632 return expression; |
630 } | 633 } |
631 PreParserExpression NewAssignment(Token::Value op, | 634 PreParserExpression NewAssignment(Token::Value op, |
632 PreParserExpression left, | 635 PreParserExpression left, |
633 PreParserExpression right, | 636 PreParserExpression right, |
634 int pos) { | 637 int pos) { |
635 // Identifiers need to be tracked since this might be a parameter with a | 638 // Identifiers need to be tracked since this might be a parameter with a |
636 // default value inside an arrow function parameter list. | 639 // default value inside an arrow function parameter list. |
637 return PreParserExpression::Assignment(left.variables_); | 640 return PreParserExpression::Assignment(left.variables_); |
638 } | 641 } |
639 PreParserExpression NewYield(PreParserExpression generator_object, | 642 PreParserExpression NewYield(PreParserExpression expression, int pos, |
640 PreParserExpression expression, int pos, | 643 Yield::OnException on_exception, |
641 Yield::OnException on_exception) { | 644 Yield::YieldType type) { |
642 return PreParserExpression::Default(); | 645 return PreParserExpression::Default(); |
643 } | 646 } |
644 PreParserExpression NewConditional(PreParserExpression condition, | 647 PreParserExpression NewConditional(PreParserExpression condition, |
645 PreParserExpression then_expression, | 648 PreParserExpression then_expression, |
646 PreParserExpression else_expression, | 649 PreParserExpression else_expression, |
647 int pos) { | 650 int pos) { |
648 return PreParserExpression::Default(); | 651 return PreParserExpression::Default(); |
649 } | 652 } |
650 PreParserExpression NewCountOperation(Token::Value op, | 653 PreParserExpression NewCountOperation(Token::Value op, |
651 bool is_prefix, | 654 bool is_prefix, |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 V8_INLINE PreParserExpression | 1008 V8_INLINE PreParserExpression |
1006 RewriteAwaitExpression(PreParserExpression value, int pos) { | 1009 RewriteAwaitExpression(PreParserExpression value, int pos) { |
1007 return value; | 1010 return value; |
1008 } | 1011 } |
1009 V8_INLINE void PrepareAsyncFunctionBody(PreParserStatementList body, | 1012 V8_INLINE void PrepareAsyncFunctionBody(PreParserStatementList body, |
1010 FunctionKind kind, int pos) {} | 1013 FunctionKind kind, int pos) {} |
1011 V8_INLINE void RewriteAsyncFunctionBody(PreParserStatementList body, | 1014 V8_INLINE void RewriteAsyncFunctionBody(PreParserStatementList body, |
1012 PreParserStatement block, | 1015 PreParserStatement block, |
1013 PreParserExpression return_value, | 1016 PreParserExpression return_value, |
1014 bool* ok) {} | 1017 bool* ok) {} |
1015 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, | 1018 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression expression, |
1016 PreParserExpression expression, | |
1017 int pos) { | 1019 int pos) { |
1018 return PreParserExpression::Default(); | 1020 return PreParserExpression::Default(); |
1019 } | 1021 } |
1020 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } | 1022 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } |
1021 | 1023 |
1022 void DeclareAndInitializeVariables( | 1024 void DeclareAndInitializeVariables( |
1023 PreParserStatement block, | 1025 PreParserStatement block, |
1024 const DeclarationDescriptor* declaration_descriptor, | 1026 const DeclarationDescriptor* declaration_descriptor, |
1025 const DeclarationParsingResult::Declaration* declaration, | 1027 const DeclarationParsingResult::Declaration* declaration, |
1026 ZoneList<const AstRawString*>* names, bool* ok); | 1028 ZoneList<const AstRawString*>* names, bool* ok); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 V8_INLINE PreParserStatement RewriteTryStatement( | 1071 V8_INLINE PreParserStatement RewriteTryStatement( |
1070 PreParserStatement try_block, PreParserStatement catch_block, | 1072 PreParserStatement try_block, PreParserStatement catch_block, |
1071 PreParserStatement finally_block, const CatchInfo& catch_info, int pos) { | 1073 PreParserStatement finally_block, const CatchInfo& catch_info, int pos) { |
1072 return PreParserStatement::Default(); | 1074 return PreParserStatement::Default(); |
1073 } | 1075 } |
1074 | 1076 |
1075 V8_INLINE void ParseAndRewriteGeneratorFunctionBody( | 1077 V8_INLINE void ParseAndRewriteGeneratorFunctionBody( |
1076 int pos, FunctionKind kind, PreParserStatementList body, bool* ok) { | 1078 int pos, FunctionKind kind, PreParserStatementList body, bool* ok) { |
1077 ParseStatementList(body, Token::RBRACE, ok); | 1079 ParseStatementList(body, Token::RBRACE, ok); |
1078 } | 1080 } |
1079 V8_INLINE void CreateFunctionNameAssignment( | 1081 V8_INLINE void CreateFunctionNameVariable( |
1080 PreParserIdentifier function_name, int pos, | 1082 PreParserIdentifier function_name, int pos, |
1081 FunctionLiteral::FunctionType function_type, | 1083 FunctionLiteral::FunctionType function_type, |
1082 DeclarationScope* function_scope, PreParserStatementList result, | 1084 DeclarationScope* function_scope) {} |
1083 int index) {} | |
1084 | 1085 |
1085 V8_INLINE PreParserExpression RewriteDoExpression(PreParserStatement body, | 1086 V8_INLINE PreParserExpression RewriteDoExpression(PreParserStatement body, |
1086 int pos, bool* ok) { | 1087 int pos, bool* ok) { |
1087 return PreParserExpression::Default(); | 1088 return PreParserExpression::Default(); |
1088 } | 1089 } |
1089 | 1090 |
1090 // TODO(nikolaos): The preparser currently does not keep track of labels | 1091 // TODO(nikolaos): The preparser currently does not keep track of labels |
1091 // and targets. | 1092 // and targets. |
1092 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, | 1093 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, |
1093 bool* ok) { | 1094 bool* ok) { |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, | 1528 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, |
1528 int pos, bool* ok) { | 1529 int pos, bool* ok) { |
1529 return PreParserExpression::Default(); | 1530 return PreParserExpression::Default(); |
1530 } | 1531 } |
1531 | 1532 |
1532 V8_INLINE PreParserStatement NewThrowStatement(PreParserExpression exception, | 1533 V8_INLINE PreParserStatement NewThrowStatement(PreParserExpression exception, |
1533 int pos) { | 1534 int pos) { |
1534 return PreParserStatement::Jump(); | 1535 return PreParserStatement::Jump(); |
1535 } | 1536 } |
1536 | 1537 |
1537 V8_INLINE void AddParameterInitializationBlock( | |
1538 const PreParserFormalParameters& parameters, PreParserStatementList body, | |
1539 bool is_async, bool* ok) {} | |
1540 | |
1541 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, | 1538 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, |
1542 PreParserExpression pattern, | 1539 PreParserExpression pattern, |
1543 PreParserExpression initializer, | 1540 PreParserExpression initializer, |
1544 int initializer_end_position, | 1541 int initializer_end_position, |
1545 bool is_rest) { | 1542 bool is_rest) { |
1546 if (track_unresolved_variables_) { | 1543 if (track_unresolved_variables_) { |
1547 DCHECK(FLAG_lazy_inner_functions); | 1544 DCHECK(FLAG_lazy_inner_functions); |
1548 parameters->params.Add(new (zone()) | 1545 parameters->params.Add(new (zone()) |
1549 PreParserFormalParameters::Parameter(pattern)); | 1546 PreParserFormalParameters::Parameter(pattern)); |
1550 } | 1547 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 function_state_->NextMaterializedLiteralIndex(); | 1653 function_state_->NextMaterializedLiteralIndex(); |
1657 function_state_->NextMaterializedLiteralIndex(); | 1654 function_state_->NextMaterializedLiteralIndex(); |
1658 } | 1655 } |
1659 return EmptyExpression(); | 1656 return EmptyExpression(); |
1660 } | 1657 } |
1661 | 1658 |
1662 } // namespace internal | 1659 } // namespace internal |
1663 } // namespace v8 | 1660 } // namespace v8 |
1664 | 1661 |
1665 #endif // V8_PARSING_PREPARSER_H | 1662 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |