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

Side by Side Diff: src/preparser.h

Issue 1247443004: [es6] Some renamings and minor clean-ups in parameter parsing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove accidental line Created 5 years, 5 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
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // // Return types for traversing functions. 55 // // Return types for traversing functions.
56 // typedef Identifier; 56 // typedef Identifier;
57 // typedef Expression; 57 // typedef Expression;
58 // typedef FunctionLiteral; 58 // typedef FunctionLiteral;
59 // typedef ClassLiteral; 59 // typedef ClassLiteral;
60 // typedef ObjectLiteralProperty; 60 // typedef ObjectLiteralProperty;
61 // typedef Literal; 61 // typedef Literal;
62 // typedef ExpressionList; 62 // typedef ExpressionList;
63 // typedef PropertyList; 63 // typedef PropertyList;
64 // typedef FormalParameter; 64 // typedef FormalParameter;
65 // typedef FormalParameters;
65 // // For constructing objects returned by the traversing functions. 66 // // For constructing objects returned by the traversing functions.
66 // typedef Factory; 67 // typedef Factory;
67 // }; 68 // };
68 // // ... 69 // // ...
69 // }; 70 // };
70 71
71 template <typename Traits> 72 template <typename Traits>
72 class ParserBase : public Traits { 73 class ParserBase : public Traits {
73 public: 74 public:
74 // Shorten type names defined by Traits. 75 // Shorten type names defined by Traits.
75 typedef typename Traits::Type::Expression ExpressionT; 76 typedef typename Traits::Type::Expression ExpressionT;
76 typedef typename Traits::Type::Identifier IdentifierT; 77 typedef typename Traits::Type::Identifier IdentifierT;
77 typedef typename Traits::Type::FormalParameter FormalParameterT; 78 typedef typename Traits::Type::FormalParameter FormalParameterT;
79 typedef typename Traits::Type::FormalParameters FormalParametersT;
78 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; 80 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT;
79 typedef typename Traits::Type::Literal LiteralT; 81 typedef typename Traits::Type::Literal LiteralT;
80 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; 82 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT;
81 typedef typename Traits::Type::FormalParameterParsingState
82 FormalParameterParsingStateT;
83 83
84 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, 84 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit,
85 v8::Extension* extension, AstValueFactory* ast_value_factory, 85 v8::Extension* extension, AstValueFactory* ast_value_factory,
86 ParserRecorder* log, typename Traits::Type::Parser this_object) 86 ParserRecorder* log, typename Traits::Type::Parser this_object)
87 : Traits(this_object), 87 : Traits(this_object),
88 parenthesized_function_(false), 88 parenthesized_function_(false),
89 scope_(NULL), 89 scope_(NULL),
90 function_state_(NULL), 90 function_state_(NULL),
91 extension_(extension), 91 extension_(extension),
92 fni_(NULL), 92 fni_(NULL),
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, 677 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier,
678 bool* ok); 678 bool* ok);
679 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, 679 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier,
680 bool* ok); 680 bool* ok);
681 ExpressionT ParseMemberWithNewPrefixesExpression( 681 ExpressionT ParseMemberWithNewPrefixesExpression(
682 ExpressionClassifier* classifier, bool* ok); 682 ExpressionClassifier* classifier, bool* ok);
683 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); 683 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok);
684 ExpressionT ParseMemberExpressionContinuation( 684 ExpressionT ParseMemberExpressionContinuation(
685 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); 685 ExpressionT expression, ExpressionClassifier* classifier, bool* ok);
686 ExpressionT ParseArrowFunctionLiteral( 686 ExpressionT ParseArrowFunctionLiteral(
687 const FormalParameterParsingStateT& parsing_state, 687 const FormalParametersT& parameters,
688 const ExpressionClassifier& classifier, bool* ok); 688 const ExpressionClassifier& classifier, bool* ok);
689 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, 689 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start,
690 ExpressionClassifier* classifier, bool* ok); 690 ExpressionClassifier* classifier, bool* ok);
691 void AddTemplateExpression(ExpressionT); 691 void AddTemplateExpression(ExpressionT);
692 ExpressionT ParseSuperExpression(bool is_new, 692 ExpressionT ParseSuperExpression(bool is_new,
693 ExpressionClassifier* classifier, bool* ok); 693 ExpressionClassifier* classifier, bool* ok);
694 ExpressionT ParseNewTargetExpression(bool* ok); 694 ExpressionT ParseNewTargetExpression(bool* ok);
695 ExpressionT ParseStrongInitializationExpression( 695 ExpressionT ParseStrongInitializationExpression(
696 ExpressionClassifier* classifier, bool* ok); 696 ExpressionClassifier* classifier, bool* ok);
697 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, 697 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier,
698 bool* ok); 698 bool* ok);
699 699
700 void ParseFormalParameter(bool is_rest, 700 void ParseFormalParameter(bool is_rest,
701 FormalParameterParsingStateT* parsing_result, 701 FormalParametersT* parameters,
702 ExpressionClassifier* classifier, bool* ok); 702 ExpressionClassifier* classifier, bool* ok);
703 int ParseFormalParameterList(FormalParameterParsingStateT* parsing_state, 703 int ParseFormalParameterList(FormalParametersT* parameters,
704 ExpressionClassifier* classifier, bool* ok); 704 ExpressionClassifier* classifier, bool* ok);
705 void CheckArityRestrictions( 705 void CheckArityRestrictions(
706 int param_count, FunctionLiteral::ArityRestriction arity_restriction, 706 int param_count, FunctionLiteral::ArityRestriction arity_restriction,
707 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); 707 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok);
708 708
709 // Checks if the expression is a valid reference expression (e.g., on the 709 // Checks if the expression is a valid reference expression (e.g., on the
710 // left-hand side of assignments). Although ruled out by ECMA as early errors, 710 // left-hand side of assignments). Although ruled out by ECMA as early errors,
711 // we allow calls for web compatibility and rewrite them to a runtime throw. 711 // we allow calls for web compatibility and rewrite them to a runtime throw.
712 ExpressionT CheckAndRewriteReferenceExpression( 712 ExpressionT CheckAndRewriteReferenceExpression(
713 ExpressionT expression, Scanner::Location location, 713 ExpressionT expression, Scanner::Location location,
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 // Return the object itself as AstVisitor and implement the needed 1302 // Return the object itself as AstVisitor and implement the needed
1303 // dummy method right in this class. 1303 // dummy method right in this class.
1304 PreParserFactory* visitor() { return this; } 1304 PreParserFactory* visitor() { return this; }
1305 int* ast_properties() { 1305 int* ast_properties() {
1306 static int dummy = 42; 1306 static int dummy = 42;
1307 return &dummy; 1307 return &dummy;
1308 } 1308 }
1309 }; 1309 };
1310 1310
1311 1311
1312 struct PreParserFormalParameterParsingState { 1312 struct PreParserFormalParameters {
1313 explicit PreParserFormalParameterParsingState(Scope* scope) 1313 explicit PreParserFormalParameters(Scope* scope)
1314 : scope(scope), 1314 : scope(scope),
1315 has_rest(false), 1315 has_rest(false),
1316 is_simple_parameter_list(true), 1316 is_simple(true),
1317 materialized_literals_count(0) {} 1317 materialized_literals_count(0) {}
1318 Scope* scope; 1318 Scope* scope;
1319 bool has_rest; 1319 bool has_rest;
1320 bool is_simple_parameter_list; 1320 bool is_simple;
1321 int materialized_literals_count; 1321 int materialized_literals_count;
1322 }; 1322 };
1323 1323
1324 1324
1325 class PreParser; 1325 class PreParser;
1326 1326
1327 class PreParserTraits { 1327 class PreParserTraits {
1328 public: 1328 public:
1329 struct Type { 1329 struct Type {
1330 // TODO(marja): To be removed. The Traits object should contain all the data 1330 // TODO(marja): To be removed. The Traits object should contain all the data
1331 // it needs. 1331 // it needs.
1332 typedef PreParser* Parser; 1332 typedef PreParser* Parser;
1333 1333
1334 // PreParser doesn't need to store generator variables. 1334 // PreParser doesn't need to store generator variables.
1335 typedef void GeneratorVariable; 1335 typedef void GeneratorVariable;
1336 1336
1337 typedef int AstProperties; 1337 typedef int AstProperties;
1338 1338
1339 // Return types for traversing functions. 1339 // Return types for traversing functions.
1340 typedef PreParserIdentifier Identifier; 1340 typedef PreParserIdentifier Identifier;
1341 typedef PreParserExpression Expression; 1341 typedef PreParserExpression Expression;
1342 typedef PreParserExpression YieldExpression; 1342 typedef PreParserExpression YieldExpression;
1343 typedef PreParserExpression FunctionLiteral; 1343 typedef PreParserExpression FunctionLiteral;
1344 typedef PreParserExpression ClassLiteral; 1344 typedef PreParserExpression ClassLiteral;
1345 typedef PreParserExpression ObjectLiteralProperty; 1345 typedef PreParserExpression ObjectLiteralProperty;
1346 typedef PreParserExpression Literal; 1346 typedef PreParserExpression Literal;
1347 typedef PreParserExpressionList ExpressionList; 1347 typedef PreParserExpressionList ExpressionList;
1348 typedef PreParserExpressionList PropertyList; 1348 typedef PreParserExpressionList PropertyList;
1349 typedef PreParserIdentifier FormalParameter; 1349 typedef PreParserIdentifier FormalParameter;
1350 typedef PreParserFormalParameters FormalParameters;
1350 typedef PreParserStatementList StatementList; 1351 typedef PreParserStatementList StatementList;
1351 typedef PreParserFormalParameterParsingState FormalParameterParsingState;
1352 1352
1353 // For constructing objects returned by the traversing functions. 1353 // For constructing objects returned by the traversing functions.
1354 typedef PreParserFactory Factory; 1354 typedef PreParserFactory Factory;
1355 }; 1355 };
1356 1356
1357 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 1357 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
1358 1358
1359 // Helper functions for recursive descent. 1359 // Helper functions for recursive descent.
1360 static bool IsEval(PreParserIdentifier identifier) { 1360 static bool IsEval(PreParserIdentifier identifier) {
1361 return identifier.IsEval(); 1361 return identifier.IsEval();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 1581
1582 static PreParserStatementList NewStatementList(int size, Zone* zone) { 1582 static PreParserStatementList NewStatementList(int size, Zone* zone) {
1583 return PreParserStatementList(); 1583 return PreParserStatementList();
1584 } 1584 }
1585 1585
1586 static PreParserExpressionList NewPropertyList(int size, Zone* zone) { 1586 static PreParserExpressionList NewPropertyList(int size, Zone* zone) {
1587 return PreParserExpressionList(); 1587 return PreParserExpressionList();
1588 } 1588 }
1589 1589
1590 static void AddParameterInitializationBlock( 1590 static void AddParameterInitializationBlock(
1591 const PreParserFormalParameterParsingState& formal_parameters, 1591 const PreParserFormalParameters& parameters,
1592 PreParserStatementList list, bool* ok) {} 1592 PreParserStatementList list, bool* ok) {}
1593 1593
1594 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, 1594 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count,
1595 int* expected_property_count, bool* ok) { 1595 int* expected_property_count, bool* ok) {
1596 UNREACHABLE(); 1596 UNREACHABLE();
1597 } 1597 }
1598 1598
1599 V8_INLINE PreParserStatementList ParseEagerFunctionBody( 1599 V8_INLINE PreParserStatementList ParseEagerFunctionBody(
1600 PreParserIdentifier function_name, int pos, 1600 PreParserIdentifier function_name, int pos,
1601 const PreParserFormalParameterParsingState& formal_parameters, 1601 const PreParserFormalParameters& parameters,
1602 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); 1602 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok);
1603 1603
1604 V8_INLINE void ParseArrowFunctionFormalParameters( 1604 V8_INLINE void ParseArrowFunctionFormalParameters(
1605 PreParserFormalParameterParsingState* parsing_state, 1605 PreParserFormalParameters* parameters,
1606 PreParserExpression expression, const Scanner::Location& params_loc, 1606 PreParserExpression expression, const Scanner::Location& params_loc,
1607 Scanner::Location* duplicate_loc, bool* ok); 1607 Scanner::Location* duplicate_loc, bool* ok);
1608 1608
1609 void ReindexLiterals( 1609 void ReindexLiterals(const PreParserFormalParameters& paramaters) {}
1610 const PreParserFormalParameterParsingState& parsing_state) {}
1611 1610
1612 struct TemplateLiteralState {}; 1611 struct TemplateLiteralState {};
1613 1612
1614 TemplateLiteralState OpenTemplateLiteral(int pos) { 1613 TemplateLiteralState OpenTemplateLiteral(int pos) {
1615 return TemplateLiteralState(); 1614 return TemplateLiteralState();
1616 } 1615 }
1617 void AddTemplateSpan(TemplateLiteralState*, bool) {} 1616 void AddTemplateSpan(TemplateLiteralState*, bool) {}
1618 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {} 1617 void AddTemplateExpression(TemplateLiteralState*, PreParserExpression) {}
1619 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int, 1618 PreParserExpression CloseTemplateLiteral(TemplateLiteralState*, int,
1620 PreParserExpression tag) { 1619 PreParserExpression tag) {
1621 if (IsTaggedTemplate(tag)) { 1620 if (IsTaggedTemplate(tag)) {
1622 // Emulate generation of array literals for tag callsite 1621 // Emulate generation of array literals for tag callsite
1623 // 1st is array of cooked strings, second is array of raw strings 1622 // 1st is array of cooked strings, second is array of raw strings
1624 MaterializeTemplateCallsiteLiterals(); 1623 MaterializeTemplateCallsiteLiterals();
1625 } 1624 }
1626 return EmptyExpression(); 1625 return EmptyExpression();
1627 } 1626 }
1628 inline void MaterializeTemplateCallsiteLiterals(); 1627 inline void MaterializeTemplateCallsiteLiterals();
1629 PreParserExpression NoTemplateTag() { 1628 PreParserExpression NoTemplateTag() {
1630 return PreParserExpression::NoTemplateTag(); 1629 return PreParserExpression::NoTemplateTag();
1631 } 1630 }
1632 static bool IsTaggedTemplate(const PreParserExpression tag) { 1631 static bool IsTaggedTemplate(const PreParserExpression tag) {
1633 return !tag.IsNoTemplateTag(); 1632 return !tag.IsNoTemplateTag();
1634 } 1633 }
1635 1634
1636 void DeclareFormalParameter(void* parsing_state, PreParserExpression pattern, 1635 void DeclareFormalParameter(PreParserFormalParameters* parameters,
1637 ExpressionClassifier* classifier, bool is_rest) {} 1636 PreParserExpression pattern, bool is_rest,
1637 ExpressionClassifier* classifier) {}
1638 1638
1639 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} 1639 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
1640 1640
1641 // Temporary glue; these functions will move to ParserBase. 1641 // Temporary glue; these functions will move to ParserBase.
1642 PreParserExpression ParseV8Intrinsic(bool* ok); 1642 PreParserExpression ParseV8Intrinsic(bool* ok);
1643 PreParserExpression ParseFunctionLiteral( 1643 PreParserExpression ParseFunctionLiteral(
1644 PreParserIdentifier name, Scanner::Location function_name_location, 1644 PreParserIdentifier name, Scanner::Location function_name_location,
1645 FunctionNameValidity function_name_validity, FunctionKind kind, 1645 FunctionNameValidity function_name_validity, FunctionKind kind,
1646 int function_token_position, FunctionLiteral::FunctionType type, 1646 int function_token_position, FunctionLiteral::FunctionType type,
1647 FunctionLiteral::ArityRestriction arity_restriction, 1647 FunctionLiteral::ArityRestriction arity_restriction,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 Statement ParseTryStatement(bool* ok); 1778 Statement ParseTryStatement(bool* ok);
1779 Statement ParseDebuggerStatement(bool* ok); 1779 Statement ParseDebuggerStatement(bool* ok);
1780 Expression ParseConditionalExpression(bool accept_IN, bool* ok); 1780 Expression ParseConditionalExpression(bool accept_IN, bool* ok);
1781 Expression ParseObjectLiteral(bool* ok); 1781 Expression ParseObjectLiteral(bool* ok);
1782 Expression ParseV8Intrinsic(bool* ok); 1782 Expression ParseV8Intrinsic(bool* ok);
1783 1783
1784 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, 1784 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count,
1785 int* expected_property_count, bool* ok); 1785 int* expected_property_count, bool* ok);
1786 V8_INLINE PreParserStatementList 1786 V8_INLINE PreParserStatementList
1787 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, 1787 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos,
1788 const FormalParameterParsingStateT& formal_parameters, 1788 const PreParserFormalParameters& parameters,
1789 Variable* fvar, Token::Value fvar_init_op, 1789 Variable* fvar, Token::Value fvar_init_op,
1790 FunctionKind kind, bool* ok); 1790 FunctionKind kind, bool* ok);
1791 1791
1792 Expression ParseFunctionLiteral( 1792 Expression ParseFunctionLiteral(
1793 Identifier name, Scanner::Location function_name_location, 1793 Identifier name, Scanner::Location function_name_location,
1794 FunctionNameValidity function_name_validity, FunctionKind kind, 1794 FunctionNameValidity function_name_validity, FunctionKind kind,
1795 int function_token_pos, FunctionLiteral::FunctionType function_type, 1795 int function_token_pos, FunctionLiteral::FunctionType function_type,
1796 FunctionLiteral::ArityRestriction arity_restriction, 1796 FunctionLiteral::ArityRestriction arity_restriction,
1797 LanguageMode language_mode, bool* ok); 1797 LanguageMode language_mode, bool* ok);
1798 void ParseLazyFunctionLiteralBody(bool* ok, 1798 void ParseLazyFunctionLiteralBody(bool* ok,
(...skipping 26 matching lines...) Expand all
1825 } 1825 }
1826 1826
1827 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, 1827 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function,
1828 PreParserExpressionList args, 1828 PreParserExpressionList args,
1829 int pos) { 1829 int pos) {
1830 return pre_parser_->factory()->NewCallNew(function, args, pos); 1830 return pre_parser_->factory()->NewCallNew(function, args, pos);
1831 } 1831 }
1832 1832
1833 1833
1834 void PreParserTraits::ParseArrowFunctionFormalParameters( 1834 void PreParserTraits::ParseArrowFunctionFormalParameters(
1835 PreParserFormalParameterParsingState* parsing_state, 1835 PreParserFormalParameters* parameters,
1836 PreParserExpression params, const Scanner::Location& params_loc, 1836 PreParserExpression params, const Scanner::Location& params_loc,
1837 Scanner::Location* duplicate_loc, bool* ok) { 1837 Scanner::Location* duplicate_loc, bool* ok) {
1838 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter 1838 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter
1839 // lists that are too long. 1839 // lists that are too long.
1840 } 1840 }
1841 1841
1842 1842
1843 PreParserStatementList PreParser::ParseEagerFunctionBody( 1843 PreParserStatementList PreParser::ParseEagerFunctionBody(
1844 PreParserIdentifier function_name, int pos, 1844 PreParserIdentifier function_name, int pos,
1845 const PreParserFormalParameterParsingState& formal_parameters, 1845 const PreParserFormalParameters& parameters,
1846 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) { 1846 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
1847 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); 1847 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
1848 1848
1849 ParseStatementList(Token::RBRACE, ok); 1849 ParseStatementList(Token::RBRACE, ok);
1850 if (!*ok) return PreParserStatementList(); 1850 if (!*ok) return PreParserStatementList();
1851 1851
1852 Expect(Token::RBRACE, ok); 1852 Expect(Token::RBRACE, ok);
1853 return PreParserStatementList(); 1853 return PreParserStatementList();
1854 } 1854 }
1855 1855
1856 1856
1857 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( 1857 PreParserStatementList PreParserTraits::ParseEagerFunctionBody(
1858 PreParserIdentifier function_name, int pos, 1858 PreParserIdentifier function_name, int pos,
1859 const PreParserFormalParameterParsingState& formal_parameters, 1859 const PreParserFormalParameters& parameters,
1860 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) { 1860 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
1861 return pre_parser_->ParseEagerFunctionBody( 1861 return pre_parser_->ParseEagerFunctionBody(
1862 function_name, pos, formal_parameters, fvar, fvar_init_op, kind, ok); 1862 function_name, pos, parameters, fvar, fvar_init_op, kind, ok);
1863 } 1863 }
1864 1864
1865 1865
1866 template <class Traits> 1866 template <class Traits>
1867 ParserBase<Traits>::FunctionState::FunctionState( 1867 ParserBase<Traits>::FunctionState::FunctionState(
1868 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, 1868 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope,
1869 FunctionKind kind, typename Traits::Type::Factory* factory) 1869 FunctionKind kind, typename Traits::Type::Factory* factory)
1870 : next_materialized_literal_index_(0), 1870 : next_materialized_literal_index_(0),
1871 expected_property_count_(0), 1871 expected_property_count_(0),
1872 this_location_(Scanner::Location::invalid()), 1872 this_location_(Scanner::Location::invalid()),
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 Token::String(Token::RPAREN)); 2259 Token::String(Token::RPAREN));
2260 // Give a good error to the user who might have typed e.g. "return();". 2260 // Give a good error to the user who might have typed e.g. "return();".
2261 if (peek() != Token::ARROW) { 2261 if (peek() != Token::ARROW) {
2262 ReportUnexpectedTokenAt(scanner_->peek_location(), peek(), 2262 ReportUnexpectedTokenAt(scanner_->peek_location(), peek(),
2263 MessageTemplate::kMissingArrow); 2263 MessageTemplate::kMissingArrow);
2264 *ok = false; 2264 *ok = false;
2265 return this->EmptyExpression(); 2265 return this->EmptyExpression();
2266 } 2266 }
2267 Scope* scope = 2267 Scope* scope =
2268 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 2268 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2269 FormalParameterParsingStateT parsing_state(scope); 2269 FormalParametersT parameters(scope);
2270 scope->set_start_position(beg_pos); 2270 scope->set_start_position(beg_pos);
2271 ExpressionClassifier args_classifier; 2271 ExpressionClassifier args_classifier;
2272 result = this->ParseArrowFunctionLiteral(parsing_state, args_classifier, 2272 result = this->ParseArrowFunctionLiteral(parameters, args_classifier,
2273 CHECK_OK); 2273 CHECK_OK);
2274 } else if (allow_harmony_arrow_functions() && 2274 } else if (allow_harmony_arrow_functions() &&
2275 allow_harmony_rest_params() && Check(Token::ELLIPSIS)) { 2275 allow_harmony_rest_params() && Check(Token::ELLIPSIS)) {
2276 // (...x) => y 2276 // (...x) => y
2277 Scope* scope = 2277 Scope* scope =
2278 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 2278 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2279 FormalParameterParsingStateT parsing_state(scope); 2279 FormalParametersT parameters(scope);
2280 scope->set_start_position(beg_pos); 2280 scope->set_start_position(beg_pos);
2281 ExpressionClassifier args_classifier; 2281 ExpressionClassifier args_classifier;
2282 const bool is_rest = true; 2282 const bool is_rest = true;
2283 this->ParseFormalParameter(is_rest, &parsing_state, &args_classifier, 2283 this->ParseFormalParameter(is_rest, &parameters, &args_classifier,
2284 CHECK_OK); 2284 CHECK_OK);
2285 if (peek() == Token::COMMA) { 2285 if (peek() == Token::COMMA) {
2286 ReportMessageAt(scanner()->peek_location(), 2286 ReportMessageAt(scanner()->peek_location(),
2287 MessageTemplate::kParamAfterRest); 2287 MessageTemplate::kParamAfterRest);
2288 *ok = false; 2288 *ok = false;
2289 return this->EmptyExpression(); 2289 return this->EmptyExpression();
2290 } 2290 }
2291 Expect(Token::RPAREN, CHECK_OK); 2291 Expect(Token::RPAREN, CHECK_OK);
2292 result = this->ParseArrowFunctionLiteral(parsing_state, args_classifier, 2292 result = this->ParseArrowFunctionLiteral(parameters, args_classifier,
2293 CHECK_OK); 2293 CHECK_OK);
2294 } else { 2294 } else {
2295 // Heuristically try to detect immediately called functions before 2295 // Heuristically try to detect immediately called functions before
2296 // seeing the call parentheses. 2296 // seeing the call parentheses.
2297 parenthesized_function_ = (peek() == Token::FUNCTION); 2297 parenthesized_function_ = (peek() == Token::FUNCTION);
2298 result = this->ParseExpression(true, classifier, CHECK_OK); 2298 result = this->ParseExpression(true, classifier, CHECK_OK);
2299 Expect(Token::RPAREN, CHECK_OK); 2299 Expect(Token::RPAREN, CHECK_OK);
2300 } 2300 }
2301 break; 2301 break;
2302 2302
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 ExpressionT expression = this->ParseConditionalExpression( 2829 ExpressionT expression = this->ParseConditionalExpression(
2830 accept_IN, &arrow_formals_classifier, CHECK_OK); 2830 accept_IN, &arrow_formals_classifier, CHECK_OK);
2831 2831
2832 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) { 2832 if (allow_harmony_arrow_functions() && peek() == Token::ARROW) {
2833 BindingPatternUnexpectedToken(classifier); 2833 BindingPatternUnexpectedToken(classifier);
2834 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 2834 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
2835 parenthesized_formals, CHECK_OK); 2835 parenthesized_formals, CHECK_OK);
2836 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); 2836 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos);
2837 Scope* scope = 2837 Scope* scope =
2838 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); 2838 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
2839 FormalParameterParsingStateT parsing_state(scope); 2839 FormalParametersT parameters(scope);
2840 checkpoint.Restore(&parsing_state.materialized_literals_count); 2840 checkpoint.Restore(&parameters.materialized_literals_count);
2841 2841
2842 scope->set_start_position(lhs_location.beg_pos); 2842 scope->set_start_position(lhs_location.beg_pos);
2843 Scanner::Location duplicate_loc = Scanner::Location::invalid(); 2843 Scanner::Location duplicate_loc = Scanner::Location::invalid();
2844 this->ParseArrowFunctionFormalParameters(&parsing_state, expression, loc, 2844 this->ParseArrowFunctionFormalParameters(&parameters, expression, loc,
2845 &duplicate_loc, CHECK_OK); 2845 &duplicate_loc, CHECK_OK);
2846 if (duplicate_loc.IsValid()) { 2846 if (duplicate_loc.IsValid()) {
2847 arrow_formals_classifier.RecordDuplicateFormalParameterError( 2847 arrow_formals_classifier.RecordDuplicateFormalParameterError(
2848 duplicate_loc); 2848 duplicate_loc);
2849 } 2849 }
2850 expression = this->ParseArrowFunctionLiteral( 2850 expression = this->ParseArrowFunctionLiteral(
2851 parsing_state, arrow_formals_classifier, CHECK_OK); 2851 parameters, arrow_formals_classifier, CHECK_OK);
2852 return expression; 2852 return expression;
2853 } 2853 }
2854 2854
2855 // "expression" was not itself an arrow function parameter list, but it might 2855 // "expression" was not itself an arrow function parameter list, but it might
2856 // form part of one. Propagate speculative formal parameter error locations. 2856 // form part of one. Propagate speculative formal parameter error locations.
2857 classifier->Accumulate(arrow_formals_classifier, 2857 classifier->Accumulate(arrow_formals_classifier,
2858 ExpressionClassifier::StandardProductions | 2858 ExpressionClassifier::StandardProductions |
2859 ExpressionClassifier::FormalParametersProductions); 2859 ExpressionClassifier::FormalParametersProductions);
2860 2860
2861 if (!Token::IsAssignmentOp(peek())) { 2861 if (!Token::IsAssignmentOp(peek())) {
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
3609 return expression; 3609 return expression;
3610 } 3610 }
3611 } 3611 }
3612 DCHECK(false); 3612 DCHECK(false);
3613 return this->EmptyExpression(); 3613 return this->EmptyExpression();
3614 } 3614 }
3615 3615
3616 3616
3617 template <class Traits> 3617 template <class Traits>
3618 void ParserBase<Traits>::ParseFormalParameter( 3618 void ParserBase<Traits>::ParseFormalParameter(
3619 bool is_rest, FormalParameterParsingStateT* parsing_state, 3619 bool is_rest, FormalParametersT* parameters,
3620 ExpressionClassifier* classifier, bool* ok) { 3620 ExpressionClassifier* classifier, bool* ok) {
3621 // FormalParameter[Yield,GeneratorParameter] : 3621 // FormalParameter[Yield,GeneratorParameter] :
3622 // BindingElement[?Yield, ?GeneratorParameter] 3622 // BindingElement[?Yield, ?GeneratorParameter]
3623 3623
3624 Token::Value next = peek(); 3624 Token::Value next = peek();
3625 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); 3625 ExpressionT pattern = ParsePrimaryExpression(classifier, ok);
3626 if (!*ok) return; 3626 if (!*ok) return;
3627 3627
3628 ValidateBindingPattern(classifier, ok); 3628 ValidateBindingPattern(classifier, ok);
3629 if (!*ok) return; 3629 if (!*ok) return;
3630 3630
3631 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) { 3631 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) {
3632 ReportUnexpectedToken(next); 3632 ReportUnexpectedToken(next);
3633 *ok = false; 3633 *ok = false;
3634 return; 3634 return;
3635 } 3635 }
3636 3636
3637 if (parsing_state->is_simple_parameter_list) { 3637 if (parameters->is_simple) {
3638 parsing_state->is_simple_parameter_list = 3638 parameters->is_simple = !is_rest && Traits::IsIdentifier(pattern);
3639 !is_rest && Traits::IsIdentifier(pattern);
3640 } 3639 }
3641 parsing_state->has_rest = is_rest; 3640 parameters->has_rest = is_rest;
3642 if (is_rest && !Traits::IsIdentifier(pattern)) { 3641 if (is_rest && !Traits::IsIdentifier(pattern)) {
3643 ReportUnexpectedToken(next); 3642 ReportUnexpectedToken(next);
3644 *ok = false; 3643 *ok = false;
3645 return; 3644 return;
3646 } 3645 }
3647 Traits::DeclareFormalParameter(parsing_state, pattern, classifier, is_rest); 3646 Traits::DeclareFormalParameter(parameters, pattern, is_rest, classifier);
3648 } 3647 }
3649 3648
3650 3649
3651 template <class Traits> 3650 template <class Traits>
3652 int ParserBase<Traits>::ParseFormalParameterList( 3651 int ParserBase<Traits>::ParseFormalParameterList(
3653 FormalParameterParsingStateT* parsing_state, 3652 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) {
3654 ExpressionClassifier* classifier, bool* ok) {
3655 // FormalParameters[Yield,GeneratorParameter] : 3653 // FormalParameters[Yield,GeneratorParameter] :
3656 // [empty] 3654 // [empty]
3657 // FormalParameterList[?Yield, ?GeneratorParameter] 3655 // FormalParameterList[?Yield, ?GeneratorParameter]
3658 // 3656 //
3659 // FormalParameterList[Yield,GeneratorParameter] : 3657 // FormalParameterList[Yield,GeneratorParameter] :
3660 // FunctionRestParameter[?Yield] 3658 // FunctionRestParameter[?Yield]
3661 // FormalsList[?Yield, ?GeneratorParameter] 3659 // FormalsList[?Yield, ?GeneratorParameter]
3662 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] 3660 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield]
3663 // 3661 //
3664 // FormalsList[Yield,GeneratorParameter] : 3662 // FormalsList[Yield,GeneratorParameter] :
3665 // FormalParameter[?Yield, ?GeneratorParameter] 3663 // FormalParameter[?Yield, ?GeneratorParameter]
3666 // FormalsList[?Yield, ?GeneratorParameter] , 3664 // FormalsList[?Yield, ?GeneratorParameter] ,
3667 // FormalParameter[?Yield,?GeneratorParameter] 3665 // FormalParameter[?Yield,?GeneratorParameter]
3668 3666
3669 int parameter_count = 0; 3667 int arity = 0;
3670 3668
3671 if (peek() != Token::RPAREN) { 3669 if (peek() != Token::RPAREN) {
3672 do { 3670 do {
3673 if (++parameter_count > Code::kMaxArguments) { 3671 if (++arity > Code::kMaxArguments) {
3674 ReportMessage(MessageTemplate::kTooManyParameters); 3672 ReportMessage(MessageTemplate::kTooManyParameters);
3675 *ok = false; 3673 *ok = false;
3676 return -1; 3674 return -1;
3677 } 3675 }
3678 bool is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); 3676 bool is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS);
3679 ParseFormalParameter(is_rest, parsing_state, classifier, ok); 3677 ParseFormalParameter(is_rest, parameters, classifier, ok);
3680 if (!*ok) return -1; 3678 if (!*ok) return -1;
3681 } while (!parsing_state->has_rest && Check(Token::COMMA)); 3679 } while (!parameters->has_rest && Check(Token::COMMA));
3682 3680
3683 if (parsing_state->has_rest && peek() == Token::COMMA) { 3681 if (parameters->has_rest && peek() == Token::COMMA) {
3684 ReportMessageAt(scanner()->peek_location(), 3682 ReportMessageAt(scanner()->peek_location(),
3685 MessageTemplate::kParamAfterRest); 3683 MessageTemplate::kParamAfterRest);
3686 *ok = false; 3684 *ok = false;
3687 return -1; 3685 return -1;
3688 } 3686 }
3689 } 3687 }
3690 3688
3691 return parameter_count; 3689 return arity;
3692 } 3690 }
3693 3691
3694 3692
3695 template <class Traits> 3693 template <class Traits>
3696 void ParserBase<Traits>::CheckArityRestrictions( 3694 void ParserBase<Traits>::CheckArityRestrictions(
3697 int param_count, FunctionLiteral::ArityRestriction arity_restriction, 3695 int param_count, FunctionLiteral::ArityRestriction arity_restriction,
3698 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { 3696 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) {
3699 switch (arity_restriction) { 3697 switch (arity_restriction) {
3700 case FunctionLiteral::GETTER_ARITY: 3698 case FunctionLiteral::GETTER_ARITY:
3701 if (param_count != 0) { 3699 if (param_count != 0) {
(...skipping 16 matching lines...) Expand all
3718 break; 3716 break;
3719 default: 3717 default:
3720 break; 3718 break;
3721 } 3719 }
3722 } 3720 }
3723 3721
3724 3722
3725 template <class Traits> 3723 template <class Traits>
3726 typename ParserBase<Traits>::ExpressionT 3724 typename ParserBase<Traits>::ExpressionT
3727 ParserBase<Traits>::ParseArrowFunctionLiteral( 3725 ParserBase<Traits>::ParseArrowFunctionLiteral(
3728 const FormalParameterParsingStateT& formal_parameters, 3726 const FormalParametersT& formal_parameters,
3729 const ExpressionClassifier& formals_classifier, bool* ok) { 3727 const ExpressionClassifier& formals_classifier, bool* ok) {
3730 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { 3728 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
3731 // ASI inserts `;` after arrow parameters if a line terminator is found. 3729 // ASI inserts `;` after arrow parameters if a line terminator is found.
3732 // `=> ...` is never a valid expression, so report as syntax error. 3730 // `=> ...` is never a valid expression, so report as syntax error.
3733 // If next token is not `=>`, it's a syntax error anyways. 3731 // If next token is not `=>`, it's a syntax error anyways.
3734 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); 3732 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
3735 *ok = false; 3733 *ok = false;
3736 return this->EmptyExpression(); 3734 return this->EmptyExpression();
3737 } 3735 }
3738 3736
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
4012 *ok = false; 4010 *ok = false;
4013 return; 4011 return;
4014 } 4012 }
4015 has_seen_constructor_ = true; 4013 has_seen_constructor_ = true;
4016 return; 4014 return;
4017 } 4015 }
4018 } 4016 }
4019 } } // v8::internal 4017 } } // v8::internal
4020 4018
4021 #endif // V8_PREPARSER_H 4019 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698