Chromium Code Reviews| 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 | 10 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 expression.AddIdentifier(id.string_, zone); | 146 expression.AddIdentifier(id.string_, zone); |
| 147 return expression; | 147 return expression; |
| 148 } | 148 } |
| 149 | 149 |
| 150 static PreParserExpression BinaryOperation(PreParserExpression left, | 150 static PreParserExpression BinaryOperation(PreParserExpression left, |
| 151 Token::Value op, | 151 Token::Value op, |
| 152 PreParserExpression right) { | 152 PreParserExpression right) { |
| 153 return PreParserExpression(TypeField::encode(kExpression)); | 153 return PreParserExpression(TypeField::encode(kExpression)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 static PreParserExpression Assignment() { | 156 static PreParserExpression Assignment( |
| 157 ZoneList<const AstRawString*>* identifiers = nullptr) { | |
| 157 return PreParserExpression(TypeField::encode(kExpression) | | 158 return PreParserExpression(TypeField::encode(kExpression) | |
| 158 ExpressionTypeField::encode(kAssignment)); | 159 ExpressionTypeField::encode(kAssignment), |
| 160 identifiers); | |
| 159 } | 161 } |
| 160 | 162 |
| 161 static PreParserExpression ObjectLiteral( | 163 static PreParserExpression ObjectLiteral( |
| 162 ZoneList<const AstRawString*>* identifiers = nullptr) { | 164 ZoneList<const AstRawString*>* identifiers = nullptr) { |
| 163 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), | 165 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), |
| 164 identifiers); | 166 identifiers); |
| 165 } | 167 } |
| 166 | 168 |
| 167 static PreParserExpression ArrayLiteral( | 169 static PreParserExpression ArrayLiteral( |
| 168 ZoneList<const AstRawString*>* identifiers = nullptr) { | 170 ZoneList<const AstRawString*>* identifiers = nullptr) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 PreParserExpression right, int pos) { | 603 PreParserExpression right, int pos) { |
| 602 return PreParserExpression::Default(); | 604 return PreParserExpression::Default(); |
| 603 } | 605 } |
| 604 PreParserExpression NewRewritableExpression(PreParserExpression expression) { | 606 PreParserExpression NewRewritableExpression(PreParserExpression expression) { |
| 605 return expression; | 607 return expression; |
| 606 } | 608 } |
| 607 PreParserExpression NewAssignment(Token::Value op, | 609 PreParserExpression NewAssignment(Token::Value op, |
| 608 PreParserExpression left, | 610 PreParserExpression left, |
| 609 PreParserExpression right, | 611 PreParserExpression right, |
| 610 int pos) { | 612 int pos) { |
| 611 return PreParserExpression::Assignment(); | 613 // For tracking identifiers for parameters with a default value. |
| 614 return PreParserExpression::Assignment(left.identifiers_); | |
|
Toon Verwaest
2016/12/01 13:33:27
Mmh, actually this isn't correct is it?
var {a:b}
marja
2016/12/05 16:05:19
Tracking unresolved variables doesn't go via this
| |
| 612 } | 615 } |
| 613 PreParserExpression NewYield(PreParserExpression generator_object, | 616 PreParserExpression NewYield(PreParserExpression generator_object, |
| 614 PreParserExpression expression, int pos, | 617 PreParserExpression expression, int pos, |
| 615 Yield::OnException on_exception) { | 618 Yield::OnException on_exception) { |
| 616 return PreParserExpression::Default(); | 619 return PreParserExpression::Default(); |
| 617 } | 620 } |
| 618 PreParserExpression NewConditional(PreParserExpression condition, | 621 PreParserExpression NewConditional(PreParserExpression condition, |
| 619 PreParserExpression then_expression, | 622 PreParserExpression then_expression, |
| 620 PreParserExpression else_expression, | 623 PreParserExpression else_expression, |
| 621 int pos) { | 624 int pos) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 static int dummy = 42; | 746 static int dummy = 42; |
| 744 return &dummy; | 747 return &dummy; |
| 745 } | 748 } |
| 746 | 749 |
| 747 private: | 750 private: |
| 748 Zone* zone_; | 751 Zone* zone_; |
| 749 }; | 752 }; |
| 750 | 753 |
| 751 | 754 |
| 752 struct PreParserFormalParameters : FormalParametersBase { | 755 struct PreParserFormalParameters : FormalParametersBase { |
| 756 struct Parameter : public ZoneObject { | |
| 757 Parameter(const AstRawString* name, bool is_optional, bool is_rest) | |
| 758 : name(name), | |
| 759 pattern(PreParserExpression::Default()), | |
| 760 is_optional(is_optional), | |
| 761 is_rest(is_rest) {} | |
| 762 Parameter(PreParserExpression pattern, bool is_optional, bool is_rest) | |
| 763 : name(nullptr), | |
| 764 pattern(pattern), | |
| 765 is_optional(is_optional), | |
| 766 is_rest(is_rest) {} | |
| 767 Parameter() | |
| 768 : name(nullptr), | |
| 769 pattern(PreParserExpression::Default()), | |
| 770 is_optional(false), | |
| 771 is_rest(false) {} | |
| 772 Parameter** next() { return &next_parameter; } | |
| 773 Parameter* const* next() const { return &next_parameter; } | |
| 774 const AstRawString* name; | |
| 775 PreParserExpression pattern; | |
| 776 bool is_optional; | |
| 777 bool is_rest; | |
| 778 Parameter* next_parameter = nullptr; | |
| 779 }; | |
| 753 explicit PreParserFormalParameters(DeclarationScope* scope) | 780 explicit PreParserFormalParameters(DeclarationScope* scope) |
| 754 : FormalParametersBase(scope) {} | 781 : FormalParametersBase(scope) {} |
| 755 | 782 |
| 756 void* params = nullptr; // Dummy | 783 ThreadedList<Parameter> params; |
| 757 }; | 784 }; |
| 758 | 785 |
| 759 | 786 |
| 760 class PreParser; | 787 class PreParser; |
| 761 | 788 |
| 762 class PreParserTarget { | 789 class PreParserTarget { |
| 763 public: | 790 public: |
| 764 PreParserTarget(ParserBase<PreParser>* preparser, | 791 PreParserTarget(ParserBase<PreParser>* preparser, |
| 765 PreParserStatement statement) {} | 792 PreParserStatement statement) {} |
| 766 }; | 793 }; |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1447 | 1474 |
| 1448 V8_INLINE void AddParameterInitializationBlock( | 1475 V8_INLINE void AddParameterInitializationBlock( |
| 1449 const PreParserFormalParameters& parameters, PreParserStatementList body, | 1476 const PreParserFormalParameters& parameters, PreParserStatementList body, |
| 1450 bool is_async, bool* ok) {} | 1477 bool is_async, bool* ok) {} |
| 1451 | 1478 |
| 1452 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, | 1479 V8_INLINE void AddFormalParameter(PreParserFormalParameters* parameters, |
| 1453 PreParserExpression pattern, | 1480 PreParserExpression pattern, |
| 1454 PreParserExpression initializer, | 1481 PreParserExpression initializer, |
| 1455 int initializer_end_position, | 1482 int initializer_end_position, |
| 1456 bool is_rest) { | 1483 bool is_rest) { |
| 1484 if (track_unresolved_variables_) { | |
| 1485 DCHECK(FLAG_lazy_inner_functions); | |
| 1486 bool is_simple = pattern.IsIdentifier() && IsEmptyExpression(initializer); | |
| 1487 if (is_simple) { | |
| 1488 DCHECK_EQ(1, pattern.identifiers_->length()); | |
| 1489 parameters->params.Add( | |
| 1490 new (zone()) PreParserFormalParameters::Parameter( | |
| 1491 (*pattern.identifiers_)[0], !IsEmptyExpression(initializer), | |
| 1492 is_rest)); | |
| 1493 } else { | |
| 1494 parameters->params.Add( | |
| 1495 new (zone()) PreParserFormalParameters::Parameter( | |
| 1496 pattern, !IsEmptyExpression(initializer), is_rest)); | |
| 1497 } | |
| 1498 } | |
| 1457 parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest); | 1499 parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest); |
| 1458 } | 1500 } |
| 1459 | 1501 |
| 1460 V8_INLINE void DeclareFormalParameters(DeclarationScope* scope, | 1502 V8_INLINE void DeclareFormalParameters( |
| 1461 void* parameters) { | 1503 DeclarationScope* scope, |
| 1504 const ThreadedList<PreParserFormalParameters::Parameter>& parameters) { | |
| 1462 if (!classifier()->is_simple_parameter_list()) { | 1505 if (!classifier()->is_simple_parameter_list()) { |
| 1463 scope->SetHasNonSimpleParameters(); | 1506 scope->SetHasNonSimpleParameters(); |
| 1464 } | 1507 } |
| 1508 if (track_unresolved_variables_) { | |
| 1509 DCHECK(FLAG_lazy_inner_functions); | |
| 1510 for (auto parameter : parameters) { | |
| 1511 if (parameter->name != nullptr) { | |
| 1512 DCHECK(FLAG_lazy_inner_functions); | |
| 1513 bool is_duplicate = false; | |
| 1514 scope->DeclareParameterName(parameter->name, parameter->is_optional, | |
| 1515 parameter->is_rest, &is_duplicate, | |
| 1516 ast_value_factory()); | |
| 1517 } | |
| 1518 if (parameter->pattern.identifiers_ != nullptr) { | |
| 1519 DCHECK(FLAG_lazy_inner_functions); | |
| 1520 for (auto i : *parameter->pattern.identifiers_) { | |
| 1521 scope->DeclareVariableName(i, VAR); | |
| 1522 } | |
| 1523 } | |
| 1524 } | |
| 1525 } | |
| 1465 } | 1526 } |
| 1466 | 1527 |
| 1467 V8_INLINE void DeclareArrowFunctionFormalParameters( | 1528 V8_INLINE void DeclareArrowFunctionFormalParameters( |
| 1468 PreParserFormalParameters* parameters, PreParserExpression params, | 1529 PreParserFormalParameters* parameters, PreParserExpression params, |
| 1469 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 1530 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
| 1470 bool* ok) { | 1531 bool* ok) { |
| 1471 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect | 1532 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect |
| 1472 // parameter lists that are too long. | 1533 // parameter lists that are too long. |
| 1534 // FIXME(marja): Add code to declare arrow function parameters (once we add | |
| 1535 // lazy inner arrow functions - at the moment inner arrow functions are | |
| 1536 // parsed eagerly). | |
| 1473 } | 1537 } |
| 1474 | 1538 |
| 1475 V8_INLINE void ReindexLiterals(const PreParserFormalParameters& parameters) {} | 1539 V8_INLINE void ReindexLiterals(const PreParserFormalParameters& parameters) {} |
| 1476 | 1540 |
| 1477 V8_INLINE PreParserExpression NoTemplateTag() { | 1541 V8_INLINE PreParserExpression NoTemplateTag() { |
| 1478 return PreParserExpression::NoTemplateTag(); | 1542 return PreParserExpression::NoTemplateTag(); |
| 1479 } | 1543 } |
| 1480 | 1544 |
| 1481 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) { | 1545 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) { |
| 1482 return !tag.IsNoTemplateTag(); | 1546 return !tag.IsNoTemplateTag(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1562 function_state_->NextMaterializedLiteralIndex(); | 1626 function_state_->NextMaterializedLiteralIndex(); |
| 1563 function_state_->NextMaterializedLiteralIndex(); | 1627 function_state_->NextMaterializedLiteralIndex(); |
| 1564 } | 1628 } |
| 1565 return EmptyExpression(); | 1629 return EmptyExpression(); |
| 1566 } | 1630 } |
| 1567 | 1631 |
| 1568 } // namespace internal | 1632 } // namespace internal |
| 1569 } // namespace v8 | 1633 } // namespace v8 |
| 1570 | 1634 |
| 1571 #endif // V8_PARSING_PREPARSER_H | 1635 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |