| 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" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 class Snapshot final BASE_EMBEDDED { | 89 class Snapshot final BASE_EMBEDDED { |
| 90 public: | 90 public: |
| 91 explicit Snapshot(Scope* scope); | 91 explicit Snapshot(Scope* scope); |
| 92 | 92 |
| 93 void Reparent(DeclarationScope* new_parent) const; | 93 void Reparent(DeclarationScope* new_parent) const; |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 Scope* outer_scope_; | 96 Scope* outer_scope_; |
| 97 Scope* top_inner_scope_; | 97 Scope* top_inner_scope_; |
| 98 VariableProxy* top_unresolved_; | 98 VariableProxy* top_unresolved_; |
| 99 int top_local_; | 99 ThreadedList<Variable>::Iterator top_local_; |
| 100 ThreadedList<Declaration>::Iterator top_decl_; | 100 ThreadedList<Declaration>::Iterator top_decl_; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 enum class DeserializationMode { kIncludingVariables, kScopesOnly }; | 103 enum class DeserializationMode { kIncludingVariables, kScopesOnly }; |
| 104 | 104 |
| 105 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, | 105 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, |
| 106 ScopeInfo* scope_info, | 106 ScopeInfo* scope_info, |
| 107 DeclarationScope* script_scope, | 107 DeclarationScope* script_scope, |
| 108 AstValueFactory* ast_value_factory, | 108 AstValueFactory* ast_value_factory, |
| 109 DeserializationMode deserialization_mode); | 109 DeserializationMode deserialization_mode); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 Variable* DeclareVariable(Declaration* declaration, VariableMode mode, | 149 Variable* DeclareVariable(Declaration* declaration, VariableMode mode, |
| 150 InitializationFlag init, | 150 InitializationFlag init, |
| 151 bool allow_harmony_restrictive_generators, | 151 bool allow_harmony_restrictive_generators, |
| 152 bool* sloppy_mode_block_scope_function_redefinition, | 152 bool* sloppy_mode_block_scope_function_redefinition, |
| 153 bool* ok); | 153 bool* ok); |
| 154 | 154 |
| 155 // Declarations list. | 155 // Declarations list. |
| 156 ThreadedList<Declaration>* declarations() { return &decls_; } | 156 ThreadedList<Declaration>* declarations() { return &decls_; } |
| 157 | 157 |
| 158 ZoneList<Variable*>* locals() { return &locals_; } | 158 ThreadedList<Variable>* locals() { return &locals_; } |
| 159 | 159 |
| 160 // Create a new unresolved variable. | 160 // Create a new unresolved variable. |
| 161 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 161 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 162 const AstRawString* name, | 162 const AstRawString* name, |
| 163 int start_position = kNoSourcePosition, | 163 int start_position = kNoSourcePosition, |
| 164 VariableKind kind = NORMAL_VARIABLE); | 164 VariableKind kind = NORMAL_VARIABLE); |
| 165 | 165 |
| 166 void AddUnresolved(VariableProxy* proxy); | 166 void AddUnresolved(VariableProxy* proxy); |
| 167 | 167 |
| 168 // Remove a unresolved variable. During parsing, an unresolved variable | 168 // Remove a unresolved variable. During parsing, an unresolved variable |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 explicit Scope(Zone* zone); | 422 explicit Scope(Zone* zone); |
| 423 | 423 |
| 424 void set_language_mode(LanguageMode language_mode) { | 424 void set_language_mode(LanguageMode language_mode) { |
| 425 is_strict_ = is_strict(language_mode); | 425 is_strict_ = is_strict(language_mode); |
| 426 } | 426 } |
| 427 | 427 |
| 428 private: | 428 private: |
| 429 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 429 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
| 430 VariableMode mode, VariableKind kind, | 430 VariableMode mode, VariableKind kind, |
| 431 InitializationFlag initialization_flag, | 431 InitializationFlag initialization_flag, |
| 432 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { | 432 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 433 bool added; | |
| 434 Variable* var = | |
| 435 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, | |
| 436 maybe_assigned_flag, &added); | |
| 437 if (added) locals_.Add(var, zone); | |
| 438 return var; | |
| 439 } | |
| 440 | 433 |
| 441 // This method should only be invoked on scopes created during parsing (i.e., | 434 // This method should only be invoked on scopes created during parsing (i.e., |
| 442 // not deserialized from a context). Also, since NeedsContext() is only | 435 // not deserialized from a context). Also, since NeedsContext() is only |
| 443 // returning a valid result after variables are resolved, NeedsScopeInfo() | 436 // returning a valid result after variables are resolved, NeedsScopeInfo() |
| 444 // should also be invoked after resolution. | 437 // should also be invoked after resolution. |
| 445 bool NeedsScopeInfo() const; | 438 bool NeedsScopeInfo() const; |
| 446 | 439 |
| 447 Zone* zone_; | 440 Zone* zone_; |
| 448 | 441 |
| 449 // Scope tree. | 442 // Scope tree. |
| 450 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 443 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 451 Scope* inner_scope_; // an inner scope of this scope | 444 Scope* inner_scope_; // an inner scope of this scope |
| 452 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. | 445 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. |
| 453 | 446 |
| 454 // The variables declared in this scope: | 447 // The variables declared in this scope: |
| 455 // | 448 // |
| 456 // All user-declared variables (incl. parameters). For script scopes | 449 // All user-declared variables (incl. parameters). For script scopes |
| 457 // variables may be implicitly 'declared' by being used (possibly in | 450 // variables may be implicitly 'declared' by being used (possibly in |
| 458 // an inner scope) with no intervening with statements or eval calls. | 451 // an inner scope) with no intervening with statements or eval calls. |
| 459 VariableMap variables_; | 452 VariableMap variables_; |
| 460 // In case of non-scopeinfo-backed scopes, this contains the variables of the | 453 // In case of non-scopeinfo-backed scopes, this contains the variables of the |
| 461 // map above in order of addition. | 454 // map above in order of addition. |
| 462 // TODO(verwaest): Thread through Variable. | 455 ThreadedList<Variable> locals_; |
| 463 ZoneList<Variable*> locals_; | |
| 464 // Unresolved variables referred to from this scope. The proxies themselves | 456 // Unresolved variables referred to from this scope. The proxies themselves |
| 465 // form a linked list of all unresolved proxies. | 457 // form a linked list of all unresolved proxies. |
| 466 VariableProxy* unresolved_; | 458 VariableProxy* unresolved_; |
| 467 // Declarations. | 459 // Declarations. |
| 468 ThreadedList<Declaration> decls_; | 460 ThreadedList<Declaration> decls_; |
| 469 | 461 |
| 470 // Serialized scope info support. | 462 // Serialized scope info support. |
| 471 Handle<ScopeInfo> scope_info_; | 463 Handle<ScopeInfo> scope_info_; |
| 472 // Debugging support. | 464 // Debugging support. |
| 473 #ifdef DEBUG | 465 #ifdef DEBUG |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 DCHECK(this_function_ == nullptr || | 722 DCHECK(this_function_ == nullptr || |
| 731 (is_function_scope() && (IsClassConstructor(function_kind()) || | 723 (is_function_scope() && (IsClassConstructor(function_kind()) || |
| 732 IsConciseMethod(function_kind()) || | 724 IsConciseMethod(function_kind()) || |
| 733 IsAccessorFunction(function_kind())))); | 725 IsAccessorFunction(function_kind())))); |
| 734 return this_function_; | 726 return this_function_; |
| 735 } | 727 } |
| 736 | 728 |
| 737 // Adds a local variable in this scope's locals list. This is for adjusting | 729 // Adds a local variable in this scope's locals list. This is for adjusting |
| 738 // the scope of temporaries and do-expression vars when desugaring parameter | 730 // the scope of temporaries and do-expression vars when desugaring parameter |
| 739 // initializers. | 731 // initializers. |
| 740 void AddLocal(Variable* var) { | 732 void AddLocal(Variable* var); |
| 741 DCHECK(!already_resolved_); | |
| 742 // Temporaries are only placed in ClosureScopes. | |
| 743 DCHECK_EQ(GetClosureScope(), this); | |
| 744 locals_.Add(var, zone()); | |
| 745 } | |
| 746 | 733 |
| 747 void DeclareSloppyBlockFunction(const AstRawString* name, | 734 void DeclareSloppyBlockFunction(const AstRawString* name, |
| 748 SloppyBlockFunctionStatement* statement) { | 735 SloppyBlockFunctionStatement* statement) { |
| 749 sloppy_block_function_map_.Declare(zone(), name, statement); | 736 sloppy_block_function_map_.Declare(zone(), name, statement); |
| 750 } | 737 } |
| 751 | 738 |
| 752 // Go through sloppy_block_function_map_ and hoist those (into this scope) | 739 // Go through sloppy_block_function_map_ and hoist those (into this scope) |
| 753 // which should be hoisted. | 740 // which should be hoisted. |
| 754 void HoistSloppyBlockFunctions(AstNodeFactory* factory); | 741 void HoistSloppyBlockFunctions(AstNodeFactory* factory); |
| 755 | 742 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 void AllocateModuleVariables(); | 854 void AllocateModuleVariables(); |
| 868 | 855 |
| 869 private: | 856 private: |
| 870 ModuleDescriptor* module_descriptor_; | 857 ModuleDescriptor* module_descriptor_; |
| 871 }; | 858 }; |
| 872 | 859 |
| 873 } // namespace internal | 860 } // namespace internal |
| 874 } // namespace v8 | 861 } // namespace v8 |
| 875 | 862 |
| 876 #endif // V8_AST_SCOPES_H_ | 863 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |