OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 | 138 |
139 | 139 |
140 class Type : public Object { | 140 class Type : public Object { |
141 public: | 141 public: |
142 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | 142 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
143 static Type* type() { return from_bitset(k##type); } | 143 static Type* type() { return from_bitset(k##type); } |
144 TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) | 144 TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) |
145 #undef DEFINE_TYPE_CONSTRUCTOR | 145 #undef DEFINE_TYPE_CONSTRUCTOR |
146 | 146 |
147 static Type* Class(Handle<Map> map) { return from_handle(map); } | 147 static Type* Class(Handle<i::Map> map) { return from_handle(map); } |
148 static Type* Constant(Handle<HeapObject> value) { | 148 static Type* Constant(Handle<i::HeapObject> value) { |
149 return Constant(value, value->GetIsolate()); | 149 return Constant(value, value->GetIsolate()); |
150 } | 150 } |
151 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) { | 151 static Type* Constant(Handle<i::Object> value, Isolate* isolate) { |
152 return from_handle(isolate->factory()->NewBox(value)); | 152 return from_handle(isolate->factory()->NewBox(value)); |
153 } | 153 } |
154 | 154 |
155 static Type* Union(Handle<Type> type1, Handle<Type> type2); | 155 static Type* Union(Handle<Type> type1, Handle<Type> type2); |
156 static Type* Intersect(Handle<Type> type1, Handle<Type> type2); | 156 static Type* Intersect(Handle<Type> type1, Handle<Type> type2); |
157 static Type* Optional(Handle<Type> type); // type \/ Undefined | 157 static Type* Optional(Handle<Type> type); // type \/ Undefined |
158 | 158 |
| 159 static Type* Of(Handle<i::Object> value) { |
| 160 return from_bitset(LubBitset(*value)); |
| 161 } |
| 162 static Type* CurrentOf(Handle<i::Object> value); |
| 163 |
159 bool Is(Type* that) { return (this == that) ? true : SlowIs(that); } | 164 bool Is(Type* that) { return (this == that) ? true : SlowIs(that); } |
160 bool Is(Handle<Type> that) { return this->Is(*that); } | 165 bool Is(Handle<Type> that) { return this->Is(*that); } |
161 bool Maybe(Type* that); | 166 bool Maybe(Type* that); |
162 bool Maybe(Handle<Type> that) { return this->Maybe(*that); } | 167 bool Maybe(Handle<Type> that) { return this->Maybe(*that); } |
163 | 168 |
164 bool IsClass() { return is_class(); } | 169 bool IsClass() { return is_class(); } |
165 bool IsConstant() { return is_constant(); } | 170 bool IsConstant() { return is_constant(); } |
166 Handle<Map> AsClass() { return as_class(); } | 171 Handle<i::Map> AsClass() { return as_class(); } |
167 Handle<v8::internal::Object> AsConstant() { return as_constant(); } | 172 Handle<i::Object> AsConstant() { return as_constant(); } |
168 | 173 |
169 int NumClasses(); | 174 int NumClasses(); |
170 int NumConstants(); | 175 int NumConstants(); |
171 | 176 |
172 template<class T> | 177 template<class T> |
173 class Iterator { | 178 class Iterator { |
174 public: | 179 public: |
175 bool Done() const { return index_ < 0; } | 180 bool Done() const { return index_ < 0; } |
176 Handle<T> Current(); | 181 Handle<T> Current(); |
177 void Advance(); | 182 void Advance(); |
178 | 183 |
179 private: | 184 private: |
180 friend class Type; | 185 friend class Type; |
181 | 186 |
182 Iterator() : index_(-1) {} | 187 Iterator() : index_(-1) {} |
183 explicit Iterator(Handle<Type> type) : type_(type), index_(-1) { | 188 explicit Iterator(Handle<Type> type) : type_(type), index_(-1) { |
184 Advance(); | 189 Advance(); |
185 } | 190 } |
186 | 191 |
187 inline bool matches(Handle<Type> type); | 192 inline bool matches(Handle<Type> type); |
188 inline Handle<Type> get_type(); | 193 inline Handle<Type> get_type(); |
189 | 194 |
190 Handle<Type> type_; | 195 Handle<Type> type_; |
191 int index_; | 196 int index_; |
192 }; | 197 }; |
193 | 198 |
194 Iterator<Map> Classes() { | 199 Iterator<i::Map> Classes() { |
195 if (this->is_bitset()) return Iterator<Map>(); | 200 if (this->is_bitset()) return Iterator<i::Map>(); |
196 return Iterator<Map>(this->handle()); | 201 return Iterator<i::Map>(this->handle()); |
197 } | 202 } |
198 Iterator<v8::internal::Object> Constants() { | 203 Iterator<i::Object> Constants() { |
199 if (this->is_bitset()) return Iterator<v8::internal::Object>(); | 204 if (this->is_bitset()) return Iterator<i::Object>(); |
200 return Iterator<v8::internal::Object>(this->handle()); | 205 return Iterator<i::Object>(this->handle()); |
201 } | 206 } |
202 | 207 |
203 static Type* cast(v8::internal::Object* object) { | 208 static Type* cast(i::Object* object) { |
204 Type* t = static_cast<Type*>(object); | 209 Type* t = static_cast<Type*>(object); |
205 ASSERT(t->is_bitset() || t->is_class() || | 210 ASSERT(t->is_bitset() || t->is_class() || |
206 t->is_constant() || t->is_union()); | 211 t->is_constant() || t->is_union()); |
207 return t; | 212 return t; |
208 } | 213 } |
209 | 214 |
210 #ifdef OBJECT_PRINT | 215 #ifdef OBJECT_PRINT |
211 void TypePrint(); | 216 void TypePrint(); |
212 void TypePrint(FILE* out); | 217 void TypePrint(FILE* out); |
213 #endif | 218 #endif |
(...skipping 14 matching lines...) Expand all Loading... |
228 | 233 |
229 bool is_none() { return this == None(); } | 234 bool is_none() { return this == None(); } |
230 bool is_bitset() { return this->IsSmi(); } | 235 bool is_bitset() { return this->IsSmi(); } |
231 bool is_class() { return this->IsMap(); } | 236 bool is_class() { return this->IsMap(); } |
232 bool is_constant() { return this->IsBox(); } | 237 bool is_constant() { return this->IsBox(); } |
233 bool is_union() { return this->IsFixedArray(); } | 238 bool is_union() { return this->IsFixedArray(); } |
234 | 239 |
235 bool SlowIs(Type* that); | 240 bool SlowIs(Type* that); |
236 | 241 |
237 int as_bitset() { return Smi::cast(this)->value(); } | 242 int as_bitset() { return Smi::cast(this)->value(); } |
238 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } | 243 Handle<i::Map> as_class() { return Handle<i::Map>::cast(handle()); } |
239 Handle<v8::internal::Object> as_constant() { | 244 Handle<i::Object> as_constant() { |
240 Handle<Box> box = Handle<Box>::cast(handle()); | 245 Handle<i::Box> box = Handle<i::Box>::cast(handle()); |
241 return v8::internal::handle(box->value(), box->GetIsolate()); | 246 return i::handle(box->value(), box->GetIsolate()); |
242 } | 247 } |
243 Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); } | 248 Handle<Unioned> as_union() { return Handle<Unioned>::cast(handle()); } |
244 | 249 |
245 Handle<Type> handle() { return handle_via_isolate_of(this); } | 250 Handle<Type> handle() { return handle_via_isolate_of(this); } |
246 Handle<Type> handle_via_isolate_of(Type* type) { | 251 Handle<Type> handle_via_isolate_of(Type* type) { |
247 ASSERT(type->IsHeapObject()); | 252 ASSERT(type->IsHeapObject()); |
248 return v8::internal::handle(this, HeapObject::cast(type)->GetIsolate()); | 253 return i::handle(this, i::HeapObject::cast(type)->GetIsolate()); |
249 } | 254 } |
250 | 255 |
251 static Type* from_bitset(int bitset) { | 256 static Type* from_bitset(int bitset) { |
252 return static_cast<Type*>(Object::cast(Smi::FromInt(bitset))); | 257 return static_cast<Type*>(i::Object::cast(i::Smi::FromInt(bitset))); |
253 } | 258 } |
254 static Type* from_handle(Handle<HeapObject> handle) { | 259 static Type* from_handle(Handle<i::HeapObject> handle) { |
255 return static_cast<Type*>(Object::cast(*handle)); | 260 return static_cast<Type*>(i::Object::cast(*handle)); |
256 } | 261 } |
257 | 262 |
258 static Handle<Type> union_get(Handle<Unioned> unioned, int i) { | 263 static Handle<Type> union_get(Handle<Unioned> unioned, int i) { |
259 Type* type = static_cast<Type*>(unioned->get(i)); | 264 Type* type = static_cast<Type*>(unioned->get(i)); |
260 ASSERT(!type->is_union()); | 265 ASSERT(!type->is_union()); |
261 return type->handle_via_isolate_of(from_handle(unioned)); | 266 return type->handle_via_isolate_of(from_handle(unioned)); |
262 } | 267 } |
263 | 268 |
264 int LubBitset(); // least upper bound that's a bitset | 269 int LubBitset(); // least upper bound that's a bitset |
265 int GlbBitset(); // greatest lower bound that's a bitset | 270 int GlbBitset(); // greatest lower bound that's a bitset |
| 271 |
| 272 static int LubBitset(i::Object* value); |
| 273 static int LubBitset(i::Map* map); |
| 274 |
266 bool InUnion(Handle<Unioned> unioned, int current_size); | 275 bool InUnion(Handle<Unioned> unioned, int current_size); |
267 int ExtendUnion(Handle<Unioned> unioned, int current_size); | 276 int ExtendUnion(Handle<Unioned> unioned, int current_size); |
268 int ExtendIntersection( | 277 int ExtendIntersection( |
269 Handle<Unioned> unioned, Handle<Type> type, int current_size); | 278 Handle<Unioned> unioned, Handle<Type> type, int current_size); |
270 | 279 |
271 static const char* GetComposedName(int type) { | 280 static const char* GetComposedName(int type) { |
272 switch (type) { | 281 switch (type) { |
273 #define PRINT_COMPOSED_TYPE(type, value) \ | 282 #define PRINT_COMPOSED_TYPE(type, value) \ |
274 case k##type: \ | 283 case k##type: \ |
275 return # type; | 284 return # type; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) { | 351 static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) { |
343 return Bounds( | 352 return Bounds( |
344 handle(Type::Intersect(b.lower, t), isl), | 353 handle(Type::Intersect(b.lower, t), isl), |
345 handle(Type::Intersect(b.upper, t), isl)); | 354 handle(Type::Intersect(b.upper, t), isl)); |
346 } | 355 } |
347 }; | 356 }; |
348 | 357 |
349 } } // namespace v8::internal | 358 } } // namespace v8::internal |
350 | 359 |
351 #endif // V8_TYPES_H_ | 360 #endif // V8_TYPES_H_ |
OLD | NEW |