OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_TYPES_H_ | 5 #ifndef V8_TYPES_H_ |
6 #define V8_TYPES_H_ | 6 #define V8_TYPES_H_ |
7 | 7 |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/ostreams.h" | 10 #include "src/ostreams.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 V(String, kInternalizedString | kOtherString) \ | 197 V(String, kInternalizedString | kOtherString) \ |
198 V(UniqueName, kSymbol | kInternalizedString) \ | 198 V(UniqueName, kSymbol | kInternalizedString) \ |
199 V(Name, kSymbol | kString) \ | 199 V(Name, kSymbol | kString) \ |
200 V(NumberOrString, kNumber | kString) \ | 200 V(NumberOrString, kNumber | kString) \ |
201 V(Primitive, kNumber | kName | kBoolean | kNull | kUndefined) \ | 201 V(Primitive, kNumber | kName | kBoolean | kNull | kUndefined) \ |
202 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \ | 202 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \ |
203 V(DetectableReceiver, kDetectableObject | kProxy) \ | 203 V(DetectableReceiver, kDetectableObject | kProxy) \ |
204 V(Detectable, kDetectableReceiver | kNumber | kName) \ | 204 V(Detectable, kDetectableReceiver | kNumber | kName) \ |
205 V(Object, kDetectableObject | kUndetectable) \ | 205 V(Object, kDetectableObject | kUndetectable) \ |
206 V(Receiver, kObject | kProxy) \ | 206 V(Receiver, kObject | kProxy) \ |
207 V(NonNumber, kBoolean | kName | kNull | kReceiver | \ | 207 V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \ |
208 kUndefined | kInternal) \ | 208 kReceiver) \ |
| 209 V(NonNumber, kUnique | kString | kInternal) \ |
209 V(Any, -1) | 210 V(Any, -1) |
210 | 211 |
211 #define BITSET_TYPE_LIST(V) \ | 212 #define BITSET_TYPE_LIST(V) \ |
212 MASK_BITSET_TYPE_LIST(V) \ | 213 MASK_BITSET_TYPE_LIST(V) \ |
213 REPRESENTATION_BITSET_TYPE_LIST(V) \ | 214 REPRESENTATION_BITSET_TYPE_LIST(V) \ |
214 SEMANTIC_BITSET_TYPE_LIST(V) | 215 SEMANTIC_BITSET_TYPE_LIST(V) |
215 | 216 |
216 | 217 |
217 // ----------------------------------------------------------------------------- | 218 // ----------------------------------------------------------------------------- |
218 // The abstract Type class, parameterized over the low-level representation. | 219 // The abstract Type class, parameterized over the low-level representation. |
219 | 220 |
220 // struct Config { | 221 // struct Config { |
221 // typedef TypeImpl<Config> Type; | 222 // typedef TypeImpl<Config> Type; |
222 // typedef Base; | 223 // typedef Base; |
223 // typedef Struct; | 224 // typedef Struct; |
224 // typedef Region; | 225 // typedef Region; |
225 // template<class> struct Handle { typedef type; } // No template typedefs... | 226 // template<class> struct Handle { typedef type; } // No template typedefs... |
| 227 // template<class T> static Handle<T>::type null_handle(); |
226 // template<class T> static Handle<T>::type handle(T* t); // !is_bitset(t) | 228 // template<class T> static Handle<T>::type handle(T* t); // !is_bitset(t) |
227 // template<class T> static Handle<T>::type cast(Handle<Type>::type); | 229 // template<class T> static Handle<T>::type cast(Handle<Type>::type); |
228 // static bool is_bitset(Type*); | 230 // static bool is_bitset(Type*); |
229 // static bool is_class(Type*); | 231 // static bool is_class(Type*); |
230 // static bool is_struct(Type*, int tag); | 232 // static bool is_struct(Type*, int tag); |
231 // static int as_bitset(Type*); | 233 // static int as_bitset(Type*); |
232 // static i::Handle<i::Map> as_class(Type*); | 234 // static i::Handle<i::Map> as_class(Type*); |
233 // static Handle<Struct>::type as_struct(Type*); | 235 // static Handle<Struct>::type as_struct(Type*); |
234 // static Type* from_bitset(int bitset); | 236 // static Type* from_bitset(int bitset); |
235 // static Handle<Type>::type from_bitset(int bitset, Region*); | 237 // static Handle<Type>::type from_bitset(int bitset, Region*); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 TypeHandle param2, Region* region) { | 325 TypeHandle param2, Region* region) { |
324 FunctionHandle function = Function(result, Any(region), 3, region); | 326 FunctionHandle function = Function(result, Any(region), 3, region); |
325 function->InitParameter(0, param0); | 327 function->InitParameter(0, param0); |
326 function->InitParameter(1, param1); | 328 function->InitParameter(1, param1); |
327 function->InitParameter(2, param2); | 329 function->InitParameter(2, param2); |
328 return function; | 330 return function; |
329 } | 331 } |
330 | 332 |
331 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); | 333 static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg); |
332 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); | 334 static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg); |
| 335 static TypeImpl* Union(TypeImpl* type1, TypeImpl* type2) { |
| 336 return BitsetType::New(type1->AsBitset() | type2->AsBitset()); |
| 337 } |
| 338 static TypeImpl* Intersect(TypeImpl* type1, TypeImpl* type2) { |
| 339 return BitsetType::New(type1->AsBitset() & type2->AsBitset()); |
| 340 } |
333 | 341 |
334 static TypeHandle Of(double value, Region* region) { | 342 static TypeHandle Of(double value, Region* region) { |
335 return Config::from_bitset(BitsetType::Lub(value), region); | 343 return Config::from_bitset(BitsetType::Lub(value), region); |
336 } | 344 } |
337 static TypeHandle Of(i::Object* value, Region* region) { | 345 static TypeHandle Of(i::Object* value, Region* region) { |
338 return Config::from_bitset(BitsetType::Lub(value), region); | 346 return Config::from_bitset(BitsetType::Lub(value), region); |
339 } | 347 } |
340 static TypeHandle Of(i::Handle<i::Object> value, Region* region) { | 348 static TypeHandle Of(i::Handle<i::Object> value, Region* region) { |
341 return Of(*value, region); | 349 return Of(*value, region); |
342 } | 350 } |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 class Base {}; | 859 class Base {}; |
852 typedef void* Struct; | 860 typedef void* Struct; |
853 typedef i::Zone Region; | 861 typedef i::Zone Region; |
854 template<class T> struct Handle { typedef T* type; }; | 862 template<class T> struct Handle { typedef T* type; }; |
855 | 863 |
856 // TODO(neis): This will be removed again once we have struct_get_double(). | 864 // TODO(neis): This will be removed again once we have struct_get_double(). |
857 static inline i::Isolate* isolate(Region* region) { | 865 static inline i::Isolate* isolate(Region* region) { |
858 return region->isolate(); | 866 return region->isolate(); |
859 } | 867 } |
860 | 868 |
| 869 template<class T> static inline T* null_handle(); |
861 template<class T> static inline T* handle(T* type); | 870 template<class T> static inline T* handle(T* type); |
862 template<class T> static inline T* cast(Type* type); | 871 template<class T> static inline T* cast(Type* type); |
863 | 872 |
864 static inline bool is_bitset(Type* type); | 873 static inline bool is_bitset(Type* type); |
865 static inline bool is_class(Type* type); | 874 static inline bool is_class(Type* type); |
866 static inline bool is_struct(Type* type, int tag); | 875 static inline bool is_struct(Type* type, int tag); |
867 | 876 |
868 static inline int as_bitset(Type* type); | 877 static inline int as_bitset(Type* type); |
869 static inline i::Handle<i::Map> as_class(Type* type); | 878 static inline i::Handle<i::Map> as_class(Type* type); |
870 static inline Struct* as_struct(Type* type); | 879 static inline Struct* as_struct(Type* type); |
(...skipping 27 matching lines...) Expand all Loading... |
898 typedef i::Object Base; | 907 typedef i::Object Base; |
899 typedef i::FixedArray Struct; | 908 typedef i::FixedArray Struct; |
900 typedef i::Isolate Region; | 909 typedef i::Isolate Region; |
901 template<class T> struct Handle { typedef i::Handle<T> type; }; | 910 template<class T> struct Handle { typedef i::Handle<T> type; }; |
902 | 911 |
903 // TODO(neis): This will be removed again once we have struct_get_double(). | 912 // TODO(neis): This will be removed again once we have struct_get_double(). |
904 static inline i::Isolate* isolate(Region* region) { | 913 static inline i::Isolate* isolate(Region* region) { |
905 return region; | 914 return region; |
906 } | 915 } |
907 | 916 |
| 917 template<class T> static inline i::Handle<T> null_handle(); |
908 template<class T> static inline i::Handle<T> handle(T* type); | 918 template<class T> static inline i::Handle<T> handle(T* type); |
909 template<class T> static inline i::Handle<T> cast(i::Handle<Type> type); | 919 template<class T> static inline i::Handle<T> cast(i::Handle<Type> type); |
910 | 920 |
911 static inline bool is_bitset(Type* type); | 921 static inline bool is_bitset(Type* type); |
912 static inline bool is_class(Type* type); | 922 static inline bool is_class(Type* type); |
913 static inline bool is_struct(Type* type, int tag); | 923 static inline bool is_struct(Type* type, int tag); |
914 | 924 |
915 static inline int as_bitset(Type* type); | 925 static inline int as_bitset(Type* type); |
916 static inline i::Handle<i::Map> as_class(Type* type); | 926 static inline i::Handle<i::Map> as_class(Type* type); |
917 static inline i::Handle<Struct> as_struct(Type* type); | 927 static inline i::Handle<Struct> as_struct(Type* type); |
(...skipping 28 matching lines...) Expand all Loading... |
946 | 956 |
947 template<class Config> | 957 template<class Config> |
948 struct BoundsImpl { | 958 struct BoundsImpl { |
949 typedef TypeImpl<Config> Type; | 959 typedef TypeImpl<Config> Type; |
950 typedef typename Type::TypeHandle TypeHandle; | 960 typedef typename Type::TypeHandle TypeHandle; |
951 typedef typename Type::Region Region; | 961 typedef typename Type::Region Region; |
952 | 962 |
953 TypeHandle lower; | 963 TypeHandle lower; |
954 TypeHandle upper; | 964 TypeHandle upper; |
955 | 965 |
956 BoundsImpl() {} | 966 BoundsImpl() : // Make sure accessing uninitialized bounds crashes big-time. |
| 967 lower(Config::template null_handle<Type>()), |
| 968 upper(Config::template null_handle<Type>()) {} |
957 explicit BoundsImpl(TypeHandle t) : lower(t), upper(t) {} | 969 explicit BoundsImpl(TypeHandle t) : lower(t), upper(t) {} |
958 BoundsImpl(TypeHandle l, TypeHandle u) : lower(l), upper(u) { | 970 BoundsImpl(TypeHandle l, TypeHandle u) : lower(l), upper(u) { |
959 DCHECK(lower->Is(upper)); | 971 DCHECK(lower->Is(upper)); |
960 } | 972 } |
961 | 973 |
962 // Unrestricted bounds. | 974 // Unrestricted bounds. |
963 static BoundsImpl Unbounded(Region* region) { | 975 static BoundsImpl Unbounded(Region* region) { |
964 return BoundsImpl(Type::None(region), Type::Any(region)); | 976 return BoundsImpl(Type::None(region), Type::Any(region)); |
965 } | 977 } |
966 | 978 |
(...skipping 28 matching lines...) Expand all Loading... |
995 bool Narrows(BoundsImpl that) { | 1007 bool Narrows(BoundsImpl that) { |
996 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 1008 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
997 } | 1009 } |
998 }; | 1010 }; |
999 | 1011 |
1000 typedef BoundsImpl<ZoneTypeConfig> Bounds; | 1012 typedef BoundsImpl<ZoneTypeConfig> Bounds; |
1001 | 1013 |
1002 } } // namespace v8::internal | 1014 } } // namespace v8::internal |
1003 | 1015 |
1004 #endif // V8_TYPES_H_ | 1016 #endif // V8_TYPES_H_ |
OLD | NEW |