Chromium Code Reviews| 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/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 allow_lazy_(false), | 191 allow_lazy_(false), |
| 192 allow_natives_(false), | 192 allow_natives_(false), |
| 193 allow_tailcalls_(false), | 193 allow_tailcalls_(false), |
| 194 allow_harmony_restrictive_declarations_(false), | 194 allow_harmony_restrictive_declarations_(false), |
| 195 allow_harmony_do_expressions_(false), | 195 allow_harmony_do_expressions_(false), |
| 196 allow_harmony_for_in_(false), | 196 allow_harmony_for_in_(false), |
| 197 allow_harmony_function_sent_(false), | 197 allow_harmony_function_sent_(false), |
| 198 allow_harmony_async_await_(false), | 198 allow_harmony_async_await_(false), |
| 199 allow_harmony_restrictive_generators_(false), | 199 allow_harmony_restrictive_generators_(false), |
| 200 allow_harmony_trailing_commas_(false), | 200 allow_harmony_trailing_commas_(false), |
| 201 allow_harmony_class_fields_(false) {} | 201 allow_harmony_class_fields_(false), |
| 202 allow_harmony_private_class_fields_(false) {} | |
| 202 | 203 |
| 203 #define ALLOW_ACCESSORS(name) \ | 204 #define ALLOW_ACCESSORS(name) \ |
| 204 bool allow_##name() const { return allow_##name##_; } \ | 205 bool allow_##name() const { return allow_##name##_; } \ |
| 205 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 206 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
| 206 | 207 |
| 207 ALLOW_ACCESSORS(lazy); | 208 ALLOW_ACCESSORS(lazy); |
| 208 ALLOW_ACCESSORS(natives); | 209 ALLOW_ACCESSORS(natives); |
| 209 ALLOW_ACCESSORS(tailcalls); | 210 ALLOW_ACCESSORS(tailcalls); |
| 210 ALLOW_ACCESSORS(harmony_restrictive_declarations); | 211 ALLOW_ACCESSORS(harmony_restrictive_declarations); |
| 211 ALLOW_ACCESSORS(harmony_do_expressions); | 212 ALLOW_ACCESSORS(harmony_do_expressions); |
| 212 ALLOW_ACCESSORS(harmony_for_in); | 213 ALLOW_ACCESSORS(harmony_for_in); |
| 213 ALLOW_ACCESSORS(harmony_function_sent); | 214 ALLOW_ACCESSORS(harmony_function_sent); |
| 214 ALLOW_ACCESSORS(harmony_async_await); | 215 ALLOW_ACCESSORS(harmony_async_await); |
| 215 ALLOW_ACCESSORS(harmony_restrictive_generators); | 216 ALLOW_ACCESSORS(harmony_restrictive_generators); |
| 216 ALLOW_ACCESSORS(harmony_trailing_commas); | 217 ALLOW_ACCESSORS(harmony_trailing_commas); |
| 217 ALLOW_ACCESSORS(harmony_class_fields); | 218 ALLOW_ACCESSORS(harmony_class_fields); |
| 219 ALLOW_ACCESSORS(harmony_private_class_fields); | |
| 218 | 220 |
| 219 #undef ALLOW_ACCESSORS | 221 #undef ALLOW_ACCESSORS |
| 220 | 222 |
| 221 uintptr_t stack_limit() const { return stack_limit_; } | 223 uintptr_t stack_limit() const { return stack_limit_; } |
| 222 | 224 |
| 223 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 225 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
| 224 | 226 |
| 225 Zone* zone() const { return zone_; } | 227 Zone* zone() const { return zone_; } |
| 226 | 228 |
| 227 protected: | 229 protected: |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1098 kNotSet | 1100 kNotSet |
| 1099 }; | 1101 }; |
| 1100 | 1102 |
| 1101 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); | 1103 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); |
| 1102 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, | 1104 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, |
| 1103 bool* is_generator, bool* is_get, bool* is_set, | 1105 bool* is_generator, bool* is_get, bool* is_set, |
| 1104 bool* is_async, bool* is_computed_name, | 1106 bool* is_async, bool* is_computed_name, |
| 1105 bool* ok); | 1107 bool* ok); |
| 1106 ExpressionT ParseObjectLiteral(bool* ok); | 1108 ExpressionT ParseObjectLiteral(bool* ok); |
| 1107 ClassLiteralPropertyT ParseClassPropertyDefinition( | 1109 ClassLiteralPropertyT ParseClassPropertyDefinition( |
| 1108 ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, | 1110 ClassLiteralChecker* checker, bool has_extends, IdentifierT* private_name, |
| 1109 bool* has_seen_constructor, bool* ok); | 1111 bool* is_computed_name, bool* has_seen_constructor, bool* ok); |
| 1110 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, | 1112 FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, |
| 1111 bool* ok); | 1113 bool* ok); |
| 1112 ObjectLiteralPropertyT ParseObjectPropertyDefinition( | 1114 ObjectLiteralPropertyT ParseObjectPropertyDefinition( |
| 1113 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); | 1115 ObjectLiteralChecker* checker, bool* is_computed_name, bool* ok); |
| 1114 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1116 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
| 1115 bool maybe_arrow, bool* ok); | 1117 bool maybe_arrow, bool* ok); |
| 1116 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, | 1118 ExpressionListT ParseArguments(Scanner::Location* first_spread_pos, |
| 1117 bool* ok) { | 1119 bool* ok) { |
| 1118 return ParseArguments(first_spread_pos, false, ok); | 1120 return ParseArguments(first_spread_pos, false, ok); |
| 1119 } | 1121 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1334 bool allow_natives_; | 1336 bool allow_natives_; |
| 1335 bool allow_tailcalls_; | 1337 bool allow_tailcalls_; |
| 1336 bool allow_harmony_restrictive_declarations_; | 1338 bool allow_harmony_restrictive_declarations_; |
| 1337 bool allow_harmony_do_expressions_; | 1339 bool allow_harmony_do_expressions_; |
| 1338 bool allow_harmony_for_in_; | 1340 bool allow_harmony_for_in_; |
| 1339 bool allow_harmony_function_sent_; | 1341 bool allow_harmony_function_sent_; |
| 1340 bool allow_harmony_async_await_; | 1342 bool allow_harmony_async_await_; |
| 1341 bool allow_harmony_restrictive_generators_; | 1343 bool allow_harmony_restrictive_generators_; |
| 1342 bool allow_harmony_trailing_commas_; | 1344 bool allow_harmony_trailing_commas_; |
| 1343 bool allow_harmony_class_fields_; | 1345 bool allow_harmony_class_fields_; |
| 1346 bool allow_harmony_private_class_fields_; | |
| 1344 | 1347 |
| 1345 friend class DiscardableZoneScope; | 1348 friend class DiscardableZoneScope; |
| 1346 }; | 1349 }; |
| 1347 | 1350 |
| 1348 template <typename Impl> | 1351 template <typename Impl> |
| 1349 ParserBase<Impl>::FunctionState::FunctionState( | 1352 ParserBase<Impl>::FunctionState::FunctionState( |
| 1350 FunctionState** function_state_stack, ScopeState** scope_stack, | 1353 FunctionState** function_state_stack, ScopeState** scope_stack, |
| 1351 Scope* scope, FunctionKind kind) | 1354 Scope* scope, FunctionKind kind) |
| 1352 : ScopeState(scope_stack, scope), | 1355 : ScopeState(scope_stack, scope), |
| 1353 next_materialized_literal_index_(0), | 1356 next_materialized_literal_index_(0), |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1598 // Number | 1601 // Number |
| 1599 // String | 1602 // String |
| 1600 // ArrayLiteral | 1603 // ArrayLiteral |
| 1601 // ObjectLiteral | 1604 // ObjectLiteral |
| 1602 // RegExpLiteral | 1605 // RegExpLiteral |
| 1603 // ClassLiteral | 1606 // ClassLiteral |
| 1604 // '(' Expression ')' | 1607 // '(' Expression ')' |
| 1605 // TemplateLiteral | 1608 // TemplateLiteral |
| 1606 // do Block | 1609 // do Block |
| 1607 // AsyncFunctionExpression | 1610 // AsyncFunctionExpression |
| 1611 // PrivateName | |
| 1608 | 1612 |
| 1609 int beg_pos = peek_position(); | 1613 int beg_pos = peek_position(); |
| 1610 switch (peek()) { | 1614 switch (peek()) { |
| 1611 case Token::THIS: { | 1615 case Token::THIS: { |
| 1612 BindingPatternUnexpectedToken(); | 1616 BindingPatternUnexpectedToken(); |
| 1613 Consume(Token::THIS); | 1617 Consume(Token::THIS); |
| 1614 return impl()->ThisExpression(beg_pos); | 1618 return impl()->ThisExpression(beg_pos); |
| 1615 } | 1619 } |
| 1616 | 1620 |
| 1617 case Token::NULL_LITERAL: | 1621 case Token::NULL_LITERAL: |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1721 } | 1725 } |
| 1722 break; | 1726 break; |
| 1723 | 1727 |
| 1724 case Token::DO: | 1728 case Token::DO: |
| 1725 if (allow_harmony_do_expressions()) { | 1729 if (allow_harmony_do_expressions()) { |
| 1726 BindingPatternUnexpectedToken(); | 1730 BindingPatternUnexpectedToken(); |
| 1727 return impl()->ParseDoExpression(ok); | 1731 return impl()->ParseDoExpression(ok); |
| 1728 } | 1732 } |
| 1729 break; | 1733 break; |
| 1730 | 1734 |
| 1735 case Token::HASH: | |
| 1736 if (allow_harmony_private_class_fields()) { | |
| 1737 BindingPatternUnexpectedToken(); | |
| 1738 return impl()->ParsePrivateFieldReference( | |
| 1739 impl()->ThisExpression(beg_pos), ok); | |
| 1740 } | |
| 1741 break; | |
| 1742 | |
| 1731 default: | 1743 default: |
| 1732 break; | 1744 break; |
| 1733 } | 1745 } |
| 1734 | 1746 |
| 1735 ReportUnexpectedToken(Next()); | 1747 ReportUnexpectedToken(Next()); |
| 1736 *ok = false; | 1748 *ok = false; |
| 1737 return impl()->EmptyExpression(); | 1749 return impl()->EmptyExpression(); |
| 1738 } | 1750 } |
| 1739 | 1751 |
| 1740 template <typename Impl> | 1752 template <typename Impl> |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2007 impl()->PushLiteralName(*name); | 2019 impl()->PushLiteralName(*name); |
| 2008 | 2020 |
| 2009 uint32_t index; | 2021 uint32_t index; |
| 2010 return impl()->IsArrayIndex(*name, &index) | 2022 return impl()->IsArrayIndex(*name, &index) |
| 2011 ? factory()->NewNumberLiteral(index, pos) | 2023 ? factory()->NewNumberLiteral(index, pos) |
| 2012 : factory()->NewStringLiteral(*name, pos); | 2024 : factory()->NewStringLiteral(*name, pos); |
| 2013 } | 2025 } |
| 2014 | 2026 |
| 2015 template <typename Impl> | 2027 template <typename Impl> |
| 2016 typename ParserBase<Impl>::ClassLiteralPropertyT | 2028 typename ParserBase<Impl>::ClassLiteralPropertyT |
| 2017 ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, | 2029 ParserBase<Impl>::ParseClassPropertyDefinition( |
| 2018 bool has_extends, | 2030 ClassLiteralChecker* checker, bool has_extends, IdentifierT* private_name, |
| 2019 bool* is_computed_name, | 2031 bool* is_computed_name, bool* has_seen_constructor, bool* ok) { |
| 2020 bool* has_seen_constructor, | 2032 DCHECK(!allow_harmony_private_class_fields() || private_name != nullptr); |
| 2021 bool* ok) { | |
| 2022 DCHECK(has_seen_constructor != nullptr); | 2033 DCHECK(has_seen_constructor != nullptr); |
| 2023 bool is_get = false; | 2034 bool is_get = false; |
| 2024 bool is_set = false; | 2035 bool is_set = false; |
| 2025 bool is_generator = false; | 2036 bool is_generator = false; |
| 2026 bool is_async = false; | 2037 bool is_async = false; |
| 2027 bool is_static = false; | 2038 bool is_static = false; |
| 2028 PropertyKind kind = PropertyKind::kNotSet; | 2039 PropertyKind kind = PropertyKind::kNotSet; |
| 2029 | 2040 |
| 2030 Token::Value name_token = peek(); | 2041 Token::Value name_token = peek(); |
| 2031 | 2042 |
| 2032 IdentifierT name = impl()->EmptyIdentifier(); | 2043 IdentifierT name = impl()->EmptyIdentifier(); |
| 2033 ExpressionT name_expression; | 2044 ExpressionT name_expression; |
| 2034 if (name_token == Token::STATIC) { | 2045 if (name_token == Token::STATIC) { |
| 2035 Consume(Token::STATIC); | 2046 Consume(Token::STATIC); |
| 2036 if (peek() == Token::LPAREN) { | 2047 if (peek() == Token::LPAREN) { |
| 2037 kind = PropertyKind::kMethodProperty; | 2048 kind = PropertyKind::kMethodProperty; |
| 2038 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' | 2049 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
| 2039 name_expression = factory()->NewStringLiteral(name, position()); | 2050 name_expression = factory()->NewStringLiteral(name, position()); |
| 2040 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON || | 2051 } else if (peek() == Token::ASSIGN || peek() == Token::SEMICOLON || |
| 2041 peek() == Token::RBRACE) { | 2052 peek() == Token::RBRACE) { |
| 2042 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' | 2053 name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
| 2043 name_expression = factory()->NewStringLiteral(name, position()); | 2054 name_expression = factory()->NewStringLiteral(name, position()); |
| 2044 } else { | 2055 } else { |
| 2045 is_static = true; | 2056 is_static = true; |
| 2046 name_expression = ParsePropertyName( | 2057 name_expression = ParsePropertyName( |
| 2047 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2058 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
| 2048 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2059 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2049 } | 2060 } |
| 2061 } else if (allow_harmony_private_class_fields() && | |
| 2062 name_token == Token::HASH) { | |
| 2063 Consume(Token::HASH); | |
| 2064 // Private field | |
| 2065 *private_name = ParseIdentifierName(CHECK_OK_CUSTOM( | |
| 2066 EmptyClassLiteralProperty)); // TODO(bakkot) IdentifierPart | |
|
Dan Ehrenberg
2016/09/15 21:26:58
Actually I like using IdentifierName here; I think
| |
| 2067 name_expression = impl()->EmptyExpression(); | |
| 2068 | |
| 2069 bool has_initializer = Check(Token::ASSIGN); | |
| 2070 FunctionLiteralT function_literal = ParseClassFieldForInitializer( | |
| 2071 has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | |
| 2072 ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | |
| 2073 return factory()->NewClassLiteralProperty(name_expression, function_literal, | |
| 2074 ClassLiteralProperty::FIELD, | |
| 2075 false, false); | |
| 2050 } else { | 2076 } else { |
| 2051 name_expression = ParsePropertyName( | 2077 name_expression = ParsePropertyName( |
| 2052 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2078 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
| 2053 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); | 2079 is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
| 2054 } | 2080 } |
| 2055 | 2081 |
| 2056 switch (kind) { | 2082 switch (kind) { |
| 2057 case PropertyKind::kClassField: | 2083 case PropertyKind::kClassField: |
| 2058 case PropertyKind::kNotSet: // This case is a name followed by a name or | 2084 case PropertyKind::kNotSet: // This case is a name followed by a name or |
| 2059 // other property. Here we have to assume | 2085 // other property. Here we have to assume |
| (...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3365 Expect(Token::RBRACK, CHECK_OK); | 3391 Expect(Token::RBRACK, CHECK_OK); |
| 3366 break; | 3392 break; |
| 3367 } | 3393 } |
| 3368 case Token::PERIOD: { | 3394 case Token::PERIOD: { |
| 3369 *is_async = false; | 3395 *is_async = false; |
| 3370 impl()->RewriteNonPattern(CHECK_OK); | 3396 impl()->RewriteNonPattern(CHECK_OK); |
| 3371 BindingPatternUnexpectedToken(); | 3397 BindingPatternUnexpectedToken(); |
| 3372 ArrowFormalParametersUnexpectedToken(); | 3398 ArrowFormalParametersUnexpectedToken(); |
| 3373 | 3399 |
| 3374 Consume(Token::PERIOD); | 3400 Consume(Token::PERIOD); |
| 3401 if (allow_harmony_private_class_fields() && peek() == Token::HASH) { | |
| 3402 expression = impl()->ParsePrivateFieldReference(expression, CHECK_OK); | |
| 3403 break; | |
| 3404 } | |
| 3375 int pos = position(); | 3405 int pos = position(); |
| 3376 IdentifierT name = ParseIdentifierName(CHECK_OK); | 3406 IdentifierT name = ParseIdentifierName(CHECK_OK); |
| 3377 expression = factory()->NewProperty( | 3407 expression = factory()->NewProperty( |
| 3378 expression, factory()->NewStringLiteral(name, pos), pos); | 3408 expression, factory()->NewStringLiteral(name, pos), pos); |
| 3379 impl()->PushLiteralName(name); | 3409 impl()->PushLiteralName(name); |
| 3380 break; | 3410 break; |
| 3381 } | 3411 } |
| 3382 case Token::TEMPLATE_SPAN: | 3412 case Token::TEMPLATE_SPAN: |
| 3383 case Token::TEMPLATE_TAIL: { | 3413 case Token::TEMPLATE_TAIL: { |
| 3384 *is_async = false; | 3414 *is_async = false; |
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4308 has_seen_constructor_ = true; | 4338 has_seen_constructor_ = true; |
| 4309 return; | 4339 return; |
| 4310 } | 4340 } |
| 4311 } | 4341 } |
| 4312 | 4342 |
| 4313 | 4343 |
| 4314 } // namespace internal | 4344 } // namespace internal |
| 4315 } // namespace v8 | 4345 } // namespace v8 |
| 4316 | 4346 |
| 4317 #endif // V8_PARSING_PARSER_BASE_H | 4347 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |