Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: src/ast/scopes.h

Issue 2193793002: Put Scopes into temporary Zone (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/ast.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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());
204 VariableProxy* proxy = 205 VariableProxy* proxy =
205 factory->NewVariableProxy(name, kind, start_position, end_position); 206 factory->NewVariableProxy(name, kind, start_position, end_position);
206 proxy->set_next_unresolved(unresolved_); 207 proxy->set_next_unresolved(unresolved_);
207 unresolved_ = proxy; 208 unresolved_ = proxy;
208 return proxy; 209 return proxy;
209 } 210 }
210 211
211 void AddUnresolved(VariableProxy* proxy) { 212 void AddUnresolved(VariableProxy* proxy) {
212 DCHECK(!already_resolved()); 213 DCHECK(!already_resolved());
213 DCHECK(!proxy->is_resolved()); 214 DCHECK(!proxy->is_resolved());
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 // the assumptions explained above do not hold. 603 // the assumptions explained above do not hold.
603 return params_.Contains(variables_.Lookup(name)); 604 return params_.Contains(variables_.Lookup(name));
604 } 605 }
605 606
606 int num_var() const { return variables_.occupancy(); } 607 int num_var() const { return variables_.occupancy(); }
607 608
608 SloppyBlockFunctionMap* sloppy_block_function_map() { 609 SloppyBlockFunctionMap* sloppy_block_function_map() {
609 return &sloppy_block_function_map_; 610 return &sloppy_block_function_map_;
610 } 611 }
611 612
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
612 // --------------------------------------------------------------------------- 620 // ---------------------------------------------------------------------------
613 // Debugging. 621 // Debugging.
614 622
615 #ifdef DEBUG 623 #ifdef DEBUG
616 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively 624 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively
617 625
618 // Check that the scope has positions assigned. 626 // Check that the scope has positions assigned.
619 void CheckScopePositions(); 627 void CheckScopePositions();
628
629 // Check that all Scopes in the scope tree use the same Zone.
630 void CheckZones();
620 #endif 631 #endif
621 632
622 // --------------------------------------------------------------------------- 633 // ---------------------------------------------------------------------------
623 // Implementation. 634 // Implementation.
624 private: 635 private:
625 // Scope tree. 636 // Scope tree.
626 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL 637 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
627 Scope* inner_scope_; // an inner scope of this scope 638 Scope* inner_scope_; // an inner scope of this scope
628 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. 639 Scope* sibling_; // a sibling inner scope of the outer scope of this scope.
629 640
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 // * A 'with' statement has been encountered and there is no variable 781 // * A 'with' statement has been encountered and there is no variable
771 // binding for the name between the variable reference and the 'with'. 782 // binding for the name between the variable reference and the 'with'.
772 // The variable potentially references a property of the 'with' object. 783 // The variable potentially references a property of the 'with' object.
773 // * The code is being executed as part of a call to 'eval' and the calling 784 // * The code is being executed as part of a call to 'eval' and the calling
774 // context chain contains either a variable binding for the name or it 785 // context chain contains either a variable binding for the name or it
775 // contains a 'with' context. 786 // contains a 'with' context.
776 DYNAMIC_LOOKUP 787 DYNAMIC_LOOKUP
777 }; 788 };
778 789
779 // Lookup a variable reference given by name recursively starting with this 790 // Lookup a variable reference given by name recursively starting with this
780 // scope. If the code is executed because of a call to 'eval', the context 791 // scope, but only until max_outer_scope (if not nullptr). If the code is
781 // parameter should be set to the calling context of 'eval'. 792 // executed because of a call to 'eval', the context parameter should be set
793 // to the calling context of 'eval'.
782 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, 794 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind,
783 AstNodeFactory* factory); 795 AstNodeFactory* factory,
796 Scope* max_outer_scope = nullptr);
784 MUST_USE_RESULT 797 MUST_USE_RESULT
785 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, 798 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy,
786 AstNodeFactory* factory); 799 AstNodeFactory* factory);
787 MUST_USE_RESULT 800 MUST_USE_RESULT
788 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); 801 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory);
789 802
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
790 // Scope analysis. 808 // Scope analysis.
791 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); 809 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
792 bool HasTrivialContext() const; 810 bool HasTrivialContext() const;
793 811
794 // Predicates. 812 // Predicates.
795 bool MustAllocate(Variable* var); 813 bool MustAllocate(Variable* var);
796 bool MustAllocateInContext(Variable* var); 814 bool MustAllocateInContext(Variable* var);
797 815
798 // Variable allocation. 816 // Variable allocation.
799 void AllocateStackSlot(Variable* var); 817 void AllocateStackSlot(Variable* var);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 871
854 void SetDefaults(); 872 void SetDefaults();
855 873
856 PendingCompilationErrorHandler pending_error_handler_; 874 PendingCompilationErrorHandler pending_error_handler_;
857 }; 875 };
858 876
859 } // namespace internal 877 } // namespace internal
860 } // namespace v8 878 } // namespace v8
861 879
862 #endif // V8_AST_SCOPES_H_ 880 #endif // V8_AST_SCOPES_H_
OLDNEW
« no previous file with comments | « src/ast/ast.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698