| 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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // typedef Factory; | 77 // typedef Factory; |
| 78 // }; | 78 // }; |
| 79 // // ... | 79 // // ... |
| 80 // }; | 80 // }; |
| 81 | 81 |
| 82 template <typename Traits> | 82 template <typename Traits> |
| 83 class ParserBase : public Traits { | 83 class ParserBase : public Traits { |
| 84 public: | 84 public: |
| 85 // Shorten type names defined by Traits. | 85 // Shorten type names defined by Traits. |
| 86 typedef typename Traits::Type::Expression ExpressionT; | 86 typedef typename Traits::Type::Expression ExpressionT; |
| 87 typedef typename Traits::Type::ExpressionList ExpressionListT; |
| 87 typedef typename Traits::Type::Identifier IdentifierT; | 88 typedef typename Traits::Type::Identifier IdentifierT; |
| 88 typedef typename Traits::Type::FormalParameter FormalParameterT; | 89 typedef typename Traits::Type::FormalParameter FormalParameterT; |
| 89 typedef typename Traits::Type::FormalParameterScope FormalParameterScopeT; | 90 typedef typename Traits::Type::FormalParameterScope FormalParameterScopeT; |
| 90 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 91 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
| 91 typedef typename Traits::Type::Literal LiteralT; | 92 typedef typename Traits::Type::Literal LiteralT; |
| 92 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 93 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
| 93 | 94 |
| 94 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 95 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
| 95 v8::Extension* extension, AstValueFactory* ast_value_factory, | 96 v8::Extension* extension, AstValueFactory* ast_value_factory, |
| 96 ParserRecorder* log, typename Traits::Type::Parser this_object) | 97 ParserRecorder* log, typename Traits::Type::Parser this_object) |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 ExpressionClassifier* classifier, bool* ok); | 688 ExpressionClassifier* classifier, bool* ok); |
| 688 void AddTemplateExpression(ExpressionT); | 689 void AddTemplateExpression(ExpressionT); |
| 689 ExpressionT ParseSuperExpression(bool is_new, | 690 ExpressionT ParseSuperExpression(bool is_new, |
| 690 ExpressionClassifier* classifier, bool* ok); | 691 ExpressionClassifier* classifier, bool* ok); |
| 691 ExpressionT ParseStrongInitializationExpression( | 692 ExpressionT ParseStrongInitializationExpression( |
| 692 ExpressionClassifier* classifier, bool* ok); | 693 ExpressionClassifier* classifier, bool* ok); |
| 693 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, | 694 ExpressionT ParseStrongSuperCallExpression(ExpressionClassifier* classifier, |
| 694 bool* ok); | 695 bool* ok); |
| 695 | 696 |
| 696 void ParseFormalParameter(FormalParameterScopeT* scope, | 697 void ParseFormalParameter(FormalParameterScopeT* scope, |
| 697 FormalParameterErrorLocations* locs, bool is_rest, | 698 Scope* initializer_scope, |
| 699 FormalParameterErrorLocations* locs, |
| 700 ExpressionT* initializer, |
| 701 bool* has_initializer, bool is_rest, |
| 698 bool* ok); | 702 bool* ok); |
| 699 int ParseFormalParameterList(FormalParameterScopeT* scope, | 703 int ParseFormalParameterList(FormalParameterScopeT* scope, |
| 704 Scope* initializer_scope, |
| 700 FormalParameterErrorLocations* locs, | 705 FormalParameterErrorLocations* locs, |
| 706 ExpressionListT initializers, |
| 707 bool* has_initializers, |
| 701 bool* has_rest, bool* ok); | 708 bool* has_rest, bool* ok); |
| 702 void CheckArityRestrictions( | 709 void CheckArityRestrictions( |
| 703 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 710 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
| 704 int formals_start_pos, int formals_end_pos, bool* ok); | 711 int formals_start_pos, int formals_end_pos, bool* ok); |
| 705 | 712 |
| 706 // Checks if the expression is a valid reference expression (e.g., on the | 713 // Checks if the expression is a valid reference expression (e.g., on the |
| 707 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 714 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
| 708 // we allow calls for web compatibility and rewrite them to a runtime throw. | 715 // we allow calls for web compatibility and rewrite them to a runtime throw. |
| 709 ExpressionT CheckAndRewriteReferenceExpression( | 716 ExpressionT CheckAndRewriteReferenceExpression( |
| 710 ExpressionT expression, | 717 ExpressionT expression, |
| (...skipping 2625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3336 return expression; | 3343 return expression; |
| 3337 } | 3344 } |
| 3338 } | 3345 } |
| 3339 DCHECK(false); | 3346 DCHECK(false); |
| 3340 return this->EmptyExpression(); | 3347 return this->EmptyExpression(); |
| 3341 } | 3348 } |
| 3342 | 3349 |
| 3343 | 3350 |
| 3344 template <class Traits> | 3351 template <class Traits> |
| 3345 void ParserBase<Traits>::ParseFormalParameter( | 3352 void ParserBase<Traits>::ParseFormalParameter( |
| 3346 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3353 FormalParameterScopeT* scope, Scope* parameter_scope, |
| 3347 bool is_rest, bool* ok) { | 3354 FormalParameterErrorLocations* locs, |
| 3355 ExpressionT* initializer, bool* has_initializer, bool is_rest, bool* ok) { |
| 3348 // FormalParameter[Yield,GeneratorParameter] : | 3356 // FormalParameter[Yield,GeneratorParameter] : |
| 3349 // BindingElement[?Yield, ?GeneratorParameter] | 3357 // BindingElement[?Yield, ?GeneratorParameter] |
| 3350 bool is_strict_reserved; | 3358 bool is_strict_reserved; |
| 3351 IdentifierT name = | 3359 IdentifierT name = |
| 3352 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); | 3360 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, ok); |
| 3353 if (!*ok) return; | 3361 if (!*ok) return; |
| 3354 | 3362 |
| 3363 if (parameter_scope && Check(Token::ASSIGN)) { |
| 3364 // Optional argument initializer |
| 3365 // let formalName = IS_UNDEFINED(arguments[i]) ? initializer : arguments[i]; |
| 3366 BlockState state(&scope_, NewScope(parameter_scope, BLOCK_SCOPE)); |
| 3367 static const bool accept_IN = true; |
| 3368 ExpressionClassifier classifier; |
| 3369 *initializer = ParseAssignmentExpression(accept_IN, &classifier, ok); |
| 3370 if (!*ok) return; |
| 3371 *has_initializer = true; |
| 3372 } |
| 3373 |
| 3355 // Store locations for possible future error reports. | 3374 // Store locations for possible future error reports. |
| 3356 if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { | 3375 if (!locs->eval_or_arguments.IsValid() && this->IsEvalOrArguments(name)) { |
| 3357 locs->eval_or_arguments = scanner()->location(); | 3376 locs->eval_or_arguments = scanner()->location(); |
| 3358 } | 3377 } |
| 3359 if (!locs->undefined.IsValid() && this->IsUndefined(name)) { | 3378 if (!locs->undefined.IsValid() && this->IsUndefined(name)) { |
| 3360 locs->undefined = scanner()->location(); | 3379 locs->undefined = scanner()->location(); |
| 3361 } | 3380 } |
| 3362 if (!locs->reserved.IsValid() && is_strict_reserved) { | 3381 if (!locs->reserved.IsValid() && is_strict_reserved) { |
| 3363 locs->reserved = scanner()->location(); | 3382 locs->reserved = scanner()->location(); |
| 3364 } | 3383 } |
| 3365 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); | 3384 bool was_declared = Traits::DeclareFormalParameter(scope, name, is_rest); |
| 3366 if (!locs->duplicate.IsValid() && was_declared) { | 3385 if (!locs->duplicate.IsValid() && was_declared) { |
| 3367 locs->duplicate = scanner()->location(); | 3386 locs->duplicate = scanner()->location(); |
| 3368 } | 3387 } |
| 3369 } | 3388 } |
| 3370 | 3389 |
| 3371 | 3390 |
| 3372 template <class Traits> | 3391 template <class Traits> |
| 3373 int ParserBase<Traits>::ParseFormalParameterList( | 3392 int ParserBase<Traits>::ParseFormalParameterList( |
| 3374 FormalParameterScopeT* scope, FormalParameterErrorLocations* locs, | 3393 FormalParameterScopeT* scope, Scope* parameter_scope, |
| 3375 bool* is_rest, bool* ok) { | 3394 FormalParameterErrorLocations* locs, |
| 3395 ExpressionListT initializers, bool* has_initializers, bool* is_rest, |
| 3396 bool* ok) { |
| 3376 // FormalParameters[Yield,GeneratorParameter] : | 3397 // FormalParameters[Yield,GeneratorParameter] : |
| 3377 // [empty] | 3398 // [empty] |
| 3378 // FormalParameterList[?Yield, ?GeneratorParameter] | 3399 // FormalParameterList[?Yield, ?GeneratorParameter] |
| 3379 // | 3400 // |
| 3380 // FormalParameterList[Yield,GeneratorParameter] : | 3401 // FormalParameterList[Yield,GeneratorParameter] : |
| 3381 // FunctionRestParameter[?Yield] | 3402 // FunctionRestParameter[?Yield] |
| 3382 // FormalsList[?Yield, ?GeneratorParameter] | 3403 // FormalsList[?Yield, ?GeneratorParameter] |
| 3383 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] | 3404 // FormalsList[?Yield, ?GeneratorParameter] , FunctionRestParameter[?Yield] |
| 3384 // | 3405 // |
| 3385 // FormalsList[Yield,GeneratorParameter] : | 3406 // FormalsList[Yield,GeneratorParameter] : |
| 3386 // FormalParameter[?Yield, ?GeneratorParameter] | 3407 // FormalParameter[?Yield, ?GeneratorParameter] |
| 3387 // FormalsList[?Yield, ?GeneratorParameter] , | 3408 // FormalsList[?Yield, ?GeneratorParameter] , |
| 3388 // FormalParameter[?Yield,?GeneratorParameter] | 3409 // FormalParameter[?Yield,?GeneratorParameter] |
| 3389 | 3410 |
| 3390 int parameter_count = 0; | 3411 int parameter_count = 0; |
| 3391 | 3412 |
| 3413 BlockState parameter_block(&scope_, parameter_scope); |
| 3414 |
| 3392 if (peek() != Token::RPAREN) { | 3415 if (peek() != Token::RPAREN) { |
| 3393 do { | 3416 do { |
| 3394 if (++parameter_count > Code::kMaxArguments) { | 3417 if (++parameter_count > Code::kMaxArguments) { |
| 3395 ReportMessage("too_many_parameters"); | 3418 ReportMessage("too_many_parameters"); |
| 3396 *ok = false; | 3419 *ok = false; |
| 3397 return -1; | 3420 return -1; |
| 3398 } | 3421 } |
| 3422 bool has_initializer = false; |
| 3423 ExpressionT initializer = this->EmptyExpression(); |
| 3399 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); | 3424 *is_rest = allow_harmony_rest_params() && Check(Token::ELLIPSIS); |
| 3400 ParseFormalParameter(scope, locs, *is_rest, ok); | 3425 ParseFormalParameter(scope, parameter_scope, locs, &initializer, |
| 3426 &has_initializer, *is_rest, ok); |
| 3401 if (!*ok) return -1; | 3427 if (!*ok) return -1; |
| 3428 initializers->Add(initializer, zone()); |
| 3429 if (has_initializer) *has_initializers = true; |
| 3402 } while (!*is_rest && Check(Token::COMMA)); | 3430 } while (!*is_rest && Check(Token::COMMA)); |
| 3403 | 3431 |
| 3404 if (*is_rest && peek() == Token::COMMA) { | 3432 if (*is_rest && peek() == Token::COMMA) { |
| 3405 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); | 3433 ReportMessageAt(scanner()->peek_location(), "param_after_rest"); |
| 3406 *ok = false; | 3434 *ok = false; |
| 3407 return -1; | 3435 return -1; |
| 3408 } | 3436 } |
| 3409 } | 3437 } |
| 3410 | 3438 |
| 3411 return parameter_count; | 3439 return parameter_count; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3713 *ok = false; | 3741 *ok = false; |
| 3714 return; | 3742 return; |
| 3715 } | 3743 } |
| 3716 has_seen_constructor_ = true; | 3744 has_seen_constructor_ = true; |
| 3717 return; | 3745 return; |
| 3718 } | 3746 } |
| 3719 } | 3747 } |
| 3720 } } // v8::internal | 3748 } } // v8::internal |
| 3721 | 3749 |
| 3722 #endif // V8_PREPARSER_H | 3750 #endif // V8_PREPARSER_H |
| OLD | NEW |