| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 // The AST refers to variables via VariableProxies - placeholders for the actual | 36 // The AST refers to variables via VariableProxies - placeholders for the actual |
| 37 // variables. Variables themselves are never directly referred to from the AST, | 37 // variables. Variables themselves are never directly referred to from the AST, |
| 38 // they are maintained by scopes, and referred to from VariableProxies and Slots | 38 // they are maintained by scopes, and referred to from VariableProxies and Slots |
| 39 // after binding and variable allocation. | 39 // after binding and variable allocation. |
| 40 | 40 |
| 41 class Variable: public ZoneObject { | 41 class Variable: public ZoneObject { |
| 42 public: | 42 public: |
| 43 enum Mode { | |
| 44 // User declared variables: | |
| 45 VAR, // declared via 'var', and 'function' declarations | |
| 46 | |
| 47 CONST, // declared via 'const' declarations | |
| 48 | |
| 49 LET, // declared via 'let' declarations | |
| 50 | |
| 51 // Variables introduced by the compiler: | |
| 52 DYNAMIC, // always require dynamic lookup (we don't know | |
| 53 // the declaration) | |
| 54 | |
| 55 DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the | |
| 56 // variable is global unless it has been shadowed | |
| 57 // by an eval-introduced variable | |
| 58 | |
| 59 DYNAMIC_LOCAL, // requires dynamic lookup, but we know that the | |
| 60 // variable is local and where it is unless it | |
| 61 // has been shadowed by an eval-introduced | |
| 62 // variable | |
| 63 | |
| 64 INTERNAL, // like VAR, but not user-visible (may or may not | |
| 65 // be in a context) | |
| 66 | |
| 67 TEMPORARY // temporary variables (not user-visible), never | |
| 68 // in a context | |
| 69 }; | |
| 70 | |
| 71 enum Kind { | 43 enum Kind { |
| 72 NORMAL, | 44 NORMAL, |
| 73 THIS, | 45 THIS, |
| 74 ARGUMENTS | 46 ARGUMENTS |
| 75 }; | 47 }; |
| 76 | 48 |
| 77 enum Location { | 49 enum Location { |
| 78 // Before and during variable allocation, a variable whose location is | 50 // Before and during variable allocation, a variable whose location is |
| 79 // not yet determined. After allocation, a variable looked up as a | 51 // not yet determined. After allocation, a variable looked up as a |
| 80 // property on the global object (and possibly absent). name() is the | 52 // property on the global object (and possibly absent). name() is the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 96 CONTEXT, | 68 CONTEXT, |
| 97 | 69 |
| 98 // A named slot in a heap context. name() is the variable name in the | 70 // A named slot in a heap context. name() is the variable name in the |
| 99 // context object on the heap, with lookup starting at the current | 71 // context object on the heap, with lookup starting at the current |
| 100 // context. index() is invalid. | 72 // context. index() is invalid. |
| 101 LOOKUP | 73 LOOKUP |
| 102 }; | 74 }; |
| 103 | 75 |
| 104 Variable(Scope* scope, | 76 Variable(Scope* scope, |
| 105 Handle<String> name, | 77 Handle<String> name, |
| 106 Mode mode, | 78 VariableMode mode, |
| 107 bool is_valid_lhs, | 79 bool is_valid_lhs, |
| 108 Kind kind); | 80 Kind kind); |
| 109 | 81 |
| 110 // Printing support | 82 // Printing support |
| 111 static const char* Mode2String(Mode mode); | 83 static const char* Mode2String(VariableMode mode); |
| 112 | 84 |
| 113 bool IsValidLeftHandSide() { return is_valid_LHS_; } | 85 bool IsValidLeftHandSide() { return is_valid_LHS_; } |
| 114 | 86 |
| 115 // The source code for an eval() call may refer to a variable that is | 87 // The source code for an eval() call may refer to a variable that is |
| 116 // in an outer scope about which we don't know anything (it may not | 88 // in an outer scope about which we don't know anything (it may not |
| 117 // be the global scope). scope() is NULL in that case. Currently the | 89 // be the global scope). scope() is NULL in that case. Currently the |
| 118 // scope is only used to follow the context chain length. | 90 // scope is only used to follow the context chain length. |
| 119 Scope* scope() const { return scope_; } | 91 Scope* scope() const { return scope_; } |
| 120 | 92 |
| 121 Handle<String> name() const { return name_; } | 93 Handle<String> name() const { return name_; } |
| 122 Mode mode() const { return mode_; } | 94 VariableMode mode() const { return mode_; } |
| 123 bool is_accessed_from_inner_scope() const { | 95 bool is_accessed_from_inner_scope() const { |
| 124 return is_accessed_from_inner_scope_; | 96 return is_accessed_from_inner_scope_; |
| 125 } | 97 } |
| 126 void MarkAsAccessedFromInnerScope() { | 98 void MarkAsAccessedFromInnerScope() { |
| 127 ASSERT(mode_ != TEMPORARY); | 99 ASSERT(mode_ != TEMPORARY); |
| 128 is_accessed_from_inner_scope_ = true; | 100 is_accessed_from_inner_scope_ = true; |
| 129 } | 101 } |
| 130 bool is_used() { return is_used_; } | 102 bool is_used() { return is_used_; } |
| 131 void set_is_used(bool flag) { is_used_ = flag; } | 103 void set_is_used(bool flag) { is_used_ = flag; } |
| 132 | 104 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 int index() const { return index_; } | 142 int index() const { return index_; } |
| 171 | 143 |
| 172 void AllocateTo(Location location, int index) { | 144 void AllocateTo(Location location, int index) { |
| 173 location_ = location; | 145 location_ = location; |
| 174 index_ = index; | 146 index_ = index; |
| 175 } | 147 } |
| 176 | 148 |
| 177 private: | 149 private: |
| 178 Scope* scope_; | 150 Scope* scope_; |
| 179 Handle<String> name_; | 151 Handle<String> name_; |
| 180 Mode mode_; | 152 VariableMode mode_; |
| 181 Kind kind_; | 153 Kind kind_; |
| 182 Location location_; | 154 Location location_; |
| 183 int index_; | 155 int index_; |
| 184 | 156 |
| 185 Variable* local_if_not_shadowed_; | 157 Variable* local_if_not_shadowed_; |
| 186 | 158 |
| 187 // Valid as a LHS? (const and this are not valid LHS, for example) | 159 // Valid as a LHS? (const and this are not valid LHS, for example) |
| 188 bool is_valid_LHS_; | 160 bool is_valid_LHS_; |
| 189 | 161 |
| 190 // Usage info. | 162 // Usage info. |
| 191 bool is_accessed_from_inner_scope_; // set by variable resolver | 163 bool is_accessed_from_inner_scope_; // set by variable resolver |
| 192 bool is_used_; | 164 bool is_used_; |
| 193 }; | 165 }; |
| 194 | 166 |
| 195 | 167 |
| 196 } } // namespace v8::internal | 168 } } // namespace v8::internal |
| 197 | 169 |
| 198 #endif // V8_VARIABLES_H_ | 170 #endif // V8_VARIABLES_H_ |
| OLD | NEW |