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 HYDROGEN_TYPES_H_ | 5 #ifndef HYDROGEN_TYPES_H_ |
6 #define HYDROGEN_TYPES_H_ | 6 #define HYDROGEN_TYPES_H_ |
7 | 7 |
8 #include <climits> | 8 #include <climits> |
9 | 9 |
10 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 V(HeapPrimitive, 0x25) /* 0000 0000 0010 0101 */ \ | 27 V(HeapPrimitive, 0x25) /* 0000 0000 0010 0101 */ \ |
28 V(Null, 0x27) /* 0000 0000 0010 0111 */ \ | 28 V(Null, 0x27) /* 0000 0000 0010 0111 */ \ |
29 V(HeapNumber, 0x2d) /* 0000 0000 0010 1101 */ \ | 29 V(HeapNumber, 0x2d) /* 0000 0000 0010 1101 */ \ |
30 V(String, 0x65) /* 0000 0000 0110 0101 */ \ | 30 V(String, 0x65) /* 0000 0000 0110 0101 */ \ |
31 V(Boolean, 0xa5) /* 0000 0000 1010 0101 */ \ | 31 V(Boolean, 0xa5) /* 0000 0000 1010 0101 */ \ |
32 V(Undefined, 0x125) /* 0000 0001 0010 0101 */ \ | 32 V(Undefined, 0x125) /* 0000 0001 0010 0101 */ \ |
33 V(JSObject, 0x221) /* 0000 0010 0010 0001 */ \ | 33 V(JSObject, 0x221) /* 0000 0010 0010 0001 */ \ |
34 V(JSArray, 0x621) /* 0000 0110 0010 0001 */ \ | 34 V(JSArray, 0x621) /* 0000 0110 0010 0001 */ \ |
35 V(None, 0x7ff) /* 0000 0111 1111 1111 */ | 35 V(None, 0x7ff) /* 0000 0111 1111 1111 */ |
36 | 36 |
37 class HType V8_FINAL { | 37 class HType FINAL { |
38 public: | 38 public: |
39 #define DECLARE_CONSTRUCTOR(Name, mask) \ | 39 #define DECLARE_CONSTRUCTOR(Name, mask) \ |
40 static HType Name() V8_WARN_UNUSED_RESULT { return HType(k##Name); } | 40 static HType Name() WARN_UNUSED_RESULT { return HType(k##Name); } |
41 HTYPE_LIST(DECLARE_CONSTRUCTOR) | 41 HTYPE_LIST(DECLARE_CONSTRUCTOR) |
42 #undef DECLARE_CONSTRUCTOR | 42 #undef DECLARE_CONSTRUCTOR |
43 | 43 |
44 // Return the weakest (least precise) common type. | 44 // Return the weakest (least precise) common type. |
45 HType Combine(HType other) const V8_WARN_UNUSED_RESULT { | 45 HType Combine(HType other) const WARN_UNUSED_RESULT { |
46 return HType(static_cast<Kind>(kind_ & other.kind_)); | 46 return HType(static_cast<Kind>(kind_ & other.kind_)); |
47 } | 47 } |
48 | 48 |
49 bool Equals(HType other) const V8_WARN_UNUSED_RESULT { | 49 bool Equals(HType other) const WARN_UNUSED_RESULT { |
50 return kind_ == other.kind_; | 50 return kind_ == other.kind_; |
51 } | 51 } |
52 | 52 |
53 bool IsSubtypeOf(HType other) const V8_WARN_UNUSED_RESULT { | 53 bool IsSubtypeOf(HType other) const WARN_UNUSED_RESULT { |
54 return Combine(other).Equals(other); | 54 return Combine(other).Equals(other); |
55 } | 55 } |
56 | 56 |
57 #define DECLARE_IS_TYPE(Name, mask) \ | 57 #define DECLARE_IS_TYPE(Name, mask) \ |
58 bool Is##Name() const V8_WARN_UNUSED_RESULT { \ | 58 bool Is##Name() const WARN_UNUSED_RESULT { \ |
59 return IsSubtypeOf(HType::Name()); \ | 59 return IsSubtypeOf(HType::Name()); \ |
60 } | 60 } |
61 HTYPE_LIST(DECLARE_IS_TYPE) | 61 HTYPE_LIST(DECLARE_IS_TYPE) |
62 #undef DECLARE_IS_TYPE | 62 #undef DECLARE_IS_TYPE |
63 | 63 |
64 template <class T> | 64 template <class T> |
65 static HType FromType(typename T::TypeHandle type) V8_WARN_UNUSED_RESULT; | 65 static HType FromType(typename T::TypeHandle type) WARN_UNUSED_RESULT; |
66 static HType FromValue(Handle<Object> value) V8_WARN_UNUSED_RESULT; | 66 static HType FromValue(Handle<Object> value) WARN_UNUSED_RESULT; |
67 | 67 |
68 friend OStream& operator<<(OStream& os, const HType& t); | 68 friend OStream& operator<<(OStream& os, const HType& t); |
69 | 69 |
70 private: | 70 private: |
71 enum Kind { | 71 enum Kind { |
72 #define DECLARE_TYPE(Name, mask) k##Name = mask, | 72 #define DECLARE_TYPE(Name, mask) k##Name = mask, |
73 HTYPE_LIST(DECLARE_TYPE) | 73 HTYPE_LIST(DECLARE_TYPE) |
74 #undef DECLARE_TYPE | 74 #undef DECLARE_TYPE |
75 LAST_KIND = kNone | 75 LAST_KIND = kNone |
76 }; | 76 }; |
77 | 77 |
78 // Make sure type fits in int16. | 78 // Make sure type fits in int16. |
79 STATIC_ASSERT(LAST_KIND < (1 << (CHAR_BIT * sizeof(int16_t)))); | 79 STATIC_ASSERT(LAST_KIND < (1 << (CHAR_BIT * sizeof(int16_t)))); |
80 | 80 |
81 explicit HType(Kind kind) : kind_(kind) { } | 81 explicit HType(Kind kind) : kind_(kind) { } |
82 | 82 |
83 int16_t kind_; | 83 int16_t kind_; |
84 }; | 84 }; |
85 | 85 |
86 | 86 |
87 OStream& operator<<(OStream& os, const HType& t); | 87 OStream& operator<<(OStream& os, const HType& t); |
88 } } // namespace v8::internal | 88 } } // namespace v8::internal |
89 | 89 |
90 #endif // HYDROGEN_TYPES_H_ | 90 #endif // HYDROGEN_TYPES_H_ |
OLD | NEW |