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/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 611 } |
612 | 612 |
613 private: | 613 private: |
614 ParserBase* parser_; | 614 ParserBase* parser_; |
615 Mode old_mode_; | 615 Mode old_mode_; |
616 }; | 616 }; |
617 | 617 |
618 Scope* NewScope(Scope* parent, ScopeType scope_type) { | 618 Scope* NewScope(Scope* parent, ScopeType scope_type) { |
619 // Must always pass the function kind for FUNCTION_SCOPE. | 619 // Must always pass the function kind for FUNCTION_SCOPE. |
620 DCHECK(scope_type != FUNCTION_SCOPE); | 620 DCHECK(scope_type != FUNCTION_SCOPE); |
621 return NewScope(parent, scope_type, kNormalFunction); | 621 Scope* result = |
622 } | 622 new (zone()) Scope(zone(), parent, scope_type, kNormalFunction); |
623 | |
624 Scope* NewScope(Scope* parent, ScopeType scope_type, FunctionKind kind) { | |
625 DCHECK(ast_value_factory()); | |
626 Scope* result = new (zone()) | |
627 Scope(zone(), parent, scope_type, ast_value_factory(), kind); | |
628 result->Initialize(); | 623 result->Initialize(); |
| 624 if (scope_type == MODULE_SCOPE) result->DeclareThis(ast_value_factory()); |
629 return result; | 625 return result; |
630 } | 626 } |
631 | 627 |
| 628 Scope* NewFunctionScope(Scope* parent, FunctionKind kind) { |
| 629 DCHECK(ast_value_factory()); |
| 630 Scope* result = new (zone()) Scope(zone(), parent, FUNCTION_SCOPE, kind); |
| 631 result->Initialize(); |
| 632 if (!IsArrowFunction(kind)) { |
| 633 result->DeclareThis(ast_value_factory()); |
| 634 result->DeclareDefaultFunctionVariables(ast_value_factory()); |
| 635 } |
| 636 return result; |
| 637 } |
| 638 |
632 Scanner* scanner() const { return scanner_; } | 639 Scanner* scanner() const { return scanner_; } |
633 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } | 640 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } |
634 int position() { return scanner_->location().beg_pos; } | 641 int position() { return scanner_->location().beg_pos; } |
635 int peek_position() { return scanner_->peek_location().beg_pos; } | 642 int peek_position() { return scanner_->peek_location().beg_pos; } |
636 bool stack_overflow() const { return stack_overflow_; } | 643 bool stack_overflow() const { return stack_overflow_; } |
637 void set_stack_overflow() { stack_overflow_ = true; } | 644 void set_stack_overflow() { stack_overflow_ = true; } |
638 Mode mode() const { return mode_; } | 645 Mode mode() const { return mode_; } |
639 Zone* zone() const { return zone_; } | 646 Zone* zone() const { return zone_; } |
640 | 647 |
641 INLINE(Token::Value peek()) { | 648 INLINE(Token::Value peek()) { |
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 parenthesized_formals, is_async, CHECK_OK); | 2307 parenthesized_formals, is_async, CHECK_OK); |
2301 // This reads strangely, but is correct: it checks whether any | 2308 // This reads strangely, but is correct: it checks whether any |
2302 // sub-expression of the parameter list failed to be a valid formal | 2309 // sub-expression of the parameter list failed to be a valid formal |
2303 // parameter initializer. Since YieldExpressions are banned anywhere | 2310 // parameter initializer. Since YieldExpressions are banned anywhere |
2304 // in an arrow parameter list, this is correct. | 2311 // in an arrow parameter list, this is correct. |
2305 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to | 2312 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to |
2306 // "YieldExpression", which is its only use. | 2313 // "YieldExpression", which is its only use. |
2307 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); | 2314 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); |
2308 | 2315 |
2309 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); | 2316 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); |
2310 Scope* scope = this->NewScope(this->scope(), FUNCTION_SCOPE, | 2317 Scope* scope = this->NewFunctionScope( |
2311 is_async ? FunctionKind::kAsyncArrowFunction | 2318 this->scope(), is_async ? FunctionKind::kAsyncArrowFunction |
2312 : FunctionKind::kArrowFunction); | 2319 : FunctionKind::kArrowFunction); |
2313 // Because the arrow's parameters were parsed in the outer scope, any | 2320 // Because the arrow's parameters were parsed in the outer scope, any |
2314 // usage flags that might have been triggered there need to be copied | 2321 // usage flags that might have been triggered there need to be copied |
2315 // to the arrow scope. | 2322 // to the arrow scope. |
2316 this->scope()->PropagateUsageFlagsToScope(scope); | 2323 this->scope()->PropagateUsageFlagsToScope(scope); |
2317 FormalParametersT parameters(scope); | 2324 FormalParametersT parameters(scope); |
2318 if (!arrow_formals_classifier.is_simple_parameter_list()) { | 2325 if (!arrow_formals_classifier.is_simple_parameter_list()) { |
2319 scope->SetHasNonSimpleParameters(); | 2326 scope->SetHasNonSimpleParameters(); |
2320 parameters.is_simple = false; | 2327 parameters.is_simple = false; |
2321 } | 2328 } |
2322 | 2329 |
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3677 has_seen_constructor_ = true; | 3684 has_seen_constructor_ = true; |
3678 return; | 3685 return; |
3679 } | 3686 } |
3680 } | 3687 } |
3681 | 3688 |
3682 | 3689 |
3683 } // namespace internal | 3690 } // namespace internal |
3684 } // namespace v8 | 3691 } // namespace v8 |
3685 | 3692 |
3686 #endif // V8_PARSING_PARSER_BASE_H | 3693 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |