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_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 764 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
765 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 765 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
766 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 766 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
767 typename Traits::Type::ExpressionList ParseArguments( | 767 typename Traits::Type::ExpressionList ParseArguments( |
768 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 768 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
769 bool* ok); | 769 bool* ok); |
770 | 770 |
771 ExpressionT ParseAssignmentExpression(bool accept_IN, | 771 ExpressionT ParseAssignmentExpression(bool accept_IN, |
772 ExpressionClassifier* classifier, | 772 ExpressionClassifier* classifier, |
773 bool* ok); | 773 bool* ok); |
774 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); | 774 ExpressionT ParseYieldExpression(bool accept_IN, |
| 775 ExpressionClassifier* classifier, bool* ok); |
775 ExpressionT ParseConditionalExpression(bool accept_IN, | 776 ExpressionT ParseConditionalExpression(bool accept_IN, |
776 ExpressionClassifier* classifier, | 777 ExpressionClassifier* classifier, |
777 bool* ok); | 778 bool* ok); |
778 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, | 779 ExpressionT ParseBinaryExpression(int prec, bool accept_IN, |
779 ExpressionClassifier* classifier, bool* ok); | 780 ExpressionClassifier* classifier, bool* ok); |
780 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); | 781 ExpressionT ParseUnaryExpression(ExpressionClassifier* classifier, bool* ok); |
781 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, | 782 ExpressionT ParsePostfixExpression(ExpressionClassifier* classifier, |
782 bool* ok); | 783 bool* ok); |
783 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, | 784 ExpressionT ParseLeftHandSideExpression(ExpressionClassifier* classifier, |
784 bool* ok); | 785 bool* ok); |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 bool* ok) { | 1887 bool* ok) { |
1887 // AssignmentExpression :: | 1888 // AssignmentExpression :: |
1888 // ConditionalExpression | 1889 // ConditionalExpression |
1889 // ArrowFunction | 1890 // ArrowFunction |
1890 // YieldExpression | 1891 // YieldExpression |
1891 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 1892 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
1892 bool is_destructuring_assignment = false; | 1893 bool is_destructuring_assignment = false; |
1893 int lhs_beg_pos = peek_position(); | 1894 int lhs_beg_pos = peek_position(); |
1894 | 1895 |
1895 if (peek() == Token::YIELD && is_generator()) { | 1896 if (peek() == Token::YIELD && is_generator()) { |
1896 return this->ParseYieldExpression(classifier, ok); | 1897 return this->ParseYieldExpression(accept_IN, classifier, ok); |
1897 } | 1898 } |
1898 | 1899 |
1899 FuncNameInferrer::State fni_state(fni_); | 1900 FuncNameInferrer::State fni_state(fni_); |
1900 ParserBase<Traits>::Checkpoint checkpoint(this); | 1901 ParserBase<Traits>::Checkpoint checkpoint(this); |
1901 ExpressionClassifier arrow_formals_classifier(this, | 1902 ExpressionClassifier arrow_formals_classifier(this, |
1902 classifier->duplicate_finder()); | 1903 classifier->duplicate_finder()); |
1903 bool parenthesized_formals = peek() == Token::LPAREN; | 1904 bool parenthesized_formals = peek() == Token::LPAREN; |
1904 if (!parenthesized_formals) { | 1905 if (!parenthesized_formals) { |
1905 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 1906 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
1906 } | 1907 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 if (is_destructuring_assignment) { | 2034 if (is_destructuring_assignment) { |
2034 result = factory()->NewRewritableExpression(result); | 2035 result = factory()->NewRewritableExpression(result); |
2035 Traits::QueueDestructuringAssignmentForRewriting(result); | 2036 Traits::QueueDestructuringAssignmentForRewriting(result); |
2036 } | 2037 } |
2037 | 2038 |
2038 return result; | 2039 return result; |
2039 } | 2040 } |
2040 | 2041 |
2041 template <class Traits> | 2042 template <class Traits> |
2042 typename ParserBase<Traits>::ExpressionT | 2043 typename ParserBase<Traits>::ExpressionT |
2043 ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier, | 2044 ParserBase<Traits>::ParseYieldExpression(bool accept_IN, |
| 2045 ExpressionClassifier* classifier, |
2044 bool* ok) { | 2046 bool* ok) { |
2045 // YieldExpression :: | 2047 // YieldExpression :: |
2046 // 'yield' ([no line terminator] '*'? AssignmentExpression)? | 2048 // 'yield' ([no line terminator] '*'? AssignmentExpression)? |
2047 int pos = peek_position(); | 2049 int pos = peek_position(); |
2048 classifier->RecordPatternError(scanner()->peek_location(), | 2050 classifier->RecordPatternError(scanner()->peek_location(), |
2049 MessageTemplate::kInvalidDestructuringTarget); | 2051 MessageTemplate::kInvalidDestructuringTarget); |
2050 FormalParameterInitializerUnexpectedToken(classifier); | 2052 FormalParameterInitializerUnexpectedToken(classifier); |
2051 Expect(Token::YIELD, CHECK_OK); | 2053 Expect(Token::YIELD, CHECK_OK); |
2052 ExpressionT generator_object = | 2054 ExpressionT generator_object = |
2053 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 2055 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
2054 ExpressionT expression = Traits::EmptyExpression(); | 2056 ExpressionT expression = Traits::EmptyExpression(); |
2055 bool delegating = false; // yield* | 2057 bool delegating = false; // yield* |
2056 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { | 2058 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { |
2057 if (Check(Token::MUL)) delegating = true; | 2059 if (Check(Token::MUL)) delegating = true; |
2058 switch (peek()) { | 2060 switch (peek()) { |
2059 case Token::EOS: | 2061 case Token::EOS: |
2060 case Token::SEMICOLON: | 2062 case Token::SEMICOLON: |
2061 case Token::RBRACE: | 2063 case Token::RBRACE: |
2062 case Token::RBRACK: | 2064 case Token::RBRACK: |
2063 case Token::RPAREN: | 2065 case Token::RPAREN: |
2064 case Token::COLON: | 2066 case Token::COLON: |
2065 case Token::COMMA: | 2067 case Token::COMMA: |
2066 // The above set of tokens is the complete set of tokens that can appear | 2068 // The above set of tokens is the complete set of tokens that can appear |
2067 // after an AssignmentExpression, and none of them can start an | 2069 // after an AssignmentExpression, and none of them can start an |
2068 // AssignmentExpression. This allows us to avoid looking for an RHS for | 2070 // AssignmentExpression. This allows us to avoid looking for an RHS for |
2069 // a regular yield, given only one look-ahead token. | 2071 // a regular yield, given only one look-ahead token. |
2070 if (!delegating) break; | 2072 if (!delegating) break; |
2071 // Delegating yields require an RHS; fall through. | 2073 // Delegating yields require an RHS; fall through. |
2072 default: | 2074 default: |
2073 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); | 2075 expression = ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
2074 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2076 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2075 break; | 2077 break; |
2076 } | 2078 } |
2077 } | 2079 } |
2078 | 2080 |
2079 if (delegating) { | 2081 if (delegating) { |
2080 return Traits::RewriteYieldStar(generator_object, expression, pos); | 2082 return Traits::RewriteYieldStar(generator_object, expression, pos); |
2081 } | 2083 } |
2082 | 2084 |
2083 expression = Traits::BuildIteratorResult(expression, false); | 2085 expression = Traits::BuildIteratorResult(expression, false); |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3112 has_seen_constructor_ = true; | 3114 has_seen_constructor_ = true; |
3113 return; | 3115 return; |
3114 } | 3116 } |
3115 } | 3117 } |
3116 | 3118 |
3117 | 3119 |
3118 } // namespace internal | 3120 } // namespace internal |
3119 } // namespace v8 | 3121 } // namespace v8 |
3120 | 3122 |
3121 #endif // V8_PARSING_PARSER_BASE_H | 3123 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |