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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // - no field is a union | 219 // - no field is a union |
220 typedef FixedArray Unioned; | 220 typedef FixedArray Unioned; |
221 | 221 |
222 enum { | 222 enum { |
223 #define DECLARE_TYPE(type, value) k##type = (value), | 223 #define DECLARE_TYPE(type, value) k##type = (value), |
224 TYPE_LIST(DECLARE_TYPE) | 224 TYPE_LIST(DECLARE_TYPE) |
225 #undef DECLARE_TYPE | 225 #undef DECLARE_TYPE |
226 kUnusedEOL = 0 | 226 kUnusedEOL = 0 |
227 }; | 227 }; |
228 | 228 |
229 bool is_none() { return this == None(); } | |
230 bool is_bitset() { return this->IsSmi(); } | 229 bool is_bitset() { return this->IsSmi(); } |
231 bool is_class() { return this->IsMap(); } | 230 bool is_class() { return this->IsMap(); } |
232 bool is_constant() { return this->IsBox(); } | 231 bool is_constant() { return this->IsBox(); } |
233 bool is_union() { return this->IsFixedArray(); } | 232 bool is_union() { return this->IsFixedArray(); } |
234 | 233 |
235 bool SlowIs(Type* that); | 234 bool SlowIs(Type* that); |
236 | 235 |
237 int as_bitset() { return Smi::cast(this)->value(); } | 236 int as_bitset() { return Smi::cast(this)->value(); } |
238 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } | 237 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } |
239 Handle<v8::internal::Object> as_constant() { | 238 Handle<v8::internal::Object> as_constant() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 292 } |
294 }; | 293 }; |
295 | 294 |
296 | 295 |
297 // A simple struct to represent a pair of lower/upper type bounds. | 296 // A simple struct to represent a pair of lower/upper type bounds. |
298 struct Bounds { | 297 struct Bounds { |
299 Handle<Type> lower; | 298 Handle<Type> lower; |
300 Handle<Type> upper; | 299 Handle<Type> upper; |
301 | 300 |
302 Bounds() {} | 301 Bounds() {} |
303 Bounds(Handle<Type> l, Handle<Type> u) : lower(l), upper(u) { | 302 Bounds(Handle<Type> l, Handle<Type> u) : lower(l), upper(u) {} |
304 ASSERT(lower->Is(upper)); | 303 Bounds(Type* l, Type* u, Isolate* isl) : lower(l, isl), upper(u, isl) {} |
305 } | 304 explicit Bounds(Handle<Type> t) : lower(t), upper(t) {} |
306 Bounds(Type* l, Type* u, Isolate* isl) : lower(l, isl), upper(u, isl) { | 305 Bounds(Type* t, Isolate* isl) : lower(t, isl), upper(t, isl) {} |
307 ASSERT(lower->Is(upper)); | |
308 } | |
309 explicit Bounds(Handle<Type> t) : lower(t), upper(t) { | |
310 ASSERT(lower->Is(upper)); | |
311 } | |
312 Bounds(Type* t, Isolate* isl) : lower(t, isl), upper(t, isl) { | |
313 ASSERT(lower->Is(upper)); | |
314 } | |
315 | 306 |
316 // Unrestricted bounds. | 307 // Unrestricted bounds. |
317 static Bounds Unbounded(Isolate* isl) { | 308 static Bounds Unbounded(Isolate* isl) { |
318 return Bounds(Type::None(), Type::Any(), isl); | 309 return Bounds(Type::None(), Type::Any(), isl); |
319 } | 310 } |
320 | 311 |
321 // Meet: both b1 and b2 are known to hold. | 312 // Meet: both b1 and b2 are known to hold. |
322 static Bounds Both(Bounds b1, Bounds b2, Isolate* isl) { | 313 static Bounds Both(Bounds b1, Bounds b2, Isolate* isl) { |
323 Handle<Type> lower(Type::Union(b1.lower, b2.lower), isl); | 314 return Bounds( |
324 Handle<Type> upper(Type::Intersect(b1.upper, b2.upper), isl); | 315 handle(Type::Union(b1.lower, b2.lower), isl), |
325 // Lower bounds are considered approximate, correct as necessary. | 316 handle(Type::Intersect(b1.upper, b2.upper), isl)); |
326 lower = handle(Type::Intersect(lower, upper), isl); | |
327 return Bounds(lower, upper); | |
328 } | 317 } |
329 | 318 |
330 // Join: either b1 or b2 is known to hold. | 319 // Join: either b1 or b2 is known to hold. |
331 static Bounds Either(Bounds b1, Bounds b2, Isolate* isl) { | 320 static Bounds Either(Bounds b1, Bounds b2, Isolate* isl) { |
332 return Bounds( | 321 return Bounds( |
333 handle(Type::Intersect(b1.lower, b2.lower), isl), | 322 handle(Type::Intersect(b1.lower, b2.lower), isl), |
334 handle(Type::Union(b1.upper, b2.upper), isl)); | 323 handle(Type::Union(b1.upper, b2.upper), isl)); |
335 } | 324 } |
336 | 325 |
337 static Bounds NarrowLower(Bounds b, Handle<Type> t, Isolate* isl) { | 326 static Bounds NarrowLower(Bounds b, Handle<Type> t, Isolate* isl) { |
338 // Lower bounds are considered approximate, correct as necessary. | |
339 t = handle(Type::Intersect(t, b.upper), isl); | |
340 return Bounds(handle(Type::Union(b.lower, t), isl), b.upper); | 327 return Bounds(handle(Type::Union(b.lower, t), isl), b.upper); |
341 } | 328 } |
342 static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) { | 329 static Bounds NarrowUpper(Bounds b, Handle<Type> t, Isolate* isl) { |
343 return Bounds( | 330 return Bounds(b.lower, handle(Type::Intersect(b.upper, t), isl)); |
344 handle(Type::Intersect(b.lower, t), isl), | |
345 handle(Type::Intersect(b.upper, t), isl)); | |
346 } | 331 } |
347 }; | 332 }; |
348 | 333 |
349 } } // namespace v8::internal | 334 } } // namespace v8::internal |
350 | 335 |
351 #endif // V8_TYPES_H_ | 336 #endif // V8_TYPES_H_ |
OLD | NEW |