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_AST_SCOPES_H_ | 5 #ifndef V8_AST_SCOPES_H_ |
6 #define V8_AST_SCOPES_H_ | 6 #define V8_AST_SCOPES_H_ |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 void DeclareThis(AstValueFactory* ast_value_factory); | 109 void DeclareThis(AstValueFactory* ast_value_factory); |
110 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); | 110 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); |
111 | 111 |
112 // Checks if the block scope is redundant, i.e. it does not contain any | 112 // Checks if the block scope is redundant, i.e. it does not contain any |
113 // block scoped declarations. In that case it is removed from the scope | 113 // block scoped declarations. In that case it is removed from the scope |
114 // tree and its children are reparented. | 114 // tree and its children are reparented. |
115 Scope* FinalizeBlockScope(); | 115 Scope* FinalizeBlockScope(); |
116 | 116 |
117 // Inserts outer_scope into this scope's scope chain (and removes this | 117 // Inserts outer_scope into this scope's scope chain (and removes this |
118 // from the current outer_scope_'s inner_scopes_). | 118 // from the current outer_scope_'s inner scope list). |
119 // Assumes outer_scope_ is non-null. | 119 // Assumes outer_scope_ is non-null. |
120 void ReplaceOuterScope(Scope* outer_scope); | 120 void ReplaceOuterScope(Scope* outer_scope); |
121 | 121 |
122 // Propagates any eagerly-gathered scope usage flags (such as calls_eval()) | 122 // Propagates any eagerly-gathered scope usage flags (such as calls_eval()) |
123 // to the passed-in scope. | 123 // to the passed-in scope. |
124 void PropagateUsageFlagsToScope(Scope* other); | 124 void PropagateUsageFlagsToScope(Scope* other); |
125 | 125 |
126 Zone* zone() const { return variables_.zone(); } | 126 Zone* zone() const { return variables_.zone(); } |
127 | 127 |
128 // --------------------------------------------------------------------------- | 128 // --------------------------------------------------------------------------- |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 DCHECK(this_function_ == nullptr || | 486 DCHECK(this_function_ == nullptr || |
487 (is_function_scope() && (IsClassConstructor(function_kind()) || | 487 (is_function_scope() && (IsClassConstructor(function_kind()) || |
488 IsConciseMethod(function_kind()) || | 488 IsConciseMethod(function_kind()) || |
489 IsAccessorFunction(function_kind())))); | 489 IsAccessorFunction(function_kind())))); |
490 return this_function_; | 490 return this_function_; |
491 } | 491 } |
492 | 492 |
493 // Declarations list. | 493 // Declarations list. |
494 ZoneList<Declaration*>* declarations() { return &decls_; } | 494 ZoneList<Declaration*>* declarations() { return &decls_; } |
495 | 495 |
496 // Inner scope list. | 496 // inner_scope() and sibling() together implement the inner scope list of a |
497 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } | 497 // scope. Inner scope points to the an inner scope of the function, and |
| 498 // "sibling" points to a next inner scope of the outer scope of this scope. |
| 499 Scope* inner_scope() const { return inner_scope_; } |
| 500 Scope* sibling() const { return sibling_; } |
498 | 501 |
499 // The scope immediately surrounding this scope, or NULL. | 502 // The scope immediately surrounding this scope, or NULL. |
500 Scope* outer_scope() const { return outer_scope_; } | 503 Scope* outer_scope() const { return outer_scope_; } |
501 | 504 |
502 // The ModuleDescriptor for this scope; only for module scopes. | 505 // The ModuleDescriptor for this scope; only for module scopes. |
503 ModuleDescriptor* module() const { return module_descriptor_; } | 506 ModuleDescriptor* module() const { return module_descriptor_; } |
504 | 507 |
505 const AstRawString* catch_variable_name() const { | 508 const AstRawString* catch_variable_name() const { |
506 DCHECK(is_catch_scope()); | 509 DCHECK(is_catch_scope()); |
507 DCHECK(num_var() == 1); | 510 DCHECK(num_var() == 1); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 604 |
602 // Check that the scope has positions assigned. | 605 // Check that the scope has positions assigned. |
603 void CheckScopePositions(); | 606 void CheckScopePositions(); |
604 #endif | 607 #endif |
605 | 608 |
606 // --------------------------------------------------------------------------- | 609 // --------------------------------------------------------------------------- |
607 // Implementation. | 610 // Implementation. |
608 private: | 611 private: |
609 // Scope tree. | 612 // Scope tree. |
610 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 613 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
611 ZoneList<Scope*> inner_scopes_; // the immediately enclosed inner scopes | 614 Scope* inner_scope_; // an inner scope of this scope |
| 615 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. |
612 | 616 |
613 // The scope type. | 617 // The scope type. |
614 const ScopeType scope_type_; | 618 const ScopeType scope_type_; |
615 // If the scope is a function scope, this is the function kind. | 619 // If the scope is a function scope, this is the function kind. |
616 const FunctionKind function_kind_; | 620 const FunctionKind function_kind_; |
617 | 621 |
618 // Debugging support. | 622 // Debugging support. |
619 const AstRawString* scope_name_; | 623 const AstRawString* scope_name_; |
620 | 624 |
621 // The variables declared in this scope: | 625 // The variables declared in this scope: |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 | 810 |
807 // Construct a scope based on the scope info. | 811 // Construct a scope based on the scope info. |
808 Scope(Zone* zone, Scope* inner_scope, ScopeType type, | 812 Scope(Zone* zone, Scope* inner_scope, ScopeType type, |
809 Handle<ScopeInfo> scope_info); | 813 Handle<ScopeInfo> scope_info); |
810 | 814 |
811 // Construct a catch scope with a binding for the name. | 815 // Construct a catch scope with a binding for the name. |
812 Scope(Zone* zone, Scope* inner_scope, | 816 Scope(Zone* zone, Scope* inner_scope, |
813 const AstRawString* catch_variable_name); | 817 const AstRawString* catch_variable_name); |
814 | 818 |
815 void AddInnerScope(Scope* inner_scope) { | 819 void AddInnerScope(Scope* inner_scope) { |
816 if (inner_scope != NULL) { | 820 if (inner_scope != nullptr) { |
817 inner_scopes_.Add(inner_scope, zone()); | 821 inner_scope->sibling_ = inner_scope_; |
| 822 inner_scope_ = inner_scope; |
818 inner_scope->outer_scope_ = this; | 823 inner_scope->outer_scope_ = this; |
819 } | 824 } |
820 } | 825 } |
821 | 826 |
822 void RemoveInnerScope(Scope* inner_scope) { | 827 void RemoveInnerScope(Scope* inner_scope) { |
823 DCHECK_NOT_NULL(inner_scope); | 828 DCHECK_NOT_NULL(inner_scope); |
824 for (int i = 0; i < inner_scopes_.length(); i++) { | 829 if (inner_scope == inner_scope_) { |
825 if (inner_scopes_[i] == inner_scope) { | 830 inner_scope_ = inner_scope_->sibling_; |
826 inner_scopes_.Remove(i); | 831 return; |
827 break; | 832 } |
| 833 for (Scope* scope = inner_scope_; scope != nullptr; |
| 834 scope = scope->sibling_) { |
| 835 if (scope->sibling_ == inner_scope) { |
| 836 scope->sibling_ = scope->sibling_->sibling_; |
| 837 return; |
828 } | 838 } |
829 } | 839 } |
830 } | 840 } |
831 | 841 |
832 void SetDefaults(); | 842 void SetDefaults(); |
833 | 843 |
834 PendingCompilationErrorHandler pending_error_handler_; | 844 PendingCompilationErrorHandler pending_error_handler_; |
835 }; | 845 }; |
836 | 846 |
837 } // namespace internal | 847 } // namespace internal |
838 } // namespace v8 | 848 } // namespace v8 |
839 | 849 |
840 #endif // V8_AST_SCOPES_H_ | 850 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |