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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 stack_overflow_(false), | 211 stack_overflow_(false), |
212 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), | 212 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), |
213 function_literal_id_(0), | 213 function_literal_id_(0), |
214 allow_natives_(false), | 214 allow_natives_(false), |
215 allow_tailcalls_(false), | 215 allow_tailcalls_(false), |
216 allow_harmony_do_expressions_(false), | 216 allow_harmony_do_expressions_(false), |
217 allow_harmony_function_sent_(false), | 217 allow_harmony_function_sent_(false), |
218 allow_harmony_async_await_(false), | 218 allow_harmony_async_await_(false), |
219 allow_harmony_restrictive_generators_(false), | 219 allow_harmony_restrictive_generators_(false), |
220 allow_harmony_trailing_commas_(false), | 220 allow_harmony_trailing_commas_(false), |
221 allow_harmony_class_fields_(false) {} | 221 allow_harmony_class_fields_(false), |
222 allow_harmony_object_spread_(false) {} | |
222 | 223 |
223 #define ALLOW_ACCESSORS(name) \ | 224 #define ALLOW_ACCESSORS(name) \ |
224 bool allow_##name() const { return allow_##name##_; } \ | 225 bool allow_##name() const { return allow_##name##_; } \ |
225 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 226 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
226 | 227 |
227 ALLOW_ACCESSORS(natives); | 228 ALLOW_ACCESSORS(natives); |
228 ALLOW_ACCESSORS(tailcalls); | 229 ALLOW_ACCESSORS(tailcalls); |
229 ALLOW_ACCESSORS(harmony_do_expressions); | 230 ALLOW_ACCESSORS(harmony_do_expressions); |
230 ALLOW_ACCESSORS(harmony_function_sent); | 231 ALLOW_ACCESSORS(harmony_function_sent); |
231 ALLOW_ACCESSORS(harmony_async_await); | 232 ALLOW_ACCESSORS(harmony_async_await); |
232 ALLOW_ACCESSORS(harmony_restrictive_generators); | 233 ALLOW_ACCESSORS(harmony_restrictive_generators); |
233 ALLOW_ACCESSORS(harmony_trailing_commas); | 234 ALLOW_ACCESSORS(harmony_trailing_commas); |
234 ALLOW_ACCESSORS(harmony_class_fields); | 235 ALLOW_ACCESSORS(harmony_class_fields); |
236 ALLOW_ACCESSORS(harmony_object_spread); | |
235 | 237 |
236 #undef ALLOW_ACCESSORS | 238 #undef ALLOW_ACCESSORS |
237 | 239 |
238 uintptr_t stack_limit() const { return stack_limit_; } | 240 uintptr_t stack_limit() const { return stack_limit_; } |
239 | 241 |
240 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 242 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
241 | 243 |
242 void set_default_eager_compile_hint( | 244 void set_default_eager_compile_hint( |
243 FunctionLiteral::EagerCompileHint eager_compile_hint) { | 245 FunctionLiteral::EagerCompileHint eager_compile_hint) { |
244 default_eager_compile_hint_ = eager_compile_hint; | 246 default_eager_compile_hint_ = eager_compile_hint; |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 ExpressionT ParseExpressionCoverGrammar(bool accept_IN, bool* ok); | 1145 ExpressionT ParseExpressionCoverGrammar(bool accept_IN, bool* ok); |
1144 | 1146 |
1145 ExpressionT ParseArrayLiteral(bool* ok); | 1147 ExpressionT ParseArrayLiteral(bool* ok); |
1146 | 1148 |
1147 enum class PropertyKind { | 1149 enum class PropertyKind { |
1148 kAccessorProperty, | 1150 kAccessorProperty, |
1149 kValueProperty, | 1151 kValueProperty, |
1150 kShorthandProperty, | 1152 kShorthandProperty, |
1151 kMethodProperty, | 1153 kMethodProperty, |
1152 kClassField, | 1154 kClassField, |
1155 kSpreadProperty, | |
1153 kNotSet | 1156 kNotSet |
1154 }; | 1157 }; |
1155 | 1158 |
1156 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); | 1159 bool SetPropertyKindFromToken(Token::Value token, PropertyKind* kind); |
1157 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, | 1160 ExpressionT ParsePropertyName(IdentifierT* name, PropertyKind* kind, |
1158 bool* is_generator, bool* is_get, bool* is_set, | 1161 bool* is_generator, bool* is_get, bool* is_set, |
1159 bool* is_async, bool* is_computed_name, | 1162 bool* is_async, bool* is_computed_name, |
1160 bool* ok); | 1163 bool* ok); |
1161 ExpressionT ParseObjectLiteral(bool* ok); | 1164 ExpressionT ParseObjectLiteral(bool* ok); |
1162 ClassLiteralPropertyT ParseClassPropertyDefinition( | 1165 ClassLiteralPropertyT ParseClassPropertyDefinition( |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1449 int function_literal_id_; | 1452 int function_literal_id_; |
1450 | 1453 |
1451 bool allow_natives_; | 1454 bool allow_natives_; |
1452 bool allow_tailcalls_; | 1455 bool allow_tailcalls_; |
1453 bool allow_harmony_do_expressions_; | 1456 bool allow_harmony_do_expressions_; |
1454 bool allow_harmony_function_sent_; | 1457 bool allow_harmony_function_sent_; |
1455 bool allow_harmony_async_await_; | 1458 bool allow_harmony_async_await_; |
1456 bool allow_harmony_restrictive_generators_; | 1459 bool allow_harmony_restrictive_generators_; |
1457 bool allow_harmony_trailing_commas_; | 1460 bool allow_harmony_trailing_commas_; |
1458 bool allow_harmony_class_fields_; | 1461 bool allow_harmony_class_fields_; |
1462 bool allow_harmony_object_spread_; | |
1459 | 1463 |
1460 friend class DiscardableZoneScope; | 1464 friend class DiscardableZoneScope; |
1461 }; | 1465 }; |
1462 | 1466 |
1463 template <typename Impl> | 1467 template <typename Impl> |
1464 ParserBase<Impl>::FunctionState::FunctionState( | 1468 ParserBase<Impl>::FunctionState::FunctionState( |
1465 FunctionState** function_state_stack, ScopeState** scope_stack, | 1469 FunctionState** function_state_stack, ScopeState** scope_stack, |
1466 DeclarationScope* scope) | 1470 DeclarationScope* scope) |
1467 : ScopeState(scope_stack, scope), | 1471 : ScopeState(scope_stack, scope), |
1468 next_materialized_literal_index_(0), | 1472 next_materialized_literal_index_(0), |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2102 *is_computed_name = true; | 2106 *is_computed_name = true; |
2103 Consume(Token::LBRACK); | 2107 Consume(Token::LBRACK); |
2104 ExpressionClassifier computed_name_classifier(this); | 2108 ExpressionClassifier computed_name_classifier(this); |
2105 expression = ParseAssignmentExpression(true, CHECK_OK); | 2109 expression = ParseAssignmentExpression(true, CHECK_OK); |
2106 impl()->RewriteNonPattern(CHECK_OK); | 2110 impl()->RewriteNonPattern(CHECK_OK); |
2107 impl()->AccumulateFormalParameterContainmentErrors(); | 2111 impl()->AccumulateFormalParameterContainmentErrors(); |
2108 Expect(Token::RBRACK, CHECK_OK); | 2112 Expect(Token::RBRACK, CHECK_OK); |
2109 break; | 2113 break; |
2110 } | 2114 } |
2111 | 2115 |
2116 case Token::ELLIPSIS: { | |
adamk
2017/01/05 22:39:14
No need for this block
gsathya
2017/01/05 22:56:29
Done.
| |
2117 if (allow_harmony_object_spread()) { | |
2118 // TODO(gsathya): Implement destructuring/rest | |
2119 classifier()->RecordPatternError(scanner()->location(), | |
2120 MessageTemplate::kUnexpectedToken); | |
2121 | |
2122 *name = impl()->EmptyIdentifier(); | |
2123 Consume(Token::ELLIPSIS); | |
2124 ExpressionClassifier spread_classifier(this); | |
2125 expression = ParseAssignmentExpression(true, CHECK_OK); | |
2126 impl()->RewriteNonPattern(CHECK_OK); | |
2127 impl()->AccumulateFormalParameterContainmentErrors(); | |
2128 *kind = PropertyKind::kSpreadProperty; | |
2129 return expression; | |
2130 } | |
2131 } | |
2132 | |
2112 default: | 2133 default: |
2113 *name = ParseIdentifierName(CHECK_OK); | 2134 *name = ParseIdentifierName(CHECK_OK); |
2114 break; | 2135 break; |
2115 } | 2136 } |
2116 | 2137 |
2117 if (*kind == PropertyKind::kNotSet) { | 2138 if (*kind == PropertyKind::kNotSet) { |
2118 SetPropertyKindFromToken(peek(), kind); | 2139 SetPropertyKindFromToken(peek(), kind); |
2119 } | 2140 } |
2120 | 2141 |
2121 if (*is_computed_name) { | 2142 if (*is_computed_name) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2262 if (!*is_computed_name) { | 2283 if (!*is_computed_name) { |
2263 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); | 2284 impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
2264 } | 2285 } |
2265 | 2286 |
2266 *property_kind = | 2287 *property_kind = |
2267 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER; | 2288 is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER; |
2268 return factory()->NewClassLiteralProperty(name_expression, value, | 2289 return factory()->NewClassLiteralProperty(name_expression, value, |
2269 *property_kind, *is_static, | 2290 *property_kind, *is_static, |
2270 *is_computed_name); | 2291 *is_computed_name); |
2271 } | 2292 } |
2293 case PropertyKind::kSpreadProperty: | |
2294 UNREACHABLE(); | |
2272 } | 2295 } |
2273 UNREACHABLE(); | 2296 UNREACHABLE(); |
2274 return impl()->EmptyClassLiteralProperty(); | 2297 return impl()->EmptyClassLiteralProperty(); |
2275 } | 2298 } |
2276 | 2299 |
2277 template <typename Impl> | 2300 template <typename Impl> |
2278 typename ParserBase<Impl>::FunctionLiteralT | 2301 typename ParserBase<Impl>::FunctionLiteralT |
2279 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, | 2302 ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, |
2280 bool* ok) { | 2303 bool* ok) { |
2281 // Makes a concise method which evaluates and returns the initialized value | 2304 // Makes a concise method which evaluates and returns the initialized value |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2323 IdentifierT name = impl()->EmptyIdentifier(); | 2346 IdentifierT name = impl()->EmptyIdentifier(); |
2324 Token::Value name_token = peek(); | 2347 Token::Value name_token = peek(); |
2325 int next_beg_pos = scanner()->peek_location().beg_pos; | 2348 int next_beg_pos = scanner()->peek_location().beg_pos; |
2326 int next_end_pos = scanner()->peek_location().end_pos; | 2349 int next_end_pos = scanner()->peek_location().end_pos; |
2327 | 2350 |
2328 ExpressionT name_expression = ParsePropertyName( | 2351 ExpressionT name_expression = ParsePropertyName( |
2329 &name, &kind, &is_generator, &is_get, &is_set, &is_async, | 2352 &name, &kind, &is_generator, &is_get, &is_set, &is_async, |
2330 is_computed_name, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2353 is_computed_name, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2331 | 2354 |
2332 switch (kind) { | 2355 switch (kind) { |
2356 case PropertyKind::kSpreadProperty: | |
2357 DCHECK(allow_harmony_object_spread()); | |
2358 DCHECK(!is_get && !is_set && !is_generator && !is_async && | |
2359 !*is_computed_name); | |
2360 DCHECK(name_token == Token::ELLIPSIS); | |
2361 | |
2362 *is_computed_name = true; | |
2363 | |
2364 return factory()->NewObjectLiteralProperty( | |
2365 impl()->GetLiteralTheHole(kNoSourcePosition), name_expression, | |
2366 ObjectLiteralProperty::SPREAD, true); | |
2367 | |
2333 case PropertyKind::kValueProperty: { | 2368 case PropertyKind::kValueProperty: { |
2334 DCHECK(!is_get && !is_set && !is_generator && !is_async); | 2369 DCHECK(!is_get && !is_set && !is_generator && !is_async); |
2335 | 2370 |
2336 if (!*is_computed_name) { | 2371 if (!*is_computed_name) { |
2337 checker->CheckDuplicateProto(name_token); | 2372 checker->CheckDuplicateProto(name_token); |
2338 } | 2373 } |
2339 Consume(Token::COLON); | 2374 Consume(Token::COLON); |
2340 int beg_pos = peek_position(); | 2375 int beg_pos = peek_position(); |
2341 ExpressionT value = ParseAssignmentExpression( | 2376 ExpressionT value = ParseAssignmentExpression( |
2342 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2377 true, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
(...skipping 3156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5499 has_seen_constructor_ = true; | 5534 has_seen_constructor_ = true; |
5500 return; | 5535 return; |
5501 } | 5536 } |
5502 } | 5537 } |
5503 | 5538 |
5504 | 5539 |
5505 } // namespace internal | 5540 } // namespace internal |
5506 } // namespace v8 | 5541 } // namespace v8 |
5507 | 5542 |
5508 #endif // V8_PARSING_PARSER_BASE_H | 5543 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |