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/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 return result; | 1686 return result; |
1687 } | 1687 } |
1688 | 1688 |
1689 template <class Traits> | 1689 template <class Traits> |
1690 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1690 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1691 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 1691 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
1692 // Expression :: | 1692 // Expression :: |
1693 // AssignmentExpression | 1693 // AssignmentExpression |
1694 // Expression ',' AssignmentExpression | 1694 // Expression ',' AssignmentExpression |
1695 | 1695 |
1696 ExpressionT result = this->EmptyExpression(); | 1696 ExpressionT result; |
1697 { | 1697 { |
1698 ExpressionClassifier binding_classifier(this); | 1698 ExpressionClassifier binding_classifier(this); |
1699 result = this->ParseAssignmentExpression(accept_IN, &binding_classifier, | 1699 result = this->ParseAssignmentExpression(accept_IN, &binding_classifier, |
1700 CHECK_OK); | 1700 CHECK_OK); |
1701 classifier->Accumulate(&binding_classifier, | 1701 classifier->Accumulate(&binding_classifier, |
1702 ExpressionClassifier::AllProductions); | 1702 ExpressionClassifier::AllProductions); |
1703 } | 1703 } |
1704 bool is_simple_parameter_list = this->IsIdentifier(result); | 1704 bool is_simple_parameter_list = this->IsIdentifier(result); |
1705 bool seen_rest = false; | 1705 bool seen_rest = false; |
1706 while (peek() == Token::COMMA) { | 1706 while (peek() == Token::COMMA) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 ExpressionClassifier* classifier, bool* ok) { | 1757 ExpressionClassifier* classifier, bool* ok) { |
1758 // ArrayLiteral :: | 1758 // ArrayLiteral :: |
1759 // '[' Expression? (',' Expression?)* ']' | 1759 // '[' Expression? (',' Expression?)* ']' |
1760 | 1760 |
1761 int pos = peek_position(); | 1761 int pos = peek_position(); |
1762 typename Traits::Type::ExpressionList values = | 1762 typename Traits::Type::ExpressionList values = |
1763 this->NewExpressionList(4, zone_); | 1763 this->NewExpressionList(4, zone_); |
1764 int first_spread_index = -1; | 1764 int first_spread_index = -1; |
1765 Expect(Token::LBRACK, CHECK_OK); | 1765 Expect(Token::LBRACK, CHECK_OK); |
1766 while (peek() != Token::RBRACK) { | 1766 while (peek() != Token::RBRACK) { |
1767 ExpressionT elem = this->EmptyExpression(); | 1767 ExpressionT elem; |
1768 if (peek() == Token::COMMA) { | 1768 if (peek() == Token::COMMA) { |
1769 elem = this->GetLiteralTheHole(peek_position(), factory()); | 1769 elem = this->GetLiteralTheHole(peek_position(), factory()); |
1770 } else if (peek() == Token::ELLIPSIS) { | 1770 } else if (peek() == Token::ELLIPSIS) { |
1771 int start_pos = peek_position(); | 1771 int start_pos = peek_position(); |
1772 Consume(Token::ELLIPSIS); | 1772 Consume(Token::ELLIPSIS); |
1773 int expr_pos = peek_position(); | 1773 int expr_pos = peek_position(); |
1774 ExpressionT argument = | 1774 ExpressionT argument = |
1775 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 1775 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
1776 CheckNoTailCallExpressions(classifier, CHECK_OK); | 1776 CheckNoTailCallExpressions(classifier, CHECK_OK); |
1777 elem = factory()->NewSpread(argument, start_pos, expr_pos); | 1777 elem = factory()->NewSpread(argument, start_pos, expr_pos); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 } | 1889 } |
1890 | 1890 |
1891 template <class Traits> | 1891 template <class Traits> |
1892 typename ParserBase<Traits>::ObjectLiteralPropertyT | 1892 typename ParserBase<Traits>::ObjectLiteralPropertyT |
1893 ParserBase<Traits>::ParsePropertyDefinition( | 1893 ParserBase<Traits>::ParsePropertyDefinition( |
1894 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 1894 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
1895 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, | 1895 MethodKind method_kind, bool* is_computed_name, bool* has_seen_constructor, |
1896 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { | 1896 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { |
1897 DCHECK(!in_class || IsStaticMethod(method_kind) || | 1897 DCHECK(!in_class || IsStaticMethod(method_kind) || |
1898 has_seen_constructor != nullptr); | 1898 has_seen_constructor != nullptr); |
1899 ExpressionT value = this->EmptyExpression(); | |
1900 bool is_get = false; | 1899 bool is_get = false; |
1901 bool is_set = false; | 1900 bool is_set = false; |
1902 bool is_await = false; | 1901 bool is_await = false; |
1903 bool is_generator = Check(Token::MUL); | 1902 bool is_generator = Check(Token::MUL); |
1904 bool is_async = false; | 1903 bool is_async = false; |
1905 const bool is_static = IsStaticMethod(method_kind); | 1904 const bool is_static = IsStaticMethod(method_kind); |
1906 | 1905 |
1907 Token::Value name_token = peek(); | 1906 Token::Value name_token = peek(); |
1908 | 1907 |
1909 if (is_generator) { | 1908 if (is_generator) { |
(...skipping 19 matching lines...) Expand all Loading... |
1929 | 1928 |
1930 if (peek() == Token::COLON) { | 1929 if (peek() == Token::COLON) { |
1931 // PropertyDefinition | 1930 // PropertyDefinition |
1932 // PropertyName ':' AssignmentExpression | 1931 // PropertyName ':' AssignmentExpression |
1933 if (!*is_computed_name) { | 1932 if (!*is_computed_name) { |
1934 checker->CheckProperty(name_token, kValueProperty, MethodKind::Normal, | 1933 checker->CheckProperty(name_token, kValueProperty, MethodKind::Normal, |
1935 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1934 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1936 } | 1935 } |
1937 Consume(Token::COLON); | 1936 Consume(Token::COLON); |
1938 int beg_pos = peek_position(); | 1937 int beg_pos = peek_position(); |
1939 value = this->ParseAssignmentExpression( | 1938 ExpressionT value = this->ParseAssignmentExpression( |
1940 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1939 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1941 CheckDestructuringElement(value, classifier, beg_pos, | 1940 CheckDestructuringElement(value, classifier, beg_pos, |
1942 scanner()->location().end_pos); | 1941 scanner()->location().end_pos); |
1943 | 1942 |
1944 return factory()->NewObjectLiteralProperty(name_expression, value, | 1943 return factory()->NewObjectLiteralProperty(name_expression, value, |
1945 is_static, *is_computed_name); | 1944 is_static, *is_computed_name); |
1946 } | 1945 } |
1947 | 1946 |
1948 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(), | 1947 if (Token::IsIdentifier(name_token, language_mode(), this->is_generator(), |
1949 parsing_module_) && | 1948 parsing_module_) && |
(...skipping 21 matching lines...) Expand all Loading... |
1971 } else { | 1970 } else { |
1972 classifier->RecordAsyncArrowFormalParametersError( | 1971 classifier->RecordAsyncArrowFormalParametersError( |
1973 Scanner::Location(next_beg_pos, next_end_pos), | 1972 Scanner::Location(next_beg_pos, next_end_pos), |
1974 MessageTemplate::kAwaitBindingIdentifier); | 1973 MessageTemplate::kAwaitBindingIdentifier); |
1975 } | 1974 } |
1976 } | 1975 } |
1977 ExpressionT lhs = this->ExpressionFromIdentifier( | 1976 ExpressionT lhs = this->ExpressionFromIdentifier( |
1978 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1977 *name, next_beg_pos, next_end_pos, scope_, factory()); |
1979 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1978 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
1980 | 1979 |
| 1980 ExpressionT value; |
1981 if (peek() == Token::ASSIGN) { | 1981 if (peek() == Token::ASSIGN) { |
1982 Consume(Token::ASSIGN); | 1982 Consume(Token::ASSIGN); |
1983 ExpressionClassifier rhs_classifier(this); | 1983 ExpressionClassifier rhs_classifier(this); |
1984 ExpressionT rhs = this->ParseAssignmentExpression( | 1984 ExpressionT rhs = this->ParseAssignmentExpression( |
1985 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1985 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1986 Traits::RewriteNonPattern(&rhs_classifier, | 1986 Traits::RewriteNonPattern(&rhs_classifier, |
1987 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1987 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1988 classifier->Accumulate(&rhs_classifier, | 1988 classifier->Accumulate(&rhs_classifier, |
1989 ExpressionClassifier::ExpressionProductions); | 1989 ExpressionClassifier::ExpressionProductions); |
1990 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 1990 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 : is_async ? FunctionKind::kAsyncConciseMethod | 2033 : is_async ? FunctionKind::kAsyncConciseMethod |
2034 : FunctionKind::kConciseMethod; | 2034 : FunctionKind::kConciseMethod; |
2035 | 2035 |
2036 if (in_class && !IsStaticMethod(method_kind) && | 2036 if (in_class && !IsStaticMethod(method_kind) && |
2037 this->IsConstructor(*name)) { | 2037 this->IsConstructor(*name)) { |
2038 *has_seen_constructor = true; | 2038 *has_seen_constructor = true; |
2039 kind = has_extends ? FunctionKind::kSubclassConstructor | 2039 kind = has_extends ? FunctionKind::kSubclassConstructor |
2040 : FunctionKind::kBaseConstructor; | 2040 : FunctionKind::kBaseConstructor; |
2041 } | 2041 } |
2042 | 2042 |
2043 value = this->ParseFunctionLiteral( | 2043 ExpressionT value = this->ParseFunctionLiteral( |
2044 *name, scanner()->location(), kSkipFunctionNameCheck, kind, | 2044 *name, scanner()->location(), kSkipFunctionNameCheck, kind, |
2045 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, language_mode(), | 2045 kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, language_mode(), |
2046 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2046 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2047 | 2047 |
2048 return factory()->NewObjectLiteralProperty(name_expression, value, | 2048 return factory()->NewObjectLiteralProperty(name_expression, value, |
2049 ObjectLiteralProperty::COMPUTED, | 2049 ObjectLiteralProperty::COMPUTED, |
2050 is_static, *is_computed_name); | 2050 is_static, *is_computed_name); |
2051 } | 2051 } |
2052 | 2052 |
2053 if (in_class && name_token == Token::STATIC && IsNormalMethod(method_kind)) { | 2053 if (in_class && name_token == Token::STATIC && IsNormalMethod(method_kind)) { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2443 // YieldExpression :: | 2443 // YieldExpression :: |
2444 // 'yield' ([no line terminator] '*'? AssignmentExpression)? | 2444 // 'yield' ([no line terminator] '*'? AssignmentExpression)? |
2445 int pos = peek_position(); | 2445 int pos = peek_position(); |
2446 classifier->RecordPatternError(scanner()->peek_location(), | 2446 classifier->RecordPatternError(scanner()->peek_location(), |
2447 MessageTemplate::kInvalidDestructuringTarget); | 2447 MessageTemplate::kInvalidDestructuringTarget); |
2448 classifier->RecordFormalParameterInitializerError( | 2448 classifier->RecordFormalParameterInitializerError( |
2449 scanner()->peek_location(), MessageTemplate::kYieldInParameter); | 2449 scanner()->peek_location(), MessageTemplate::kYieldInParameter); |
2450 Expect(Token::YIELD, CHECK_OK); | 2450 Expect(Token::YIELD, CHECK_OK); |
2451 ExpressionT generator_object = | 2451 ExpressionT generator_object = |
2452 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 2452 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
| 2453 // The following initialization is necessary. |
2453 ExpressionT expression = Traits::EmptyExpression(); | 2454 ExpressionT expression = Traits::EmptyExpression(); |
2454 bool delegating = false; // yield* | 2455 bool delegating = false; // yield* |
2455 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { | 2456 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { |
2456 if (Check(Token::MUL)) delegating = true; | 2457 if (Check(Token::MUL)) delegating = true; |
2457 switch (peek()) { | 2458 switch (peek()) { |
2458 case Token::EOS: | 2459 case Token::EOS: |
2459 case Token::SEMICOLON: | 2460 case Token::SEMICOLON: |
2460 case Token::RBRACE: | 2461 case Token::RBRACE: |
2461 case Token::RBRACK: | 2462 case Token::RBRACK: |
2462 case Token::RPAREN: | 2463 case Token::RPAREN: |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2945 // new new foo()() means (new (new foo())()) | 2946 // new new foo()() means (new (new foo())()) |
2946 // new new foo means new (new foo) | 2947 // new new foo means new (new foo) |
2947 // new new foo() means new (new foo()) | 2948 // new new foo() means new (new foo()) |
2948 // new new foo().bar().baz means (new (new foo()).bar()).baz | 2949 // new new foo().bar().baz means (new (new foo()).bar()).baz |
2949 | 2950 |
2950 if (peek() == Token::NEW) { | 2951 if (peek() == Token::NEW) { |
2951 BindingPatternUnexpectedToken(classifier); | 2952 BindingPatternUnexpectedToken(classifier); |
2952 ArrowFormalParametersUnexpectedToken(classifier); | 2953 ArrowFormalParametersUnexpectedToken(classifier); |
2953 Consume(Token::NEW); | 2954 Consume(Token::NEW); |
2954 int new_pos = position(); | 2955 int new_pos = position(); |
2955 ExpressionT result = this->EmptyExpression(); | 2956 ExpressionT result; |
2956 if (peek() == Token::SUPER) { | 2957 if (peek() == Token::SUPER) { |
2957 const bool is_new = true; | 2958 const bool is_new = true; |
2958 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2959 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
2959 } else if (peek() == Token::PERIOD) { | 2960 } else if (peek() == Token::PERIOD) { |
2960 return ParseNewTargetExpression(CHECK_OK); | 2961 return ParseNewTargetExpression(CHECK_OK); |
2961 } else { | 2962 } else { |
2962 result = this->ParseMemberWithNewPrefixesExpression(classifier, is_async, | 2963 result = this->ParseMemberWithNewPrefixesExpression(classifier, is_async, |
2963 CHECK_OK); | 2964 CHECK_OK); |
2964 } | 2965 } |
2965 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2966 Traits::RewriteNonPattern(classifier, CHECK_OK); |
(...skipping 28 matching lines...) Expand all Loading... |
2994 bool* is_async, bool* ok) { | 2995 bool* is_async, bool* ok) { |
2995 // MemberExpression :: | 2996 // MemberExpression :: |
2996 // (PrimaryExpression | FunctionLiteral | ClassLiteral) | 2997 // (PrimaryExpression | FunctionLiteral | ClassLiteral) |
2997 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* | 2998 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* |
2998 | 2999 |
2999 // The '[' Expression ']' and '.' Identifier parts are parsed by | 3000 // The '[' Expression ']' and '.' Identifier parts are parsed by |
3000 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 3001 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
3001 // caller. | 3002 // caller. |
3002 | 3003 |
3003 // Parse the initial primary or function expression. | 3004 // Parse the initial primary or function expression. |
3004 ExpressionT result = this->EmptyExpression(); | 3005 ExpressionT result; |
3005 if (peek() == Token::FUNCTION) { | 3006 if (peek() == Token::FUNCTION) { |
3006 BindingPatternUnexpectedToken(classifier); | 3007 BindingPatternUnexpectedToken(classifier); |
3007 ArrowFormalParametersUnexpectedToken(classifier); | 3008 ArrowFormalParametersUnexpectedToken(classifier); |
3008 | 3009 |
3009 Consume(Token::FUNCTION); | 3010 Consume(Token::FUNCTION); |
3010 int function_token_position = position(); | 3011 int function_token_position = position(); |
3011 | 3012 |
3012 if (allow_harmony_function_sent() && peek() == Token::PERIOD) { | 3013 if (allow_harmony_function_sent() && peek() == Token::PERIOD) { |
3013 // function.sent | 3014 // function.sent |
3014 int pos = position(); | 3015 int pos = position(); |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3668 has_seen_constructor_ = true; | 3669 has_seen_constructor_ = true; |
3669 return; | 3670 return; |
3670 } | 3671 } |
3671 } | 3672 } |
3672 | 3673 |
3673 | 3674 |
3674 } // namespace internal | 3675 } // namespace internal |
3675 } // namespace v8 | 3676 } // namespace v8 |
3676 | 3677 |
3677 #endif // V8_PARSING_PARSER_BASE_H | 3678 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |