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_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 public: | 81 public: |
82 // Shorten type names defined by Traits. | 82 // Shorten type names defined by Traits. |
83 typedef typename Traits::Type::Expression ExpressionT; | 83 typedef typename Traits::Type::Expression ExpressionT; |
84 typedef typename Traits::Type::Identifier IdentifierT; | 84 typedef typename Traits::Type::Identifier IdentifierT; |
85 typedef typename Traits::Type::FormalParameter FormalParameterT; | 85 typedef typename Traits::Type::FormalParameter FormalParameterT; |
86 typedef typename Traits::Type::FormalParameters FormalParametersT; | 86 typedef typename Traits::Type::FormalParameters FormalParametersT; |
87 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 87 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
88 typedef typename Traits::Type::Literal LiteralT; | 88 typedef typename Traits::Type::Literal LiteralT; |
89 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 89 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
90 typedef typename Traits::Type::StatementList StatementListT; | 90 typedef typename Traits::Type::StatementList StatementListT; |
| 91 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; |
91 | 92 |
92 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 93 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
93 v8::Extension* extension, AstValueFactory* ast_value_factory, | 94 v8::Extension* extension, AstValueFactory* ast_value_factory, |
94 ParserRecorder* log, typename Traits::Type::Parser this_object) | 95 ParserRecorder* log, typename Traits::Type::Parser this_object) |
95 : Traits(this_object), | 96 : Traits(this_object), |
96 parenthesized_function_(false), | 97 parenthesized_function_(false), |
97 scope_(NULL), | 98 scope_(NULL), |
98 function_state_(NULL), | 99 function_state_(NULL), |
99 extension_(extension), | 100 extension_(extension), |
100 fni_(NULL), | 101 fni_(NULL), |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 return generator_object_variable_; | 238 return generator_object_variable_; |
238 } | 239 } |
239 | 240 |
240 typename Traits::Type::Factory* factory() { return factory_; } | 241 typename Traits::Type::Factory* factory() { return factory_; } |
241 | 242 |
242 const List<DestructuringAssignment>& destructuring_assignments_to_rewrite() | 243 const List<DestructuringAssignment>& destructuring_assignments_to_rewrite() |
243 const { | 244 const { |
244 return destructuring_assignments_to_rewrite_; | 245 return destructuring_assignments_to_rewrite_; |
245 } | 246 } |
246 | 247 |
247 void AddDestructuringAssignment(DestructuringAssignment pair) { | |
248 destructuring_assignments_to_rewrite_.Add(pair); | |
249 } | |
250 | |
251 List<ExpressionT>& expressions_in_tail_position() { | 248 List<ExpressionT>& expressions_in_tail_position() { |
252 return expressions_in_tail_position_; | 249 return expressions_in_tail_position_; |
253 } | 250 } |
254 void AddExpressionInTailPosition(ExpressionT expression) { | 251 void AddExpressionInTailPosition(ExpressionT expression) { |
255 if (collect_expressions_in_tail_position_) { | 252 if (collect_expressions_in_tail_position_) { |
256 expressions_in_tail_position_.Add(expression); | 253 expressions_in_tail_position_.Add(expression); |
257 } | 254 } |
258 } | 255 } |
259 | 256 |
260 bool collect_expressions_in_tail_position() const { | 257 bool collect_expressions_in_tail_position() const { |
261 return collect_expressions_in_tail_position_; | 258 return collect_expressions_in_tail_position_; |
262 } | 259 } |
263 void set_collect_expressions_in_tail_position(bool collect) { | 260 void set_collect_expressions_in_tail_position(bool collect) { |
264 collect_expressions_in_tail_position_ = collect; | 261 collect_expressions_in_tail_position_ = collect; |
265 } | 262 } |
266 | 263 |
| 264 ZoneList<ExpressionT>* non_patterns_to_rewrite() { |
| 265 return &non_patterns_to_rewrite_; |
| 266 } |
| 267 |
267 private: | 268 private: |
| 269 void AddDestructuringAssignment(DestructuringAssignment pair) { |
| 270 destructuring_assignments_to_rewrite_.Add(pair); |
| 271 } |
| 272 |
| 273 V8_INLINE Scope* scope() { return *scope_stack_; } |
| 274 |
| 275 void AddNonPatternForRewriting(ExpressionT expr) { |
| 276 non_patterns_to_rewrite_.Add(expr, (*scope_stack_)->zone()); |
| 277 } |
| 278 |
268 // Used to assign an index to each literal that needs materialization in | 279 // Used to assign an index to each literal that needs materialization in |
269 // the function. Includes regexp literals, and boilerplate for object and | 280 // the function. Includes regexp literals, and boilerplate for object and |
270 // array literals. | 281 // array literals. |
271 int next_materialized_literal_index_; | 282 int next_materialized_literal_index_; |
272 | 283 |
273 // Properties count estimation. | 284 // Properties count estimation. |
274 int expected_property_count_; | 285 int expected_property_count_; |
275 | 286 |
276 // Location of most recent use of 'this' (invalid if none). | 287 // Location of most recent use of 'this' (invalid if none). |
277 Scanner::Location this_location_; | 288 Scanner::Location this_location_; |
(...skipping 11 matching lines...) Expand all Loading... |
289 Variable* generator_object_variable_; | 300 Variable* generator_object_variable_; |
290 | 301 |
291 FunctionState** function_state_stack_; | 302 FunctionState** function_state_stack_; |
292 FunctionState* outer_function_state_; | 303 FunctionState* outer_function_state_; |
293 Scope** scope_stack_; | 304 Scope** scope_stack_; |
294 Scope* outer_scope_; | 305 Scope* outer_scope_; |
295 | 306 |
296 List<DestructuringAssignment> destructuring_assignments_to_rewrite_; | 307 List<DestructuringAssignment> destructuring_assignments_to_rewrite_; |
297 List<ExpressionT> expressions_in_tail_position_; | 308 List<ExpressionT> expressions_in_tail_position_; |
298 bool collect_expressions_in_tail_position_; | 309 bool collect_expressions_in_tail_position_; |
299 | 310 ZoneList<ExpressionT> non_patterns_to_rewrite_; |
300 void RewriteDestructuringAssignments(); | |
301 | 311 |
302 typename Traits::Type::Factory* factory_; | 312 typename Traits::Type::Factory* factory_; |
303 | 313 |
304 friend class ParserTraits; | 314 friend class ParserTraits; |
| 315 friend class PreParserTraits; |
305 friend class Checkpoint; | 316 friend class Checkpoint; |
306 }; | 317 }; |
307 | 318 |
308 // Annoyingly, arrow functions first parse as comma expressions, then when we | 319 // Annoyingly, arrow functions first parse as comma expressions, then when we |
309 // see the => we have to go back and reinterpret the arguments as being formal | 320 // see the => we have to go back and reinterpret the arguments as being formal |
310 // parameters. To do so we need to reset some of the parser state back to | 321 // parameters. To do so we need to reset some of the parser state back to |
311 // what it was before the arguments were first seen. | 322 // what it was before the arguments were first seen. |
312 class Checkpoint BASE_EMBEDDED { | 323 class Checkpoint BASE_EMBEDDED { |
313 public: | 324 public: |
314 explicit Checkpoint(ParserBase* parser) { | 325 explicit Checkpoint(ParserBase* parser) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 594 |
584 void GetUnexpectedTokenMessage( | 595 void GetUnexpectedTokenMessage( |
585 Token::Value token, MessageTemplate::Template* message, const char** arg, | 596 Token::Value token, MessageTemplate::Template* message, const char** arg, |
586 MessageTemplate::Template default_ = MessageTemplate::kUnexpectedToken); | 597 MessageTemplate::Template default_ = MessageTemplate::kUnexpectedToken); |
587 | 598 |
588 void ReportUnexpectedToken(Token::Value token); | 599 void ReportUnexpectedToken(Token::Value token); |
589 void ReportUnexpectedTokenAt( | 600 void ReportUnexpectedTokenAt( |
590 Scanner::Location location, Token::Value token, | 601 Scanner::Location location, Token::Value token, |
591 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken); | 602 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken); |
592 | 603 |
593 | 604 void ReportClassifierError( |
594 void ReportClassifierError(const ExpressionClassifier::Error& error) { | 605 const typename ExpressionClassifier::Error& error) { |
595 Traits::ReportMessageAt(error.location, error.message, error.arg, | 606 Traits::ReportMessageAt(error.location, error.message, error.arg, |
596 error.type); | 607 error.type); |
597 } | 608 } |
598 | 609 |
599 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { | 610 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { |
600 if (!classifier->is_valid_expression() || | 611 if (!classifier->is_valid_expression() || |
601 classifier->has_cover_initialized_name()) { | 612 classifier->has_cover_initialized_name()) { |
602 const Scanner::Location& a = classifier->expression_error().location; | 613 const Scanner::Location& a = classifier->expression_error().location; |
603 const Scanner::Location& b = | 614 const Scanner::Location& b = |
604 classifier->cover_initialized_name_error().location; | 615 classifier->cover_initialized_name_error().location; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 Traits::ReportMessageAt(scanner()->location(), | 673 Traits::ReportMessageAt(scanner()->location(), |
663 MessageTemplate::kUnexpectedToken, | 674 MessageTemplate::kUnexpectedToken, |
664 Token::String(scanner()->current_token())); | 675 Token::String(scanner()->current_token())); |
665 *ok = false; | 676 *ok = false; |
666 } | 677 } |
667 } else if (!classifier->is_valid_arrow_formal_parameters()) { | 678 } else if (!classifier->is_valid_arrow_formal_parameters()) { |
668 // If after parsing the expr, we see an error but the expression is | 679 // If after parsing the expr, we see an error but the expression is |
669 // neither a valid binding pattern nor a valid parenthesized formal | 680 // neither a valid binding pattern nor a valid parenthesized formal |
670 // parameter list, show the "arrow formal parameters" error if the formals | 681 // parameter list, show the "arrow formal parameters" error if the formals |
671 // started with a parenthesis, and the binding pattern error otherwise. | 682 // started with a parenthesis, and the binding pattern error otherwise. |
672 const ExpressionClassifier::Error& error = | 683 const typename ExpressionClassifier::Error& error = |
673 parenthesized_formals ? classifier->arrow_formal_parameters_error() | 684 parenthesized_formals ? classifier->arrow_formal_parameters_error() |
674 : classifier->binding_pattern_error(); | 685 : classifier->binding_pattern_error(); |
675 ReportClassifierError(error); | 686 ReportClassifierError(error); |
676 *ok = false; | 687 *ok = false; |
677 } | 688 } |
678 } | 689 } |
679 | 690 |
680 void ValidateLetPattern(const ExpressionClassifier* classifier, bool* ok) { | 691 void ValidateLetPattern(const ExpressionClassifier* classifier, bool* ok) { |
681 if (!classifier->is_valid_let_pattern()) { | 692 if (!classifier->is_valid_let_pattern()) { |
682 ReportClassifierError(classifier->let_pattern_error()); | 693 ReportClassifierError(classifier->let_pattern_error()); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 Traits::IsEvalOrArguments(Traits::AsIdentifier(expression))) { | 841 Traits::IsEvalOrArguments(Traits::AsIdentifier(expression))) { |
831 return false; | 842 return false; |
832 } | 843 } |
833 if (is_strong(language_mode()) && | 844 if (is_strong(language_mode()) && |
834 Traits::IsUndefined(Traits::AsIdentifier(expression))) { | 845 Traits::IsUndefined(Traits::AsIdentifier(expression))) { |
835 return false; | 846 return false; |
836 } | 847 } |
837 return true; | 848 return true; |
838 } | 849 } |
839 | 850 |
840 bool IsAssignmentExpression(ExpressionT expression) { | |
841 return expression->IsAssignment() || | |
842 expression->IsRewritableAssignmentExpression(); | |
843 } | |
844 | |
845 bool IsValidPattern(ExpressionT expression) { | 851 bool IsValidPattern(ExpressionT expression) { |
846 return expression->IsObjectLiteral() || expression->IsArrayLiteral(); | 852 return expression->IsObjectLiteral() || expression->IsArrayLiteral(); |
847 } | 853 } |
848 | 854 |
849 // Keep track of eval() calls since they disable all local variable | 855 // Keep track of eval() calls since they disable all local variable |
850 // optimizations. This checks if expression is an eval call, and if yes, | 856 // optimizations. This checks if expression is an eval call, and if yes, |
851 // forwards the information to scope. | 857 // forwards the information to scope. |
852 void CheckPossibleEvalCall(ExpressionT expression, Scope* scope) { | 858 void CheckPossibleEvalCall(ExpressionT expression, Scope* scope) { |
853 if (Traits::IsIdentifier(expression) && | 859 if (Traits::IsIdentifier(expression) && |
854 Traits::IsEval(Traits::AsIdentifier(expression))) { | 860 Traits::IsEval(Traits::AsIdentifier(expression))) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 this_location_(Scanner::Location::invalid()), | 967 this_location_(Scanner::Location::invalid()), |
962 return_location_(Scanner::Location::invalid()), | 968 return_location_(Scanner::Location::invalid()), |
963 super_location_(Scanner::Location::invalid()), | 969 super_location_(Scanner::Location::invalid()), |
964 kind_(kind), | 970 kind_(kind), |
965 generator_object_variable_(NULL), | 971 generator_object_variable_(NULL), |
966 function_state_stack_(function_state_stack), | 972 function_state_stack_(function_state_stack), |
967 outer_function_state_(*function_state_stack), | 973 outer_function_state_(*function_state_stack), |
968 scope_stack_(scope_stack), | 974 scope_stack_(scope_stack), |
969 outer_scope_(*scope_stack), | 975 outer_scope_(*scope_stack), |
970 collect_expressions_in_tail_position_(true), | 976 collect_expressions_in_tail_position_(true), |
| 977 non_patterns_to_rewrite_(0, scope->zone()), |
971 factory_(factory) { | 978 factory_(factory) { |
972 *scope_stack_ = scope; | 979 *scope_stack_ = scope; |
973 *function_state_stack = this; | 980 *function_state_stack = this; |
974 } | 981 } |
975 | 982 |
976 | 983 |
977 template <class Traits> | 984 template <class Traits> |
978 ParserBase<Traits>::FunctionState::~FunctionState() { | 985 ParserBase<Traits>::FunctionState::~FunctionState() { |
979 *scope_stack_ = outer_scope_; | 986 *scope_stack_ = outer_scope_; |
980 *function_state_stack_ = outer_function_state_; | 987 *function_state_stack_ = outer_function_state_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 MessageTemplate::Template message) { | 1054 MessageTemplate::Template message) { |
1048 const char* arg; | 1055 const char* arg; |
1049 GetUnexpectedTokenMessage(token, &message, &arg); | 1056 GetUnexpectedTokenMessage(token, &message, &arg); |
1050 Traits::ReportMessageAt(source_location, message, arg); | 1057 Traits::ReportMessageAt(source_location, message, arg); |
1051 } | 1058 } |
1052 | 1059 |
1053 | 1060 |
1054 template <class Traits> | 1061 template <class Traits> |
1055 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( | 1062 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( |
1056 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { | 1063 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { |
1057 ExpressionClassifier classifier; | 1064 ExpressionClassifier classifier(this); |
1058 auto result = ParseAndClassifyIdentifier(&classifier, ok); | 1065 auto result = ParseAndClassifyIdentifier(&classifier, ok); |
1059 if (!*ok) return Traits::EmptyIdentifier(); | 1066 if (!*ok) return Traits::EmptyIdentifier(); |
1060 | 1067 |
1061 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { | 1068 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { |
1062 ValidateAssignmentPattern(&classifier, ok); | 1069 ValidateAssignmentPattern(&classifier, ok); |
1063 if (!*ok) return Traits::EmptyIdentifier(); | 1070 if (!*ok) return Traits::EmptyIdentifier(); |
1064 ValidateBindingPattern(&classifier, ok); | 1071 ValidateBindingPattern(&classifier, ok); |
1065 if (!*ok) return Traits::EmptyIdentifier(); | 1072 if (!*ok) return Traits::EmptyIdentifier(); |
1066 } | 1073 } |
1067 | 1074 |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 | 1425 |
1419 ReportUnexpectedToken(Next()); | 1426 ReportUnexpectedToken(Next()); |
1420 *ok = false; | 1427 *ok = false; |
1421 return this->EmptyExpression(); | 1428 return this->EmptyExpression(); |
1422 } | 1429 } |
1423 | 1430 |
1424 | 1431 |
1425 template <class Traits> | 1432 template <class Traits> |
1426 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1433 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1427 bool accept_IN, bool* ok) { | 1434 bool accept_IN, bool* ok) { |
1428 ExpressionClassifier classifier; | 1435 ExpressionClassifier classifier(this); |
1429 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); | 1436 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); |
1430 result = Traits::RewriteNonPattern(result, &classifier, CHECK_OK); | 1437 Traits::RewriteNonPattern(&classifier, CHECK_OK); |
1431 return result; | 1438 return result; |
1432 } | 1439 } |
1433 | 1440 |
1434 | 1441 |
1435 template <class Traits> | 1442 template <class Traits> |
1436 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1443 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1437 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 1444 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
1438 // Expression :: | 1445 // Expression :: |
1439 // AssignmentExpression | 1446 // AssignmentExpression |
1440 // Expression ',' AssignmentExpression | 1447 // Expression ',' AssignmentExpression |
1441 | 1448 |
1442 ExpressionClassifier binding_classifier; | 1449 ExpressionClassifier binding_classifier(this); |
1443 ExpressionT result = | 1450 ExpressionT result = |
1444 this->ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK); | 1451 this->ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK); |
1445 classifier->Accumulate(binding_classifier, | 1452 classifier->Accumulate(&binding_classifier, |
1446 ExpressionClassifier::AllProductions); | 1453 ExpressionClassifier::AllProductions); |
1447 bool is_simple_parameter_list = this->IsIdentifier(result); | 1454 bool is_simple_parameter_list = this->IsIdentifier(result); |
1448 bool seen_rest = false; | 1455 bool seen_rest = false; |
1449 while (peek() == Token::COMMA) { | 1456 while (peek() == Token::COMMA) { |
1450 if (seen_rest) { | 1457 if (seen_rest) { |
1451 // At this point the production can't possibly be valid, but we don't know | 1458 // At this point the production can't possibly be valid, but we don't know |
1452 // which error to signal. | 1459 // which error to signal. |
1453 classifier->RecordArrowFormalParametersError( | 1460 classifier->RecordArrowFormalParametersError( |
1454 scanner()->peek_location(), MessageTemplate::kParamAfterRest); | 1461 scanner()->peek_location(), MessageTemplate::kParamAfterRest); |
1455 } | 1462 } |
1456 Consume(Token::COMMA); | 1463 Consume(Token::COMMA); |
1457 bool is_rest = false; | 1464 bool is_rest = false; |
1458 if (peek() == Token::ELLIPSIS) { | 1465 if (peek() == Token::ELLIPSIS) { |
1459 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only | 1466 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only |
1460 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a | 1467 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a |
1461 // valid expression or binding pattern. | 1468 // valid expression or binding pattern. |
1462 ExpressionUnexpectedToken(classifier); | 1469 ExpressionUnexpectedToken(classifier); |
1463 BindingPatternUnexpectedToken(classifier); | 1470 BindingPatternUnexpectedToken(classifier); |
1464 Consume(Token::ELLIPSIS); | 1471 Consume(Token::ELLIPSIS); |
1465 seen_rest = is_rest = true; | 1472 seen_rest = is_rest = true; |
1466 } | 1473 } |
1467 int pos = position(), expr_pos = peek_position(); | 1474 int pos = position(), expr_pos = peek_position(); |
1468 ExpressionT right = this->ParseAssignmentExpression( | 1475 ExpressionT right = this->ParseAssignmentExpression( |
1469 accept_IN, &binding_classifier, CHECK_OK); | 1476 accept_IN, &binding_classifier, CHECK_OK); |
| 1477 classifier->Accumulate(&binding_classifier, |
| 1478 ExpressionClassifier::AllProductions); |
1470 if (is_rest) { | 1479 if (is_rest) { |
1471 if (!this->IsIdentifier(right) && !IsValidPattern(right)) { | 1480 if (!this->IsIdentifier(right) && !IsValidPattern(right)) { |
1472 classifier->RecordArrowFormalParametersError( | 1481 classifier->RecordArrowFormalParametersError( |
1473 Scanner::Location(pos, scanner()->location().end_pos), | 1482 Scanner::Location(pos, scanner()->location().end_pos), |
1474 MessageTemplate::kInvalidRestParameter); | 1483 MessageTemplate::kInvalidRestParameter); |
1475 } | 1484 } |
1476 right = factory()->NewSpread(right, pos, expr_pos); | 1485 right = factory()->NewSpread(right, pos, expr_pos); |
1477 } | 1486 } |
1478 is_simple_parameter_list = | 1487 is_simple_parameter_list = |
1479 is_simple_parameter_list && this->IsIdentifier(right); | 1488 is_simple_parameter_list && this->IsIdentifier(right); |
1480 classifier->Accumulate(binding_classifier, | |
1481 ExpressionClassifier::AllProductions); | |
1482 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); | 1489 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); |
1483 } | 1490 } |
1484 if (!is_simple_parameter_list || seen_rest) { | 1491 if (!is_simple_parameter_list || seen_rest) { |
1485 classifier->RecordNonSimpleParameter(); | 1492 classifier->RecordNonSimpleParameter(); |
1486 } | 1493 } |
1487 | 1494 |
1488 return result; | 1495 return result; |
1489 } | 1496 } |
1490 | 1497 |
1491 | 1498 |
(...skipping 23 matching lines...) Expand all Loading... |
1515 Consume(Token::ELLIPSIS); | 1522 Consume(Token::ELLIPSIS); |
1516 int expr_pos = peek_position(); | 1523 int expr_pos = peek_position(); |
1517 ExpressionT argument = | 1524 ExpressionT argument = |
1518 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 1525 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
1519 elem = factory()->NewSpread(argument, start_pos, expr_pos); | 1526 elem = factory()->NewSpread(argument, start_pos, expr_pos); |
1520 | 1527 |
1521 if (first_spread_index < 0) { | 1528 if (first_spread_index < 0) { |
1522 first_spread_index = values->length(); | 1529 first_spread_index = values->length(); |
1523 } | 1530 } |
1524 | 1531 |
1525 if (IsAssignmentExpression(argument)) { | 1532 if (argument->IsAssignment()) { |
1526 classifier->RecordPatternError( | 1533 classifier->RecordPatternError( |
1527 Scanner::Location(start_pos, scanner()->location().end_pos), | 1534 Scanner::Location(start_pos, scanner()->location().end_pos), |
1528 MessageTemplate::kInvalidDestructuringTarget); | 1535 MessageTemplate::kInvalidDestructuringTarget); |
1529 } else { | 1536 } else { |
1530 CheckDestructuringElement(argument, classifier, start_pos, | 1537 CheckDestructuringElement(argument, classifier, start_pos, |
1531 scanner()->location().end_pos); | 1538 scanner()->location().end_pos); |
1532 } | 1539 } |
1533 | 1540 |
1534 if (peek() == Token::COMMA) { | 1541 if (peek() == Token::COMMA) { |
1535 classifier->RecordPatternError( | 1542 classifier->RecordPatternError( |
1536 Scanner::Location(start_pos, scanner()->location().end_pos), | 1543 Scanner::Location(start_pos, scanner()->location().end_pos), |
1537 MessageTemplate::kElementAfterRest); | 1544 MessageTemplate::kElementAfterRest); |
1538 } | 1545 } |
1539 } else { | 1546 } else { |
1540 int beg_pos = peek_position(); | 1547 int beg_pos = peek_position(); |
1541 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 1548 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
1542 CheckDestructuringElement(elem, classifier, beg_pos, | 1549 CheckDestructuringElement(elem, classifier, beg_pos, |
1543 scanner()->location().end_pos); | 1550 scanner()->location().end_pos); |
1544 } | 1551 } |
1545 values->Add(elem, zone_); | 1552 values->Add(elem, zone_); |
1546 if (peek() != Token::RBRACK) { | 1553 if (peek() != Token::RBRACK) { |
1547 Expect(Token::COMMA, CHECK_OK); | 1554 Expect(Token::COMMA, CHECK_OK); |
1548 } | 1555 } |
1549 } | 1556 } |
1550 Expect(Token::RBRACK, CHECK_OK); | 1557 Expect(Token::RBRACK, CHECK_OK); |
1551 | 1558 |
1552 // Update the scope information before the pre-parsing bailout. | 1559 // Update the scope information before the pre-parsing bailout. |
1553 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1560 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1554 | 1561 |
1555 return factory()->NewArrayLiteral(values, first_spread_index, literal_index, | 1562 ExpressionT result = |
1556 is_strong(language_mode()), pos); | 1563 factory()->NewArrayLiteral(values, first_spread_index, literal_index, |
| 1564 is_strong(language_mode()), pos); |
| 1565 if (first_spread_index >= 0) { |
| 1566 result = factory()->NewRewritableExpression(result); |
| 1567 Traits::QueueNonPatternForRewriting(result); |
| 1568 } |
| 1569 return result; |
1557 } | 1570 } |
1558 | 1571 |
1559 | 1572 |
1560 template <class Traits> | 1573 template <class Traits> |
1561 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( | 1574 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( |
1562 IdentifierT* name, bool* is_get, bool* is_set, bool* is_computed_name, | 1575 IdentifierT* name, bool* is_get, bool* is_set, bool* is_computed_name, |
1563 ExpressionClassifier* classifier, bool* ok) { | 1576 ExpressionClassifier* classifier, bool* ok) { |
1564 Token::Value token = peek(); | 1577 Token::Value token = peek(); |
1565 int pos = peek_position(); | 1578 int pos = peek_position(); |
1566 | 1579 |
(...skipping 18 matching lines...) Expand all Loading... |
1585 break; | 1598 break; |
1586 | 1599 |
1587 case Token::NUMBER: | 1600 case Token::NUMBER: |
1588 Consume(Token::NUMBER); | 1601 Consume(Token::NUMBER); |
1589 *name = this->GetNumberAsSymbol(scanner()); | 1602 *name = this->GetNumberAsSymbol(scanner()); |
1590 break; | 1603 break; |
1591 | 1604 |
1592 case Token::LBRACK: { | 1605 case Token::LBRACK: { |
1593 *is_computed_name = true; | 1606 *is_computed_name = true; |
1594 Consume(Token::LBRACK); | 1607 Consume(Token::LBRACK); |
1595 ExpressionClassifier computed_name_classifier; | 1608 ExpressionClassifier computed_name_classifier(this); |
1596 ExpressionT expression = | 1609 ExpressionT expression = |
1597 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); | 1610 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); |
1598 expression = Traits::RewriteNonPattern( | 1611 Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK); |
1599 expression, &computed_name_classifier, CHECK_OK); | 1612 classifier->Accumulate(&computed_name_classifier, |
1600 classifier->Accumulate(computed_name_classifier, | |
1601 ExpressionClassifier::ExpressionProductions); | 1613 ExpressionClassifier::ExpressionProductions); |
1602 Expect(Token::RBRACK, CHECK_OK); | 1614 Expect(Token::RBRACK, CHECK_OK); |
1603 return expression; | 1615 return expression; |
1604 } | 1616 } |
1605 | 1617 |
1606 default: | 1618 default: |
1607 *name = ParseIdentifierName(CHECK_OK); | 1619 *name = ParseIdentifierName(CHECK_OK); |
1608 scanner()->IsGetOrSet(is_get, is_set); | 1620 scanner()->IsGetOrSet(is_get, is_set); |
1609 break; | 1621 break; |
1610 } | 1622 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 classifier->RecordLetPatternError( | 1690 classifier->RecordLetPatternError( |
1679 scanner()->location(), MessageTemplate::kLetInLexicalBinding); | 1691 scanner()->location(), MessageTemplate::kLetInLexicalBinding); |
1680 } | 1692 } |
1681 | 1693 |
1682 ExpressionT lhs = this->ExpressionFromIdentifier( | 1694 ExpressionT lhs = this->ExpressionFromIdentifier( |
1683 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1695 *name, next_beg_pos, next_end_pos, scope_, factory()); |
1684 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1696 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
1685 | 1697 |
1686 if (peek() == Token::ASSIGN) { | 1698 if (peek() == Token::ASSIGN) { |
1687 Consume(Token::ASSIGN); | 1699 Consume(Token::ASSIGN); |
1688 ExpressionClassifier rhs_classifier; | 1700 ExpressionClassifier rhs_classifier(this); |
1689 ExpressionT rhs = this->ParseAssignmentExpression( | 1701 ExpressionT rhs = this->ParseAssignmentExpression( |
1690 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1702 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1691 rhs = Traits::RewriteNonPattern( | 1703 Traits::RewriteNonPattern(&rhs_classifier, |
1692 rhs, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1704 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1693 classifier->Accumulate(rhs_classifier, | 1705 classifier->Accumulate(&rhs_classifier, |
1694 ExpressionClassifier::ExpressionProductions); | 1706 ExpressionClassifier::ExpressionProductions); |
1695 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 1707 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
1696 RelocInfo::kNoPosition); | 1708 RelocInfo::kNoPosition); |
1697 classifier->RecordCoverInitializedNameError( | 1709 classifier->RecordCoverInitializedNameError( |
1698 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1710 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
1699 MessageTemplate::kInvalidCoverInitializedName); | 1711 MessageTemplate::kInvalidCoverInitializedName); |
1700 | 1712 |
1701 if (allow_harmony_function_name()) { | 1713 if (allow_harmony_function_name()) { |
1702 Traits::SetFunctionNameFromIdentifierRef(rhs, lhs); | 1714 Traits::SetFunctionNameFromIdentifierRef(rhs, lhs); |
1703 } | 1715 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 is_static, *is_computed_name); | 1757 is_static, *is_computed_name); |
1746 } | 1758 } |
1747 | 1759 |
1748 if (in_class && name_token == Token::STATIC && !is_static) { | 1760 if (in_class && name_token == Token::STATIC && !is_static) { |
1749 // ClassElement (static) | 1761 // ClassElement (static) |
1750 // 'static' MethodDefinition | 1762 // 'static' MethodDefinition |
1751 *name = this->EmptyIdentifier(); | 1763 *name = this->EmptyIdentifier(); |
1752 ObjectLiteralPropertyT property = ParsePropertyDefinition( | 1764 ObjectLiteralPropertyT property = ParsePropertyDefinition( |
1753 checker, true, has_extends, true, is_computed_name, nullptr, classifier, | 1765 checker, true, has_extends, true, is_computed_name, nullptr, classifier, |
1754 name, ok); | 1766 name, ok); |
1755 property = Traits::RewriteNonPatternObjectLiteralProperty(property, | 1767 Traits::RewriteNonPattern(classifier, ok); |
1756 classifier, ok); | |
1757 return property; | 1768 return property; |
1758 } | 1769 } |
1759 | 1770 |
1760 if (is_get || is_set) { | 1771 if (is_get || is_set) { |
1761 // MethodDefinition (Accessors) | 1772 // MethodDefinition (Accessors) |
1762 // get PropertyName '(' ')' '{' FunctionBody '}' | 1773 // get PropertyName '(' ')' '{' FunctionBody '}' |
1763 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' | 1774 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' |
1764 *name = this->EmptyIdentifier(); | 1775 *name = this->EmptyIdentifier(); |
1765 bool dont_care = false; | 1776 bool dont_care = false; |
1766 name_token = peek(); | 1777 name_token = peek(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 bool done = (peek() == Token::RPAREN); | 1896 bool done = (peek() == Token::RPAREN); |
1886 bool was_unspread = false; | 1897 bool was_unspread = false; |
1887 int unspread_sequences_count = 0; | 1898 int unspread_sequences_count = 0; |
1888 while (!done) { | 1899 while (!done) { |
1889 int start_pos = peek_position(); | 1900 int start_pos = peek_position(); |
1890 bool is_spread = Check(Token::ELLIPSIS); | 1901 bool is_spread = Check(Token::ELLIPSIS); |
1891 int expr_pos = peek_position(); | 1902 int expr_pos = peek_position(); |
1892 | 1903 |
1893 ExpressionT argument = this->ParseAssignmentExpression( | 1904 ExpressionT argument = this->ParseAssignmentExpression( |
1894 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); | 1905 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
1895 argument = Traits::RewriteNonPattern(argument, classifier, | 1906 Traits::RewriteNonPattern(classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
1896 CHECK_OK_CUSTOM(NullExpressionList)); | |
1897 if (is_spread) { | 1907 if (is_spread) { |
1898 if (!spread_arg.IsValid()) { | 1908 if (!spread_arg.IsValid()) { |
1899 spread_arg.beg_pos = start_pos; | 1909 spread_arg.beg_pos = start_pos; |
1900 spread_arg.end_pos = peek_position(); | 1910 spread_arg.end_pos = peek_position(); |
1901 } | 1911 } |
1902 argument = factory()->NewSpread(argument, start_pos, expr_pos); | 1912 argument = factory()->NewSpread(argument, start_pos, expr_pos); |
1903 } | 1913 } |
1904 result->Add(argument, zone_); | 1914 result->Add(argument, zone_); |
1905 | 1915 |
1906 // unspread_sequences_count is the number of sequences of parameters which | 1916 // unspread_sequences_count is the number of sequences of parameters which |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1953 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 1963 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
1954 bool is_destructuring_assignment = false; | 1964 bool is_destructuring_assignment = false; |
1955 int lhs_beg_pos = peek_position(); | 1965 int lhs_beg_pos = peek_position(); |
1956 | 1966 |
1957 if (peek() == Token::YIELD && is_generator()) { | 1967 if (peek() == Token::YIELD && is_generator()) { |
1958 return this->ParseYieldExpression(classifier, ok); | 1968 return this->ParseYieldExpression(classifier, ok); |
1959 } | 1969 } |
1960 | 1970 |
1961 FuncNameInferrer::State fni_state(fni_); | 1971 FuncNameInferrer::State fni_state(fni_); |
1962 ParserBase<Traits>::Checkpoint checkpoint(this); | 1972 ParserBase<Traits>::Checkpoint checkpoint(this); |
1963 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); | 1973 ExpressionClassifier arrow_formals_classifier(this, |
| 1974 classifier->duplicate_finder()); |
1964 bool parenthesized_formals = peek() == Token::LPAREN; | 1975 bool parenthesized_formals = peek() == Token::LPAREN; |
1965 if (!parenthesized_formals) { | 1976 if (!parenthesized_formals) { |
1966 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 1977 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
1967 } | 1978 } |
1968 ExpressionT expression = this->ParseConditionalExpression( | 1979 ExpressionT expression = this->ParseConditionalExpression( |
1969 accept_IN, &arrow_formals_classifier, CHECK_OK); | 1980 accept_IN, &arrow_formals_classifier, CHECK_OK); |
1970 if (peek() == Token::ARROW) { | 1981 if (peek() == Token::ARROW) { |
1971 classifier->RecordPatternError(scanner()->peek_location(), | 1982 classifier->RecordPatternError(scanner()->peek_location(), |
1972 MessageTemplate::kUnexpectedToken, | 1983 MessageTemplate::kUnexpectedToken, |
1973 Token::String(Token::ARROW)); | 1984 Token::String(Token::ARROW)); |
(...skipping 29 matching lines...) Expand all Loading... |
2003 | 2014 |
2004 return expression; | 2015 return expression; |
2005 } | 2016 } |
2006 | 2017 |
2007 if (this->IsValidReferenceExpression(expression)) { | 2018 if (this->IsValidReferenceExpression(expression)) { |
2008 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2019 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
2009 } | 2020 } |
2010 | 2021 |
2011 // "expression" was not itself an arrow function parameter list, but it might | 2022 // "expression" was not itself an arrow function parameter list, but it might |
2012 // form part of one. Propagate speculative formal parameter error locations. | 2023 // form part of one. Propagate speculative formal parameter error locations. |
| 2024 // Do not merge pending non-pattern expressions yet! |
2013 classifier->Accumulate( | 2025 classifier->Accumulate( |
2014 arrow_formals_classifier, | 2026 &arrow_formals_classifier, |
2015 ExpressionClassifier::StandardProductions | | 2027 ExpressionClassifier::StandardProductions | |
2016 ExpressionClassifier::FormalParametersProductions | | 2028 ExpressionClassifier::FormalParametersProductions | |
2017 ExpressionClassifier::CoverInitializedNameProduction); | 2029 ExpressionClassifier::CoverInitializedNameProduction, |
| 2030 false); |
2018 | 2031 |
2019 if (!Token::IsAssignmentOp(peek())) { | 2032 if (!Token::IsAssignmentOp(peek())) { |
2020 // Parsed conditional expression only (no assignment). | 2033 // Parsed conditional expression only (no assignment). |
| 2034 // Now pending non-pattern expressions must be merged. |
| 2035 classifier->MergeNonPatterns(&arrow_formals_classifier); |
2021 return expression; | 2036 return expression; |
2022 } | 2037 } |
2023 | 2038 |
| 2039 // Now pending non-pattern expressions must be discarded. |
| 2040 arrow_formals_classifier.Discard(); |
| 2041 |
2024 if (!(allow_harmony_destructuring_bind() || | 2042 if (!(allow_harmony_destructuring_bind() || |
2025 allow_harmony_default_parameters())) { | 2043 allow_harmony_default_parameters())) { |
2026 BindingPatternUnexpectedToken(classifier); | 2044 BindingPatternUnexpectedToken(classifier); |
2027 } | 2045 } |
2028 | 2046 |
2029 if (allow_harmony_destructuring_assignment() && IsValidPattern(expression) && | 2047 if (allow_harmony_destructuring_assignment() && IsValidPattern(expression) && |
2030 peek() == Token::ASSIGN) { | 2048 peek() == Token::ASSIGN) { |
2031 classifier->ForgiveCoverInitializedNameError(); | 2049 classifier->ForgiveCoverInitializedNameError(); |
2032 ValidateAssignmentPattern(classifier, CHECK_OK); | 2050 ValidateAssignmentPattern(classifier, CHECK_OK); |
2033 is_destructuring_assignment = true; | 2051 is_destructuring_assignment = true; |
(...skipping 13 matching lines...) Expand all Loading... |
2047 expression = this->MarkExpressionAsAssigned(expression); | 2065 expression = this->MarkExpressionAsAssigned(expression); |
2048 | 2066 |
2049 Token::Value op = Next(); // Get assignment operator. | 2067 Token::Value op = Next(); // Get assignment operator. |
2050 if (op != Token::ASSIGN) { | 2068 if (op != Token::ASSIGN) { |
2051 classifier->RecordPatternError(scanner()->location(), | 2069 classifier->RecordPatternError(scanner()->location(), |
2052 MessageTemplate::kUnexpectedToken, | 2070 MessageTemplate::kUnexpectedToken, |
2053 Token::String(op)); | 2071 Token::String(op)); |
2054 } | 2072 } |
2055 int pos = position(); | 2073 int pos = position(); |
2056 | 2074 |
2057 ExpressionClassifier rhs_classifier; | 2075 ExpressionClassifier rhs_classifier(this); |
2058 | 2076 |
2059 ExpressionT right = | 2077 ExpressionT right = |
2060 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); | 2078 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); |
2061 right = Traits::RewriteNonPattern(right, &rhs_classifier, CHECK_OK); | 2079 Traits::RewriteNonPattern(&rhs_classifier, CHECK_OK); |
2062 classifier->Accumulate( | 2080 classifier->Accumulate( |
2063 rhs_classifier, ExpressionClassifier::ExpressionProductions | | 2081 &rhs_classifier, ExpressionClassifier::ExpressionProductions | |
2064 ExpressionClassifier::CoverInitializedNameProduction); | 2082 ExpressionClassifier::CoverInitializedNameProduction); |
2065 | 2083 |
2066 // TODO(1231235): We try to estimate the set of properties set by | 2084 // TODO(1231235): We try to estimate the set of properties set by |
2067 // constructors. We define a new property whenever there is an | 2085 // constructors. We define a new property whenever there is an |
2068 // assignment to a property of 'this'. We should probably only add | 2086 // assignment to a property of 'this'. We should probably only add |
2069 // properties if we haven't seen them before. Otherwise we'll | 2087 // properties if we haven't seen them before. Otherwise we'll |
2070 // probably overestimate the number of properties. | 2088 // probably overestimate the number of properties. |
2071 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { | 2089 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { |
2072 function_state_->AddProperty(); | 2090 function_state_->AddProperty(); |
2073 } | 2091 } |
2074 | 2092 |
(...skipping 11 matching lines...) Expand all Loading... |
2086 } | 2104 } |
2087 } | 2105 } |
2088 | 2106 |
2089 if (op == Token::ASSIGN && allow_harmony_function_name()) { | 2107 if (op == Token::ASSIGN && allow_harmony_function_name()) { |
2090 Traits::SetFunctionNameFromIdentifierRef(right, expression); | 2108 Traits::SetFunctionNameFromIdentifierRef(right, expression); |
2091 } | 2109 } |
2092 | 2110 |
2093 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); | 2111 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); |
2094 | 2112 |
2095 if (is_destructuring_assignment) { | 2113 if (is_destructuring_assignment) { |
2096 result = factory()->NewRewritableAssignmentExpression(result); | 2114 result = factory()->NewRewritableExpression(result); |
2097 Traits::QueueDestructuringAssignmentForRewriting(result); | 2115 Traits::QueueDestructuringAssignmentForRewriting(result); |
2098 } | 2116 } |
2099 | 2117 |
2100 return result; | 2118 return result; |
2101 } | 2119 } |
2102 | 2120 |
2103 template <class Traits> | 2121 template <class Traits> |
2104 typename ParserBase<Traits>::ExpressionT | 2122 typename ParserBase<Traits>::ExpressionT |
2105 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, | 2123 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, |
2106 bool* ok) { | 2124 bool* ok) { |
(...skipping 21 matching lines...) Expand all Loading... |
2128 // The above set of tokens is the complete set of tokens that can appear | 2146 // The above set of tokens is the complete set of tokens that can appear |
2129 // after an AssignmentExpression, and none of them can start an | 2147 // after an AssignmentExpression, and none of them can start an |
2130 // AssignmentExpression. This allows us to avoid looking for an RHS for | 2148 // AssignmentExpression. This allows us to avoid looking for an RHS for |
2131 // a Yield::kSuspend operation, given only one look-ahead token. | 2149 // a Yield::kSuspend operation, given only one look-ahead token. |
2132 if (kind == Yield::kSuspend) | 2150 if (kind == Yield::kSuspend) |
2133 break; | 2151 break; |
2134 DCHECK_EQ(Yield::kDelegating, kind); | 2152 DCHECK_EQ(Yield::kDelegating, kind); |
2135 // Delegating yields require an RHS; fall through. | 2153 // Delegating yields require an RHS; fall through. |
2136 default: | 2154 default: |
2137 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); | 2155 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); |
2138 expression = | 2156 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2139 Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | |
2140 break; | 2157 break; |
2141 } | 2158 } |
2142 } | 2159 } |
2143 if (kind == Yield::kDelegating) { | 2160 if (kind == Yield::kDelegating) { |
2144 return Traits::RewriteYieldStar(generator_object, expression, pos); | 2161 return Traits::RewriteYieldStar(generator_object, expression, pos); |
2145 } | 2162 } |
2146 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2163 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
2147 // TODO(verwaest): Come up with a better solution. | 2164 // TODO(verwaest): Come up with a better solution. |
2148 typename Traits::Type::YieldExpression yield = | 2165 typename Traits::Type::YieldExpression yield = |
2149 factory()->NewYield(generator_object, expression, kind, pos); | 2166 factory()->NewYield(generator_object, expression, kind, pos); |
2150 return yield; | 2167 return yield; |
2151 } | 2168 } |
2152 | 2169 |
2153 | 2170 |
2154 // Precedence = 3 | 2171 // Precedence = 3 |
2155 template <class Traits> | 2172 template <class Traits> |
2156 typename ParserBase<Traits>::ExpressionT | 2173 typename ParserBase<Traits>::ExpressionT |
2157 ParserBase<Traits>::ParseConditionalExpression(bool accept_IN, | 2174 ParserBase<Traits>::ParseConditionalExpression(bool accept_IN, |
2158 ExpressionClassifier* classifier, | 2175 ExpressionClassifier* classifier, |
2159 bool* ok) { | 2176 bool* ok) { |
2160 // ConditionalExpression :: | 2177 // ConditionalExpression :: |
2161 // LogicalOrExpression | 2178 // LogicalOrExpression |
2162 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | 2179 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
2163 | 2180 |
2164 int pos = peek_position(); | 2181 int pos = peek_position(); |
2165 // We start using the binary expression parser for prec >= 4 only! | 2182 // We start using the binary expression parser for prec >= 4 only! |
2166 ExpressionT expression = | 2183 ExpressionT expression = |
2167 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); | 2184 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); |
2168 if (peek() != Token::CONDITIONAL) return expression; | 2185 if (peek() != Token::CONDITIONAL) return expression; |
2169 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | 2186 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2170 ArrowFormalParametersUnexpectedToken(classifier); | 2187 ArrowFormalParametersUnexpectedToken(classifier); |
2171 BindingPatternUnexpectedToken(classifier); | 2188 BindingPatternUnexpectedToken(classifier); |
2172 Consume(Token::CONDITIONAL); | 2189 Consume(Token::CONDITIONAL); |
2173 // In parsing the first assignment expression in conditional | 2190 // In parsing the first assignment expression in conditional |
2174 // expressions we always accept the 'in' keyword; see ECMA-262, | 2191 // expressions we always accept the 'in' keyword; see ECMA-262, |
2175 // section 11.12, page 58. | 2192 // section 11.12, page 58. |
2176 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); | 2193 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); |
2177 left = Traits::RewriteNonPattern(left, classifier, CHECK_OK); | 2194 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2178 Expect(Token::COLON, CHECK_OK); | 2195 Expect(Token::COLON, CHECK_OK); |
2179 ExpressionT right = | 2196 ExpressionT right = |
2180 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2197 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
2181 right = Traits::RewriteNonPattern(right, classifier, CHECK_OK); | 2198 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2182 return factory()->NewConditional(expression, left, right, pos); | 2199 return factory()->NewConditional(expression, left, right, pos); |
2183 } | 2200 } |
2184 | 2201 |
2185 | 2202 |
2186 // Precedence >= 4 | 2203 // Precedence >= 4 |
2187 template <class Traits> | 2204 template <class Traits> |
2188 typename ParserBase<Traits>::ExpressionT | 2205 typename ParserBase<Traits>::ExpressionT |
2189 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, | 2206 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, |
2190 ExpressionClassifier* classifier, | 2207 ExpressionClassifier* classifier, |
2191 bool* ok) { | 2208 bool* ok) { |
2192 DCHECK(prec >= 4); | 2209 DCHECK(prec >= 4); |
2193 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 2210 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
2194 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2211 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
2195 // prec1 >= 4 | 2212 // prec1 >= 4 |
2196 while (Precedence(peek(), accept_IN) == prec1) { | 2213 while (Precedence(peek(), accept_IN) == prec1) { |
2197 x = Traits::RewriteNonPattern(x, classifier, CHECK_OK); | 2214 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2198 BindingPatternUnexpectedToken(classifier); | 2215 BindingPatternUnexpectedToken(classifier); |
2199 ArrowFormalParametersUnexpectedToken(classifier); | 2216 ArrowFormalParametersUnexpectedToken(classifier); |
2200 Token::Value op = Next(); | 2217 Token::Value op = Next(); |
2201 Scanner::Location op_location = scanner()->location(); | 2218 Scanner::Location op_location = scanner()->location(); |
2202 int pos = position(); | 2219 int pos = position(); |
2203 ExpressionT y = | 2220 ExpressionT y = |
2204 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); | 2221 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); |
2205 y = Traits::RewriteNonPattern(y, classifier, CHECK_OK); | 2222 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2206 | 2223 |
2207 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 2224 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
2208 factory())) { | 2225 factory())) { |
2209 continue; | 2226 continue; |
2210 } | 2227 } |
2211 | 2228 |
2212 // For now we distinguish between comparisons and other binary | 2229 // For now we distinguish between comparisons and other binary |
2213 // operations. (We could combine the two and get rid of this | 2230 // operations. (We could combine the two and get rid of this |
2214 // code and AST node eventually.) | 2231 // code and AST node eventually.) |
2215 if (Token::IsCompareOp(op)) { | 2232 if (Token::IsCompareOp(op)) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2258 // '!' UnaryExpression | 2275 // '!' UnaryExpression |
2259 | 2276 |
2260 Token::Value op = peek(); | 2277 Token::Value op = peek(); |
2261 if (Token::IsUnaryOp(op)) { | 2278 if (Token::IsUnaryOp(op)) { |
2262 BindingPatternUnexpectedToken(classifier); | 2279 BindingPatternUnexpectedToken(classifier); |
2263 ArrowFormalParametersUnexpectedToken(classifier); | 2280 ArrowFormalParametersUnexpectedToken(classifier); |
2264 | 2281 |
2265 op = Next(); | 2282 op = Next(); |
2266 int pos = position(); | 2283 int pos = position(); |
2267 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); | 2284 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
2268 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | 2285 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2269 | 2286 |
2270 if (op == Token::DELETE && is_strict(language_mode())) { | 2287 if (op == Token::DELETE && is_strict(language_mode())) { |
2271 if (is_strong(language_mode())) { | 2288 if (is_strong(language_mode())) { |
2272 ReportMessage(MessageTemplate::kStrongDelete); | 2289 ReportMessage(MessageTemplate::kStrongDelete); |
2273 *ok = false; | 2290 *ok = false; |
2274 return this->EmptyExpression(); | 2291 return this->EmptyExpression(); |
2275 } else if (this->IsIdentifier(expression)) { | 2292 } else if (this->IsIdentifier(expression)) { |
2276 // "delete identifier" is a syntax error in strict mode. | 2293 // "delete identifier" is a syntax error in strict mode. |
2277 ReportMessage(MessageTemplate::kStrictDelete); | 2294 ReportMessage(MessageTemplate::kStrictDelete); |
2278 *ok = false; | 2295 *ok = false; |
2279 return this->EmptyExpression(); | 2296 return this->EmptyExpression(); |
2280 } | 2297 } |
2281 } | 2298 } |
2282 | 2299 |
2283 // Allow Traits do rewrite the expression. | 2300 // Allow Traits do rewrite the expression. |
2284 return this->BuildUnaryExpression(expression, op, pos, factory()); | 2301 return this->BuildUnaryExpression(expression, op, pos, factory()); |
2285 } else if (Token::IsCountOp(op)) { | 2302 } else if (Token::IsCountOp(op)) { |
2286 BindingPatternUnexpectedToken(classifier); | 2303 BindingPatternUnexpectedToken(classifier); |
2287 ArrowFormalParametersUnexpectedToken(classifier); | 2304 ArrowFormalParametersUnexpectedToken(classifier); |
2288 op = Next(); | 2305 op = Next(); |
2289 int beg_pos = peek_position(); | 2306 int beg_pos = peek_position(); |
2290 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 2307 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
2291 expression = this->CheckAndRewriteReferenceExpression( | 2308 expression = this->CheckAndRewriteReferenceExpression( |
2292 expression, beg_pos, scanner()->location().end_pos, | 2309 expression, beg_pos, scanner()->location().end_pos, |
2293 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2310 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
2294 this->MarkExpressionAsAssigned(expression); | 2311 this->MarkExpressionAsAssigned(expression); |
2295 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | 2312 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2296 | 2313 |
2297 return factory()->NewCountOperation(op, | 2314 return factory()->NewCountOperation(op, |
2298 true /* prefix */, | 2315 true /* prefix */, |
2299 expression, | 2316 expression, |
2300 position()); | 2317 position()); |
2301 | 2318 |
2302 } else { | 2319 } else { |
2303 return this->ParsePostfixExpression(classifier, ok); | 2320 return this->ParsePostfixExpression(classifier, ok); |
2304 } | 2321 } |
2305 } | 2322 } |
(...skipping 11 matching lines...) Expand all Loading... |
2317 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 2334 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
2318 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 2335 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
2319 Token::IsCountOp(peek())) { | 2336 Token::IsCountOp(peek())) { |
2320 BindingPatternUnexpectedToken(classifier); | 2337 BindingPatternUnexpectedToken(classifier); |
2321 ArrowFormalParametersUnexpectedToken(classifier); | 2338 ArrowFormalParametersUnexpectedToken(classifier); |
2322 | 2339 |
2323 expression = this->CheckAndRewriteReferenceExpression( | 2340 expression = this->CheckAndRewriteReferenceExpression( |
2324 expression, lhs_beg_pos, scanner()->location().end_pos, | 2341 expression, lhs_beg_pos, scanner()->location().end_pos, |
2325 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); | 2342 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); |
2326 expression = this->MarkExpressionAsAssigned(expression); | 2343 expression = this->MarkExpressionAsAssigned(expression); |
2327 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | 2344 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2328 | 2345 |
2329 Token::Value next = Next(); | 2346 Token::Value next = Next(); |
2330 expression = | 2347 expression = |
2331 factory()->NewCountOperation(next, | 2348 factory()->NewCountOperation(next, |
2332 false /* postfix */, | 2349 false /* postfix */, |
2333 expression, | 2350 expression, |
2334 position()); | 2351 position()); |
2335 } | 2352 } |
2336 return expression; | 2353 return expression; |
2337 } | 2354 } |
2338 | 2355 |
2339 | 2356 |
2340 template <class Traits> | 2357 template <class Traits> |
2341 typename ParserBase<Traits>::ExpressionT | 2358 typename ParserBase<Traits>::ExpressionT |
2342 ParserBase<Traits>::ParseLeftHandSideExpression( | 2359 ParserBase<Traits>::ParseLeftHandSideExpression( |
2343 ExpressionClassifier* classifier, bool* ok) { | 2360 ExpressionClassifier* classifier, bool* ok) { |
2344 // LeftHandSideExpression :: | 2361 // LeftHandSideExpression :: |
2345 // (NewExpression | MemberExpression) ... | 2362 // (NewExpression | MemberExpression) ... |
2346 | 2363 |
2347 ExpressionT result = | 2364 ExpressionT result = |
2348 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2365 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
2349 | 2366 |
2350 while (true) { | 2367 while (true) { |
2351 switch (peek()) { | 2368 switch (peek()) { |
2352 case Token::LBRACK: { | 2369 case Token::LBRACK: { |
2353 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); | 2370 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2354 BindingPatternUnexpectedToken(classifier); | 2371 BindingPatternUnexpectedToken(classifier); |
2355 ArrowFormalParametersUnexpectedToken(classifier); | 2372 ArrowFormalParametersUnexpectedToken(classifier); |
2356 Consume(Token::LBRACK); | 2373 Consume(Token::LBRACK); |
2357 int pos = position(); | 2374 int pos = position(); |
2358 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); | 2375 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); |
2359 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); | 2376 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2360 result = factory()->NewProperty(result, index, pos); | 2377 result = factory()->NewProperty(result, index, pos); |
2361 Expect(Token::RBRACK, CHECK_OK); | 2378 Expect(Token::RBRACK, CHECK_OK); |
2362 break; | 2379 break; |
2363 } | 2380 } |
2364 | 2381 |
2365 case Token::LPAREN: { | 2382 case Token::LPAREN: { |
2366 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); | 2383 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2367 BindingPatternUnexpectedToken(classifier); | 2384 BindingPatternUnexpectedToken(classifier); |
2368 ArrowFormalParametersUnexpectedToken(classifier); | 2385 ArrowFormalParametersUnexpectedToken(classifier); |
2369 | 2386 |
2370 if (is_strong(language_mode()) && this->IsIdentifier(result) && | 2387 if (is_strong(language_mode()) && this->IsIdentifier(result) && |
2371 this->IsEval(this->AsIdentifier(result))) { | 2388 this->IsEval(this->AsIdentifier(result))) { |
2372 ReportMessage(MessageTemplate::kStrongDirectEval); | 2389 ReportMessage(MessageTemplate::kStrongDirectEval); |
2373 *ok = false; | 2390 *ok = false; |
2374 return this->EmptyExpression(); | 2391 return this->EmptyExpression(); |
2375 } | 2392 } |
2376 int pos; | 2393 int pos; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2420 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 2437 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); |
2421 result = | 2438 result = |
2422 factory()->NewAssignment(Token::INIT, this_expr, result, pos); | 2439 factory()->NewAssignment(Token::INIT, this_expr, result, pos); |
2423 } | 2440 } |
2424 | 2441 |
2425 if (fni_ != NULL) fni_->RemoveLastFunction(); | 2442 if (fni_ != NULL) fni_->RemoveLastFunction(); |
2426 break; | 2443 break; |
2427 } | 2444 } |
2428 | 2445 |
2429 case Token::PERIOD: { | 2446 case Token::PERIOD: { |
2430 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); | 2447 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2431 BindingPatternUnexpectedToken(classifier); | 2448 BindingPatternUnexpectedToken(classifier); |
2432 ArrowFormalParametersUnexpectedToken(classifier); | 2449 ArrowFormalParametersUnexpectedToken(classifier); |
2433 Consume(Token::PERIOD); | 2450 Consume(Token::PERIOD); |
2434 int pos = position(); | 2451 int pos = position(); |
2435 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2452 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2436 result = factory()->NewProperty( | 2453 result = factory()->NewProperty( |
2437 result, factory()->NewStringLiteral(name, pos), pos); | 2454 result, factory()->NewStringLiteral(name, pos), pos); |
2438 if (fni_ != NULL) this->PushLiteralName(fni_, name); | 2455 if (fni_ != NULL) this->PushLiteralName(fni_, name); |
2439 break; | 2456 break; |
2440 } | 2457 } |
2441 | 2458 |
2442 case Token::TEMPLATE_SPAN: | 2459 case Token::TEMPLATE_SPAN: |
2443 case Token::TEMPLATE_TAIL: { | 2460 case Token::TEMPLATE_TAIL: { |
2444 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); | 2461 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2445 BindingPatternUnexpectedToken(classifier); | 2462 BindingPatternUnexpectedToken(classifier); |
2446 ArrowFormalParametersUnexpectedToken(classifier); | 2463 ArrowFormalParametersUnexpectedToken(classifier); |
2447 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); | 2464 result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK); |
2448 break; | 2465 break; |
2449 } | 2466 } |
2450 | 2467 |
2451 default: | 2468 default: |
2452 return result; | 2469 return result; |
2453 } | 2470 } |
2454 } | 2471 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 int new_pos = position(); | 2503 int new_pos = position(); |
2487 ExpressionT result = this->EmptyExpression(); | 2504 ExpressionT result = this->EmptyExpression(); |
2488 if (peek() == Token::SUPER) { | 2505 if (peek() == Token::SUPER) { |
2489 const bool is_new = true; | 2506 const bool is_new = true; |
2490 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2507 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
2491 } else if (peek() == Token::PERIOD) { | 2508 } else if (peek() == Token::PERIOD) { |
2492 return ParseNewTargetExpression(CHECK_OK); | 2509 return ParseNewTargetExpression(CHECK_OK); |
2493 } else { | 2510 } else { |
2494 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2511 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
2495 } | 2512 } |
2496 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); | 2513 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2497 if (peek() == Token::LPAREN) { | 2514 if (peek() == Token::LPAREN) { |
2498 // NewExpression with arguments. | 2515 // NewExpression with arguments. |
2499 Scanner::Location spread_pos; | 2516 Scanner::Location spread_pos; |
2500 typename Traits::Type::ExpressionList args = | 2517 typename Traits::Type::ExpressionList args = |
2501 this->ParseArguments(&spread_pos, classifier, CHECK_OK); | 2518 this->ParseArguments(&spread_pos, classifier, CHECK_OK); |
2502 | 2519 |
2503 if (spread_pos.IsValid()) { | 2520 if (spread_pos.IsValid()) { |
2504 args = Traits::PrepareSpreadArguments(args); | 2521 args = Traits::PrepareSpreadArguments(args); |
2505 result = Traits::SpreadCallNew(result, args, new_pos); | 2522 result = Traits::SpreadCallNew(result, args, new_pos); |
2506 } else { | 2523 } else { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2602 int pos = position(); | 2619 int pos = position(); |
2603 function_state_->set_this_location(scanner()->location()); | 2620 function_state_->set_this_location(scanner()->location()); |
2604 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 2621 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); |
2605 | 2622 |
2606 ExpressionT left = this->EmptyExpression(); | 2623 ExpressionT left = this->EmptyExpression(); |
2607 switch (peek()) { | 2624 switch (peek()) { |
2608 case Token::LBRACK: { | 2625 case Token::LBRACK: { |
2609 Consume(Token::LBRACK); | 2626 Consume(Token::LBRACK); |
2610 int pos = position(); | 2627 int pos = position(); |
2611 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2628 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
2612 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); | 2629 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2613 left = factory()->NewProperty(this_expr, index, pos); | 2630 left = factory()->NewProperty(this_expr, index, pos); |
2614 if (fni_ != NULL) { | 2631 if (fni_ != NULL) { |
2615 this->PushPropertyName(fni_, index); | 2632 this->PushPropertyName(fni_, index); |
2616 } | 2633 } |
2617 Expect(Token::RBRACK, CHECK_OK); | 2634 Expect(Token::RBRACK, CHECK_OK); |
2618 break; | 2635 break; |
2619 } | 2636 } |
2620 case Token::PERIOD: { | 2637 case Token::PERIOD: { |
2621 Consume(Token::PERIOD); | 2638 Consume(Token::PERIOD); |
2622 int pos = position(); | 2639 int pos = position(); |
(...skipping 15 matching lines...) Expand all Loading... |
2638 ReportMessageAt(function_state_->this_location(), | 2655 ReportMessageAt(function_state_->this_location(), |
2639 MessageTemplate::kStrongConstructorThis); | 2656 MessageTemplate::kStrongConstructorThis); |
2640 *ok = false; | 2657 *ok = false; |
2641 return this->EmptyExpression(); | 2658 return this->EmptyExpression(); |
2642 } | 2659 } |
2643 Consume(Token::ASSIGN); | 2660 Consume(Token::ASSIGN); |
2644 left = this->MarkExpressionAsAssigned(left); | 2661 left = this->MarkExpressionAsAssigned(left); |
2645 | 2662 |
2646 ExpressionT right = | 2663 ExpressionT right = |
2647 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 2664 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
2648 right = Traits::RewriteNonPattern(right, classifier, CHECK_OK); | 2665 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2649 this->CheckAssigningFunctionLiteralToProperty(left, right); | 2666 this->CheckAssigningFunctionLiteralToProperty(left, right); |
2650 function_state_->AddProperty(); | 2667 function_state_->AddProperty(); |
2651 if (fni_ != NULL) { | 2668 if (fni_ != NULL) { |
2652 // Check if the right hand side is a call to avoid inferring a | 2669 // Check if the right hand side is a call to avoid inferring a |
2653 // name if we're dealing with "this.a = function(){...}();"-like | 2670 // name if we're dealing with "this.a = function(){...}();"-like |
2654 // expression. | 2671 // expression. |
2655 if (!right->IsCall() && !right->IsCallNew()) { | 2672 if (!right->IsCall() && !right->IsCallNew()) { |
2656 fni_->Infer(); | 2673 fni_->Infer(); |
2657 } else { | 2674 } else { |
2658 fni_->RemoveLastFunction(); | 2675 fni_->RemoveLastFunction(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2802 | 2819 |
2803 template <class Traits> | 2820 template <class Traits> |
2804 typename ParserBase<Traits>::ExpressionT | 2821 typename ParserBase<Traits>::ExpressionT |
2805 ParserBase<Traits>::ParseMemberExpressionContinuation( | 2822 ParserBase<Traits>::ParseMemberExpressionContinuation( |
2806 ExpressionT expression, ExpressionClassifier* classifier, bool* ok) { | 2823 ExpressionT expression, ExpressionClassifier* classifier, bool* ok) { |
2807 // Parses this part of MemberExpression: | 2824 // Parses this part of MemberExpression: |
2808 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 2825 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
2809 while (true) { | 2826 while (true) { |
2810 switch (peek()) { | 2827 switch (peek()) { |
2811 case Token::LBRACK: { | 2828 case Token::LBRACK: { |
2812 expression = | 2829 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2813 Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | |
2814 BindingPatternUnexpectedToken(classifier); | 2830 BindingPatternUnexpectedToken(classifier); |
2815 ArrowFormalParametersUnexpectedToken(classifier); | 2831 ArrowFormalParametersUnexpectedToken(classifier); |
2816 | 2832 |
2817 Consume(Token::LBRACK); | 2833 Consume(Token::LBRACK); |
2818 int pos = position(); | 2834 int pos = position(); |
2819 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2835 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
2820 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); | 2836 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2821 expression = factory()->NewProperty(expression, index, pos); | 2837 expression = factory()->NewProperty(expression, index, pos); |
2822 if (fni_ != NULL) { | 2838 if (fni_ != NULL) { |
2823 this->PushPropertyName(fni_, index); | 2839 this->PushPropertyName(fni_, index); |
2824 } | 2840 } |
2825 Expect(Token::RBRACK, CHECK_OK); | 2841 Expect(Token::RBRACK, CHECK_OK); |
2826 break; | 2842 break; |
2827 } | 2843 } |
2828 case Token::PERIOD: { | 2844 case Token::PERIOD: { |
2829 expression = | 2845 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2830 Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | |
2831 BindingPatternUnexpectedToken(classifier); | 2846 BindingPatternUnexpectedToken(classifier); |
2832 ArrowFormalParametersUnexpectedToken(classifier); | 2847 ArrowFormalParametersUnexpectedToken(classifier); |
2833 | 2848 |
2834 Consume(Token::PERIOD); | 2849 Consume(Token::PERIOD); |
2835 int pos = position(); | 2850 int pos = position(); |
2836 IdentifierT name = ParseIdentifierName(CHECK_OK); | 2851 IdentifierT name = ParseIdentifierName(CHECK_OK); |
2837 expression = factory()->NewProperty( | 2852 expression = factory()->NewProperty( |
2838 expression, factory()->NewStringLiteral(name, pos), pos); | 2853 expression, factory()->NewStringLiteral(name, pos), pos); |
2839 if (fni_ != NULL) { | 2854 if (fni_ != NULL) { |
2840 this->PushLiteralName(fni_, name); | 2855 this->PushLiteralName(fni_, name); |
2841 } | 2856 } |
2842 break; | 2857 break; |
2843 } | 2858 } |
2844 case Token::TEMPLATE_SPAN: | 2859 case Token::TEMPLATE_SPAN: |
2845 case Token::TEMPLATE_TAIL: { | 2860 case Token::TEMPLATE_TAIL: { |
2846 expression = | 2861 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2847 Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | |
2848 BindingPatternUnexpectedToken(classifier); | 2862 BindingPatternUnexpectedToken(classifier); |
2849 ArrowFormalParametersUnexpectedToken(classifier); | 2863 ArrowFormalParametersUnexpectedToken(classifier); |
2850 int pos; | 2864 int pos; |
2851 if (scanner()->current_token() == Token::IDENTIFIER) { | 2865 if (scanner()->current_token() == Token::IDENTIFIER) { |
2852 pos = position(); | 2866 pos = position(); |
2853 } else { | 2867 } else { |
2854 pos = peek_position(); | 2868 pos = peek_position(); |
2855 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { | 2869 if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) { |
2856 // If the tag function looks like an IIFE, set_parenthesized() to | 2870 // If the tag function looks like an IIFE, set_parenthesized() to |
2857 // force eager compilation. | 2871 // force eager compilation. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2892 return; | 2906 return; |
2893 } | 2907 } |
2894 parameters->is_simple = false; | 2908 parameters->is_simple = false; |
2895 ValidateFormalParameterInitializer(classifier, ok); | 2909 ValidateFormalParameterInitializer(classifier, ok); |
2896 if (!*ok) return; | 2910 if (!*ok) return; |
2897 classifier->RecordNonSimpleParameter(); | 2911 classifier->RecordNonSimpleParameter(); |
2898 } | 2912 } |
2899 | 2913 |
2900 ExpressionT initializer = Traits::EmptyExpression(); | 2914 ExpressionT initializer = Traits::EmptyExpression(); |
2901 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { | 2915 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { |
2902 ExpressionClassifier init_classifier; | 2916 ExpressionClassifier init_classifier(this); |
2903 initializer = ParseAssignmentExpression(true, &init_classifier, ok); | 2917 initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
2904 if (!*ok) return; | 2918 if (!*ok) return; |
2905 initializer = Traits::RewriteNonPattern(initializer, &init_classifier, ok); | 2919 Traits::RewriteNonPattern(&init_classifier, ok); |
2906 ValidateFormalParameterInitializer(&init_classifier, ok); | 2920 ValidateFormalParameterInitializer(&init_classifier, ok); |
2907 if (!*ok) return; | 2921 if (!*ok) return; |
2908 parameters->is_simple = false; | 2922 parameters->is_simple = false; |
| 2923 init_classifier.Discard(); |
2909 classifier->RecordNonSimpleParameter(); | 2924 classifier->RecordNonSimpleParameter(); |
2910 | 2925 |
2911 if (allow_harmony_function_name()) { | 2926 if (allow_harmony_function_name()) { |
2912 Traits::SetFunctionNameFromIdentifierRef(initializer, pattern); | 2927 Traits::SetFunctionNameFromIdentifierRef(initializer, pattern); |
2913 } | 2928 } |
2914 } | 2929 } |
2915 | 2930 |
2916 Traits::AddFormalParameter(parameters, pattern, initializer, | 2931 Traits::AddFormalParameter(parameters, pattern, initializer, |
2917 scanner()->location().end_pos, is_rest); | 2932 scanner()->location().end_pos, is_rest); |
2918 } | 2933 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3066 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, | 3081 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, |
3067 kArrowFunction, FunctionLiteral::kAnonymousExpression, CHECK_OK); | 3082 kArrowFunction, FunctionLiteral::kAnonymousExpression, CHECK_OK); |
3068 materialized_literal_count = | 3083 materialized_literal_count = |
3069 function_state.materialized_literal_count(); | 3084 function_state.materialized_literal_count(); |
3070 expected_property_count = function_state.expected_property_count(); | 3085 expected_property_count = function_state.expected_property_count(); |
3071 } | 3086 } |
3072 } else { | 3087 } else { |
3073 // Single-expression body | 3088 // Single-expression body |
3074 int pos = position(); | 3089 int pos = position(); |
3075 parenthesized_function_ = false; | 3090 parenthesized_function_ = false; |
3076 ExpressionClassifier classifier; | 3091 ExpressionClassifier classifier(this); |
3077 ExpressionT expression = | 3092 ExpressionT expression = |
3078 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); | 3093 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); |
3079 expression = Traits::RewriteNonPattern(expression, &classifier, CHECK_OK); | 3094 Traits::RewriteNonPattern(&classifier, CHECK_OK); |
3080 body = this->NewStatementList(1, zone()); | 3095 body = this->NewStatementList(1, zone()); |
3081 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); | 3096 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); |
3082 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3097 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3083 materialized_literal_count = function_state.materialized_literal_count(); | 3098 materialized_literal_count = function_state.materialized_literal_count(); |
3084 expected_property_count = function_state.expected_property_count(); | 3099 expected_property_count = function_state.expected_property_count(); |
3085 } | 3100 } |
3086 super_loc = function_state.super_location(); | 3101 super_loc = function_state.super_location(); |
3087 | 3102 |
3088 formal_parameters.scope->set_end_position(scanner()->location().end_pos); | 3103 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
3089 | 3104 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3175 } else if (next == Token::ILLEGAL) { | 3190 } else if (next == Token::ILLEGAL) { |
3176 Traits::ReportMessageAt( | 3191 Traits::ReportMessageAt( |
3177 Scanner::Location(position() + 1, peek_position()), | 3192 Scanner::Location(position() + 1, peek_position()), |
3178 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); | 3193 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); |
3179 *ok = false; | 3194 *ok = false; |
3180 return Traits::EmptyExpression(); | 3195 return Traits::EmptyExpression(); |
3181 } | 3196 } |
3182 | 3197 |
3183 int expr_pos = peek_position(); | 3198 int expr_pos = peek_position(); |
3184 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); | 3199 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); |
3185 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | 3200 Traits::RewriteNonPattern(classifier, CHECK_OK); |
3186 Traits::AddTemplateExpression(&ts, expression); | 3201 Traits::AddTemplateExpression(&ts, expression); |
3187 | 3202 |
3188 if (peek() != Token::RBRACE) { | 3203 if (peek() != Token::RBRACE) { |
3189 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), | 3204 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), |
3190 MessageTemplate::kUnterminatedTemplateExpr); | 3205 MessageTemplate::kUnterminatedTemplateExpr); |
3191 *ok = false; | 3206 *ok = false; |
3192 return Traits::EmptyExpression(); | 3207 return Traits::EmptyExpression(); |
3193 } | 3208 } |
3194 | 3209 |
3195 // If we didn't die parsing that expression, our next token should be a | 3210 // If we didn't die parsing that expression, our next token should be a |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3229 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, | 3244 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, |
3230 message, kReferenceError, ok); | 3245 message, kReferenceError, ok); |
3231 } | 3246 } |
3232 | 3247 |
3233 | 3248 |
3234 template <typename Traits> | 3249 template <typename Traits> |
3235 typename ParserBase<Traits>::ExpressionT | 3250 typename ParserBase<Traits>::ExpressionT |
3236 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 3251 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
3237 ExpressionT expression, int beg_pos, int end_pos, | 3252 ExpressionT expression, int beg_pos, int end_pos, |
3238 MessageTemplate::Template message, ParseErrorType type, bool* ok) { | 3253 MessageTemplate::Template message, ParseErrorType type, bool* ok) { |
3239 ExpressionClassifier classifier; | 3254 ExpressionClassifier classifier(this); |
3240 ExpressionT result = ClassifyAndRewriteReferenceExpression( | 3255 ExpressionT result = ClassifyAndRewriteReferenceExpression( |
3241 &classifier, expression, beg_pos, end_pos, message, type); | 3256 &classifier, expression, beg_pos, end_pos, message, type); |
3242 ValidateExpression(&classifier, ok); | 3257 ValidateExpression(&classifier, ok); |
3243 if (!*ok) return this->EmptyExpression(); | 3258 if (!*ok) return this->EmptyExpression(); |
3244 return result; | 3259 return result; |
3245 } | 3260 } |
3246 | 3261 |
3247 | 3262 |
3248 template <typename Traits> | 3263 template <typename Traits> |
3249 typename ParserBase<Traits>::ExpressionT | 3264 typename ParserBase<Traits>::ExpressionT |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3283 template <typename Traits> | 3298 template <typename Traits> |
3284 bool ParserBase<Traits>::IsValidReferenceExpression(ExpressionT expression) { | 3299 bool ParserBase<Traits>::IsValidReferenceExpression(ExpressionT expression) { |
3285 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); | 3300 return this->IsAssignableIdentifier(expression) || expression->IsProperty(); |
3286 } | 3301 } |
3287 | 3302 |
3288 | 3303 |
3289 template <typename Traits> | 3304 template <typename Traits> |
3290 void ParserBase<Traits>::CheckDestructuringElement( | 3305 void ParserBase<Traits>::CheckDestructuringElement( |
3291 ExpressionT expression, ExpressionClassifier* classifier, int begin, | 3306 ExpressionT expression, ExpressionClassifier* classifier, int begin, |
3292 int end) { | 3307 int end) { |
3293 if (!IsValidPattern(expression) && !IsAssignmentExpression(expression) && | 3308 if (!IsValidPattern(expression) && !expression->IsAssignment() && |
3294 !IsValidReferenceExpression(expression)) { | 3309 !IsValidReferenceExpression(expression)) { |
3295 classifier->RecordAssignmentPatternError( | 3310 classifier->RecordAssignmentPatternError( |
3296 Scanner::Location(begin, end), | 3311 Scanner::Location(begin, end), |
3297 MessageTemplate::kInvalidDestructuringTarget); | 3312 MessageTemplate::kInvalidDestructuringTarget); |
3298 } | 3313 } |
3299 } | 3314 } |
3300 | 3315 |
3301 | 3316 |
3302 #undef CHECK_OK | 3317 #undef CHECK_OK |
3303 #undef CHECK_OK_CUSTOM | 3318 #undef CHECK_OK_CUSTOM |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3349 } | 3364 } |
3350 if (has_seen_constructor_) { | 3365 if (has_seen_constructor_) { |
3351 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); | 3366 this->parser()->ReportMessage(MessageTemplate::kDuplicateConstructor); |
3352 *ok = false; | 3367 *ok = false; |
3353 return; | 3368 return; |
3354 } | 3369 } |
3355 has_seen_constructor_ = true; | 3370 has_seen_constructor_ = true; |
3356 return; | 3371 return; |
3357 } | 3372 } |
3358 } | 3373 } |
| 3374 |
| 3375 |
3359 } // namespace internal | 3376 } // namespace internal |
3360 } // namespace v8 | 3377 } // namespace v8 |
3361 | 3378 |
3362 #endif // V8_PARSING_PARSER_BASE_H | 3379 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |