| 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/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/parsing/parser-base.h" | 9 #include "src/parsing/parser-base.h" |
| 10 #include "src/parsing/preparse-data.h" | 10 #include "src/parsing/preparse-data.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 expression.AddIdentifier(id.string_, zone); | 142 expression.AddIdentifier(id.string_, zone); |
| 143 return expression; | 143 return expression; |
| 144 } | 144 } |
| 145 | 145 |
| 146 static PreParserExpression BinaryOperation(PreParserExpression left, | 146 static PreParserExpression BinaryOperation(PreParserExpression left, |
| 147 Token::Value op, | 147 Token::Value op, |
| 148 PreParserExpression right) { | 148 PreParserExpression right) { |
| 149 return PreParserExpression(TypeField::encode(kExpression)); | 149 return PreParserExpression(TypeField::encode(kExpression)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 static PreParserExpression Assignment() { | 152 static PreParserExpression Assignment( |
| 153 ZoneList<const AstRawString*>* identifiers = nullptr) { |
| 153 return PreParserExpression(TypeField::encode(kExpression) | | 154 return PreParserExpression(TypeField::encode(kExpression) | |
| 154 ExpressionTypeField::encode(kAssignment)); | 155 ExpressionTypeField::encode(kAssignment), |
| 156 identifiers); |
| 155 } | 157 } |
| 156 | 158 |
| 157 static PreParserExpression ObjectLiteral( | 159 static PreParserExpression ObjectLiteral( |
| 158 ZoneList<const AstRawString*>* identifiers = nullptr) { | 160 ZoneList<const AstRawString*>* identifiers = nullptr) { |
| 159 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), | 161 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), |
| 160 identifiers); | 162 identifiers); |
| 161 } | 163 } |
| 162 | 164 |
| 163 static PreParserExpression ArrayLiteral( | 165 static PreParserExpression ArrayLiteral( |
| 164 ZoneList<const AstRawString*>* identifiers = nullptr) { | 166 ZoneList<const AstRawString*>* identifiers = nullptr) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 PreParserExpression right, int pos) { | 599 PreParserExpression right, int pos) { |
| 598 return PreParserExpression::Default(); | 600 return PreParserExpression::Default(); |
| 599 } | 601 } |
| 600 PreParserExpression NewRewritableExpression(PreParserExpression expression) { | 602 PreParserExpression NewRewritableExpression(PreParserExpression expression) { |
| 601 return expression; | 603 return expression; |
| 602 } | 604 } |
| 603 PreParserExpression NewAssignment(Token::Value op, | 605 PreParserExpression NewAssignment(Token::Value op, |
| 604 PreParserExpression left, | 606 PreParserExpression left, |
| 605 PreParserExpression right, | 607 PreParserExpression right, |
| 606 int pos) { | 608 int pos) { |
| 607 return PreParserExpression::Assignment(); | 609 // For tracking identifiers for parameters with a default value. |
| 610 return PreParserExpression::Assignment(left.identifiers_); |
| 608 } | 611 } |
| 609 PreParserExpression NewYield(PreParserExpression generator_object, | 612 PreParserExpression NewYield(PreParserExpression generator_object, |
| 610 PreParserExpression expression, int pos, | 613 PreParserExpression expression, int pos, |
| 611 Yield::OnException on_exception) { | 614 Yield::OnException on_exception) { |
| 612 return PreParserExpression::Default(); | 615 return PreParserExpression::Default(); |
| 613 } | 616 } |
| 614 PreParserExpression NewConditional(PreParserExpression condition, | 617 PreParserExpression NewConditional(PreParserExpression condition, |
| 615 PreParserExpression then_expression, | 618 PreParserExpression then_expression, |
| 616 PreParserExpression else_expression, | 619 PreParserExpression else_expression, |
| 617 int pos) { | 620 int pos) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 static int dummy = 42; | 742 static int dummy = 42; |
| 740 return &dummy; | 743 return &dummy; |
| 741 } | 744 } |
| 742 | 745 |
| 743 private: | 746 private: |
| 744 Zone* zone_; | 747 Zone* zone_; |
| 745 }; | 748 }; |
| 746 | 749 |
| 747 | 750 |
| 748 struct PreParserFormalParameters : FormalParametersBase { | 751 struct PreParserFormalParameters : FormalParametersBase { |
| 752 struct Parameter : public ZoneObject { |
| 753 explicit Parameter(PreParserExpression pattern) : pattern(pattern) {} |
| 754 Parameter** next() { return &next_parameter; } |
| 755 Parameter* const* next() const { return &next_parameter; } |
| 756 PreParserExpression pattern; |
| 757 Parameter* next_parameter = nullptr; |
| 758 }; |
| 749 explicit PreParserFormalParameters(DeclarationScope* scope) | 759 explicit PreParserFormalParameters(DeclarationScope* scope) |
| 750 : FormalParametersBase(scope) {} | 760 : FormalParametersBase(scope) {} |
| 751 | 761 |
| 752 void* params = nullptr; // Dummy | 762 ThreadedList<Parameter> params; |
| 753 }; | 763 }; |
| 754 | 764 |
| 755 | 765 |
| 756 class PreParser; | 766 class PreParser; |
| 757 | 767 |
| 758 class PreParserTarget { | 768 class PreParserTarget { |
| 759 public: | 769 public: |
| 760 PreParserTarget(ParserBase<PreParser>* preparser, | 770 PreParserTarget(ParserBase<PreParser>* preparser, |
| 761 PreParserStatement statement) {} | 771 PreParserStatement statement) {} |
| 762 }; | 772 }; |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 | 1443 |
| 1434 V8_INLINE void AddParameterInitializationBlock( | 1444 V8_INLINE void AddParameterInitializationBlock( |
| 1435 const PreParserFormalParameters& parameters, PreParserStatementList body, | 1445 const PreParserFormalParameters& parameters, PreParserStatementList body, |
| 1436 bool is_async, bool* ok) {} | 1446 bool is_async, bool* ok) {} |
| 1437 | 1447 |
| 1438 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, | 1448 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, |
| 1439 PreParserExpression pattern, | 1449 PreParserExpression pattern, |
| 1440 PreParserExpression initializer, | 1450 PreParserExpression initializer, |
| 1441 int initializer_end_position, | 1451 int initializer_end_position, |
| 1442 bool is_rest) { | 1452 bool is_rest) { |
| 1453 if (track_unresolved_variables_) { |
| 1454 DCHECK(FLAG_lazy_inner_functions); |
| 1455 parameters->params.Add(new (zone()) |
| 1456 PreParserFormalParameters::Parameter(pattern)); |
| 1457 } |
| 1443 parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest); | 1458 parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest); |
| 1444 } | 1459 } |
| 1445 | 1460 |
| 1446 V8_INLINE void DeclareFormalParameters(DeclarationScope* scope, | 1461 V8_INLINE void DeclareFormalParameters( |
| 1447 void* parameters) { | 1462 DeclarationScope* scope, |
| 1463 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { |
| 1448 if (!classifier()->is_simple_parameter_list()) { | 1464 if (!classifier()->is_simple_parameter_list()) { |
| 1449 scope->SetHasNonSimpleParameters(); | 1465 scope->SetHasNonSimpleParameters(); |
| 1450 } | 1466 } |
| 1467 if (track_unresolved_variables_) { |
| 1468 DCHECK(FLAG_lazy_inner_functions); |
| 1469 for (auto parameter : parameters) { |
| 1470 if (parameter->pattern.identifiers_ != nullptr) { |
| 1471 for (auto i : *parameter->pattern.identifiers_) { |
| 1472 scope->DeclareVariableName(i, VAR); |
| 1473 } |
| 1474 } |
| 1475 } |
| 1476 } |
| 1451 } | 1477 } |
| 1452 | 1478 |
| 1453 V8_INLINE void DeclareArrowFunctionFormalParameters( | 1479 V8_INLINE void DeclareArrowFunctionFormalParameters( |
| 1454 PreParserFormalParameters* parameters, PreParserExpression params, | 1480 PreParserFormalParameters* parameters, PreParserExpression params, |
| 1455 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 1481 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
| 1456 bool* ok) { | 1482 bool* ok) { |
| 1457 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect | 1483 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect |
| 1458 // parameter lists that are too long. | 1484 // parameter lists that are too long. |
| 1485 // FIXME(marja): Add code to declare arrow function parameters to allocate |
| 1486 // less pessimistically. |
| 1459 } | 1487 } |
| 1460 | 1488 |
| 1461 V8_INLINE void ReindexLiterals(const PreParserFormalParameters& parameters) {} | 1489 V8_INLINE void ReindexLiterals(const PreParserFormalParameters& parameters) {} |
| 1462 | 1490 |
| 1463 V8_INLINE PreParserExpression NoTemplateTag() { | 1491 V8_INLINE PreParserExpression NoTemplateTag() { |
| 1464 return PreParserExpression::NoTemplateTag(); | 1492 return PreParserExpression::NoTemplateTag(); |
| 1465 } | 1493 } |
| 1466 | 1494 |
| 1467 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) { | 1495 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) { |
| 1468 return !tag.IsNoTemplateTag(); | 1496 return !tag.IsNoTemplateTag(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 function_state_->NextMaterializedLiteralIndex(); | 1576 function_state_->NextMaterializedLiteralIndex(); |
| 1549 function_state_->NextMaterializedLiteralIndex(); | 1577 function_state_->NextMaterializedLiteralIndex(); |
| 1550 } | 1578 } |
| 1551 return EmptyExpression(); | 1579 return EmptyExpression(); |
| 1552 } | 1580 } |
| 1553 | 1581 |
| 1554 } // namespace internal | 1582 } // namespace internal |
| 1555 } // namespace v8 | 1583 } // namespace v8 |
| 1556 | 1584 |
| 1557 #endif // V8_PARSING_PREPARSER_H | 1585 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |