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 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2939 &duplicate_loc, CHECK_OK); | 2940 &duplicate_loc, CHECK_OK); |
2940 | 2941 |
2941 checkpoint.Restore(¶meters.materialized_literals_count); | 2942 checkpoint.Restore(¶meters.materialized_literals_count); |
2942 | 2943 |
2943 scope->set_start_position(lhs_beg_pos); | 2944 scope->set_start_position(lhs_beg_pos); |
2944 if (duplicate_loc.IsValid()) { | 2945 if (duplicate_loc.IsValid()) { |
2945 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2946 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2946 duplicate_loc); | 2947 duplicate_loc); |
2947 } | 2948 } |
2948 expression = this->ParseArrowFunctionLiteral( | 2949 expression = this->ParseArrowFunctionLiteral( |
2949 parameters, arrow_formals_classifier, CHECK_OK); | 2950 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
2950 return expression; | 2951 return expression; |
2951 } | 2952 } |
2952 | 2953 |
2953 // "expression" was not itself an arrow function parameter list, but it might | 2954 // "expression" was not itself an arrow function parameter list, but it might |
2954 // form part of one. Propagate speculative formal parameter error locations. | 2955 // form part of one. Propagate speculative formal parameter error locations. |
2955 classifier->Accumulate(arrow_formals_classifier, | 2956 classifier->Accumulate(arrow_formals_classifier, |
2956 ExpressionClassifier::StandardProductions | | 2957 ExpressionClassifier::StandardProductions | |
2957 ExpressionClassifier::FormalParametersProductions); | 2958 ExpressionClassifier::FormalParametersProductions); |
2958 | 2959 |
2959 if (!Token::IsAssignmentOp(peek())) { | 2960 if (!Token::IsAssignmentOp(peek())) { |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3875 return true; | 3876 return true; |
3876 default: | 3877 default: |
3877 return false; | 3878 return false; |
3878 } | 3879 } |
3879 } | 3880 } |
3880 | 3881 |
3881 | 3882 |
3882 template <class Traits> | 3883 template <class Traits> |
3883 typename ParserBase<Traits>::ExpressionT | 3884 typename ParserBase<Traits>::ExpressionT |
3884 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3885 ParserBase<Traits>::ParseArrowFunctionLiteral( |
3885 const FormalParametersT& formal_parameters, | 3886 bool accept_IN, const FormalParametersT& formal_parameters, |
3886 const ExpressionClassifier& formals_classifier, bool* ok) { | 3887 const ExpressionClassifier& formals_classifier, bool* ok) { |
3887 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3888 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
3888 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3889 // ASI inserts `;` after arrow parameters if a line terminator is found. |
3889 // `=> ...` is never a valid expression, so report as syntax error. | 3890 // `=> ...` is never a valid expression, so report as syntax error. |
3890 // If next token is not `=>`, it's a syntax error anyways. | 3891 // If next token is not `=>`, it's a syntax error anyways. |
3891 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3892 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
3892 *ok = false; | 3893 *ok = false; |
3893 return this->EmptyExpression(); | 3894 return this->EmptyExpression(); |
3894 } | 3895 } |
3895 | 3896 |
3896 typename Traits::Type::StatementList body; | 3897 typename Traits::Type::StatementList body; |
3897 int num_parameters = formal_parameters.scope->num_parameters(); | 3898 int num_parameters = formal_parameters.scope->num_parameters(); |
3898 int materialized_literal_count = -1; | 3899 int materialized_literal_count = -1; |
3899 int expected_property_count = -1; | 3900 int expected_property_count = -1; |
3900 Scanner::Location super_loc; | 3901 Scanner::Location super_loc; |
3902 bool concise = false; | |
adamk
2015/10/14 15:14:09
This still need to be removed.
| |
3901 | 3903 |
3902 { | 3904 { |
3903 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3905 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3904 FunctionState function_state(&function_state_, &scope_, | 3906 FunctionState function_state(&function_state_, &scope_, |
3905 formal_parameters.scope, kArrowFunction, | 3907 formal_parameters.scope, kArrowFunction, |
3906 &function_factory); | 3908 &function_factory); |
3907 | 3909 |
3908 function_state.SkipMaterializedLiterals( | 3910 function_state.SkipMaterializedLiterals( |
3909 formal_parameters.materialized_literals_count); | 3911 formal_parameters.materialized_literals_count); |
3910 | 3912 |
(...skipping 18 matching lines...) Expand all Loading... | |
3929 } else { | 3931 } else { |
3930 body = this->ParseEagerFunctionBody( | 3932 body = this->ParseEagerFunctionBody( |
3931 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, | 3933 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, |
3932 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); | 3934 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); |
3933 materialized_literal_count = | 3935 materialized_literal_count = |
3934 function_state.materialized_literal_count(); | 3936 function_state.materialized_literal_count(); |
3935 expected_property_count = function_state.expected_property_count(); | 3937 expected_property_count = function_state.expected_property_count(); |
3936 } | 3938 } |
3937 } else { | 3939 } else { |
3938 // Single-expression body | 3940 // Single-expression body |
3941 concise = true; | |
3939 int pos = position(); | 3942 int pos = position(); |
3940 parenthesized_function_ = false; | 3943 parenthesized_function_ = false; |
3941 ExpressionClassifier classifier; | 3944 ExpressionClassifier classifier; |
3942 ExpressionT expression = | 3945 ExpressionT expression = |
3943 ParseAssignmentExpression(true, &classifier, CHECK_OK); | 3946 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); |
3944 ValidateExpression(&classifier, CHECK_OK); | 3947 ValidateExpression(&classifier, CHECK_OK); |
3945 body = this->NewStatementList(1, zone()); | 3948 body = this->NewStatementList(1, zone()); |
3946 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); | 3949 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); |
3947 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3950 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3948 materialized_literal_count = function_state.materialized_literal_count(); | 3951 materialized_literal_count = function_state.materialized_literal_count(); |
3949 expected_property_count = function_state.expected_property_count(); | 3952 expected_property_count = function_state.expected_property_count(); |
3950 } | 3953 } |
3951 super_loc = function_state.super_location(); | 3954 super_loc = function_state.super_location(); |
3952 | 3955 |
3953 formal_parameters.scope->set_end_position(scanner()->location().end_pos); | 3956 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4186 return; | 4189 return; |
4187 } | 4190 } |
4188 has_seen_constructor_ = true; | 4191 has_seen_constructor_ = true; |
4189 return; | 4192 return; |
4190 } | 4193 } |
4191 } | 4194 } |
4192 } // namespace internal | 4195 } // namespace internal |
4193 } // namespace v8 | 4196 } // namespace v8 |
4194 | 4197 |
4195 #endif // V8_PREPARSER_H | 4198 #endif // V8_PREPARSER_H |
OLD | NEW |