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 |
neis
2017/01/31 11:20:09
Please update the comment.
I'm a bit confused, th
gsathya
2017/01/31 18:26:07
This hasn't matched the spec in a while. Fixed
| |
3354 // The '[' Expression ']' and '.' Identifier parts are parsed by | 3358 // The '[' Expression ']' and '.' Identifier parts are parsed by |
3355 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the | 3359 // ParseMemberExpressionContinuation, and the Arguments part is parsed by the |
3356 // caller. | 3360 // caller. |
3357 | 3361 |
3358 // Parse the initial primary or function expression. | 3362 // Parse the initial primary or function expression. |
3359 ExpressionT result; | 3363 ExpressionT result; |
3360 if (peek() == Token::FUNCTION) { | 3364 if (peek() == Token::FUNCTION) { |
3361 BindingPatternUnexpectedToken(); | 3365 BindingPatternUnexpectedToken(); |
3362 ArrowFormalParametersUnexpectedToken(); | 3366 ArrowFormalParametersUnexpectedToken(); |
3363 | 3367 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3396 } | 3400 } |
3397 result = impl()->ParseFunctionLiteral( | 3401 result = impl()->ParseFunctionLiteral( |
3398 name, function_name_location, | 3402 name, function_name_location, |
3399 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 3403 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
3400 : kFunctionNameValidityUnknown, | 3404 : kFunctionNameValidityUnknown, |
3401 function_kind, function_token_position, function_type, language_mode(), | 3405 function_kind, function_token_position, function_type, language_mode(), |
3402 CHECK_OK); | 3406 CHECK_OK); |
3403 } else if (peek() == Token::SUPER) { | 3407 } else if (peek() == Token::SUPER) { |
3404 const bool is_new = false; | 3408 const bool is_new = false; |
3405 result = ParseSuperExpression(is_new, CHECK_OK); | 3409 result = ParseSuperExpression(is_new, CHECK_OK); |
3410 } else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) { | |
3411 result = ParseDynamicImportExpression(CHECK_OK); | |
3406 } else { | 3412 } else { |
3407 result = ParsePrimaryExpression(is_async, CHECK_OK); | 3413 result = ParsePrimaryExpression(is_async, CHECK_OK); |
3408 } | 3414 } |
3409 | 3415 |
3410 result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK); | 3416 result = ParseMemberExpressionContinuation(result, is_async, CHECK_OK); |
3411 return result; | 3417 return result; |
3412 } | 3418 } |
3413 | 3419 |
3414 template <typename Impl> | 3420 template <typename Impl> |
3421 typename ParserBase<Impl>::ExpressionT | |
3422 ParserBase<Impl>::ParseDynamicImportExpression(bool* ok) { | |
3423 DCHECK(allow_harmony_dynamic_import()); | |
3424 Consume(Token::IMPORT); | |
3425 int pos = position(); | |
3426 Expect(Token::LPAREN, CHECK_OK); | |
3427 ExpressionT arg = ParseAssignmentExpression(true, CHECK_OK); | |
3428 Expect(Token::RPAREN, CHECK_OK); | |
3429 ZoneList<ExpressionT>* args = new (zone()) ZoneList<ExpressionT>(1, zone()); | |
3430 args->Add(arg, zone()); | |
3431 return factory()->NewCallRuntime(Runtime::kDynamicImportCall, args, pos); | |
3432 } | |
3433 | |
3434 template <typename Impl> | |
3415 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( | 3435 typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression( |
3416 bool is_new, bool* ok) { | 3436 bool is_new, bool* ok) { |
3417 Expect(Token::SUPER, CHECK_OK); | 3437 Expect(Token::SUPER, CHECK_OK); |
3418 int pos = position(); | 3438 int pos = position(); |
3419 | 3439 |
3420 DeclarationScope* scope = GetReceiverScope(); | 3440 DeclarationScope* scope = GetReceiverScope(); |
3421 FunctionKind kind = scope->function_kind(); | 3441 FunctionKind kind = scope->function_kind(); |
3422 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3442 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
3423 IsClassConstructor(kind)) { | 3443 IsClassConstructor(kind)) { |
3424 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3444 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
(...skipping 2298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5723 return; | 5743 return; |
5724 } | 5744 } |
5725 } | 5745 } |
5726 | 5746 |
5727 #undef CHECK_OK_VOID | 5747 #undef CHECK_OK_VOID |
5728 | 5748 |
5729 } // namespace internal | 5749 } // namespace internal |
5730 } // namespace v8 | 5750 } // namespace v8 |
5731 | 5751 |
5732 #endif // V8_PARSING_PARSER_BASE_H | 5752 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |