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 2769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2780 typename Traits::Type::PropertyList properties = | 2780 typename Traits::Type::PropertyList properties = |
2781 this->NewPropertyList(4, zone_); | 2781 this->NewPropertyList(4, zone_); |
2782 int number_of_boilerplate_properties = 0; | 2782 int number_of_boilerplate_properties = 0; |
2783 bool has_function = false; | 2783 bool has_function = false; |
2784 bool has_computed_names = false; | 2784 bool has_computed_names = false; |
2785 ObjectLiteralChecker checker(this); | 2785 ObjectLiteralChecker checker(this); |
2786 | 2786 |
2787 Expect(Token::LBRACE, CHECK_OK); | 2787 Expect(Token::LBRACE, CHECK_OK); |
2788 | 2788 |
2789 while (peek() != Token::RBRACE) { | 2789 while (peek() != Token::RBRACE) { |
2790 if (fni_ != nullptr) fni_->Enter(); | 2790 FuncNameInferrer::State fni_state(fni_); |
2791 | 2791 |
2792 const bool in_class = false; | 2792 const bool in_class = false; |
2793 const bool is_static = false; | 2793 const bool is_static = false; |
2794 const bool has_extends = false; | 2794 const bool has_extends = false; |
2795 bool is_computed_name = false; | 2795 bool is_computed_name = false; |
2796 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | 2796 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( |
2797 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, | 2797 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, |
2798 classifier, CHECK_OK); | 2798 classifier, CHECK_OK); |
2799 | 2799 |
2800 if (is_computed_name) { | 2800 if (is_computed_name) { |
(...skipping 10 matching lines...) Expand all Loading... |
2811 if (!has_computed_names && this->IsBoilerplateProperty(property)) { | 2811 if (!has_computed_names && this->IsBoilerplateProperty(property)) { |
2812 number_of_boilerplate_properties++; | 2812 number_of_boilerplate_properties++; |
2813 } | 2813 } |
2814 properties->Add(property, zone()); | 2814 properties->Add(property, zone()); |
2815 | 2815 |
2816 if (peek() != Token::RBRACE) { | 2816 if (peek() != Token::RBRACE) { |
2817 // Need {} because of the CHECK_OK macro. | 2817 // Need {} because of the CHECK_OK macro. |
2818 Expect(Token::COMMA, CHECK_OK); | 2818 Expect(Token::COMMA, CHECK_OK); |
2819 } | 2819 } |
2820 | 2820 |
2821 if (fni_ != nullptr) { | 2821 if (fni_ != nullptr) fni_->Infer(); |
2822 fni_->Infer(); | |
2823 fni_->Leave(); | |
2824 } | |
2825 } | 2822 } |
2826 Expect(Token::RBRACE, CHECK_OK); | 2823 Expect(Token::RBRACE, CHECK_OK); |
2827 | 2824 |
2828 // Computation of literal_index must happen before pre parse bailout. | 2825 // Computation of literal_index must happen before pre parse bailout. |
2829 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 2826 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
2830 | 2827 |
2831 return factory()->NewObjectLiteral(properties, | 2828 return factory()->NewObjectLiteral(properties, |
2832 literal_index, | 2829 literal_index, |
2833 number_of_boilerplate_properties, | 2830 number_of_boilerplate_properties, |
2834 has_function, | 2831 has_function, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2914 // ArrowFunction | 2911 // ArrowFunction |
2915 // YieldExpression | 2912 // YieldExpression |
2916 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 2913 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
2917 | 2914 |
2918 int lhs_beg_pos = peek_position(); | 2915 int lhs_beg_pos = peek_position(); |
2919 | 2916 |
2920 if (peek() == Token::YIELD && is_generator()) { | 2917 if (peek() == Token::YIELD && is_generator()) { |
2921 return this->ParseYieldExpression(classifier, ok); | 2918 return this->ParseYieldExpression(classifier, ok); |
2922 } | 2919 } |
2923 | 2920 |
2924 if (fni_ != NULL) fni_->Enter(); | 2921 FuncNameInferrer::State fni_state(fni_); |
2925 ParserBase<Traits>::Checkpoint checkpoint(this); | 2922 ParserBase<Traits>::Checkpoint checkpoint(this); |
2926 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); | 2923 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); |
2927 bool parenthesized_formals = peek() == Token::LPAREN; | 2924 bool parenthesized_formals = peek() == Token::LPAREN; |
2928 if (!parenthesized_formals) { | 2925 if (!parenthesized_formals) { |
2929 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 2926 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
2930 } | 2927 } |
2931 ExpressionT expression = this->ParseConditionalExpression( | 2928 ExpressionT expression = this->ParseConditionalExpression( |
2932 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2929 accept_IN, &arrow_formals_classifier, CHECK_OK); |
2933 if (peek() == Token::ARROW) { | 2930 if (peek() == Token::ARROW) { |
2934 BindingPatternUnexpectedToken(classifier); | 2931 BindingPatternUnexpectedToken(classifier); |
(...skipping 18 matching lines...) Expand all Loading... |
2953 | 2950 |
2954 checkpoint.Restore(¶meters.materialized_literals_count); | 2951 checkpoint.Restore(¶meters.materialized_literals_count); |
2955 | 2952 |
2956 scope->set_start_position(lhs_beg_pos); | 2953 scope->set_start_position(lhs_beg_pos); |
2957 if (duplicate_loc.IsValid()) { | 2954 if (duplicate_loc.IsValid()) { |
2958 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2955 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2959 duplicate_loc); | 2956 duplicate_loc); |
2960 } | 2957 } |
2961 expression = this->ParseArrowFunctionLiteral( | 2958 expression = this->ParseArrowFunctionLiteral( |
2962 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2959 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
| 2960 |
| 2961 if (fni_ != nullptr) fni_->Infer(); |
| 2962 |
2963 return expression; | 2963 return expression; |
2964 } | 2964 } |
2965 | 2965 |
2966 // "expression" was not itself an arrow function parameter list, but it might | 2966 // "expression" was not itself an arrow function parameter list, but it might |
2967 // form part of one. Propagate speculative formal parameter error locations. | 2967 // form part of one. Propagate speculative formal parameter error locations. |
2968 classifier->Accumulate(arrow_formals_classifier, | 2968 classifier->Accumulate(arrow_formals_classifier, |
2969 ExpressionClassifier::StandardProductions | | 2969 ExpressionClassifier::StandardProductions | |
2970 ExpressionClassifier::FormalParametersProductions); | 2970 ExpressionClassifier::FormalParametersProductions); |
2971 | 2971 |
2972 if (!Token::IsAssignmentOp(peek())) { | 2972 if (!Token::IsAssignmentOp(peek())) { |
2973 if (fni_ != NULL) fni_->Leave(); | |
2974 // Parsed conditional expression only (no assignment). | 2973 // Parsed conditional expression only (no assignment). |
2975 return expression; | 2974 return expression; |
2976 } | 2975 } |
2977 | 2976 |
2978 if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) { | 2977 if (!(allow_harmony_destructuring() || allow_harmony_default_parameters())) { |
2979 BindingPatternUnexpectedToken(classifier); | 2978 BindingPatternUnexpectedToken(classifier); |
2980 } | 2979 } |
2981 | 2980 |
2982 expression = this->CheckAndRewriteReferenceExpression( | 2981 expression = this->CheckAndRewriteReferenceExpression( |
2983 expression, lhs_beg_pos, scanner()->location().end_pos, | 2982 expression, lhs_beg_pos, scanner()->location().end_pos, |
(...skipping 30 matching lines...) Expand all Loading... |
3014 // name if we're dealing with "a = function(){...}();"-like | 3013 // name if we're dealing with "a = function(){...}();"-like |
3015 // expression. | 3014 // expression. |
3016 if ((op == Token::INIT_VAR | 3015 if ((op == Token::INIT_VAR |
3017 || op == Token::INIT_CONST_LEGACY | 3016 || op == Token::INIT_CONST_LEGACY |
3018 || op == Token::ASSIGN) | 3017 || op == Token::ASSIGN) |
3019 && (!right->IsCall() && !right->IsCallNew())) { | 3018 && (!right->IsCall() && !right->IsCallNew())) { |
3020 fni_->Infer(); | 3019 fni_->Infer(); |
3021 } else { | 3020 } else { |
3022 fni_->RemoveLastFunction(); | 3021 fni_->RemoveLastFunction(); |
3023 } | 3022 } |
3024 fni_->Leave(); | |
3025 } | 3023 } |
3026 | 3024 |
3027 return factory()->NewAssignment(op, expression, right, pos); | 3025 return factory()->NewAssignment(op, expression, right, pos); |
3028 } | 3026 } |
3029 | 3027 |
3030 template <class Traits> | 3028 template <class Traits> |
3031 typename ParserBase<Traits>::ExpressionT | 3029 typename ParserBase<Traits>::ExpressionT |
3032 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, | 3030 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, |
3033 bool* ok) { | 3031 bool* ok) { |
3034 // YieldExpression :: | 3032 // YieldExpression :: |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3481 | 3479 |
3482 | 3480 |
3483 template <class Traits> | 3481 template <class Traits> |
3484 typename ParserBase<Traits>::ExpressionT | 3482 typename ParserBase<Traits>::ExpressionT |
3485 ParserBase<Traits>::ParseStrongInitializationExpression( | 3483 ParserBase<Traits>::ParseStrongInitializationExpression( |
3486 ExpressionClassifier* classifier, bool* ok) { | 3484 ExpressionClassifier* classifier, bool* ok) { |
3487 // InitializationExpression :: (strong mode) | 3485 // InitializationExpression :: (strong mode) |
3488 // 'this' '.' IdentifierName '=' AssignmentExpression | 3486 // 'this' '.' IdentifierName '=' AssignmentExpression |
3489 // 'this' '[' Expression ']' '=' AssignmentExpression | 3487 // 'this' '[' Expression ']' '=' AssignmentExpression |
3490 | 3488 |
3491 if (fni_ != NULL) fni_->Enter(); | 3489 FuncNameInferrer::State fni_state(fni_); |
3492 | 3490 |
3493 Consume(Token::THIS); | 3491 Consume(Token::THIS); |
3494 int pos = position(); | 3492 int pos = position(); |
3495 function_state_->set_this_location(scanner()->location()); | 3493 function_state_->set_this_location(scanner()->location()); |
3496 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 3494 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); |
3497 | 3495 |
3498 ExpressionT left = this->EmptyExpression(); | 3496 ExpressionT left = this->EmptyExpression(); |
3499 switch (peek()) { | 3497 switch (peek()) { |
3500 case Token::LBRACK: { | 3498 case Token::LBRACK: { |
3501 Consume(Token::LBRACK); | 3499 Consume(Token::LBRACK); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3540 function_state_->AddProperty(); | 3538 function_state_->AddProperty(); |
3541 if (fni_ != NULL) { | 3539 if (fni_ != NULL) { |
3542 // Check if the right hand side is a call to avoid inferring a | 3540 // Check if the right hand side is a call to avoid inferring a |
3543 // name if we're dealing with "this.a = function(){...}();"-like | 3541 // name if we're dealing with "this.a = function(){...}();"-like |
3544 // expression. | 3542 // expression. |
3545 if (!right->IsCall() && !right->IsCallNew()) { | 3543 if (!right->IsCall() && !right->IsCallNew()) { |
3546 fni_->Infer(); | 3544 fni_->Infer(); |
3547 } else { | 3545 } else { |
3548 fni_->RemoveLastFunction(); | 3546 fni_->RemoveLastFunction(); |
3549 } | 3547 } |
3550 fni_->Leave(); | |
3551 } | 3548 } |
3552 | 3549 |
3553 if (function_state_->return_location().IsValid()) { | 3550 if (function_state_->return_location().IsValid()) { |
3554 ReportMessageAt(function_state_->return_location(), | 3551 ReportMessageAt(function_state_->return_location(), |
3555 MessageTemplate::kStrongConstructorReturnMisplaced); | 3552 MessageTemplate::kStrongConstructorReturnMisplaced); |
3556 *ok = false; | 3553 *ok = false; |
3557 return this->EmptyExpression(); | 3554 return this->EmptyExpression(); |
3558 } | 3555 } |
3559 | 3556 |
3560 return factory()->NewAssignment(Token::ASSIGN, left, right, pos); | 3557 return factory()->NewAssignment(Token::ASSIGN, left, right, pos); |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4199 return; | 4196 return; |
4200 } | 4197 } |
4201 has_seen_constructor_ = true; | 4198 has_seen_constructor_ = true; |
4202 return; | 4199 return; |
4203 } | 4200 } |
4204 } | 4201 } |
4205 } // namespace internal | 4202 } // namespace internal |
4206 } // namespace v8 | 4203 } // namespace v8 |
4207 | 4204 |
4208 #endif // V8_PREPARSER_H | 4205 #endif // V8_PREPARSER_H |
OLD | NEW |