Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_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 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1317 : scope(scope), | 1317 : scope(scope), |
| 1318 arity(0), | 1318 arity(0), |
| 1319 has_rest(false), | 1319 has_rest(false), |
| 1320 is_simple(true), | 1320 is_simple(true), |
| 1321 materialized_literals_count(0) {} | 1321 materialized_literals_count(0) {} |
| 1322 Scope* scope; | 1322 Scope* scope; |
| 1323 int arity; | 1323 int arity; |
| 1324 bool has_rest; | 1324 bool has_rest; |
| 1325 bool is_simple; | 1325 bool is_simple; |
| 1326 int materialized_literals_count; | 1326 int materialized_literals_count; |
| 1327 | |
| 1328 PreParserIdentifier at(int i) { return PreParserIdentifier(); } // Dummy | |
| 1327 }; | 1329 }; |
| 1328 | 1330 |
| 1329 | 1331 |
| 1330 class PreParser; | 1332 class PreParser; |
| 1331 | 1333 |
| 1332 class PreParserTraits { | 1334 class PreParserTraits { |
| 1333 public: | 1335 public: |
| 1334 struct Type { | 1336 struct Type { |
| 1335 // TODO(marja): To be removed. The Traits object should contain all the data | 1337 // TODO(marja): To be removed. The Traits object should contain all the data |
| 1336 // it needs. | 1338 // it needs. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, | 1601 V8_INLINE void SkipLazyFunctionBody(int* materialized_literal_count, |
| 1600 int* expected_property_count, bool* ok) { | 1602 int* expected_property_count, bool* ok) { |
| 1601 UNREACHABLE(); | 1603 UNREACHABLE(); |
| 1602 } | 1604 } |
| 1603 | 1605 |
| 1604 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 1606 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
| 1605 PreParserIdentifier function_name, int pos, | 1607 PreParserIdentifier function_name, int pos, |
| 1606 const PreParserFormalParameters& parameters, | 1608 const PreParserFormalParameters& parameters, |
| 1607 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); | 1609 Variable* fvar, Token::Value fvar_init_op, FunctionKind kind, bool* ok); |
| 1608 | 1610 |
| 1609 V8_INLINE void ParseArrowFunctionFormalParameters( | 1611 V8_INLINE void ParseArrowFunctionFormalParameterList( |
| 1610 PreParserFormalParameters* parameters, | 1612 PreParserFormalParameters* parameters, |
| 1611 PreParserExpression expression, const Scanner::Location& params_loc, | 1613 PreParserExpression expression, const Scanner::Location& params_loc, |
| 1612 Scanner::Location* duplicate_loc, bool* ok); | 1614 Scanner::Location* duplicate_loc, bool* ok); |
| 1613 | 1615 |
| 1614 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} | 1616 void ReindexLiterals(const PreParserFormalParameters& paramaters) {} |
| 1615 | 1617 |
| 1616 struct TemplateLiteralState {}; | 1618 struct TemplateLiteralState {}; |
| 1617 | 1619 |
| 1618 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1620 TemplateLiteralState OpenTemplateLiteral(int pos) { |
| 1619 return TemplateLiteralState(); | 1621 return TemplateLiteralState(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1630 return EmptyExpression(); | 1632 return EmptyExpression(); |
| 1631 } | 1633 } |
| 1632 inline void MaterializeTemplateCallsiteLiterals(); | 1634 inline void MaterializeTemplateCallsiteLiterals(); |
| 1633 PreParserExpression NoTemplateTag() { | 1635 PreParserExpression NoTemplateTag() { |
| 1634 return PreParserExpression::NoTemplateTag(); | 1636 return PreParserExpression::NoTemplateTag(); |
| 1635 } | 1637 } |
| 1636 static bool IsTaggedTemplate(const PreParserExpression tag) { | 1638 static bool IsTaggedTemplate(const PreParserExpression tag) { |
| 1637 return !tag.IsNoTemplateTag(); | 1639 return !tag.IsNoTemplateTag(); |
| 1638 } | 1640 } |
| 1639 | 1641 |
| 1640 void DeclareFormalParameter(PreParserFormalParameters* parameters, | 1642 void AddFormalParameter( |
| 1641 PreParserExpression pattern, bool is_rest, | 1643 PreParserFormalParameters* parameters, PreParserExpression pattern, |
| 1644 bool is_rest) {} | |
|
adamk
2015/08/03 18:43:52
One option that would make this thing slightly les
| |
| 1645 void DeclareFormalParameter(Scope* scope, PreParserIdentifier parameter, | |
| 1646 bool is_simple, | |
| 1642 ExpressionClassifier* classifier) {} | 1647 ExpressionClassifier* classifier) {} |
| 1643 | 1648 |
| 1644 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 1649 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
| 1645 | 1650 |
| 1646 // Temporary glue; these functions will move to ParserBase. | 1651 // Temporary glue; these functions will move to ParserBase. |
| 1647 PreParserExpression ParseV8Intrinsic(bool* ok); | 1652 PreParserExpression ParseV8Intrinsic(bool* ok); |
| 1648 PreParserExpression ParseFunctionLiteral( | 1653 PreParserExpression ParseFunctionLiteral( |
| 1649 PreParserIdentifier name, Scanner::Location function_name_location, | 1654 PreParserIdentifier name, Scanner::Location function_name_location, |
| 1650 FunctionNameValidity function_name_validity, FunctionKind kind, | 1655 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 1651 int function_token_position, FunctionLiteral::FunctionType type, | 1656 int function_token_position, FunctionLiteral::FunctionType type, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1829 return pre_parser_->factory()->NewCall(function, args, pos); | 1834 return pre_parser_->factory()->NewCall(function, args, pos); |
| 1830 } | 1835 } |
| 1831 | 1836 |
| 1832 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, | 1837 PreParserExpression PreParserTraits::SpreadCallNew(PreParserExpression function, |
| 1833 PreParserExpressionList args, | 1838 PreParserExpressionList args, |
| 1834 int pos) { | 1839 int pos) { |
| 1835 return pre_parser_->factory()->NewCallNew(function, args, pos); | 1840 return pre_parser_->factory()->NewCallNew(function, args, pos); |
| 1836 } | 1841 } |
| 1837 | 1842 |
| 1838 | 1843 |
| 1839 void PreParserTraits::ParseArrowFunctionFormalParameters( | 1844 void PreParserTraits::ParseArrowFunctionFormalParameterList( |
| 1840 PreParserFormalParameters* parameters, | 1845 PreParserFormalParameters* parameters, |
| 1841 PreParserExpression params, const Scanner::Location& params_loc, | 1846 PreParserExpression params, const Scanner::Location& params_loc, |
| 1842 Scanner::Location* duplicate_loc, bool* ok) { | 1847 Scanner::Location* duplicate_loc, bool* ok) { |
| 1843 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter | 1848 // TODO(wingo): Detect duplicated identifiers in paramlists. Detect parameter |
| 1844 // lists that are too long. | 1849 // lists that are too long. |
| 1845 } | 1850 } |
| 1846 | 1851 |
| 1847 | 1852 |
| 1848 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1853 PreParserStatementList PreParser::ParseEagerFunctionBody( |
| 1849 PreParserIdentifier function_name, int pos, | 1854 PreParserIdentifier function_name, int pos, |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2274 FormalParametersT parameters(scope); | 2279 FormalParametersT parameters(scope); |
| 2275 scope->set_start_position(beg_pos); | 2280 scope->set_start_position(beg_pos); |
| 2276 ExpressionClassifier args_classifier; | 2281 ExpressionClassifier args_classifier; |
| 2277 result = this->ParseArrowFunctionLiteral(parameters, args_classifier, | 2282 result = this->ParseArrowFunctionLiteral(parameters, args_classifier, |
| 2278 CHECK_OK); | 2283 CHECK_OK); |
| 2279 } else if (allow_harmony_arrow_functions() && | 2284 } else if (allow_harmony_arrow_functions() && |
| 2280 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) { | 2285 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) { |
| 2281 // (...x) => y | 2286 // (...x) => y |
| 2282 Scope* scope = | 2287 Scope* scope = |
| 2283 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2288 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| 2284 FormalParametersT parameters(scope); | 2289 FormalParametersT formals(scope); |
| 2285 scope->set_start_position(beg_pos); | 2290 scope->set_start_position(beg_pos); |
| 2286 ExpressionClassifier args_classifier; | 2291 ExpressionClassifier formals_classifier; |
| 2287 const bool is_rest = true; | 2292 const bool is_rest = true; |
| 2288 this->ParseFormalParameter(is_rest, ¶meters, &args_classifier, | 2293 this->ParseFormalParameter(is_rest, &formals, &formals_classifier, |
| 2289 CHECK_OK); | 2294 CHECK_OK); |
| 2295 Traits::DeclareFormalParameter( | |
| 2296 formals.scope, formals.at(0), formals.is_simple, | |
| 2297 &formals_classifier); | |
| 2290 if (peek() == Token::COMMA) { | 2298 if (peek() == Token::COMMA) { |
| 2291 ReportMessageAt(scanner()->peek_location(), | 2299 ReportMessageAt(scanner()->peek_location(), |
| 2292 MessageTemplate::kParamAfterRest); | 2300 MessageTemplate::kParamAfterRest); |
| 2293 *ok = false; | 2301 *ok = false; |
| 2294 return this->EmptyExpression(); | 2302 return this->EmptyExpression(); |
| 2295 } | 2303 } |
| 2296 Expect(Token::RPAREN, CHECK_OK); | 2304 Expect(Token::RPAREN, CHECK_OK); |
| 2297 result = this->ParseArrowFunctionLiteral(parameters, args_classifier, | 2305 result = this->ParseArrowFunctionLiteral(formals, formals_classifier, |
| 2298 CHECK_OK); | 2306 CHECK_OK); |
| 2299 } else { | 2307 } else { |
| 2300 // Heuristically try to detect immediately called functions before | 2308 // Heuristically try to detect immediately called functions before |
| 2301 // seeing the call parentheses. | 2309 // seeing the call parentheses. |
| 2302 parenthesized_function_ = (peek() == Token::FUNCTION); | 2310 parenthesized_function_ = (peek() == Token::FUNCTION); |
| 2303 result = this->ParseExpression(true, classifier, CHECK_OK); | 2311 result = this->ParseExpression(true, classifier, CHECK_OK); |
| 2304 Expect(Token::RPAREN, CHECK_OK); | 2312 Expect(Token::RPAREN, CHECK_OK); |
| 2305 } | 2313 } |
| 2306 break; | 2314 break; |
| 2307 | 2315 |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2839 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 2847 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
| 2840 parenthesized_formals, CHECK_OK); | 2848 parenthesized_formals, CHECK_OK); |
| 2841 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); | 2849 Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos); |
| 2842 Scope* scope = | 2850 Scope* scope = |
| 2843 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); | 2851 this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| 2844 FormalParametersT parameters(scope); | 2852 FormalParametersT parameters(scope); |
| 2845 checkpoint.Restore(¶meters.materialized_literals_count); | 2853 checkpoint.Restore(¶meters.materialized_literals_count); |
| 2846 | 2854 |
| 2847 scope->set_start_position(lhs_location.beg_pos); | 2855 scope->set_start_position(lhs_location.beg_pos); |
| 2848 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2856 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
| 2849 this->ParseArrowFunctionFormalParameters(¶meters, expression, loc, | 2857 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
| 2850 &duplicate_loc, CHECK_OK); | 2858 &duplicate_loc, CHECK_OK); |
| 2851 if (duplicate_loc.IsValid()) { | 2859 if (duplicate_loc.IsValid()) { |
| 2852 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2860 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
| 2853 duplicate_loc); | 2861 duplicate_loc); |
| 2854 } | 2862 } |
| 2855 expression = this->ParseArrowFunctionLiteral( | 2863 expression = this->ParseArrowFunctionLiteral( |
| 2856 parameters, arrow_formals_classifier, CHECK_OK); | 2864 parameters, arrow_formals_classifier, CHECK_OK); |
| 2857 return expression; | 2865 return expression; |
| 2858 } | 2866 } |
| 2859 | 2867 |
| 2860 // "expression" was not itself an arrow function parameter list, but it might | 2868 // "expression" was not itself an arrow function parameter list, but it might |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3642 if (parameters->is_simple) { | 3650 if (parameters->is_simple) { |
| 3643 parameters->is_simple = !is_rest && Traits::IsIdentifier(pattern); | 3651 parameters->is_simple = !is_rest && Traits::IsIdentifier(pattern); |
| 3644 } | 3652 } |
| 3645 parameters->has_rest = is_rest; | 3653 parameters->has_rest = is_rest; |
| 3646 if (is_rest && !Traits::IsIdentifier(pattern)) { | 3654 if (is_rest && !Traits::IsIdentifier(pattern)) { |
| 3647 ReportUnexpectedToken(next); | 3655 ReportUnexpectedToken(next); |
| 3648 *ok = false; | 3656 *ok = false; |
| 3649 return; | 3657 return; |
| 3650 } | 3658 } |
| 3651 ++parameters->arity; | 3659 ++parameters->arity; |
| 3652 Traits::DeclareFormalParameter(parameters, pattern, is_rest, classifier); | 3660 Traits::AddFormalParameter(parameters, pattern, is_rest); |
| 3653 } | 3661 } |
| 3654 | 3662 |
| 3655 | 3663 |
| 3656 template <class Traits> | 3664 template <class Traits> |
| 3657 void ParserBase<Traits>::ParseFormalParameterList( | 3665 void ParserBase<Traits>::ParseFormalParameterList( |
| 3658 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { | 3666 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { |
| 3659 // FormalParameters[Yield,GeneratorParameter] : | 3667 // FormalParameters[Yield,GeneratorParameter] : |
| 3660 // [empty] | 3668 // [empty] |
| 3661 // FormalParameterList[?Yield, ?GeneratorParameter] | 3669 // FormalParameterList[?Yield, ?GeneratorParameter] |
| 3662 // | 3670 // |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 3681 } | 3689 } |
| 3682 bool is_rest = allow_harmony_rest_parameters() && Check(Token::ELLIPSIS); | 3690 bool is_rest = allow_harmony_rest_parameters() && Check(Token::ELLIPSIS); |
| 3683 ParseFormalParameter(is_rest, parameters, classifier, ok); | 3691 ParseFormalParameter(is_rest, parameters, classifier, ok); |
| 3684 if (!*ok) return; | 3692 if (!*ok) return; |
| 3685 } while (!parameters->has_rest && Check(Token::COMMA)); | 3693 } while (!parameters->has_rest && Check(Token::COMMA)); |
| 3686 | 3694 |
| 3687 if (parameters->has_rest && peek() == Token::COMMA) { | 3695 if (parameters->has_rest && peek() == Token::COMMA) { |
| 3688 ReportMessageAt(scanner()->peek_location(), | 3696 ReportMessageAt(scanner()->peek_location(), |
| 3689 MessageTemplate::kParamAfterRest); | 3697 MessageTemplate::kParamAfterRest); |
| 3690 *ok = false; | 3698 *ok = false; |
| 3699 return; | |
| 3691 } | 3700 } |
| 3692 } | 3701 } |
| 3702 | |
| 3703 for (int i = 0; i < parameters->arity; ++i) { | |
| 3704 auto parameter = parameters->at(i); | |
| 3705 Traits::DeclareFormalParameter( | |
| 3706 parameters->scope, parameter, parameters->is_simple, classifier); | |
| 3707 } | |
| 3693 } | 3708 } |
| 3694 | 3709 |
| 3695 | 3710 |
| 3696 template <class Traits> | 3711 template <class Traits> |
| 3697 void ParserBase<Traits>::CheckArityRestrictions( | 3712 void ParserBase<Traits>::CheckArityRestrictions( |
| 3698 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 3713 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
| 3699 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { | 3714 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok) { |
| 3700 switch (arity_restriction) { | 3715 switch (arity_restriction) { |
| 3701 case FunctionLiteral::GETTER_ARITY: | 3716 case FunctionLiteral::GETTER_ARITY: |
| 3702 if (param_count != 0) { | 3717 if (param_count != 0) { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4013 *ok = false; | 4028 *ok = false; |
| 4014 return; | 4029 return; |
| 4015 } | 4030 } |
| 4016 has_seen_constructor_ = true; | 4031 has_seen_constructor_ = true; |
| 4017 return; | 4032 return; |
| 4018 } | 4033 } |
| 4019 } | 4034 } |
| 4020 } } // v8::internal | 4035 } } // v8::internal |
| 4021 | 4036 |
| 4022 #endif // V8_PREPARSER_H | 4037 #endif // V8_PREPARSER_H |
| OLD | NEW |