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

Side by Side Diff: src/scopes.h

Issue 679943004: Remove AstConstructionVisitor/AstNullVisitor (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/rewriter.cc ('k') | src/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_SCOPES_H_ 5 #ifndef V8_SCOPES_H_
6 #define V8_SCOPES_H_ 6 #define V8_SCOPES_H_
7 7
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/zone.h" 9 #include "src/zone.h"
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Declarations 101 // Declarations
102 102
103 // Lookup a variable in this scope. Returns the variable or NULL if not found. 103 // Lookup a variable in this scope. Returns the variable or NULL if not found.
104 Variable* LookupLocal(const AstRawString* name); 104 Variable* LookupLocal(const AstRawString* name);
105 105
106 // This lookup corresponds to a lookup in the "intermediate" scope sitting 106 // This lookup corresponds to a lookup in the "intermediate" scope sitting
107 // between this scope and the outer scope. (ECMA-262, 3rd., requires that 107 // between this scope and the outer scope. (ECMA-262, 3rd., requires that
108 // the name of named function literal is kept in an intermediate scope 108 // the name of named function literal is kept in an intermediate scope
109 // in between this scope and the next outer scope.) 109 // in between this scope and the next outer scope.)
110 Variable* LookupFunctionVar(const AstRawString* name, 110 Variable* LookupFunctionVar(const AstRawString* name,
111 AstNodeFactory<AstNullVisitor>* factory); 111 AstNodeFactory* factory);
112 112
113 // Lookup a variable in this scope or outer scopes. 113 // Lookup a variable in this scope or outer scopes.
114 // Returns the variable or NULL if not found. 114 // Returns the variable or NULL if not found.
115 Variable* Lookup(const AstRawString* name); 115 Variable* Lookup(const AstRawString* name);
116 116
117 // Declare the function variable for a function literal. This variable 117 // Declare the function variable for a function literal. This variable
118 // is in an intermediate scope between this function scope and the the 118 // is in an intermediate scope between this function scope and the the
119 // outer scope. Only possible for function scopes; at most one variable. 119 // outer scope. Only possible for function scopes; at most one variable.
120 void DeclareFunctionVar(VariableDeclaration* declaration) { 120 void DeclareFunctionVar(VariableDeclaration* declaration) {
121 DCHECK(is_function_scope()); 121 DCHECK(is_function_scope());
(...skipping 12 matching lines...) Expand all
134 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, 134 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
135 Interface* interface = Interface::NewValue()); 135 Interface* interface = Interface::NewValue());
136 136
137 // Declare an implicit global variable in this scope which must be a 137 // Declare an implicit global variable in this scope which must be a
138 // global scope. The variable was introduced (possibly from an inner 138 // global scope. The variable was introduced (possibly from an inner
139 // scope) by a reference to an unresolved variable with no intervening 139 // scope) by a reference to an unresolved variable with no intervening
140 // with statements or eval calls. 140 // with statements or eval calls.
141 Variable* DeclareDynamicGlobal(const AstRawString* name); 141 Variable* DeclareDynamicGlobal(const AstRawString* name);
142 142
143 // Create a new unresolved variable. 143 // Create a new unresolved variable.
144 template<class Visitor> 144 VariableProxy* NewUnresolved(AstNodeFactory* factory,
145 VariableProxy* NewUnresolved(AstNodeFactory<Visitor>* factory,
146 const AstRawString* name, 145 const AstRawString* name,
147 Interface* interface = Interface::NewValue(), 146 Interface* interface = Interface::NewValue(),
148 int position = RelocInfo::kNoPosition) { 147 int position = RelocInfo::kNoPosition) {
149 // Note that we must not share the unresolved variables with 148 // Note that we must not share the unresolved variables with
150 // the same name because they may be removed selectively via 149 // the same name because they may be removed selectively via
151 // RemoveUnresolved(). 150 // RemoveUnresolved().
152 DCHECK(!already_resolved()); 151 DCHECK(!already_resolved());
153 VariableProxy* proxy = 152 VariableProxy* proxy =
154 factory->NewVariableProxy(name, false, interface, position); 153 factory->NewVariableProxy(name, false, interface, position);
155 unresolved_.Add(proxy, zone_); 154 unresolved_.Add(proxy, zone_);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // The variable potentially references a property of the 'with' object. 574 // The variable potentially references a property of the 'with' object.
576 // * The code is being executed as part of a call to 'eval' and the calling 575 // * The code is being executed as part of a call to 'eval' and the calling
577 // context chain contains either a variable binding for the name or it 576 // context chain contains either a variable binding for the name or it
578 // contains a 'with' context. 577 // contains a 'with' context.
579 DYNAMIC_LOOKUP 578 DYNAMIC_LOOKUP
580 }; 579 };
581 580
582 // Lookup a variable reference given by name recursively starting with this 581 // Lookup a variable reference given by name recursively starting with this
583 // scope. If the code is executed because of a call to 'eval', the context 582 // scope. If the code is executed because of a call to 'eval', the context
584 // parameter should be set to the calling context of 'eval'. 583 // parameter should be set to the calling context of 'eval'.
585 Variable* LookupRecursive(VariableProxy* proxy, 584 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind,
586 BindingKind* binding_kind, 585 AstNodeFactory* factory);
587 AstNodeFactory<AstNullVisitor>* factory);
588 MUST_USE_RESULT 586 MUST_USE_RESULT
589 bool ResolveVariable(CompilationInfo* info, 587 bool ResolveVariable(CompilationInfo* info, VariableProxy* proxy,
590 VariableProxy* proxy, 588 AstNodeFactory* factory);
591 AstNodeFactory<AstNullVisitor>* factory);
592 MUST_USE_RESULT 589 MUST_USE_RESULT
593 bool ResolveVariablesRecursively(CompilationInfo* info, 590 bool ResolveVariablesRecursively(CompilationInfo* info,
594 AstNodeFactory<AstNullVisitor>* factory); 591 AstNodeFactory* factory);
595 592
596 // Scope analysis. 593 // Scope analysis.
597 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); 594 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval);
598 bool HasTrivialContext() const; 595 bool HasTrivialContext() const;
599 596
600 // Predicates. 597 // Predicates.
601 bool MustAllocate(Variable* var); 598 bool MustAllocate(Variable* var);
602 bool MustAllocateInContext(Variable* var); 599 bool MustAllocateInContext(Variable* var);
603 bool HasArgumentsParameter(); 600 bool HasArgumentsParameter();
604 601
605 // Variable allocation. 602 // Variable allocation.
606 void AllocateStackSlot(Variable* var); 603 void AllocateStackSlot(Variable* var);
607 void AllocateHeapSlot(Variable* var); 604 void AllocateHeapSlot(Variable* var);
608 void AllocateParameterLocals(); 605 void AllocateParameterLocals();
609 void AllocateNonParameterLocal(Variable* var); 606 void AllocateNonParameterLocal(Variable* var);
610 void AllocateNonParameterLocals(); 607 void AllocateNonParameterLocals();
611 void AllocateVariablesRecursively(); 608 void AllocateVariablesRecursively();
612 void AllocateModulesRecursively(Scope* host_scope); 609 void AllocateModulesRecursively(Scope* host_scope);
613 610
614 // Resolve and fill in the allocation information for all variables 611 // Resolve and fill in the allocation information for all variables
615 // in this scopes. Must be called *after* all scopes have been 612 // in this scopes. Must be called *after* all scopes have been
616 // processed (parsed) to ensure that unresolved variables can be 613 // processed (parsed) to ensure that unresolved variables can be
617 // resolved properly. 614 // resolved properly.
618 // 615 //
619 // In the case of code compiled and run using 'eval', the context 616 // In the case of code compiled and run using 'eval', the context
620 // parameter is the context in which eval was called. In all other 617 // parameter is the context in which eval was called. In all other
621 // cases the context parameter is an empty handle. 618 // cases the context parameter is an empty handle.
622 MUST_USE_RESULT 619 MUST_USE_RESULT
623 bool AllocateVariables(CompilationInfo* info, 620 bool AllocateVariables(CompilationInfo* info, AstNodeFactory* factory);
624 AstNodeFactory<AstNullVisitor>* factory);
625 621
626 private: 622 private:
627 // Construct a scope based on the scope info. 623 // Construct a scope based on the scope info.
628 Scope(Scope* inner_scope, ScopeType type, Handle<ScopeInfo> scope_info, 624 Scope(Scope* inner_scope, ScopeType type, Handle<ScopeInfo> scope_info,
629 AstValueFactory* value_factory, Zone* zone); 625 AstValueFactory* value_factory, Zone* zone);
630 626
631 // Construct a catch scope with a binding for the name. 627 // Construct a catch scope with a binding for the name.
632 Scope(Scope* inner_scope, 628 Scope(Scope* inner_scope,
633 const AstRawString* catch_variable_name, 629 const AstRawString* catch_variable_name,
634 AstValueFactory* value_factory, Zone* zone); 630 AstValueFactory* value_factory, Zone* zone);
635 631
636 void AddInnerScope(Scope* inner_scope) { 632 void AddInnerScope(Scope* inner_scope) {
637 if (inner_scope != NULL) { 633 if (inner_scope != NULL) {
638 inner_scopes_.Add(inner_scope, zone_); 634 inner_scopes_.Add(inner_scope, zone_);
639 inner_scope->outer_scope_ = this; 635 inner_scope->outer_scope_ = this;
640 } 636 }
641 } 637 }
642 638
643 void SetDefaults(ScopeType type, 639 void SetDefaults(ScopeType type,
644 Scope* outer_scope, 640 Scope* outer_scope,
645 Handle<ScopeInfo> scope_info); 641 Handle<ScopeInfo> scope_info);
646 642
647 AstValueFactory* ast_value_factory_; 643 AstValueFactory* ast_value_factory_;
648 Zone* zone_; 644 Zone* zone_;
649 }; 645 };
650 646
651 } } // namespace v8::internal 647 } } // namespace v8::internal
652 648
653 #endif // V8_SCOPES_H_ 649 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/rewriter.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698