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

Side by Side Diff: src/variables.h

Issue 1060913005: [strong] Stricter check for referring to other classes inside methods. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: . Created 5 years, 8 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
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
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 CONTEXT, 42 CONTEXT,
43 43
44 // A named slot in a heap context. name() is the variable name in the 44 // A named slot in a heap context. name() is the variable name in the
45 // context object on the heap, with lookup starting at the current 45 // context object on the heap, with lookup starting at the current
46 // context. index() is invalid. 46 // context. index() is invalid.
47 LOOKUP 47 LOOKUP
48 }; 48 };
49 49
50 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, 50 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind,
51 InitializationFlag initialization_flag, 51 InitializationFlag initialization_flag,
52 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 52 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
53 int consecutive_declaration_group_start = -1);
53 54
54 // Printing support 55 // Printing support
55 static const char* Mode2String(VariableMode mode); 56 static const char* Mode2String(VariableMode mode);
56 57
57 // The source code for an eval() call may refer to a variable that is 58 // The source code for an eval() call may refer to a variable that is
58 // in an outer scope about which we don't know anything (it may not 59 // in an outer scope about which we don't know anything (it may not
59 // be the script scope). scope() is NULL in that case. Currently the 60 // be the script scope). scope() is NULL in that case. Currently the
60 // scope is only used to follow the context chain length. 61 // scope is only used to follow the context chain length.
61 Scope* scope() const { return scope_; } 62 Scope* scope() const { return scope_; }
62 63
63 Handle<String> name() const { return name_->string(); } 64 Handle<String> name() const { return name_->string(); }
64 const AstRawString* raw_name() const { return name_; } 65 const AstRawString* raw_name() const { return name_; }
65 VariableMode mode() const { return mode_; } 66 VariableMode mode() const { return mode_; }
66 bool has_forced_context_allocation() const { 67 bool has_forced_context_allocation() const {
67 return force_context_allocation_; 68 return force_context_allocation_;
68 } 69 }
69 void ForceContextAllocation() { 70 void ForceContextAllocation() {
70 DCHECK(mode_ != TEMPORARY); 71 DCHECK(mode_ != TEMPORARY);
71 force_context_allocation_ = true; 72 force_context_allocation_ = true;
72 } 73 }
73 bool is_used() { return is_used_; } 74 bool is_used() { return is_used_; }
74 void set_is_used() { is_used_ = true; } 75 void set_is_used() { is_used_ = true; }
75 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; } 76 MaybeAssignedFlag maybe_assigned() const { return maybe_assigned_; }
76 void set_maybe_assigned() { maybe_assigned_ = kMaybeAssigned; } 77 void set_maybe_assigned() { maybe_assigned_ = kMaybeAssigned; }
78 int consecutive_declaration_group_start() const {
79 return consecutive_declaration_group_start_;
80 }
77 81
78 int initializer_position() { return initializer_position_; } 82 int initializer_position() { return initializer_position_; }
79 void set_initializer_position(int pos) { initializer_position_ = pos; } 83 void set_initializer_position(int pos) { initializer_position_ = pos; }
80 84
81 bool IsVariable(Handle<String> n) const { 85 bool IsVariable(Handle<String> n) const {
82 return !is_this() && name().is_identical_to(n); 86 return !is_this() && name().is_identical_to(n);
83 } 87 }
84 88
85 bool IsUnallocated() const { return location_ == UNALLOCATED; } 89 bool IsUnallocated() const { return location_ == UNALLOCATED; }
86 bool IsParameter() const { return location_ == PARAMETER; } 90 bool IsParameter() const { return location_ == PARAMETER; }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 145 }
142 146
143 bool has_strong_mode_reference() const { return has_strong_mode_reference_; } 147 bool has_strong_mode_reference() const { return has_strong_mode_reference_; }
144 int strong_mode_reference_start_position() const { 148 int strong_mode_reference_start_position() const {
145 return strong_mode_reference_start_position_; 149 return strong_mode_reference_start_position_;
146 } 150 }
147 int strong_mode_reference_end_position() const { 151 int strong_mode_reference_end_position() const {
148 return strong_mode_reference_end_position_; 152 return strong_mode_reference_end_position_;
149 } 153 }
150 154
155 Variable* corresponding_outer_class_variable() const {
156 return corresponding_outer_class_variable_;
157 }
158 void set_corresponding_outer_class_variable(Variable* var) {
159 corresponding_outer_class_variable_ = var;
160 }
161
151 private: 162 private:
152 Scope* scope_; 163 Scope* scope_;
153 const AstRawString* name_; 164 const AstRawString* name_;
154 VariableMode mode_; 165 VariableMode mode_;
155 Kind kind_; 166 Kind kind_;
156 Location location_; 167 Location location_;
157 int index_; 168 int index_;
158 int initializer_position_; 169 int initializer_position_;
159 // Tracks whether the variable is bound to a VariableProxy which is in strong 170 // Tracks whether the variable is bound to a VariableProxy which is in strong
160 // mode, and if yes, the source location of the reference. 171 // mode, and if yes, the source location of the reference.
161 bool has_strong_mode_reference_; 172 bool has_strong_mode_reference_;
162 int strong_mode_reference_start_position_; 173 int strong_mode_reference_start_position_;
163 int strong_mode_reference_end_position_; 174 int strong_mode_reference_end_position_;
164 175
165 // If this field is set, this variable references the stored locally bound 176 // If this field is set, this variable references the stored locally bound
166 // variable, but it might be shadowed by variable bindings introduced by 177 // variable, but it might be shadowed by variable bindings introduced by
167 // sloppy 'eval' calls between the reference scope (inclusive) and the 178 // sloppy 'eval' calls between the reference scope (inclusive) and the
168 // binding scope (exclusive). 179 // binding scope (exclusive).
169 Variable* local_if_not_shadowed_; 180 Variable* local_if_not_shadowed_;
170 181
171 // Usage info. 182 // Usage info.
172 bool force_context_allocation_; // set by variable resolver 183 bool force_context_allocation_; // set by variable resolver
173 bool is_used_; 184 bool is_used_;
174 InitializationFlag initialization_flag_; 185 InitializationFlag initialization_flag_;
175 MaybeAssignedFlag maybe_assigned_; 186 MaybeAssignedFlag maybe_assigned_;
187
188 // For classes and functions we keep track of consecutive groups of class /
189 // function delcarations. They are needed for strong mode scoping
190 // checks. TODO(marja, rossberg): Implement checks for functions too.
191 int consecutive_declaration_group_start_;
192 // For classes.
193 Variable* corresponding_outer_class_variable_;
rossberg 2015/04/21 13:30:02 As discussed offline, maybe we want to introduce a
marja 2015/04/23 09:52:37 Done.
176 }; 194 };
177 195
178 196
179 } } // namespace v8::internal 197 } } // namespace v8::internal
180 198
181 #endif // V8_VARIABLES_H_ 199 #endif // V8_VARIABLES_H_
OLDNEW
« src/scopes.cc ('K') | « src/scopes.cc ('k') | src/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698