OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 class TypeInfo { | 48 class TypeInfo { |
49 public: | 49 public: |
50 TypeInfo() : type_(kUnknownType) { } | 50 TypeInfo() : type_(kUnknownType) { } |
51 | 51 |
52 static inline TypeInfo Unknown(); | 52 static inline TypeInfo Unknown(); |
53 // We know it's a primitive type. | 53 // We know it's a primitive type. |
54 static inline TypeInfo Primitive(); | 54 static inline TypeInfo Primitive(); |
55 // We know it's a number of some sort. | 55 // We know it's a number of some sort. |
56 static inline TypeInfo Number(); | 56 static inline TypeInfo Number(); |
57 // We know it's signed or unsigned 32 bit integer. | 57 // We know it's signed 32 bit integer. |
58 static inline TypeInfo Integer32(); | 58 static inline TypeInfo Integer32(); |
59 // We know it's a Smi. | 59 // We know it's a Smi. |
60 static inline TypeInfo Smi(); | 60 static inline TypeInfo Smi(); |
61 // We know it's a heap number. | 61 // We know it's a heap number. |
62 static inline TypeInfo Double(); | 62 static inline TypeInfo Double(); |
63 // We know it's a string. | 63 // We know it's a string. |
64 static inline TypeInfo String(); | 64 static inline TypeInfo String(); |
65 // We haven't started collecting info yet. | 65 // We haven't started collecting info yet. |
66 static inline TypeInfo Uninitialized(); | 66 static inline TypeInfo Uninitialized(); |
67 | 67 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 t == kStringType); | 106 t == kStringType); |
107 return TypeInfo(t); | 107 return TypeInfo(t); |
108 } | 108 } |
109 | 109 |
110 // Return the weakest (least precise) common type. | 110 // Return the weakest (least precise) common type. |
111 static TypeInfo Combine(TypeInfo a, TypeInfo b) { | 111 static TypeInfo Combine(TypeInfo a, TypeInfo b) { |
112 return TypeInfo(static_cast<Type>(a.type_ & b.type_)); | 112 return TypeInfo(static_cast<Type>(a.type_ & b.type_)); |
113 } | 113 } |
114 | 114 |
115 | 115 |
116 // Integer32 is an integer that can be represented as either a signed | 116 // Integer32 is an integer that can be represented as a signed |
117 // 32-bit integer or as an unsigned 32-bit integer. It has to be | 117 // 32-bit integer. It has to be in the range [-2^31, 2^31 - 1]. |
118 // in the range [-2^31, 2^32 - 1]. We also have to check for negative 0 | 118 // We also have to check for negative 0 as it is not an Integer32. |
119 // as it is not an Integer32. | |
120 static inline bool IsInt32Double(double value) { | 119 static inline bool IsInt32Double(double value) { |
121 const DoubleRepresentation minus_zero(-0.0); | 120 const DoubleRepresentation minus_zero(-0.0); |
122 DoubleRepresentation rep(value); | 121 DoubleRepresentation rep(value); |
123 if (rep.bits == minus_zero.bits) return false; | 122 if (rep.bits == minus_zero.bits) return false; |
124 if (value >= kMinInt && value <= kMaxUInt32) { | 123 if (value >= kMinInt && value <= kMaxInt) { |
125 if (value <= kMaxInt && value == static_cast<int32_t>(value)) { | 124 if (value == static_cast<int32_t>(value)) return true; |
126 return true; | |
127 } | |
128 if (value == static_cast<uint32_t>(value)) return true; | |
129 } | 125 } |
130 return false; | 126 return false; |
131 } | 127 } |
132 | 128 |
133 static TypeInfo TypeFromValue(Handle<Object> value); | 129 static TypeInfo TypeFromValue(Handle<Object> value); |
134 | 130 |
135 inline bool IsUnknown() { | 131 inline bool IsUnknown() { |
136 return type_ == kUnknownType; | 132 return type_ == kUnknownType; |
137 } | 133 } |
138 | 134 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 231 } |
236 | 232 |
237 | 233 |
238 TypeInfo TypeInfo::Uninitialized() { | 234 TypeInfo TypeInfo::Uninitialized() { |
239 return TypeInfo(kUninitializedType); | 235 return TypeInfo(kUninitializedType); |
240 } | 236 } |
241 | 237 |
242 } } // namespace v8::internal | 238 } } // namespace v8::internal |
243 | 239 |
244 #endif // V8_TYPE_INFO_H_ | 240 #endif // V8_TYPE_INFO_H_ |
OLD | NEW |