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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 407 |
408 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 408 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
409 // the like. If the PreParser is used in variable tracking mode, it needs to | 409 // the like. If the PreParser is used in variable tracking mode, it needs to |
410 // build lists of variables though. | 410 // build lists of variables though. |
411 template <typename T> | 411 template <typename T> |
412 class PreParserList { | 412 class PreParserList { |
413 public: | 413 public: |
414 // These functions make list->Add(some_expression) work (and do nothing). | 414 // These functions make list->Add(some_expression) work (and do nothing). |
415 PreParserList() : length_(0), variables_(nullptr) {} | 415 PreParserList() : length_(0), variables_(nullptr) {} |
416 PreParserList* operator->() { return this; } | 416 PreParserList* operator->() { return this; } |
417 void Add(T, Zone* zone); | 417 void Add(const T& element, Zone* zone); |
418 int length() const { return length_; } | 418 int length() const { return length_; } |
419 static PreParserList Null() { return PreParserList(-1); } | 419 static PreParserList Null() { return PreParserList(-1); } |
420 bool IsNull() const { return length_ == -1; } | 420 bool IsNull() const { return length_ == -1; } |
| 421 void Set(int index, const T& element) {} |
421 | 422 |
422 private: | 423 private: |
423 explicit PreParserList(int n) : length_(n), variables_(nullptr) {} | 424 explicit PreParserList(int n) : length_(n), variables_(nullptr) {} |
424 int length_; | 425 int length_; |
425 ZoneList<VariableProxy*>* variables_; | 426 ZoneList<VariableProxy*>* variables_; |
426 | 427 |
427 friend class PreParser; | 428 friend class PreParser; |
428 friend class PreParserFactory; | 429 friend class PreParserFactory; |
429 }; | 430 }; |
430 | 431 |
431 template <> | 432 template <> |
432 inline void PreParserList<PreParserExpression>::Add( | 433 inline void PreParserList<PreParserExpression>::Add( |
433 PreParserExpression expression, Zone* zone) { | 434 const PreParserExpression& expression, Zone* zone) { |
434 if (expression.variables_ != nullptr) { | 435 if (expression.variables_ != nullptr) { |
435 DCHECK(FLAG_lazy_inner_functions); | 436 DCHECK(FLAG_lazy_inner_functions); |
436 DCHECK(zone != nullptr); | 437 DCHECK(zone != nullptr); |
437 if (variables_ == nullptr) { | 438 if (variables_ == nullptr) { |
438 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); | 439 variables_ = new (zone) ZoneList<VariableProxy*>(1, zone); |
439 } | 440 } |
440 for (auto identifier : (*expression.variables_)) { | 441 for (auto identifier : (*expression.variables_)) { |
441 variables_->Add(identifier, zone); | 442 variables_->Add(identifier, zone); |
442 } | 443 } |
443 } | 444 } |
444 ++length_; | 445 ++length_; |
445 } | 446 } |
446 | 447 |
447 template <typename T> | 448 template <typename T> |
448 void PreParserList<T>::Add(T, Zone* zone) { | 449 void PreParserList<T>::Add(const T& element, Zone* zone) { |
449 ++length_; | 450 ++length_; |
450 } | 451 } |
451 | 452 |
452 typedef PreParserList<PreParserExpression> PreParserExpressionList; | 453 typedef PreParserList<PreParserExpression> PreParserExpressionList; |
453 | 454 |
454 class PreParserStatement; | 455 class PreParserStatement; |
455 typedef PreParserList<PreParserStatement> PreParserStatementList; | 456 typedef PreParserList<PreParserStatement> PreParserStatementList; |
456 | 457 |
457 class PreParserStatement { | 458 class PreParserStatement { |
458 public: | 459 public: |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 // These types form an algebra over syntactic categories that is just | 933 // These types form an algebra over syntactic categories that is just |
933 // rich enough to let us recognize and propagate the constructs that | 934 // rich enough to let us recognize and propagate the constructs that |
934 // are either being counted in the preparser data, or is important | 935 // are either being counted in the preparser data, or is important |
935 // to throw the correct syntax error exceptions. | 936 // to throw the correct syntax error exceptions. |
936 | 937 |
937 // All ParseXXX functions take as the last argument an *ok parameter | 938 // All ParseXXX functions take as the last argument an *ok parameter |
938 // which is set to false if parsing failed; it is unchanged otherwise. | 939 // which is set to false if parsing failed; it is unchanged otherwise. |
939 // By making the 'exception handling' explicit, we are forced to check | 940 // By making the 'exception handling' explicit, we are forced to check |
940 // for failure at the call sites. | 941 // for failure at the call sites. |
941 | 942 |
942 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | |
943 PreParserIdentifier function_name, int pos, | |
944 const PreParserFormalParameters& parameters, FunctionKind kind, | |
945 FunctionLiteral::FunctionType function_type, bool* ok); | |
946 | |
947 // Indicates that we won't switch from the preparser to the preparser; we'll | 943 // Indicates that we won't switch from the preparser to the preparser; we'll |
948 // just stay where we are. | 944 // just stay where we are. |
949 bool AllowsLazyParsingWithoutUnresolvedVariables() const { return false; } | 945 bool AllowsLazyParsingWithoutUnresolvedVariables() const { return false; } |
950 bool parse_lazily() const { return false; } | 946 bool parse_lazily() const { return false; } |
951 | 947 |
952 V8_INLINE LazyParsingResult SkipFunction( | 948 V8_INLINE LazyParsingResult SkipFunction( |
953 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, | 949 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, |
954 int* function_length, bool* has_duplicate_parameters, | 950 int* function_length, bool* has_duplicate_parameters, |
955 int* materialized_literal_count, int* expected_property_count, | 951 int* materialized_literal_count, int* expected_property_count, |
956 bool is_inner_function, bool may_abort, bool* ok) { | 952 bool is_inner_function, bool may_abort, bool* ok) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 } | 1064 } |
1069 } | 1065 } |
1070 | 1066 |
1071 V8_INLINE void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok) {} | 1067 V8_INLINE void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok) {} |
1072 V8_INLINE PreParserStatement RewriteTryStatement( | 1068 V8_INLINE PreParserStatement RewriteTryStatement( |
1073 PreParserStatement try_block, PreParserStatement catch_block, | 1069 PreParserStatement try_block, PreParserStatement catch_block, |
1074 PreParserStatement finally_block, const CatchInfo& catch_info, int pos) { | 1070 PreParserStatement finally_block, const CatchInfo& catch_info, int pos) { |
1075 return PreParserStatement::Default(); | 1071 return PreParserStatement::Default(); |
1076 } | 1072 } |
1077 | 1073 |
| 1074 V8_INLINE void ParseAndRewriteGeneratorFunctionBody( |
| 1075 int pos, FunctionKind kind, PreParserStatementList body, bool* ok) { |
| 1076 ParseStatementList(body, Token::RBRACE, ok); |
| 1077 } |
| 1078 V8_INLINE void CreateFunctionNameAssignment( |
| 1079 PreParserIdentifier function_name, int pos, |
| 1080 FunctionLiteral::FunctionType function_type, |
| 1081 DeclarationScope* function_scope, PreParserStatementList result, |
| 1082 int index) {} |
| 1083 |
1078 V8_INLINE PreParserExpression RewriteDoExpression(PreParserStatement body, | 1084 V8_INLINE PreParserExpression RewriteDoExpression(PreParserStatement body, |
1079 int pos, bool* ok) { | 1085 int pos, bool* ok) { |
1080 return PreParserExpression::Default(); | 1086 return PreParserExpression::Default(); |
1081 } | 1087 } |
1082 | 1088 |
1083 // TODO(nikolaos): The preparser currently does not keep track of labels | 1089 // TODO(nikolaos): The preparser currently does not keep track of labels |
1084 // and targets. | 1090 // and targets. |
1085 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, | 1091 V8_INLINE PreParserStatement LookupBreakTarget(PreParserIdentifier label, |
1086 bool* ok) { | 1092 bool* ok) { |
1087 return PreParserStatement::Default(); | 1093 return PreParserStatement::Default(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 } | 1327 } |
1322 | 1328 |
1323 V8_INLINE StatementT DesugarLexicalBindingsInForStatement( | 1329 V8_INLINE StatementT DesugarLexicalBindingsInForStatement( |
1324 PreParserStatement loop, PreParserStatement init, | 1330 PreParserStatement loop, PreParserStatement init, |
1325 PreParserExpression cond, PreParserStatement next, | 1331 PreParserExpression cond, PreParserStatement next, |
1326 PreParserStatement body, Scope* inner_scope, const ForInfo& for_info, | 1332 PreParserStatement body, Scope* inner_scope, const ForInfo& for_info, |
1327 bool* ok) { | 1333 bool* ok) { |
1328 return loop; | 1334 return loop; |
1329 } | 1335 } |
1330 | 1336 |
| 1337 V8_INLINE PreParserStatement BuildParameterInitializationBlock( |
| 1338 const PreParserFormalParameters& parameters, bool* ok) { |
| 1339 return PreParserStatement::Default(); |
| 1340 } |
| 1341 |
| 1342 V8_INLINE PreParserStatement |
| 1343 BuildRejectPromiseOnException(PreParserStatement init_block) { |
| 1344 return PreParserStatement::Default(); |
| 1345 } |
| 1346 |
| 1347 V8_INLINE void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope) { |
| 1348 scope->HoistSloppyBlockFunctions(nullptr); |
| 1349 } |
| 1350 |
| 1351 V8_INLINE void InsertShadowingVarBindingInitializers( |
| 1352 PreParserStatement block) {} |
| 1353 |
1331 V8_INLINE PreParserExpression | 1354 V8_INLINE PreParserExpression |
1332 NewThrowReferenceError(MessageTemplate::Template message, int pos) { | 1355 NewThrowReferenceError(MessageTemplate::Template message, int pos) { |
1333 return PreParserExpression::Default(); | 1356 return PreParserExpression::Default(); |
1334 } | 1357 } |
1335 | 1358 |
1336 V8_INLINE PreParserExpression NewThrowSyntaxError( | 1359 V8_INLINE PreParserExpression NewThrowSyntaxError( |
1337 MessageTemplate::Template message, PreParserIdentifier arg, int pos) { | 1360 MessageTemplate::Template message, PreParserIdentifier arg, int pos) { |
1338 return PreParserExpression::Default(); | 1361 return PreParserExpression::Default(); |
1339 } | 1362 } |
1340 | 1363 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 int pos) { | 1639 int pos) { |
1617 return factory()->NewCall(function, args, pos); | 1640 return factory()->NewCall(function, args, pos); |
1618 } | 1641 } |
1619 | 1642 |
1620 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, | 1643 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, |
1621 PreParserExpressionList args, | 1644 PreParserExpressionList args, |
1622 int pos) { | 1645 int pos) { |
1623 return factory()->NewCallNew(function, args, pos); | 1646 return factory()->NewCallNew(function, args, pos); |
1624 } | 1647 } |
1625 | 1648 |
1626 PreParserStatementList PreParser::ParseEagerFunctionBody( | |
1627 PreParserIdentifier function_name, int pos, | |
1628 const PreParserFormalParameters& parameters, FunctionKind kind, | |
1629 FunctionLiteral::FunctionType function_type, bool* ok) { | |
1630 PreParserStatementList result; | |
1631 | |
1632 DeclarationScope* inner_scope = scope()->AsDeclarationScope(); | |
1633 if (!parameters.is_simple) inner_scope = NewVarblockScope(); | |
1634 | |
1635 { | |
1636 BlockState block_state(&scope_state_, inner_scope); | |
1637 ParseStatementList(result, Token::RBRACE, ok); | |
1638 if (!*ok) return PreParserStatementList(); | |
1639 } | |
1640 | |
1641 Expect(Token::RBRACE, ok); | |
1642 | |
1643 if (is_sloppy(inner_scope->language_mode())) { | |
1644 inner_scope->HoistSloppyBlockFunctions(nullptr); | |
1645 } | |
1646 return result; | |
1647 } | |
1648 | |
1649 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state, | 1649 PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state, |
1650 int start, | 1650 int start, |
1651 PreParserExpression tag) { | 1651 PreParserExpression tag) { |
1652 if (IsTaggedTemplate(tag)) { | 1652 if (IsTaggedTemplate(tag)) { |
1653 // Emulate generation of array literals for tag callsite | 1653 // Emulate generation of array literals for tag callsite |
1654 // 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 |
1655 function_state_->NextMaterializedLiteralIndex(); | 1655 function_state_->NextMaterializedLiteralIndex(); |
1656 function_state_->NextMaterializedLiteralIndex(); | 1656 function_state_->NextMaterializedLiteralIndex(); |
1657 } | 1657 } |
1658 return EmptyExpression(); | 1658 return EmptyExpression(); |
1659 } | 1659 } |
1660 | 1660 |
1661 } // namespace internal | 1661 } // namespace internal |
1662 } // namespace v8 | 1662 } // namespace v8 |
1663 | 1663 |
1664 #endif // V8_PARSING_PREPARSER_H | 1664 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |