| 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 |
| 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; |
| 20 |
| 19 class Variable: public ZoneObject { | 21 class Variable: public ZoneObject { |
| 20 public: | 22 public: |
| 21 enum Kind { NORMAL, FUNCTION, CLASS, THIS, NEW_TARGET, ARGUMENTS }; | 23 enum Kind { NORMAL, FUNCTION, CLASS, THIS, NEW_TARGET, ARGUMENTS }; |
| 22 | 24 |
| 23 enum Location { | 25 enum Location { |
| 24 // Before and during variable allocation, a variable whose location is | 26 // Before and during variable allocation, a variable whose location is |
| 25 // not yet determined. After allocation, a variable looked up as a | 27 // not yet determined. After allocation, a variable looked up as a |
| 26 // property on the global object (and possibly absent). name() is the | 28 // property on the global object (and possibly absent). name() is the |
| 27 // variable name, index() is invalid. | 29 // variable name, index() is invalid. |
| 28 UNALLOCATED, | 30 UNALLOCATED, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 44 // A named slot in a heap context. name() is the variable name in the | 46 // 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 | 47 // context object on the heap, with lookup starting at the current |
| 46 // context. index() is invalid. | 48 // context. index() is invalid. |
| 47 LOOKUP | 49 LOOKUP |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, | 52 Variable(Scope* scope, const AstRawString* name, VariableMode mode, Kind kind, |
| 51 InitializationFlag initialization_flag, | 53 InitializationFlag initialization_flag, |
| 52 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 54 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 53 | 55 |
| 56 virtual ~Variable() {} |
| 57 |
| 54 // Printing support | 58 // Printing support |
| 55 static const char* Mode2String(VariableMode mode); | 59 static const char* Mode2String(VariableMode mode); |
| 56 | 60 |
| 57 // The source code for an eval() call may refer to a variable that is | 61 // 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 | 62 // 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 | 63 // be the script scope). scope() is NULL in that case. Currently the |
| 60 // scope is only used to follow the context chain length. | 64 // scope is only used to follow the context chain length. |
| 61 Scope* scope() const { return scope_; } | 65 Scope* scope() const { return scope_; } |
| 62 | 66 |
| 63 Handle<String> name() const { return name_->string(); } | 67 Handle<String> name() const { return name_->string(); } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 bool binding_needs_init() const { | 99 bool binding_needs_init() const { |
| 96 return initialization_flag_ == kNeedsInitialization; | 100 return initialization_flag_ == kNeedsInitialization; |
| 97 } | 101 } |
| 98 | 102 |
| 99 bool is_function() const { return kind_ == FUNCTION; } | 103 bool is_function() const { return kind_ == FUNCTION; } |
| 100 bool is_class() const { return kind_ == CLASS; } | 104 bool is_class() const { return kind_ == CLASS; } |
| 101 bool is_this() const { return kind_ == THIS; } | 105 bool is_this() const { return kind_ == THIS; } |
| 102 bool is_new_target() const { return kind_ == NEW_TARGET; } | 106 bool is_new_target() const { return kind_ == NEW_TARGET; } |
| 103 bool is_arguments() const { return kind_ == ARGUMENTS; } | 107 bool is_arguments() const { return kind_ == ARGUMENTS; } |
| 104 | 108 |
| 109 ClassVariable* AsClassVariable() { |
| 110 DCHECK(is_class()); |
| 111 return reinterpret_cast<ClassVariable*>(this); |
| 112 } |
| 113 |
| 105 // True if the variable is named eval and not known to be shadowed. | 114 // True if the variable is named eval and not known to be shadowed. |
| 106 bool is_possibly_eval(Isolate* isolate) const { | 115 bool is_possibly_eval(Isolate* isolate) const { |
| 107 return IsVariable(isolate->factory()->eval_string()); | 116 return IsVariable(isolate->factory()->eval_string()); |
| 108 } | 117 } |
| 109 | 118 |
| 110 Variable* local_if_not_shadowed() const { | 119 Variable* local_if_not_shadowed() const { |
| 111 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); | 120 DCHECK(mode_ == DYNAMIC_LOCAL && local_if_not_shadowed_ != NULL); |
| 112 return local_if_not_shadowed_; | 121 return local_if_not_shadowed_; |
| 113 } | 122 } |
| 114 | 123 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // binding scope (exclusive). | 177 // binding scope (exclusive). |
| 169 Variable* local_if_not_shadowed_; | 178 Variable* local_if_not_shadowed_; |
| 170 | 179 |
| 171 // Usage info. | 180 // Usage info. |
| 172 bool force_context_allocation_; // set by variable resolver | 181 bool force_context_allocation_; // set by variable resolver |
| 173 bool is_used_; | 182 bool is_used_; |
| 174 InitializationFlag initialization_flag_; | 183 InitializationFlag initialization_flag_; |
| 175 MaybeAssignedFlag maybe_assigned_; | 184 MaybeAssignedFlag maybe_assigned_; |
| 176 }; | 185 }; |
| 177 | 186 |
| 187 class ClassVariable : public Variable { |
| 188 public: |
| 189 ClassVariable(Scope* scope, const AstRawString* name, VariableMode mode, |
| 190 Kind kind, InitializationFlag initialization_flag, |
| 191 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
| 192 int declaration_group_start = -1) |
| 193 : Variable(scope, name, mode, kind, initialization_flag, |
| 194 maybe_assigned_flag), |
| 195 declaration_group_start_(declaration_group_start), |
| 196 corresponding_outer_class_variable_(nullptr) {} |
| 178 | 197 |
| 198 int declaration_group_start() const { return declaration_group_start_; } |
| 199 |
| 200 ClassVariable* corresponding_outer_class_variable() const { |
| 201 return corresponding_outer_class_variable_; |
| 202 } |
| 203 void set_corresponding_outer_class_variable(ClassVariable* var) { |
| 204 corresponding_outer_class_variable_ = var; |
| 205 } |
| 206 |
| 207 private: |
| 208 // For classes we keep track of consecutive groups of delcarations. They are |
| 209 // needed for strong mode scoping checks. TODO(marja, rossberg): Implement |
| 210 // checks for functions too. |
| 211 int declaration_group_start_; |
| 212 ClassVariable* corresponding_outer_class_variable_; |
| 213 }; |
| 179 } } // namespace v8::internal | 214 } } // namespace v8::internal |
| 180 | 215 |
| 181 #endif // V8_VARIABLES_H_ | 216 #endif // V8_VARIABLES_H_ |
| OLD | NEW |