Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/scopeinfo.h

Issue 7523027: Provisional implementation of stack allocated catch variables. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 "ast.h"
35 #include "scopes.h"
34 36
35 namespace v8 { 37 namespace v8 {
36 namespace internal { 38 namespace internal {
37 39
38 // Scope information represents information about a functions's 40 // Scope information represents information about a functions's
39 // scopes (currently only one, because we don't do any inlining) 41 // scopes (currently only one, because we don't do any inlining)
40 // and the allocation of the scope's variables. Scope information 42 // and the allocation of the scope's variables. Scope information
41 // is stored in a compressed form in FixedArray objects and is used 43 // is stored in a compressed form in FixedArray objects and is used
42 // at runtime (stack dumps, deoptimization, etc.). 44 // at runtime (stack dumps, deoptimization, etc.).
43 // 45 //
(...skipping 28 matching lines...) Expand all
72 Handle<String> stack_slot_name(int i) const { return stack_slots_[i]; } 74 Handle<String> stack_slot_name(int i) const { return stack_slots_[i]; }
73 int number_of_stack_slots() const { return stack_slots_.length(); } 75 int number_of_stack_slots() const { return stack_slots_.length(); }
74 76
75 Handle<String> context_slot_name(int i) const { 77 Handle<String> context_slot_name(int i) const {
76 return context_slots_[i - Context::MIN_CONTEXT_SLOTS]; 78 return context_slots_[i - Context::MIN_CONTEXT_SLOTS];
77 } 79 }
78 int number_of_context_slots() const { 80 int number_of_context_slots() const {
79 int l = context_slots_.length(); 81 int l = context_slots_.length();
80 return l == 0 ? 0 : l + Context::MIN_CONTEXT_SLOTS; 82 return l == 0 ? 0 : l + Context::MIN_CONTEXT_SLOTS;
81 } 83 }
84 int first_stack_index() const {
85 return first_stack_index_;
86 }
82 87
83 Handle<String> LocalName(int i) const; 88 Handle<String> LocalName(int i) const;
84 int NumberOfLocals() const; 89 int NumberOfLocals() const;
85 90
91 Scope::Type type() const { return type_; }
92 int SourceBegStatementPos() const { return source_beg_statement_pos_; }
93 int SourceEndStatementPos() const { return source_end_statement_pos_; }
94
95
86 // -------------------------------------------------------------------------- 96 // --------------------------------------------------------------------------
87 // Debugging support 97 // Debugging support
88 98
89 #ifdef DEBUG 99 #ifdef DEBUG
90 void Print(); 100 void Print();
91 #endif 101 #endif
92 102
93 private: 103 private:
94 Handle<String> function_name_; 104 Handle<String> function_name_;
95 bool calls_eval_; 105 bool calls_eval_;
96 bool is_strict_mode_; 106 bool is_strict_mode_;
107 Scope::Type type_;
108 int source_beg_statement_pos_;
109 int source_end_statement_pos_;
110 int first_stack_index_;
97 List<Handle<String>, Allocator > parameters_; 111 List<Handle<String>, Allocator > parameters_;
98 List<Handle<String>, Allocator > stack_slots_; 112 List<Handle<String>, Allocator > stack_slots_;
99 List<Handle<String>, Allocator > context_slots_; 113 List<Handle<String>, Allocator > context_slots_;
100 List<Variable::Mode, Allocator > context_modes_; 114 List<Variable::Mode, Allocator > context_modes_;
115 List<Handle<SerializedScopeInfo>, Allocator> inner_scopeinfos_;
101 }; 116 };
102 117
103 118
104 // This object provides quick access to scope info details for runtime 119 // This object provides quick access to scope info details for runtime
105 // routines w/o the need to explicitly create a ScopeInfo object. 120 // routines w/o the need to explicitly create a ScopeInfo object.
106 class SerializedScopeInfo : public FixedArray { 121 class SerializedScopeInfo : public FixedArray {
107 public : 122 public :
108 123
109 static SerializedScopeInfo* cast(Object* object) { 124 static SerializedScopeInfo* cast(Object* object) {
110 ASSERT(object->IsFixedArray()); 125 ASSERT(object->IsFixedArray());
111 return reinterpret_cast<SerializedScopeInfo*>(object); 126 return reinterpret_cast<SerializedScopeInfo*>(object);
112 } 127 }
113 128
114 // Does this scope call eval? 129 // Does this scope call eval?
115 bool CallsEval(); 130 bool CallsEval();
116 131
117 // Is this scope a strict mode scope? 132 // Is this scope a strict mode scope?
118 bool IsStrictMode(); 133 bool IsStrictMode();
119 134
135 // Start position of this scope in the source string.
136 int SourceBegStatementPos();
137
138 // End position of this scope in the source string.
139 int SourceEndStatementPos();
140
141 // First stack slot index for stack slots.
142 int FirstStackSlot();
143
144 // Return the number of parameters for code.
145 int NumberOfParameters();
146
120 // Return the number of stack slots for code. 147 // Return the number of stack slots for code.
121 int NumberOfStackSlots(); 148 int NumberOfStackSlots();
122 149
123 // Return the number of context slots for code. 150 // Return the number of context slots for code.
124 int NumberOfContextSlots(); 151 int NumberOfContextSlots();
125 152
153 // Return the number of nested scopes for code.
154 int NumberOfNestedScopes();
155
156 Handle<SerializedScopeInfo> NestedScope(int i);
157
126 // Return if this has context slots besides MIN_CONTEXT_SLOTS; 158 // Return if this has context slots besides MIN_CONTEXT_SLOTS;
127 bool HasHeapAllocatedLocals(); 159 bool HasHeapAllocatedLocals();
128 160
161 bool HasContext();
162
163 Handle<String> FunctionName();
164 Handle<String> ParameterName(int i);
165 Handle<String> StackSlotName(int i);
166 Handle<String> ContextSlotName(int i, Variable::Mode* mode);
167
129 // Lookup support for serialized scope info. Returns the 168 // Lookup support for serialized scope info. Returns the
130 // the stack slot index for a given slot name if the slot is 169 // 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 170 // present; otherwise returns a value < 0. The name must be a symbol
132 // (canonicalized). 171 // (canonicalized).
133 int StackSlotIndex(String* name); 172 int StackSlotIndex(String* name);
134 173
135 // Lookup support for serialized scope info. Returns the 174 // Lookup support for serialized scope info. Returns the
136 // context slot index for a given slot name if the slot is present; otherwise 175 // 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). 176 // 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 177 // If the slot is present and mode != NULL, sets *mode to the corresponding
139 // mode for that variable. 178 // mode for that variable.
140 int ContextSlotIndex(String* name, Variable::Mode* mode); 179 int ContextSlotIndex(String* name, Variable::Mode* mode);
141 180
142 // Lookup support for serialized scope info. Returns the 181 // Lookup support for serialized scope info. Returns the
143 // parameter index for a given parameter name if the parameter is present; 182 // 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). 183 // otherwise returns a value < 0. The name must be a symbol (canonicalized).
145 int ParameterIndex(String* name); 184 int ParameterIndex(String* name);
146 185
147 // Lookup support for serialized scope info. Returns the 186 // Lookup support for serialized scope info. Returns the
148 // function context slot index if the function name is present (named 187 // function context slot index if the function name is present (named
149 // function expressions, only), otherwise returns a value < 0. The name 188 // function expressions, only), otherwise returns a value < 0. The name
150 // must be a symbol (canonicalized). 189 // must be a symbol (canonicalized).
151 int FunctionContextSlotIndex(String* name); 190 int FunctionContextSlotIndex(String* name);
152 191
192 Scope::Type ScopeType();
193
194 void GetLocalScopeChain(List<Handle<SerializedScopeInfo> >* chain,
195 int position);
196
153 static Handle<SerializedScopeInfo> Create(Scope* scope); 197 static Handle<SerializedScopeInfo> Create(Scope* scope);
154 198
155 // Serializes empty scope info. 199 // Serializes empty scope info.
156 static SerializedScopeInfo* Empty(); 200 static SerializedScopeInfo* Empty();
157 201
158 private: 202 private:
159 203
160 inline Object** ContextEntriesAddr(); 204 inline Object** ContextEntriesAddr();
161 205
162 inline Object** ParameterEntriesAddr(); 206 inline Object** ParameterEntriesAddr();
163 207
164 inline Object** StackSlotEntriesAddr(); 208 inline Object** StackSlotEntriesAddr();
209
210 inline Object** NestedScopeEntriesAddr();
165 }; 211 };
166 212
167 213
168 // Cache for mapping (data, property name) into context slot index. 214 // Cache for mapping (data, property name) into context slot index.
169 // The cache contains both positive and negative results. 215 // The cache contains both positive and negative results.
170 // Slot index equals -1 means the property is absent. 216 // Slot index equals -1 means the property is absent.
171 // Cleared at startup and prior to mark sweep collection. 217 // Cleared at startup and prior to mark sweep collection.
172 class ContextSlotCache { 218 class ContextSlotCache {
173 public: 219 public:
174 // Lookup context slot index for (data, name). 220 // Lookup context slot index for (data, name).
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 uint32_t values_[kLength]; 286 uint32_t values_[kLength];
241 287
242 friend class Isolate; 288 friend class Isolate;
243 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); 289 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache);
244 }; 290 };
245 291
246 292
247 } } // namespace v8::internal 293 } } // namespace v8::internal
248 294
249 #endif // V8_SCOPEINFO_H_ 295 #endif // V8_SCOPEINFO_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698