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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 738 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
739 ObjectLiteralPropertyT ParsePropertyDefinition( | 739 ObjectLiteralPropertyT ParsePropertyDefinition( |
740 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 740 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
741 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 741 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
742 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 742 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
743 typename Traits::Type::ExpressionList ParseArguments( | 743 typename Traits::Type::ExpressionList ParseArguments( |
744 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 744 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
745 bool* ok); | 745 bool* ok); |
746 | 746 |
747 enum AssignmentExpressionFlags { | 747 enum AssignmentExpressionFlags { |
748 kIsLeftHandSide = 0, | 748 kIsNormalAssignment = 0, |
749 kIsRightHandSide = 1 << 0, | 749 kIsPossiblePatternElement = 1 << 0, |
750 kIsPatternElement = 1 << 1, | 750 kIsPossibleArrowFormals = 1 << 1 |
751 kIsPossibleArrowFormals = 1 << 2 | |
752 }; | 751 }; |
753 | 752 |
754 ExpressionT ParseAssignmentExpression(bool accept_IN, int flags, | 753 ExpressionT ParseAssignmentExpression(bool accept_IN, int flags, |
755 ExpressionClassifier* classifier, | 754 ExpressionClassifier* classifier, |
756 bool* ok); | 755 bool* ok); |
757 ExpressionT ParseAssignmentExpression(bool accept_IN, | 756 ExpressionT ParseAssignmentExpression(bool accept_IN, |
758 ExpressionClassifier* classifier, | 757 ExpressionClassifier* classifier, |
759 bool* ok) { | 758 bool* ok) { |
760 return ParseAssignmentExpression(accept_IN, kIsLeftHandSide, classifier, | 759 return ParseAssignmentExpression(accept_IN, kIsNormalAssignment, classifier, |
761 ok); | 760 ok); |
762 } | 761 } |
763 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); | 762 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); |
764 ExpressionT ParseConditionalExpression(bool accept_IN, | 763 ExpressionT ParseConditionalExpression(bool accept_IN, |
765 ExpressionClassifier* classifier, | 764 ExpressionClassifier* classifier, |
766 bool* ok); | 765 bool* ok); |
767 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, | 766 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, |
768 ExpressionClassifier* classifier, bool* ok); | 767 ExpressionClassifier* classifier, bool* ok); |
769 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 768 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
770 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 769 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { | 1028 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { |
1030 ExpressionClassifier classifier; | 1029 ExpressionClassifier classifier; |
1031 auto result = ParseAndClassifyIdentifier(&classifier, ok); | 1030 auto result = ParseAndClassifyIdentifier(&classifier, ok); |
1032 if (!*ok) return Traits::EmptyIdentifier(); | 1031 if (!*ok) return Traits::EmptyIdentifier(); |
1033 | 1032 |
1034 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { | 1033 if (allow_restricted_identifiers == kDontAllowRestrictedIdentifiers) { |
1035 ValidateAssignmentPattern(&classifier, ok); | 1034 ValidateAssignmentPattern(&classifier, ok); |
1036 if (!*ok) return Traits::EmptyIdentifier(); | 1035 if (!*ok) return Traits::EmptyIdentifier(); |
1037 ValidateBindingPattern(&classifier, ok); | 1036 ValidateBindingPattern(&classifier, ok); |
1038 if (!*ok) return Traits::EmptyIdentifier(); | 1037 if (!*ok) return Traits::EmptyIdentifier(); |
1039 } else { | |
1040 #if 0 // TODO(nikolaos): is this needed? | |
1041 ValidateExpression(&classifier, ok); | |
1042 if (!*ok) return Traits::EmptyIdentifier(); | |
1043 #endif | |
1044 } | 1038 } |
1045 | 1039 |
1046 return result; | 1040 return result; |
1047 } | 1041 } |
1048 | 1042 |
1049 | 1043 |
1050 template <class Traits> | 1044 template <class Traits> |
1051 typename ParserBase<Traits>::IdentifierT | 1045 typename ParserBase<Traits>::IdentifierT |
1052 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, | 1046 ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, |
1053 bool* ok) { | 1047 bool* ok) { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 Expect(Token::RPAREN, CHECK_OK); | 1343 Expect(Token::RPAREN, CHECK_OK); |
1350 return factory()->NewSpread(expr, ellipsis_pos); | 1344 return factory()->NewSpread(expr, ellipsis_pos); |
1351 } | 1345 } |
1352 // Heuristically try to detect immediately called functions before | 1346 // Heuristically try to detect immediately called functions before |
1353 // seeing the call parentheses. | 1347 // seeing the call parentheses. |
1354 parenthesized_function_ = (peek() == Token::FUNCTION); | 1348 parenthesized_function_ = (peek() == Token::FUNCTION); |
1355 ExpressionT expr = this->ParseExpression(true, kIsPossibleArrowFormals, | 1349 ExpressionT expr = this->ParseExpression(true, kIsPossibleArrowFormals, |
1356 classifier, CHECK_OK); | 1350 classifier, CHECK_OK); |
1357 Expect(Token::RPAREN, CHECK_OK); | 1351 Expect(Token::RPAREN, CHECK_OK); |
1358 if (peek() != Token::ARROW) { | 1352 if (peek() != Token::ARROW) { |
1359 #if 0 // TODO(nikolaos): is this needed? | |
1360 ValidateExpression(classifier, CHECK_OK); | |
1361 #endif | |
1362 expr->set_is_parenthesized(); | 1353 expr->set_is_parenthesized(); |
1363 } | 1354 } |
1364 return expr; | 1355 return expr; |
1365 } | 1356 } |
1366 | 1357 |
1367 case Token::CLASS: { | 1358 case Token::CLASS: { |
1368 BindingPatternUnexpectedToken(classifier); | 1359 BindingPatternUnexpectedToken(classifier); |
1369 Consume(Token::CLASS); | 1360 Consume(Token::CLASS); |
1370 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { | 1361 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
1371 ReportMessage(MessageTemplate::kSloppyLexical); | 1362 ReportMessage(MessageTemplate::kSloppyLexical); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 *ok = false; | 1407 *ok = false; |
1417 return this->EmptyExpression(); | 1408 return this->EmptyExpression(); |
1418 } | 1409 } |
1419 | 1410 |
1420 | 1411 |
1421 template <class Traits> | 1412 template <class Traits> |
1422 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1413 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1423 bool accept_IN, bool* ok) { | 1414 bool accept_IN, bool* ok) { |
1424 ExpressionClassifier classifier; | 1415 ExpressionClassifier classifier; |
1425 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); | 1416 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); |
1426 result = Traits::RewriteExpression(result, &classifier, CHECK_OK); | 1417 result = Traits::RewriteNonPattern(result, &classifier, CHECK_OK); |
1427 return result; | 1418 return result; |
1428 } | 1419 } |
1429 | 1420 |
1430 | 1421 |
1431 template <class Traits> | 1422 template <class Traits> |
1432 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1423 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1433 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 1424 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
1434 return ParseExpression(accept_IN, kIsLeftHandSide, classifier, ok); | 1425 return ParseExpression(accept_IN, kIsNormalAssignment, classifier, ok); |
1435 } | 1426 } |
1436 | 1427 |
1437 | 1428 |
1438 template <class Traits> | 1429 template <class Traits> |
1439 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1430 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1440 bool accept_IN, int flags, ExpressionClassifier* classifier, bool* ok) { | 1431 bool accept_IN, int flags, ExpressionClassifier* classifier, bool* ok) { |
1441 // Expression :: | 1432 // Expression :: |
1442 // AssignmentExpression | 1433 // AssignmentExpression |
1443 // Expression ',' AssignmentExpression | 1434 // Expression ',' AssignmentExpression |
1444 | 1435 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 CheckDestructuringElement(argument, classifier, start_pos, | 1516 CheckDestructuringElement(argument, classifier, start_pos, |
1526 scanner()->location().end_pos); | 1517 scanner()->location().end_pos); |
1527 } | 1518 } |
1528 | 1519 |
1529 if (peek() == Token::COMMA) { | 1520 if (peek() == Token::COMMA) { |
1530 classifier->RecordPatternError( | 1521 classifier->RecordPatternError( |
1531 Scanner::Location(start_pos, scanner()->location().end_pos), | 1522 Scanner::Location(start_pos, scanner()->location().end_pos), |
1532 MessageTemplate::kElementAfterRest); | 1523 MessageTemplate::kElementAfterRest); |
1533 } | 1524 } |
1534 } else { | 1525 } else { |
1535 elem = this->ParseAssignmentExpression(true, kIsPatternElement, | 1526 elem = this->ParseAssignmentExpression(true, kIsPossiblePatternElement, |
1536 classifier, CHECK_OK); | 1527 classifier, CHECK_OK); |
1537 } | 1528 } |
1538 values->Add(elem, zone_); | 1529 values->Add(elem, zone_); |
1539 if (peek() != Token::RBRACK) { | 1530 if (peek() != Token::RBRACK) { |
1540 Expect(Token::COMMA, CHECK_OK); | 1531 Expect(Token::COMMA, CHECK_OK); |
1541 } | 1532 } |
1542 } | 1533 } |
1543 Expect(Token::RBRACK, CHECK_OK); | 1534 Expect(Token::RBRACK, CHECK_OK); |
1544 | 1535 |
1545 // Update the scope information before the pre-parsing bailout. | 1536 // Update the scope information before the pre-parsing bailout. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 Consume(Token::NUMBER); | 1573 Consume(Token::NUMBER); |
1583 *name = this->GetNumberAsSymbol(scanner()); | 1574 *name = this->GetNumberAsSymbol(scanner()); |
1584 break; | 1575 break; |
1585 | 1576 |
1586 case Token::LBRACK: { | 1577 case Token::LBRACK: { |
1587 *is_computed_name = true; | 1578 *is_computed_name = true; |
1588 Consume(Token::LBRACK); | 1579 Consume(Token::LBRACK); |
1589 ExpressionClassifier computed_name_classifier; | 1580 ExpressionClassifier computed_name_classifier; |
1590 ExpressionT expression = | 1581 ExpressionT expression = |
1591 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); | 1582 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); |
1592 expression = Traits::RewriteExpression( | 1583 expression = Traits::RewriteNonPattern( |
1593 expression, &computed_name_classifier, CHECK_OK); | 1584 expression, &computed_name_classifier, CHECK_OK); |
1594 classifier->Accumulate(computed_name_classifier, | 1585 classifier->Accumulate(computed_name_classifier, |
1595 ExpressionClassifier::ExpressionProductions); | 1586 ExpressionClassifier::ExpressionProductions); |
1596 Expect(Token::RBRACK, CHECK_OK); | 1587 Expect(Token::RBRACK, CHECK_OK); |
1597 return expression; | 1588 return expression; |
1598 } | 1589 } |
1599 | 1590 |
1600 case Token::ESCAPED_KEYWORD: | 1591 case Token::ESCAPED_KEYWORD: |
1601 *is_escaped_keyword = true; | 1592 *is_escaped_keyword = true; |
1602 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); | 1593 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 | 1646 |
1656 if (peek() == Token::COLON) { | 1647 if (peek() == Token::COLON) { |
1657 // PropertyDefinition | 1648 // PropertyDefinition |
1658 // PropertyName ':' AssignmentExpression | 1649 // PropertyName ':' AssignmentExpression |
1659 if (!*is_computed_name) { | 1650 if (!*is_computed_name) { |
1660 checker->CheckProperty(name_token, kValueProperty, false, false, | 1651 checker->CheckProperty(name_token, kValueProperty, false, false, |
1661 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1652 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1662 } | 1653 } |
1663 Consume(Token::COLON); | 1654 Consume(Token::COLON); |
1664 value = this->ParseAssignmentExpression( | 1655 value = this->ParseAssignmentExpression( |
1665 true, kIsPatternElement, classifier, | 1656 true, kIsPossiblePatternElement, classifier, |
1666 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1657 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1667 | 1658 |
1668 return factory()->NewObjectLiteralProperty(name_expression, value, false, | 1659 return factory()->NewObjectLiteralProperty(name_expression, value, false, |
1669 *is_computed_name); | 1660 *is_computed_name); |
1670 } | 1661 } |
1671 | 1662 |
1672 if ((is_identifier || is_escaped_keyword) && | 1663 if ((is_identifier || is_escaped_keyword) && |
1673 (peek() == Token::COMMA || peek() == Token::RBRACE || | 1664 (peek() == Token::COMMA || peek() == Token::RBRACE || |
1674 peek() == Token::ASSIGN)) { | 1665 peek() == Token::ASSIGN)) { |
1675 // PropertyDefinition | 1666 // PropertyDefinition |
(...skipping 21 matching lines...) Expand all Loading... |
1697 | 1688 |
1698 ExpressionT lhs = this->ExpressionFromIdentifier( | 1689 ExpressionT lhs = this->ExpressionFromIdentifier( |
1699 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1690 *name, next_beg_pos, next_end_pos, scope_, factory()); |
1700 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1691 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
1701 | 1692 |
1702 if (peek() == Token::ASSIGN) { | 1693 if (peek() == Token::ASSIGN) { |
1703 Consume(Token::ASSIGN); | 1694 Consume(Token::ASSIGN); |
1704 ExpressionClassifier rhs_classifier; | 1695 ExpressionClassifier rhs_classifier; |
1705 ExpressionT rhs = this->ParseAssignmentExpression( | 1696 ExpressionT rhs = this->ParseAssignmentExpression( |
1706 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1697 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1707 rhs = Traits::RewriteExpression( | 1698 rhs = Traits::RewriteNonPattern( |
1708 rhs, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1699 rhs, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1709 classifier->Accumulate(rhs_classifier, | 1700 classifier->Accumulate(rhs_classifier, |
1710 ExpressionClassifier::ExpressionProductions); | 1701 ExpressionClassifier::ExpressionProductions); |
1711 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 1702 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
1712 RelocInfo::kNoPosition); | 1703 RelocInfo::kNoPosition); |
1713 classifier->RecordCoverInitializedNameError( | 1704 classifier->RecordCoverInitializedNameError( |
1714 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1705 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
1715 MessageTemplate::kInvalidCoverInitializedName); | 1706 MessageTemplate::kInvalidCoverInitializedName); |
1716 } else { | 1707 } else { |
1717 value = lhs; | 1708 value = lhs; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1906 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 1897 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
1907 bool done = (peek() == Token::RPAREN); | 1898 bool done = (peek() == Token::RPAREN); |
1908 bool was_unspread = false; | 1899 bool was_unspread = false; |
1909 int unspread_sequences_count = 0; | 1900 int unspread_sequences_count = 0; |
1910 while (!done) { | 1901 while (!done) { |
1911 int start_pos = peek_position(); | 1902 int start_pos = peek_position(); |
1912 bool is_spread = Check(Token::ELLIPSIS); | 1903 bool is_spread = Check(Token::ELLIPSIS); |
1913 | 1904 |
1914 ExpressionT argument = this->ParseAssignmentExpression( | 1905 ExpressionT argument = this->ParseAssignmentExpression( |
1915 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); | 1906 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
1916 argument = Traits::RewriteExpression(argument, classifier, | 1907 argument = Traits::RewriteNonPattern(argument, classifier, |
1917 CHECK_OK_CUSTOM(NullExpressionList)); | 1908 CHECK_OK_CUSTOM(NullExpressionList)); |
1918 if (is_spread) { | 1909 if (is_spread) { |
1919 if (!spread_arg.IsValid()) { | 1910 if (!spread_arg.IsValid()) { |
1920 spread_arg.beg_pos = start_pos; | 1911 spread_arg.beg_pos = start_pos; |
1921 spread_arg.end_pos = peek_position(); | 1912 spread_arg.end_pos = peek_position(); |
1922 } | 1913 } |
1923 argument = factory()->NewSpread(argument, start_pos); | 1914 argument = factory()->NewSpread(argument, start_pos); |
1924 } | 1915 } |
1925 result->Add(argument, zone_); | 1916 result->Add(argument, zone_); |
1926 | 1917 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 template <class Traits> | 1956 template <class Traits> |
1966 typename ParserBase<Traits>::ExpressionT | 1957 typename ParserBase<Traits>::ExpressionT |
1967 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, | 1958 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, |
1968 ExpressionClassifier* classifier, | 1959 ExpressionClassifier* classifier, |
1969 bool* ok) { | 1960 bool* ok) { |
1970 // AssignmentExpression :: | 1961 // AssignmentExpression :: |
1971 // ConditionalExpression | 1962 // ConditionalExpression |
1972 // ArrowFunction | 1963 // ArrowFunction |
1973 // YieldExpression | 1964 // YieldExpression |
1974 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 1965 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
1975 bool is_rhs = flags & kIsRightHandSide; | 1966 bool maybe_pattern_element = flags & kIsPossiblePatternElement; |
1976 bool is_pattern_element = flags & kIsPatternElement; | 1967 bool maybe_arrow_formals = flags & kIsPossibleArrowFormals; |
1977 bool is_destructuring_assignment = false; | 1968 bool is_destructuring_assignment = false; |
1978 bool is_arrow_formals = flags & kIsPossibleArrowFormals; | |
1979 int lhs_beg_pos = peek_position(); | 1969 int lhs_beg_pos = peek_position(); |
1980 | 1970 |
1981 if (peek() == Token::YIELD && is_generator()) { | 1971 if (peek() == Token::YIELD && is_generator()) { |
1982 return this->ParseYieldExpression(classifier, ok); | 1972 return this->ParseYieldExpression(classifier, ok); |
1983 } | 1973 } |
1984 | 1974 |
1985 FuncNameInferrer::State fni_state(fni_); | 1975 FuncNameInferrer::State fni_state(fni_); |
1986 ParserBase<Traits>::Checkpoint checkpoint(this); | 1976 ParserBase<Traits>::Checkpoint checkpoint(this); |
1987 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); | 1977 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); |
1988 bool parenthesized_formals = peek() == Token::LPAREN; | 1978 bool parenthesized_formals = peek() == Token::LPAREN; |
(...skipping 24 matching lines...) Expand all Loading... |
2013 scope->set_start_position(lhs_beg_pos); | 2003 scope->set_start_position(lhs_beg_pos); |
2014 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2004 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
2015 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, | 2005 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
2016 &duplicate_loc, CHECK_OK); | 2006 &duplicate_loc, CHECK_OK); |
2017 if (duplicate_loc.IsValid()) { | 2007 if (duplicate_loc.IsValid()) { |
2018 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2008 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2019 duplicate_loc); | 2009 duplicate_loc); |
2020 } | 2010 } |
2021 expression = this->ParseArrowFunctionLiteral( | 2011 expression = this->ParseArrowFunctionLiteral( |
2022 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2012 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
2023 if (is_pattern_element) { | 2013 if (maybe_pattern_element) { |
2024 classifier->RecordPatternError( | 2014 classifier->RecordPatternError( |
2025 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), | 2015 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), |
2026 MessageTemplate::kInvalidDestructuringTarget); | 2016 MessageTemplate::kInvalidDestructuringTarget); |
2027 } | 2017 } |
2028 | 2018 |
2029 if (fni_ != nullptr) fni_->Infer(); | 2019 if (fni_ != nullptr) fni_->Infer(); |
2030 | 2020 |
2031 return expression; | 2021 return expression; |
2032 } | 2022 } |
2033 | 2023 |
2034 if (this->IsValidReferenceExpression(expression)) { | 2024 if (this->IsValidReferenceExpression(expression)) { |
2035 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2025 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
2036 } | 2026 } |
2037 | 2027 |
2038 // "expression" was not itself an arrow function parameter list, but it might | 2028 // "expression" was not itself an arrow function parameter list, but it might |
2039 // form part of one. Propagate speculative formal parameter error locations. | 2029 // form part of one. Propagate speculative formal parameter error locations. |
2040 classifier->Accumulate( | 2030 classifier->Accumulate( |
2041 arrow_formals_classifier, | 2031 arrow_formals_classifier, |
2042 ExpressionClassifier::StandardProductions | | 2032 ExpressionClassifier::StandardProductions | |
2043 ExpressionClassifier::FormalParametersProductions | | 2033 ExpressionClassifier::FormalParametersProductions | |
2044 ExpressionClassifier::CoverInitializedNameProduction); | 2034 ExpressionClassifier::CoverInitializedNameProduction); |
2045 | 2035 |
2046 bool maybe_pattern = | 2036 bool maybe_pattern = |
2047 (expression->IsObjectLiteral() || expression->IsArrayLiteral()) && | 2037 (expression->IsObjectLiteral() || expression->IsArrayLiteral()) && |
2048 !expression->is_parenthesized(); | 2038 !expression->is_parenthesized(); |
2049 | 2039 |
2050 if (!Token::IsAssignmentOp(peek())) { | 2040 if (!Token::IsAssignmentOp(peek())) { |
2051 // Parsed conditional expression only (no assignment). | 2041 // Parsed conditional expression only (no assignment). |
2052 if (is_pattern_element) { | 2042 if (maybe_pattern_element) { |
2053 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | 2043 CheckDestructuringElement(expression, classifier, lhs_beg_pos, |
2054 scanner()->location().end_pos); | 2044 scanner()->location().end_pos); |
2055 } else if (is_rhs && maybe_pattern) { | |
2056 #if 0 // TODO(nikolaos): is this needed? | |
2057 ValidateExpression(classifier, CHECK_OK); | |
2058 #endif | |
2059 } | 2045 } |
2060 return expression; | 2046 return expression; |
2061 } | 2047 } |
2062 | 2048 |
2063 if (!(allow_harmony_destructuring_bind() || | 2049 if (!(allow_harmony_destructuring_bind() || |
2064 allow_harmony_default_parameters())) { | 2050 allow_harmony_default_parameters())) { |
2065 BindingPatternUnexpectedToken(classifier); | 2051 BindingPatternUnexpectedToken(classifier); |
2066 } | 2052 } |
2067 | 2053 |
2068 if (allow_harmony_destructuring_assignment() && maybe_pattern && | 2054 if (allow_harmony_destructuring_assignment() && maybe_pattern && |
2069 peek() == Token::ASSIGN) { | 2055 peek() == Token::ASSIGN) { |
2070 classifier->ForgiveCoverInitializedNameError(); | 2056 classifier->ForgiveCoverInitializedNameError(); |
2071 ValidateAssignmentPattern(classifier, CHECK_OK); | 2057 ValidateAssignmentPattern(classifier, CHECK_OK); |
2072 is_destructuring_assignment = true; | 2058 is_destructuring_assignment = true; |
2073 } else if (is_arrow_formals) { | 2059 } else if (maybe_arrow_formals) { |
2074 expression = this->ClassifyAndRewriteReferenceExpression( | 2060 expression = this->ClassifyAndRewriteReferenceExpression( |
2075 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, | 2061 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, |
2076 MessageTemplate::kInvalidLhsInAssignment); | 2062 MessageTemplate::kInvalidLhsInAssignment); |
2077 } else { | 2063 } else { |
2078 if (is_pattern_element) { | 2064 if (maybe_pattern_element) { |
2079 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | 2065 CheckDestructuringElement(expression, classifier, lhs_beg_pos, |
2080 scanner()->location().end_pos); | 2066 scanner()->location().end_pos); |
2081 } | 2067 } |
2082 expression = this->CheckAndRewriteReferenceExpression( | 2068 expression = this->CheckAndRewriteReferenceExpression( |
2083 expression, lhs_beg_pos, scanner()->location().end_pos, | 2069 expression, lhs_beg_pos, scanner()->location().end_pos, |
2084 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 2070 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); |
2085 } | 2071 } |
2086 | 2072 |
2087 expression = this->MarkExpressionAsAssigned(expression); | 2073 expression = this->MarkExpressionAsAssigned(expression); |
2088 | 2074 |
2089 Token::Value op = Next(); // Get assignment operator. | 2075 Token::Value op = Next(); // Get assignment operator. |
2090 if (op != Token::ASSIGN) { | 2076 if (op != Token::ASSIGN) { |
2091 classifier->RecordBindingPatternError(scanner()->location(), | 2077 classifier->RecordBindingPatternError(scanner()->location(), |
2092 MessageTemplate::kUnexpectedToken, | 2078 MessageTemplate::kUnexpectedToken, |
2093 Token::String(op)); | 2079 Token::String(op)); |
2094 } | 2080 } |
2095 int pos = position(); | 2081 int pos = position(); |
2096 | 2082 |
2097 ExpressionClassifier rhs_classifier; | 2083 ExpressionClassifier rhs_classifier; |
2098 | 2084 |
2099 int rhs_flags = flags; | 2085 ExpressionT right = |
2100 rhs_flags &= ~(kIsPatternElement | kIsPossibleArrowFormals); | 2086 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); |
2101 rhs_flags |= kIsRightHandSide; | 2087 right = Traits::RewriteNonPattern(right, &rhs_classifier, CHECK_OK); |
2102 ExpressionT right = this->ParseAssignmentExpression( | |
2103 accept_IN, rhs_flags, &rhs_classifier, CHECK_OK); | |
2104 right = Traits::RewriteExpression(right, &rhs_classifier, CHECK_OK); | |
2105 classifier->Accumulate( | 2088 classifier->Accumulate( |
2106 rhs_classifier, ExpressionClassifier::ExpressionProductions | | 2089 rhs_classifier, ExpressionClassifier::ExpressionProductions | |
2107 ExpressionClassifier::CoverInitializedNameProduction); | 2090 ExpressionClassifier::CoverInitializedNameProduction); |
2108 | 2091 |
2109 // TODO(1231235): We try to estimate the set of properties set by | 2092 // TODO(1231235): We try to estimate the set of properties set by |
2110 // constructors. We define a new property whenever there is an | 2093 // constructors. We define a new property whenever there is an |
2111 // assignment to a property of 'this'. We should probably only add | 2094 // assignment to a property of 'this'. We should probably only add |
2112 // properties if we haven't seen them before. Otherwise we'll | 2095 // properties if we haven't seen them before. Otherwise we'll |
2113 // probably overestimate the number of properties. | 2096 // probably overestimate the number of properties. |
2114 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { | 2097 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2167 // after an AssignmentExpression, and none of them can start an | 2150 // after an AssignmentExpression, and none of them can start an |
2168 // AssignmentExpression. This allows us to avoid looking for an RHS for | 2151 // AssignmentExpression. This allows us to avoid looking for an RHS for |
2169 // a Yield::kSuspend operation, given only one look-ahead token. | 2152 // a Yield::kSuspend operation, given only one look-ahead token. |
2170 if (kind == Yield::kSuspend) | 2153 if (kind == Yield::kSuspend) |
2171 break; | 2154 break; |
2172 DCHECK_EQ(Yield::kDelegating, kind); | 2155 DCHECK_EQ(Yield::kDelegating, kind); |
2173 // Delegating yields require an RHS; fall through. | 2156 // Delegating yields require an RHS; fall through. |
2174 default: | 2157 default: |
2175 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); | 2158 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); |
2176 expression = | 2159 expression = |
2177 Traits::RewriteExpression(expression, classifier, CHECK_OK); | 2160 Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
2178 break; | 2161 break; |
2179 } | 2162 } |
2180 } | 2163 } |
2181 if (kind == Yield::kDelegating) { | 2164 if (kind == Yield::kDelegating) { |
2182 // var iterator = subject[Symbol.iterator](); | 2165 // var iterator = subject[Symbol.iterator](); |
2183 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2166 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
2184 // TODO(verwaest): Come up with a better solution. | 2167 // TODO(verwaest): Come up with a better solution. |
2185 expression = this->GetIterator(expression, factory(), pos + 1); | 2168 expression = this->GetIterator(expression, factory(), pos + 1); |
2186 } | 2169 } |
2187 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2170 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
(...skipping 12 matching lines...) Expand all Loading... |
2200 bool* ok) { | 2183 bool* ok) { |
2201 // ConditionalExpression :: | 2184 // ConditionalExpression :: |
2202 // LogicalOrExpression | 2185 // LogicalOrExpression |
2203 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | 2186 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
2204 | 2187 |
2205 int pos = peek_position(); | 2188 int pos = peek_position(); |
2206 // We start using the binary expression parser for prec >= 4 only! | 2189 // We start using the binary expression parser for prec >= 4 only! |
2207 ExpressionT expression = | 2190 ExpressionT expression = |
2208 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); | 2191 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); |
2209 if (peek() != Token::CONDITIONAL) return expression; | 2192 if (peek() != Token::CONDITIONAL) return expression; |
2210 expression = Traits::RewriteExpression(expression, classifier, CHECK_OK); | 2193 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
2211 ArrowFormalParametersUnexpectedToken(classifier); | 2194 ArrowFormalParametersUnexpectedToken(classifier); |
2212 BindingPatternUnexpectedToken(classifier); | 2195 BindingPatternUnexpectedToken(classifier); |
2213 Consume(Token::CONDITIONAL); | 2196 Consume(Token::CONDITIONAL); |
2214 // In parsing the first assignment expression in conditional | 2197 // In parsing the first assignment expression in conditional |
2215 // expressions we always accept the 'in' keyword; see ECMA-262, | 2198 // expressions we always accept the 'in' keyword; see ECMA-262, |
2216 // section 11.12, page 58. | 2199 // section 11.12, page 58. |
2217 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); | 2200 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); |
2218 left = Traits::RewriteExpression(left, classifier, CHECK_OK); | 2201 left = Traits::RewriteNonPattern(left, classifier, CHECK_OK); |
2219 Expect(Token::COLON, CHECK_OK); | 2202 Expect(Token::COLON, CHECK_OK); |
2220 ExpressionT right = | 2203 ExpressionT right = |
2221 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2204 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
2222 right = Traits::RewriteExpression(right, classifier, CHECK_OK); | 2205 right = Traits::RewriteNonPattern(right, classifier, CHECK_OK); |
2223 return factory()->NewConditional(expression, left, right, pos); | 2206 return factory()->NewConditional(expression, left, right, pos); |
2224 } | 2207 } |
2225 | 2208 |
2226 | 2209 |
2227 // Precedence >= 4 | 2210 // Precedence >= 4 |
2228 template <class Traits> | 2211 template <class Traits> |
2229 typename ParserBase<Traits>::ExpressionT | 2212 typename ParserBase<Traits>::ExpressionT |
2230 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, | 2213 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, |
2231 ExpressionClassifier* classifier, | 2214 ExpressionClassifier* classifier, |
2232 bool* ok) { | 2215 bool* ok) { |
2233 DCHECK(prec >= 4); | 2216 DCHECK(prec >= 4); |
2234 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 2217 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
2235 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2218 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
2236 // prec1 >= 4 | 2219 // prec1 >= 4 |
2237 while (Precedence(peek(), accept_IN) == prec1) { | 2220 while (Precedence(peek(), accept_IN) == prec1) { |
2238 x = Traits::RewriteExpression(x, classifier, CHECK_OK); | 2221 x = Traits::RewriteNonPattern(x, classifier, CHECK_OK); |
2239 BindingPatternUnexpectedToken(classifier); | 2222 BindingPatternUnexpectedToken(classifier); |
2240 ArrowFormalParametersUnexpectedToken(classifier); | 2223 ArrowFormalParametersUnexpectedToken(classifier); |
2241 Token::Value op = Next(); | 2224 Token::Value op = Next(); |
2242 Scanner::Location op_location = scanner()->location(); | 2225 Scanner::Location op_location = scanner()->location(); |
2243 int pos = position(); | 2226 int pos = position(); |
2244 ExpressionT y = | 2227 ExpressionT y = |
2245 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); | 2228 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); |
2246 y = Traits::RewriteExpression(y, classifier, CHECK_OK); | 2229 y = Traits::RewriteNonPattern(y, classifier, CHECK_OK); |
2247 | 2230 |
2248 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 2231 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
2249 factory())) { | 2232 factory())) { |
2250 continue; | 2233 continue; |
2251 } | 2234 } |
2252 | 2235 |
2253 // For now we distinguish between comparisons and other binary | 2236 // For now we distinguish between comparisons and other binary |
2254 // operations. (We could combine the two and get rid of this | 2237 // operations. (We could combine the two and get rid of this |
2255 // code and AST node eventually.) | 2238 // code and AST node eventually.) |
2256 if (Token::IsCompareOp(op)) { | 2239 if (Token::IsCompareOp(op)) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2299 // '!' UnaryExpression | 2282 // '!' UnaryExpression |
2300 | 2283 |
2301 Token::Value op = peek(); | 2284 Token::Value op = peek(); |
2302 if (Token::IsUnaryOp(op)) { | 2285 if (Token::IsUnaryOp(op)) { |
2303 BindingPatternUnexpectedToken(classifier); | 2286 BindingPatternUnexpectedToken(classifier); |
2304 ArrowFormalParametersUnexpectedToken(classifier); | 2287 ArrowFormalParametersUnexpectedToken(classifier); |
2305 | 2288 |
2306 op = Next(); | 2289 op = Next(); |
2307 int pos = position(); | 2290 int pos = position(); |
2308 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); | 2291 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
2309 expression = Traits::RewriteExpression(expression, classifier, CHECK_OK); | 2292 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
2310 | 2293 |
2311 if (op == Token::DELETE && is_strict(language_mode())) { | 2294 if (op == Token::DELETE && is_strict(language_mode())) { |
2312 if (is_strong(language_mode())) { | 2295 if (is_strong(language_mode())) { |
2313 ReportMessage(MessageTemplate::kStrongDelete); | 2296 ReportMessage(MessageTemplate::kStrongDelete); |
2314 *ok = false; | 2297 *ok = false; |
2315 return this->EmptyExpression(); | 2298 return this->EmptyExpression(); |
2316 } else if (this->IsIdentifier(expression)) { | 2299 } else if (this->IsIdentifier(expression)) { |
2317 // "delete identifier" is a syntax error in strict mode. | 2300 // "delete identifier" is a syntax error in strict mode. |
2318 ReportMessage(MessageTemplate::kStrictDelete); | 2301 ReportMessage(MessageTemplate::kStrictDelete); |
2319 *ok = false; | 2302 *ok = false; |
2320 return this->EmptyExpression(); | 2303 return this->EmptyExpression(); |
2321 } | 2304 } |
2322 } | 2305 } |
2323 | 2306 |
2324 // Allow Traits do rewrite the expression. | 2307 // Allow Traits do rewrite the expression. |
2325 return this->BuildUnaryExpression(expression, op, pos, factory()); | 2308 return this->BuildUnaryExpression(expression, op, pos, factory()); |
2326 } else if (Token::IsCountOp(op)) { | 2309 } else if (Token::IsCountOp(op)) { |
2327 BindingPatternUnexpectedToken(classifier); | 2310 BindingPatternUnexpectedToken(classifier); |
2328 ArrowFormalParametersUnexpectedToken(classifier); | 2311 ArrowFormalParametersUnexpectedToken(classifier); |
2329 op = Next(); | 2312 op = Next(); |
2330 int beg_pos = peek_position(); | 2313 int beg_pos = peek_position(); |
2331 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 2314 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
2332 expression = this->CheckAndRewriteReferenceExpression( | 2315 expression = this->CheckAndRewriteReferenceExpression( |
2333 expression, beg_pos, scanner()->location().end_pos, | 2316 expression, beg_pos, scanner()->location().end_pos, |
2334 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2317 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
2335 this->MarkExpressionAsAssigned(expression); | 2318 this->MarkExpressionAsAssigned(expression); |
2336 expression = Traits::RewriteExpression(expression, classifier, CHECK_OK); | 2319 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
2337 | 2320 |
2338 return factory()->NewCountOperation(op, | 2321 return factory()->NewCountOperation(op, |
2339 true /* prefix */, | 2322 true /* prefix */, |
2340 expression, | 2323 expression, |
2341 position()); | 2324 position()); |
2342 | 2325 |
2343 } else { | 2326 } else { |
2344 return this->ParsePostfixExpression(classifier, ok); | 2327 return this->ParsePostfixExpression(classifier, ok); |
2345 } | 2328 } |
2346 } | 2329 } |
(...skipping 11 matching lines...) Expand all Loading... |
2358 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | 2341 this->ParseLeftHandSideExpression(classifier, CHECK_OK); |
2359 if (!scanner()->HasAnyLineTerminatorBeforeNext() && | 2342 if (!scanner()->HasAnyLineTerminatorBeforeNext() && |
2360 Token::IsCountOp(peek())) { | 2343 Token::IsCountOp(peek())) { |
2361 BindingPatternUnexpectedToken(classifier); | 2344 BindingPatternUnexpectedToken(classifier); |
2362 ArrowFormalParametersUnexpectedToken(classifier); | 2345 ArrowFormalParametersUnexpectedToken(classifier); |
2363 | 2346 |
2364 expression = this->CheckAndRewriteReferenceExpression( | 2347 expression = this->CheckAndRewriteReferenceExpression( |
2365 expression, lhs_beg_pos, scanner()->location().end_pos, | 2348 expression, lhs_beg_pos, scanner()->location().end_pos, |
2366 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); | 2349 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); |
2367 expression = this->MarkExpressionAsAssigned(expression); | 2350 expression = this->MarkExpressionAsAssigned(expression); |
2368 expression = Traits::RewriteExpression(expression, classifier, CHECK_OK); | 2351 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
2369 | 2352 |
2370 Token::Value next = Next(); | 2353 Token::Value next = Next(); |
2371 expression = | 2354 expression = |
2372 factory()->NewCountOperation(next, | 2355 factory()->NewCountOperation(next, |
2373 false /* postfix */, | 2356 false /* postfix */, |
2374 expression, | 2357 expression, |
2375 position()); | 2358 position()); |
2376 } | 2359 } |
2377 return expression; | 2360 return expression; |
2378 } | 2361 } |
(...skipping 10 matching lines...) Expand all Loading... |
2389 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2372 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
2390 | 2373 |
2391 while (true) { | 2374 while (true) { |
2392 switch (peek()) { | 2375 switch (peek()) { |
2393 case Token::LBRACK: { | 2376 case Token::LBRACK: { |
2394 BindingPatternUnexpectedToken(classifier); | 2377 BindingPatternUnexpectedToken(classifier); |
2395 ArrowFormalParametersUnexpectedToken(classifier); | 2378 ArrowFormalParametersUnexpectedToken(classifier); |
2396 Consume(Token::LBRACK); | 2379 Consume(Token::LBRACK); |
2397 int pos = position(); | 2380 int pos = position(); |
2398 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); | 2381 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); |
2399 index = Traits::RewriteExpression(index, classifier, CHECK_OK); | 2382 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); |
2400 result = factory()->NewProperty(result, index, pos); | 2383 result = factory()->NewProperty(result, index, pos); |
2401 Expect(Token::RBRACK, CHECK_OK); | 2384 Expect(Token::RBRACK, CHECK_OK); |
2402 break; | 2385 break; |
2403 } | 2386 } |
2404 | 2387 |
2405 case Token::LPAREN: { | 2388 case Token::LPAREN: { |
2406 result = Traits::RewriteExpression(result, classifier, CHECK_OK); | 2389 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); |
2407 BindingPatternUnexpectedToken(classifier); | 2390 BindingPatternUnexpectedToken(classifier); |
2408 ArrowFormalParametersUnexpectedToken(classifier); | 2391 ArrowFormalParametersUnexpectedToken(classifier); |
2409 | 2392 |
2410 if (is_strong(language_mode()) && this->IsIdentifier(result) && | 2393 if (is_strong(language_mode()) && this->IsIdentifier(result) && |
2411 this->IsEval(this->AsIdentifier(result))) { | 2394 this->IsEval(this->AsIdentifier(result))) { |
2412 ReportMessage(MessageTemplate::kStrongDirectEval); | 2395 ReportMessage(MessageTemplate::kStrongDirectEval); |
2413 *ok = false; | 2396 *ok = false; |
2414 return this->EmptyExpression(); | 2397 return this->EmptyExpression(); |
2415 } | 2398 } |
2416 int pos; | 2399 int pos; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2524 int new_pos = position(); | 2507 int new_pos = position(); |
2525 ExpressionT result = this->EmptyExpression(); | 2508 ExpressionT result = this->EmptyExpression(); |
2526 if (peek() == Token::SUPER) { | 2509 if (peek() == Token::SUPER) { |
2527 const bool is_new = true; | 2510 const bool is_new = true; |
2528 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2511 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
2529 } else if (peek() == Token::PERIOD) { | 2512 } else if (peek() == Token::PERIOD) { |
2530 return ParseNewTargetExpression(CHECK_OK); | 2513 return ParseNewTargetExpression(CHECK_OK); |
2531 } else { | 2514 } else { |
2532 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2515 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
2533 } | 2516 } |
2534 result = Traits::RewriteExpression(result, classifier, CHECK_OK); | 2517 result = Traits::RewriteNonPattern(result, classifier, CHECK_OK); |
2535 if (peek() == Token::LPAREN) { | 2518 if (peek() == Token::LPAREN) { |
2536 // NewExpression with arguments. | 2519 // NewExpression with arguments. |
2537 Scanner::Location spread_pos; | 2520 Scanner::Location spread_pos; |
2538 typename Traits::Type::ExpressionList args = | 2521 typename Traits::Type::ExpressionList args = |
2539 this->ParseArguments(&spread_pos, classifier, CHECK_OK); | 2522 this->ParseArguments(&spread_pos, classifier, CHECK_OK); |
2540 | 2523 |
2541 if (spread_pos.IsValid()) { | 2524 if (spread_pos.IsValid()) { |
2542 args = Traits::PrepareSpreadArguments(args); | 2525 args = Traits::PrepareSpreadArguments(args); |
2543 result = Traits::SpreadCallNew(result, args, new_pos); | 2526 result = Traits::SpreadCallNew(result, args, new_pos); |
2544 } else { | 2527 } else { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2624 int pos = position(); | 2607 int pos = position(); |
2625 function_state_->set_this_location(scanner()->location()); | 2608 function_state_->set_this_location(scanner()->location()); |
2626 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 2609 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); |
2627 | 2610 |
2628 ExpressionT left = this->EmptyExpression(); | 2611 ExpressionT left = this->EmptyExpression(); |
2629 switch (peek()) { | 2612 switch (peek()) { |
2630 case Token::LBRACK: { | 2613 case Token::LBRACK: { |
2631 Consume(Token::LBRACK); | 2614 Consume(Token::LBRACK); |
2632 int pos = position(); | 2615 int pos = position(); |
2633 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2616 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
2634 index = Traits::RewriteExpression(index, classifier, CHECK_OK); | 2617 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); |
2635 left = factory()->NewProperty(this_expr, index, pos); | 2618 left = factory()->NewProperty(this_expr, index, pos); |
2636 if (fni_ != NULL) { | 2619 if (fni_ != NULL) { |
2637 this->PushPropertyName(fni_, index); | 2620 this->PushPropertyName(fni_, index); |
2638 } | 2621 } |
2639 Expect(Token::RBRACK, CHECK_OK); | 2622 Expect(Token::RBRACK, CHECK_OK); |
2640 break; | 2623 break; |
2641 } | 2624 } |
2642 case Token::PERIOD: { | 2625 case Token::PERIOD: { |
2643 Consume(Token::PERIOD); | 2626 Consume(Token::PERIOD); |
2644 int pos = position(); | 2627 int pos = position(); |
(...skipping 15 matching lines...) Expand all Loading... |
2660 ReportMessageAt(function_state_->this_location(), | 2643 ReportMessageAt(function_state_->this_location(), |
2661 MessageTemplate::kStrongConstructorThis); | 2644 MessageTemplate::kStrongConstructorThis); |
2662 *ok = false; | 2645 *ok = false; |
2663 return this->EmptyExpression(); | 2646 return this->EmptyExpression(); |
2664 } | 2647 } |
2665 Consume(Token::ASSIGN); | 2648 Consume(Token::ASSIGN); |
2666 left = this->MarkExpressionAsAssigned(left); | 2649 left = this->MarkExpressionAsAssigned(left); |
2667 | 2650 |
2668 ExpressionT right = | 2651 ExpressionT right = |
2669 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 2652 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
2670 right = Traits::RewriteExpression(right, classifier, CHECK_OK); | 2653 right = Traits::RewriteNonPattern(right, classifier, CHECK_OK); |
2671 this->CheckAssigningFunctionLiteralToProperty(left, right); | 2654 this->CheckAssigningFunctionLiteralToProperty(left, right); |
2672 function_state_->AddProperty(); | 2655 function_state_->AddProperty(); |
2673 if (fni_ != NULL) { | 2656 if (fni_ != NULL) { |
2674 // Check if the right hand side is a call to avoid inferring a | 2657 // Check if the right hand side is a call to avoid inferring a |
2675 // name if we're dealing with "this.a = function(){...}();"-like | 2658 // name if we're dealing with "this.a = function(){...}();"-like |
2676 // expression. | 2659 // expression. |
2677 if (!right->IsCall() && !right->IsCallNew()) { | 2660 if (!right->IsCall() && !right->IsCallNew()) { |
2678 fni_->Infer(); | 2661 fni_->Infer(); |
2679 } else { | 2662 } else { |
2680 fni_->RemoveLastFunction(); | 2663 fni_->RemoveLastFunction(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2817 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 2800 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
2818 while (true) { | 2801 while (true) { |
2819 switch (peek()) { | 2802 switch (peek()) { |
2820 case Token::LBRACK: { | 2803 case Token::LBRACK: { |
2821 BindingPatternUnexpectedToken(classifier); | 2804 BindingPatternUnexpectedToken(classifier); |
2822 ArrowFormalParametersUnexpectedToken(classifier); | 2805 ArrowFormalParametersUnexpectedToken(classifier); |
2823 | 2806 |
2824 Consume(Token::LBRACK); | 2807 Consume(Token::LBRACK); |
2825 int pos = position(); | 2808 int pos = position(); |
2826 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2809 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
2827 index = Traits::RewriteExpression(index, classifier, CHECK_OK); | 2810 index = Traits::RewriteNonPattern(index, classifier, CHECK_OK); |
2828 expression = factory()->NewProperty(expression, index, pos); | 2811 expression = factory()->NewProperty(expression, index, pos); |
2829 if (fni_ != NULL) { | 2812 if (fni_ != NULL) { |
2830 this->PushPropertyName(fni_, index); | 2813 this->PushPropertyName(fni_, index); |
2831 } | 2814 } |
2832 Expect(Token::RBRACK, CHECK_OK); | 2815 Expect(Token::RBRACK, CHECK_OK); |
2833 break; | 2816 break; |
2834 } | 2817 } |
2835 case Token::PERIOD: { | 2818 case Token::PERIOD: { |
2836 BindingPatternUnexpectedToken(classifier); | 2819 BindingPatternUnexpectedToken(classifier); |
2837 ArrowFormalParametersUnexpectedToken(classifier); | 2820 ArrowFormalParametersUnexpectedToken(classifier); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2898 ValidateFormalParameterInitializer(classifier, ok); | 2881 ValidateFormalParameterInitializer(classifier, ok); |
2899 if (!*ok) return; | 2882 if (!*ok) return; |
2900 classifier->RecordNonSimpleParameter(); | 2883 classifier->RecordNonSimpleParameter(); |
2901 } | 2884 } |
2902 | 2885 |
2903 ExpressionT initializer = Traits::EmptyExpression(); | 2886 ExpressionT initializer = Traits::EmptyExpression(); |
2904 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { | 2887 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { |
2905 ExpressionClassifier init_classifier; | 2888 ExpressionClassifier init_classifier; |
2906 initializer = ParseAssignmentExpression(true, &init_classifier, ok); | 2889 initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
2907 if (!*ok) return; | 2890 if (!*ok) return; |
2908 initializer = Traits::RewriteExpression(initializer, &init_classifier, ok); | 2891 initializer = Traits::RewriteNonPattern(initializer, &init_classifier, ok); |
2909 ValidateFormalParameterInitializer(&init_classifier, ok); | 2892 ValidateFormalParameterInitializer(&init_classifier, ok); |
2910 if (!*ok) return; | 2893 if (!*ok) return; |
2911 parameters->is_simple = false; | 2894 parameters->is_simple = false; |
2912 classifier->RecordNonSimpleParameter(); | 2895 classifier->RecordNonSimpleParameter(); |
2913 } | 2896 } |
2914 | 2897 |
2915 Traits::AddFormalParameter(parameters, pattern, initializer, | 2898 Traits::AddFormalParameter(parameters, pattern, initializer, |
2916 scanner()->location().end_pos, is_rest); | 2899 scanner()->location().end_pos, is_rest); |
2917 } | 2900 } |
2918 | 2901 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3072 function_state.materialized_literal_count(); | 3055 function_state.materialized_literal_count(); |
3073 expected_property_count = function_state.expected_property_count(); | 3056 expected_property_count = function_state.expected_property_count(); |
3074 } | 3057 } |
3075 } else { | 3058 } else { |
3076 // Single-expression body | 3059 // Single-expression body |
3077 int pos = position(); | 3060 int pos = position(); |
3078 parenthesized_function_ = false; | 3061 parenthesized_function_ = false; |
3079 ExpressionClassifier classifier; | 3062 ExpressionClassifier classifier; |
3080 ExpressionT expression = | 3063 ExpressionT expression = |
3081 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); | 3064 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); |
3082 expression = Traits::RewriteExpression(expression, &classifier, CHECK_OK); | 3065 expression = Traits::RewriteNonPattern(expression, &classifier, CHECK_OK); |
3083 body = this->NewStatementList(1, zone()); | 3066 body = this->NewStatementList(1, zone()); |
3084 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); | 3067 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); |
3085 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3068 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3086 materialized_literal_count = function_state.materialized_literal_count(); | 3069 materialized_literal_count = function_state.materialized_literal_count(); |
3087 expected_property_count = function_state.expected_property_count(); | 3070 expected_property_count = function_state.expected_property_count(); |
3088 } | 3071 } |
3089 super_loc = function_state.super_location(); | 3072 super_loc = function_state.super_location(); |
3090 | 3073 |
3091 formal_parameters.scope->set_end_position(scanner()->location().end_pos); | 3074 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
3092 | 3075 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3178 } else if (next == Token::ILLEGAL) { | 3161 } else if (next == Token::ILLEGAL) { |
3179 Traits::ReportMessageAt( | 3162 Traits::ReportMessageAt( |
3180 Scanner::Location(position() + 1, peek_position()), | 3163 Scanner::Location(position() + 1, peek_position()), |
3181 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); | 3164 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); |
3182 *ok = false; | 3165 *ok = false; |
3183 return Traits::EmptyExpression(); | 3166 return Traits::EmptyExpression(); |
3184 } | 3167 } |
3185 | 3168 |
3186 int expr_pos = peek_position(); | 3169 int expr_pos = peek_position(); |
3187 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); | 3170 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); |
3188 expression = Traits::RewriteExpression(expression, classifier, CHECK_OK); | 3171 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
3189 Traits::AddTemplateExpression(&ts, expression); | 3172 Traits::AddTemplateExpression(&ts, expression); |
3190 | 3173 |
3191 if (peek() != Token::RBRACE) { | 3174 if (peek() != Token::RBRACE) { |
3192 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), | 3175 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), |
3193 MessageTemplate::kUnterminatedTemplateExpr); | 3176 MessageTemplate::kUnterminatedTemplateExpr); |
3194 *ok = false; | 3177 *ok = false; |
3195 return Traits::EmptyExpression(); | 3178 return Traits::EmptyExpression(); |
3196 } | 3179 } |
3197 | 3180 |
3198 // If we didn't die parsing that expression, our next token should be a | 3181 // If we didn't die parsing that expression, our next token should be a |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3361 return; | 3344 return; |
3362 } | 3345 } |
3363 has_seen_constructor_ = true; | 3346 has_seen_constructor_ = true; |
3364 return; | 3347 return; |
3365 } | 3348 } |
3366 } | 3349 } |
3367 } // namespace internal | 3350 } // namespace internal |
3368 } // namespace v8 | 3351 } // namespace v8 |
3369 | 3352 |
3370 #endif // V8_PARSING_PARSER_BASE_H | 3353 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |