| 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/base/hashmap.h" | 8 #include "src/base/hashmap.h" |
| 9 #include "src/globals.h" | 9 #include "src/globals.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void Reparent(DeclarationScope* new_parent) const; | 91 void Reparent(DeclarationScope* new_parent) const; |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 Scope* outer_scope_; | 94 Scope* outer_scope_; |
| 95 Scope* top_inner_scope_; | 95 Scope* top_inner_scope_; |
| 96 VariableProxy* top_unresolved_; | 96 VariableProxy* top_unresolved_; |
| 97 int top_local_; | 97 int top_local_; |
| 98 int top_decl_; | 98 int top_decl_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 enum class DeserializationMode { kDeserializeOffHeap, kKeepScopeInfo }; | 101 enum class DeserializationMode { kIncludingVariables, kScopesOnly }; |
| 102 | 102 |
| 103 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, | 103 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, |
| 104 Context* context, | 104 Context* context, |
| 105 DeclarationScope* script_scope, | 105 DeclarationScope* script_scope, |
| 106 AstValueFactory* ast_value_factory, | 106 AstValueFactory* ast_value_factory, |
| 107 DeserializationMode deserialization_mode); | 107 DeserializationMode deserialization_mode); |
| 108 | 108 |
| 109 // Checks if the block scope is redundant, i.e. it does not contain any | 109 // Checks if the block scope is redundant, i.e. it does not contain any |
| 110 // block scoped declarations. In that case it is removed from the scope | 110 // block scoped declarations. In that case it is removed from the scope |
| 111 // tree and its children are reparented. | 111 // tree and its children are reparented. |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 scope = scope->sibling_) { | 569 scope = scope->sibling_) { |
| 570 if (scope->sibling_ == inner_scope) { | 570 if (scope->sibling_ == inner_scope) { |
| 571 scope->sibling_ = scope->sibling_->sibling_; | 571 scope->sibling_ = scope->sibling_->sibling_; |
| 572 return; | 572 return; |
| 573 } | 573 } |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 | 576 |
| 577 void SetDefaults(); | 577 void SetDefaults(); |
| 578 | 578 |
| 579 void DeserializeScopeInfo(Isolate* isolate, | |
| 580 AstValueFactory* ast_value_factory); | |
| 581 | |
| 582 friend class DeclarationScope; | 579 friend class DeclarationScope; |
| 583 }; | 580 }; |
| 584 | 581 |
| 585 class DeclarationScope : public Scope { | 582 class DeclarationScope : public Scope { |
| 586 public: | 583 public: |
| 587 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 584 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
| 588 FunctionKind function_kind = kNormalFunction); | 585 FunctionKind function_kind = kNormalFunction); |
| 589 DeclarationScope(Zone* zone, ScopeType scope_type, | 586 DeclarationScope(Zone* zone, ScopeType scope_type, |
| 590 Handle<ScopeInfo> scope_info); | 587 Handle<ScopeInfo> scope_info); |
| 591 // Creates a script scope. | 588 // Creates a script scope. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 locals_.Add(var, zone()); | 738 locals_.Add(var, zone()); |
| 742 } | 739 } |
| 743 | 740 |
| 744 void DeclareSloppyBlockFunction(const AstRawString* name, | 741 void DeclareSloppyBlockFunction(const AstRawString* name, |
| 745 SloppyBlockFunctionStatement* statement) { | 742 SloppyBlockFunctionStatement* statement) { |
| 746 sloppy_block_function_map_.Declare(zone(), name, statement); | 743 sloppy_block_function_map_.Declare(zone(), name, statement); |
| 747 } | 744 } |
| 748 | 745 |
| 749 // Go through sloppy_block_function_map_ and hoist those (into this scope) | 746 // Go through sloppy_block_function_map_ and hoist those (into this scope) |
| 750 // which should be hoisted. | 747 // which should be hoisted. |
| 751 void HoistSloppyBlockFunctions(AstNodeFactory* factory, bool* ok); | 748 void HoistSloppyBlockFunctions(AstNodeFactory* factory); |
| 752 | 749 |
| 753 SloppyBlockFunctionMap* sloppy_block_function_map() { | 750 SloppyBlockFunctionMap* sloppy_block_function_map() { |
| 754 return &sloppy_block_function_map_; | 751 return &sloppy_block_function_map_; |
| 755 } | 752 } |
| 756 | 753 |
| 757 // Compute top scope and allocate variables. For lazy compilation the top | 754 // Compute top scope and allocate variables. For lazy compilation the top |
| 758 // scope only contains the single lazily compiled function, so this | 755 // scope only contains the single lazily compiled function, so this |
| 759 // doesn't re-allocate variables repeatedly. | 756 // doesn't re-allocate variables repeatedly. |
| 760 static void Analyze(ParseInfo* info, AnalyzeMode mode); | 757 static void Analyze(ParseInfo* info, AnalyzeMode mode); |
| 761 | 758 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 void AllocateModuleVariables(); | 856 void AllocateModuleVariables(); |
| 860 | 857 |
| 861 private: | 858 private: |
| 862 ModuleDescriptor* module_descriptor_; | 859 ModuleDescriptor* module_descriptor_; |
| 863 }; | 860 }; |
| 864 | 861 |
| 865 } // namespace internal | 862 } // namespace internal |
| 866 } // namespace v8 | 863 } // namespace v8 |
| 867 | 864 |
| 868 #endif // V8_AST_SCOPES_H_ | 865 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |