| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 VariableProxy* variable, | 145 VariableProxy* variable, |
| 146 Zone* zone) { | 146 Zone* zone) { |
| 147 PreParserExpression expression(TypeField::encode(kIdentifierExpression) | | 147 PreParserExpression expression(TypeField::encode(kIdentifierExpression) | |
| 148 IdentifierTypeField::encode(id.type_)); | 148 IdentifierTypeField::encode(id.type_)); |
| 149 expression.AddVariable(variable, zone); | 149 expression.AddVariable(variable, zone); |
| 150 return expression; | 150 return expression; |
| 151 } | 151 } |
| 152 | 152 |
| 153 static PreParserExpression BinaryOperation(PreParserExpression left, | 153 static PreParserExpression BinaryOperation(PreParserExpression left, |
| 154 Token::Value op, | 154 Token::Value op, |
| 155 PreParserExpression right) { | 155 PreParserExpression right, |
| 156 Zone* zone) { |
| 157 if (op == Token::COMMA) { |
| 158 // Possibly an arrow function parameter list. |
| 159 if (left.variables_ == nullptr) { |
| 160 return PreParserExpression(TypeField::encode(kExpression), |
| 161 right.variables_); |
| 162 } |
| 163 if (right.variables_ != nullptr) { |
| 164 for (auto variable : *right.variables_) { |
| 165 left.variables_->Add(variable, zone); |
| 166 } |
| 167 } |
| 168 return PreParserExpression(TypeField::encode(kExpression), |
| 169 left.variables_); |
| 170 } |
| 156 return PreParserExpression(TypeField::encode(kExpression)); | 171 return PreParserExpression(TypeField::encode(kExpression)); |
| 157 } | 172 } |
| 158 | 173 |
| 159 static PreParserExpression Assignment() { | 174 static PreParserExpression Assignment(ZoneList<VariableProxy*>* variables) { |
| 160 return PreParserExpression(TypeField::encode(kExpression) | | 175 return PreParserExpression(TypeField::encode(kExpression) | |
| 161 ExpressionTypeField::encode(kAssignment)); | 176 ExpressionTypeField::encode(kAssignment), |
| 177 variables); |
| 162 } | 178 } |
| 163 | 179 |
| 164 static PreParserExpression ObjectLiteral( | 180 static PreParserExpression ObjectLiteral( |
| 165 ZoneList<VariableProxy*>* variables) { | 181 ZoneList<VariableProxy*>* variables) { |
| 166 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), | 182 return PreParserExpression(TypeField::encode(kObjectLiteralExpression), |
| 167 variables); | 183 variables); |
| 168 } | 184 } |
| 169 | 185 |
| 170 static PreParserExpression ArrayLiteral(ZoneList<VariableProxy*>* variables) { | 186 static PreParserExpression ArrayLiteral(ZoneList<VariableProxy*>* variables) { |
| 171 return PreParserExpression(TypeField::encode(kArrayLiteralExpression), | 187 return PreParserExpression(TypeField::encode(kArrayLiteralExpression), |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 return PreParserExpression::Property(); | 610 return PreParserExpression::Property(); |
| 595 } | 611 } |
| 596 PreParserExpression NewUnaryOperation(Token::Value op, | 612 PreParserExpression NewUnaryOperation(Token::Value op, |
| 597 PreParserExpression expression, | 613 PreParserExpression expression, |
| 598 int pos) { | 614 int pos) { |
| 599 return PreParserExpression::Default(); | 615 return PreParserExpression::Default(); |
| 600 } | 616 } |
| 601 PreParserExpression NewBinaryOperation(Token::Value op, | 617 PreParserExpression NewBinaryOperation(Token::Value op, |
| 602 PreParserExpression left, | 618 PreParserExpression left, |
| 603 PreParserExpression right, int pos) { | 619 PreParserExpression right, int pos) { |
| 604 return PreParserExpression::BinaryOperation(left, op, right); | 620 return PreParserExpression::BinaryOperation(left, op, right, zone_); |
| 605 } | 621 } |
| 606 PreParserExpression NewCompareOperation(Token::Value op, | 622 PreParserExpression NewCompareOperation(Token::Value op, |
| 607 PreParserExpression left, | 623 PreParserExpression left, |
| 608 PreParserExpression right, int pos) { | 624 PreParserExpression right, int pos) { |
| 609 return PreParserExpression::Default(); | 625 return PreParserExpression::Default(); |
| 610 } | 626 } |
| 611 PreParserExpression NewRewritableExpression(PreParserExpression expression) { | 627 PreParserExpression NewRewritableExpression(PreParserExpression expression) { |
| 612 return expression; | 628 return expression; |
| 613 } | 629 } |
| 614 PreParserExpression NewAssignment(Token::Value op, | 630 PreParserExpression NewAssignment(Token::Value op, |
| 615 PreParserExpression left, | 631 PreParserExpression left, |
| 616 PreParserExpression right, | 632 PreParserExpression right, |
| 617 int pos) { | 633 int pos) { |
| 618 return PreParserExpression::Assignment(); | 634 // Identifiers need to be tracked since this might be a parameter with a |
| 635 // default value inside an arrow function parameter list. |
| 636 return PreParserExpression::Assignment(left.variables_); |
| 619 } | 637 } |
| 620 PreParserExpression NewYield(PreParserExpression generator_object, | 638 PreParserExpression NewYield(PreParserExpression generator_object, |
| 621 PreParserExpression expression, int pos, | 639 PreParserExpression expression, int pos, |
| 622 Yield::OnException on_exception) { | 640 Yield::OnException on_exception) { |
| 623 return PreParserExpression::Default(); | 641 return PreParserExpression::Default(); |
| 624 } | 642 } |
| 625 PreParserExpression NewConditional(PreParserExpression condition, | 643 PreParserExpression NewConditional(PreParserExpression condition, |
| 626 PreParserExpression then_expression, | 644 PreParserExpression then_expression, |
| 627 PreParserExpression else_expression, | 645 PreParserExpression else_expression, |
| 628 int pos) { | 646 int pos) { |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 } | 1496 } |
| 1479 } | 1497 } |
| 1480 } | 1498 } |
| 1481 | 1499 |
| 1482 V8_INLINE void DeclareArrowFunctionFormalParameters( | 1500 V8_INLINE void DeclareArrowFunctionFormalParameters( |
| 1483 PreParserFormalParameters* parameters, PreParserExpression params, | 1501 PreParserFormalParameters* parameters, PreParserExpression params, |
| 1484 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 1502 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
| 1485 bool* ok) { | 1503 bool* ok) { |
| 1486 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect | 1504 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect |
| 1487 // parameter lists that are too long. | 1505 // parameter lists that are too long. |
| 1488 // FIXME(marja): Add code to declare arrow function parameters to allocate | 1506 if (track_unresolved_variables_) { |
| 1489 // less pessimistically. | 1507 DCHECK(FLAG_lazy_inner_functions); |
| 1508 if (params.variables_ != nullptr) { |
| 1509 for (auto variable : *params.variables_) { |
| 1510 parameters->scope->DeclareVariableName(variable->raw_name(), VAR); |
| 1511 } |
| 1512 } |
| 1513 } |
| 1490 } | 1514 } |
| 1491 | 1515 |
| 1492 V8_INLINE void ReindexLiterals(const PreParserFormalParameters& parameters) {} | 1516 V8_INLINE void ReindexLiterals(const PreParserFormalParameters& parameters) {} |
| 1493 | 1517 |
| 1494 V8_INLINE PreParserExpression NoTemplateTag() { | 1518 V8_INLINE PreParserExpression NoTemplateTag() { |
| 1495 return PreParserExpression::NoTemplateTag(); | 1519 return PreParserExpression::NoTemplateTag(); |
| 1496 } | 1520 } |
| 1497 | 1521 |
| 1498 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) { | 1522 V8_INLINE static bool IsTaggedTemplate(const PreParserExpression tag) { |
| 1499 return !tag.IsNoTemplateTag(); | 1523 return !tag.IsNoTemplateTag(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 function_state_->NextMaterializedLiteralIndex(); | 1603 function_state_->NextMaterializedLiteralIndex(); |
| 1580 function_state_->NextMaterializedLiteralIndex(); | 1604 function_state_->NextMaterializedLiteralIndex(); |
| 1581 } | 1605 } |
| 1582 return EmptyExpression(); | 1606 return EmptyExpression(); |
| 1583 } | 1607 } |
| 1584 | 1608 |
| 1585 } // namespace internal | 1609 } // namespace internal |
| 1586 } // namespace v8 | 1610 } // namespace v8 |
| 1587 | 1611 |
| 1588 #endif // V8_PARSING_PREPARSER_H | 1612 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |