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_AST_AST_TYPES_H_ |
6 #define V8_TYPES_H_ | 6 #define V8_AST_AST_TYPES_H_ |
7 | 7 |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
11 #include "src/ostreams.h" | 11 #include "src/ostreams.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 // SUMMARY | 16 // SUMMARY |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // constructors and predicates (those prefixed 'Now'). | 137 // constructors and predicates (those prefixed 'Now'). |
138 // | 138 // |
139 // | 139 // |
140 // IMPLEMENTATION | 140 // IMPLEMENTATION |
141 // | 141 // |
142 // Internally, all 'primitive' types, and their unions, are represented as | 142 // Internally, all 'primitive' types, and their unions, are represented as |
143 // bitsets. Bit 0 is reserved for tagging. Class is a heap pointer to the | 143 // bitsets. Bit 0 is reserved for tagging. Class is a heap pointer to the |
144 // respective map. Only structured types require allocation. | 144 // respective map. Only structured types require allocation. |
145 // Note that the bitset representation is closed under both Union and Intersect. | 145 // Note that the bitset representation is closed under both Union and Intersect. |
146 | 146 |
147 | |
148 // ----------------------------------------------------------------------------- | 147 // ----------------------------------------------------------------------------- |
149 // Values for bitset types | 148 // Values for bitset types |
150 | 149 |
151 // clang-format off | 150 // clang-format off |
152 | 151 |
153 #define MASK_BITSET_TYPE_LIST(V) \ | 152 #define AST_MASK_BITSET_TYPE_LIST(V) \ |
154 V(Representation, 0xffc00000u) \ | 153 V(Representation, 0xffc00000u) \ |
155 V(Semantic, 0x003ffffeu) | 154 V(Semantic, 0x003ffffeu) |
156 | 155 |
157 #define REPRESENTATION(k) ((k) & BitsetType::kRepresentation) | 156 #define AST_REPRESENTATION(k) ((k) & AstBitsetType::kRepresentation) |
158 #define SEMANTIC(k) ((k) & BitsetType::kSemantic) | 157 #define AST_SEMANTIC(k) ((k) & AstBitsetType::kSemantic) |
159 | 158 |
160 #define REPRESENTATION_BITSET_TYPE_LIST(V) \ | 159 #define AST_REPRESENTATION_BITSET_TYPE_LIST(V) \ |
161 V(None, 0) \ | 160 V(None, 0) \ |
162 V(UntaggedBit, 1u << 22 | kSemantic) \ | 161 V(UntaggedBit, 1u << 22 | kSemantic) \ |
163 V(UntaggedIntegral8, 1u << 23 | kSemantic) \ | 162 V(UntaggedIntegral8, 1u << 23 | kSemantic) \ |
164 V(UntaggedIntegral16, 1u << 24 | kSemantic) \ | 163 V(UntaggedIntegral16, 1u << 24 | kSemantic) \ |
165 V(UntaggedIntegral32, 1u << 25 | kSemantic) \ | 164 V(UntaggedIntegral32, 1u << 25 | kSemantic) \ |
166 V(UntaggedFloat32, 1u << 26 | kSemantic) \ | 165 V(UntaggedFloat32, 1u << 26 | kSemantic) \ |
167 V(UntaggedFloat64, 1u << 27 | kSemantic) \ | 166 V(UntaggedFloat64, 1u << 27 | kSemantic) \ |
168 V(UntaggedSimd128, 1u << 28 | kSemantic) \ | 167 V(UntaggedSimd128, 1u << 28 | kSemantic) \ |
169 V(UntaggedPointer, 1u << 29 | kSemantic) \ | 168 V(UntaggedPointer, 1u << 29 | kSemantic) \ |
170 V(TaggedSigned, 1u << 30 | kSemantic) \ | 169 V(TaggedSigned, 1u << 30 | kSemantic) \ |
171 V(TaggedPointer, 1u << 31 | kSemantic) \ | 170 V(TaggedPointer, 1u << 31 | kSemantic) \ |
172 \ | 171 \ |
173 V(UntaggedIntegral, kUntaggedBit | kUntaggedIntegral8 | \ | 172 V(UntaggedIntegral, kUntaggedBit | kUntaggedIntegral8 | \ |
174 kUntaggedIntegral16 | kUntaggedIntegral32) \ | 173 kUntaggedIntegral16 | kUntaggedIntegral32) \ |
175 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \ | 174 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \ |
176 V(UntaggedNumber, kUntaggedIntegral | kUntaggedFloat) \ | 175 V(UntaggedNumber, kUntaggedIntegral | kUntaggedFloat) \ |
177 V(Untagged, kUntaggedNumber | kUntaggedPointer) \ | 176 V(Untagged, kUntaggedNumber | kUntaggedPointer) \ |
178 V(Tagged, kTaggedSigned | kTaggedPointer) | 177 V(Tagged, kTaggedSigned | kTaggedPointer) |
179 | 178 |
180 #define INTERNAL_BITSET_TYPE_LIST(V) \ | 179 #define AST_INTERNAL_BITSET_TYPE_LIST(V) \ |
181 V(OtherUnsigned31, 1u << 1 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 180 V(OtherUnsigned31, 1u << 1 | AST_REPRESENTATION(kTagged | kUntaggedNumber)) \ |
182 V(OtherUnsigned32, 1u << 2 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 181 V(OtherUnsigned32, 1u << 2 | AST_REPRESENTATION(kTagged | kUntaggedNumber)) \ |
183 V(OtherSigned32, 1u << 3 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 182 V(OtherSigned32, 1u << 3 | AST_REPRESENTATION(kTagged | kUntaggedNumber)) \ |
184 V(OtherNumber, 1u << 4 | REPRESENTATION(kTagged | kUntaggedNumber)) | 183 V(OtherNumber, 1u << 4 | AST_REPRESENTATION(kTagged | kUntaggedNumber)) |
185 | 184 |
186 #define SEMANTIC_BITSET_TYPE_LIST(V) \ | 185 #define AST_SEMANTIC_BITSET_TYPE_LIST(V) \ |
187 V(Negative31, 1u << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 186 V(Negative31, 1u << 5 | \ |
188 V(Null, 1u << 6 | REPRESENTATION(kTaggedPointer)) \ | 187 AST_REPRESENTATION(kTagged | kUntaggedNumber)) \ |
189 V(Undefined, 1u << 7 | REPRESENTATION(kTaggedPointer)) \ | 188 V(Null, 1u << 6 | AST_REPRESENTATION(kTaggedPointer)) \ |
190 V(Boolean, 1u << 8 | REPRESENTATION(kTaggedPointer)) \ | 189 V(Undefined, 1u << 7 | AST_REPRESENTATION(kTaggedPointer)) \ |
191 V(Unsigned30, 1u << 9 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 190 V(Boolean, 1u << 8 | AST_REPRESENTATION(kTaggedPointer)) \ |
192 V(MinusZero, 1u << 10 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 191 V(Unsigned30, 1u << 9 | \ |
193 V(NaN, 1u << 11 | REPRESENTATION(kTagged | kUntaggedNumber)) \ | 192 AST_REPRESENTATION(kTagged | kUntaggedNumber)) \ |
194 V(Symbol, 1u << 12 | REPRESENTATION(kTaggedPointer)) \ | 193 V(MinusZero, 1u << 10 | \ |
195 V(InternalizedString, 1u << 13 | REPRESENTATION(kTaggedPointer)) \ | 194 AST_REPRESENTATION(kTagged | kUntaggedNumber)) \ |
196 V(OtherString, 1u << 14 | REPRESENTATION(kTaggedPointer)) \ | 195 V(NaN, 1u << 11 | \ |
197 V(Simd, 1u << 15 | REPRESENTATION(kTaggedPointer)) \ | 196 AST_REPRESENTATION(kTagged | kUntaggedNumber)) \ |
198 V(OtherObject, 1u << 17 | REPRESENTATION(kTaggedPointer)) \ | 197 V(Symbol, 1u << 12 | AST_REPRESENTATION(kTaggedPointer)) \ |
199 V(OtherUndetectable, 1u << 16 | REPRESENTATION(kTaggedPointer)) \ | 198 V(InternalizedString, 1u << 13 | AST_REPRESENTATION(kTaggedPointer)) \ |
200 V(Proxy, 1u << 18 | REPRESENTATION(kTaggedPointer)) \ | 199 V(OtherString, 1u << 14 | AST_REPRESENTATION(kTaggedPointer)) \ |
201 V(Function, 1u << 19 | REPRESENTATION(kTaggedPointer)) \ | 200 V(Simd, 1u << 15 | AST_REPRESENTATION(kTaggedPointer)) \ |
202 V(Hole, 1u << 20 | REPRESENTATION(kTaggedPointer)) \ | 201 V(OtherObject, 1u << 17 | AST_REPRESENTATION(kTaggedPointer)) \ |
203 V(OtherInternal, 1u << 21 | REPRESENTATION(kTagged | kUntagged)) \ | 202 V(OtherUndetectable, 1u << 16 | AST_REPRESENTATION(kTaggedPointer)) \ |
| 203 V(Proxy, 1u << 18 | AST_REPRESENTATION(kTaggedPointer)) \ |
| 204 V(Function, 1u << 19 | AST_REPRESENTATION(kTaggedPointer)) \ |
| 205 V(Hole, 1u << 20 | AST_REPRESENTATION(kTaggedPointer)) \ |
| 206 V(OtherInternal, 1u << 21 | \ |
| 207 AST_REPRESENTATION(kTagged | kUntagged)) \ |
204 \ | 208 \ |
205 V(Signed31, kUnsigned30 | kNegative31) \ | 209 V(Signed31, kUnsigned30 | kNegative31) \ |
206 V(Signed32, kSigned31 | kOtherUnsigned31 | kOtherSigned32) \ | 210 V(Signed32, kSigned31 | kOtherUnsigned31 | \ |
| 211 kOtherSigned32) \ |
207 V(Signed32OrMinusZero, kSigned32 | kMinusZero) \ | 212 V(Signed32OrMinusZero, kSigned32 | kMinusZero) \ |
208 V(Signed32OrMinusZeroOrNaN, kSigned32 | kMinusZero | kNaN) \ | 213 V(Signed32OrMinusZeroOrNaN, kSigned32 | kMinusZero | kNaN) \ |
209 V(Negative32, kNegative31 | kOtherSigned32) \ | 214 V(Negative32, kNegative31 | kOtherSigned32) \ |
210 V(Unsigned31, kUnsigned30 | kOtherUnsigned31) \ | 215 V(Unsigned31, kUnsigned30 | kOtherUnsigned31) \ |
211 V(Unsigned32, kUnsigned30 | kOtherUnsigned31 | \ | 216 V(Unsigned32, kUnsigned30 | kOtherUnsigned31 | \ |
212 kOtherUnsigned32) \ | 217 kOtherUnsigned32) \ |
213 V(Unsigned32OrMinusZero, kUnsigned32 | kMinusZero) \ | 218 V(Unsigned32OrMinusZero, kUnsigned32 | kMinusZero) \ |
214 V(Unsigned32OrMinusZeroOrNaN, kUnsigned32 | kMinusZero | kNaN) \ | 219 V(Unsigned32OrMinusZeroOrNaN, kUnsigned32 | kMinusZero | kNaN) \ |
215 V(Integral32, kSigned32 | kUnsigned32) \ | 220 V(Integral32, kSigned32 | kUnsigned32) \ |
216 V(PlainNumber, kIntegral32 | kOtherNumber) \ | 221 V(PlainNumber, kIntegral32 | kOtherNumber) \ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 * -2^31 -2^30 0 2^30 2^31 2^32 | 259 * -2^31 -2^30 0 2^30 2^31 2^32 |
255 * | 260 * |
256 * E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1. | 261 * E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1. |
257 * | 262 * |
258 * Some of the atomic numerical bitsets are internal only (see | 263 * Some of the atomic numerical bitsets are internal only (see |
259 * INTERNAL_BITSET_TYPE_LIST). To a types user, they should only occur in | 264 * INTERNAL_BITSET_TYPE_LIST). To a types user, they should only occur in |
260 * union with certain other bitsets. For instance, OtherNumber should only | 265 * union with certain other bitsets. For instance, OtherNumber should only |
261 * occur as part of PlainNumber. | 266 * occur as part of PlainNumber. |
262 */ | 267 */ |
263 | 268 |
264 #define PROPER_BITSET_TYPE_LIST(V) \ | 269 #define AST_PROPER_BITSET_TYPE_LIST(V) \ |
265 REPRESENTATION_BITSET_TYPE_LIST(V) \ | 270 AST_REPRESENTATION_BITSET_TYPE_LIST(V) \ |
266 SEMANTIC_BITSET_TYPE_LIST(V) | 271 AST_SEMANTIC_BITSET_TYPE_LIST(V) |
267 | 272 |
268 #define BITSET_TYPE_LIST(V) \ | 273 #define AST_BITSET_TYPE_LIST(V) \ |
269 MASK_BITSET_TYPE_LIST(V) \ | 274 AST_MASK_BITSET_TYPE_LIST(V) \ |
270 REPRESENTATION_BITSET_TYPE_LIST(V) \ | 275 AST_REPRESENTATION_BITSET_TYPE_LIST(V) \ |
271 INTERNAL_BITSET_TYPE_LIST(V) \ | 276 AST_INTERNAL_BITSET_TYPE_LIST(V) \ |
272 SEMANTIC_BITSET_TYPE_LIST(V) | 277 AST_SEMANTIC_BITSET_TYPE_LIST(V) |
273 | 278 |
274 class Type; | 279 class AstType; |
275 | 280 |
276 // ----------------------------------------------------------------------------- | 281 // ----------------------------------------------------------------------------- |
277 // Bitset types (internal). | 282 // Bitset types (internal). |
278 | 283 |
279 class BitsetType { | 284 class AstBitsetType { |
280 public: | 285 public: |
281 typedef uint32_t bitset; // Internal | 286 typedef uint32_t bitset; // Internal |
282 | 287 |
283 enum : uint32_t { | 288 enum : uint32_t { |
284 #define DECLARE_TYPE(type, value) k##type = (value), | 289 #define DECLARE_TYPE(type, value) k##type = (value), |
285 BITSET_TYPE_LIST(DECLARE_TYPE) | 290 AST_BITSET_TYPE_LIST(DECLARE_TYPE) |
286 #undef DECLARE_TYPE | 291 #undef DECLARE_TYPE |
287 kUnusedEOL = 0 | 292 kUnusedEOL = 0 |
288 }; | 293 }; |
289 | 294 |
290 static bitset SignedSmall(); | 295 static bitset SignedSmall(); |
291 static bitset UnsignedSmall(); | 296 static bitset UnsignedSmall(); |
292 | 297 |
293 bitset Bitset() { | 298 bitset Bitset() { |
294 return static_cast<bitset>(reinterpret_cast<uintptr_t>(this) ^ 1u); | 299 return static_cast<bitset>(reinterpret_cast<uintptr_t>(this) ^ 1u); |
295 } | 300 } |
296 | 301 |
297 static bool IsInhabited(bitset bits) { | 302 static bool IsInhabited(bitset bits) { |
298 return SEMANTIC(bits) != kNone && REPRESENTATION(bits) != kNone; | 303 return AST_SEMANTIC(bits) != kNone && AST_REPRESENTATION(bits) != kNone; |
299 } | 304 } |
300 | 305 |
301 static bool SemanticIsInhabited(bitset bits) { | 306 static bool SemanticIsInhabited(bitset bits) { |
302 return SEMANTIC(bits) != kNone; | 307 return AST_SEMANTIC(bits) != kNone; |
303 } | 308 } |
304 | 309 |
305 static bool Is(bitset bits1, bitset bits2) { | 310 static bool Is(bitset bits1, bitset bits2) { |
306 return (bits1 | bits2) == bits2; | 311 return (bits1 | bits2) == bits2; |
307 } | 312 } |
308 | 313 |
309 static double Min(bitset); | 314 static double Min(bitset); |
310 static double Max(bitset); | 315 static double Max(bitset); |
311 | 316 |
312 static bitset Glb(Type* type); // greatest lower bound that's a bitset | 317 static bitset Glb(AstType* type); // greatest lower bound that's a bitset |
313 static bitset Glb(double min, double max); | 318 static bitset Glb(double min, double max); |
314 static bitset Lub(Type* type); // least upper bound that's a bitset | 319 static bitset Lub(AstType* type); // least upper bound that's a bitset |
315 static bitset Lub(i::Map* map); | 320 static bitset Lub(i::Map* map); |
316 static bitset Lub(i::Object* value); | 321 static bitset Lub(i::Object* value); |
317 static bitset Lub(double value); | 322 static bitset Lub(double value); |
318 static bitset Lub(double min, double max); | 323 static bitset Lub(double min, double max); |
319 static bitset ExpandInternals(bitset bits); | 324 static bitset ExpandInternals(bitset bits); |
320 | 325 |
321 static const char* Name(bitset); | 326 static const char* Name(bitset); |
322 static void Print(std::ostream& os, bitset); // NOLINT | 327 static void Print(std::ostream& os, bitset); // NOLINT |
323 #ifdef DEBUG | 328 #ifdef DEBUG |
324 static void Print(bitset); | 329 static void Print(bitset); |
325 #endif | 330 #endif |
326 | 331 |
327 static bitset NumberBits(bitset bits); | 332 static bitset NumberBits(bitset bits); |
328 | 333 |
329 static bool IsBitset(Type* type) { | 334 static bool IsBitset(AstType* type) { |
330 return reinterpret_cast<uintptr_t>(type) & 1; | 335 return reinterpret_cast<uintptr_t>(type) & 1; |
331 } | 336 } |
332 | 337 |
333 static Type* NewForTesting(bitset bits) { return New(bits); } | 338 static AstType* NewForTesting(bitset bits) { return New(bits); } |
334 | 339 |
335 private: | 340 private: |
336 friend class Type; | 341 friend class AstType; |
337 | 342 |
338 static Type* New(bitset bits) { | 343 static AstType* New(bitset bits) { |
339 return reinterpret_cast<Type*>(static_cast<uintptr_t>(bits | 1u)); | 344 return reinterpret_cast<AstType*>(static_cast<uintptr_t>(bits | 1u)); |
340 } | 345 } |
341 | 346 |
342 struct Boundary { | 347 struct Boundary { |
343 bitset internal; | 348 bitset internal; |
344 bitset external; | 349 bitset external; |
345 double min; | 350 double min; |
346 }; | 351 }; |
347 static const Boundary BoundariesArray[]; | 352 static const Boundary BoundariesArray[]; |
348 static inline const Boundary* Boundaries(); | 353 static inline const Boundary* Boundaries(); |
349 static inline size_t BoundariesSize(); | 354 static inline size_t BoundariesSize(); |
350 }; | 355 }; |
351 | 356 |
352 // ----------------------------------------------------------------------------- | 357 // ----------------------------------------------------------------------------- |
353 // Superclass for non-bitset types (internal). | 358 // Superclass for non-bitset types (internal). |
354 class TypeBase { | 359 class AstTypeBase { |
355 protected: | 360 protected: |
356 friend class Type; | 361 friend class AstType; |
357 | 362 |
358 enum Kind { | 363 enum Kind { |
359 kClass, | 364 kClass, |
360 kConstant, | 365 kConstant, |
361 kContext, | 366 kContext, |
362 kArray, | 367 kArray, |
363 kFunction, | 368 kFunction, |
364 kTuple, | 369 kTuple, |
365 kUnion, | 370 kUnion, |
366 kRange | 371 kRange |
367 }; | 372 }; |
368 | 373 |
369 Kind kind() const { return kind_; } | 374 Kind kind() const { return kind_; } |
370 explicit TypeBase(Kind kind) : kind_(kind) {} | 375 explicit AstTypeBase(Kind kind) : kind_(kind) {} |
371 | 376 |
372 static bool IsKind(Type* type, Kind kind) { | 377 static bool IsKind(AstType* type, Kind kind) { |
373 if (BitsetType::IsBitset(type)) return false; | 378 if (AstBitsetType::IsBitset(type)) return false; |
374 TypeBase* base = reinterpret_cast<TypeBase*>(type); | 379 AstTypeBase* base = reinterpret_cast<AstTypeBase*>(type); |
375 return base->kind() == kind; | 380 return base->kind() == kind; |
376 } | 381 } |
377 | 382 |
378 // The hacky conversion to/from Type*. | 383 // The hacky conversion to/from AstType*. |
379 static Type* AsType(TypeBase* type) { return reinterpret_cast<Type*>(type); } | 384 static AstType* AsType(AstTypeBase* type) { |
380 static TypeBase* FromType(Type* type) { | 385 return reinterpret_cast<AstType*>(type); |
381 return reinterpret_cast<TypeBase*>(type); | 386 } |
| 387 static AstTypeBase* FromType(AstType* type) { |
| 388 return reinterpret_cast<AstTypeBase*>(type); |
382 } | 389 } |
383 | 390 |
384 private: | 391 private: |
385 Kind kind_; | 392 Kind kind_; |
386 }; | 393 }; |
387 | 394 |
388 // ----------------------------------------------------------------------------- | 395 // ----------------------------------------------------------------------------- |
389 // Class types. | 396 // Class types. |
390 | 397 |
391 class ClassType : public TypeBase { | 398 class AstClassType : public AstTypeBase { |
392 public: | 399 public: |
393 i::Handle<i::Map> Map() { return map_; } | 400 i::Handle<i::Map> Map() { return map_; } |
394 | 401 |
395 private: | 402 private: |
396 friend class Type; | 403 friend class AstType; |
397 friend class BitsetType; | 404 friend class AstBitsetType; |
398 | 405 |
399 static Type* New(i::Handle<i::Map> map, Zone* zone) { | 406 static AstType* New(i::Handle<i::Map> map, Zone* zone) { |
400 return AsType(new (zone->New(sizeof(ClassType))) | 407 return AsType(new (zone->New(sizeof(AstClassType))) |
401 ClassType(BitsetType::Lub(*map), map)); | 408 AstClassType(AstBitsetType::Lub(*map), map)); |
402 } | 409 } |
403 | 410 |
404 static ClassType* cast(Type* type) { | 411 static AstClassType* cast(AstType* type) { |
405 DCHECK(IsKind(type, kClass)); | 412 DCHECK(IsKind(type, kClass)); |
406 return static_cast<ClassType*>(FromType(type)); | 413 return static_cast<AstClassType*>(FromType(type)); |
407 } | 414 } |
408 | 415 |
409 ClassType(BitsetType::bitset bitset, i::Handle<i::Map> map) | 416 AstClassType(AstBitsetType::bitset bitset, i::Handle<i::Map> map) |
410 : TypeBase(kClass), bitset_(bitset), map_(map) {} | 417 : AstTypeBase(kClass), bitset_(bitset), map_(map) {} |
411 | 418 |
412 BitsetType::bitset Lub() { return bitset_; } | 419 AstBitsetType::bitset Lub() { return bitset_; } |
413 | 420 |
414 BitsetType::bitset bitset_; | 421 AstBitsetType::bitset bitset_; |
415 Handle<i::Map> map_; | 422 Handle<i::Map> map_; |
416 }; | 423 }; |
417 | 424 |
418 // ----------------------------------------------------------------------------- | 425 // ----------------------------------------------------------------------------- |
419 // Constant types. | 426 // Constant types. |
420 | 427 |
421 class ConstantType : public TypeBase { | 428 class AstConstantType : public AstTypeBase { |
422 public: | 429 public: |
423 i::Handle<i::Object> Value() { return object_; } | 430 i::Handle<i::Object> Value() { return object_; } |
424 | 431 |
425 private: | 432 private: |
426 friend class Type; | 433 friend class AstType; |
427 friend class BitsetType; | 434 friend class AstBitsetType; |
428 | 435 |
429 static Type* New(i::Handle<i::Object> value, Zone* zone) { | 436 static AstType* New(i::Handle<i::Object> value, Zone* zone) { |
430 BitsetType::bitset bitset = BitsetType::Lub(*value); | 437 AstBitsetType::bitset bitset = AstBitsetType::Lub(*value); |
431 return AsType(new (zone->New(sizeof(ConstantType))) | 438 return AsType(new (zone->New(sizeof(AstConstantType))) |
432 ConstantType(bitset, value)); | 439 AstConstantType(bitset, value)); |
433 } | 440 } |
434 | 441 |
435 static ConstantType* cast(Type* type) { | 442 static AstConstantType* cast(AstType* type) { |
436 DCHECK(IsKind(type, kConstant)); | 443 DCHECK(IsKind(type, kConstant)); |
437 return static_cast<ConstantType*>(FromType(type)); | 444 return static_cast<AstConstantType*>(FromType(type)); |
438 } | 445 } |
439 | 446 |
440 ConstantType(BitsetType::bitset bitset, i::Handle<i::Object> object) | 447 AstConstantType(AstBitsetType::bitset bitset, i::Handle<i::Object> object) |
441 : TypeBase(kConstant), bitset_(bitset), object_(object) {} | 448 : AstTypeBase(kConstant), bitset_(bitset), object_(object) {} |
442 | 449 |
443 BitsetType::bitset Lub() { return bitset_; } | 450 AstBitsetType::bitset Lub() { return bitset_; } |
444 | 451 |
445 BitsetType::bitset bitset_; | 452 AstBitsetType::bitset bitset_; |
446 Handle<i::Object> object_; | 453 Handle<i::Object> object_; |
447 }; | 454 }; |
448 // TODO(neis): Also cache value if numerical. | 455 // TODO(neis): Also cache value if numerical. |
449 // TODO(neis): Allow restricting the representation. | 456 // TODO(neis): Allow restricting the representation. |
450 | 457 |
451 // ----------------------------------------------------------------------------- | 458 // ----------------------------------------------------------------------------- |
452 // Range types. | 459 // Range types. |
453 | 460 |
454 class RangeType : public TypeBase { | 461 class AstRangeType : public AstTypeBase { |
455 public: | 462 public: |
456 struct Limits { | 463 struct Limits { |
457 double min; | 464 double min; |
458 double max; | 465 double max; |
459 Limits(double min, double max) : min(min), max(max) {} | 466 Limits(double min, double max) : min(min), max(max) {} |
460 explicit Limits(RangeType* range) : min(range->Min()), max(range->Max()) {} | 467 explicit Limits(AstRangeType* range) |
| 468 : min(range->Min()), max(range->Max()) {} |
461 bool IsEmpty(); | 469 bool IsEmpty(); |
462 static Limits Empty() { return Limits(1, 0); } | 470 static Limits Empty() { return Limits(1, 0); } |
463 static Limits Intersect(Limits lhs, Limits rhs); | 471 static Limits Intersect(Limits lhs, Limits rhs); |
464 static Limits Union(Limits lhs, Limits rhs); | 472 static Limits Union(Limits lhs, Limits rhs); |
465 }; | 473 }; |
466 | 474 |
467 double Min() { return limits_.min; } | 475 double Min() { return limits_.min; } |
468 double Max() { return limits_.max; } | 476 double Max() { return limits_.max; } |
469 | 477 |
470 private: | 478 private: |
471 friend class Type; | 479 friend class AstType; |
472 friend class BitsetType; | 480 friend class AstBitsetType; |
473 friend class UnionType; | 481 friend class AstUnionType; |
474 | 482 |
475 static Type* New(double min, double max, BitsetType::bitset representation, | 483 static AstType* New(double min, double max, |
476 Zone* zone) { | 484 AstBitsetType::bitset representation, Zone* zone) { |
477 return New(Limits(min, max), representation, zone); | 485 return New(Limits(min, max), representation, zone); |
478 } | 486 } |
479 | 487 |
480 static bool IsInteger(double x) { | 488 static bool IsInteger(double x) { |
481 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. | 489 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. |
482 } | 490 } |
483 | 491 |
484 static Type* New(Limits lim, BitsetType::bitset representation, Zone* zone) { | 492 static AstType* New(Limits lim, AstBitsetType::bitset representation, |
| 493 Zone* zone) { |
485 DCHECK(IsInteger(lim.min) && IsInteger(lim.max)); | 494 DCHECK(IsInteger(lim.min) && IsInteger(lim.max)); |
486 DCHECK(lim.min <= lim.max); | 495 DCHECK(lim.min <= lim.max); |
487 DCHECK(REPRESENTATION(representation) == representation); | 496 DCHECK(AST_REPRESENTATION(representation) == representation); |
488 BitsetType::bitset bits = | 497 AstBitsetType::bitset bits = |
489 SEMANTIC(BitsetType::Lub(lim.min, lim.max)) | representation; | 498 AST_SEMANTIC(AstBitsetType::Lub(lim.min, lim.max)) | representation; |
490 | 499 |
491 return AsType(new (zone->New(sizeof(RangeType))) RangeType(bits, lim)); | 500 return AsType(new (zone->New(sizeof(AstRangeType))) |
| 501 AstRangeType(bits, lim)); |
492 } | 502 } |
493 | 503 |
494 static RangeType* cast(Type* type) { | 504 static AstRangeType* cast(AstType* type) { |
495 DCHECK(IsKind(type, kRange)); | 505 DCHECK(IsKind(type, kRange)); |
496 return static_cast<RangeType*>(FromType(type)); | 506 return static_cast<AstRangeType*>(FromType(type)); |
497 } | 507 } |
498 | 508 |
499 RangeType(BitsetType::bitset bitset, Limits limits) | 509 AstRangeType(AstBitsetType::bitset bitset, Limits limits) |
500 : TypeBase(kRange), bitset_(bitset), limits_(limits) {} | 510 : AstTypeBase(kRange), bitset_(bitset), limits_(limits) {} |
501 | 511 |
502 BitsetType::bitset Lub() { return bitset_; } | 512 AstBitsetType::bitset Lub() { return bitset_; } |
503 | 513 |
504 BitsetType::bitset bitset_; | 514 AstBitsetType::bitset bitset_; |
505 Limits limits_; | 515 Limits limits_; |
506 }; | 516 }; |
507 | 517 |
508 // ----------------------------------------------------------------------------- | 518 // ----------------------------------------------------------------------------- |
509 // Context types. | 519 // Context types. |
510 | 520 |
511 class ContextType : public TypeBase { | 521 class AstContextType : public AstTypeBase { |
512 public: | 522 public: |
513 Type* Outer() { return outer_; } | 523 AstType* Outer() { return outer_; } |
514 | 524 |
515 private: | 525 private: |
516 friend class Type; | 526 friend class AstType; |
517 | 527 |
518 static Type* New(Type* outer, Zone* zone) { | 528 static AstType* New(AstType* outer, Zone* zone) { |
519 return AsType(new (zone->New(sizeof(ContextType))) ContextType(outer)); | 529 return AsType(new (zone->New(sizeof(AstContextType))) |
| 530 AstContextType(outer)); // NOLINT |
520 } | 531 } |
521 | 532 |
522 static ContextType* cast(Type* type) { | 533 static AstContextType* cast(AstType* type) { |
523 DCHECK(IsKind(type, kContext)); | 534 DCHECK(IsKind(type, kContext)); |
524 return static_cast<ContextType*>(FromType(type)); | 535 return static_cast<AstContextType*>(FromType(type)); |
525 } | 536 } |
526 | 537 |
527 explicit ContextType(Type* outer) : TypeBase(kContext), outer_(outer) {} | 538 explicit AstContextType(AstType* outer) |
| 539 : AstTypeBase(kContext), outer_(outer) {} |
528 | 540 |
529 Type* outer_; | 541 AstType* outer_; |
530 }; | 542 }; |
531 | 543 |
532 // ----------------------------------------------------------------------------- | 544 // ----------------------------------------------------------------------------- |
533 // Array types. | 545 // Array types. |
534 | 546 |
535 class ArrayType : public TypeBase { | 547 class AstArrayType : public AstTypeBase { |
536 public: | 548 public: |
537 Type* Element() { return element_; } | 549 AstType* Element() { return element_; } |
538 | 550 |
539 private: | 551 private: |
540 friend class Type; | 552 friend class AstType; |
541 | 553 |
542 explicit ArrayType(Type* element) : TypeBase(kArray), element_(element) {} | 554 explicit AstArrayType(AstType* element) |
| 555 : AstTypeBase(kArray), element_(element) {} |
543 | 556 |
544 static Type* New(Type* element, Zone* zone) { | 557 static AstType* New(AstType* element, Zone* zone) { |
545 return AsType(new (zone->New(sizeof(ArrayType))) ArrayType(element)); | 558 return AsType(new (zone->New(sizeof(AstArrayType))) AstArrayType(element)); |
546 } | 559 } |
547 | 560 |
548 static ArrayType* cast(Type* type) { | 561 static AstArrayType* cast(AstType* type) { |
549 DCHECK(IsKind(type, kArray)); | 562 DCHECK(IsKind(type, kArray)); |
550 return static_cast<ArrayType*>(FromType(type)); | 563 return static_cast<AstArrayType*>(FromType(type)); |
551 } | 564 } |
552 | 565 |
553 Type* element_; | 566 AstType* element_; |
554 }; | 567 }; |
555 | 568 |
556 // ----------------------------------------------------------------------------- | 569 // ----------------------------------------------------------------------------- |
557 // Superclass for types with variable number of type fields. | 570 // Superclass for types with variable number of type fields. |
558 class StructuralType : public TypeBase { | 571 class AstStructuralType : public AstTypeBase { |
559 public: | 572 public: |
560 int LengthForTesting() { return Length(); } | 573 int LengthForTesting() { return Length(); } |
561 | 574 |
562 protected: | 575 protected: |
563 friend class Type; | 576 friend class AstType; |
564 | 577 |
565 int Length() { return length_; } | 578 int Length() { return length_; } |
566 | 579 |
567 Type* Get(int i) { | 580 AstType* Get(int i) { |
568 DCHECK(0 <= i && i < this->Length()); | 581 DCHECK(0 <= i && i < this->Length()); |
569 return elements_[i]; | 582 return elements_[i]; |
570 } | 583 } |
571 | 584 |
572 void Set(int i, Type* type) { | 585 void Set(int i, AstType* type) { |
573 DCHECK(0 <= i && i < this->Length()); | 586 DCHECK(0 <= i && i < this->Length()); |
574 elements_[i] = type; | 587 elements_[i] = type; |
575 } | 588 } |
576 | 589 |
577 void Shrink(int length) { | 590 void Shrink(int length) { |
578 DCHECK(2 <= length && length <= this->Length()); | 591 DCHECK(2 <= length && length <= this->Length()); |
579 length_ = length; | 592 length_ = length; |
580 } | 593 } |
581 | 594 |
582 StructuralType(Kind kind, int length, i::Zone* zone) | 595 AstStructuralType(Kind kind, int length, i::Zone* zone) |
583 : TypeBase(kind), length_(length) { | 596 : AstTypeBase(kind), length_(length) { |
584 elements_ = reinterpret_cast<Type**>(zone->New(sizeof(Type*) * length)); | 597 elements_ = |
| 598 reinterpret_cast<AstType**>(zone->New(sizeof(AstType*) * length)); |
585 } | 599 } |
586 | 600 |
587 private: | 601 private: |
588 int length_; | 602 int length_; |
589 Type** elements_; | 603 AstType** elements_; |
590 }; | 604 }; |
591 | 605 |
592 // ----------------------------------------------------------------------------- | 606 // ----------------------------------------------------------------------------- |
593 // Function types. | 607 // Function types. |
594 | 608 |
595 class FunctionType : public StructuralType { | 609 class AstFunctionType : public AstStructuralType { |
596 public: | 610 public: |
597 int Arity() { return this->Length() - 2; } | 611 int Arity() { return this->Length() - 2; } |
598 Type* Result() { return this->Get(0); } | 612 AstType* Result() { return this->Get(0); } |
599 Type* Receiver() { return this->Get(1); } | 613 AstType* Receiver() { return this->Get(1); } |
600 Type* Parameter(int i) { return this->Get(2 + i); } | 614 AstType* Parameter(int i) { return this->Get(2 + i); } |
601 | 615 |
602 void InitParameter(int i, Type* type) { this->Set(2 + i, type); } | 616 void InitParameter(int i, AstType* type) { this->Set(2 + i, type); } |
603 | 617 |
604 private: | 618 private: |
605 friend class Type; | 619 friend class AstType; |
606 | 620 |
607 FunctionType(Type* result, Type* receiver, int arity, Zone* zone) | 621 AstFunctionType(AstType* result, AstType* receiver, int arity, Zone* zone) |
608 : StructuralType(kFunction, 2 + arity, zone) { | 622 : AstStructuralType(kFunction, 2 + arity, zone) { |
609 Set(0, result); | 623 Set(0, result); |
610 Set(1, receiver); | 624 Set(1, receiver); |
611 } | 625 } |
612 | 626 |
613 static Type* New(Type* result, Type* receiver, int arity, Zone* zone) { | 627 static AstType* New(AstType* result, AstType* receiver, int arity, |
614 return AsType(new (zone->New(sizeof(FunctionType))) | 628 Zone* zone) { |
615 FunctionType(result, receiver, arity, zone)); | 629 return AsType(new (zone->New(sizeof(AstFunctionType))) |
| 630 AstFunctionType(result, receiver, arity, zone)); |
616 } | 631 } |
617 | 632 |
618 static FunctionType* cast(Type* type) { | 633 static AstFunctionType* cast(AstType* type) { |
619 DCHECK(IsKind(type, kFunction)); | 634 DCHECK(IsKind(type, kFunction)); |
620 return static_cast<FunctionType*>(FromType(type)); | 635 return static_cast<AstFunctionType*>(FromType(type)); |
621 } | 636 } |
622 }; | 637 }; |
623 | 638 |
624 // ----------------------------------------------------------------------------- | 639 // ----------------------------------------------------------------------------- |
625 // Tuple types. | 640 // Tuple types. |
626 | 641 |
627 class TupleType : public StructuralType { | 642 class AstTupleType : public AstStructuralType { |
628 public: | 643 public: |
629 int Arity() { return this->Length(); } | 644 int Arity() { return this->Length(); } |
630 Type* Element(int i) { return this->Get(i); } | 645 AstType* Element(int i) { return this->Get(i); } |
631 | 646 |
632 void InitElement(int i, Type* type) { this->Set(i, type); } | 647 void InitElement(int i, AstType* type) { this->Set(i, type); } |
633 | 648 |
634 private: | 649 private: |
635 friend class Type; | 650 friend class AstType; |
636 | 651 |
637 TupleType(int length, Zone* zone) : StructuralType(kTuple, length, zone) {} | 652 AstTupleType(int length, Zone* zone) |
| 653 : AstStructuralType(kTuple, length, zone) {} |
638 | 654 |
639 static Type* New(int length, Zone* zone) { | 655 static AstType* New(int length, Zone* zone) { |
640 return AsType(new (zone->New(sizeof(TupleType))) TupleType(length, zone)); | 656 return AsType(new (zone->New(sizeof(AstTupleType))) |
| 657 AstTupleType(length, zone)); |
641 } | 658 } |
642 | 659 |
643 static TupleType* cast(Type* type) { | 660 static AstTupleType* cast(AstType* type) { |
644 DCHECK(IsKind(type, kTuple)); | 661 DCHECK(IsKind(type, kTuple)); |
645 return static_cast<TupleType*>(FromType(type)); | 662 return static_cast<AstTupleType*>(FromType(type)); |
646 } | 663 } |
647 }; | 664 }; |
648 | 665 |
649 // ----------------------------------------------------------------------------- | 666 // ----------------------------------------------------------------------------- |
650 // Union types (internal). | 667 // Union types (internal). |
651 // A union is a structured type with the following invariants: | 668 // A union is a structured type with the following invariants: |
652 // - its length is at least 2 | 669 // - its length is at least 2 |
653 // - at most one field is a bitset, and it must go into index 0 | 670 // - at most one field is a bitset, and it must go into index 0 |
654 // - no field is a union | 671 // - no field is a union |
655 // - no field is a subtype of any other field | 672 // - no field is a subtype of any other field |
656 class UnionType : public StructuralType { | 673 class AstUnionType : public AstStructuralType { |
657 private: | 674 private: |
658 friend Type; | 675 friend AstType; |
659 friend BitsetType; | 676 friend AstBitsetType; |
660 | 677 |
661 UnionType(int length, Zone* zone) : StructuralType(kUnion, length, zone) {} | 678 AstUnionType(int length, Zone* zone) |
| 679 : AstStructuralType(kUnion, length, zone) {} |
662 | 680 |
663 static Type* New(int length, Zone* zone) { | 681 static AstType* New(int length, Zone* zone) { |
664 return AsType(new (zone->New(sizeof(UnionType))) UnionType(length, zone)); | 682 return AsType(new (zone->New(sizeof(AstUnionType))) |
| 683 AstUnionType(length, zone)); |
665 } | 684 } |
666 | 685 |
667 static UnionType* cast(Type* type) { | 686 static AstUnionType* cast(AstType* type) { |
668 DCHECK(IsKind(type, kUnion)); | 687 DCHECK(IsKind(type, kUnion)); |
669 return static_cast<UnionType*>(FromType(type)); | 688 return static_cast<AstUnionType*>(FromType(type)); |
670 } | 689 } |
671 | 690 |
672 bool Wellformed(); | 691 bool Wellformed(); |
673 }; | 692 }; |
674 | 693 |
675 class Type { | 694 class AstType { |
676 public: | 695 public: |
677 typedef BitsetType::bitset bitset; // Internal | 696 typedef AstBitsetType::bitset bitset; // Internal |
678 | 697 |
679 // Constructors. | 698 // Constructors. |
680 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ | 699 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
681 static Type* type() { return BitsetType::New(BitsetType::k##type); } | 700 static AstType* type() { return AstBitsetType::New(AstBitsetType::k##type); } |
682 PROPER_BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) | 701 AST_PROPER_BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) |
683 #undef DEFINE_TYPE_CONSTRUCTOR | 702 #undef DEFINE_TYPE_CONSTRUCTOR |
684 | 703 |
685 static Type* SignedSmall() { | 704 static AstType* SignedSmall() { |
686 return BitsetType::New(BitsetType::SignedSmall()); | 705 return AstBitsetType::New(AstBitsetType::SignedSmall()); |
687 } | 706 } |
688 static Type* UnsignedSmall() { | 707 static AstType* UnsignedSmall() { |
689 return BitsetType::New(BitsetType::UnsignedSmall()); | 708 return AstBitsetType::New(AstBitsetType::UnsignedSmall()); |
690 } | 709 } |
691 | 710 |
692 static Type* Class(i::Handle<i::Map> map, Zone* zone) { | 711 static AstType* Class(i::Handle<i::Map> map, Zone* zone) { |
693 return ClassType::New(map, zone); | 712 return AstClassType::New(map, zone); |
694 } | 713 } |
695 static Type* Constant(i::Handle<i::Object> value, Zone* zone) { | 714 static AstType* Constant(i::Handle<i::Object> value, Zone* zone) { |
696 return ConstantType::New(value, zone); | 715 return AstConstantType::New(value, zone); |
697 } | 716 } |
698 static Type* Range(double min, double max, Zone* zone) { | 717 static AstType* Range(double min, double max, Zone* zone) { |
699 return RangeType::New(min, max, REPRESENTATION(BitsetType::kTagged | | 718 return AstRangeType::New(min, max, |
700 BitsetType::kUntaggedNumber), | 719 AST_REPRESENTATION(AstBitsetType::kTagged | |
701 zone); | 720 AstBitsetType::kUntaggedNumber), |
| 721 zone); |
702 } | 722 } |
703 static Type* Context(Type* outer, Zone* zone) { | 723 static AstType* Context(AstType* outer, Zone* zone) { |
704 return ContextType::New(outer, zone); | 724 return AstContextType::New(outer, zone); |
705 } | 725 } |
706 static Type* Array(Type* element, Zone* zone) { | 726 static AstType* Array(AstType* element, Zone* zone) { |
707 return ArrayType::New(element, zone); | 727 return AstArrayType::New(element, zone); |
708 } | 728 } |
709 static Type* Function(Type* result, Type* receiver, int arity, Zone* zone) { | 729 static AstType* Function(AstType* result, AstType* receiver, int arity, |
710 return FunctionType::New(result, receiver, arity, zone); | 730 Zone* zone) { |
| 731 return AstFunctionType::New(result, receiver, arity, zone); |
711 } | 732 } |
712 static Type* Function(Type* result, Zone* zone) { | 733 static AstType* Function(AstType* result, Zone* zone) { |
713 return Function(result, Any(), 0, zone); | 734 return Function(result, Any(), 0, zone); |
714 } | 735 } |
715 static Type* Function(Type* result, Type* param0, Zone* zone) { | 736 static AstType* Function(AstType* result, AstType* param0, Zone* zone) { |
716 Type* function = Function(result, Any(), 1, zone); | 737 AstType* function = Function(result, Any(), 1, zone); |
717 function->AsFunction()->InitParameter(0, param0); | 738 function->AsFunction()->InitParameter(0, param0); |
718 return function; | 739 return function; |
719 } | 740 } |
720 static Type* Function(Type* result, Type* param0, Type* param1, Zone* zone) { | 741 static AstType* Function(AstType* result, AstType* param0, AstType* param1, |
721 Type* function = Function(result, Any(), 2, zone); | 742 Zone* zone) { |
| 743 AstType* function = Function(result, Any(), 2, zone); |
722 function->AsFunction()->InitParameter(0, param0); | 744 function->AsFunction()->InitParameter(0, param0); |
723 function->AsFunction()->InitParameter(1, param1); | 745 function->AsFunction()->InitParameter(1, param1); |
724 return function; | 746 return function; |
725 } | 747 } |
726 static Type* Function(Type* result, Type* param0, Type* param1, Type* param2, | 748 static AstType* Function(AstType* result, AstType* param0, AstType* param1, |
727 Zone* zone) { | 749 AstType* param2, Zone* zone) { |
728 Type* function = Function(result, Any(), 3, zone); | 750 AstType* function = Function(result, Any(), 3, zone); |
729 function->AsFunction()->InitParameter(0, param0); | 751 function->AsFunction()->InitParameter(0, param0); |
730 function->AsFunction()->InitParameter(1, param1); | 752 function->AsFunction()->InitParameter(1, param1); |
731 function->AsFunction()->InitParameter(2, param2); | 753 function->AsFunction()->InitParameter(2, param2); |
732 return function; | 754 return function; |
733 } | 755 } |
734 static Type* Function(Type* result, int arity, Type** params, Zone* zone) { | 756 static AstType* Function(AstType* result, int arity, AstType** params, |
735 Type* function = Function(result, Any(), arity, zone); | 757 Zone* zone) { |
| 758 AstType* function = Function(result, Any(), arity, zone); |
736 for (int i = 0; i < arity; ++i) { | 759 for (int i = 0; i < arity; ++i) { |
737 function->AsFunction()->InitParameter(i, params[i]); | 760 function->AsFunction()->InitParameter(i, params[i]); |
738 } | 761 } |
739 return function; | 762 return function; |
740 } | 763 } |
741 static Type* Tuple(Type* first, Type* second, Type* third, Zone* zone) { | 764 static AstType* Tuple(AstType* first, AstType* second, AstType* third, |
742 Type* tuple = TupleType::New(3, zone); | 765 Zone* zone) { |
| 766 AstType* tuple = AstTupleType::New(3, zone); |
743 tuple->AsTuple()->InitElement(0, first); | 767 tuple->AsTuple()->InitElement(0, first); |
744 tuple->AsTuple()->InitElement(1, second); | 768 tuple->AsTuple()->InitElement(1, second); |
745 tuple->AsTuple()->InitElement(2, third); | 769 tuple->AsTuple()->InitElement(2, third); |
746 return tuple; | 770 return tuple; |
747 } | 771 } |
748 | 772 |
749 #define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \ | 773 #define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \ |
750 static Type* Name(Isolate* isolate, Zone* zone); | 774 static AstType* Name(Isolate* isolate, Zone* zone); |
751 SIMD128_TYPES(CONSTRUCT_SIMD_TYPE) | 775 SIMD128_TYPES(CONSTRUCT_SIMD_TYPE) |
752 #undef CONSTRUCT_SIMD_TYPE | 776 #undef CONSTRUCT_SIMD_TYPE |
753 | 777 |
754 static Type* Union(Type* type1, Type* type2, Zone* zone); | 778 static AstType* Union(AstType* type1, AstType* type2, Zone* zone); |
755 static Type* Intersect(Type* type1, Type* type2, Zone* zone); | 779 static AstType* Intersect(AstType* type1, AstType* type2, Zone* zone); |
756 | 780 |
757 static Type* Of(double value, Zone* zone) { | 781 static AstType* Of(double value, Zone* zone) { |
758 return BitsetType::New(BitsetType::ExpandInternals(BitsetType::Lub(value))); | 782 return AstBitsetType::New( |
| 783 AstBitsetType::ExpandInternals(AstBitsetType::Lub(value))); |
759 } | 784 } |
760 static Type* Of(i::Object* value, Zone* zone) { | 785 static AstType* Of(i::Object* value, Zone* zone) { |
761 return BitsetType::New(BitsetType::ExpandInternals(BitsetType::Lub(value))); | 786 return AstBitsetType::New( |
| 787 AstBitsetType::ExpandInternals(AstBitsetType::Lub(value))); |
762 } | 788 } |
763 static Type* Of(i::Handle<i::Object> value, Zone* zone) { | 789 static AstType* Of(i::Handle<i::Object> value, Zone* zone) { |
764 return Of(*value, zone); | 790 return Of(*value, zone); |
765 } | 791 } |
766 | 792 |
767 static Type* For(i::Map* map) { | 793 static AstType* For(i::Map* map) { |
768 return BitsetType::New(BitsetType::ExpandInternals(BitsetType::Lub(map))); | 794 return AstBitsetType::New( |
| 795 AstBitsetType::ExpandInternals(AstBitsetType::Lub(map))); |
769 } | 796 } |
770 static Type* For(i::Handle<i::Map> map) { return For(*map); } | 797 static AstType* For(i::Handle<i::Map> map) { return For(*map); } |
771 | 798 |
772 // Extraction of components. | 799 // Extraction of components. |
773 static Type* Representation(Type* t, Zone* zone); | 800 static AstType* Representation(AstType* t, Zone* zone); |
774 static Type* Semantic(Type* t, Zone* zone); | 801 static AstType* Semantic(AstType* t, Zone* zone); |
775 | 802 |
776 // Predicates. | 803 // Predicates. |
777 bool IsInhabited() { return BitsetType::IsInhabited(this->BitsetLub()); } | 804 bool IsInhabited() { return AstBitsetType::IsInhabited(this->BitsetLub()); } |
778 | 805 |
779 bool Is(Type* that) { return this == that || this->SlowIs(that); } | 806 bool Is(AstType* that) { return this == that || this->SlowIs(that); } |
780 bool Maybe(Type* that); | 807 bool Maybe(AstType* that); |
781 bool Equals(Type* that) { return this->Is(that) && that->Is(this); } | 808 bool Equals(AstType* that) { return this->Is(that) && that->Is(this); } |
782 | 809 |
783 // Equivalent to Constant(val)->Is(this), but avoiding allocation. | 810 // Equivalent to Constant(val)->Is(this), but avoiding allocation. |
784 bool Contains(i::Object* val); | 811 bool Contains(i::Object* val); |
785 bool Contains(i::Handle<i::Object> val) { return this->Contains(*val); } | 812 bool Contains(i::Handle<i::Object> val) { return this->Contains(*val); } |
786 | 813 |
787 // State-dependent versions of the above that consider subtyping between | 814 // State-dependent versions of the above that consider subtyping between |
788 // a constant and its map class. | 815 // a constant and its map class. |
789 static Type* NowOf(i::Object* value, Zone* zone); | 816 static AstType* NowOf(i::Object* value, Zone* zone); |
790 static Type* NowOf(i::Handle<i::Object> value, Zone* zone) { | 817 static AstType* NowOf(i::Handle<i::Object> value, Zone* zone) { |
791 return NowOf(*value, zone); | 818 return NowOf(*value, zone); |
792 } | 819 } |
793 bool NowIs(Type* that); | 820 bool NowIs(AstType* that); |
794 bool NowContains(i::Object* val); | 821 bool NowContains(i::Object* val); |
795 bool NowContains(i::Handle<i::Object> val) { return this->NowContains(*val); } | 822 bool NowContains(i::Handle<i::Object> val) { return this->NowContains(*val); } |
796 | 823 |
797 bool NowStable(); | 824 bool NowStable(); |
798 | 825 |
799 // Inspection. | 826 // Inspection. |
800 bool IsRange() { return IsKind(TypeBase::kRange); } | 827 bool IsRange() { return IsKind(AstTypeBase::kRange); } |
801 bool IsClass() { return IsKind(TypeBase::kClass); } | 828 bool IsClass() { return IsKind(AstTypeBase::kClass); } |
802 bool IsConstant() { return IsKind(TypeBase::kConstant); } | 829 bool IsConstant() { return IsKind(AstTypeBase::kConstant); } |
803 bool IsContext() { return IsKind(TypeBase::kContext); } | 830 bool IsContext() { return IsKind(AstTypeBase::kContext); } |
804 bool IsArray() { return IsKind(TypeBase::kArray); } | 831 bool IsArray() { return IsKind(AstTypeBase::kArray); } |
805 bool IsFunction() { return IsKind(TypeBase::kFunction); } | 832 bool IsFunction() { return IsKind(AstTypeBase::kFunction); } |
806 bool IsTuple() { return IsKind(TypeBase::kTuple); } | 833 bool IsTuple() { return IsKind(AstTypeBase::kTuple); } |
807 | 834 |
808 ClassType* AsClass() { return ClassType::cast(this); } | 835 AstClassType* AsClass() { return AstClassType::cast(this); } |
809 ConstantType* AsConstant() { return ConstantType::cast(this); } | 836 AstConstantType* AsConstant() { return AstConstantType::cast(this); } |
810 RangeType* AsRange() { return RangeType::cast(this); } | 837 AstRangeType* AsRange() { return AstRangeType::cast(this); } |
811 ContextType* AsContext() { return ContextType::cast(this); } | 838 AstContextType* AsContext() { return AstContextType::cast(this); } |
812 ArrayType* AsArray() { return ArrayType::cast(this); } | 839 AstArrayType* AsArray() { return AstArrayType::cast(this); } |
813 FunctionType* AsFunction() { return FunctionType::cast(this); } | 840 AstFunctionType* AsFunction() { return AstFunctionType::cast(this); } |
814 TupleType* AsTuple() { return TupleType::cast(this); } | 841 AstTupleType* AsTuple() { return AstTupleType::cast(this); } |
815 | 842 |
816 // Minimum and maximum of a numeric type. | 843 // Minimum and maximum of a numeric type. |
817 // These functions do not distinguish between -0 and +0. If the type equals | 844 // These functions do not distinguish between -0 and +0. If the type equals |
818 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these | 845 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these |
819 // functions on subtypes of Number. | 846 // functions on subtypes of Number. |
820 double Min(); | 847 double Min(); |
821 double Max(); | 848 double Max(); |
822 | 849 |
823 // Extracts a range from the type: if the type is a range or a union | 850 // Extracts a range from the type: if the type is a range or a union |
824 // containing a range, that range is returned; otherwise, NULL is returned. | 851 // containing a range, that range is returned; otherwise, NULL is returned. |
825 Type* GetRange(); | 852 AstType* GetRange(); |
826 | 853 |
827 static bool IsInteger(i::Object* x); | 854 static bool IsInteger(i::Object* x); |
828 static bool IsInteger(double x) { | 855 static bool IsInteger(double x) { |
829 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. | 856 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. |
830 } | 857 } |
831 | 858 |
832 int NumClasses(); | 859 int NumClasses(); |
833 int NumConstants(); | 860 int NumConstants(); |
834 | 861 |
835 template <class T> | 862 template <class T> |
836 class Iterator { | 863 class Iterator { |
837 public: | 864 public: |
838 bool Done() const { return index_ < 0; } | 865 bool Done() const { return index_ < 0; } |
839 i::Handle<T> Current(); | 866 i::Handle<T> Current(); |
840 void Advance(); | 867 void Advance(); |
841 | 868 |
842 private: | 869 private: |
843 friend class Type; | 870 friend class AstType; |
844 | 871 |
845 Iterator() : index_(-1) {} | 872 Iterator() : index_(-1) {} |
846 explicit Iterator(Type* type) : type_(type), index_(-1) { Advance(); } | 873 explicit Iterator(AstType* type) : type_(type), index_(-1) { Advance(); } |
847 | 874 |
848 inline bool matches(Type* type); | 875 inline bool matches(AstType* type); |
849 inline Type* get_type(); | 876 inline AstType* get_type(); |
850 | 877 |
851 Type* type_; | 878 AstType* type_; |
852 int index_; | 879 int index_; |
853 }; | 880 }; |
854 | 881 |
855 Iterator<i::Map> Classes() { | 882 Iterator<i::Map> Classes() { |
856 if (this->IsBitset()) return Iterator<i::Map>(); | 883 if (this->IsBitset()) return Iterator<i::Map>(); |
857 return Iterator<i::Map>(this); | 884 return Iterator<i::Map>(this); |
858 } | 885 } |
859 Iterator<i::Object> Constants() { | 886 Iterator<i::Object> Constants() { |
860 if (this->IsBitset()) return Iterator<i::Object>(); | 887 if (this->IsBitset()) return Iterator<i::Object>(); |
861 return Iterator<i::Object>(this); | 888 return Iterator<i::Object>(this); |
862 } | 889 } |
863 | 890 |
864 // Printing. | 891 // Printing. |
865 | 892 |
866 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; | 893 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; |
867 | 894 |
868 void PrintTo(std::ostream& os, PrintDimension dim = BOTH_DIMS); // NOLINT | 895 void PrintTo(std::ostream& os, PrintDimension dim = BOTH_DIMS); // NOLINT |
869 | 896 |
870 #ifdef DEBUG | 897 #ifdef DEBUG |
871 void Print(); | 898 void Print(); |
872 #endif | 899 #endif |
873 | 900 |
874 // Helpers for testing. | 901 // Helpers for testing. |
875 bool IsBitsetForTesting() { return IsBitset(); } | 902 bool IsBitsetForTesting() { return IsBitset(); } |
876 bool IsUnionForTesting() { return IsUnion(); } | 903 bool IsUnionForTesting() { return IsUnion(); } |
877 bitset AsBitsetForTesting() { return AsBitset(); } | 904 bitset AsBitsetForTesting() { return AsBitset(); } |
878 UnionType* AsUnionForTesting() { return AsUnion(); } | 905 AstUnionType* AsUnionForTesting() { return AsUnion(); } |
879 | 906 |
880 private: | 907 private: |
881 // Friends. | 908 // Friends. |
882 template <class> | 909 template <class> |
883 friend class Iterator; | 910 friend class Iterator; |
884 friend BitsetType; | 911 friend AstBitsetType; |
885 friend UnionType; | 912 friend AstUnionType; |
886 | 913 |
887 // Internal inspection. | 914 // Internal inspection. |
888 bool IsKind(TypeBase::Kind kind) { return TypeBase::IsKind(this, kind); } | 915 bool IsKind(AstTypeBase::Kind kind) { |
| 916 return AstTypeBase::IsKind(this, kind); |
| 917 } |
889 | 918 |
890 bool IsNone() { return this == None(); } | 919 bool IsNone() { return this == None(); } |
891 bool IsAny() { return this == Any(); } | 920 bool IsAny() { return this == Any(); } |
892 bool IsBitset() { return BitsetType::IsBitset(this); } | 921 bool IsBitset() { return AstBitsetType::IsBitset(this); } |
893 bool IsUnion() { return IsKind(TypeBase::kUnion); } | 922 bool IsUnion() { return IsKind(AstTypeBase::kUnion); } |
894 | 923 |
895 bitset AsBitset() { | 924 bitset AsBitset() { |
896 DCHECK(this->IsBitset()); | 925 DCHECK(this->IsBitset()); |
897 return reinterpret_cast<BitsetType*>(this)->Bitset(); | 926 return reinterpret_cast<AstBitsetType*>(this)->Bitset(); |
898 } | 927 } |
899 UnionType* AsUnion() { return UnionType::cast(this); } | 928 AstUnionType* AsUnion() { return AstUnionType::cast(this); } |
900 | 929 |
901 bitset Representation(); | 930 bitset Representation(); |
902 | 931 |
903 // Auxiliary functions. | 932 // Auxiliary functions. |
904 bool SemanticMaybe(Type* that); | 933 bool SemanticMaybe(AstType* that); |
905 | 934 |
906 bitset BitsetGlb() { return BitsetType::Glb(this); } | 935 bitset BitsetGlb() { return AstBitsetType::Glb(this); } |
907 bitset BitsetLub() { return BitsetType::Lub(this); } | 936 bitset BitsetLub() { return AstBitsetType::Lub(this); } |
908 | 937 |
909 bool SlowIs(Type* that); | 938 bool SlowIs(AstType* that); |
910 bool SemanticIs(Type* that); | 939 bool SemanticIs(AstType* that); |
911 | 940 |
912 static bool Overlap(RangeType* lhs, RangeType* rhs); | 941 static bool Overlap(AstRangeType* lhs, AstRangeType* rhs); |
913 static bool Contains(RangeType* lhs, RangeType* rhs); | 942 static bool Contains(AstRangeType* lhs, AstRangeType* rhs); |
914 static bool Contains(RangeType* range, ConstantType* constant); | 943 static bool Contains(AstRangeType* range, AstConstantType* constant); |
915 static bool Contains(RangeType* range, i::Object* val); | 944 static bool Contains(AstRangeType* range, i::Object* val); |
916 | 945 |
917 static int UpdateRange(Type* type, UnionType* result, int size, Zone* zone); | 946 static int UpdateRange(AstType* type, AstUnionType* result, int size, |
| 947 Zone* zone); |
918 | 948 |
919 static RangeType::Limits IntersectRangeAndBitset(Type* range, Type* bits, | 949 static AstRangeType::Limits IntersectRangeAndBitset(AstType* range, |
920 Zone* zone); | 950 AstType* bits, |
921 static RangeType::Limits ToLimits(bitset bits, Zone* zone); | 951 Zone* zone); |
| 952 static AstRangeType::Limits ToLimits(bitset bits, Zone* zone); |
922 | 953 |
923 bool SimplyEquals(Type* that); | 954 bool SimplyEquals(AstType* that); |
924 | 955 |
925 static int AddToUnion(Type* type, UnionType* result, int size, Zone* zone); | 956 static int AddToUnion(AstType* type, AstUnionType* result, int size, |
926 static int IntersectAux(Type* type, Type* other, UnionType* result, int size, | 957 Zone* zone); |
927 RangeType::Limits* limits, Zone* zone); | 958 static int IntersectAux(AstType* type, AstType* other, AstUnionType* result, |
928 static Type* NormalizeUnion(Type* unioned, int size, Zone* zone); | 959 int size, AstRangeType::Limits* limits, Zone* zone); |
929 static Type* NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone); | 960 static AstType* NormalizeUnion(AstType* unioned, int size, Zone* zone); |
| 961 static AstType* NormalizeRangeAndBitset(AstType* range, bitset* bits, |
| 962 Zone* zone); |
930 }; | 963 }; |
931 | 964 |
932 // ----------------------------------------------------------------------------- | 965 // ----------------------------------------------------------------------------- |
933 // Type bounds. A simple struct to represent a pair of lower/upper types. | 966 // Type bounds. A simple struct to represent a pair of lower/upper types. |
934 | 967 |
935 struct Bounds { | 968 struct AstBounds { |
936 Type* lower; | 969 AstType* lower; |
937 Type* upper; | 970 AstType* upper; |
938 | 971 |
939 Bounds() | 972 AstBounds() |
940 : // Make sure accessing uninitialized bounds crashes big-time. | 973 : // Make sure accessing uninitialized bounds crashes big-time. |
941 lower(nullptr), | 974 lower(nullptr), |
942 upper(nullptr) {} | 975 upper(nullptr) {} |
943 explicit Bounds(Type* t) : lower(t), upper(t) {} | 976 explicit AstBounds(AstType* t) : lower(t), upper(t) {} |
944 Bounds(Type* l, Type* u) : lower(l), upper(u) { DCHECK(lower->Is(upper)); } | 977 AstBounds(AstType* l, AstType* u) : lower(l), upper(u) { |
| 978 DCHECK(lower->Is(upper)); |
| 979 } |
945 | 980 |
946 // Unrestricted bounds. | 981 // Unrestricted bounds. |
947 static Bounds Unbounded() { return Bounds(Type::None(), Type::Any()); } | 982 static AstBounds Unbounded() { |
| 983 return AstBounds(AstType::None(), AstType::Any()); |
| 984 } |
948 | 985 |
949 // Meet: both b1 and b2 are known to hold. | 986 // Meet: both b1 and b2 are known to hold. |
950 static Bounds Both(Bounds b1, Bounds b2, Zone* zone) { | 987 static AstBounds Both(AstBounds b1, AstBounds b2, Zone* zone) { |
951 Type* lower = Type::Union(b1.lower, b2.lower, zone); | 988 AstType* lower = AstType::Union(b1.lower, b2.lower, zone); |
952 Type* upper = Type::Intersect(b1.upper, b2.upper, zone); | 989 AstType* upper = AstType::Intersect(b1.upper, b2.upper, zone); |
953 // Lower bounds are considered approximate, correct as necessary. | 990 // Lower bounds are considered approximate, correct as necessary. |
954 if (!lower->Is(upper)) lower = upper; | 991 if (!lower->Is(upper)) lower = upper; |
955 return Bounds(lower, upper); | 992 return AstBounds(lower, upper); |
956 } | 993 } |
957 | 994 |
958 // Join: either b1 or b2 is known to hold. | 995 // Join: either b1 or b2 is known to hold. |
959 static Bounds Either(Bounds b1, Bounds b2, Zone* zone) { | 996 static AstBounds Either(AstBounds b1, AstBounds b2, Zone* zone) { |
960 Type* lower = Type::Intersect(b1.lower, b2.lower, zone); | 997 AstType* lower = AstType::Intersect(b1.lower, b2.lower, zone); |
961 Type* upper = Type::Union(b1.upper, b2.upper, zone); | 998 AstType* upper = AstType::Union(b1.upper, b2.upper, zone); |
962 return Bounds(lower, upper); | 999 return AstBounds(lower, upper); |
963 } | 1000 } |
964 | 1001 |
965 static Bounds NarrowLower(Bounds b, Type* t, Zone* zone) { | 1002 static AstBounds NarrowLower(AstBounds b, AstType* t, Zone* zone) { |
966 Type* lower = Type::Union(b.lower, t, zone); | 1003 AstType* lower = AstType::Union(b.lower, t, zone); |
967 // Lower bounds are considered approximate, correct as necessary. | 1004 // Lower bounds are considered approximate, correct as necessary. |
968 if (!lower->Is(b.upper)) lower = b.upper; | 1005 if (!lower->Is(b.upper)) lower = b.upper; |
969 return Bounds(lower, b.upper); | 1006 return AstBounds(lower, b.upper); |
970 } | 1007 } |
971 static Bounds NarrowUpper(Bounds b, Type* t, Zone* zone) { | 1008 static AstBounds NarrowUpper(AstBounds b, AstType* t, Zone* zone) { |
972 Type* lower = b.lower; | 1009 AstType* lower = b.lower; |
973 Type* upper = Type::Intersect(b.upper, t, zone); | 1010 AstType* upper = AstType::Intersect(b.upper, t, zone); |
974 // Lower bounds are considered approximate, correct as necessary. | 1011 // Lower bounds are considered approximate, correct as necessary. |
975 if (!lower->Is(upper)) lower = upper; | 1012 if (!lower->Is(upper)) lower = upper; |
976 return Bounds(lower, upper); | 1013 return AstBounds(lower, upper); |
977 } | 1014 } |
978 | 1015 |
979 bool Narrows(Bounds that) { | 1016 bool Narrows(AstBounds that) { |
980 return that.lower->Is(this->lower) && this->upper->Is(that.upper); | 1017 return that.lower->Is(this->lower) && this->upper->Is(that.upper); |
981 } | 1018 } |
982 }; | 1019 }; |
983 | 1020 |
984 } // namespace internal | 1021 } // namespace internal |
985 } // namespace v8 | 1022 } // namespace v8 |
986 | 1023 |
987 #endif // V8_TYPES_H_ | 1024 #endif // V8_AST_AST_TYPES_H_ |
OLD | NEW |