| 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/bailout-reason.h" | 8 #include "src/bailout-reason.h" |
| 9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" |
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 zone_(zone), | 104 zone_(zone), |
| 105 scanner_(scanner), | 105 scanner_(scanner), |
| 106 stack_overflow_(false), | 106 stack_overflow_(false), |
| 107 allow_lazy_(false), | 107 allow_lazy_(false), |
| 108 allow_natives_(false), | 108 allow_natives_(false), |
| 109 allow_harmony_arrow_functions_(false), | 109 allow_harmony_arrow_functions_(false), |
| 110 allow_harmony_sloppy_(false), | 110 allow_harmony_sloppy_(false), |
| 111 allow_harmony_sloppy_function_(false), | 111 allow_harmony_sloppy_function_(false), |
| 112 allow_harmony_sloppy_let_(false), | 112 allow_harmony_sloppy_let_(false), |
| 113 allow_harmony_rest_parameters_(false), | 113 allow_harmony_rest_parameters_(false), |
| 114 allow_harmony_default_parameters_(false), |
| 114 allow_harmony_spreadcalls_(false), | 115 allow_harmony_spreadcalls_(false), |
| 115 allow_harmony_destructuring_(false), | 116 allow_harmony_destructuring_(false), |
| 116 allow_harmony_spread_arrays_(false), | 117 allow_harmony_spread_arrays_(false), |
| 117 allow_harmony_new_target_(false), | 118 allow_harmony_new_target_(false), |
| 118 allow_strong_mode_(false), | 119 allow_strong_mode_(false), |
| 119 allow_legacy_const_(true) {} | 120 allow_legacy_const_(true) {} |
| 120 | 121 |
| 121 #define ALLOW_ACCESSORS(name) \ | 122 #define ALLOW_ACCESSORS(name) \ |
| 122 bool allow_##name() const { return allow_##name##_; } \ | 123 bool allow_##name() const { return allow_##name##_; } \ |
| 123 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 124 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
| 124 | 125 |
| 125 ALLOW_ACCESSORS(lazy); | 126 ALLOW_ACCESSORS(lazy); |
| 126 ALLOW_ACCESSORS(natives); | 127 ALLOW_ACCESSORS(natives); |
| 127 ALLOW_ACCESSORS(harmony_arrow_functions); | 128 ALLOW_ACCESSORS(harmony_arrow_functions); |
| 128 ALLOW_ACCESSORS(harmony_sloppy); | 129 ALLOW_ACCESSORS(harmony_sloppy); |
| 129 ALLOW_ACCESSORS(harmony_sloppy_function); | 130 ALLOW_ACCESSORS(harmony_sloppy_function); |
| 130 ALLOW_ACCESSORS(harmony_sloppy_let); | 131 ALLOW_ACCESSORS(harmony_sloppy_let); |
| 131 ALLOW_ACCESSORS(harmony_rest_parameters); | 132 ALLOW_ACCESSORS(harmony_rest_parameters); |
| 133 ALLOW_ACCESSORS(harmony_default_parameters); |
| 132 ALLOW_ACCESSORS(harmony_spreadcalls); | 134 ALLOW_ACCESSORS(harmony_spreadcalls); |
| 133 ALLOW_ACCESSORS(harmony_destructuring); | 135 ALLOW_ACCESSORS(harmony_destructuring); |
| 134 ALLOW_ACCESSORS(harmony_spread_arrays); | 136 ALLOW_ACCESSORS(harmony_spread_arrays); |
| 135 ALLOW_ACCESSORS(harmony_new_target); | 137 ALLOW_ACCESSORS(harmony_new_target); |
| 136 ALLOW_ACCESSORS(strong_mode); | 138 ALLOW_ACCESSORS(strong_mode); |
| 137 ALLOW_ACCESSORS(legacy_const); | 139 ALLOW_ACCESSORS(legacy_const); |
| 138 #undef ALLOW_ACCESSORS | 140 #undef ALLOW_ACCESSORS |
| 139 | 141 |
| 140 protected: | 142 protected: |
| 141 enum AllowRestrictedIdentifiers { | 143 enum AllowRestrictedIdentifiers { |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 Scanner* scanner_; | 800 Scanner* scanner_; |
| 799 bool stack_overflow_; | 801 bool stack_overflow_; |
| 800 | 802 |
| 801 bool allow_lazy_; | 803 bool allow_lazy_; |
| 802 bool allow_natives_; | 804 bool allow_natives_; |
| 803 bool allow_harmony_arrow_functions_; | 805 bool allow_harmony_arrow_functions_; |
| 804 bool allow_harmony_sloppy_; | 806 bool allow_harmony_sloppy_; |
| 805 bool allow_harmony_sloppy_function_; | 807 bool allow_harmony_sloppy_function_; |
| 806 bool allow_harmony_sloppy_let_; | 808 bool allow_harmony_sloppy_let_; |
| 807 bool allow_harmony_rest_parameters_; | 809 bool allow_harmony_rest_parameters_; |
| 810 bool allow_harmony_default_parameters_; |
| 808 bool allow_harmony_spreadcalls_; | 811 bool allow_harmony_spreadcalls_; |
| 809 bool allow_harmony_destructuring_; | 812 bool allow_harmony_destructuring_; |
| 810 bool allow_harmony_spread_arrays_; | 813 bool allow_harmony_spread_arrays_; |
| 811 bool allow_harmony_new_target_; | 814 bool allow_harmony_new_target_; |
| 812 bool allow_strong_mode_; | 815 bool allow_strong_mode_; |
| 813 bool allow_legacy_const_; | 816 bool allow_legacy_const_; |
| 814 }; | 817 }; |
| 815 | 818 |
| 816 | 819 |
| 817 class PreParserIdentifier { | 820 class PreParserIdentifier { |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 inline void MaterializeTemplateCallsiteLiterals(); | 1633 inline void MaterializeTemplateCallsiteLiterals(); |
| 1631 PreParserExpression NoTemplateTag() { | 1634 PreParserExpression NoTemplateTag() { |
| 1632 return PreParserExpression::NoTemplateTag(); | 1635 return PreParserExpression::NoTemplateTag(); |
| 1633 } | 1636 } |
| 1634 static bool IsTaggedTemplate(const PreParserExpression tag) { | 1637 static bool IsTaggedTemplate(const PreParserExpression tag) { |
| 1635 return !tag.IsNoTemplateTag(); | 1638 return !tag.IsNoTemplateTag(); |
| 1636 } | 1639 } |
| 1637 | 1640 |
| 1638 void AddFormalParameter( | 1641 void AddFormalParameter( |
| 1639 PreParserFormalParameters* parameters, PreParserExpression pattern, | 1642 PreParserFormalParameters* parameters, PreParserExpression pattern, |
| 1640 bool is_rest) { | 1643 PreParserExpression initializer, bool is_rest) { |
| 1641 ++parameters->arity; | 1644 ++parameters->arity; |
| 1642 } | 1645 } |
| 1643 void DeclareFormalParameter(Scope* scope, PreParserIdentifier parameter, | 1646 void DeclareFormalParameter(Scope* scope, PreParserIdentifier parameter, |
| 1644 bool is_simple, | 1647 bool is_simple, |
| 1645 ExpressionClassifier* classifier) {} | 1648 ExpressionClassifier* classifier) {} |
| 1646 | 1649 |
| 1647 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} | 1650 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
| 1648 | 1651 |
| 1649 // Temporary glue; these functions will move to ParserBase. | 1652 // Temporary glue; these functions will move to ParserBase. |
| 1650 PreParserExpression ParseV8Intrinsic(bool* ok); | 1653 PreParserExpression ParseV8Intrinsic(bool* ok); |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2866 classifier->Accumulate(arrow_formals_classifier, | 2869 classifier->Accumulate(arrow_formals_classifier, |
| 2867 ExpressionClassifier::StandardProductions | | 2870 ExpressionClassifier::StandardProductions | |
| 2868 ExpressionClassifier::FormalParametersProductions); | 2871 ExpressionClassifier::FormalParametersProductions); |
| 2869 | 2872 |
| 2870 if (!Token::IsAssignmentOp(peek())) { | 2873 if (!Token::IsAssignmentOp(peek())) { |
| 2871 if (fni_ != NULL) fni_->Leave(); | 2874 if (fni_ != NULL) fni_->Leave(); |
| 2872 // Parsed conditional expression only (no assignment). | 2875 // Parsed conditional expression only (no assignment). |
| 2873 return expression; | 2876 return expression; |
| 2874 } | 2877 } |
| 2875 | 2878 |
| 2876 if (!allow_harmony_destructuring()) { | 2879 if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) { |
| 2877 BindingPatternUnexpectedToken(classifier); | 2880 BindingPatternUnexpectedToken(classifier); |
| 2878 } | 2881 } |
| 2879 | 2882 |
| 2880 expression = this->CheckAndRewriteReferenceExpression( | 2883 expression = this->CheckAndRewriteReferenceExpression( |
| 2881 expression, lhs_beg_pos, scanner()->location().end_pos, | 2884 expression, lhs_beg_pos, scanner()->location().end_pos, |
| 2882 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); | 2885 MessageTemplate::kInvalidLhsInAssignment, CHECK_OK); |
| 2883 expression = this->MarkExpressionAsAssigned(expression); | 2886 expression = this->MarkExpressionAsAssigned(expression); |
| 2884 | 2887 |
| 2885 Token::Value op = Next(); // Get assignment operator. | 2888 Token::Value op = Next(); // Get assignment operator. |
| 2886 if (op != Token::ASSIGN) { | 2889 if (op != Token::ASSIGN) { |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3631 // BindingElement[?Yield, ?GeneratorParameter] | 3634 // BindingElement[?Yield, ?GeneratorParameter] |
| 3632 bool is_rest = parameters->has_rest; | 3635 bool is_rest = parameters->has_rest; |
| 3633 | 3636 |
| 3634 Token::Value next = peek(); | 3637 Token::Value next = peek(); |
| 3635 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); | 3638 ExpressionT pattern = ParsePrimaryExpression(classifier, ok); |
| 3636 if (!*ok) return; | 3639 if (!*ok) return; |
| 3637 | 3640 |
| 3638 ValidateBindingPattern(classifier, ok); | 3641 ValidateBindingPattern(classifier, ok); |
| 3639 if (!*ok) return; | 3642 if (!*ok) return; |
| 3640 | 3643 |
| 3641 if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) { | 3644 if (!Traits::IsIdentifier(pattern)) { |
| 3642 ReportUnexpectedToken(next); | 3645 if (is_rest || !allow_harmony_destructuring()) { |
| 3643 *ok = false; | 3646 ReportUnexpectedToken(next); |
| 3644 return; | 3647 *ok = false; |
| 3648 return; |
| 3649 } |
| 3650 parameters->is_simple = false; |
| 3645 } | 3651 } |
| 3646 | 3652 |
| 3647 if (parameters->is_simple) { | 3653 ExpressionT initializer = Traits::EmptyExpression(); |
| 3648 parameters->is_simple = !is_rest && Traits::IsIdentifier(pattern); | 3654 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { |
| 3655 ExpressionClassifier init_classifier; |
| 3656 initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
| 3657 if (!*ok) return; |
| 3658 ValidateExpression(&init_classifier, ok); |
| 3659 if (!*ok) return; |
| 3660 parameters->is_simple = false; |
| 3649 } | 3661 } |
| 3650 parameters->has_rest = is_rest; | 3662 |
| 3651 if (is_rest && !Traits::IsIdentifier(pattern)) { | 3663 Traits::AddFormalParameter(parameters, pattern, initializer, is_rest); |
| 3652 ReportUnexpectedToken(next); | |
| 3653 *ok = false; | |
| 3654 return; | |
| 3655 } | |
| 3656 Traits::AddFormalParameter(parameters, pattern, is_rest); | |
| 3657 } | 3664 } |
| 3658 | 3665 |
| 3659 | 3666 |
| 3660 template <class Traits> | 3667 template <class Traits> |
| 3661 void ParserBase<Traits>::ParseFormalParameterList( | 3668 void ParserBase<Traits>::ParseFormalParameterList( |
| 3662 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { | 3669 FormalParametersT* parameters, ExpressionClassifier* classifier, bool* ok) { |
| 3663 // FormalParameters[Yield,GeneratorParameter] : | 3670 // FormalParameters[Yield,GeneratorParameter] : |
| 3664 // [empty] | 3671 // [empty] |
| 3665 // FormalParameterList[?Yield, ?GeneratorParameter] | 3672 // FormalParameterList[?Yield, ?GeneratorParameter] |
| 3666 // | 3673 // |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3682 ReportMessage(MessageTemplate::kTooManyParameters); | 3689 ReportMessage(MessageTemplate::kTooManyParameters); |
| 3683 *ok = false; | 3690 *ok = false; |
| 3684 return; | 3691 return; |
| 3685 } | 3692 } |
| 3686 parameters->has_rest = | 3693 parameters->has_rest = |
| 3687 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS); | 3694 allow_harmony_rest_parameters() && Check(Token::ELLIPSIS); |
| 3688 ParseFormalParameter(parameters, classifier, ok); | 3695 ParseFormalParameter(parameters, classifier, ok); |
| 3689 if (!*ok) return; | 3696 if (!*ok) return; |
| 3690 } while (!parameters->has_rest && Check(Token::COMMA)); | 3697 } while (!parameters->has_rest && Check(Token::COMMA)); |
| 3691 | 3698 |
| 3692 if (parameters->has_rest && peek() == Token::COMMA) { | 3699 if (parameters->has_rest) { |
| 3693 ReportMessageAt(scanner()->peek_location(), | 3700 parameters->is_simple = false; |
| 3701 if (peek() == Token::COMMA) { |
| 3702 ReportMessageAt(scanner()->peek_location(), |
| 3694 MessageTemplate::kParamAfterRest); | 3703 MessageTemplate::kParamAfterRest); |
| 3695 *ok = false; | 3704 *ok = false; |
| 3696 return; | 3705 return; |
| 3706 } |
| 3697 } | 3707 } |
| 3698 } | 3708 } |
| 3699 | 3709 |
| 3700 for (int i = 0; i < parameters->Arity(); ++i) { | 3710 for (int i = 0; i < parameters->Arity(); ++i) { |
| 3701 auto parameter = parameters->at(i); | 3711 auto parameter = parameters->at(i); |
| 3702 Traits::DeclareFormalParameter( | 3712 Traits::DeclareFormalParameter( |
| 3703 parameters->scope, parameter, parameters->is_simple, classifier); | 3713 parameters->scope, parameter, parameters->is_simple, classifier); |
| 3704 } | 3714 } |
| 3705 } | 3715 } |
| 3706 | 3716 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4036 *ok = false; | 4046 *ok = false; |
| 4037 return; | 4047 return; |
| 4038 } | 4048 } |
| 4039 has_seen_constructor_ = true; | 4049 has_seen_constructor_ = true; |
| 4040 return; | 4050 return; |
| 4041 } | 4051 } |
| 4042 } | 4052 } |
| 4043 } } // v8::internal | 4053 } } // v8::internal |
| 4044 | 4054 |
| 4045 #endif // V8_PREPARSER_H | 4055 #endif // V8_PREPARSER_H |
| OLD | NEW |