| 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/ast.h" | 7 #include "src/ast.h" |
| 8 #include "src/scopes.h" | 8 #include "src/scopes.h" |
| 9 #include "src/variables.h" | 9 #include "src/variables.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 // ---------------------------------------------------------------------------- | 14 // ---------------------------------------------------------------------------- |
| 15 // Implementation Variable. | 15 // Implementation Variable. |
| 16 | 16 |
| 17 const char* Variable::Mode2String(VariableMode mode) { | 17 const char* Variable::Mode2String(VariableMode mode) { |
| 18 switch (mode) { | 18 switch (mode) { |
| 19 case VAR: return "VAR"; | 19 case VAR: return "VAR"; |
| 20 case CONST_LEGACY: return "CONST_LEGACY"; | 20 case CONST_LEGACY: return "CONST_LEGACY"; |
| 21 case LET: return "LET"; | 21 case LET: return "LET"; |
| 22 case CONST: return "CONST"; | 22 case CONST: return "CONST"; |
| 23 case MODULE: return "MODULE"; | |
| 24 case DYNAMIC: return "DYNAMIC"; | 23 case DYNAMIC: return "DYNAMIC"; |
| 25 case DYNAMIC_GLOBAL: return "DYNAMIC_GLOBAL"; | 24 case DYNAMIC_GLOBAL: return "DYNAMIC_GLOBAL"; |
| 26 case DYNAMIC_LOCAL: return "DYNAMIC_LOCAL"; | 25 case DYNAMIC_LOCAL: return "DYNAMIC_LOCAL"; |
| 27 case INTERNAL: return "INTERNAL"; | 26 case INTERNAL: return "INTERNAL"; |
| 28 case TEMPORARY: return "TEMPORARY"; | 27 case TEMPORARY: return "TEMPORARY"; |
| 29 } | 28 } |
| 30 UNREACHABLE(); | 29 UNREACHABLE(); |
| 31 return NULL; | 30 return NULL; |
| 32 } | 31 } |
| 33 | 32 |
| 34 | 33 |
| 35 Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode, | 34 Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode, |
| 36 bool is_valid_ref, Kind kind, | 35 bool is_valid_ref, Kind kind, |
| 37 InitializationFlag initialization_flag, | 36 InitializationFlag initialization_flag, |
| 38 MaybeAssignedFlag maybe_assigned_flag, Interface* interface) | 37 MaybeAssignedFlag maybe_assigned_flag) |
| 39 : scope_(scope), | 38 : scope_(scope), |
| 40 name_(name), | 39 name_(name), |
| 41 mode_(mode), | 40 mode_(mode), |
| 42 kind_(kind), | 41 kind_(kind), |
| 43 location_(UNALLOCATED), | 42 location_(UNALLOCATED), |
| 44 index_(-1), | 43 index_(-1), |
| 45 initializer_position_(RelocInfo::kNoPosition), | 44 initializer_position_(RelocInfo::kNoPosition), |
| 46 local_if_not_shadowed_(NULL), | 45 local_if_not_shadowed_(NULL), |
| 47 is_valid_ref_(is_valid_ref), | 46 is_valid_ref_(is_valid_ref), |
| 48 force_context_allocation_(false), | 47 force_context_allocation_(false), |
| 49 is_used_(false), | 48 is_used_(false), |
| 50 initialization_flag_(initialization_flag), | 49 initialization_flag_(initialization_flag), |
| 51 maybe_assigned_(maybe_assigned_flag), | 50 maybe_assigned_(maybe_assigned_flag) { |
| 52 interface_(interface) { | |
| 53 // Var declared variables never need initialization. | 51 // Var declared variables never need initialization. |
| 54 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization)); | 52 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization)); |
| 55 } | 53 } |
| 56 | 54 |
| 57 | 55 |
| 58 bool Variable::IsGlobalObjectProperty() const { | 56 bool Variable::IsGlobalObjectProperty() const { |
| 59 // Temporaries are never global, they must always be allocated in the | 57 // Temporaries are never global, they must always be allocated in the |
| 60 // activation frame. | 58 // activation frame. |
| 61 return (IsDynamicVariableMode(mode_) || | 59 return (IsDynamicVariableMode(mode_) || |
| 62 (IsDeclaredVariableMode(mode_) && !IsLexicalVariableMode(mode_))) | 60 (IsDeclaredVariableMode(mode_) && !IsLexicalVariableMode(mode_))) |
| 63 && scope_ != NULL && scope_->is_script_scope(); | 61 && scope_ != NULL && scope_->is_script_scope(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 | 64 |
| 67 int Variable::CompareIndex(Variable* const* v, Variable* const* w) { | 65 int Variable::CompareIndex(Variable* const* v, Variable* const* w) { |
| 68 int x = (*v)->index(); | 66 int x = (*v)->index(); |
| 69 int y = (*w)->index(); | 67 int y = (*w)->index(); |
| 70 // Consider sorting them according to type as well? | 68 // Consider sorting them according to type as well? |
| 71 return x - y; | 69 return x - y; |
| 72 } | 70 } |
| 73 | 71 |
| 74 } } // namespace v8::internal | 72 } } // namespace v8::internal |
| OLD | NEW |