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