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 13 matching lines...) Expand all Loading... | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_SCOPEINFO_H_ | 28 #ifndef V8_SCOPEINFO_H_ |
29 #define V8_SCOPEINFO_H_ | 29 #define V8_SCOPEINFO_H_ |
30 | 30 |
31 #include "allocation.h" | 31 #include "allocation.h" |
32 #include "variables.h" | 32 #include "variables.h" |
33 #include "zone-inl.h" | 33 #include "zone-inl.h" |
34 #include "scopes.h" | |
Kevin Millikin (Chromium)
2011/10/05 08:43:36
Maybe we should avoid this? It's not yet a circul
Steven
2011/10/06 19:09:27
Yes, I totally agree.
On 2011/10/05 08:43:36, Kevi
| |
34 | 35 |
35 namespace v8 { | 36 namespace v8 { |
36 namespace internal { | 37 namespace internal { |
37 | 38 |
38 // Scope information represents information about a functions's | 39 // Scope information represents information about a functions's |
Kevin Millikin (Chromium)
2011/10/05 08:43:36
This comment seems out of date. And the Historica
Steven
2011/10/06 19:09:27
Done. But could use more love when cleaning up Sco
| |
39 // scopes (currently only one, because we don't do any inlining) | 40 // scopes (currently only one, because we don't do any inlining) |
40 // and the allocation of the scope's variables. Scope information | 41 // and the allocation of the scope's variables. Scope information |
41 // is stored in a compressed form in FixedArray objects and is used | 42 // is stored in a compressed form in FixedArray objects and is used |
42 // at runtime (stack dumps, deoptimization, etc.). | 43 // at runtime (stack dumps, deoptimization, etc.). |
43 // | 44 // |
44 // Historical note: In other VMs built by this team, ScopeInfo was | 45 // Historical note: In other VMs built by this team, ScopeInfo was |
45 // usually called DebugInfo since the information was used (among | 46 // usually called DebugInfo since the information was used (among |
46 // other things) for on-demand debugging (Self, Smalltalk). However, | 47 // other things) for on-demand debugging (Self, Smalltalk). However, |
47 // DebugInfo seems misleading, since this information is primarily used | 48 // DebugInfo seems misleading, since this information is primarily used |
48 // in debugging-unrelated contexts. | 49 // in debugging-unrelated contexts. |
(...skipping 27 matching lines...) Expand all Loading... | |
76 return context_slots_[i - Context::MIN_CONTEXT_SLOTS]; | 77 return context_slots_[i - Context::MIN_CONTEXT_SLOTS]; |
77 } | 78 } |
78 int number_of_context_slots() const { | 79 int number_of_context_slots() const { |
79 int l = context_slots_.length(); | 80 int l = context_slots_.length(); |
80 return l == 0 ? 0 : l + Context::MIN_CONTEXT_SLOTS; | 81 return l == 0 ? 0 : l + Context::MIN_CONTEXT_SLOTS; |
81 } | 82 } |
82 | 83 |
83 Handle<String> LocalName(int i) const; | 84 Handle<String> LocalName(int i) const; |
84 int NumberOfLocals() const; | 85 int NumberOfLocals() const; |
85 | 86 |
87 Scope::Type type() const { return type_; } | |
88 int SourceBegStatementPos() const { return source_beg_statement_pos_; } | |
89 int SourceEndStatementPos() const { return source_end_statement_pos_; } | |
90 | |
86 // -------------------------------------------------------------------------- | 91 // -------------------------------------------------------------------------- |
87 // Debugging support | 92 // Debugging support |
88 | 93 |
89 #ifdef DEBUG | 94 #ifdef DEBUG |
90 void Print(); | 95 void Print(); |
91 #endif | 96 #endif |
92 | 97 |
93 private: | 98 private: |
94 Handle<String> function_name_; | 99 Handle<String> function_name_; |
95 bool calls_eval_; | 100 bool calls_eval_; |
96 bool is_strict_mode_; | 101 bool is_strict_mode_; |
102 Scope::Type type_; | |
103 int source_beg_statement_pos_; | |
104 int source_end_statement_pos_; | |
97 List<Handle<String>, Allocator > parameters_; | 105 List<Handle<String>, Allocator > parameters_; |
98 List<Handle<String>, Allocator > stack_slots_; | 106 List<Handle<String>, Allocator > stack_slots_; |
99 List<Handle<String>, Allocator > context_slots_; | 107 List<Handle<String>, Allocator > context_slots_; |
100 List<Variable::Mode, Allocator > context_modes_; | 108 List<Variable::Mode, Allocator > context_modes_; |
109 List<Handle<SerializedScopeInfo>, Allocator> inner_scopeinfos_; | |
101 }; | 110 }; |
102 | 111 |
103 | 112 |
104 // This object provides quick access to scope info details for runtime | 113 // This object provides quick access to scope info details for runtime |
105 // routines w/o the need to explicitly create a ScopeInfo object. | 114 // routines w/o the need to explicitly create a ScopeInfo object. |
106 class SerializedScopeInfo : public FixedArray { | 115 class SerializedScopeInfo : public FixedArray { |
107 public : | 116 public : |
108 | 117 |
109 static SerializedScopeInfo* cast(Object* object) { | 118 static SerializedScopeInfo* cast(Object* object) { |
110 ASSERT(object->IsSerializedScopeInfo()); | 119 ASSERT(object->IsSerializedScopeInfo()); |
111 return reinterpret_cast<SerializedScopeInfo*>(object); | 120 return reinterpret_cast<SerializedScopeInfo*>(object); |
112 } | 121 } |
113 | 122 |
123 // Return the type of this scope. | |
124 Scope::Type ScopeType(); | |
125 | |
114 // Does this scope call eval? | 126 // Does this scope call eval? |
115 bool CallsEval(); | 127 bool CallsEval(); |
116 | 128 |
117 // Is this scope a strict mode scope? | 129 // Is this scope a strict mode scope? |
118 bool IsStrictMode(); | 130 bool IsStrictMode(); |
119 | 131 |
132 // Start position of this scope in the source string. | |
Kevin Millikin (Chromium)
2011/10/05 08:43:36
I think we want a crisp characterization of start
Steven
2011/10/06 19:09:27
Added a description to scopes.h. PTAL there.
On 20
| |
133 int SourceBegStatementPos(); | |
134 | |
135 // End position of this scope in the source string. | |
136 int SourceEndStatementPos(); | |
137 | |
120 // Return the number of stack slots for code. | 138 // Return the number of stack slots for code. |
121 int NumberOfStackSlots(); | 139 int NumberOfStackSlots(); |
122 | 140 |
123 // Return the number of context slots for code. | 141 // Return the number of context slots for code. |
124 int NumberOfContextSlots(); | 142 int NumberOfContextSlots(); |
125 | 143 |
144 // Return the number of immediate nested scopes. | |
145 int NumberOfNestedScopes(); | |
146 | |
147 // Lookup an immediate nested scope by its index. | |
148 Handle<SerializedScopeInfo> NestedScope(int i); | |
149 | |
126 // Return if this has context slots besides MIN_CONTEXT_SLOTS; | 150 // Return if this has context slots besides MIN_CONTEXT_SLOTS; |
127 bool HasHeapAllocatedLocals(); | 151 bool HasHeapAllocatedLocals(); |
128 | 152 |
153 // Return if contexts are allocated for this scope. | |
154 bool HasContext(); | |
155 | |
129 // Lookup support for serialized scope info. Returns the | 156 // Lookup support for serialized scope info. Returns the |
130 // the stack slot index for a given slot name if the slot is | 157 // the stack slot index for a given slot name if the slot is |
131 // present; otherwise returns a value < 0. The name must be a symbol | 158 // present; otherwise returns a value < 0. The name must be a symbol |
132 // (canonicalized). | 159 // (canonicalized). |
133 int StackSlotIndex(String* name); | 160 int StackSlotIndex(String* name); |
134 | 161 |
135 // Lookup support for serialized scope info. Returns the | 162 // Lookup support for serialized scope info. Returns the |
136 // context slot index for a given slot name if the slot is present; otherwise | 163 // context slot index for a given slot name if the slot is present; otherwise |
137 // returns a value < 0. The name must be a symbol (canonicalized). | 164 // returns a value < 0. The name must be a symbol (canonicalized). |
138 // If the slot is present and mode != NULL, sets *mode to the corresponding | 165 // If the slot is present and mode != NULL, sets *mode to the corresponding |
139 // mode for that variable. | 166 // mode for that variable. |
140 int ContextSlotIndex(String* name, Variable::Mode* mode); | 167 int ContextSlotIndex(String* name, Variable::Mode* mode); |
141 | 168 |
142 // Lookup support for serialized scope info. Returns the | 169 // Lookup support for serialized scope info. Returns the |
143 // parameter index for a given parameter name if the parameter is present; | 170 // parameter index for a given parameter name if the parameter is present; |
144 // otherwise returns a value < 0. The name must be a symbol (canonicalized). | 171 // otherwise returns a value < 0. The name must be a symbol (canonicalized). |
145 int ParameterIndex(String* name); | 172 int ParameterIndex(String* name); |
146 | 173 |
147 // Lookup support for serialized scope info. Returns the | 174 // Lookup support for serialized scope info. Returns the |
148 // function context slot index if the function name is present (named | 175 // function context slot index if the function name is present (named |
149 // function expressions, only), otherwise returns a value < 0. The name | 176 // function expressions, only), otherwise returns a value < 0. The name |
150 // must be a symbol (canonicalized). | 177 // must be a symbol (canonicalized). |
151 int FunctionContextSlotIndex(String* name); | 178 int FunctionContextSlotIndex(String* name); |
152 | 179 |
180 // Get the chain of nested scopes within this scope for the source statement | |
181 // position. The scopes will be added to the list from the outermost scope to | |
182 // the innermost scope. Only nested block, catch or with scopes are tracked | |
183 // and will be returned, but no inner function scopes. | |
184 void GetNestedScopeChain(List<Handle<SerializedScopeInfo> >* chain, | |
185 int statement_position); | |
186 | |
153 static Handle<SerializedScopeInfo> Create(Scope* scope); | 187 static Handle<SerializedScopeInfo> Create(Scope* scope); |
154 | 188 |
155 // Serializes empty scope info. | 189 // Serializes empty scope info. |
156 static SerializedScopeInfo* Empty(); | 190 static SerializedScopeInfo* Empty(); |
157 | 191 |
158 private: | 192 private: |
159 inline Object** ContextEntriesAddr(); | 193 inline Object** ContextEntriesAddr(); |
160 | 194 |
161 inline Object** ParameterEntriesAddr(); | 195 inline Object** ParameterEntriesAddr(); |
162 | 196 |
163 inline Object** StackSlotEntriesAddr(); | 197 inline Object** StackSlotEntriesAddr(); |
198 | |
199 inline Object** NestedScopeEntriesAddr(); | |
164 }; | 200 }; |
165 | 201 |
166 | 202 |
167 // Cache for mapping (data, property name) into context slot index. | 203 // Cache for mapping (data, property name) into context slot index. |
168 // The cache contains both positive and negative results. | 204 // The cache contains both positive and negative results. |
169 // Slot index equals -1 means the property is absent. | 205 // Slot index equals -1 means the property is absent. |
170 // Cleared at startup and prior to mark sweep collection. | 206 // Cleared at startup and prior to mark sweep collection. |
171 class ContextSlotCache { | 207 class ContextSlotCache { |
172 public: | 208 public: |
173 // Lookup context slot index for (data, name). | 209 // Lookup context slot index for (data, name). |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 uint32_t values_[kLength]; | 276 uint32_t values_[kLength]; |
241 | 277 |
242 friend class Isolate; | 278 friend class Isolate; |
243 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); | 279 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); |
244 }; | 280 }; |
245 | 281 |
246 | 282 |
247 } } // namespace v8::internal | 283 } } // namespace v8::internal |
248 | 284 |
249 #endif // V8_SCOPEINFO_H_ | 285 #endif // V8_SCOPEINFO_H_ |
OLD | NEW |