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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 explicit PreParserIdentifier(Type type) : type_(type), string_(nullptr) {} | 118 explicit PreParserIdentifier(Type type) : type_(type), string_(nullptr) {} |
119 Type type_; | 119 Type type_; |
120 // Only non-nullptr when PreParser.track_unresolved_variables_ is true. | 120 // Only non-nullptr when PreParser.track_unresolved_variables_ is true. |
121 const AstRawString* string_; | 121 const AstRawString* string_; |
122 friend class PreParserExpression; | 122 friend class PreParserExpression; |
123 friend class PreParser; | 123 friend class PreParser; |
124 friend class PreParserFactory; | 124 friend class PreParserFactory; |
125 }; | 125 }; |
126 | 126 |
127 | 127 class PreParserStatement; |
128 class PreParserExpression { | 128 class PreParserExpression { |
129 public: | 129 public: |
130 PreParserExpression() | 130 PreParserExpression() |
131 : code_(TypeField::encode(kEmpty)), variables_(nullptr) {} | 131 : code_(TypeField::encode(kEmpty)), variables_(nullptr) {} |
132 | 132 |
133 static PreParserExpression Empty() { return PreParserExpression(); } | 133 static PreParserExpression Empty() { return PreParserExpression(); } |
134 | 134 |
135 static PreParserExpression Default( | 135 static PreParserExpression Default( |
136 ZoneList<VariableProxy*>* variables = nullptr) { | 136 ZoneList<VariableProxy*>* variables = nullptr) { |
137 return PreParserExpression(TypeField::encode(kExpression), variables); | 137 return PreParserExpression(TypeField::encode(kExpression), variables); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // and PreParser. | 331 // and PreParser. |
332 PreParserExpression* operator->() { return this; } | 332 PreParserExpression* operator->() { return this; } |
333 | 333 |
334 // More dummy implementations of things PreParser doesn't need to track: | 334 // More dummy implementations of things PreParser doesn't need to track: |
335 void set_index(int index) {} // For YieldExpressions | 335 void set_index(int index) {} // For YieldExpressions |
336 void SetShouldEagerCompile() {} | 336 void SetShouldEagerCompile() {} |
337 void set_should_be_used_once_hint() {} | 337 void set_should_be_used_once_hint() {} |
338 | 338 |
339 int position() const { return kNoSourcePosition; } | 339 int position() const { return kNoSourcePosition; } |
340 void set_function_token_position(int position) {} | 340 void set_function_token_position(int position) {} |
| 341 void set_parameter_init_block(PreParserStatement block); |
341 | 342 |
342 private: | 343 private: |
343 enum Type { | 344 enum Type { |
344 kEmpty, | 345 kEmpty, |
345 kExpression, | 346 kExpression, |
346 kIdentifierExpression, | 347 kIdentifierExpression, |
347 kStringLiteralExpression, | 348 kStringLiteralExpression, |
348 kSpreadExpression, | 349 kSpreadExpression, |
349 kObjectLiteralExpression, | 350 kObjectLiteralExpression, |
350 kArrayLiteralExpression | 351 kArrayLiteralExpression |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 kJumpStatement, | 529 kJumpStatement, |
529 kStringLiteralExpressionStatement, | 530 kStringLiteralExpressionStatement, |
530 kUseStrictExpressionStatement, | 531 kUseStrictExpressionStatement, |
531 kUseAsmExpressionStatement, | 532 kUseAsmExpressionStatement, |
532 }; | 533 }; |
533 | 534 |
534 explicit PreParserStatement(Type code) : code_(code) {} | 535 explicit PreParserStatement(Type code) : code_(code) {} |
535 Type code_; | 536 Type code_; |
536 }; | 537 }; |
537 | 538 |
| 539 V8_INLINE void PreParserExpression::set_parameter_init_block( |
| 540 PreParserStatement block) {} |
538 | 541 |
539 class PreParserFactory { | 542 class PreParserFactory { |
540 public: | 543 public: |
541 explicit PreParserFactory(AstValueFactory* ast_value_factory) | 544 explicit PreParserFactory(AstValueFactory* ast_value_factory) |
542 : ast_value_factory_(ast_value_factory), | 545 : ast_value_factory_(ast_value_factory), |
543 zone_(ast_value_factory->zone()) {} | 546 zone_(ast_value_factory->zone()) {} |
544 | 547 |
545 void set_zone(Zone* zone) { zone_ = zone; } | 548 void set_zone(Zone* zone) { zone_ = zone; } |
546 | 549 |
547 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 550 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 return left; | 1009 return left; |
1007 } | 1010 } |
1008 | 1011 |
1009 V8_INLINE PreParserExpression | 1012 V8_INLINE PreParserExpression |
1010 RewriteAwaitExpression(PreParserExpression value, int pos) { | 1013 RewriteAwaitExpression(PreParserExpression value, int pos) { |
1011 return value; | 1014 return value; |
1012 } | 1015 } |
1013 V8_INLINE void PrepareAsyncFunctionBody(PreParserStatementList body, | 1016 V8_INLINE void PrepareAsyncFunctionBody(PreParserStatementList body, |
1014 FunctionKind kind, int pos) {} | 1017 FunctionKind kind, int pos) {} |
1015 V8_INLINE void RewriteAsyncFunctionBody(PreParserStatementList body, | 1018 V8_INLINE void RewriteAsyncFunctionBody(PreParserStatementList body, |
1016 PreParserStatement block, | |
1017 PreParserExpression return_value, | 1019 PreParserExpression return_value, |
1018 bool* ok) {} | 1020 bool* ok) {} |
1019 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, | 1021 V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator, |
1020 PreParserExpression expression, | 1022 PreParserExpression expression, |
1021 int pos) { | 1023 int pos) { |
1022 return PreParserExpression::Default(); | 1024 return PreParserExpression::Default(); |
1023 } | 1025 } |
1024 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } | 1026 V8_INLINE void RewriteNonPattern(bool* ok) { ValidateExpression(ok); } |
1025 | 1027 |
1026 void DeclareAndInitializeVariables( | 1028 void DeclareAndInitializeVariables( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 V8_INLINE PreParserStatement RewriteTryStatement( | 1075 V8_INLINE PreParserStatement RewriteTryStatement( |
1074 PreParserStatement try_block, PreParserStatement catch_block, | 1076 PreParserStatement try_block, PreParserStatement catch_block, |
1075 PreParserStatement finally_block, const CatchInfo& catch_info, int pos) { | 1077 PreParserStatement finally_block, const CatchInfo& catch_info, int pos) { |
1076 return PreParserStatement::Default(); | 1078 return PreParserStatement::Default(); |
1077 } | 1079 } |
1078 | 1080 |
1079 V8_INLINE void ParseAndRewriteGeneratorFunctionBody( | 1081 V8_INLINE void ParseAndRewriteGeneratorFunctionBody( |
1080 int pos, FunctionKind kind, PreParserStatementList body, bool* ok) { | 1082 int pos, FunctionKind kind, PreParserStatementList body, bool* ok) { |
1081 ParseStatementList(body, Token::RBRACE, ok); | 1083 ParseStatementList(body, Token::RBRACE, ok); |
1082 } | 1084 } |
1083 V8_INLINE void CreateFunctionNameAssignment( | 1085 V8_INLINE void CreateFunctionNameVariable( |
1084 PreParserIdentifier function_name, int pos, | 1086 PreParserIdentifier function_name, |
1085 FunctionLiteral::FunctionType function_type, | 1087 FunctionLiteral::FunctionType function_type, |
1086 DeclarationScope* function_scope, PreParserStatementList result, | 1088 DeclarationScope* function_scope) {} |
1087 int index) {} | |
1088 | 1089 |
1089 V8_INLINE PreParserExpression RewriteDoExpression(PreParserStatement body, | 1090 V8_INLINE PreParserExpression RewriteDoExpression(PreParserStatement body, |
1090 int pos, bool* ok) { | 1091 int pos, bool* ok) { |
1091 return PreParserExpression::Default(); | 1092 return PreParserExpression::Default(); |
1092 } | 1093 } |
1093 | 1094 |
1094 // TODO(nikolaos): The preparser currently does not keep track of labels | 1095 // TODO(nikolaos): The preparser currently does not keep track of labels |
1095 // and targets. | 1096 // and targets. |
1096 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, | 1097 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, |
1097 bool* ok) { | 1098 bool* ok) { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 } | 1361 } |
1361 } | 1362 } |
1362 return loop; | 1363 return loop; |
1363 } | 1364 } |
1364 | 1365 |
1365 V8_INLINE PreParserStatement BuildParameterInitializationBlock( | 1366 V8_INLINE PreParserStatement BuildParameterInitializationBlock( |
1366 const PreParserFormalParameters& parameters, bool* ok) { | 1367 const PreParserFormalParameters& parameters, bool* ok) { |
1367 return PreParserStatement::Default(); | 1368 return PreParserStatement::Default(); |
1368 } | 1369 } |
1369 | 1370 |
1370 V8_INLINE PreParserStatement | |
1371 BuildRejectPromiseOnException(PreParserStatement init_block) { | |
1372 return PreParserStatement::Default(); | |
1373 } | |
1374 | |
1375 V8_INLINE void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope) { | 1371 V8_INLINE void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope) { |
1376 scope->HoistSloppyBlockFunctions(nullptr); | 1372 scope->HoistSloppyBlockFunctions(nullptr); |
1377 } | 1373 } |
1378 | 1374 |
1379 V8_INLINE void InsertShadowingVarBindingInitializers( | 1375 V8_INLINE void InsertShadowingVarBindingInitializers( |
1380 PreParserStatement block) {} | 1376 PreParserStatement block) {} |
1381 | 1377 |
1382 V8_INLINE PreParserExpression | 1378 V8_INLINE PreParserExpression |
1383 NewThrowReferenceError(MessageTemplate::Template message, int pos) { | 1379 NewThrowReferenceError(MessageTemplate::Template message, int pos) { |
1384 return PreParserExpression::Default(); | 1380 return PreParserExpression::Default(); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, | 1550 NewV8Intrinsic(PreParserIdentifier name, PreParserExpressionList arguments, |
1555 int pos, bool* ok) { | 1551 int pos, bool* ok) { |
1556 return PreParserExpression::Default(); | 1552 return PreParserExpression::Default(); |
1557 } | 1553 } |
1558 | 1554 |
1559 V8_INLINE PreParserStatement NewThrowStatement(PreParserExpression exception, | 1555 V8_INLINE PreParserStatement NewThrowStatement(PreParserExpression exception, |
1560 int pos) { | 1556 int pos) { |
1561 return PreParserStatement::Jump(); | 1557 return PreParserStatement::Jump(); |
1562 } | 1558 } |
1563 | 1559 |
1564 V8_INLINE void AddParameterInitializationBlock( | |
1565 const PreParserFormalParameters& parameters, PreParserStatementList body, | |
1566 bool is_async, bool* ok) {} | |
1567 | |
1568 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, | 1560 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, |
1569 PreParserExpression pattern, | 1561 PreParserExpression pattern, |
1570 PreParserExpression initializer, | 1562 PreParserExpression initializer, |
1571 int initializer_end_position, | 1563 int initializer_end_position, |
1572 bool is_rest) { | 1564 bool is_rest) { |
1573 if (track_unresolved_variables_) { | 1565 if (track_unresolved_variables_) { |
1574 DCHECK(FLAG_lazy_inner_functions); | 1566 DCHECK(FLAG_lazy_inner_functions); |
1575 parameters->params.Add(new (zone()) | 1567 parameters->params.Add(new (zone()) |
1576 PreParserFormalParameters::Parameter(pattern)); | 1568 PreParserFormalParameters::Parameter(pattern)); |
1577 } | 1569 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 function_state_->NextMaterializedLiteralIndex(); | 1673 function_state_->NextMaterializedLiteralIndex(); |
1682 function_state_->NextMaterializedLiteralIndex(); | 1674 function_state_->NextMaterializedLiteralIndex(); |
1683 } | 1675 } |
1684 return EmptyExpression(); | 1676 return EmptyExpression(); |
1685 } | 1677 } |
1686 | 1678 |
1687 } // namespace internal | 1679 } // namespace internal |
1688 } // namespace v8 | 1680 } // namespace v8 |
1689 | 1681 |
1690 #endif // V8_PARSING_PREPARSER_H | 1682 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |