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 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 token = peek(); | 1947 token = peek(); |
1948 pos = peek_position(); | 1948 pos = peek_position(); |
1949 } | 1949 } |
1950 | 1950 |
1951 if (allow_harmony_async_await() && !*is_generator && token == Token::ASYNC && | 1951 if (allow_harmony_async_await() && !*is_generator && token == Token::ASYNC && |
1952 !scanner()->HasAnyLineTerminatorAfterNext()) { | 1952 !scanner()->HasAnyLineTerminatorAfterNext()) { |
1953 Consume(Token::ASYNC); | 1953 Consume(Token::ASYNC); |
1954 token = peek(); | 1954 token = peek(); |
1955 if (SetPropertyKindFromToken(token, kind)) { | 1955 if (SetPropertyKindFromToken(token, kind)) { |
1956 *name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'async' | 1956 *name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'async' |
1957 if (fni_ != nullptr) { | 1957 impl()->PushLiteralName(*name); |
1958 impl()->PushLiteralName(fni_, *name); | |
1959 } | |
1960 return factory()->NewStringLiteral(*name, pos); | 1958 return factory()->NewStringLiteral(*name, pos); |
1961 } | 1959 } |
1962 *kind = PropertyKind::kMethodProperty; | 1960 *kind = PropertyKind::kMethodProperty; |
1963 *is_async = true; | 1961 *is_async = true; |
1964 pos = peek_position(); | 1962 pos = peek_position(); |
1965 } | 1963 } |
1966 | 1964 |
1967 if (token == Token::IDENTIFIER && !*is_generator && !*is_async) { | 1965 if (token == Token::IDENTIFIER && !*is_generator && !*is_async) { |
1968 // This is checking for 'get' and 'set' in particular. Any other identifier | 1966 // This is checking for 'get' and 'set' in particular. Any other identifier |
1969 // must be the property name, and so SetPropertyKindFromToken will return | 1967 // must be the property name, and so SetPropertyKindFromToken will return |
1970 // true (unless there's a syntax error). | 1968 // true (unless there's a syntax error). |
1971 Consume(Token::IDENTIFIER); | 1969 Consume(Token::IDENTIFIER); |
1972 token = peek(); | 1970 token = peek(); |
1973 if (SetPropertyKindFromToken(token, kind)) { | 1971 if (SetPropertyKindFromToken(token, kind)) { |
1974 *name = impl()->GetSymbol(); | 1972 *name = impl()->GetSymbol(); |
1975 if (fni_ != nullptr) { | 1973 impl()->PushLiteralName(*name); |
1976 impl()->PushLiteralName(fni_, *name); | |
1977 } | |
1978 return factory()->NewStringLiteral(*name, pos); | 1974 return factory()->NewStringLiteral(*name, pos); |
1979 } | 1975 } |
1980 scanner()->IsGetOrSet(is_get, is_set); | 1976 scanner()->IsGetOrSet(is_get, is_set); |
1981 if (!*is_get && !*is_set) { // TODO(bakkot) have IsGetOrSet return a bool | 1977 if (!*is_get && !*is_set) { // TODO(bakkot) have IsGetOrSet return a bool |
1982 Token::Value next = Next(); | 1978 Token::Value next = Next(); |
1983 ReportUnexpectedToken(next); | 1979 ReportUnexpectedToken(next); |
1984 *ok = false; | 1980 *ok = false; |
1985 return impl()->EmptyExpression(); | 1981 return impl()->EmptyExpression(); |
1986 } | 1982 } |
1987 *kind = PropertyKind::kAccessorProperty; | 1983 *kind = PropertyKind::kAccessorProperty; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2041 *ok = false; | 2037 *ok = false; |
2042 return impl()->EmptyExpression(); | 2038 return impl()->EmptyExpression(); |
2043 } | 2039 } |
2044 } | 2040 } |
2045 DCHECK(*kind != PropertyKind::kNotSet); | 2041 DCHECK(*kind != PropertyKind::kNotSet); |
2046 | 2042 |
2047 if (*is_computed_name) { | 2043 if (*is_computed_name) { |
2048 return expression; | 2044 return expression; |
2049 } | 2045 } |
2050 | 2046 |
2051 if (fni_ != nullptr) { | 2047 impl()->PushLiteralName(*name); |
2052 impl()->PushLiteralName(fni_, *name); | |
2053 } | |
2054 | 2048 |
2055 uint32_t index; | 2049 uint32_t index; |
2056 return impl()->IsArrayIndex(*name, &index) | 2050 return impl()->IsArrayIndex(*name, &index) |
2057 ? factory()->NewNumberLiteral(index, pos) | 2051 ? factory()->NewNumberLiteral(index, pos) |
2058 : factory()->NewStringLiteral(*name, pos); | 2052 : factory()->NewStringLiteral(*name, pos); |
2059 } | 2053 } |
2060 | 2054 |
2061 template <typename Impl> | 2055 template <typename Impl> |
2062 typename ParserBase<Impl>::ObjectLiteralPropertyT | 2056 typename ParserBase<Impl>::ObjectLiteralPropertyT |
2063 ParserBase<Impl>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker, | 2057 ParserBase<Impl>::ParsePropertyDefinition(ObjectLiteralCheckerBase* checker, |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3037 case Token::PERIOD: { | 3031 case Token::PERIOD: { |
3038 CheckNoTailCallExpressions(CHECK_OK); | 3032 CheckNoTailCallExpressions(CHECK_OK); |
3039 impl()->RewriteNonPattern(CHECK_OK); | 3033 impl()->RewriteNonPattern(CHECK_OK); |
3040 BindingPatternUnexpectedToken(); | 3034 BindingPatternUnexpectedToken(); |
3041 ArrowFormalParametersUnexpectedToken(); | 3035 ArrowFormalParametersUnexpectedToken(); |
3042 Consume(Token::PERIOD); | 3036 Consume(Token::PERIOD); |
3043 int pos = position(); | 3037 int pos = position(); |
3044 IdentifierT name = ParseIdentifierName(CHECK_OK); | 3038 IdentifierT name = ParseIdentifierName(CHECK_OK); |
3045 result = factory()->NewProperty( | 3039 result = factory()->NewProperty( |
3046 result, factory()->NewStringLiteral(name, pos), pos); | 3040 result, factory()->NewStringLiteral(name, pos), pos); |
3047 if (fni_ != NULL) impl()->PushLiteralName(fni_, name); | 3041 impl()->PushLiteralName(name); |
3048 break; | 3042 break; |
3049 } | 3043 } |
3050 | 3044 |
3051 case Token::TEMPLATE_SPAN: | 3045 case Token::TEMPLATE_SPAN: |
3052 case Token::TEMPLATE_TAIL: { | 3046 case Token::TEMPLATE_TAIL: { |
3053 CheckNoTailCallExpressions(CHECK_OK); | 3047 CheckNoTailCallExpressions(CHECK_OK); |
3054 impl()->RewriteNonPattern(CHECK_OK); | 3048 impl()->RewriteNonPattern(CHECK_OK); |
3055 BindingPatternUnexpectedToken(); | 3049 BindingPatternUnexpectedToken(); |
3056 ArrowFormalParametersUnexpectedToken(); | 3050 ArrowFormalParametersUnexpectedToken(); |
3057 result = ParseTemplateLiteral(result, position(), CHECK_OK); | 3051 result = ParseTemplateLiteral(result, position(), CHECK_OK); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3263 *is_async = false; | 3257 *is_async = false; |
3264 impl()->RewriteNonPattern(CHECK_OK); | 3258 impl()->RewriteNonPattern(CHECK_OK); |
3265 BindingPatternUnexpectedToken(); | 3259 BindingPatternUnexpectedToken(); |
3266 ArrowFormalParametersUnexpectedToken(); | 3260 ArrowFormalParametersUnexpectedToken(); |
3267 | 3261 |
3268 Consume(Token::LBRACK); | 3262 Consume(Token::LBRACK); |
3269 int pos = position(); | 3263 int pos = position(); |
3270 ExpressionT index = ParseExpressionCoverGrammar(true, CHECK_OK); | 3264 ExpressionT index = ParseExpressionCoverGrammar(true, CHECK_OK); |
3271 impl()->RewriteNonPattern(CHECK_OK); | 3265 impl()->RewriteNonPattern(CHECK_OK); |
3272 expression = factory()->NewProperty(expression, index, pos); | 3266 expression = factory()->NewProperty(expression, index, pos); |
3273 if (fni_ != NULL) { | 3267 impl()->PushPropertyName(index); |
3274 impl()->PushPropertyName(fni_, index); | |
3275 } | |
3276 Expect(Token::RBRACK, CHECK_OK); | 3268 Expect(Token::RBRACK, CHECK_OK); |
3277 break; | 3269 break; |
3278 } | 3270 } |
3279 case Token::PERIOD: { | 3271 case Token::PERIOD: { |
3280 *is_async = false; | 3272 *is_async = false; |
3281 impl()->RewriteNonPattern(CHECK_OK); | 3273 impl()->RewriteNonPattern(CHECK_OK); |
3282 BindingPatternUnexpectedToken(); | 3274 BindingPatternUnexpectedToken(); |
3283 ArrowFormalParametersUnexpectedToken(); | 3275 ArrowFormalParametersUnexpectedToken(); |
3284 | 3276 |
3285 Consume(Token::PERIOD); | 3277 Consume(Token::PERIOD); |
3286 int pos = position(); | 3278 int pos = position(); |
3287 IdentifierT name = ParseIdentifierName(CHECK_OK); | 3279 IdentifierT name = ParseIdentifierName(CHECK_OK); |
3288 expression = factory()->NewProperty( | 3280 expression = factory()->NewProperty( |
3289 expression, factory()->NewStringLiteral(name, pos), pos); | 3281 expression, factory()->NewStringLiteral(name, pos), pos); |
3290 if (fni_ != NULL) { | 3282 impl()->PushLiteralName(name); |
3291 impl()->PushLiteralName(fni_, name); | |
3292 } | |
3293 break; | 3283 break; |
3294 } | 3284 } |
3295 case Token::TEMPLATE_SPAN: | 3285 case Token::TEMPLATE_SPAN: |
3296 case Token::TEMPLATE_TAIL: { | 3286 case Token::TEMPLATE_TAIL: { |
3297 *is_async = false; | 3287 *is_async = false; |
3298 impl()->RewriteNonPattern(CHECK_OK); | 3288 impl()->RewriteNonPattern(CHECK_OK); |
3299 BindingPatternUnexpectedToken(); | 3289 BindingPatternUnexpectedToken(); |
3300 ArrowFormalParametersUnexpectedToken(); | 3290 ArrowFormalParametersUnexpectedToken(); |
3301 int pos; | 3291 int pos; |
3302 if (scanner()->current_token() == Token::IDENTIFIER) { | 3292 if (scanner()->current_token() == Token::IDENTIFIER) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3475 | 3465 |
3476 ValidateBindingPattern(CHECK_OK_CUSTOM(NullBlock)); | 3466 ValidateBindingPattern(CHECK_OK_CUSTOM(NullBlock)); |
3477 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) { | 3467 if (IsLexicalVariableMode(parsing_result->descriptor.mode)) { |
3478 ValidateLetPattern(CHECK_OK_CUSTOM(NullBlock)); | 3468 ValidateLetPattern(CHECK_OK_CUSTOM(NullBlock)); |
3479 } | 3469 } |
3480 } | 3470 } |
3481 | 3471 |
3482 Scanner::Location variable_loc = scanner()->location(); | 3472 Scanner::Location variable_loc = scanner()->location(); |
3483 bool single_name = impl()->IsIdentifier(pattern); | 3473 bool single_name = impl()->IsIdentifier(pattern); |
3484 | 3474 |
3485 if (single_name && fni_ != nullptr) { | 3475 if (single_name) { |
3486 impl()->PushVariableName(fni_, impl()->AsIdentifier(pattern)); | 3476 impl()->PushVariableName(impl()->AsIdentifier(pattern)); |
3487 } | 3477 } |
3488 | 3478 |
3489 ExpressionT value = impl()->EmptyExpression(); | 3479 ExpressionT value = impl()->EmptyExpression(); |
3490 int initializer_position = kNoSourcePosition; | 3480 int initializer_position = kNoSourcePosition; |
3491 if (Check(Token::ASSIGN)) { | 3481 if (Check(Token::ASSIGN)) { |
3492 ExpressionClassifier classifier(this); | 3482 ExpressionClassifier classifier(this); |
3493 value = ParseAssignmentExpression(var_context != kForStatement, | 3483 value = ParseAssignmentExpression(var_context != kForStatement, |
3494 CHECK_OK_CUSTOM(NullBlock)); | 3484 CHECK_OK_CUSTOM(NullBlock)); |
3495 impl()->RewriteNonPattern(CHECK_OK_CUSTOM(NullBlock)); | 3485 impl()->RewriteNonPattern(CHECK_OK_CUSTOM(NullBlock)); |
3496 variable_loc.end_pos = scanner()->location().end_pos; | 3486 variable_loc.end_pos = scanner()->location().end_pos; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3756 FunctionLiteral::kNoDuplicateParameters, | 3746 FunctionLiteral::kNoDuplicateParameters, |
3757 FunctionLiteral::kAnonymousExpression, eager_compile_hint, arrow_kind, | 3747 FunctionLiteral::kAnonymousExpression, eager_compile_hint, arrow_kind, |
3758 formal_parameters.scope->start_position()); | 3748 formal_parameters.scope->start_position()); |
3759 | 3749 |
3760 function_literal->set_function_token_position( | 3750 function_literal->set_function_token_position( |
3761 formal_parameters.scope->start_position()); | 3751 formal_parameters.scope->start_position()); |
3762 if (should_be_used_once_hint) { | 3752 if (should_be_used_once_hint) { |
3763 function_literal->set_should_be_used_once_hint(); | 3753 function_literal->set_should_be_used_once_hint(); |
3764 } | 3754 } |
3765 | 3755 |
3766 if (fni_ != NULL) impl()->InferFunctionName(fni_, function_literal); | 3756 impl()->InferFunctionName(function_literal); |
3767 | 3757 |
3768 return function_literal; | 3758 return function_literal; |
3769 } | 3759 } |
3770 | 3760 |
3771 template <typename Impl> | 3761 template <typename Impl> |
3772 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( | 3762 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( |
3773 ExpressionT tag, int start, bool* ok) { | 3763 ExpressionT tag, int start, bool* ok) { |
3774 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal | 3764 // A TemplateLiteral is made up of 0 or more TEMPLATE_SPAN tokens (literal |
3775 // text followed by a substitution expression), finalized by a single | 3765 // text followed by a substitution expression), finalized by a single |
3776 // TEMPLATE_TAIL. | 3766 // TEMPLATE_TAIL. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3971 has_seen_constructor_ = true; | 3961 has_seen_constructor_ = true; |
3972 return; | 3962 return; |
3973 } | 3963 } |
3974 } | 3964 } |
3975 | 3965 |
3976 | 3966 |
3977 } // namespace internal | 3967 } // namespace internal |
3978 } // namespace v8 | 3968 } // namespace v8 |
3979 | 3969 |
3980 #endif // V8_PARSING_PARSER_BASE_H | 3970 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |