| 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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } | 599 } |
| 600 ~ParsingModeScope() { | 600 ~ParsingModeScope() { |
| 601 parser_->mode_ = old_mode_; | 601 parser_->mode_ = old_mode_; |
| 602 } | 602 } |
| 603 | 603 |
| 604 private: | 604 private: |
| 605 ParserBase* parser_; | 605 ParserBase* parser_; |
| 606 Mode old_mode_; | 606 Mode old_mode_; |
| 607 }; | 607 }; |
| 608 | 608 |
| 609 DeclarationScope* NewScriptScope() { | 609 DeclarationScope* NewScriptScope() const { |
| 610 return new (zone()) DeclarationScope(zone()); | 610 return new (zone()) DeclarationScope(zone()); |
| 611 } | 611 } |
| 612 | 612 |
| 613 DeclarationScope* NewVarblockScope() { | 613 DeclarationScope* NewVarblockScope() const { |
| 614 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); | 614 return new (zone()) DeclarationScope(zone(), scope(), BLOCK_SCOPE); |
| 615 } | 615 } |
| 616 | 616 |
| 617 ModuleScope* NewModuleScope(DeclarationScope* parent) { | 617 ModuleScope* NewModuleScope(DeclarationScope* parent) const { |
| 618 return new (zone()) ModuleScope(zone(), parent, ast_value_factory()); | 618 return new (zone()) ModuleScope(zone(), parent, ast_value_factory()); |
| 619 } | 619 } |
| 620 | 620 |
| 621 DeclarationScope* NewEvalScope(Scope* parent) { | 621 DeclarationScope* NewEvalScope(Scope* parent) const { |
| 622 return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE); | 622 return new (zone()) DeclarationScope(zone(), parent, EVAL_SCOPE); |
| 623 } | 623 } |
| 624 | 624 |
| 625 Scope* NewScope(ScopeType scope_type) { | 625 Scope* NewScope(ScopeType scope_type) const { |
| 626 return NewScopeWithParent(scope(), scope_type); | 626 return NewScopeWithParent(scope(), scope_type); |
| 627 } | 627 } |
| 628 | 628 |
| 629 // This constructor should only be used when absolutely necessary. Most scopes | 629 // This constructor should only be used when absolutely necessary. Most scopes |
| 630 // should automatically use scope() as parent, and be fine with | 630 // should automatically use scope() as parent, and be fine with |
| 631 // NewScope(ScopeType) above. | 631 // NewScope(ScopeType) above. |
| 632 Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type) { | 632 Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type) const { |
| 633 // Must always use the specific constructors for the blacklisted scope | 633 // Must always use the specific constructors for the blacklisted scope |
| 634 // types. | 634 // types. |
| 635 DCHECK_NE(FUNCTION_SCOPE, scope_type); | 635 DCHECK_NE(FUNCTION_SCOPE, scope_type); |
| 636 DCHECK_NE(SCRIPT_SCOPE, scope_type); | 636 DCHECK_NE(SCRIPT_SCOPE, scope_type); |
| 637 DCHECK_NE(MODULE_SCOPE, scope_type); | 637 DCHECK_NE(MODULE_SCOPE, scope_type); |
| 638 DCHECK_NOT_NULL(parent); | 638 DCHECK_NOT_NULL(parent); |
| 639 return new (zone()) Scope(zone(), parent, scope_type); | 639 return new (zone()) Scope(zone(), parent, scope_type); |
| 640 } | 640 } |
| 641 | 641 |
| 642 DeclarationScope* NewFunctionScope(FunctionKind kind) { | 642 DeclarationScope* NewFunctionScope(FunctionKind kind) const { |
| 643 DCHECK(ast_value_factory()); | 643 DCHECK(ast_value_factory()); |
| 644 DeclarationScope* result = | 644 DeclarationScope* result = |
| 645 new (zone()) DeclarationScope(zone(), scope(), FUNCTION_SCOPE, kind); | 645 new (zone()) DeclarationScope(zone(), scope(), FUNCTION_SCOPE, kind); |
| 646 // TODO(verwaest): Move into the DeclarationScope constructor. | 646 // TODO(verwaest): Move into the DeclarationScope constructor. |
| 647 if (!IsArrowFunction(kind)) { | 647 if (!IsArrowFunction(kind)) { |
| 648 result->DeclareThis(ast_value_factory()); | 648 result->DeclareThis(ast_value_factory()); |
| 649 result->DeclareDefaultFunctionVariables(ast_value_factory()); | 649 result->DeclareDefaultFunctionVariables(ast_value_factory()); |
| 650 } | 650 } |
| 651 return result; | 651 return result; |
| 652 } | 652 } |
| 653 | 653 |
| 654 Scanner* scanner() const { return scanner_; } | 654 Scanner* scanner() const { return scanner_; } |
| 655 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } | 655 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } |
| 656 int position() { return scanner_->location().beg_pos; } | 656 int position() const { return scanner_->location().beg_pos; } |
| 657 int peek_position() { return scanner_->peek_location().beg_pos; } | 657 int peek_position() const { return scanner_->peek_location().beg_pos; } |
| 658 bool stack_overflow() const { return stack_overflow_; } | 658 bool stack_overflow() const { return stack_overflow_; } |
| 659 void set_stack_overflow() { stack_overflow_ = true; } | 659 void set_stack_overflow() { stack_overflow_ = true; } |
| 660 Mode mode() const { return mode_; } | 660 Mode mode() const { return mode_; } |
| 661 Zone* zone() const { return zone_; } | 661 Zone* zone() const { return zone_; } |
| 662 | 662 |
| 663 INLINE(Token::Value peek()) { | 663 INLINE(Token::Value peek()) { |
| 664 if (stack_overflow_) return Token::ILLEGAL; | 664 if (stack_overflow_) return Token::ILLEGAL; |
| 665 return scanner()->peek(); | 665 return scanner()->peek(); |
| 666 } | 666 } |
| 667 | 667 |
| (...skipping 3033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3701 has_seen_constructor_ = true; | 3701 has_seen_constructor_ = true; |
| 3702 return; | 3702 return; |
| 3703 } | 3703 } |
| 3704 } | 3704 } |
| 3705 | 3705 |
| 3706 | 3706 |
| 3707 } // namespace internal | 3707 } // namespace internal |
| 3708 } // namespace v8 | 3708 } // namespace v8 |
| 3709 | 3709 |
| 3710 #endif // V8_PARSING_PARSER_BASE_H | 3710 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |