| 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/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
| 9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
| 10 #include "src/globals.h" | 10 #include "src/globals.h" |
| 11 #include "src/objects.h" | 11 #include "src/objects.h" |
| 12 #include "src/zone/zone.h" | 12 #include "src/zone/zone.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 class AstNodeFactory; | 17 class AstNodeFactory; |
| 18 class AstValueFactory; | 18 class AstValueFactory; |
| 19 class AstRawString; | 19 class AstRawString; |
| 20 class Declaration; | 20 class Declaration; |
| 21 class ParseInfo; | 21 class ParseInfo; |
| 22 class PreParsedScopeData; |
| 22 class SloppyBlockFunctionStatement; | 23 class SloppyBlockFunctionStatement; |
| 23 class Statement; | 24 class Statement; |
| 24 class StringSet; | 25 class StringSet; |
| 25 class VariableProxy; | 26 class VariableProxy; |
| 26 | 27 |
| 27 // A hash map to support fast variable declaration and lookup. | 28 // A hash map to support fast variable declaration and lookup. |
| 28 class VariableMap: public ZoneHashMap { | 29 class VariableMap: public ZoneHashMap { |
| 29 public: | 30 public: |
| 30 explicit VariableMap(Zone* zone); | 31 explicit VariableMap(Zone* zone); |
| 31 | 32 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 void AllocateNonParameterLocal(Variable* var); | 579 void AllocateNonParameterLocal(Variable* var); |
| 579 void AllocateDeclaredGlobal(Variable* var); | 580 void AllocateDeclaredGlobal(Variable* var); |
| 580 void AllocateNonParameterLocalsAndDeclaredGlobals(); | 581 void AllocateNonParameterLocalsAndDeclaredGlobals(); |
| 581 void AllocateVariablesRecursively(); | 582 void AllocateVariablesRecursively(); |
| 582 | 583 |
| 583 void AllocateScopeInfosRecursively(Isolate* isolate, | 584 void AllocateScopeInfosRecursively(Isolate* isolate, |
| 584 MaybeHandle<ScopeInfo> outer_scope); | 585 MaybeHandle<ScopeInfo> outer_scope); |
| 585 void AllocateDebuggerScopeInfos(Isolate* isolate, | 586 void AllocateDebuggerScopeInfos(Isolate* isolate, |
| 586 MaybeHandle<ScopeInfo> outer_scope); | 587 MaybeHandle<ScopeInfo> outer_scope); |
| 587 | 588 |
| 589 void CollectVariableData(PreParsedScopeData* data); |
| 590 |
| 588 // Construct a scope based on the scope info. | 591 // Construct a scope based on the scope info. |
| 589 Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info); | 592 Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info); |
| 590 | 593 |
| 591 // Construct a catch scope with a binding for the name. | 594 // Construct a catch scope with a binding for the name. |
| 592 Scope(Zone* zone, const AstRawString* catch_variable_name, | 595 Scope(Zone* zone, const AstRawString* catch_variable_name, |
| 593 Handle<ScopeInfo> scope_info); | 596 Handle<ScopeInfo> scope_info); |
| 594 | 597 |
| 595 void AddInnerScope(Scope* inner_scope) { | 598 void AddInnerScope(Scope* inner_scope) { |
| 596 inner_scope->sibling_ = inner_scope_; | 599 inner_scope->sibling_ = inner_scope_; |
| 597 inner_scope_ = inner_scope; | 600 inner_scope_ = inner_scope; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 // Compute top scope and allocate variables. For lazy compilation the top | 784 // Compute top scope and allocate variables. For lazy compilation the top |
| 782 // scope only contains the single lazily compiled function, so this | 785 // scope only contains the single lazily compiled function, so this |
| 783 // doesn't re-allocate variables repeatedly. | 786 // doesn't re-allocate variables repeatedly. |
| 784 static void Analyze(ParseInfo* info, AnalyzeMode mode); | 787 static void Analyze(ParseInfo* info, AnalyzeMode mode); |
| 785 | 788 |
| 786 // To be called during parsing. Do just enough scope analysis that we can | 789 // To be called during parsing. Do just enough scope analysis that we can |
| 787 // discard the Scope for lazily compiled functions. In particular, this | 790 // discard the Scope for lazily compiled functions. In particular, this |
| 788 // records variables which cannot be resolved inside the Scope (we don't yet | 791 // records variables which cannot be resolved inside the Scope (we don't yet |
| 789 // know what they will resolve to since the outer Scopes are incomplete) and | 792 // know what they will resolve to since the outer Scopes are incomplete) and |
| 790 // migrates them into migrate_to. | 793 // migrates them into migrate_to. |
| 791 void AnalyzePartially(AstNodeFactory* ast_node_factory); | 794 void AnalyzePartially(AstNodeFactory* ast_node_factory, |
| 795 PreParsedScopeData* preparsed_scope_data); |
| 792 | 796 |
| 793 Handle<StringSet> CollectNonLocals(ParseInfo* info, | 797 Handle<StringSet> CollectNonLocals(ParseInfo* info, |
| 794 Handle<StringSet> non_locals); | 798 Handle<StringSet> non_locals); |
| 795 | 799 |
| 796 // Determine if we can use lazy compilation for this scope. | 800 // Determine if we can use lazy compilation for this scope. |
| 797 bool AllowsLazyCompilation() const; | 801 bool AllowsLazyCompilation() const; |
| 798 | 802 |
| 799 // Make sure this closure and all outer closures are eagerly compiled. | 803 // Make sure this closure and all outer closures are eagerly compiled. |
| 800 void ForceEagerCompilation() { | 804 void ForceEagerCompilation() { |
| 801 DCHECK_EQ(this, GetClosureScope()); | 805 DCHECK_EQ(this, GetClosureScope()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 void AllocateModuleVariables(); | 896 void AllocateModuleVariables(); |
| 893 | 897 |
| 894 private: | 898 private: |
| 895 ModuleDescriptor* module_descriptor_; | 899 ModuleDescriptor* module_descriptor_; |
| 896 }; | 900 }; |
| 897 | 901 |
| 898 } // namespace internal | 902 } // namespace internal |
| 899 } // namespace v8 | 903 } // namespace v8 |
| 900 | 904 |
| 901 #endif // V8_AST_SCOPES_H_ | 905 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |