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 16 matching lines...) Expand all Loading... |
27 class VariableMap: public ZoneHashMap { | 27 class VariableMap: public ZoneHashMap { |
28 public: | 28 public: |
29 explicit VariableMap(Zone* zone); | 29 explicit VariableMap(Zone* zone); |
30 | 30 |
31 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 31 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
32 VariableMode mode, VariableKind kind, | 32 VariableMode mode, VariableKind kind, |
33 InitializationFlag initialization_flag, | 33 InitializationFlag initialization_flag, |
34 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, | 34 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
35 bool* added = nullptr); | 35 bool* added = nullptr); |
36 | 36 |
| 37 // Records that "name" exists but doesn't create a Variable. Useful for |
| 38 // preparsing. |
| 39 void DeclareName(Zone* zone, const AstRawString* name); |
| 40 |
37 Variable* Lookup(const AstRawString* name); | 41 Variable* Lookup(const AstRawString* name); |
38 void Remove(Variable* var); | 42 void Remove(Variable* var); |
39 void Add(Zone* zone, Variable* var); | 43 void Add(Zone* zone, Variable* var); |
40 }; | 44 }; |
41 | 45 |
42 | 46 |
43 // Sloppy block-scoped function declarations to var-bind | 47 // Sloppy block-scoped function declarations to var-bind |
44 class SloppyBlockFunctionMap : public ZoneHashMap { | 48 class SloppyBlockFunctionMap : public ZoneHashMap { |
45 public: | 49 public: |
46 explicit SloppyBlockFunctionMap(Zone* zone); | 50 explicit SloppyBlockFunctionMap(Zone* zone); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 154 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
151 InitializationFlag init_flag, VariableKind kind, | 155 InitializationFlag init_flag, VariableKind kind, |
152 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 156 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
153 | 157 |
154 Variable* DeclareVariable(Declaration* declaration, VariableMode mode, | 158 Variable* DeclareVariable(Declaration* declaration, VariableMode mode, |
155 InitializationFlag init, | 159 InitializationFlag init, |
156 bool allow_harmony_restrictive_generators, | 160 bool allow_harmony_restrictive_generators, |
157 bool* sloppy_mode_block_scope_function_redefinition, | 161 bool* sloppy_mode_block_scope_function_redefinition, |
158 bool* ok); | 162 bool* ok); |
159 | 163 |
| 164 void DeclareVariableName(const AstRawString* name, VariableMode mode); |
| 165 |
160 // Declarations list. | 166 // Declarations list. |
161 ThreadedList<Declaration>* declarations() { return &decls_; } | 167 ThreadedList<Declaration>* declarations() { return &decls_; } |
162 | 168 |
163 ThreadedList<Variable>* locals() { return &locals_; } | 169 ThreadedList<Variable>* locals() { return &locals_; } |
164 | 170 |
165 // Create a new unresolved variable. | 171 // Create a new unresolved variable. |
166 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 172 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
167 const AstRawString* name, | 173 const AstRawString* name, |
168 int start_position = kNoSourcePosition, | 174 int start_position = kNoSourcePosition, |
169 VariableKind kind = NORMAL_VARIABLE); | 175 VariableKind kind = NORMAL_VARIABLE); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 // to the calling context of 'eval'. | 538 // to the calling context of 'eval'. |
533 Variable* LookupRecursive(VariableProxy* proxy, Scope* outer_scope_end); | 539 Variable* LookupRecursive(VariableProxy* proxy, Scope* outer_scope_end); |
534 void ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var); | 540 void ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var); |
535 void ResolveVariable(ParseInfo* info, VariableProxy* proxy); | 541 void ResolveVariable(ParseInfo* info, VariableProxy* proxy); |
536 void ResolveVariablesRecursively(ParseInfo* info); | 542 void ResolveVariablesRecursively(ParseInfo* info); |
537 | 543 |
538 // Finds free variables of this scope. This mutates the unresolved variables | 544 // Finds free variables of this scope. This mutates the unresolved variables |
539 // list along the way, so full resolution cannot be done afterwards. | 545 // list along the way, so full resolution cannot be done afterwards. |
540 // If a ParseInfo* is passed, non-free variables will be resolved. | 546 // If a ParseInfo* is passed, non-free variables will be resolved. |
541 VariableProxy* FetchFreeVariables(DeclarationScope* max_outer_scope, | 547 VariableProxy* FetchFreeVariables(DeclarationScope* max_outer_scope, |
542 bool try_to_resolve = true, | |
543 ParseInfo* info = nullptr, | 548 ParseInfo* info = nullptr, |
544 VariableProxy* stack = nullptr); | 549 VariableProxy* stack = nullptr); |
545 | 550 |
546 // Predicates. | 551 // Predicates. |
547 bool MustAllocate(Variable* var); | 552 bool MustAllocate(Variable* var); |
548 bool MustAllocateInContext(Variable* var); | 553 bool MustAllocateInContext(Variable* var); |
549 | 554 |
550 // Variable allocation. | 555 // Variable allocation. |
551 void AllocateStackSlot(Variable* var); | 556 void AllocateStackSlot(Variable* var); |
552 void AllocateHeapSlot(Variable* var); | 557 void AllocateHeapSlot(Variable* var); |
(...skipping 16 matching lines...) Expand all Loading... |
569 | 574 |
570 void AddInnerScope(Scope* inner_scope) { | 575 void AddInnerScope(Scope* inner_scope) { |
571 inner_scope->sibling_ = inner_scope_; | 576 inner_scope->sibling_ = inner_scope_; |
572 inner_scope_ = inner_scope; | 577 inner_scope_ = inner_scope; |
573 inner_scope->outer_scope_ = this; | 578 inner_scope->outer_scope_ = this; |
574 } | 579 } |
575 | 580 |
576 void SetDefaults(); | 581 void SetDefaults(); |
577 | 582 |
578 friend class DeclarationScope; | 583 friend class DeclarationScope; |
| 584 friend class ScopeTestHelper; |
579 }; | 585 }; |
580 | 586 |
581 class DeclarationScope : public Scope { | 587 class DeclarationScope : public Scope { |
582 public: | 588 public: |
583 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 589 DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
584 FunctionKind function_kind = kNormalFunction); | 590 FunctionKind function_kind = kNormalFunction); |
585 DeclarationScope(Zone* zone, ScopeType scope_type, | 591 DeclarationScope(Zone* zone, ScopeType scope_type, |
586 Handle<ScopeInfo> scope_info); | 592 Handle<ScopeInfo> scope_info); |
587 // Creates a script scope. | 593 // Creates a script scope. |
588 DeclarationScope(Zone* zone, AstValueFactory* ast_value_factory); | 594 DeclarationScope(Zone* zone, AstValueFactory* ast_value_factory); |
(...skipping 16 matching lines...) Expand all Loading... |
605 // Does this scope access "super" property (super.foo). | 611 // Does this scope access "super" property (super.foo). |
606 bool uses_super_property() const { return scope_uses_super_property_; } | 612 bool uses_super_property() const { return scope_uses_super_property_; } |
607 | 613 |
608 bool NeedsHomeObject() const { | 614 bool NeedsHomeObject() const { |
609 return scope_uses_super_property_ || | 615 return scope_uses_super_property_ || |
610 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || | 616 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || |
611 IsAccessorFunction(function_kind()) || | 617 IsAccessorFunction(function_kind()) || |
612 IsClassConstructor(function_kind()))); | 618 IsClassConstructor(function_kind()))); |
613 } | 619 } |
614 | 620 |
615 bool is_lazily_parsed() const { return is_lazily_parsed_; } | 621 bool was_lazily_parsed() const { return was_lazily_parsed_; } |
| 622 |
| 623 #ifdef DEBUG |
| 624 void set_is_being_lazily_parsed(bool is_being_lazily_parsed) { |
| 625 is_being_lazily_parsed_ = is_being_lazily_parsed; |
| 626 } |
| 627 bool is_being_lazily_parsed() const { return is_being_lazily_parsed_; } |
| 628 #endif |
| 629 |
616 bool ShouldEagerCompile() const; | 630 bool ShouldEagerCompile() const; |
617 void set_should_eager_compile(); | 631 void set_should_eager_compile(); |
618 | 632 |
619 void SetScriptScopeInfo(Handle<ScopeInfo> scope_info) { | 633 void SetScriptScopeInfo(Handle<ScopeInfo> scope_info) { |
620 DCHECK(is_script_scope()); | 634 DCHECK(is_script_scope()); |
621 DCHECK(scope_info_.is_null()); | 635 DCHECK(scope_info_.is_null()); |
622 scope_info_ = scope_info; | 636 scope_info_ = scope_info; |
623 } | 637 } |
624 | 638 |
625 bool asm_module() const { return asm_module_; } | 639 bool asm_module() const { return asm_module_; } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 // This scope's outer context is an asm module. | 822 // This scope's outer context is an asm module. |
809 bool asm_function_ : 1; | 823 bool asm_function_ : 1; |
810 bool force_eager_compilation_ : 1; | 824 bool force_eager_compilation_ : 1; |
811 // This function scope has a rest parameter. | 825 // This function scope has a rest parameter. |
812 bool has_rest_ : 1; | 826 bool has_rest_ : 1; |
813 // This scope has a parameter called "arguments". | 827 // This scope has a parameter called "arguments". |
814 bool has_arguments_parameter_ : 1; | 828 bool has_arguments_parameter_ : 1; |
815 // This scope uses "super" property ('super.foo'). | 829 // This scope uses "super" property ('super.foo'). |
816 bool scope_uses_super_property_ : 1; | 830 bool scope_uses_super_property_ : 1; |
817 bool should_eager_compile_ : 1; | 831 bool should_eager_compile_ : 1; |
818 bool is_lazily_parsed_ : 1; | 832 // Set to true after we have finished lazy parsing the scope. |
| 833 bool was_lazily_parsed_ : 1; |
| 834 #if DEBUG |
| 835 bool is_being_lazily_parsed_ : 1; |
| 836 #endif |
819 | 837 |
820 // Parameter list in source order. | 838 // Parameter list in source order. |
821 ZoneList<Variable*> params_; | 839 ZoneList<Variable*> params_; |
822 // Map of function names to lists of functions defined in sloppy blocks | 840 // Map of function names to lists of functions defined in sloppy blocks |
823 SloppyBlockFunctionMap sloppy_block_function_map_; | 841 SloppyBlockFunctionMap sloppy_block_function_map_; |
824 // Convenience variable. | 842 // Convenience variable. |
825 Variable* receiver_; | 843 Variable* receiver_; |
826 // Function variable, if any; function scopes only. | 844 // Function variable, if any; function scopes only. |
827 Variable* function_; | 845 Variable* function_; |
828 // new.target variable, function scopes only. | 846 // new.target variable, function scopes only. |
(...skipping 26 matching lines...) Expand all Loading... |
855 void AllocateModuleVariables(); | 873 void AllocateModuleVariables(); |
856 | 874 |
857 private: | 875 private: |
858 ModuleDescriptor* module_descriptor_; | 876 ModuleDescriptor* module_descriptor_; |
859 }; | 877 }; |
860 | 878 |
861 } // namespace internal | 879 } // namespace internal |
862 } // namespace v8 | 880 } // namespace v8 |
863 | 881 |
864 #endif // V8_AST_SCOPES_H_ | 882 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |