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

Side by Side Diff: src/variables.h

Issue 1218783005: Support for global var shortcuts in script contexts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixing builds Created 5 years, 5 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/typing.cc ('k') | src/variables.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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_VARIABLES_H_ 5 #ifndef V8_VARIABLES_H_
6 #define V8_VARIABLES_H_ 6 #define V8_VARIABLES_H_
7 7
8 #include "src/ast-value-factory.h" 8 #include "src/ast-value-factory.h"
9 #include "src/zone.h" 9 #include "src/zone.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 13
14 // The AST refers to variables via VariableProxies - placeholders for the actual 14 // The AST refers to variables via VariableProxies - placeholders for the actual
15 // variables. Variables themselves are never directly referred to from the AST, 15 // variables. Variables themselves are never directly referred to from the AST,
16 // they are maintained by scopes, and referred to from VariableProxies and Slots 16 // they are maintained by scopes, and referred to from VariableProxies and Slots
17 // after binding and variable allocation. 17 // after binding and variable allocation.
18 18
19 class ClassVariable; 19 class ClassVariable;
20 20
21 class Variable: public ZoneObject { 21 class Variable: public ZoneObject {
22 public: 22 public:
23 enum Kind { NORMAL, FUNCTION, CLASS, THIS, ARGUMENTS }; 23 enum Kind { NORMAL, FUNCTION, CLASS, THIS, ARGUMENTS };
24 24
25 enum Location {
26 // Before and during variable allocation, a variable whose location is
27 // not yet determined. After allocation, a variable looked up as a
28 // property on the global object (and possibly absent). name() is the
29 // variable name, index() is invalid.
30 UNALLOCATED,
31
32 // A slot in the parameter section on the stack. index() is the
33 // parameter index, counting left-to-right. The receiver is index -1;
34 // the first parameter is index 0.
35 PARAMETER,
36
37 // A slot in the local section on the stack. index() is the variable
38 // index in the stack frame, starting at 0.
39 LOCAL,
40
41 // An indexed slot in a heap context. index() is the variable index in
42 // the context object on the heap, starting at 0. scope() is the
43 // corresponding scope.
44 CONTEXT,
45
46 // A named slot in a heap context. name() is the variable name in the
47 // context object on the heap, with lookup starting at the current
48 // context. index() is invalid.
49 LOOKUP
50 };
51
52 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, 25 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind,
53 InitializationFlag initialization_flag, 26 InitializationFlag initialization_flag,
54 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 27 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
55 28
56 virtual ~Variable() {} 29 virtual ~Variable() {}
57 30
58 // Printing support 31 // Printing support
59 static const char* Mode2String(VariableMode mode); 32 static const char* Mode2String(VariableMode mode);
60 33
61 // The source code for an eval() call may refer to a variable that is 34 // The source code for an eval() call may refer to a variable that is
(...skipping 17 matching lines...) Expand all
79 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; } 52 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; }
80 void set_maybe_assigned() { maybe_assigned_ = kMaybeAssigned; } 53 void set_maybe_assigned() { maybe_assigned_ = kMaybeAssigned; }
81 54
82 int initializer_position() { return initializer_position_; } 55 int initializer_position() { return initializer_position_; }
83 void set_initializer_position(int pos) { initializer_position_ = pos; } 56 void set_initializer_position(int pos) { initializer_position_ = pos; }
84 57
85 bool IsVariable(Handle<String> n) const { 58 bool IsVariable(Handle<String> n) const {
86 return !is_this() && name().is_identical_to(n); 59 return !is_this() && name().is_identical_to(n);
87 } 60 }
88 61
89 bool IsUnallocated() const { return location_ == UNALLOCATED; } 62 bool IsUnallocated() const {
90 bool IsParameter() const { return location_ == PARAMETER; } 63 return location_ == VariableLocation::UNALLOCATED;
91 bool IsStackLocal() const { return location_ == LOCAL; } 64 }
65 bool IsParameter() const { return location_ == VariableLocation::PARAMETER; }
66 bool IsStackLocal() const { return location_ == VariableLocation::LOCAL; }
92 bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); } 67 bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); }
93 bool IsContextSlot() const { return location_ == CONTEXT; } 68 bool IsContextSlot() const { return location_ == VariableLocation::CONTEXT; }
94 bool IsLookupSlot() const { return location_ == LOOKUP; } 69 bool IsGlobalSlot() const { return location_ == VariableLocation::GLOBAL; }
70 bool IsUnallocatedOrGlobalSlot() const {
71 return IsUnallocated() || IsGlobalSlot();
72 }
73 bool IsLookupSlot() const { return location_ == VariableLocation::LOOKUP; }
95 bool IsGlobalObjectProperty() const; 74 bool IsGlobalObjectProperty() const;
75 bool IsStaticGlobalObjectProperty() const;
96 76
97 bool is_dynamic() const { return IsDynamicVariableMode(mode_); } 77 bool is_dynamic() const { return IsDynamicVariableMode(mode_); }
98 bool is_const_mode() const { return IsImmutableVariableMode(mode_); } 78 bool is_const_mode() const { return IsImmutableVariableMode(mode_); }
99 bool binding_needs_init() const { 79 bool binding_needs_init() const {
100 return initialization_flag_ == kNeedsInitialization; 80 return initialization_flag_ == kNeedsInitialization;
101 } 81 }
102 82
103 bool is_function() const { return kind_ == FUNCTION; } 83 bool is_function() const { return kind_ == FUNCTION; }
104 bool is_class() const { return kind_ == CLASS; } 84 bool is_class() const { return kind_ == CLASS; }
105 bool is_this() const { return kind_ == THIS; } 85 bool is_this() const { return kind_ == THIS; }
(...skipping 21 matching lines...) Expand all
127 107
128 Variable* local_if_not_shadowed() const { 108 Variable* local_if_not_shadowed() const {
129 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); 109 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL);
130 return local_if_not_shadowed_; 110 return local_if_not_shadowed_;
131 } 111 }
132 112
133 void set_local_if_not_shadowed(Variable* local) { 113 void set_local_if_not_shadowed(Variable* local) {
134 local_if_not_shadowed_ = local; 114 local_if_not_shadowed_ = local;
135 } 115 }
136 116
137 Location location() const { return location_; } 117 VariableLocation location() const { return location_; }
138 int index() const { return index_; } 118 int index() const { return index_; }
139 InitializationFlag initialization_flag() const { 119 InitializationFlag initialization_flag() const {
140 return initialization_flag_; 120 return initialization_flag_;
141 } 121 }
142 122
143 void AllocateTo(Location location, int index) { 123 void AllocateTo(VariableLocation location, int index) {
144 location_ = location; 124 location_ = location;
145 index_ = index; 125 index_ = index;
146 } 126 }
147 127
148 static int CompareIndex(Variable* const* v, Variable* const* w); 128 static int CompareIndex(Variable* const* v, Variable* const* w);
149 129
150 void RecordStrongModeReference(int start_position, int end_position) { 130 void RecordStrongModeReference(int start_position, int end_position) {
151 // Record the earliest reference to the variable. Used in error messages for 131 // Record the earliest reference to the variable. Used in error messages for
152 // strong mode references to undeclared variables. 132 // strong mode references to undeclared variables.
153 if (has_strong_mode_reference_ && 133 if (has_strong_mode_reference_ &&
(...skipping 10 matching lines...) Expand all
164 } 144 }
165 int strong_mode_reference_end_position() const { 145 int strong_mode_reference_end_position() const {
166 return strong_mode_reference_end_position_; 146 return strong_mode_reference_end_position_;
167 } 147 }
168 148
169 private: 149 private:
170 Scope* scope_; 150 Scope* scope_;
171 const AstRawString* name_; 151 const AstRawString* name_;
172 VariableMode mode_; 152 VariableMode mode_;
173 Kind kind_; 153 Kind kind_;
174 Location location_; 154 VariableLocation location_;
175 int index_; 155 int index_;
176 int initializer_position_; 156 int initializer_position_;
177 // Tracks whether the variable is bound to a VariableProxy which is in strong 157 // Tracks whether the variable is bound to a VariableProxy which is in strong
178 // mode, and if yes, the source location of the reference. 158 // mode, and if yes, the source location of the reference.
179 bool has_strong_mode_reference_; 159 bool has_strong_mode_reference_;
180 int strong_mode_reference_start_position_; 160 int strong_mode_reference_start_position_;
181 int strong_mode_reference_end_position_; 161 int strong_mode_reference_end_position_;
182 162
183 // If this field is set, this variable references the stored locally bound 163 // If this field is set, this variable references the stored locally bound
184 // variable, but it might be shadowed by variable bindings introduced by 164 // variable, but it might be shadowed by variable bindings introduced by
(...skipping 25 matching lines...) Expand all
210 190
211 private: 191 private:
212 // For classes we keep track of consecutive groups of delcarations. They are 192 // For classes we keep track of consecutive groups of delcarations. They are
213 // needed for strong mode scoping checks. TODO(marja, rossberg): Implement 193 // needed for strong mode scoping checks. TODO(marja, rossberg): Implement
214 // checks for functions too. 194 // checks for functions too.
215 int declaration_group_start_; 195 int declaration_group_start_;
216 }; 196 };
217 } } // namespace v8::internal 197 } } // namespace v8::internal
218 198
219 #endif // V8_VARIABLES_H_ 199 #endif // V8_VARIABLES_H_
OLDNEW
« no previous file with comments | « src/typing.cc ('k') | src/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698