V8 Project
variables.h
Go to the documentation of this file.
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.
4 
5 #ifndef V8_VARIABLES_H_
6 #define V8_VARIABLES_H_
7 
9 #include "src/interface.h"
10 #include "src/zone.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 // The AST refers to variables via VariableProxies - placeholders for the actual
16 // variables. Variables themselves are never directly referred to from the AST,
17 // they are maintained by scopes, and referred to from VariableProxies and Slots
18 // after binding and variable allocation.
19 
20 class Variable: public ZoneObject {
21  public:
22  enum Kind {
25  ARGUMENTS
26  };
27 
28  enum Location {
29  // Before and during variable allocation, a variable whose location is
30  // not yet determined. After allocation, a variable looked up as a
31  // property on the global object (and possibly absent). name() is the
32  // variable name, index() is invalid.
34 
35  // A slot in the parameter section on the stack. index() is the
36  // parameter index, counting left-to-right. The receiver is index -1;
37  // the first parameter is index 0.
39 
40  // A slot in the local section on the stack. index() is the variable
41  // index in the stack frame, starting at 0.
43 
44  // An indexed slot in a heap context. index() is the variable index in
45  // the context object on the heap, starting at 0. scope() is the
46  // corresponding scope.
48 
49  // A named slot in a heap context. name() is the variable name in the
50  // context object on the heap, with lookup starting at the current
51  // context. index() is invalid.
52  LOOKUP
53  };
54 
56  bool is_valid_ref, Kind kind, InitializationFlag initialization_flag,
57  MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
59 
60  // Printing support
61  static const char* Mode2String(VariableMode mode);
62 
63  bool IsValidReference() { return is_valid_ref_; }
64 
65  // The source code for an eval() call may refer to a variable that is
66  // in an outer scope about which we don't know anything (it may not
67  // be the global scope). scope() is NULL in that case. Currently the
68  // scope is only used to follow the context chain length.
69  Scope* scope() const { return scope_; }
70 
71  Handle<String> name() const { return name_->string(); }
72  const AstRawString* raw_name() const { return name_; }
73  VariableMode mode() const { return mode_; }
76  }
80  }
81  bool is_used() { return is_used_; }
82  void set_is_used() { is_used_ = true; }
85 
88 
89  bool IsVariable(Handle<String> n) const {
90  return !is_this() && name().is_identical_to(n);
91  }
92 
93  bool IsUnallocated() const { return location_ == UNALLOCATED; }
94  bool IsParameter() const { return location_ == PARAMETER; }
95  bool IsStackLocal() const { return location_ == LOCAL; }
96  bool IsStackAllocated() const { return IsParameter() || IsStackLocal(); }
97  bool IsContextSlot() const { return location_ == CONTEXT; }
98  bool IsLookupSlot() const { return location_ == LOOKUP; }
99  bool IsGlobalObjectProperty() const;
100 
101  bool is_dynamic() const { return IsDynamicVariableMode(mode_); }
102  bool is_const_mode() const { return IsImmutableVariableMode(mode_); }
103  bool binding_needs_init() const {
105  }
106 
107  bool is_this() const { return kind_ == THIS; }
108  bool is_arguments() const { return kind_ == ARGUMENTS; }
109 
110  // True if the variable is named eval and not known to be shadowed.
111  bool is_possibly_eval(Isolate* isolate) const {
112  return IsVariable(isolate->factory()->eval_string());
113  }
114 
117  return local_if_not_shadowed_;
118  }
119 
121  local_if_not_shadowed_ = local;
122  }
123 
124  Location location() const { return location_; }
125  int index() const { return index_; }
127  return initialization_flag_;
128  }
129  Interface* interface() const { return interface_; }
130 
133  index_ = index;
134  }
135 
136  static int CompareIndex(Variable* const* v, Variable* const* w);
137 
138  private:
144  int index_;
146 
147  // If this field is set, this variable references the stored locally bound
148  // variable, but it might be shadowed by variable bindings introduced by
149  // sloppy 'eval' calls between the reference scope (inclusive) and the
150  // binding scope (exclusive).
152 
153  // Valid as a reference? (const and this are not valid, for example)
155 
156  // Usage info.
157  bool force_context_allocation_; // set by variable resolver
158  bool is_used_;
161 
162  // Module type info.
164 };
165 
166 
167 } } // namespace v8::internal
168 
169 #endif // V8_VARIABLES_H_
Handle< String > string() const
static Interface * NewValue()
Definition: interface.h:44
Factory * factory()
Definition: isolate.h:982
Handle< String > name() const
Definition: variables.h:71
bool is_dynamic() const
Definition: variables.h:101
static const char * Mode2String(VariableMode mode)
Definition: variables.cc:17
bool binding_needs_init() const
Definition: variables.h:103
MaybeAssignedFlag maybe_assigned_
Definition: variables.h:160
VariableMode mode() const
Definition: variables.h:73
bool IsStackAllocated() const
Definition: variables.h:96
Location location() const
Definition: variables.h:124
bool is_const_mode() const
Definition: variables.h:102
const AstRawString * name_
Definition: variables.h:140
Interface * interface() const
Definition: variables.h:129
bool IsParameter() const
Definition: variables.h:94
Interface * interface_
Definition: variables.h:163
MaybeAssignedFlag maybe_assigned() const
Definition: variables.h:83
bool is_this() const
Definition: variables.h:107
bool is_possibly_eval(Isolate *isolate) const
Definition: variables.h:111
Scope * scope() const
Definition: variables.h:69
bool IsVariable(Handle< String > n) const
Definition: variables.h:89
void AllocateTo(Location location, int index)
Definition: variables.h:131
Variable(Scope *scope, const AstRawString *name, VariableMode mode, bool is_valid_ref, Kind kind, InitializationFlag initialization_flag, MaybeAssignedFlag maybe_assigned_flag=kNotAssigned, Interface *interface=Interface::NewValue())
Definition: variables.cc:35
Variable * local_if_not_shadowed() const
Definition: variables.h:115
bool IsLookupSlot() const
Definition: variables.h:98
Variable * local_if_not_shadowed_
Definition: variables.h:151
bool is_arguments() const
Definition: variables.h:108
void set_local_if_not_shadowed(Variable *local)
Definition: variables.h:120
bool has_forced_context_allocation() const
Definition: variables.h:74
void set_initializer_position(int pos)
Definition: variables.h:87
InitializationFlag initialization_flag() const
Definition: variables.h:126
bool IsGlobalObjectProperty() const
Definition: variables.cc:58
bool IsStackLocal() const
Definition: variables.h:95
InitializationFlag initialization_flag_
Definition: variables.h:159
const AstRawString * raw_name() const
Definition: variables.h:72
void ForceContextAllocation()
Definition: variables.h:77
bool IsContextSlot() const
Definition: variables.h:97
VariableMode mode_
Definition: variables.h:141
static int CompareIndex(Variable *const *v, Variable *const *w)
Definition: variables.cc:67
bool IsUnallocated() const
Definition: variables.h:93
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
InitializationFlag
Definition: globals.h:751
@ kNeedsInitialization
Definition: globals.h:752
@ kNotAssigned
Definition: globals.h:757
@ kMaybeAssigned
Definition: globals.h:757
bool IsImmutableVariableMode(VariableMode mode)
Definition: globals.h:715
@ DYNAMIC_LOCAL
Definition: globals.h:693
bool IsDynamicVariableMode(VariableMode mode)
Definition: globals.h:700
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20