Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: src/parsing/parser-base.h

Issue 2277843002: [parser] Clean up (pre)parser traits, part 5, last (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@nickie-2274113002-ref-traits
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // class ParserBase : public ParserBaseTraits<Impl> { ... }; 154 // class ParserBase : public ParserBaseTraits<Impl> { ... };
155 // 155 //
156 // // And then, for each parser variant (e.g., parser, preparser, etc): 156 // // And then, for each parser variant (e.g., parser, preparser, etc):
157 // class Parser; 157 // class Parser;
158 // 158 //
159 // template <> 159 // template <>
160 // class ParserBaseTraits<Parser> { ... }; 160 // class ParserBaseTraits<Parser> { ... };
161 // 161 //
162 // class Parser : public ParserBase<Parser> { ... }; 162 // class Parser : public ParserBase<Parser> { ... };
163 // 163 //
164 // TODO(nikolaos): Currently the traits objects contain many things
165 // that will be moved to the implementation objects or to the parser
166 // base. The following comments will have to change, when this happens.
167
168 // The traits class template encapsulates the differences between 164 // The traits class template encapsulates the differences between
169 // parser/pre-parser implementations. In particular: 165 // parser/pre-parser implementations. In particular:
170 166
171 // - Return types: For example, Parser functions return Expression* and 167 // - Return types: For example, Parser functions return Expression* and
172 // PreParser functions return PreParserExpression. 168 // PreParser functions return PreParserExpression.
173 169
174 // - Creating parse tree nodes: Parser generates an AST during the recursive 170 // - Creating parse tree nodes: Parser generates an AST during the recursive
175 // descent. PreParser doesn't create a tree. Instead, it passes around minimal 171 // descent. PreParser doesn't create a tree. Instead, it passes around minimal
176 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain 172 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain
177 // just enough data for the upper layer functions. PreParserFactory is 173 // just enough data for the upper layer functions. PreParserFactory is
178 // responsible for creating these dummy objects. It provides a similar kind of 174 // responsible for creating these dummy objects. It provides a similar kind of
179 // interface as AstNodeFactory, so ParserBase doesn't need to care which one is 175 // interface as AstNodeFactory, so ParserBase doesn't need to care which one is
180 // used. 176 // used.
181 177
182 // - Miscellaneous other tasks interleaved with the recursive descent. For
183 // example, Parser keeps track of which function literals should be marked as
184 // pretenured, and PreParser doesn't care.
185
186 // The traits are expected to contain the following typedefs: 178 // The traits are expected to contain the following typedefs:
187 // template <> 179 // template <>
188 // class ParserBaseTraits<Impl> { 180 // class ParserBaseTraits<Impl> {
189 // // In particular... 181 // // In particular...
190 // struct Type { 182 // struct Type {
183 // // Synonyms for ParserBase<Impl> and Impl, respectively.
184 // typedef Base;
185 // typedef Impl;
191 // typedef GeneratorVariable; 186 // typedef GeneratorVariable;
192 // typedef AstProperties; 187 // typedef AstProperties;
193 // typedef ExpressionClassifier; 188 // typedef ExpressionClassifier;
194 // // Return types for traversing functions. 189 // // Return types for traversing functions.
195 // typedef Identifier; 190 // typedef Identifier;
196 // typedef Expression; 191 // typedef Expression;
197 // typedef YieldExpression; 192 // typedef YieldExpression;
198 // typedef FunctionLiteral; 193 // typedef FunctionLiteral;
199 // typedef ClassLiteral; 194 // typedef ClassLiteral;
200 // typedef Literal; 195 // typedef Literal;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ALLOW_ACCESSORS(harmony_async_await); 268 ALLOW_ACCESSORS(harmony_async_await);
274 ALLOW_ACCESSORS(harmony_restrictive_generators); 269 ALLOW_ACCESSORS(harmony_restrictive_generators);
275 ALLOW_ACCESSORS(harmony_trailing_commas); 270 ALLOW_ACCESSORS(harmony_trailing_commas);
276 271
277 #undef ALLOW_ACCESSORS 272 #undef ALLOW_ACCESSORS
278 273
279 uintptr_t stack_limit() const { return stack_limit_; } 274 uintptr_t stack_limit() const { return stack_limit_; }
280 275
281 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } 276 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
282 277
278 Zone* zone() const { return zone_; }
279
283 protected: 280 protected:
284 enum AllowRestrictedIdentifiers { 281 enum AllowRestrictedIdentifiers {
285 kAllowRestrictedIdentifiers, 282 kAllowRestrictedIdentifiers,
286 kDontAllowRestrictedIdentifiers 283 kDontAllowRestrictedIdentifiers
287 }; 284 };
288 285
289 enum Mode { 286 enum Mode {
290 PARSE_LAZILY, 287 PARSE_LAZILY,
291 PARSE_EAGERLY 288 PARSE_EAGERLY
292 }; 289 };
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 return result; 686 return result;
690 } 687 }
691 688
692 Scanner* scanner() const { return scanner_; } 689 Scanner* scanner() const { return scanner_; }
693 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } 690 AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
694 int position() const { return scanner_->location().beg_pos; } 691 int position() const { return scanner_->location().beg_pos; }
695 int peek_position() const { return scanner_->peek_location().beg_pos; } 692 int peek_position() const { return scanner_->peek_location().beg_pos; }
696 bool stack_overflow() const { return stack_overflow_; } 693 bool stack_overflow() const { return stack_overflow_; }
697 void set_stack_overflow() { stack_overflow_ = true; } 694 void set_stack_overflow() { stack_overflow_ = true; }
698 Mode mode() const { return mode_; } 695 Mode mode() const { return mode_; }
699 Zone* zone() const { return zone_; }
700 696
701 INLINE(Token::Value peek()) { 697 INLINE(Token::Value peek()) {
702 if (stack_overflow_) return Token::ILLEGAL; 698 if (stack_overflow_) return Token::ILLEGAL;
703 return scanner()->peek(); 699 return scanner()->peek();
704 } 700 }
705 701
706 INLINE(Token::Value PeekAhead()) { 702 INLINE(Token::Value PeekAhead()) {
707 if (stack_overflow_) return Token::ILLEGAL; 703 if (stack_overflow_) return Token::ILLEGAL;
708 return scanner()->PeekAhead(); 704 return scanner()->PeekAhead();
709 } 705 }
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 return impl()->EmptyIdentifier(); 1458 return impl()->EmptyIdentifier();
1463 } 1459 }
1464 if (next == Token::LET || 1460 if (next == Token::LET ||
1465 (next == Token::ESCAPED_STRICT_RESERVED_WORD && 1461 (next == Token::ESCAPED_STRICT_RESERVED_WORD &&
1466 scanner()->is_literal_contextual_keyword(CStrVector("let")))) { 1462 scanner()->is_literal_contextual_keyword(CStrVector("let")))) {
1467 classifier->RecordLetPatternError(scanner()->location(), 1463 classifier->RecordLetPatternError(scanner()->location(),
1468 MessageTemplate::kLetInLexicalBinding); 1464 MessageTemplate::kLetInLexicalBinding);
1469 } 1465 }
1470 return impl()->GetSymbol(); 1466 return impl()->GetSymbol();
1471 } else { 1467 } else {
1472 this->ReportUnexpectedToken(next); 1468 ReportUnexpectedToken(next);
1473 *ok = false; 1469 *ok = false;
1474 return impl()->EmptyIdentifier(); 1470 return impl()->EmptyIdentifier();
1475 } 1471 }
1476 } 1472 }
1477 1473
1478 template <class Impl> 1474 template <class Impl>
1479 typename ParserBase<Impl>::IdentifierT 1475 typename ParserBase<Impl>::IdentifierT
1480 ParserBase<Impl>::ParseIdentifierOrStrictReservedWord( 1476 ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(
1481 FunctionKind function_kind, bool* is_strict_reserved, bool* ok) { 1477 FunctionKind function_kind, bool* is_strict_reserved, bool* ok) {
1482 Token::Value next = Next(); 1478 Token::Value next = Next();
(...skipping 17 matching lines...) Expand all
1500 template <typename Impl> 1496 template <typename Impl>
1501 typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName( 1497 typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName(
1502 bool* ok) { 1498 bool* ok) {
1503 Token::Value next = Next(); 1499 Token::Value next = Next();
1504 if (next != Token::IDENTIFIER && next != Token::ASYNC && 1500 if (next != Token::IDENTIFIER && next != Token::ASYNC &&
1505 next != Token::ENUM && next != Token::AWAIT && next != Token::LET && 1501 next != Token::ENUM && next != Token::AWAIT && next != Token::LET &&
1506 next != Token::STATIC && next != Token::YIELD && 1502 next != Token::STATIC && next != Token::YIELD &&
1507 next != Token::FUTURE_STRICT_RESERVED_WORD && 1503 next != Token::FUTURE_STRICT_RESERVED_WORD &&
1508 next != Token::ESCAPED_KEYWORD && 1504 next != Token::ESCAPED_KEYWORD &&
1509 next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { 1505 next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) {
1510 this->ReportUnexpectedToken(next); 1506 ReportUnexpectedToken(next);
1511 *ok = false; 1507 *ok = false;
1512 return impl()->EmptyIdentifier(); 1508 return impl()->EmptyIdentifier();
1513 } 1509 }
1514 1510
1515 return impl()->GetSymbol(); 1511 return impl()->GetSymbol();
1516 } 1512 }
1517 1513
1518 template <typename Impl> 1514 template <typename Impl>
1519 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral( 1515 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseRegExpLiteral(
1520 bool* ok) { 1516 bool* ok) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 case Token::STRING: { 1599 case Token::STRING: {
1604 BindingPatternUnexpectedToken(classifier); 1600 BindingPatternUnexpectedToken(classifier);
1605 Consume(Token::STRING); 1601 Consume(Token::STRING);
1606 return impl()->ExpressionFromString(beg_pos); 1602 return impl()->ExpressionFromString(beg_pos);
1607 } 1603 }
1608 1604
1609 case Token::ASSIGN_DIV: 1605 case Token::ASSIGN_DIV:
1610 case Token::DIV: 1606 case Token::DIV:
1611 classifier->RecordBindingPatternError( 1607 classifier->RecordBindingPatternError(
1612 scanner()->peek_location(), MessageTemplate::kUnexpectedTokenRegExp); 1608 scanner()->peek_location(), MessageTemplate::kUnexpectedTokenRegExp);
1613 return this->ParseRegExpLiteral(ok); 1609 return ParseRegExpLiteral(ok);
1614 1610
1615 case Token::LBRACK: 1611 case Token::LBRACK:
1616 return this->ParseArrayLiteral(classifier, ok); 1612 return ParseArrayLiteral(classifier, ok);
1617 1613
1618 case Token::LBRACE: 1614 case Token::LBRACE:
1619 return this->ParseObjectLiteral(classifier, ok); 1615 return ParseObjectLiteral(classifier, ok);
1620 1616
1621 case Token::LPAREN: { 1617 case Token::LPAREN: {
1622 // Arrow function formal parameters are either a single identifier or a 1618 // Arrow function formal parameters are either a single identifier or a
1623 // list of BindingPattern productions enclosed in parentheses. 1619 // list of BindingPattern productions enclosed in parentheses.
1624 // Parentheses are not valid on the LHS of a BindingPattern, so we use the 1620 // Parentheses are not valid on the LHS of a BindingPattern, so we use the
1625 // is_valid_binding_pattern() check to detect multiple levels of 1621 // is_valid_binding_pattern() check to detect multiple levels of
1626 // parenthesization. 1622 // parenthesization.
1627 bool pattern_error = !classifier->is_valid_binding_pattern(); 1623 bool pattern_error = !classifier->is_valid_binding_pattern();
1628 classifier->RecordPatternError(scanner()->peek_location(), 1624 classifier->RecordPatternError(scanner()->peek_location(),
1629 MessageTemplate::kUnexpectedToken, 1625 MessageTemplate::kUnexpectedToken,
(...skipping 10 matching lines...) Expand all
1640 } else if (Check(Token::ELLIPSIS)) { 1636 } else if (Check(Token::ELLIPSIS)) {
1641 // (...x)=>x. The continuation that looks for the => is in 1637 // (...x)=>x. The continuation that looks for the => is in
1642 // ParseAssignmentExpression. 1638 // ParseAssignmentExpression.
1643 int ellipsis_pos = position(); 1639 int ellipsis_pos = position();
1644 int expr_pos = peek_position(); 1640 int expr_pos = peek_position();
1645 classifier->RecordExpressionError(scanner()->location(), 1641 classifier->RecordExpressionError(scanner()->location(),
1646 MessageTemplate::kUnexpectedToken, 1642 MessageTemplate::kUnexpectedToken,
1647 Token::String(Token::ELLIPSIS)); 1643 Token::String(Token::ELLIPSIS));
1648 classifier->RecordNonSimpleParameter(); 1644 classifier->RecordNonSimpleParameter();
1649 ExpressionClassifier binding_classifier(this); 1645 ExpressionClassifier binding_classifier(this);
1650 ExpressionT expr = this->ParseAssignmentExpression( 1646 ExpressionT expr =
1651 true, &binding_classifier, CHECK_OK); 1647 ParseAssignmentExpression(true, &binding_classifier, CHECK_OK);
1652 classifier->Accumulate(&binding_classifier, 1648 classifier->Accumulate(&binding_classifier,
1653 ExpressionClassifier::AllProductions); 1649 ExpressionClassifier::AllProductions);
1654 if (!impl()->IsIdentifier(expr) && !IsValidPattern(expr)) { 1650 if (!impl()->IsIdentifier(expr) && !IsValidPattern(expr)) {
1655 classifier->RecordArrowFormalParametersError( 1651 classifier->RecordArrowFormalParametersError(
1656 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), 1652 Scanner::Location(ellipsis_pos, scanner()->location().end_pos),
1657 MessageTemplate::kInvalidRestParameter); 1653 MessageTemplate::kInvalidRestParameter);
1658 } 1654 }
1659 if (peek() == Token::COMMA) { 1655 if (peek() == Token::COMMA) {
1660 impl()->ReportMessageAt(scanner()->peek_location(), 1656 impl()->ReportMessageAt(scanner()->peek_location(),
1661 MessageTemplate::kParamAfterRest); 1657 MessageTemplate::kParamAfterRest);
1662 *ok = false; 1658 *ok = false;
1663 return impl()->EmptyExpression(); 1659 return impl()->EmptyExpression();
1664 } 1660 }
1665 Expect(Token::RPAREN, CHECK_OK); 1661 Expect(Token::RPAREN, CHECK_OK);
1666 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); 1662 return factory()->NewSpread(expr, ellipsis_pos, expr_pos);
1667 } 1663 }
1668 // Heuristically try to detect immediately called functions before 1664 // Heuristically try to detect immediately called functions before
1669 // seeing the call parentheses. 1665 // seeing the call parentheses.
1670 function_state_->set_next_function_is_parenthesized(peek() == 1666 function_state_->set_next_function_is_parenthesized(peek() ==
1671 Token::FUNCTION); 1667 Token::FUNCTION);
1672 ExpressionT expr = this->ParseExpression(true, classifier, CHECK_OK); 1668 ExpressionT expr = ParseExpression(true, classifier, CHECK_OK);
1673 Expect(Token::RPAREN, CHECK_OK); 1669 Expect(Token::RPAREN, CHECK_OK);
1674 return expr; 1670 return expr;
1675 } 1671 }
1676 1672
1677 case Token::CLASS: { 1673 case Token::CLASS: {
1678 BindingPatternUnexpectedToken(classifier); 1674 BindingPatternUnexpectedToken(classifier);
1679 Consume(Token::CLASS); 1675 Consume(Token::CLASS);
1680 int class_token_position = position(); 1676 int class_token_position = position();
1681 IdentifierT name = impl()->EmptyIdentifier(); 1677 IdentifierT name = impl()->EmptyIdentifier();
1682 bool is_strict_reserved_name = false; 1678 bool is_strict_reserved_name = false;
1683 Scanner::Location class_name_location = Scanner::Location::invalid(); 1679 Scanner::Location class_name_location = Scanner::Location::invalid();
1684 if (peek_any_identifier()) { 1680 if (peek_any_identifier()) {
1685 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 1681 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
1686 CHECK_OK); 1682 CHECK_OK);
1687 class_name_location = scanner()->location(); 1683 class_name_location = scanner()->location();
1688 } 1684 }
1689 return impl()->ParseClassLiteral(classifier, name, class_name_location, 1685 return impl()->ParseClassLiteral(classifier, name, class_name_location,
1690 is_strict_reserved_name, 1686 is_strict_reserved_name,
1691 class_token_position, ok); 1687 class_token_position, ok);
1692 } 1688 }
1693 1689
1694 case Token::TEMPLATE_SPAN: 1690 case Token::TEMPLATE_SPAN:
1695 case Token::TEMPLATE_TAIL: 1691 case Token::TEMPLATE_TAIL:
1696 BindingPatternUnexpectedToken(classifier); 1692 BindingPatternUnexpectedToken(classifier);
1697 return this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, 1693 return ParseTemplateLiteral(impl()->NoTemplateTag(), beg_pos, classifier,
1698 classifier, ok); 1694 ok);
1699 1695
1700 case Token::MOD: 1696 case Token::MOD:
1701 if (allow_natives() || extension_ != NULL) { 1697 if (allow_natives() || extension_ != NULL) {
1702 BindingPatternUnexpectedToken(classifier); 1698 BindingPatternUnexpectedToken(classifier);
1703 return impl()->ParseV8Intrinsic(ok); 1699 return impl()->ParseV8Intrinsic(ok);
1704 } 1700 }
1705 break; 1701 break;
1706 1702
1707 case Token::DO: 1703 case Token::DO:
1708 if (allow_harmony_do_expressions()) { 1704 if (allow_harmony_do_expressions()) {
(...skipping 23 matching lines...) Expand all
1732 template <typename Impl> 1728 template <typename Impl>
1733 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseExpression( 1729 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseExpression(
1734 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { 1730 bool accept_IN, ExpressionClassifier* classifier, bool* ok) {
1735 // Expression :: 1731 // Expression ::
1736 // AssignmentExpression 1732 // AssignmentExpression
1737 // Expression ',' AssignmentExpression 1733 // Expression ',' AssignmentExpression
1738 1734
1739 ExpressionT result; 1735 ExpressionT result;
1740 { 1736 {
1741 ExpressionClassifier binding_classifier(this); 1737 ExpressionClassifier binding_classifier(this);
1742 result = this->ParseAssignmentExpression(accept_IN, &binding_classifier, 1738 result =
1743 CHECK_OK); 1739 ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK);
1744 classifier->Accumulate(&binding_classifier, 1740 classifier->Accumulate(&binding_classifier,
1745 ExpressionClassifier::AllProductions); 1741 ExpressionClassifier::AllProductions);
1746 } 1742 }
1747 bool is_simple_parameter_list = impl()->IsIdentifier(result); 1743 bool is_simple_parameter_list = impl()->IsIdentifier(result);
1748 bool seen_rest = false; 1744 bool seen_rest = false;
1749 while (peek() == Token::COMMA) { 1745 while (peek() == Token::COMMA) {
1750 CheckNoTailCallExpressions(classifier, CHECK_OK); 1746 CheckNoTailCallExpressions(classifier, CHECK_OK);
1751 if (seen_rest) { 1747 if (seen_rest) {
1752 // At this point the production can't possibly be valid, but we don't know 1748 // At this point the production can't possibly be valid, but we don't know
1753 // which error to signal. 1749 // which error to signal.
(...skipping 10 matching lines...) Expand all
1764 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only 1760 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only
1765 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a 1761 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a
1766 // valid expression or binding pattern. 1762 // valid expression or binding pattern.
1767 ExpressionUnexpectedToken(classifier); 1763 ExpressionUnexpectedToken(classifier);
1768 BindingPatternUnexpectedToken(classifier); 1764 BindingPatternUnexpectedToken(classifier);
1769 Consume(Token::ELLIPSIS); 1765 Consume(Token::ELLIPSIS);
1770 seen_rest = is_rest = true; 1766 seen_rest = is_rest = true;
1771 } 1767 }
1772 int pos = position(), expr_pos = peek_position(); 1768 int pos = position(), expr_pos = peek_position();
1773 ExpressionClassifier binding_classifier(this); 1769 ExpressionClassifier binding_classifier(this);
1774 ExpressionT right = this->ParseAssignmentExpression( 1770 ExpressionT right =
1775 accept_IN, &binding_classifier, CHECK_OK); 1771 ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK);
1776 classifier->Accumulate(&binding_classifier, 1772 classifier->Accumulate(&binding_classifier,
1777 ExpressionClassifier::AllProductions); 1773 ExpressionClassifier::AllProductions);
1778 if (is_rest) { 1774 if (is_rest) {
1779 if (!impl()->IsIdentifier(right) && !IsValidPattern(right)) { 1775 if (!impl()->IsIdentifier(right) && !IsValidPattern(right)) {
1780 classifier->RecordArrowFormalParametersError( 1776 classifier->RecordArrowFormalParametersError(
1781 Scanner::Location(pos, scanner()->location().end_pos), 1777 Scanner::Location(pos, scanner()->location().end_pos),
1782 MessageTemplate::kInvalidRestParameter); 1778 MessageTemplate::kInvalidRestParameter);
1783 } 1779 }
1784 right = factory()->NewSpread(right, pos, expr_pos); 1780 right = factory()->NewSpread(right, pos, expr_pos);
1785 } 1781 }
(...skipping 20 matching lines...) Expand all
1806 Expect(Token::LBRACK, CHECK_OK); 1802 Expect(Token::LBRACK, CHECK_OK);
1807 while (peek() != Token::RBRACK) { 1803 while (peek() != Token::RBRACK) {
1808 ExpressionT elem; 1804 ExpressionT elem;
1809 if (peek() == Token::COMMA) { 1805 if (peek() == Token::COMMA) {
1810 elem = impl()->GetLiteralTheHole(peek_position()); 1806 elem = impl()->GetLiteralTheHole(peek_position());
1811 } else if (peek() == Token::ELLIPSIS) { 1807 } else if (peek() == Token::ELLIPSIS) {
1812 int start_pos = peek_position(); 1808 int start_pos = peek_position();
1813 Consume(Token::ELLIPSIS); 1809 Consume(Token::ELLIPSIS);
1814 int expr_pos = peek_position(); 1810 int expr_pos = peek_position();
1815 ExpressionT argument = 1811 ExpressionT argument =
1816 this->ParseAssignmentExpression(true, classifier, CHECK_OK); 1812 ParseAssignmentExpression(true, classifier, CHECK_OK);
1817 CheckNoTailCallExpressions(classifier, CHECK_OK); 1813 CheckNoTailCallExpressions(classifier, CHECK_OK);
1818 elem = factory()->NewSpread(argument, start_pos, expr_pos); 1814 elem = factory()->NewSpread(argument, start_pos, expr_pos);
1819 1815
1820 if (first_spread_index < 0) { 1816 if (first_spread_index < 0) {
1821 first_spread_index = values->length(); 1817 first_spread_index = values->length();
1822 } 1818 }
1823 1819
1824 if (argument->IsAssignment()) { 1820 if (argument->IsAssignment()) {
1825 classifier->RecordPatternError( 1821 classifier->RecordPatternError(
1826 Scanner::Location(start_pos, scanner()->location().end_pos), 1822 Scanner::Location(start_pos, scanner()->location().end_pos),
1827 MessageTemplate::kInvalidDestructuringTarget); 1823 MessageTemplate::kInvalidDestructuringTarget);
1828 } else { 1824 } else {
1829 CheckDestructuringElement(argument, classifier, start_pos, 1825 CheckDestructuringElement(argument, classifier, start_pos,
1830 scanner()->location().end_pos); 1826 scanner()->location().end_pos);
1831 } 1827 }
1832 1828
1833 if (peek() == Token::COMMA) { 1829 if (peek() == Token::COMMA) {
1834 classifier->RecordPatternError( 1830 classifier->RecordPatternError(
1835 Scanner::Location(start_pos, scanner()->location().end_pos), 1831 Scanner::Location(start_pos, scanner()->location().end_pos),
1836 MessageTemplate::kElementAfterRest); 1832 MessageTemplate::kElementAfterRest);
1837 } 1833 }
1838 } else { 1834 } else {
1839 int beg_pos = peek_position(); 1835 int beg_pos = peek_position();
1840 elem = this->ParseAssignmentExpression(true, classifier, CHECK_OK); 1836 elem = ParseAssignmentExpression(true, classifier, CHECK_OK);
1841 CheckNoTailCallExpressions(classifier, CHECK_OK); 1837 CheckNoTailCallExpressions(classifier, CHECK_OK);
1842 CheckDestructuringElement(elem, classifier, beg_pos, 1838 CheckDestructuringElement(elem, classifier, beg_pos,
1843 scanner()->location().end_pos); 1839 scanner()->location().end_pos);
1844 } 1840 }
1845 values->Add(elem, zone_); 1841 values->Add(elem, zone_);
1846 if (peek() != Token::RBRACK) { 1842 if (peek() != Token::RBRACK) {
1847 Expect(Token::COMMA, CHECK_OK); 1843 Expect(Token::COMMA, CHECK_OK);
1848 } 1844 }
1849 } 1845 }
1850 Expect(Token::RBRACK, CHECK_OK); 1846 Expect(Token::RBRACK, CHECK_OK);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 if (peek() == Token::COLON) { 1961 if (peek() == Token::COLON) {
1966 // PropertyDefinition 1962 // PropertyDefinition
1967 // PropertyName ':' AssignmentExpression 1963 // PropertyName ':' AssignmentExpression
1968 if (!*is_computed_name) { 1964 if (!*is_computed_name) {
1969 checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal, 1965 checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal,
1970 classifier, 1966 classifier,
1971 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1967 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1972 } 1968 }
1973 Consume(Token::COLON); 1969 Consume(Token::COLON);
1974 int beg_pos = peek_position(); 1970 int beg_pos = peek_position();
1975 ExpressionT value = this->ParseAssignmentExpression( 1971 ExpressionT value = ParseAssignmentExpression(
1976 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1972 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1977 CheckDestructuringElement(value, classifier, beg_pos, 1973 CheckDestructuringElement(value, classifier, beg_pos,
1978 scanner()->location().end_pos); 1974 scanner()->location().end_pos);
1979 1975
1980 return factory()->NewObjectLiteralProperty(name_expression, value, 1976 return factory()->NewObjectLiteralProperty(name_expression, value,
1981 is_static, *is_computed_name); 1977 is_static, *is_computed_name);
1982 } 1978 }
1983 1979
1984 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(), 1980 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(),
1985 parsing_module_ || is_async_function()) && 1981 parsing_module_ || is_async_function()) &&
(...skipping 26 matching lines...) Expand all
2012 MessageTemplate::kAwaitBindingIdentifier); 2008 MessageTemplate::kAwaitBindingIdentifier);
2013 } 2009 }
2014 ExpressionT lhs = 2010 ExpressionT lhs =
2015 impl()->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos); 2011 impl()->ExpressionFromIdentifier(*name, next_beg_pos, next_end_pos);
2016 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); 2012 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
2017 2013
2018 ExpressionT value; 2014 ExpressionT value;
2019 if (peek() == Token::ASSIGN) { 2015 if (peek() == Token::ASSIGN) {
2020 Consume(Token::ASSIGN); 2016 Consume(Token::ASSIGN);
2021 ExpressionClassifier rhs_classifier(this); 2017 ExpressionClassifier rhs_classifier(this);
2022 ExpressionT rhs = this->ParseAssignmentExpression( 2018 ExpressionT rhs = ParseAssignmentExpression(
2023 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2019 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2024 impl()->RewriteNonPattern(&rhs_classifier, 2020 impl()->RewriteNonPattern(&rhs_classifier,
2025 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 2021 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
2026 classifier->Accumulate(&rhs_classifier, 2022 classifier->Accumulate(&rhs_classifier,
2027 ExpressionClassifier::ExpressionProductions); 2023 ExpressionClassifier::ExpressionProductions);
2028 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, 2024 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
2029 kNoSourcePosition); 2025 kNoSourcePosition);
2030 classifier->RecordObjectLiteralError( 2026 classifier->RecordObjectLiteralError(
2031 Scanner::Location(next_beg_pos, scanner()->location().end_pos), 2027 Scanner::Location(next_beg_pos, scanner()->location().end_pos),
2032 MessageTemplate::kInvalidCoverInitializedName); 2028 MessageTemplate::kInvalidCoverInitializedName);
2033 2029
2034 Traits::SetFunctionNameFromIdentifierRef(rhs, lhs); 2030 impl()->SetFunctionNameFromIdentifierRef(rhs, lhs);
2035 } else { 2031 } else {
2036 value = lhs; 2032 value = lhs;
2037 } 2033 }
2038 2034
2039 return factory()->NewObjectLiteralProperty( 2035 return factory()->NewObjectLiteralProperty(
2040 name_expression, value, ObjectLiteralProperty::COMPUTED, is_static, 2036 name_expression, value, ObjectLiteralProperty::COMPUTED, is_static,
2041 false); 2037 false);
2042 } 2038 }
2043 } 2039 }
2044 2040
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 2154
2159 Expect(Token::LBRACE, CHECK_OK); 2155 Expect(Token::LBRACE, CHECK_OK);
2160 2156
2161 while (peek() != Token::RBRACE) { 2157 while (peek() != Token::RBRACE) {
2162 FuncNameInferrer::State fni_state(fni_); 2158 FuncNameInferrer::State fni_state(fni_);
2163 2159
2164 const bool in_class = false; 2160 const bool in_class = false;
2165 const bool has_extends = false; 2161 const bool has_extends = false;
2166 bool is_computed_name = false; 2162 bool is_computed_name = false;
2167 IdentifierT name = impl()->EmptyIdentifier(); 2163 IdentifierT name = impl()->EmptyIdentifier();
2168 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( 2164 ObjectLiteralPropertyT property = ParsePropertyDefinition(
2169 &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name, 2165 &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name,
2170 NULL, classifier, &name, CHECK_OK); 2166 NULL, classifier, &name, CHECK_OK);
2171 2167
2172 if (is_computed_name) { 2168 if (is_computed_name) {
2173 has_computed_names = true; 2169 has_computed_names = true;
2174 } 2170 }
2175 2171
2176 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. 2172 // Count CONSTANT or COMPUTED properties to maintain the enumeration order.
2177 if (!has_computed_names && impl()->IsBoilerplateProperty(property)) { 2173 if (!has_computed_names && impl()->IsBoilerplateProperty(property)) {
2178 number_of_boilerplate_properties++; 2174 number_of_boilerplate_properties++;
2179 } 2175 }
2180 properties->Add(property, zone()); 2176 properties->Add(property, zone());
2181 2177
2182 if (peek() != Token::RBRACE) { 2178 if (peek() != Token::RBRACE) {
2183 // Need {} because of the CHECK_OK macro. 2179 // Need {} because of the CHECK_OK macro.
2184 Expect(Token::COMMA, CHECK_OK); 2180 Expect(Token::COMMA, CHECK_OK);
2185 } 2181 }
2186 2182
2187 if (fni_ != nullptr) fni_->Infer(); 2183 if (fni_ != nullptr) fni_->Infer();
2188 2184
2189 Traits::SetFunctionNameFromPropertyName(property, name); 2185 impl()->SetFunctionNameFromPropertyName(property, name);
2190 } 2186 }
2191 Expect(Token::RBRACE, CHECK_OK); 2187 Expect(Token::RBRACE, CHECK_OK);
2192 2188
2193 // Computation of literal_index must happen before pre parse bailout. 2189 // Computation of literal_index must happen before pre parse bailout.
2194 int literal_index = function_state_->NextMaterializedLiteralIndex(); 2190 int literal_index = function_state_->NextMaterializedLiteralIndex();
2195 2191
2196 return factory()->NewObjectLiteral(properties, 2192 return factory()->NewObjectLiteral(properties,
2197 literal_index, 2193 literal_index,
2198 number_of_boilerplate_properties, 2194 number_of_boilerplate_properties,
2199 pos); 2195 pos);
(...skipping 11 matching lines...) Expand all
2211 typename Traits::Type::ExpressionList result = impl()->NewExpressionList(4); 2207 typename Traits::Type::ExpressionList result = impl()->NewExpressionList(4);
2212 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); 2208 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList));
2213 bool done = (peek() == Token::RPAREN); 2209 bool done = (peek() == Token::RPAREN);
2214 bool was_unspread = false; 2210 bool was_unspread = false;
2215 int unspread_sequences_count = 0; 2211 int unspread_sequences_count = 0;
2216 while (!done) { 2212 while (!done) {
2217 int start_pos = peek_position(); 2213 int start_pos = peek_position();
2218 bool is_spread = Check(Token::ELLIPSIS); 2214 bool is_spread = Check(Token::ELLIPSIS);
2219 int expr_pos = peek_position(); 2215 int expr_pos = peek_position();
2220 2216
2221 ExpressionT argument = this->ParseAssignmentExpression( 2217 ExpressionT argument = ParseAssignmentExpression(
2222 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); 2218 true, classifier, CHECK_OK_CUSTOM(NullExpressionList));
2223 CheckNoTailCallExpressions(classifier, CHECK_OK_CUSTOM(NullExpressionList)); 2219 CheckNoTailCallExpressions(classifier, CHECK_OK_CUSTOM(NullExpressionList));
2224 if (!maybe_arrow) { 2220 if (!maybe_arrow) {
2225 impl()->RewriteNonPattern(classifier, 2221 impl()->RewriteNonPattern(classifier,
2226 CHECK_OK_CUSTOM(NullExpressionList)); 2222 CHECK_OK_CUSTOM(NullExpressionList));
2227 } 2223 }
2228 if (is_spread) { 2224 if (is_spread) {
2229 if (!spread_arg.IsValid()) { 2225 if (!spread_arg.IsValid()) {
2230 spread_arg.beg_pos = start_pos; 2226 spread_arg.beg_pos = start_pos;
2231 spread_arg.end_pos = peek_position(); 2227 spread_arg.end_pos = peek_position();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 2263
2268 if (!maybe_arrow || peek() != Token::ARROW) { 2264 if (!maybe_arrow || peek() != Token::ARROW) {
2269 if (maybe_arrow) { 2265 if (maybe_arrow) {
2270 impl()->RewriteNonPattern(classifier, 2266 impl()->RewriteNonPattern(classifier,
2271 CHECK_OK_CUSTOM(NullExpressionList)); 2267 CHECK_OK_CUSTOM(NullExpressionList));
2272 } 2268 }
2273 if (spread_arg.IsValid()) { 2269 if (spread_arg.IsValid()) {
2274 // Unspread parameter sequences are translated into array literals in the 2270 // Unspread parameter sequences are translated into array literals in the
2275 // parser. Ensure that the number of materialized literals matches between 2271 // parser. Ensure that the number of materialized literals matches between
2276 // the parser and preparser 2272 // the parser and preparser
2277 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); 2273 impl()->MaterializeUnspreadArgumentsLiterals(unspread_sequences_count);
2278 } 2274 }
2279 } 2275 }
2280 2276
2281 return result; 2277 return result;
2282 } 2278 }
2283 2279
2284 // Precedence = 2 2280 // Precedence = 2
2285 template <typename Impl> 2281 template <typename Impl>
2286 typename ParserBase<Impl>::ExpressionT 2282 typename ParserBase<Impl>::ExpressionT
2287 ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, 2283 ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
2288 ExpressionClassifier* classifier, 2284 ExpressionClassifier* classifier,
2289 bool* ok) { 2285 bool* ok) {
2290 // AssignmentExpression :: 2286 // AssignmentExpression ::
2291 // ConditionalExpression 2287 // ConditionalExpression
2292 // ArrowFunction 2288 // ArrowFunction
2293 // YieldExpression 2289 // YieldExpression
2294 // LeftHandSideExpression AssignmentOperator AssignmentExpression 2290 // LeftHandSideExpression AssignmentOperator AssignmentExpression
2295 int lhs_beg_pos = peek_position(); 2291 int lhs_beg_pos = peek_position();
2296 2292
2297 if (peek() == Token::YIELD && is_generator()) { 2293 if (peek() == Token::YIELD && is_generator()) {
2298 return this->ParseYieldExpression(accept_IN, classifier, ok); 2294 return ParseYieldExpression(accept_IN, classifier, ok);
2299 } 2295 }
2300 2296
2301 FuncNameInferrer::State fni_state(fni_); 2297 FuncNameInferrer::State fni_state(fni_);
2302 Checkpoint checkpoint(this); 2298 Checkpoint checkpoint(this);
2303 ExpressionClassifier arrow_formals_classifier(this, 2299 ExpressionClassifier arrow_formals_classifier(this,
2304 classifier->duplicate_finder()); 2300 classifier->duplicate_finder());
2305 2301
2306 Scope::Snapshot scope_snapshot(scope()); 2302 Scope::Snapshot scope_snapshot(scope());
2307 2303
2308 bool is_async = allow_harmony_async_await() && peek() == Token::ASYNC && 2304 bool is_async = allow_harmony_async_await() && peek() == Token::ASYNC &&
2309 !scanner()->HasAnyLineTerminatorAfterNext() && 2305 !scanner()->HasAnyLineTerminatorAfterNext() &&
2310 IsValidArrowFormalParametersStart(PeekAhead()); 2306 IsValidArrowFormalParametersStart(PeekAhead());
2311 2307
2312 bool parenthesized_formals = peek() == Token::LPAREN; 2308 bool parenthesized_formals = peek() == Token::LPAREN;
2313 if (!is_async && !parenthesized_formals) { 2309 if (!is_async && !parenthesized_formals) {
2314 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); 2310 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
2315 } 2311 }
2316 2312
2317 // Parse a simple, faster sub-grammar (primary expression) if it's evident 2313 // Parse a simple, faster sub-grammar (primary expression) if it's evident
2318 // that we have only a trivial expression to parse. 2314 // that we have only a trivial expression to parse.
2319 ExpressionT expression; 2315 ExpressionT expression;
2320 if (IsTrivialExpression()) { 2316 if (IsTrivialExpression()) {
2321 expression = this->ParsePrimaryExpression(&arrow_formals_classifier, 2317 expression =
2322 &is_async, CHECK_OK); 2318 ParsePrimaryExpression(&arrow_formals_classifier, &is_async, CHECK_OK);
2323 } else { 2319 } else {
2324 expression = this->ParseConditionalExpression( 2320 expression = ParseConditionalExpression(
2325 accept_IN, &arrow_formals_classifier, CHECK_OK); 2321 accept_IN, &arrow_formals_classifier, CHECK_OK);
2326 } 2322 }
2327 2323
2328 if (is_async && impl()->IsIdentifier(expression) && peek_any_identifier() && 2324 if (is_async && impl()->IsIdentifier(expression) && peek_any_identifier() &&
2329 PeekAhead() == Token::ARROW) { 2325 PeekAhead() == Token::ARROW) {
2330 // async Identifier => AsyncConciseBody 2326 // async Identifier => AsyncConciseBody
2331 IdentifierT name = 2327 IdentifierT name =
2332 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); 2328 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
2333 expression = impl()->ExpressionFromIdentifier( 2329 expression = impl()->ExpressionFromIdentifier(
2334 name, position(), scanner()->location().end_pos, InferName::kNo); 2330 name, position(), scanner()->location().end_pos, InferName::kNo);
(...skipping 10 matching lines...) Expand all
2345 // This reads strangely, but is correct: it checks whether any 2341 // This reads strangely, but is correct: it checks whether any
2346 // sub-expression of the parameter list failed to be a valid formal 2342 // sub-expression of the parameter list failed to be a valid formal
2347 // parameter initializer. Since YieldExpressions are banned anywhere 2343 // parameter initializer. Since YieldExpressions are banned anywhere
2348 // in an arrow parameter list, this is correct. 2344 // in an arrow parameter list, this is correct.
2349 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to 2345 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to
2350 // "YieldExpression", which is its only use. 2346 // "YieldExpression", which is its only use.
2351 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); 2347 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
2352 2348
2353 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); 2349 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
2354 DeclarationScope* scope = 2350 DeclarationScope* scope =
2355 this->NewFunctionScope(is_async ? FunctionKind::kAsyncArrowFunction 2351 NewFunctionScope(is_async ? FunctionKind::kAsyncArrowFunction
2356 : FunctionKind::kArrowFunction); 2352 : FunctionKind::kArrowFunction);
2357 // Because the arrow's parameters were parsed in the outer scope, any 2353 // Because the arrow's parameters were parsed in the outer scope, any
2358 // usage flags that might have been triggered there need to be copied 2354 // usage flags that might have been triggered there need to be copied
2359 // to the arrow scope. 2355 // to the arrow scope.
2360 this->scope()->PropagateUsageFlagsToScope(scope); 2356 this->scope()->PropagateUsageFlagsToScope(scope);
2361 FormalParametersT parameters(scope); 2357 FormalParametersT parameters(scope);
2362 if (!arrow_formals_classifier.is_simple_parameter_list()) { 2358 if (!arrow_formals_classifier.is_simple_parameter_list()) {
2363 scope->SetHasNonSimpleParameters(); 2359 scope->SetHasNonSimpleParameters();
2364 parameters.is_simple = false; 2360 parameters.is_simple = false;
2365 } 2361 }
2366 2362
2367 checkpoint.Restore(&parameters.materialized_literals_count); 2363 checkpoint.Restore(&parameters.materialized_literals_count);
2368 2364
2369 scope->set_start_position(lhs_beg_pos); 2365 scope->set_start_position(lhs_beg_pos);
2370 Scanner::Location duplicate_loc = Scanner::Location::invalid(); 2366 Scanner::Location duplicate_loc = Scanner::Location::invalid();
2371 this->ParseArrowFunctionFormalParameterList( 2367 impl()->ParseArrowFunctionFormalParameterList(
2372 &parameters, expression, loc, &duplicate_loc, scope_snapshot, CHECK_OK); 2368 &parameters, expression, loc, &duplicate_loc, scope_snapshot, CHECK_OK);
2373 if (duplicate_loc.IsValid()) { 2369 if (duplicate_loc.IsValid()) {
2374 arrow_formals_classifier.RecordDuplicateFormalParameterError( 2370 arrow_formals_classifier.RecordDuplicateFormalParameterError(
2375 duplicate_loc); 2371 duplicate_loc);
2376 } 2372 }
2377 expression = this->ParseArrowFunctionLiteral( 2373 expression = ParseArrowFunctionLiteral(accept_IN, parameters, is_async,
2378 accept_IN, parameters, is_async, arrow_formals_classifier, CHECK_OK); 2374 arrow_formals_classifier, CHECK_OK);
2379 arrow_formals_classifier.Discard(); 2375 arrow_formals_classifier.Discard();
2380 classifier->RecordPatternError(arrow_loc, 2376 classifier->RecordPatternError(arrow_loc,
2381 MessageTemplate::kUnexpectedToken, 2377 MessageTemplate::kUnexpectedToken,
2382 Token::String(Token::ARROW)); 2378 Token::String(Token::ARROW));
2383 2379
2384 if (fni_ != nullptr) fni_->Infer(); 2380 if (fni_ != nullptr) fni_->Infer();
2385 2381
2386 return expression; 2382 return expression;
2387 } 2383 }
2388 2384
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 } 2422 }
2427 2423
2428 // Now pending non-pattern expressions must be discarded. 2424 // Now pending non-pattern expressions must be discarded.
2429 arrow_formals_classifier.Discard(); 2425 arrow_formals_classifier.Discard();
2430 2426
2431 CheckNoTailCallExpressions(classifier, CHECK_OK); 2427 CheckNoTailCallExpressions(classifier, CHECK_OK);
2432 2428
2433 if (is_destructuring_assignment) { 2429 if (is_destructuring_assignment) {
2434 ValidateAssignmentPattern(classifier, CHECK_OK); 2430 ValidateAssignmentPattern(classifier, CHECK_OK);
2435 } else { 2431 } else {
2436 expression = this->CheckAndRewriteReferenceExpression( 2432 expression = CheckAndRewriteReferenceExpression(
2437 expression, lhs_beg_pos, scanner()->location().end_pos, 2433 expression, lhs_beg_pos, scanner()->location().end_pos,
2438 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); 2434 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK);
2439 } 2435 }
2440 2436
2441 expression = impl()->MarkExpressionAsAssigned(expression); 2437 expression = impl()->MarkExpressionAsAssigned(expression);
2442 2438
2443 Token::Value op = Next(); // Get assignment operator. 2439 Token::Value op = Next(); // Get assignment operator.
2444 if (op != Token::ASSIGN) { 2440 if (op != Token::ASSIGN) {
2445 classifier->RecordPatternError(scanner()->location(), 2441 classifier->RecordPatternError(scanner()->location(),
2446 MessageTemplate::kUnexpectedToken, 2442 MessageTemplate::kUnexpectedToken,
2447 Token::String(op)); 2443 Token::String(op));
2448 } 2444 }
2449 int pos = position(); 2445 int pos = position();
2450 2446
2451 ExpressionClassifier rhs_classifier(this); 2447 ExpressionClassifier rhs_classifier(this);
2452 2448
2453 ExpressionT right = 2449 ExpressionT right =
2454 this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK); 2450 ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
2455 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK); 2451 CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK);
2456 impl()->RewriteNonPattern(&rhs_classifier, CHECK_OK); 2452 impl()->RewriteNonPattern(&rhs_classifier, CHECK_OK);
2457 classifier->Accumulate( 2453 classifier->Accumulate(
2458 &rhs_classifier, 2454 &rhs_classifier,
2459 ExpressionClassifier::ExpressionProductions | 2455 ExpressionClassifier::ExpressionProductions |
2460 ExpressionClassifier::ObjectLiteralProduction | 2456 ExpressionClassifier::ObjectLiteralProduction |
2461 ExpressionClassifier::AsyncArrowFormalParametersProduction); 2457 ExpressionClassifier::AsyncArrowFormalParametersProduction);
2462 2458
2463 // TODO(1231235): We try to estimate the set of properties set by 2459 // TODO(1231235): We try to estimate the set of properties set by
2464 // constructors. We define a new property whenever there is an 2460 // constructors. We define a new property whenever there is an
(...skipping 12 matching lines...) Expand all
2477 // expression. 2473 // expression.
2478 if ((op == Token::INIT || op == Token::ASSIGN) && 2474 if ((op == Token::INIT || op == Token::ASSIGN) &&
2479 (!right->IsCall() && !right->IsCallNew())) { 2475 (!right->IsCall() && !right->IsCallNew())) {
2480 fni_->Infer(); 2476 fni_->Infer();
2481 } else { 2477 } else {
2482 fni_->RemoveLastFunction(); 2478 fni_->RemoveLastFunction();
2483 } 2479 }
2484 } 2480 }
2485 2481
2486 if (op == Token::ASSIGN) { 2482 if (op == Token::ASSIGN) {
2487 Traits::SetFunctionNameFromIdentifierRef(right, expression); 2483 impl()->SetFunctionNameFromIdentifierRef(right, expression);
2488 } 2484 }
2489 2485
2490 if (op == Token::ASSIGN_EXP) { 2486 if (op == Token::ASSIGN_EXP) {
2491 DCHECK(!is_destructuring_assignment); 2487 DCHECK(!is_destructuring_assignment);
2492 return impl()->RewriteAssignExponentiation(expression, right, pos); 2488 return impl()->RewriteAssignExponentiation(expression, right, pos);
2493 } 2489 }
2494 2490
2495 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); 2491 ExpressionT result = factory()->NewAssignment(op, expression, right, pos);
2496 2492
2497 if (is_destructuring_assignment) { 2493 if (is_destructuring_assignment) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier, 2554 ParserBase<Impl>::ParseTailCallExpression(ExpressionClassifier* classifier,
2559 bool* ok) { 2555 bool* ok) {
2560 // TailCallExpression:: 2556 // TailCallExpression::
2561 // 'continue' MemberExpression Arguments 2557 // 'continue' MemberExpression Arguments
2562 // 'continue' CallExpression Arguments 2558 // 'continue' CallExpression Arguments
2563 // 'continue' MemberExpression TemplateLiteral 2559 // 'continue' MemberExpression TemplateLiteral
2564 // 'continue' CallExpression TemplateLiteral 2560 // 'continue' CallExpression TemplateLiteral
2565 Expect(Token::CONTINUE, CHECK_OK); 2561 Expect(Token::CONTINUE, CHECK_OK);
2566 int pos = position(); 2562 int pos = position();
2567 int sub_expression_pos = peek_position(); 2563 int sub_expression_pos = peek_position();
2568 ExpressionT expression = 2564 ExpressionT expression = ParseLeftHandSideExpression(classifier, CHECK_OK);
2569 this->ParseLeftHandSideExpression(classifier, CHECK_OK);
2570 CheckNoTailCallExpressions(classifier, CHECK_OK); 2565 CheckNoTailCallExpressions(classifier, CHECK_OK);
2571 2566
2572 Scanner::Location loc(pos, scanner()->location().end_pos); 2567 Scanner::Location loc(pos, scanner()->location().end_pos);
2573 if (!expression->IsCall()) { 2568 if (!expression->IsCall()) {
2574 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos); 2569 Scanner::Location sub_loc(sub_expression_pos, loc.end_pos);
2575 impl()->ReportMessageAt(sub_loc, 2570 impl()->ReportMessageAt(sub_loc,
2576 MessageTemplate::kUnexpectedInsideTailCall); 2571 MessageTemplate::kUnexpectedInsideTailCall);
2577 *ok = false; 2572 *ok = false;
2578 return impl()->EmptyExpression(); 2573 return impl()->EmptyExpression();
2579 } 2574 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 ParserBase<Impl>::ParseConditionalExpression(bool accept_IN, 2618 ParserBase<Impl>::ParseConditionalExpression(bool accept_IN,
2624 ExpressionClassifier* classifier, 2619 ExpressionClassifier* classifier,
2625 bool* ok) { 2620 bool* ok) {
2626 // ConditionalExpression :: 2621 // ConditionalExpression ::
2627 // LogicalOrExpression 2622 // LogicalOrExpression
2628 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression 2623 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
2629 2624
2630 int pos = peek_position(); 2625 int pos = peek_position();
2631 // We start using the binary expression parser for prec >= 4 only! 2626 // We start using the binary expression parser for prec >= 4 only!
2632 ExpressionT expression = 2627 ExpressionT expression =
2633 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); 2628 ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK);
2634 if (peek() != Token::CONDITIONAL) return expression; 2629 if (peek() != Token::CONDITIONAL) return expression;
2635 CheckNoTailCallExpressions(classifier, CHECK_OK); 2630 CheckNoTailCallExpressions(classifier, CHECK_OK);
2636 impl()->RewriteNonPattern(classifier, CHECK_OK); 2631 impl()->RewriteNonPattern(classifier, CHECK_OK);
2637 BindingPatternUnexpectedToken(classifier); 2632 BindingPatternUnexpectedToken(classifier);
2638 ArrowFormalParametersUnexpectedToken(classifier); 2633 ArrowFormalParametersUnexpectedToken(classifier);
2639 Consume(Token::CONDITIONAL); 2634 Consume(Token::CONDITIONAL);
2640 // In parsing the first assignment expression in conditional 2635 // In parsing the first assignment expression in conditional
2641 // expressions we always accept the 'in' keyword; see ECMA-262, 2636 // expressions we always accept the 'in' keyword; see ECMA-262,
2642 // section 11.12, page 58. 2637 // section 11.12, page 58.
2643 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); 2638 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK);
2644 impl()->RewriteNonPattern(classifier, CHECK_OK); 2639 impl()->RewriteNonPattern(classifier, CHECK_OK);
2645 Expect(Token::COLON, CHECK_OK); 2640 Expect(Token::COLON, CHECK_OK);
2646 ExpressionT right = 2641 ExpressionT right =
2647 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); 2642 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
2648 impl()->RewriteNonPattern(classifier, CHECK_OK); 2643 impl()->RewriteNonPattern(classifier, CHECK_OK);
2649 return factory()->NewConditional(expression, left, right, pos); 2644 return factory()->NewConditional(expression, left, right, pos);
2650 } 2645 }
2651 2646
2652 2647
2653 // Precedence >= 4 2648 // Precedence >= 4
2654 template <typename Impl> 2649 template <typename Impl>
2655 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression( 2650 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression(
2656 int prec, bool accept_IN, ExpressionClassifier* classifier, bool* ok) { 2651 int prec, bool accept_IN, ExpressionClassifier* classifier, bool* ok) {
2657 DCHECK(prec >= 4); 2652 DCHECK(prec >= 4);
2658 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); 2653 ExpressionT x = ParseUnaryExpression(classifier, CHECK_OK);
2659 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { 2654 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) {
2660 // prec1 >= 4 2655 // prec1 >= 4
2661 while (Precedence(peek(), accept_IN) == prec1) { 2656 while (Precedence(peek(), accept_IN) == prec1) {
2662 CheckNoTailCallExpressions(classifier, CHECK_OK); 2657 CheckNoTailCallExpressions(classifier, CHECK_OK);
2663 impl()->RewriteNonPattern(classifier, CHECK_OK); 2658 impl()->RewriteNonPattern(classifier, CHECK_OK);
2664 BindingPatternUnexpectedToken(classifier); 2659 BindingPatternUnexpectedToken(classifier);
2665 ArrowFormalParametersUnexpectedToken(classifier); 2660 ArrowFormalParametersUnexpectedToken(classifier);
2666 Token::Value op = Next(); 2661 Token::Value op = Next();
2667 int pos = position(); 2662 int pos = position();
2668 2663
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 return impl()->EmptyExpression(); 2743 return impl()->EmptyExpression();
2749 } 2744 }
2750 2745
2751 // Allow Traits do rewrite the expression. 2746 // Allow Traits do rewrite the expression.
2752 return impl()->BuildUnaryExpression(expression, op, pos); 2747 return impl()->BuildUnaryExpression(expression, op, pos);
2753 } else if (Token::IsCountOp(op)) { 2748 } else if (Token::IsCountOp(op)) {
2754 BindingPatternUnexpectedToken(classifier); 2749 BindingPatternUnexpectedToken(classifier);
2755 ArrowFormalParametersUnexpectedToken(classifier); 2750 ArrowFormalParametersUnexpectedToken(classifier);
2756 op = Next(); 2751 op = Next();
2757 int beg_pos = peek_position(); 2752 int beg_pos = peek_position();
2758 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); 2753 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK);
2759 CheckNoTailCallExpressions(classifier, CHECK_OK); 2754 CheckNoTailCallExpressions(classifier, CHECK_OK);
2760 expression = this->CheckAndRewriteReferenceExpression( 2755 expression = CheckAndRewriteReferenceExpression(
2761 expression, beg_pos, scanner()->location().end_pos, 2756 expression, beg_pos, scanner()->location().end_pos,
2762 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); 2757 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
2763 expression = impl()->MarkExpressionAsAssigned(expression); 2758 expression = impl()->MarkExpressionAsAssigned(expression);
2764 impl()->RewriteNonPattern(classifier, CHECK_OK); 2759 impl()->RewriteNonPattern(classifier, CHECK_OK);
2765 2760
2766 return factory()->NewCountOperation(op, 2761 return factory()->NewCountOperation(op,
2767 true /* prefix */, 2762 true /* prefix */,
2768 expression, 2763 expression,
2769 position()); 2764 position());
2770 2765
2771 } else if (is_async_function() && peek() == Token::AWAIT) { 2766 } else if (is_async_function() && peek() == Token::AWAIT) {
2772 classifier->RecordFormalParameterInitializerError( 2767 classifier->RecordFormalParameterInitializerError(
2773 scanner()->peek_location(), 2768 scanner()->peek_location(),
2774 MessageTemplate::kAwaitExpressionFormalParameter); 2769 MessageTemplate::kAwaitExpressionFormalParameter);
2775 2770
2776 int await_pos = peek_position(); 2771 int await_pos = peek_position();
2777 Consume(Token::AWAIT); 2772 Consume(Token::AWAIT);
2778 2773
2779 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); 2774 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK);
2780 2775
2781 return impl()->RewriteAwaitExpression(value, await_pos); 2776 return impl()->RewriteAwaitExpression(value, await_pos);
2782 } else { 2777 } else {
2783 return this->ParsePostfixExpression(classifier, ok); 2778 return ParsePostfixExpression(classifier, ok);
2784 } 2779 }
2785 } 2780 }
2786 2781
2787 template <typename Impl> 2782 template <typename Impl>
2788 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression( 2783 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression(
2789 ExpressionClassifier* classifier, bool* ok) { 2784 ExpressionClassifier* classifier, bool* ok) {
2790 // PostfixExpression :: 2785 // PostfixExpression ::
2791 // LeftHandSideExpression ('++' | '--')? 2786 // LeftHandSideExpression ('++' | '--')?
2792 2787
2793 int lhs_beg_pos = peek_position(); 2788 int lhs_beg_pos = peek_position();
2794 ExpressionT expression = 2789 ExpressionT expression = ParseLeftHandSideExpression(classifier, CHECK_OK);
2795 this->ParseLeftHandSideExpression(classifier, CHECK_OK);
2796 if (!scanner()->HasAnyLineTerminatorBeforeNext() && 2790 if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
2797 Token::IsCountOp(peek())) { 2791 Token::IsCountOp(peek())) {
2798 CheckNoTailCallExpressions(classifier, CHECK_OK); 2792 CheckNoTailCallExpressions(classifier, CHECK_OK);
2799 BindingPatternUnexpectedToken(classifier); 2793 BindingPatternUnexpectedToken(classifier);
2800 ArrowFormalParametersUnexpectedToken(classifier); 2794 ArrowFormalParametersUnexpectedToken(classifier);
2801 2795
2802 expression = this->CheckAndRewriteReferenceExpression( 2796 expression = CheckAndRewriteReferenceExpression(
2803 expression, lhs_beg_pos, scanner()->location().end_pos, 2797 expression, lhs_beg_pos, scanner()->location().end_pos,
2804 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); 2798 MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK);
2805 expression = impl()->MarkExpressionAsAssigned(expression); 2799 expression = impl()->MarkExpressionAsAssigned(expression);
2806 impl()->RewriteNonPattern(classifier, CHECK_OK); 2800 impl()->RewriteNonPattern(classifier, CHECK_OK);
2807 2801
2808 Token::Value next = Next(); 2802 Token::Value next = Next();
2809 expression = 2803 expression =
2810 factory()->NewCountOperation(next, 2804 factory()->NewCountOperation(next,
2811 false /* postfix */, 2805 false /* postfix */,
2812 expression, 2806 expression,
2813 position()); 2807 position());
2814 } 2808 }
2815 return expression; 2809 return expression;
2816 } 2810 }
2817 2811
2818 template <typename Impl> 2812 template <typename Impl>
2819 typename ParserBase<Impl>::ExpressionT 2813 typename ParserBase<Impl>::ExpressionT
2820 ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier, 2814 ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
2821 bool* ok) { 2815 bool* ok) {
2822 // LeftHandSideExpression :: 2816 // LeftHandSideExpression ::
2823 // (NewExpression | MemberExpression) ... 2817 // (NewExpression | MemberExpression) ...
2824 2818
2825 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) { 2819 if (FLAG_harmony_explicit_tailcalls && peek() == Token::CONTINUE) {
2826 return this->ParseTailCallExpression(classifier, ok); 2820 return ParseTailCallExpression(classifier, ok);
2827 } 2821 }
2828 2822
2829 bool is_async = false; 2823 bool is_async = false;
2830 ExpressionT result = this->ParseMemberWithNewPrefixesExpression( 2824 ExpressionT result =
2831 classifier, &is_async, CHECK_OK); 2825 ParseMemberWithNewPrefixesExpression(classifier, &is_async, CHECK_OK);
2832 2826
2833 while (true) { 2827 while (true) {
2834 switch (peek()) { 2828 switch (peek()) {
2835 case Token::LBRACK: { 2829 case Token::LBRACK: {
2836 CheckNoTailCallExpressions(classifier, CHECK_OK); 2830 CheckNoTailCallExpressions(classifier, CHECK_OK);
2837 impl()->RewriteNonPattern(classifier, CHECK_OK); 2831 impl()->RewriteNonPattern(classifier, CHECK_OK);
2838 BindingPatternUnexpectedToken(classifier); 2832 BindingPatternUnexpectedToken(classifier);
2839 ArrowFormalParametersUnexpectedToken(classifier); 2833 ArrowFormalParametersUnexpectedToken(classifier);
2840 Consume(Token::LBRACK); 2834 Consume(Token::LBRACK);
2841 int pos = position(); 2835 int pos = position();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2883 ValidateBindingPattern(&async_classifier, CHECK_OK); 2877 ValidateBindingPattern(&async_classifier, CHECK_OK);
2884 ValidateFormalParameterInitializer(&async_classifier, CHECK_OK); 2878 ValidateFormalParameterInitializer(&async_classifier, CHECK_OK);
2885 if (!async_classifier.is_valid_async_arrow_formal_parameters()) { 2879 if (!async_classifier.is_valid_async_arrow_formal_parameters()) {
2886 ReportClassifierError( 2880 ReportClassifierError(
2887 async_classifier.async_arrow_formal_parameters_error()); 2881 async_classifier.async_arrow_formal_parameters_error());
2888 *ok = false; 2882 *ok = false;
2889 return impl()->EmptyExpression(); 2883 return impl()->EmptyExpression();
2890 } 2884 }
2891 if (args->length()) { 2885 if (args->length()) {
2892 // async ( Arguments ) => ... 2886 // async ( Arguments ) => ...
2893 return Traits::ExpressionListToExpression(args); 2887 return impl()->ExpressionListToExpression(args);
2894 } 2888 }
2895 // async () => ... 2889 // async () => ...
2896 return factory()->NewEmptyParentheses(pos); 2890 return factory()->NewEmptyParentheses(pos);
2897 } else { 2891 } else {
2898 classifier->Accumulate(&async_classifier, 2892 classifier->Accumulate(&async_classifier,
2899 ExpressionClassifier::AllProductions); 2893 ExpressionClassifier::AllProductions);
2900 } 2894 }
2901 } else { 2895 } else {
2902 args = ParseArguments(&spread_pos, false, classifier, CHECK_OK); 2896 args = ParseArguments(&spread_pos, false, classifier, CHECK_OK);
2903 } 2897 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2993 ArrowFormalParametersUnexpectedToken(classifier); 2987 ArrowFormalParametersUnexpectedToken(classifier);
2994 Consume(Token::NEW); 2988 Consume(Token::NEW);
2995 int new_pos = position(); 2989 int new_pos = position();
2996 ExpressionT result; 2990 ExpressionT result;
2997 if (peek() == Token::SUPER) { 2991 if (peek() == Token::SUPER) {
2998 const bool is_new = true; 2992 const bool is_new = true;
2999 result = ParseSuperExpression(is_new, CHECK_OK); 2993 result = ParseSuperExpression(is_new, CHECK_OK);
3000 } else if (peek() == Token::PERIOD) { 2994 } else if (peek() == Token::PERIOD) {
3001 return ParseNewTargetExpression(CHECK_OK); 2995 return ParseNewTargetExpression(CHECK_OK);
3002 } else { 2996 } else {
3003 result = this->ParseMemberWithNewPrefixesExpression(classifier, is_async, 2997 result =
3004 CHECK_OK); 2998 ParseMemberWithNewPrefixesExpression(classifier, is_async, CHECK_OK);
3005 } 2999 }
3006 impl()->RewriteNonPattern(classifier, CHECK_OK); 3000 impl()->RewriteNonPattern(classifier, CHECK_OK);
3007 if (peek() == Token::LPAREN) { 3001 if (peek() == Token::LPAREN) {
3008 // NewExpression with arguments. 3002 // NewExpression with arguments.
3009 Scanner::Location spread_pos; 3003 Scanner::Location spread_pos;
3010 typename Traits::Type::ExpressionList args = 3004 typename Traits::Type::ExpressionList args =
3011 this->ParseArguments(&spread_pos, classifier, CHECK_OK); 3005 ParseArguments(&spread_pos, classifier, CHECK_OK);
3012 3006
3013 if (spread_pos.IsValid()) { 3007 if (spread_pos.IsValid()) {
3014 args = impl()->PrepareSpreadArguments(args); 3008 args = impl()->PrepareSpreadArguments(args);
3015 result = impl()->SpreadCallNew(result, args, new_pos); 3009 result = impl()->SpreadCallNew(result, args, new_pos);
3016 } else { 3010 } else {
3017 result = factory()->NewCallNew(result, args, new_pos); 3011 result = factory()->NewCallNew(result, args, new_pos);
3018 } 3012 }
3019 // The expression can still continue with . or [ after the arguments. 3013 // The expression can still continue with . or [ after the arguments.
3020 result = this->ParseMemberExpressionContinuation(result, is_async, 3014 result = ParseMemberExpressionContinuation(result, is_async, classifier,
3021 classifier, CHECK_OK); 3015 CHECK_OK);
3022 return result; 3016 return result;
3023 } 3017 }
3024 // NewExpression without arguments. 3018 // NewExpression without arguments.
3025 return factory()->NewCallNew(result, impl()->NewExpressionList(0), new_pos); 3019 return factory()->NewCallNew(result, impl()->NewExpressionList(0), new_pos);
3026 } 3020 }
3027 // No 'new' or 'super' keyword. 3021 // No 'new' or 'super' keyword.
3028 return this->ParseMemberExpression(classifier, is_async, ok); 3022 return ParseMemberExpression(classifier, is_async, ok);
3029 } 3023 }
3030 3024
3031 template <typename Impl> 3025 template <typename Impl>
3032 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( 3026 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
3033 ExpressionClassifier* classifier, bool* is_async, bool* ok) { 3027 ExpressionClassifier* classifier, bool* is_async, bool* ok) {
3034 // MemberExpression :: 3028 // MemberExpression ::
3035 // (PrimaryExpression | FunctionLiteral | ClassLiteral) 3029 // (PrimaryExpression | FunctionLiteral | ClassLiteral)
3036 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* 3030 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)*
3037 3031
3038 // The '[' Expression ']' and '.' Identifier parts are parsed by 3032 // The '[' Expression ']' and '.' Identifier parts are parsed by
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 while (true) { 3159 while (true) {
3166 switch (peek()) { 3160 switch (peek()) {
3167 case Token::LBRACK: { 3161 case Token::LBRACK: {
3168 *is_async = false; 3162 *is_async = false;
3169 impl()->RewriteNonPattern(classifier, CHECK_OK); 3163 impl()->RewriteNonPattern(classifier, CHECK_OK);
3170 BindingPatternUnexpectedToken(classifier); 3164 BindingPatternUnexpectedToken(classifier);
3171 ArrowFormalParametersUnexpectedToken(classifier); 3165 ArrowFormalParametersUnexpectedToken(classifier);
3172 3166
3173 Consume(Token::LBRACK); 3167 Consume(Token::LBRACK);
3174 int pos = position(); 3168 int pos = position();
3175 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); 3169 ExpressionT index = ParseExpression(true, classifier, CHECK_OK);
3176 impl()->RewriteNonPattern(classifier, CHECK_OK); 3170 impl()->RewriteNonPattern(classifier, CHECK_OK);
3177 expression = factory()->NewProperty(expression, index, pos); 3171 expression = factory()->NewProperty(expression, index, pos);
3178 if (fni_ != NULL) { 3172 if (fni_ != NULL) {
3179 impl()->PushPropertyName(fni_, index); 3173 impl()->PushPropertyName(fni_, index);
3180 } 3174 }
3181 Expect(Token::RBRACK, CHECK_OK); 3175 Expect(Token::RBRACK, CHECK_OK);
3182 break; 3176 break;
3183 } 3177 }
3184 case Token::PERIOD: { 3178 case Token::PERIOD: {
3185 *is_async = false; 3179 *is_async = false;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 if (!is_rest && Check(Token::ASSIGN)) { 3247 if (!is_rest && Check(Token::ASSIGN)) {
3254 ExpressionClassifier init_classifier(this); 3248 ExpressionClassifier init_classifier(this);
3255 initializer = ParseAssignmentExpression(true, &init_classifier, 3249 initializer = ParseAssignmentExpression(true, &init_classifier,
3256 CHECK_OK_CUSTOM(Void)); 3250 CHECK_OK_CUSTOM(Void));
3257 impl()->RewriteNonPattern(&init_classifier, CHECK_OK_CUSTOM(Void)); 3251 impl()->RewriteNonPattern(&init_classifier, CHECK_OK_CUSTOM(Void));
3258 ValidateFormalParameterInitializer(&init_classifier, CHECK_OK_CUSTOM(Void)); 3252 ValidateFormalParameterInitializer(&init_classifier, CHECK_OK_CUSTOM(Void));
3259 parameters->is_simple = false; 3253 parameters->is_simple = false;
3260 init_classifier.Discard(); 3254 init_classifier.Discard();
3261 classifier->RecordNonSimpleParameter(); 3255 classifier->RecordNonSimpleParameter();
3262 3256
3263 Traits::SetFunctionNameFromIdentifierRef(initializer, pattern); 3257 impl()->SetFunctionNameFromIdentifierRef(initializer, pattern);
3264 } 3258 }
3265 3259
3266 Traits::AddFormalParameter(parameters, pattern, initializer, 3260 impl()->AddFormalParameter(parameters, pattern, initializer,
3267 scanner()->location().end_pos, is_rest); 3261 scanner()->location().end_pos, is_rest);
3268 } 3262 }
3269 3263
3270 template <typename Impl> 3264 template <typename Impl>
3271 void ParserBase<Impl>::ParseFormalParameterList( 3265 void ParserBase<Impl>::ParseFormalParameterList(
3272 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { 3266 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) {
3273 // FormalParameters[Yield] : 3267 // FormalParameters[Yield] :
3274 // [empty] 3268 // [empty]
3275 // FunctionRestParameter[?Yield] 3269 // FunctionRestParameter[?Yield]
3276 // FormalParameterList[?Yield] 3270 // FormalParameterList[?Yield]
(...skipping 30 matching lines...) Expand all
3307 if (!Check(Token::COMMA)) break; 3301 if (!Check(Token::COMMA)) break;
3308 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) { 3302 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) {
3309 // allow the trailing comma 3303 // allow the trailing comma
3310 break; 3304 break;
3311 } 3305 }
3312 } 3306 }
3313 } 3307 }
3314 3308
3315 for (int i = 0; i < parameters->Arity(); ++i) { 3309 for (int i = 0; i < parameters->Arity(); ++i) {
3316 auto parameter = parameters->at(i); 3310 auto parameter = parameters->at(i);
3317 Traits::DeclareFormalParameter(parameters->scope, parameter, classifier); 3311 impl()->DeclareFormalParameter(parameters->scope, parameter, classifier);
3318 } 3312 }
3319 } 3313 }
3320 3314
3321 template <typename Impl> 3315 template <typename Impl>
3322 void ParserBase<Impl>::CheckArityRestrictions(int param_count, 3316 void ParserBase<Impl>::CheckArityRestrictions(int param_count,
3323 FunctionKind function_kind, 3317 FunctionKind function_kind,
3324 bool has_rest, 3318 bool has_rest,
3325 int formals_start_pos, 3319 int formals_start_pos,
3326 int formals_end_pos, bool* ok) { 3320 int formals_end_pos, bool* ok) {
3327 if (IsGetterFunction(function_kind)) { 3321 if (IsGetterFunction(function_kind)) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 int expected_property_count = -1; 3404 int expected_property_count = -1;
3411 3405
3412 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; 3406 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
3413 { 3407 {
3414 FunctionState function_state(&function_state_, &scope_state_, 3408 FunctionState function_state(&function_state_, &scope_state_,
3415 formal_parameters.scope, arrow_kind); 3409 formal_parameters.scope, arrow_kind);
3416 3410
3417 function_state.SkipMaterializedLiterals( 3411 function_state.SkipMaterializedLiterals(
3418 formal_parameters.materialized_literals_count); 3412 formal_parameters.materialized_literals_count);
3419 3413
3420 this->ReindexLiterals(formal_parameters); 3414 impl()->ReindexLiterals(formal_parameters);
3421 3415
3422 Expect(Token::ARROW, CHECK_OK); 3416 Expect(Token::ARROW, CHECK_OK);
3423 3417
3424 if (peek() == Token::LBRACE) { 3418 if (peek() == Token::LBRACE) {
3425 // Multiple statement body 3419 // Multiple statement body
3426 Consume(Token::LBRACE); 3420 Consume(Token::LBRACE);
3427 DCHECK_EQ(scope(), formal_parameters.scope); 3421 DCHECK_EQ(scope(), formal_parameters.scope);
3428 bool is_lazily_parsed = (mode() == PARSE_LAZILY && 3422 bool is_lazily_parsed = (mode() == PARSE_LAZILY &&
3429 formal_parameters.scope->AllowsLazyParsing()); 3423 formal_parameters.scope->AllowsLazyParsing());
3430 if (is_lazily_parsed) { 3424 if (is_lazily_parsed) {
(...skipping 13 matching lines...) Expand all
3444 expected_property_count = function_state.expected_property_count(); 3438 expected_property_count = function_state.expected_property_count();
3445 } 3439 }
3446 } else { 3440 } else {
3447 // Single-expression body 3441 // Single-expression body
3448 int pos = position(); 3442 int pos = position();
3449 DCHECK(ReturnExprContext::kInsideValidBlock == 3443 DCHECK(ReturnExprContext::kInsideValidBlock ==
3450 function_state_->return_expr_context()); 3444 function_state_->return_expr_context());
3451 ReturnExprScope allow_tail_calls( 3445 ReturnExprScope allow_tail_calls(
3452 function_state_, ReturnExprContext::kInsideValidReturnStatement); 3446 function_state_, ReturnExprContext::kInsideValidReturnStatement);
3453 body = impl()->NewStatementList(1); 3447 body = impl()->NewStatementList(1);
3454 this->AddParameterInitializationBlock(formal_parameters, body, is_async, 3448 impl()->AddParameterInitializationBlock(formal_parameters, body, is_async,
3455 CHECK_OK); 3449 CHECK_OK);
3456 ExpressionClassifier classifier(this); 3450 ExpressionClassifier classifier(this);
3457 if (is_async) { 3451 if (is_async) {
3458 impl()->ParseAsyncArrowSingleExpressionBody(body, accept_IN, 3452 impl()->ParseAsyncArrowSingleExpressionBody(body, accept_IN,
3459 &classifier, pos, CHECK_OK); 3453 &classifier, pos, CHECK_OK);
3460 impl()->RewriteNonPattern(&classifier, CHECK_OK); 3454 impl()->RewriteNonPattern(&classifier, CHECK_OK);
3461 } else { 3455 } else {
3462 ExpressionT expression = 3456 ExpressionT expression =
3463 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); 3457 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
3464 impl()->RewriteNonPattern(&classifier, CHECK_OK); 3458 impl()->RewriteNonPattern(&classifier, CHECK_OK);
3465 body->Add(factory()->NewReturnStatement(expression, pos), zone()); 3459 body->Add(factory()->NewReturnStatement(expression, pos), zone());
3466 if (allow_tailcalls() && !is_sloppy(language_mode())) { 3460 if (allow_tailcalls() && !is_sloppy(language_mode())) {
3467 // ES6 14.6.1 Static Semantics: IsInTailPosition 3461 // ES6 14.6.1 Static Semantics: IsInTailPosition
3468 impl()->MarkTailPosition(expression); 3462 impl()->MarkTailPosition(expression);
3469 } 3463 }
3470 } 3464 }
3471 materialized_literal_count = function_state.materialized_literal_count(); 3465 materialized_literal_count = function_state.materialized_literal_count();
3472 expected_property_count = function_state.expected_property_count(); 3466 expected_property_count = function_state.expected_property_count();
3473 impl()->MarkCollectedTailCallExpressions(); 3467 impl()->MarkCollectedTailCallExpressions();
3474 } 3468 }
3475 3469
3476 formal_parameters.scope->set_end_position(scanner()->location().end_pos); 3470 formal_parameters.scope->set_end_position(scanner()->location().end_pos);
3477 3471
3478 // Arrow function formal parameters are parsed as StrictFormalParameterList, 3472 // Arrow function formal parameters are parsed as StrictFormalParameterList,
3479 // which is not the same as "parameters of a strict function"; it only means 3473 // which is not the same as "parameters of a strict function"; it only means
3480 // that duplicates are not allowed. Of course, the arrow function may 3474 // that duplicates are not allowed. Of course, the arrow function may
3481 // itself be strict as well. 3475 // itself be strict as well.
3482 const bool allow_duplicate_parameters = false; 3476 const bool allow_duplicate_parameters = false;
3483 this->ValidateFormalParameters(&formals_classifier, language_mode(), 3477 ValidateFormalParameters(&formals_classifier, language_mode(),
3484 allow_duplicate_parameters, CHECK_OK); 3478 allow_duplicate_parameters, CHECK_OK);
3485 3479
3486 // Validate strict mode. 3480 // Validate strict mode.
3487 if (is_strict(language_mode())) { 3481 if (is_strict(language_mode())) {
3488 CheckStrictOctalLiteral(formal_parameters.scope->start_position(), 3482 CheckStrictOctalLiteral(formal_parameters.scope->start_position(),
3489 scanner()->location().end_pos, CHECK_OK); 3483 scanner()->location().end_pos, CHECK_OK);
3490 } 3484 }
3491 impl()->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK); 3485 impl()->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
3492 3486
3493 impl()->RewriteDestructuringAssignments(); 3487 impl()->RewriteDestructuringAssignments();
3494 } 3488 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3556 return impl()->EmptyExpression(); 3550 return impl()->EmptyExpression();
3557 } else if (next == Token::ILLEGAL) { 3551 } else if (next == Token::ILLEGAL) {
3558 impl()->ReportMessageAt( 3552 impl()->ReportMessageAt(
3559 Scanner::Location(position() + 1, peek_position()), 3553 Scanner::Location(position() + 1, peek_position()),
3560 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); 3554 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError);
3561 *ok = false; 3555 *ok = false;
3562 return impl()->EmptyExpression(); 3556 return impl()->EmptyExpression();
3563 } 3557 }
3564 3558
3565 int expr_pos = peek_position(); 3559 int expr_pos = peek_position();
3566 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); 3560 ExpressionT expression = ParseExpression(true, classifier, CHECK_OK);
3567 CheckNoTailCallExpressions(classifier, CHECK_OK); 3561 CheckNoTailCallExpressions(classifier, CHECK_OK);
3568 impl()->RewriteNonPattern(classifier, CHECK_OK); 3562 impl()->RewriteNonPattern(classifier, CHECK_OK);
3569 impl()->AddTemplateExpression(&ts, expression); 3563 impl()->AddTemplateExpression(&ts, expression);
3570 3564
3571 if (peek() != Token::RBRACE) { 3565 if (peek() != Token::RBRACE) {
3572 impl()->ReportMessageAt(Scanner::Location(expr_pos, peek_position()), 3566 impl()->ReportMessageAt(Scanner::Location(expr_pos, peek_position()),
3573 MessageTemplate::kUnterminatedTemplateExpr); 3567 MessageTemplate::kUnterminatedTemplateExpr);
3574 *ok = false; 3568 *ok = false;
3575 return impl()->EmptyExpression(); 3569 return impl()->EmptyExpression();
3576 } 3570 }
(...skipping 24 matching lines...) Expand all
3601 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); 3595 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK);
3602 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. 3596 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral.
3603 return impl()->CloseTemplateLiteral(&ts, start, tag); 3597 return impl()->CloseTemplateLiteral(&ts, start, tag);
3604 } 3598 }
3605 3599
3606 template <typename Impl> 3600 template <typename Impl>
3607 typename ParserBase<Impl>::ExpressionT 3601 typename ParserBase<Impl>::ExpressionT
3608 ParserBase<Impl>::CheckAndRewriteReferenceExpression( 3602 ParserBase<Impl>::CheckAndRewriteReferenceExpression(
3609 ExpressionT expression, int beg_pos, int end_pos, 3603 ExpressionT expression, int beg_pos, int end_pos,
3610 MessageTemplate::Template message, bool* ok) { 3604 MessageTemplate::Template message, bool* ok) {
3611 return this->CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos, 3605 return CheckAndRewriteReferenceExpression(expression, beg_pos, end_pos,
3612 message, kReferenceError, ok); 3606 message, kReferenceError, ok);
3613 } 3607 }
3614 3608
3615 template <typename Impl> 3609 template <typename Impl>
3616 typename ParserBase<Impl>::ExpressionT 3610 typename ParserBase<Impl>::ExpressionT
3617 ParserBase<Impl>::CheckAndRewriteReferenceExpression( 3611 ParserBase<Impl>::CheckAndRewriteReferenceExpression(
3618 ExpressionT expression, int beg_pos, int end_pos, 3612 ExpressionT expression, int beg_pos, int end_pos,
3619 MessageTemplate::Template message, ParseErrorType type, bool* ok) { 3613 MessageTemplate::Template message, ParseErrorType type, bool* ok) {
3620 if (impl()->IsIdentifier(expression) && is_strict(language_mode()) && 3614 if (impl()->IsIdentifier(expression) && is_strict(language_mode()) &&
3621 impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) { 3615 impl()->IsEvalOrArguments(impl()->AsIdentifier(expression))) {
3622 ReportMessageAt(Scanner::Location(beg_pos, end_pos), 3616 ReportMessageAt(Scanner::Location(beg_pos, end_pos),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3712 has_seen_constructor_ = true; 3706 has_seen_constructor_ = true;
3713 return; 3707 return;
3714 } 3708 }
3715 } 3709 }
3716 3710
3717 3711
3718 } // namespace internal 3712 } // namespace internal
3719 } // namespace v8 3713 } // namespace v8
3720 3714
3721 #endif // V8_PARSING_PARSER_BASE_H 3715 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« src/parsing/parser.h ('K') | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698