OLD | NEW |
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 Loading... |
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_batch_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_batch_start() const { |
| 79 return consecutive_declaration_batch_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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // variable, but it might be shadowed by variable bindings introduced by | 170 // variable, but it might be shadowed by variable bindings introduced by |
167 // sloppy 'eval' calls between the reference scope (inclusive) and the | 171 // sloppy 'eval' calls between the reference scope (inclusive) and the |
168 // binding scope (exclusive). | 172 // binding scope (exclusive). |
169 Variable* local_if_not_shadowed_; | 173 Variable* local_if_not_shadowed_; |
170 | 174 |
171 // Usage info. | 175 // Usage info. |
172 bool force_context_allocation_; // set by variable resolver | 176 bool force_context_allocation_; // set by variable resolver |
173 bool is_used_; | 177 bool is_used_; |
174 InitializationFlag initialization_flag_; | 178 InitializationFlag initialization_flag_; |
175 MaybeAssignedFlag maybe_assigned_; | 179 MaybeAssignedFlag maybe_assigned_; |
| 180 |
| 181 // For classes and functions we keep track of consecutive batches of class / |
| 182 // function delcarations. They are needed for strong mode scoping |
| 183 // checks. TODO(marja, rossberg): Implement checks for functions too. |
| 184 int consecutive_declaration_batch_start_; |
176 }; | 185 }; |
177 | 186 |
178 | 187 |
179 } } // namespace v8::internal | 188 } } // namespace v8::internal |
180 | 189 |
181 #endif // V8_VARIABLES_H_ | 190 #endif // V8_VARIABLES_H_ |
OLD | NEW |