| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // Create a new unresolved variable. | 194 // Create a new unresolved variable. |
| 195 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 195 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 196 const AstRawString* name, | 196 const AstRawString* name, |
| 197 Variable::Kind kind = Variable::NORMAL, | 197 Variable::Kind kind = Variable::NORMAL, |
| 198 int start_position = kNoSourcePosition, | 198 int start_position = kNoSourcePosition, |
| 199 int end_position = kNoSourcePosition) { | 199 int end_position = kNoSourcePosition) { |
| 200 // Note that we must not share the unresolved variables with | 200 // Note that we must not share the unresolved variables with |
| 201 // the same name because they may be removed selectively via | 201 // the same name because they may be removed selectively via |
| 202 // RemoveUnresolved(). | 202 // RemoveUnresolved(). |
| 203 DCHECK(!already_resolved()); | 203 DCHECK(!already_resolved()); |
| 204 DCHECK_EQ(factory->zone(), zone()); | |
| 205 VariableProxy* proxy = | 204 VariableProxy* proxy = |
| 206 factory->NewVariableProxy(name, kind, start_position, end_position); | 205 factory->NewVariableProxy(name, kind, start_position, end_position); |
| 207 proxy->set_next_unresolved(unresolved_); | 206 proxy->set_next_unresolved(unresolved_); |
| 208 unresolved_ = proxy; | 207 unresolved_ = proxy; |
| 209 return proxy; | 208 return proxy; |
| 210 } | 209 } |
| 211 | 210 |
| 212 void AddUnresolved(VariableProxy* proxy) { | 211 void AddUnresolved(VariableProxy* proxy) { |
| 213 DCHECK(!already_resolved()); | 212 DCHECK(!already_resolved()); |
| 214 DCHECK(!proxy->is_resolved()); | 213 DCHECK(!proxy->is_resolved()); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 // the assumptions explained above do not hold. | 602 // the assumptions explained above do not hold. |
| 604 return params_.Contains(variables_.Lookup(name)); | 603 return params_.Contains(variables_.Lookup(name)); |
| 605 } | 604 } |
| 606 | 605 |
| 607 int num_var() const { return variables_.occupancy(); } | 606 int num_var() const { return variables_.occupancy(); } |
| 608 | 607 |
| 609 SloppyBlockFunctionMap* sloppy_block_function_map() { | 608 SloppyBlockFunctionMap* sloppy_block_function_map() { |
| 610 return &sloppy_block_function_map_; | 609 return &sloppy_block_function_map_; |
| 611 } | 610 } |
| 612 | 611 |
| 613 // To be called during parsing. Do just enough scope analysis that we can | |
| 614 // discard the Scope for lazily compiled functions. In particular, this | |
| 615 // records variables which cannot be resolved inside the Scope (we don't yet | |
| 616 // know what they will resolve to since the outer Scopes are incomplete) and | |
| 617 // migrates them into migrate_to. | |
| 618 void AnalyzePartially(Scope* migrate_to, AstNodeFactory* ast_node_factory); | |
| 619 | |
| 620 // --------------------------------------------------------------------------- | 612 // --------------------------------------------------------------------------- |
| 621 // Debugging. | 613 // Debugging. |
| 622 | 614 |
| 623 #ifdef DEBUG | 615 #ifdef DEBUG |
| 624 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively | 616 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively |
| 625 | 617 |
| 626 // Check that the scope has positions assigned. | 618 // Check that the scope has positions assigned. |
| 627 void CheckScopePositions(); | 619 void CheckScopePositions(); |
| 628 | |
| 629 // Check that all Scopes in the scope tree use the same Zone. | |
| 630 void CheckZones(); | |
| 631 #endif | 620 #endif |
| 632 | 621 |
| 633 // --------------------------------------------------------------------------- | 622 // --------------------------------------------------------------------------- |
| 634 // Implementation. | 623 // Implementation. |
| 635 private: | 624 private: |
| 636 // Scope tree. | 625 // Scope tree. |
| 637 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 626 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 638 Scope* inner_scope_; // an inner scope of this scope | 627 Scope* inner_scope_; // an inner scope of this scope |
| 639 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. | 628 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. |
| 640 | 629 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 // * A 'with' statement has been encountered and there is no variable | 770 // * A 'with' statement has been encountered and there is no variable |
| 782 // binding for the name between the variable reference and the 'with'. | 771 // binding for the name between the variable reference and the 'with'. |
| 783 // The variable potentially references a property of the 'with' object. | 772 // The variable potentially references a property of the 'with' object. |
| 784 // * The code is being executed as part of a call to 'eval' and the calling | 773 // * The code is being executed as part of a call to 'eval' and the calling |
| 785 // context chain contains either a variable binding for the name or it | 774 // context chain contains either a variable binding for the name or it |
| 786 // contains a 'with' context. | 775 // contains a 'with' context. |
| 787 DYNAMIC_LOOKUP | 776 DYNAMIC_LOOKUP |
| 788 }; | 777 }; |
| 789 | 778 |
| 790 // Lookup a variable reference given by name recursively starting with this | 779 // Lookup a variable reference given by name recursively starting with this |
| 791 // scope, but only until max_outer_scope (if not nullptr). If the code is | 780 // scope. If the code is executed because of a call to 'eval', the context |
| 792 // executed because of a call to 'eval', the context parameter should be set | 781 // parameter should be set to the calling context of 'eval'. |
| 793 // to the calling context of 'eval'. | |
| 794 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, | 782 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, |
| 795 AstNodeFactory* factory, | 783 AstNodeFactory* factory); |
| 796 Scope* max_outer_scope = nullptr); | |
| 797 MUST_USE_RESULT | 784 MUST_USE_RESULT |
| 798 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, | 785 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, |
| 799 AstNodeFactory* factory); | 786 AstNodeFactory* factory); |
| 800 MUST_USE_RESULT | 787 MUST_USE_RESULT |
| 801 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); | 788 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); |
| 802 | 789 |
| 803 // Tries to resolve local variables inside max_outer_scope; collects those | |
| 804 // which cannot be resolved. | |
| 805 void CollectUnresolvableLocals(VariableProxy** still_unresolved, | |
| 806 Scope* max_outer_scope); | |
| 807 | |
| 808 // Scope analysis. | 790 // Scope analysis. |
| 809 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); | 791 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); |
| 810 bool HasTrivialContext() const; | 792 bool HasTrivialContext() const; |
| 811 | 793 |
| 812 // Predicates. | 794 // Predicates. |
| 813 bool MustAllocate(Variable* var); | 795 bool MustAllocate(Variable* var); |
| 814 bool MustAllocateInContext(Variable* var); | 796 bool MustAllocateInContext(Variable* var); |
| 815 | 797 |
| 816 // Variable allocation. | 798 // Variable allocation. |
| 817 void AllocateStackSlot(Variable* var); | 799 void AllocateStackSlot(Variable* var); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 | 853 |
| 872 void SetDefaults(); | 854 void SetDefaults(); |
| 873 | 855 |
| 874 PendingCompilationErrorHandler pending_error_handler_; | 856 PendingCompilationErrorHandler pending_error_handler_; |
| 875 }; | 857 }; |
| 876 | 858 |
| 877 } // namespace internal | 859 } // namespace internal |
| 878 } // namespace v8 | 860 } // namespace v8 |
| 879 | 861 |
| 880 #endif // V8_AST_SCOPES_H_ | 862 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |