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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 707 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
708 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 708 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
709 bool* ok); | 709 bool* ok); |
710 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 710 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
711 bool* ok); | 711 bool* ok); |
712 ExpressionT ParseMemberWithNewPrefixesExpression( | 712 ExpressionT ParseMemberWithNewPrefixesExpression( |
713 ExpressionClassifier* classifier, bool* ok); | 713 ExpressionClassifier* classifier, bool* ok); |
714 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); | 714 ExpressionT ParseMemberExpression(ExpressionClassifier* classifier, bool* ok); |
715 ExpressionT ParseMemberExpressionContinuation( | 715 ExpressionT ParseMemberExpressionContinuation( |
716 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); | 716 ExpressionT expression, ExpressionClassifier* classifier, bool* ok); |
717 ExpressionT ParseArrowFunctionLiteral( | 717 ExpressionT ParseArrowFunctionLiteral(bool accept_IN, |
718 const FormalParametersT& parameters, | 718 const FormalParametersT& parameters, |
719 const ExpressionClassifier& classifier, bool* ok); | 719 const ExpressionClassifier& classifier, |
720 bool* ok); | |
720 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, | 721 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, |
721 ExpressionClassifier* classifier, bool* ok); | 722 ExpressionClassifier* classifier, bool* ok); |
722 void AddTemplateExpression(ExpressionT); | 723 void AddTemplateExpression(ExpressionT); |
723 ExpressionT ParseSuperExpression(bool is_new, | 724 ExpressionT ParseSuperExpression(bool is_new, |
724 ExpressionClassifier* classifier, bool* ok); | 725 ExpressionClassifier* classifier, bool* ok); |
725 ExpressionT ParseNewTargetExpression(bool* ok); | 726 ExpressionT ParseNewTargetExpression(bool* ok); |
726 ExpressionT ParseStrongInitializationExpression( | 727 ExpressionT ParseStrongInitializationExpression( |
727 ExpressionClassifier* classifier, bool* ok); | 728 ExpressionClassifier* classifier, bool* ok); |
728 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, | 729 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, |
729 bool* ok); | 730 bool* ok); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 bool IsArrowFunctionFormalParametersWithRestParameter() const { | 1068 bool IsArrowFunctionFormalParametersWithRestParameter() const { |
1068 // Iff the expression classifier has determined that this expression is a | 1069 // Iff the expression classifier has determined that this expression is a |
1069 // valid arrow fformal parameter list, return true if the formal parameter | 1070 // valid arrow fformal parameter list, return true if the formal parameter |
1070 // list ends with a rest parameter. | 1071 // list ends with a rest parameter. |
1071 return IsSpreadExpression() || | 1072 return IsSpreadExpression() || |
1072 (IsBinaryOperation() && HasRestField::decode(code_)); | 1073 (IsBinaryOperation() && HasRestField::decode(code_)); |
1073 } | 1074 } |
1074 | 1075 |
1075 PreParserExpression AsFunctionLiteral() { return *this; } | 1076 PreParserExpression AsFunctionLiteral() { return *this; } |
1076 | 1077 |
1078 // Only used by arrow functions with concise bodies, only for lazy parsing. | |
1079 void set_accept_IN(bool value) {} | |
1080 | |
1077 bool IsBinaryOperation() const { | 1081 bool IsBinaryOperation() const { |
1078 return TypeField::decode(code_) == kBinaryOperationExpression; | 1082 return TypeField::decode(code_) == kBinaryOperationExpression; |
1079 } | 1083 } |
1080 | 1084 |
1081 // Dummy implementation for making expression->somefunc() work in both Parser | 1085 // Dummy implementation for making expression->somefunc() work in both Parser |
1082 // and PreParser. | 1086 // and PreParser. |
1083 PreParserExpression* operator->() { return this; } | 1087 PreParserExpression* operator->() { return this; } |
1084 | 1088 |
1085 // More dummy implementations of things PreParser doesn't need to track: | 1089 // More dummy implementations of things PreParser doesn't need to track: |
1086 void set_index(int index) {} // For YieldExpressions | 1090 void set_index(int index) {} // For YieldExpressions |
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2939 &duplicate_loc, CHECK_OK); | 2943 &duplicate_loc, CHECK_OK); |
2940 | 2944 |
2941 checkpoint.Restore(¶meters.materialized_literals_count); | 2945 checkpoint.Restore(¶meters.materialized_literals_count); |
2942 | 2946 |
2943 scope->set_start_position(lhs_beg_pos); | 2947 scope->set_start_position(lhs_beg_pos); |
2944 if (duplicate_loc.IsValid()) { | 2948 if (duplicate_loc.IsValid()) { |
2945 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2949 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2946 duplicate_loc); | 2950 duplicate_loc); |
2947 } | 2951 } |
2948 expression = this->ParseArrowFunctionLiteral( | 2952 expression = this->ParseArrowFunctionLiteral( |
2949 parameters, arrow_formals_classifier, CHECK_OK); | 2953 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
2950 return expression; | 2954 return expression; |
2951 } | 2955 } |
2952 | 2956 |
2953 // "expression" was not itself an arrow function parameter list, but it might | 2957 // "expression" was not itself an arrow function parameter list, but it might |
2954 // form part of one. Propagate speculative formal parameter error locations. | 2958 // form part of one. Propagate speculative formal parameter error locations. |
2955 classifier->Accumulate(arrow_formals_classifier, | 2959 classifier->Accumulate(arrow_formals_classifier, |
2956 ExpressionClassifier::StandardProductions | | 2960 ExpressionClassifier::StandardProductions | |
2957 ExpressionClassifier::FormalParametersProductions); | 2961 ExpressionClassifier::FormalParametersProductions); |
2958 | 2962 |
2959 if (!Token::IsAssignmentOp(peek())) { | 2963 if (!Token::IsAssignmentOp(peek())) { |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3875 return true; | 3879 return true; |
3876 default: | 3880 default: |
3877 return false; | 3881 return false; |
3878 } | 3882 } |
3879 } | 3883 } |
3880 | 3884 |
3881 | 3885 |
3882 template <class Traits> | 3886 template <class Traits> |
3883 typename ParserBase<Traits>::ExpressionT | 3887 typename ParserBase<Traits>::ExpressionT |
3884 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3888 ParserBase<Traits>::ParseArrowFunctionLiteral( |
3885 const FormalParametersT& formal_parameters, | 3889 bool accept_IN, const FormalParametersT& formal_parameters, |
3886 const ExpressionClassifier& formals_classifier, bool* ok) { | 3890 const ExpressionClassifier& formals_classifier, bool* ok) { |
3887 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3891 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
3888 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3892 // ASI inserts `;` after arrow parameters if a line terminator is found. |
3889 // `=> ...` is never a valid expression, so report as syntax error. | 3893 // `=> ...` is never a valid expression, so report as syntax error. |
3890 // If next token is not `=>`, it's a syntax error anyways. | 3894 // If next token is not `=>`, it's a syntax error anyways. |
3891 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3895 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
3892 *ok = false; | 3896 *ok = false; |
3893 return this->EmptyExpression(); | 3897 return this->EmptyExpression(); |
3894 } | 3898 } |
3895 | 3899 |
3896 typename Traits::Type::StatementList body; | 3900 typename Traits::Type::StatementList body; |
3897 int num_parameters = formal_parameters.scope->num_parameters(); | 3901 int num_parameters = formal_parameters.scope->num_parameters(); |
3898 int materialized_literal_count = -1; | 3902 int materialized_literal_count = -1; |
3899 int expected_property_count = -1; | 3903 int expected_property_count = -1; |
3900 Scanner::Location super_loc; | 3904 Scanner::Location super_loc; |
3905 bool concise = false; | |
adamk
2015/10/14 12:46:44
I don't see this used anywhere (other than it bein
caitp (gmail)
2015/10/14 13:20:18
probably left over from an older version of the pa
| |
3901 | 3906 |
3902 { | 3907 { |
3903 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3908 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3904 FunctionState function_state(&function_state_, &scope_, | 3909 FunctionState function_state(&function_state_, &scope_, |
3905 formal_parameters.scope, kArrowFunction, | 3910 formal_parameters.scope, kArrowFunction, |
3906 &function_factory); | 3911 &function_factory); |
3907 | 3912 |
3908 function_state.SkipMaterializedLiterals( | 3913 function_state.SkipMaterializedLiterals( |
3909 formal_parameters.materialized_literals_count); | 3914 formal_parameters.materialized_literals_count); |
3910 | 3915 |
(...skipping 18 matching lines...) Expand all Loading... | |
3929 } else { | 3934 } else { |
3930 body = this->ParseEagerFunctionBody( | 3935 body = this->ParseEagerFunctionBody( |
3931 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, | 3936 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, |
3932 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); | 3937 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); |
3933 materialized_literal_count = | 3938 materialized_literal_count = |
3934 function_state.materialized_literal_count(); | 3939 function_state.materialized_literal_count(); |
3935 expected_property_count = function_state.expected_property_count(); | 3940 expected_property_count = function_state.expected_property_count(); |
3936 } | 3941 } |
3937 } else { | 3942 } else { |
3938 // Single-expression body | 3943 // Single-expression body |
3944 concise = true; | |
3939 int pos = position(); | 3945 int pos = position(); |
3940 parenthesized_function_ = false; | 3946 parenthesized_function_ = false; |
3941 ExpressionClassifier classifier; | 3947 ExpressionClassifier classifier; |
3942 ExpressionT expression = | 3948 ExpressionT expression = |
3943 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 3949 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); |
3944 ValidateExpression(&classifier, CHECK_OK); | 3950 ValidateExpression(&classifier, CHECK_OK); |
3945 body = this->NewStatementList(1, zone()); | 3951 body = this->NewStatementList(1, zone()); |
3946 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); | 3952 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); |
3947 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3953 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3948 materialized_literal_count = function_state.materialized_literal_count(); | 3954 materialized_literal_count = function_state.materialized_literal_count(); |
3949 expected_property_count = function_state.expected_property_count(); | 3955 expected_property_count = function_state.expected_property_count(); |
3950 } | 3956 } |
3951 super_loc = function_state.super_location(); | 3957 super_loc = function_state.super_location(); |
3952 | 3958 |
3953 formal_parameters.scope->set_end_position(scanner()->location().end_pos); | 3959 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
(...skipping 22 matching lines...) Expand all Loading... | |
3976 expected_property_count, num_parameters, | 3982 expected_property_count, num_parameters, |
3977 FunctionLiteral::kNoDuplicateParameters, | 3983 FunctionLiteral::kNoDuplicateParameters, |
3978 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 3984 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
3979 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, | 3985 FunctionLiteral::kShouldLazyCompile, FunctionKind::kArrowFunction, |
3980 formal_parameters.scope->start_position()); | 3986 formal_parameters.scope->start_position()); |
3981 | 3987 |
3982 function_literal->set_function_token_position( | 3988 function_literal->set_function_token_position( |
3983 formal_parameters.scope->start_position()); | 3989 formal_parameters.scope->start_position()); |
3984 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); | 3990 if (super_loc.IsValid()) function_state_->set_super_location(super_loc); |
3985 | 3991 |
3992 function_literal->set_accept_IN(accept_IN); | |
3993 | |
3986 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 3994 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
3987 | 3995 |
3988 return function_literal; | 3996 return function_literal; |
3989 } | 3997 } |
3990 | 3998 |
3991 | 3999 |
3992 template <typename Traits> | 4000 template <typename Traits> |
3993 typename ParserBase<Traits>::ExpressionT | 4001 typename ParserBase<Traits>::ExpressionT |
3994 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, | 4002 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, |
3995 ExpressionClassifier* classifier, | 4003 ExpressionClassifier* classifier, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4186 return; | 4194 return; |
4187 } | 4195 } |
4188 has_seen_constructor_ = true; | 4196 has_seen_constructor_ = true; |
4189 return; | 4197 return; |
4190 } | 4198 } |
4191 } | 4199 } |
4192 } // namespace internal | 4200 } // namespace internal |
4193 } // namespace v8 | 4201 } // namespace v8 |
4194 | 4202 |
4195 #endif // V8_PREPARSER_H | 4203 #endif // V8_PREPARSER_H |
OLD | NEW |