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
3 // found in the LICENSE file.
8 #include "src/scopes.h"
9 #include "src/variables.h"
14 // ----------------------------------------------------------------------------
15 // Implementation Variable.
17 const char* Variable::Mode2String(VariableMode mode) {
19 case VAR: return "VAR";
20 case CONST_LEGACY: return "CONST_LEGACY";
21 case LET: return "LET";
22 case CONST: return "CONST";
23 case IMPORT: return "IMPORT";
24 case DYNAMIC: return "DYNAMIC";
25 case DYNAMIC_GLOBAL: return "DYNAMIC_GLOBAL";
26 case DYNAMIC_LOCAL: return "DYNAMIC_LOCAL";
27 case INTERNAL: return "INTERNAL";
28 case TEMPORARY: return "TEMPORARY";
35 Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode,
36 Kind kind, InitializationFlag initialization_flag,
37 MaybeAssignedFlag maybe_assigned_flag)
42 location_(UNALLOCATED),
44 initializer_position_(RelocInfo::kNoPosition),
45 has_strong_mode_reference_(false),
46 strong_mode_reference_start_position_(RelocInfo::kNoPosition),
47 strong_mode_reference_end_position_(RelocInfo::kNoPosition),
48 local_if_not_shadowed_(NULL),
49 force_context_allocation_(false),
51 initialization_flag_(initialization_flag),
52 maybe_assigned_(maybe_assigned_flag) {
53 // Var declared variables never need initialization.
54 DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization));
58 bool Variable::IsGlobalObjectProperty() const {
59 // Temporaries are never global, they must always be allocated in the
61 return (IsDynamicVariableMode(mode_) ||
62 (IsDeclaredVariableMode(mode_) && !IsLexicalVariableMode(mode_)))
63 && scope_ != NULL && scope_->is_script_scope();
67 int Variable::CompareIndex(Variable* const* v, Variable* const* w) {
68 int x = (*v)->index();
69 int y = (*w)->index();
70 // Consider sorting them according to type as well?
74 } } // namespace v8::internal