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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 stack_overflow_(false), | 217 stack_overflow_(false), |
218 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), | 218 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), |
219 function_literal_id_(0), | 219 function_literal_id_(0), |
220 allow_natives_(false), | 220 allow_natives_(false), |
221 allow_tailcalls_(false), | 221 allow_tailcalls_(false), |
222 allow_harmony_do_expressions_(false), | 222 allow_harmony_do_expressions_(false), |
223 allow_harmony_function_sent_(false), | 223 allow_harmony_function_sent_(false), |
224 allow_harmony_restrictive_generators_(false), | 224 allow_harmony_restrictive_generators_(false), |
225 allow_harmony_trailing_commas_(false), | 225 allow_harmony_trailing_commas_(false), |
226 allow_harmony_class_fields_(false), | 226 allow_harmony_class_fields_(false), |
227 allow_harmony_object_rest_spread_(false) {} | 227 allow_harmony_object_rest_spread_(false), |
| 228 allow_harmony_dynamic_import_(false) {} |
228 | 229 |
229 #define ALLOW_ACCESSORS(name) \ | 230 #define ALLOW_ACCESSORS(name) \ |
230 bool allow_##name() const { return allow_##name##_; } \ | 231 bool allow_##name() const { return allow_##name##_; } \ |
231 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 232 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
232 | 233 |
233 ALLOW_ACCESSORS(natives); | 234 ALLOW_ACCESSORS(natives); |
234 ALLOW_ACCESSORS(tailcalls); | 235 ALLOW_ACCESSORS(tailcalls); |
235 ALLOW_ACCESSORS(harmony_do_expressions); | 236 ALLOW_ACCESSORS(harmony_do_expressions); |
236 ALLOW_ACCESSORS(harmony_function_sent); | 237 ALLOW_ACCESSORS(harmony_function_sent); |
237 ALLOW_ACCESSORS(harmony_restrictive_generators); | 238 ALLOW_ACCESSORS(harmony_restrictive_generators); |
238 ALLOW_ACCESSORS(harmony_trailing_commas); | 239 ALLOW_ACCESSORS(harmony_trailing_commas); |
239 ALLOW_ACCESSORS(harmony_class_fields); | 240 ALLOW_ACCESSORS(harmony_class_fields); |
240 ALLOW_ACCESSORS(harmony_object_rest_spread); | 241 ALLOW_ACCESSORS(harmony_object_rest_spread); |
| 242 ALLOW_ACCESSORS(harmony_dynamic_import); |
241 | 243 |
242 #undef ALLOW_ACCESSORS | 244 #undef ALLOW_ACCESSORS |
243 | 245 |
244 uintptr_t stack_limit() const { return stack_limit_; } | 246 uintptr_t stack_limit() const { return stack_limit_; } |
245 | 247 |
246 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 248 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
247 | 249 |
248 void set_default_eager_compile_hint( | 250 void set_default_eager_compile_hint( |
249 FunctionLiteral::EagerCompileHint eager_compile_hint) { | 251 FunctionLiteral::EagerCompileHint eager_compile_hint) { |
250 default_eager_compile_hint_ = eager_compile_hint; | 252 default_eager_compile_hint_ = eager_compile_hint; |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 void ParseAsyncFunctionBody(Scope* scope, StatementListT body, | 1201 void ParseAsyncFunctionBody(Scope* scope, StatementListT body, |
1200 FunctionKind kind, FunctionBodyType type, | 1202 FunctionKind kind, FunctionBodyType type, |
1201 bool accept_IN, int pos, bool* ok); | 1203 bool accept_IN, int pos, bool* ok); |
1202 ExpressionT ParseAsyncFunctionLiteral(bool* ok); | 1204 ExpressionT ParseAsyncFunctionLiteral(bool* ok); |
1203 ExpressionT ParseClassLiteral(IdentifierT name, | 1205 ExpressionT ParseClassLiteral(IdentifierT name, |
1204 Scanner::Location class_name_location, | 1206 Scanner::Location class_name_location, |
1205 bool name_is_strict_reserved, | 1207 bool name_is_strict_reserved, |
1206 int class_token_pos, bool* ok); | 1208 int class_token_pos, bool* ok); |
1207 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); | 1209 ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok); |
1208 ExpressionT ParseSuperExpression(bool is_new, bool* ok); | 1210 ExpressionT ParseSuperExpression(bool is_new, bool* ok); |
| 1211 ExpressionT ParseDynamicImportExpression(bool* ok); |
1209 ExpressionT ParseNewTargetExpression(bool* ok); | 1212 ExpressionT ParseNewTargetExpression(bool* ok); |
1210 | 1213 |
1211 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); | 1214 void ParseFormalParameter(FormalParametersT* parameters, bool* ok); |
1212 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); | 1215 void ParseFormalParameterList(FormalParametersT* parameters, bool* ok); |
1213 void CheckArityRestrictions(int param_count, FunctionKind function_type, | 1216 void CheckArityRestrictions(int param_count, FunctionKind function_type, |
1214 bool has_rest, int formals_start_pos, | 1217 bool has_rest, int formals_start_pos, |
1215 int formals_end_pos, bool* ok); | 1218 int formals_end_pos, bool* ok); |
1216 | 1219 |
1217 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, | 1220 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, |
1218 DeclarationParsingResult* parsing_result, | 1221 DeclarationParsingResult* parsing_result, |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 int function_literal_id_; | 1480 int function_literal_id_; |
1478 | 1481 |
1479 bool allow_natives_; | 1482 bool allow_natives_; |
1480 bool allow_tailcalls_; | 1483 bool allow_tailcalls_; |
1481 bool allow_harmony_do_expressions_; | 1484 bool allow_harmony_do_expressions_; |
1482 bool allow_harmony_function_sent_; | 1485 bool allow_harmony_function_sent_; |
1483 bool allow_harmony_restrictive_generators_; | 1486 bool allow_harmony_restrictive_generators_; |
1484 bool allow_harmony_trailing_commas_; | 1487 bool allow_harmony_trailing_commas_; |
1485 bool allow_harmony_class_fields_; | 1488 bool allow_harmony_class_fields_; |
1486 bool allow_harmony_object_rest_spread_; | 1489 bool allow_harmony_object_rest_spread_; |
| 1490 bool allow_harmony_dynamic_import_; |
1487 | 1491 |
1488 friend class DiscardableZoneScope; | 1492 friend class DiscardableZoneScope; |
1489 }; | 1493 }; |
1490 | 1494 |
1491 template <typename Impl> | 1495 template <typename Impl> |
1492 ParserBase<Impl>::FunctionState::FunctionState( | 1496 ParserBase<Impl>::FunctionState::FunctionState( |
1493 FunctionState** function_state_stack, ScopeState** scope_stack, | 1497 FunctionState** function_state_stack, ScopeState** scope_stack, |
1494 DeclarationScope* scope) | 1498 DeclarationScope* scope) |
1495 : ScopeState(scope_stack, scope), | 1499 : ScopeState(scope_stack, scope), |
1496 next_materialized_literal_index_(0), | 1500 next_materialized_literal_index_(0), |
(...skipping 1846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3343 // No 'new' or 'super' keyword. | 3347 // No 'new' or 'super' keyword. |
3344 return ParseMemberExpression(is_async, ok); | 3348 return ParseMemberExpression(is_async, ok); |
3345 } | 3349 } |
3346 | 3350 |
3347 template <typename Impl> | 3351 template <typename Impl> |
3348 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( | 3352 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression( |
3349 bool* is_async, bool* ok) { | 3353 bool* is_async, bool* ok) { |
3350 // MemberExpression :: | 3354 // MemberExpression :: |
3351 // (PrimaryExpression | FunctionLiteral | ClassLiteral) | 3355 // (PrimaryExpression | FunctionLiteral | ClassLiteral) |
3352 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* | 3356 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* |
3353 | 3357 // |
| 3358 // CallExpression :: |
| 3359 // (SuperCall | ImportCall) |
| 3360 // ('[' Expression ']' | '.' Identifier | Arguments | TemplateLiteral)* |
| 3361 // |
3354 // The '[' Expression ']' and '.' Identifier parts are parsed by | 3362 // The '[' Expression ']' and '.' Identifier parts are parsed by |
3355 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 3363 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
3356 // caller. | 3364 // caller. |
3357 | 3365 |
3358 // Parse the initial primary or function expression. | 3366 // Parse the initial primary or function expression. |
3359 ExpressionT result; | 3367 ExpressionT result; |
3360 if (peek() == Token::FUNCTION) { | 3368 if (peek() == Token::FUNCTION) { |
3361 BindingPatternUnexpectedToken(); | 3369 BindingPatternUnexpectedToken(); |
3362 ArrowFormalParametersUnexpectedToken(); | 3370 ArrowFormalParametersUnexpectedToken(); |
3363 | 3371 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3396 } | 3404 } |
3397 result = impl()->ParseFunctionLiteral( | 3405 result = impl()->ParseFunctionLiteral( |
3398 name, function_name_location, | 3406 name, function_name_location, |
3399 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 3407 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
3400 : kFunctionNameValidityUnknown, | 3408 : kFunctionNameValidityUnknown, |
3401 function_kind, function_token_position, function_type, language_mode(), | 3409 function_kind, function_token_position, function_type, language_mode(), |
3402 CHECK_OK); | 3410 CHECK_OK); |
3403 } else if (peek() == Token::SUPER) { | 3411 } else if (peek() == Token::SUPER) { |
3404 const bool is_new = false; | 3412 const bool is_new = false; |
3405 result = ParseSuperExpression(is_new, CHECK_OK); | 3413 result = ParseSuperExpression(is_new, CHECK_OK); |
| 3414 } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) { |
| 3415 result = ParseDynamicImportExpression(CHECK_OK); |
3406 } else { | 3416 } else { |
3407 result = ParsePrimaryExpression(is_async, CHECK_OK); | 3417 result = ParsePrimaryExpression(is_async, CHECK_OK); |
3408 } | 3418 } |
3409 | 3419 |
3410 result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK); | 3420 result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK); |
3411 return result; | 3421 return result; |
3412 } | 3422 } |
3413 | 3423 |
3414 template <typename Impl> | 3424 template <typename Impl> |
| 3425 typename ParserBase<Impl>::ExpressionT |
| 3426 ParserBase<Impl>::ParseDynamicImportExpression(bool* ok) { |
| 3427 DCHECK(allow_harmony_dynamic_import()); |
| 3428 Consume(Token::IMPORT); |
| 3429 int pos = position(); |
| 3430 Expect(Token::LPAREN, CHECK_OK); |
| 3431 ExpressionT arg = ParseAssignmentExpression(true, CHECK_OK); |
| 3432 Expect(Token::RPAREN, CHECK_OK); |
| 3433 ZoneList<ExpressionT>* args = new (zone()) ZoneList<ExpressionT>(1, zone()); |
| 3434 args->Add(arg, zone()); |
| 3435 return factory()->NewCallRuntime(Runtime::kDynamicImportCall, args, pos); |
| 3436 } |
| 3437 |
| 3438 template <typename Impl> |
3415 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( | 3439 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( |
3416 bool is_new, bool* ok) { | 3440 bool is_new, bool* ok) { |
3417 Expect(Token::SUPER, CHECK_OK); | 3441 Expect(Token::SUPER, CHECK_OK); |
3418 int pos = position(); | 3442 int pos = position(); |
3419 | 3443 |
3420 DeclarationScope* scope = GetReceiverScope(); | 3444 DeclarationScope* scope = GetReceiverScope(); |
3421 FunctionKind kind = scope->function_kind(); | 3445 FunctionKind kind = scope->function_kind(); |
3422 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3446 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
3423 IsClassConstructor(kind)) { | 3447 IsClassConstructor(kind)) { |
3424 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3448 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
(...skipping 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5723 return; | 5747 return; |
5724 } | 5748 } |
5725 } | 5749 } |
5726 | 5750 |
5727 #undef CHECK_OK_VOID | 5751 #undef CHECK_OK_VOID |
5728 | 5752 |
5729 } // namespace internal | 5753 } // namespace internal |
5730 } // namespace v8 | 5754 } // namespace v8 |
5731 | 5755 |
5732 #endif // V8_PARSING_PARSER_BASE_H | 5756 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |