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

Side by Side Diff: src/scopeinfo.h

Issue 8221004: Move declaration of SerializedScopeInfo from variables.h to objects.h (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 2 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
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 void Print(); 90 void Print();
91 #endif 91 #endif
92 92
93 private: 93 private:
94 Handle<String> function_name_; 94 Handle<String> function_name_;
95 bool calls_eval_; 95 bool calls_eval_;
96 bool is_strict_mode_; 96 bool is_strict_mode_;
97 List<Handle<String>, Allocator > parameters_; 97 List<Handle<String>, Allocator > parameters_;
98 List<Handle<String>, Allocator > stack_slots_; 98 List<Handle<String>, Allocator > stack_slots_;
99 List<Handle<String>, Allocator > context_slots_; 99 List<Handle<String>, Allocator > context_slots_;
100 List<Variable::Mode, Allocator > context_modes_; 100 List<VariableMode, Allocator > context_modes_;
101 };
102
103
104 // This object provides quick access to scope info details for runtime
105 // routines w/o the need to explicitly create a ScopeInfo object.
106 class SerializedScopeInfo : public FixedArray {
107 public :
108
109 static SerializedScopeInfo* cast(Object* object) {
110 ASSERT(object->IsSerializedScopeInfo());
111 return reinterpret_cast<SerializedScopeInfo*>(object);
112 }
113
114 // Does this scope call eval?
115 bool CallsEval();
116
117 // Is this scope a strict mode scope?
118 bool IsStrictMode();
119
120 // Return the number of stack slots for code.
121 int NumberOfStackSlots();
122
123 // Return the number of context slots for code.
124 int NumberOfContextSlots();
125
126 // Return if this has context slots besides MIN_CONTEXT_SLOTS;
127 bool HasHeapAllocatedLocals();
128
129 // Lookup support for serialized scope info. Returns the
130 // 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
132 // (canonicalized).
133 int StackSlotIndex(String* name);
134
135 // Lookup support for serialized scope info. Returns the
136 // 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).
138 // If the slot is present and mode != NULL, sets *mode to the corresponding
139 // mode for that variable.
140 int ContextSlotIndex(String* name, Variable::Mode* mode);
141
142 // Lookup support for serialized scope info. Returns the
143 // 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).
145 int ParameterIndex(String* name);
146
147 // Lookup support for serialized scope info. Returns the
148 // function context slot index if the function name is present (named
149 // function expressions, only), otherwise returns a value < 0. The name
150 // must be a symbol (canonicalized).
151 int FunctionContextSlotIndex(String* name);
152
153 static Handle<SerializedScopeInfo> Create(Scope* scope);
154
155 // Serializes empty scope info.
156 static SerializedScopeInfo* Empty();
157
158 private:
159 inline Object** ContextEntriesAddr();
160
161 inline Object** ParameterEntriesAddr();
162
163 inline Object** StackSlotEntriesAddr();
164 }; 101 };
165 102
166 103
167 // Cache for mapping (data, property name) into context slot index. 104 // Cache for mapping (data, property name) into context slot index.
168 // The cache contains both positive and negative results. 105 // The cache contains both positive and negative results.
169 // Slot index equals -1 means the property is absent. 106 // Slot index equals -1 means the property is absent.
170 // Cleared at startup and prior to mark sweep collection. 107 // Cleared at startup and prior to mark sweep collection.
171 class ContextSlotCache { 108 class ContextSlotCache {
172 public: 109 public:
173 // Lookup context slot index for (data, name). 110 // Lookup context slot index for (data, name).
174 // If absent, kNotFound is returned. 111 // If absent, kNotFound is returned.
175 int Lookup(Object* data, 112 int Lookup(Object* data,
176 String* name, 113 String* name,
177 Variable::Mode* mode); 114 VariableMode* mode);
178 115
179 // Update an element in the cache. 116 // Update an element in the cache.
180 void Update(Object* data, 117 void Update(Object* data,
181 String* name, 118 String* name,
182 Variable::Mode mode, 119 VariableMode mode,
183 int slot_index); 120 int slot_index);
184 121
185 // Clear the cache. 122 // Clear the cache.
186 void Clear(); 123 void Clear();
187 124
188 static const int kNotFound = -2; 125 static const int kNotFound = -2;
189 126
190 private: 127 private:
191 ContextSlotCache() { 128 ContextSlotCache() {
192 for (int i = 0; i < kLength; ++i) { 129 for (int i = 0; i < kLength; ++i) {
193 keys_[i].data = NULL; 130 keys_[i].data = NULL;
194 keys_[i].name = NULL; 131 keys_[i].name = NULL;
195 values_[i] = kNotFound; 132 values_[i] = kNotFound;
196 } 133 }
197 } 134 }
198 135
199 inline static int Hash(Object* data, String* name); 136 inline static int Hash(Object* data, String* name);
200 137
201 #ifdef DEBUG 138 #ifdef DEBUG
202 void ValidateEntry(Object* data, 139 void ValidateEntry(Object* data,
203 String* name, 140 String* name,
204 Variable::Mode mode, 141 VariableMode mode,
205 int slot_index); 142 int slot_index);
206 #endif 143 #endif
207 144
208 static const int kLength = 256; 145 static const int kLength = 256;
209 struct Key { 146 struct Key {
210 Object* data; 147 Object* data;
211 String* name; 148 String* name;
212 }; 149 };
213 150
214 struct Value { 151 struct Value {
215 Value(Variable::Mode mode, int index) { 152 Value(VariableMode mode, int index) {
216 ASSERT(ModeField::is_valid(mode)); 153 ASSERT(ModeField::is_valid(mode));
217 ASSERT(IndexField::is_valid(index)); 154 ASSERT(IndexField::is_valid(index));
218 value_ = ModeField::encode(mode) | IndexField::encode(index); 155 value_ = ModeField::encode(mode) | IndexField::encode(index);
219 ASSERT(mode == this->mode()); 156 ASSERT(mode == this->mode());
220 ASSERT(index == this->index()); 157 ASSERT(index == this->index());
221 } 158 }
222 159
223 explicit inline Value(uint32_t value) : value_(value) {} 160 explicit inline Value(uint32_t value) : value_(value) {}
224 161
225 uint32_t raw() { return value_; } 162 uint32_t raw() { return value_; }
226 163
227 Variable::Mode mode() { return ModeField::decode(value_); } 164 VariableMode mode() { return ModeField::decode(value_); }
228 165
229 int index() { return IndexField::decode(value_); } 166 int index() { return IndexField::decode(value_); }
230 167
231 // Bit fields in value_ (type, shift, size). Must be public so the 168 // Bit fields in value_ (type, shift, size). Must be public so the
232 // constants can be embedded in generated code. 169 // constants can be embedded in generated code.
233 class ModeField: public BitField<Variable::Mode, 0, 3> {}; 170 class ModeField: public BitField<VariableMode, 0, 3> {};
234 class IndexField: public BitField<int, 3, 32-3> {}; 171 class IndexField: public BitField<int, 3, 32-3> {};
235 private: 172 private:
236 uint32_t value_; 173 uint32_t value_;
237 }; 174 };
238 175
239 Key keys_[kLength]; 176 Key keys_[kLength];
240 uint32_t values_[kLength]; 177 uint32_t values_[kLength];
241 178
242 friend class Isolate; 179 friend class Isolate;
243 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache); 180 DISALLOW_COPY_AND_ASSIGN(ContextSlotCache);
244 }; 181 };
245 182
246 183
247 } } // namespace v8::internal 184 } } // namespace v8::internal
248 185
249 #endif // V8_SCOPEINFO_H_ 186 #endif // V8_SCOPEINFO_H_
OLDNEW
« src/parser.cc ('K') | « src/parser.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698