Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: src/ast/ast-types.cc

Issue 2302283002: Forking the type system between Crankshaft & Turbofan. (Closed)
Patch Set: Nits. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/ast-types.h ('k') | src/code-stubs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <iomanip> 5 #include <iomanip>
6 6
7 #include "src/types.h" 7 #include "src/ast/ast-types.h"
8 8
9 #include "src/handles-inl.h" 9 #include "src/handles-inl.h"
10 #include "src/ostreams.h" 10 #include "src/ostreams.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15
16 // NOTE: If code is marked as being a "shortcut", this means that removing 15 // NOTE: If code is marked as being a "shortcut", this means that removing
17 // the code won't affect the semantics of the surrounding function definition. 16 // the code won't affect the semantics of the surrounding function definition.
18 17
19 // static 18 // static
20 bool Type::IsInteger(i::Object* x) { 19 bool AstType::IsInteger(i::Object* x) {
21 return x->IsNumber() && Type::IsInteger(x->Number()); 20 return x->IsNumber() && AstType::IsInteger(x->Number());
22 } 21 }
23 22
24 // ----------------------------------------------------------------------------- 23 // -----------------------------------------------------------------------------
25 // Range-related helper functions. 24 // Range-related helper functions.
26 25
27 bool RangeType::Limits::IsEmpty() { return this->min > this->max; } 26 bool AstRangeType::Limits::IsEmpty() { return this->min > this->max; }
28 27
29 RangeType::Limits RangeType::Limits::Intersect(Limits lhs, Limits rhs) { 28 AstRangeType::Limits AstRangeType::Limits::Intersect(Limits lhs, Limits rhs) {
30 DisallowHeapAllocation no_allocation; 29 DisallowHeapAllocation no_allocation;
31 Limits result(lhs); 30 Limits result(lhs);
32 if (lhs.min < rhs.min) result.min = rhs.min; 31 if (lhs.min < rhs.min) result.min = rhs.min;
33 if (lhs.max > rhs.max) result.max = rhs.max; 32 if (lhs.max > rhs.max) result.max = rhs.max;
34 return result; 33 return result;
35 } 34 }
36 35
37 RangeType::Limits RangeType::Limits::Union(Limits lhs, Limits rhs) { 36 AstRangeType::Limits AstRangeType::Limits::Union(Limits lhs, Limits rhs) {
38 DisallowHeapAllocation no_allocation; 37 DisallowHeapAllocation no_allocation;
39 if (lhs.IsEmpty()) return rhs; 38 if (lhs.IsEmpty()) return rhs;
40 if (rhs.IsEmpty()) return lhs; 39 if (rhs.IsEmpty()) return lhs;
41 Limits result(lhs); 40 Limits result(lhs);
42 if (lhs.min > rhs.min) result.min = rhs.min; 41 if (lhs.min > rhs.min) result.min = rhs.min;
43 if (lhs.max < rhs.max) result.max = rhs.max; 42 if (lhs.max < rhs.max) result.max = rhs.max;
44 return result; 43 return result;
45 } 44 }
46 45
47 bool Type::Overlap(RangeType* lhs, RangeType* rhs) { 46 bool AstType::Overlap(AstRangeType* lhs, AstRangeType* rhs) {
48 DisallowHeapAllocation no_allocation; 47 DisallowHeapAllocation no_allocation;
49 return !RangeType::Limits::Intersect(RangeType::Limits(lhs), 48 return !AstRangeType::Limits::Intersect(AstRangeType::Limits(lhs),
50 RangeType::Limits(rhs)) 49 AstRangeType::Limits(rhs))
51 .IsEmpty(); 50 .IsEmpty();
52 } 51 }
53 52
54 bool Type::Contains(RangeType* lhs, RangeType* rhs) { 53 bool AstType::Contains(AstRangeType* lhs, AstRangeType* rhs) {
55 DisallowHeapAllocation no_allocation; 54 DisallowHeapAllocation no_allocation;
56 return lhs->Min() <= rhs->Min() && rhs->Max() <= lhs->Max(); 55 return lhs->Min() <= rhs->Min() && rhs->Max() <= lhs->Max();
57 } 56 }
58 57
59 bool Type::Contains(RangeType* lhs, ConstantType* rhs) { 58 bool AstType::Contains(AstRangeType* lhs, AstConstantType* rhs) {
60 DisallowHeapAllocation no_allocation; 59 DisallowHeapAllocation no_allocation;
61 return IsInteger(*rhs->Value()) && 60 return IsInteger(*rhs->Value()) && lhs->Min() <= rhs->Value()->Number() &&
62 lhs->Min() <= rhs->Value()->Number() &&
63 rhs->Value()->Number() <= lhs->Max(); 61 rhs->Value()->Number() <= lhs->Max();
64 } 62 }
65 63
66 bool Type::Contains(RangeType* range, i::Object* val) { 64 bool AstType::Contains(AstRangeType* range, i::Object* val) {
67 DisallowHeapAllocation no_allocation; 65 DisallowHeapAllocation no_allocation;
68 return IsInteger(val) && 66 return IsInteger(val) && range->Min() <= val->Number() &&
69 range->Min() <= val->Number() && val->Number() <= range->Max(); 67 val->Number() <= range->Max();
70 } 68 }
71 69
72
73 // ----------------------------------------------------------------------------- 70 // -----------------------------------------------------------------------------
74 // Min and Max computation. 71 // Min and Max computation.
75 72
76 double Type::Min() { 73 double AstType::Min() {
77 DCHECK(this->SemanticIs(Number())); 74 DCHECK(this->SemanticIs(Number()));
78 if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); 75 if (this->IsBitset()) return AstBitsetType::Min(this->AsBitset());
79 if (this->IsUnion()) { 76 if (this->IsUnion()) {
80 double min = +V8_INFINITY; 77 double min = +V8_INFINITY;
81 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 78 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
82 min = std::min(min, this->AsUnion()->Get(i)->Min()); 79 min = std::min(min, this->AsUnion()->Get(i)->Min());
83 } 80 }
84 return min; 81 return min;
85 } 82 }
86 if (this->IsRange()) return this->AsRange()->Min(); 83 if (this->IsRange()) return this->AsRange()->Min();
87 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); 84 if (this->IsConstant()) return this->AsConstant()->Value()->Number();
88 UNREACHABLE(); 85 UNREACHABLE();
89 return 0; 86 return 0;
90 } 87 }
91 88
92 double Type::Max() { 89 double AstType::Max() {
93 DCHECK(this->SemanticIs(Number())); 90 DCHECK(this->SemanticIs(Number()));
94 if (this->IsBitset()) return BitsetType::Max(this->AsBitset()); 91 if (this->IsBitset()) return AstBitsetType::Max(this->AsBitset());
95 if (this->IsUnion()) { 92 if (this->IsUnion()) {
96 double max = -V8_INFINITY; 93 double max = -V8_INFINITY;
97 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 94 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
98 max = std::max(max, this->AsUnion()->Get(i)->Max()); 95 max = std::max(max, this->AsUnion()->Get(i)->Max());
99 } 96 }
100 return max; 97 return max;
101 } 98 }
102 if (this->IsRange()) return this->AsRange()->Max(); 99 if (this->IsRange()) return this->AsRange()->Max();
103 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); 100 if (this->IsConstant()) return this->AsConstant()->Value()->Number();
104 UNREACHABLE(); 101 UNREACHABLE();
105 return 0; 102 return 0;
106 } 103 }
107 104
108
109 // ----------------------------------------------------------------------------- 105 // -----------------------------------------------------------------------------
110 // Glb and lub computation. 106 // Glb and lub computation.
111 107
112
113 // The largest bitset subsumed by this type. 108 // The largest bitset subsumed by this type.
114 Type::bitset BitsetType::Glb(Type* type) { 109 AstType::bitset AstBitsetType::Glb(AstType* type) {
115 DisallowHeapAllocation no_allocation; 110 DisallowHeapAllocation no_allocation;
116 // Fast case. 111 // Fast case.
117 if (IsBitset(type)) { 112 if (IsBitset(type)) {
118 return type->AsBitset(); 113 return type->AsBitset();
119 } else if (type->IsUnion()) { 114 } else if (type->IsUnion()) {
120 SLOW_DCHECK(type->AsUnion()->Wellformed()); 115 SLOW_DCHECK(type->AsUnion()->Wellformed());
121 return type->AsUnion()->Get(0)->BitsetGlb() | 116 return type->AsUnion()->Get(0)->BitsetGlb() |
122 SEMANTIC(type->AsUnion()->Get(1)->BitsetGlb()); // Shortcut. 117 AST_SEMANTIC(type->AsUnion()->Get(1)->BitsetGlb()); // Shortcut.
123 } else if (type->IsRange()) { 118 } else if (type->IsRange()) {
124 bitset glb = SEMANTIC( 119 bitset glb = AST_SEMANTIC(
125 BitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max())); 120 AstBitsetType::Glb(type->AsRange()->Min(), type->AsRange()->Max()));
126 return glb | REPRESENTATION(type->BitsetLub()); 121 return glb | AST_REPRESENTATION(type->BitsetLub());
127 } else { 122 } else {
128 return type->Representation(); 123 return type->Representation();
129 } 124 }
130 } 125 }
131 126
132
133 // The smallest bitset subsuming this type, possibly not a proper one. 127 // The smallest bitset subsuming this type, possibly not a proper one.
134 Type::bitset BitsetType::Lub(Type* type) { 128 AstType::bitset AstBitsetType::Lub(AstType* type) {
135 DisallowHeapAllocation no_allocation; 129 DisallowHeapAllocation no_allocation;
136 if (IsBitset(type)) return type->AsBitset(); 130 if (IsBitset(type)) return type->AsBitset();
137 if (type->IsUnion()) { 131 if (type->IsUnion()) {
138 // Take the representation from the first element, which is always 132 // Take the representation from the first element, which is always
139 // a bitset. 133 // a bitset.
140 int bitset = type->AsUnion()->Get(0)->BitsetLub(); 134 int bitset = type->AsUnion()->Get(0)->BitsetLub();
141 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { 135 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
142 // Other elements only contribute their semantic part. 136 // Other elements only contribute their semantic part.
143 bitset |= SEMANTIC(type->AsUnion()->Get(i)->BitsetLub()); 137 bitset |= AST_SEMANTIC(type->AsUnion()->Get(i)->BitsetLub());
144 } 138 }
145 return bitset; 139 return bitset;
146 } 140 }
147 if (type->IsClass()) return type->AsClass()->Lub(); 141 if (type->IsClass()) return type->AsClass()->Lub();
148 if (type->IsConstant()) return type->AsConstant()->Lub(); 142 if (type->IsConstant()) return type->AsConstant()->Lub();
149 if (type->IsRange()) return type->AsRange()->Lub(); 143 if (type->IsRange()) return type->AsRange()->Lub();
150 if (type->IsContext()) return kOtherInternal & kTaggedPointer; 144 if (type->IsContext()) return kOtherInternal & kTaggedPointer;
151 if (type->IsArray()) return kOtherObject; 145 if (type->IsArray()) return kOtherObject;
152 if (type->IsFunction()) return kFunction; 146 if (type->IsFunction()) return kFunction;
153 if (type->IsTuple()) return kOtherInternal; 147 if (type->IsTuple()) return kOtherInternal;
154 UNREACHABLE(); 148 UNREACHABLE();
155 return kNone; 149 return kNone;
156 } 150 }
157 151
158 Type::bitset BitsetType::Lub(i::Map* map) { 152 AstType::bitset AstBitsetType::Lub(i::Map* map) {
159 DisallowHeapAllocation no_allocation; 153 DisallowHeapAllocation no_allocation;
160 switch (map->instance_type()) { 154 switch (map->instance_type()) {
161 case STRING_TYPE: 155 case STRING_TYPE:
162 case ONE_BYTE_STRING_TYPE: 156 case ONE_BYTE_STRING_TYPE:
163 case CONS_STRING_TYPE: 157 case CONS_STRING_TYPE:
164 case CONS_ONE_BYTE_STRING_TYPE: 158 case CONS_ONE_BYTE_STRING_TYPE:
165 case SLICED_STRING_TYPE: 159 case SLICED_STRING_TYPE:
166 case SLICED_ONE_BYTE_STRING_TYPE: 160 case SLICED_ONE_BYTE_STRING_TYPE:
167 case EXTERNAL_STRING_TYPE: 161 case EXTERNAL_STRING_TYPE:
168 case EXTERNAL_ONE_BYTE_STRING_TYPE: 162 case EXTERNAL_ONE_BYTE_STRING_TYPE:
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 case WEAK_CELL_TYPE: 273 case WEAK_CELL_TYPE:
280 case PROTOTYPE_INFO_TYPE: 274 case PROTOTYPE_INFO_TYPE:
281 case CONTEXT_EXTENSION_TYPE: 275 case CONTEXT_EXTENSION_TYPE:
282 UNREACHABLE(); 276 UNREACHABLE();
283 return kNone; 277 return kNone;
284 } 278 }
285 UNREACHABLE(); 279 UNREACHABLE();
286 return kNone; 280 return kNone;
287 } 281 }
288 282
289 Type::bitset BitsetType::Lub(i::Object* value) { 283 AstType::bitset AstBitsetType::Lub(i::Object* value) {
290 DisallowHeapAllocation no_allocation; 284 DisallowHeapAllocation no_allocation;
291 if (value->IsNumber()) { 285 if (value->IsNumber()) {
292 return Lub(value->Number()) & 286 return Lub(value->Number()) &
293 (value->IsSmi() ? kTaggedSigned : kTaggedPointer); 287 (value->IsSmi() ? kTaggedSigned : kTaggedPointer);
294 } 288 }
295 return Lub(i::HeapObject::cast(value)->map()); 289 return Lub(i::HeapObject::cast(value)->map());
296 } 290 }
297 291
298 Type::bitset BitsetType::Lub(double value) { 292 AstType::bitset AstBitsetType::Lub(double value) {
299 DisallowHeapAllocation no_allocation; 293 DisallowHeapAllocation no_allocation;
300 if (i::IsMinusZero(value)) return kMinusZero; 294 if (i::IsMinusZero(value)) return kMinusZero;
301 if (std::isnan(value)) return kNaN; 295 if (std::isnan(value)) return kNaN;
302 if (IsUint32Double(value) || IsInt32Double(value)) return Lub(value, value); 296 if (IsUint32Double(value) || IsInt32Double(value)) return Lub(value, value);
303 return kOtherNumber; 297 return kOtherNumber;
304 } 298 }
305 299
306
307 // Minimum values of plain numeric bitsets. 300 // Minimum values of plain numeric bitsets.
308 const BitsetType::Boundary BitsetType::BoundariesArray[] = { 301 const AstBitsetType::Boundary AstBitsetType::BoundariesArray[] = {
309 {kOtherNumber, kPlainNumber, -V8_INFINITY}, 302 {kOtherNumber, kPlainNumber, -V8_INFINITY},
310 {kOtherSigned32, kNegative32, kMinInt}, 303 {kOtherSigned32, kNegative32, kMinInt},
311 {kNegative31, kNegative31, -0x40000000}, 304 {kNegative31, kNegative31, -0x40000000},
312 {kUnsigned30, kUnsigned30, 0}, 305 {kUnsigned30, kUnsigned30, 0},
313 {kOtherUnsigned31, kUnsigned31, 0x40000000}, 306 {kOtherUnsigned31, kUnsigned31, 0x40000000},
314 {kOtherUnsigned32, kUnsigned32, 0x80000000}, 307 {kOtherUnsigned32, kUnsigned32, 0x80000000},
315 {kOtherNumber, kPlainNumber, static_cast<double>(kMaxUInt32) + 1}}; 308 {kOtherNumber, kPlainNumber, static_cast<double>(kMaxUInt32) + 1}};
316 309
317 const BitsetType::Boundary* BitsetType::Boundaries() { return BoundariesArray; } 310 const AstBitsetType::Boundary* AstBitsetType::Boundaries() {
311 return BoundariesArray;
312 }
318 313
319 size_t BitsetType::BoundariesSize() { 314 size_t AstBitsetType::BoundariesSize() {
320 // Windows doesn't like arraysize here. 315 // Windows doesn't like arraysize here.
321 // return arraysize(BoundariesArray); 316 // return arraysize(BoundariesArray);
322 return 7; 317 return 7;
323 } 318 }
324 319
325 Type::bitset BitsetType::ExpandInternals(Type::bitset bits) { 320 AstType::bitset AstBitsetType::ExpandInternals(AstType::bitset bits) {
326 DisallowHeapAllocation no_allocation; 321 DisallowHeapAllocation no_allocation;
327 if (!(bits & SEMANTIC(kPlainNumber))) return bits; // Shortcut. 322 if (!(bits & AST_SEMANTIC(kPlainNumber))) return bits; // Shortcut.
328 const Boundary* boundaries = Boundaries(); 323 const Boundary* boundaries = Boundaries();
329 for (size_t i = 0; i < BoundariesSize(); ++i) { 324 for (size_t i = 0; i < BoundariesSize(); ++i) {
330 DCHECK(BitsetType::Is(boundaries[i].internal, boundaries[i].external)); 325 DCHECK(AstBitsetType::Is(boundaries[i].internal, boundaries[i].external));
331 if (bits & SEMANTIC(boundaries[i].internal)) 326 if (bits & AST_SEMANTIC(boundaries[i].internal))
332 bits |= SEMANTIC(boundaries[i].external); 327 bits |= AST_SEMANTIC(boundaries[i].external);
333 } 328 }
334 return bits; 329 return bits;
335 } 330 }
336 331
337 Type::bitset BitsetType::Lub(double min, double max) { 332 AstType::bitset AstBitsetType::Lub(double min, double max) {
338 DisallowHeapAllocation no_allocation; 333 DisallowHeapAllocation no_allocation;
339 int lub = kNone; 334 int lub = kNone;
340 const Boundary* mins = Boundaries(); 335 const Boundary* mins = Boundaries();
341 336
342 for (size_t i = 1; i < BoundariesSize(); ++i) { 337 for (size_t i = 1; i < BoundariesSize(); ++i) {
343 if (min < mins[i].min) { 338 if (min < mins[i].min) {
344 lub |= mins[i-1].internal; 339 lub |= mins[i - 1].internal;
345 if (max < mins[i].min) return lub; 340 if (max < mins[i].min) return lub;
346 } 341 }
347 } 342 }
348 return lub | mins[BoundariesSize() - 1].internal; 343 return lub | mins[BoundariesSize() - 1].internal;
349 } 344 }
350 345
351 Type::bitset BitsetType::NumberBits(bitset bits) { 346 AstType::bitset AstBitsetType::NumberBits(bitset bits) {
352 return SEMANTIC(bits & kPlainNumber); 347 return AST_SEMANTIC(bits & kPlainNumber);
353 } 348 }
354 349
355 Type::bitset BitsetType::Glb(double min, double max) { 350 AstType::bitset AstBitsetType::Glb(double min, double max) {
356 DisallowHeapAllocation no_allocation; 351 DisallowHeapAllocation no_allocation;
357 int glb = kNone; 352 int glb = kNone;
358 const Boundary* mins = Boundaries(); 353 const Boundary* mins = Boundaries();
359 354
360 // If the range does not touch 0, the bound is empty. 355 // If the range does not touch 0, the bound is empty.
361 if (max < -1 || min > 0) return glb; 356 if (max < -1 || min > 0) return glb;
362 357
363 for (size_t i = 1; i + 1 < BoundariesSize(); ++i) { 358 for (size_t i = 1; i + 1 < BoundariesSize(); ++i) {
364 if (min <= mins[i].min) { 359 if (min <= mins[i].min) {
365 if (max + 1 < mins[i + 1].min) break; 360 if (max + 1 < mins[i + 1].min) break;
366 glb |= mins[i].external; 361 glb |= mins[i].external;
367 } 362 }
368 } 363 }
369 // OtherNumber also contains float numbers, so it can never be 364 // OtherNumber also contains float numbers, so it can never be
370 // in the greatest lower bound. 365 // in the greatest lower bound.
371 return glb & ~(SEMANTIC(kOtherNumber)); 366 return glb & ~(AST_SEMANTIC(kOtherNumber));
372 } 367 }
373 368
374 double BitsetType::Min(bitset bits) { 369 double AstBitsetType::Min(bitset bits) {
375 DisallowHeapAllocation no_allocation; 370 DisallowHeapAllocation no_allocation;
376 DCHECK(Is(SEMANTIC(bits), kNumber)); 371 DCHECK(Is(AST_SEMANTIC(bits), kNumber));
377 const Boundary* mins = Boundaries(); 372 const Boundary* mins = Boundaries();
378 bool mz = SEMANTIC(bits & kMinusZero); 373 bool mz = AST_SEMANTIC(bits & kMinusZero);
379 for (size_t i = 0; i < BoundariesSize(); ++i) { 374 for (size_t i = 0; i < BoundariesSize(); ++i) {
380 if (Is(SEMANTIC(mins[i].internal), bits)) { 375 if (Is(AST_SEMANTIC(mins[i].internal), bits)) {
381 return mz ? std::min(0.0, mins[i].min) : mins[i].min; 376 return mz ? std::min(0.0, mins[i].min) : mins[i].min;
382 } 377 }
383 } 378 }
384 if (mz) return 0; 379 if (mz) return 0;
385 return std::numeric_limits<double>::quiet_NaN(); 380 return std::numeric_limits<double>::quiet_NaN();
386 } 381 }
387 382
388 double BitsetType::Max(bitset bits) { 383 double AstBitsetType::Max(bitset bits) {
389 DisallowHeapAllocation no_allocation; 384 DisallowHeapAllocation no_allocation;
390 DCHECK(Is(SEMANTIC(bits), kNumber)); 385 DCHECK(Is(AST_SEMANTIC(bits), kNumber));
391 const Boundary* mins = Boundaries(); 386 const Boundary* mins = Boundaries();
392 bool mz = SEMANTIC(bits & kMinusZero); 387 bool mz = AST_SEMANTIC(bits & kMinusZero);
393 if (BitsetType::Is(SEMANTIC(mins[BoundariesSize() - 1].internal), bits)) { 388 if (AstBitsetType::Is(AST_SEMANTIC(mins[BoundariesSize() - 1].internal),
389 bits)) {
394 return +V8_INFINITY; 390 return +V8_INFINITY;
395 } 391 }
396 for (size_t i = BoundariesSize() - 1; i-- > 0;) { 392 for (size_t i = BoundariesSize() - 1; i-- > 0;) {
397 if (Is(SEMANTIC(mins[i].internal), bits)) { 393 if (Is(AST_SEMANTIC(mins[i].internal), bits)) {
398 return mz ? 394 return mz ? std::max(0.0, mins[i + 1].min - 1) : mins[i + 1].min - 1;
399 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1;
400 } 395 }
401 } 396 }
402 if (mz) return 0; 397 if (mz) return 0;
403 return std::numeric_limits<double>::quiet_NaN(); 398 return std::numeric_limits<double>::quiet_NaN();
404 } 399 }
405 400
406
407 // ----------------------------------------------------------------------------- 401 // -----------------------------------------------------------------------------
408 // Predicates. 402 // Predicates.
409 403
410 bool Type::SimplyEquals(Type* that) { 404 bool AstType::SimplyEquals(AstType* that) {
411 DisallowHeapAllocation no_allocation; 405 DisallowHeapAllocation no_allocation;
412 if (this->IsClass()) { 406 if (this->IsClass()) {
413 return that->IsClass() 407 return that->IsClass() &&
414 && *this->AsClass()->Map() == *that->AsClass()->Map(); 408 *this->AsClass()->Map() == *that->AsClass()->Map();
415 } 409 }
416 if (this->IsConstant()) { 410 if (this->IsConstant()) {
417 return that->IsConstant() 411 return that->IsConstant() &&
418 && *this->AsConstant()->Value() == *that->AsConstant()->Value(); 412 *this->AsConstant()->Value() == *that->AsConstant()->Value();
419 } 413 }
420 if (this->IsContext()) { 414 if (this->IsContext()) {
421 return that->IsContext() 415 return that->IsContext() &&
422 && this->AsContext()->Outer()->Equals(that->AsContext()->Outer()); 416 this->AsContext()->Outer()->Equals(that->AsContext()->Outer());
423 } 417 }
424 if (this->IsArray()) { 418 if (this->IsArray()) {
425 return that->IsArray() 419 return that->IsArray() &&
426 && this->AsArray()->Element()->Equals(that->AsArray()->Element()); 420 this->AsArray()->Element()->Equals(that->AsArray()->Element());
427 } 421 }
428 if (this->IsFunction()) { 422 if (this->IsFunction()) {
429 if (!that->IsFunction()) return false; 423 if (!that->IsFunction()) return false;
430 FunctionType* this_fun = this->AsFunction(); 424 AstFunctionType* this_fun = this->AsFunction();
431 FunctionType* that_fun = that->AsFunction(); 425 AstFunctionType* that_fun = that->AsFunction();
432 if (this_fun->Arity() != that_fun->Arity() || 426 if (this_fun->Arity() != that_fun->Arity() ||
433 !this_fun->Result()->Equals(that_fun->Result()) || 427 !this_fun->Result()->Equals(that_fun->Result()) ||
434 !this_fun->Receiver()->Equals(that_fun->Receiver())) { 428 !this_fun->Receiver()->Equals(that_fun->Receiver())) {
435 return false; 429 return false;
436 } 430 }
437 for (int i = 0, n = this_fun->Arity(); i < n; ++i) { 431 for (int i = 0, n = this_fun->Arity(); i < n; ++i) {
438 if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false; 432 if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false;
439 } 433 }
440 return true; 434 return true;
441 } 435 }
442 if (this->IsTuple()) { 436 if (this->IsTuple()) {
443 if (!that->IsTuple()) return false; 437 if (!that->IsTuple()) return false;
444 TupleType* this_tuple = this->AsTuple(); 438 AstTupleType* this_tuple = this->AsTuple();
445 TupleType* that_tuple = that->AsTuple(); 439 AstTupleType* that_tuple = that->AsTuple();
446 if (this_tuple->Arity() != that_tuple->Arity()) { 440 if (this_tuple->Arity() != that_tuple->Arity()) {
447 return false; 441 return false;
448 } 442 }
449 for (int i = 0, n = this_tuple->Arity(); i < n; ++i) { 443 for (int i = 0, n = this_tuple->Arity(); i < n; ++i) {
450 if (!this_tuple->Element(i)->Equals(that_tuple->Element(i))) return false; 444 if (!this_tuple->Element(i)->Equals(that_tuple->Element(i))) return false;
451 } 445 }
452 return true; 446 return true;
453 } 447 }
454 UNREACHABLE(); 448 UNREACHABLE();
455 return false; 449 return false;
456 } 450 }
457 451
458 Type::bitset Type::Representation() { 452 AstType::bitset AstType::Representation() {
459 return REPRESENTATION(this->BitsetLub()); 453 return AST_REPRESENTATION(this->BitsetLub());
460 } 454 }
461 455
462
463 // Check if [this] <= [that]. 456 // Check if [this] <= [that].
464 bool Type::SlowIs(Type* that) { 457 bool AstType::SlowIs(AstType* that) {
465 DisallowHeapAllocation no_allocation; 458 DisallowHeapAllocation no_allocation;
466 459
467 // Fast bitset cases 460 // Fast bitset cases
468 if (that->IsBitset()) { 461 if (that->IsBitset()) {
469 return BitsetType::Is(this->BitsetLub(), that->AsBitset()); 462 return AstBitsetType::Is(this->BitsetLub(), that->AsBitset());
470 } 463 }
471 464
472 if (this->IsBitset()) { 465 if (this->IsBitset()) {
473 return BitsetType::Is(this->AsBitset(), that->BitsetGlb()); 466 return AstBitsetType::Is(this->AsBitset(), that->BitsetGlb());
474 } 467 }
475 468
476 // Check the representations. 469 // Check the representations.
477 if (!BitsetType::Is(Representation(), that->Representation())) { 470 if (!AstBitsetType::Is(Representation(), that->Representation())) {
478 return false; 471 return false;
479 } 472 }
480 473
481 // Check the semantic part. 474 // Check the semantic part.
482 return SemanticIs(that); 475 return SemanticIs(that);
483 } 476 }
484 477
485 478 // Check if AST_SEMANTIC([this]) <= AST_SEMANTIC([that]). The result of the
486 // Check if SEMANTIC([this]) <= SEMANTIC([that]). The result of the method 479 // method
487 // should be independent of the representation axis of the types. 480 // should be independent of the representation axis of the types.
488 bool Type::SemanticIs(Type* that) { 481 bool AstType::SemanticIs(AstType* that) {
489 DisallowHeapAllocation no_allocation; 482 DisallowHeapAllocation no_allocation;
490 483
491 if (this == that) return true; 484 if (this == that) return true;
492 485
493 if (that->IsBitset()) { 486 if (that->IsBitset()) {
494 return BitsetType::Is(SEMANTIC(this->BitsetLub()), that->AsBitset()); 487 return AstBitsetType::Is(AST_SEMANTIC(this->BitsetLub()), that->AsBitset());
495 } 488 }
496 if (this->IsBitset()) { 489 if (this->IsBitset()) {
497 return BitsetType::Is(SEMANTIC(this->AsBitset()), that->BitsetGlb()); 490 return AstBitsetType::Is(AST_SEMANTIC(this->AsBitset()), that->BitsetGlb());
498 } 491 }
499 492
500 // (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T) 493 // (T1 \/ ... \/ Tn) <= T if (T1 <= T) /\ ... /\ (Tn <= T)
501 if (this->IsUnion()) { 494 if (this->IsUnion()) {
502 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 495 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
503 if (!this->AsUnion()->Get(i)->SemanticIs(that)) return false; 496 if (!this->AsUnion()->Get(i)->SemanticIs(that)) return false;
504 } 497 }
505 return true; 498 return true;
506 } 499 }
507 500
(...skipping 10 matching lines...) Expand all
518 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) || 511 return (this->IsRange() && Contains(that->AsRange(), this->AsRange())) ||
519 (this->IsConstant() && 512 (this->IsConstant() &&
520 Contains(that->AsRange(), this->AsConstant())); 513 Contains(that->AsRange(), this->AsConstant()));
521 } 514 }
522 if (this->IsRange()) return false; 515 if (this->IsRange()) return false;
523 516
524 return this->SimplyEquals(that); 517 return this->SimplyEquals(that);
525 } 518 }
526 519
527 // Most precise _current_ type of a value (usually its class). 520 // Most precise _current_ type of a value (usually its class).
528 Type* Type::NowOf(i::Object* value, Zone* zone) { 521 AstType* AstType::NowOf(i::Object* value, Zone* zone) {
529 if (value->IsSmi() || 522 if (value->IsSmi() ||
530 i::HeapObject::cast(value)->map()->instance_type() == HEAP_NUMBER_TYPE) { 523 i::HeapObject::cast(value)->map()->instance_type() == HEAP_NUMBER_TYPE) {
531 return Of(value, zone); 524 return Of(value, zone);
532 } 525 }
533 return Class(i::handle(i::HeapObject::cast(value)->map()), zone); 526 return Class(i::handle(i::HeapObject::cast(value)->map()), zone);
534 } 527 }
535 528
536 bool Type::NowContains(i::Object* value) { 529 bool AstType::NowContains(i::Object* value) {
537 DisallowHeapAllocation no_allocation; 530 DisallowHeapAllocation no_allocation;
538 if (this->IsAny()) return true; 531 if (this->IsAny()) return true;
539 if (value->IsHeapObject()) { 532 if (value->IsHeapObject()) {
540 i::Map* map = i::HeapObject::cast(value)->map(); 533 i::Map* map = i::HeapObject::cast(value)->map();
541 for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) { 534 for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) {
542 if (*it.Current() == map) return true; 535 if (*it.Current() == map) return true;
543 } 536 }
544 } 537 }
545 return this->Contains(value); 538 return this->Contains(value);
546 } 539 }
547 540
548 bool Type::NowIs(Type* that) { 541 bool AstType::NowIs(AstType* that) {
549 DisallowHeapAllocation no_allocation; 542 DisallowHeapAllocation no_allocation;
550 543
551 // TODO(rossberg): this is incorrect for 544 // TODO(rossberg): this is incorrect for
552 // Union(Constant(V), T)->NowIs(Class(M)) 545 // Union(Constant(V), T)->NowIs(Class(M))
553 // but fuzzing does not cover that! 546 // but fuzzing does not cover that!
554 if (this->IsConstant()) { 547 if (this->IsConstant()) {
555 i::Object* object = *this->AsConstant()->Value(); 548 i::Object* object = *this->AsConstant()->Value();
556 if (object->IsHeapObject()) { 549 if (object->IsHeapObject()) {
557 i::Map* map = i::HeapObject::cast(object)->map(); 550 i::Map* map = i::HeapObject::cast(object)->map();
558 for (Iterator<i::Map> it = that->Classes(); !it.Done(); it.Advance()) { 551 for (Iterator<i::Map> it = that->Classes(); !it.Done(); it.Advance()) {
559 if (*it.Current() == map) return true; 552 if (*it.Current() == map) return true;
560 } 553 }
561 } 554 }
562 } 555 }
563 return this->Is(that); 556 return this->Is(that);
564 } 557 }
565 558
566
567 // Check if [this] contains only (currently) stable classes. 559 // Check if [this] contains only (currently) stable classes.
568 bool Type::NowStable() { 560 bool AstType::NowStable() {
569 DisallowHeapAllocation no_allocation; 561 DisallowHeapAllocation no_allocation;
570 return !this->IsClass() || this->AsClass()->Map()->is_stable(); 562 return !this->IsClass() || this->AsClass()->Map()->is_stable();
571 } 563 }
572 564
573
574 // Check if [this] and [that] overlap. 565 // Check if [this] and [that] overlap.
575 bool Type::Maybe(Type* that) { 566 bool AstType::Maybe(AstType* that) {
576 DisallowHeapAllocation no_allocation; 567 DisallowHeapAllocation no_allocation;
577 568
578 // Take care of the representation part (and also approximate 569 // Take care of the representation part (and also approximate
579 // the semantic part). 570 // the semantic part).
580 if (!BitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub())) 571 if (!AstBitsetType::IsInhabited(this->BitsetLub() & that->BitsetLub()))
581 return false; 572 return false;
582 573
583 return SemanticMaybe(that); 574 return SemanticMaybe(that);
584 } 575 }
585 576
586 bool Type::SemanticMaybe(Type* that) { 577 bool AstType::SemanticMaybe(AstType* that) {
587 DisallowHeapAllocation no_allocation; 578 DisallowHeapAllocation no_allocation;
588 579
589 // (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T) 580 // (T1 \/ ... \/ Tn) overlaps T if (T1 overlaps T) \/ ... \/ (Tn overlaps T)
590 if (this->IsUnion()) { 581 if (this->IsUnion()) {
591 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 582 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
592 if (this->AsUnion()->Get(i)->SemanticMaybe(that)) return true; 583 if (this->AsUnion()->Get(i)->SemanticMaybe(that)) return true;
593 } 584 }
594 return false; 585 return false;
595 } 586 }
596 587
597 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn) 588 // T overlaps (T1 \/ ... \/ Tn) if (T overlaps T1) \/ ... \/ (T overlaps Tn)
598 if (that->IsUnion()) { 589 if (that->IsUnion()) {
599 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) { 590 for (int i = 0, n = that->AsUnion()->Length(); i < n; ++i) {
600 if (this->SemanticMaybe(that->AsUnion()->Get(i))) return true; 591 if (this->SemanticMaybe(that->AsUnion()->Get(i))) return true;
601 } 592 }
602 return false; 593 return false;
603 } 594 }
604 595
605 if (!BitsetType::SemanticIsInhabited(this->BitsetLub() & that->BitsetLub())) 596 if (!AstBitsetType::SemanticIsInhabited(this->BitsetLub() &
597 that->BitsetLub()))
606 return false; 598 return false;
607 599
608 if (this->IsBitset() && that->IsBitset()) return true; 600 if (this->IsBitset() && that->IsBitset()) return true;
609 601
610 if (this->IsClass() != that->IsClass()) return true; 602 if (this->IsClass() != that->IsClass()) return true;
611 603
612 if (this->IsRange()) { 604 if (this->IsRange()) {
613 if (that->IsConstant()) { 605 if (that->IsConstant()) {
614 return Contains(this->AsRange(), that->AsConstant()); 606 return Contains(this->AsRange(), that->AsConstant());
615 } 607 }
616 if (that->IsRange()) { 608 if (that->IsRange()) {
617 return Overlap(this->AsRange(), that->AsRange()); 609 return Overlap(this->AsRange(), that->AsRange());
618 } 610 }
619 if (that->IsBitset()) { 611 if (that->IsBitset()) {
620 bitset number_bits = BitsetType::NumberBits(that->AsBitset()); 612 bitset number_bits = AstBitsetType::NumberBits(that->AsBitset());
621 if (number_bits == BitsetType::kNone) { 613 if (number_bits == AstBitsetType::kNone) {
622 return false; 614 return false;
623 } 615 }
624 double min = std::max(BitsetType::Min(number_bits), this->Min()); 616 double min = std::max(AstBitsetType::Min(number_bits), this->Min());
625 double max = std::min(BitsetType::Max(number_bits), this->Max()); 617 double max = std::min(AstBitsetType::Max(number_bits), this->Max());
626 return min <= max; 618 return min <= max;
627 } 619 }
628 } 620 }
629 if (that->IsRange()) { 621 if (that->IsRange()) {
630 return that->SemanticMaybe(this); // This case is handled above. 622 return that->SemanticMaybe(this); // This case is handled above.
631 } 623 }
632 624
633 if (this->IsBitset() || that->IsBitset()) return true; 625 if (this->IsBitset() || that->IsBitset()) return true;
634 626
635 return this->SimplyEquals(that); 627 return this->SimplyEquals(that);
636 } 628 }
637 629
638
639 // Return the range in [this], or [NULL]. 630 // Return the range in [this], or [NULL].
640 Type* Type::GetRange() { 631 AstType* AstType::GetRange() {
641 DisallowHeapAllocation no_allocation; 632 DisallowHeapAllocation no_allocation;
642 if (this->IsRange()) return this; 633 if (this->IsRange()) return this;
643 if (this->IsUnion() && this->AsUnion()->Get(1)->IsRange()) { 634 if (this->IsUnion() && this->AsUnion()->Get(1)->IsRange()) {
644 return this->AsUnion()->Get(1); 635 return this->AsUnion()->Get(1);
645 } 636 }
646 return NULL; 637 return NULL;
647 } 638 }
648 639
649 bool Type::Contains(i::Object* value) { 640 bool AstType::Contains(i::Object* value) {
650 DisallowHeapAllocation no_allocation; 641 DisallowHeapAllocation no_allocation;
651 for (Iterator<i::Object> it = this->Constants(); !it.Done(); it.Advance()) { 642 for (Iterator<i::Object> it = this->Constants(); !it.Done(); it.Advance()) {
652 if (*it.Current() == value) return true; 643 if (*it.Current() == value) return true;
653 } 644 }
654 if (IsInteger(value)) { 645 if (IsInteger(value)) {
655 Type* range = this->GetRange(); 646 AstType* range = this->GetRange();
656 if (range != NULL && Contains(range->AsRange(), value)) return true; 647 if (range != NULL && Contains(range->AsRange(), value)) return true;
657 } 648 }
658 return BitsetType::New(BitsetType::Lub(value))->Is(this); 649 return AstBitsetType::New(AstBitsetType::Lub(value))->Is(this);
659 } 650 }
660 651
661 bool UnionType::Wellformed() { 652 bool AstUnionType::Wellformed() {
662 DisallowHeapAllocation no_allocation; 653 DisallowHeapAllocation no_allocation;
663 // This checks the invariants of the union representation: 654 // This checks the invariants of the union representation:
664 // 1. There are at least two elements. 655 // 1. There are at least two elements.
665 // 2. The first element is a bitset, no other element is a bitset. 656 // 2. The first element is a bitset, no other element is a bitset.
666 // 3. At most one element is a range, and it must be the second one. 657 // 3. At most one element is a range, and it must be the second one.
667 // 4. No element is itself a union. 658 // 4. No element is itself a union.
668 // 5. No element (except the bitset) is a subtype of any other. 659 // 5. No element (except the bitset) is a subtype of any other.
669 // 6. If there is a range, then the bitset type does not contain 660 // 6. If there is a range, then the bitset type does not contain
670 // plain number bits. 661 // plain number bits.
671 DCHECK(this->Length() >= 2); // (1) 662 DCHECK(this->Length() >= 2); // (1)
672 DCHECK(this->Get(0)->IsBitset()); // (2a) 663 DCHECK(this->Get(0)->IsBitset()); // (2a)
673 664
674 for (int i = 0; i < this->Length(); ++i) { 665 for (int i = 0; i < this->Length(); ++i) {
675 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2b) 666 if (i != 0) DCHECK(!this->Get(i)->IsBitset()); // (2b)
676 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3) 667 if (i != 1) DCHECK(!this->Get(i)->IsRange()); // (3)
677 DCHECK(!this->Get(i)->IsUnion()); // (4) 668 DCHECK(!this->Get(i)->IsUnion()); // (4)
678 for (int j = 0; j < this->Length(); ++j) { 669 for (int j = 0; j < this->Length(); ++j) {
679 if (i != j && i != 0) 670 if (i != j && i != 0)
680 DCHECK(!this->Get(i)->SemanticIs(this->Get(j))); // (5) 671 DCHECK(!this->Get(i)->SemanticIs(this->Get(j))); // (5)
681 } 672 }
682 } 673 }
683 DCHECK(!this->Get(1)->IsRange() || 674 DCHECK(!this->Get(1)->IsRange() ||
684 (BitsetType::NumberBits(this->Get(0)->AsBitset()) == 675 (AstBitsetType::NumberBits(this->Get(0)->AsBitset()) ==
685 BitsetType::kNone)); // (6) 676 AstBitsetType::kNone)); // (6)
686 return true; 677 return true;
687 } 678 }
688 679
689
690 // ----------------------------------------------------------------------------- 680 // -----------------------------------------------------------------------------
691 // Union and intersection 681 // Union and intersection
692 682
693
694 static bool AddIsSafe(int x, int y) { 683 static bool AddIsSafe(int x, int y) {
695 return x >= 0 ? 684 return x >= 0 ? y <= std::numeric_limits<int>::max() - x
696 y <= std::numeric_limits<int>::max() - x : 685 : y >= std::numeric_limits<int>::min() - x;
697 y >= std::numeric_limits<int>::min() - x;
698 } 686 }
699 687
700 Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) { 688 AstType* AstType::Intersect(AstType* type1, AstType* type2, Zone* zone) {
701 // Fast case: bit sets. 689 // Fast case: bit sets.
702 if (type1->IsBitset() && type2->IsBitset()) { 690 if (type1->IsBitset() && type2->IsBitset()) {
703 return BitsetType::New(type1->AsBitset() & type2->AsBitset()); 691 return AstBitsetType::New(type1->AsBitset() & type2->AsBitset());
704 } 692 }
705 693
706 // Fast case: top or bottom types. 694 // Fast case: top or bottom types.
707 if (type1->IsNone() || type2->IsAny()) return type1; // Shortcut. 695 if (type1->IsNone() || type2->IsAny()) return type1; // Shortcut.
708 if (type2->IsNone() || type1->IsAny()) return type2; // Shortcut. 696 if (type2->IsNone() || type1->IsAny()) return type2; // Shortcut.
709 697
710 // Semi-fast case. 698 // Semi-fast case.
711 if (type1->Is(type2)) return type1; 699 if (type1->Is(type2)) return type1;
712 if (type2->Is(type1)) return type2; 700 if (type2->Is(type1)) return type2;
713 701
(...skipping 10 matching lines...) Expand all
724 // semi-fast case above - we should behave the same way regardless of 712 // semi-fast case above - we should behave the same way regardless of
725 // representations. Intersection with a universal bitset should only update 713 // representations. Intersection with a universal bitset should only update
726 // the representations. 714 // the representations.
727 if (type1->SemanticIs(type2)) { 715 if (type1->SemanticIs(type2)) {
728 type2 = Any(); 716 type2 = Any();
729 } else if (type2->SemanticIs(type1)) { 717 } else if (type2->SemanticIs(type1)) {
730 type1 = Any(); 718 type1 = Any();
731 } 719 }
732 720
733 bitset bits = 721 bitset bits =
734 SEMANTIC(type1->BitsetGlb() & type2->BitsetGlb()) | representation; 722 AST_SEMANTIC(type1->BitsetGlb() & type2->BitsetGlb()) | representation;
735 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; 723 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
736 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; 724 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
737 if (!AddIsSafe(size1, size2)) return Any(); 725 if (!AddIsSafe(size1, size2)) return Any();
738 int size = size1 + size2; 726 int size = size1 + size2;
739 if (!AddIsSafe(size, 2)) return Any(); 727 if (!AddIsSafe(size, 2)) return Any();
740 size += 2; 728 size += 2;
741 Type* result_type = UnionType::New(size, zone); 729 AstType* result_type = AstUnionType::New(size, zone);
742 UnionType* result = result_type->AsUnion(); 730 AstUnionType* result = result_type->AsUnion();
743 size = 0; 731 size = 0;
744 732
745 // Deal with bitsets. 733 // Deal with bitsets.
746 result->Set(size++, BitsetType::New(bits)); 734 result->Set(size++, AstBitsetType::New(bits));
747 735
748 RangeType::Limits lims = RangeType::Limits::Empty(); 736 AstRangeType::Limits lims = AstRangeType::Limits::Empty();
749 size = IntersectAux(type1, type2, result, size, &lims, zone); 737 size = IntersectAux(type1, type2, result, size, &lims, zone);
750 738
751 // If the range is not empty, then insert it into the union and 739 // If the range is not empty, then insert it into the union and
752 // remove the number bits from the bitset. 740 // remove the number bits from the bitset.
753 if (!lims.IsEmpty()) { 741 if (!lims.IsEmpty()) {
754 size = UpdateRange(RangeType::New(lims, representation, zone), result, size, 742 size = UpdateRange(AstRangeType::New(lims, representation, zone), result,
755 zone); 743 size, zone);
756 744
757 // Remove the number bits. 745 // Remove the number bits.
758 bitset number_bits = BitsetType::NumberBits(bits); 746 bitset number_bits = AstBitsetType::NumberBits(bits);
759 bits &= ~number_bits; 747 bits &= ~number_bits;
760 result->Set(0, BitsetType::New(bits)); 748 result->Set(0, AstBitsetType::New(bits));
761 } 749 }
762 return NormalizeUnion(result_type, size, zone); 750 return NormalizeUnion(result_type, size, zone);
763 } 751 }
764 752
765 int Type::UpdateRange(Type* range, UnionType* result, int size, Zone* zone) { 753 int AstType::UpdateRange(AstType* range, AstUnionType* result, int size,
754 Zone* zone) {
766 if (size == 1) { 755 if (size == 1) {
767 result->Set(size++, range); 756 result->Set(size++, range);
768 } else { 757 } else {
769 // Make space for the range. 758 // Make space for the range.
770 result->Set(size++, result->Get(1)); 759 result->Set(size++, result->Get(1));
771 result->Set(1, range); 760 result->Set(1, range);
772 } 761 }
773 762
774 // Remove any components that just got subsumed. 763 // Remove any components that just got subsumed.
775 for (int i = 2; i < size; ) { 764 for (int i = 2; i < size;) {
776 if (result->Get(i)->SemanticIs(range)) { 765 if (result->Get(i)->SemanticIs(range)) {
777 result->Set(i, result->Get(--size)); 766 result->Set(i, result->Get(--size));
778 } else { 767 } else {
779 ++i; 768 ++i;
780 } 769 }
781 } 770 }
782 return size; 771 return size;
783 } 772 }
784 773
785 RangeType::Limits Type::ToLimits(bitset bits, Zone* zone) { 774 AstRangeType::Limits AstType::ToLimits(bitset bits, Zone* zone) {
786 bitset number_bits = BitsetType::NumberBits(bits); 775 bitset number_bits = AstBitsetType::NumberBits(bits);
787 776
788 if (number_bits == BitsetType::kNone) { 777 if (number_bits == AstBitsetType::kNone) {
789 return RangeType::Limits::Empty(); 778 return AstRangeType::Limits::Empty();
790 } 779 }
791 780
792 return RangeType::Limits(BitsetType::Min(number_bits), 781 return AstRangeType::Limits(AstBitsetType::Min(number_bits),
793 BitsetType::Max(number_bits)); 782 AstBitsetType::Max(number_bits));
794 } 783 }
795 784
796 RangeType::Limits Type::IntersectRangeAndBitset(Type* range, Type* bitset, 785 AstRangeType::Limits AstType::IntersectRangeAndBitset(AstType* range,
797 Zone* zone) { 786 AstType* bitset,
798 RangeType::Limits range_lims(range->AsRange()); 787 Zone* zone) {
799 RangeType::Limits bitset_lims = ToLimits(bitset->AsBitset(), zone); 788 AstRangeType::Limits range_lims(range->AsRange());
800 return RangeType::Limits::Intersect(range_lims, bitset_lims); 789 AstRangeType::Limits bitset_lims = ToLimits(bitset->AsBitset(), zone);
790 return AstRangeType::Limits::Intersect(range_lims, bitset_lims);
801 } 791 }
802 792
803 int Type::IntersectAux(Type* lhs, Type* rhs, UnionType* result, int size, 793 int AstType::IntersectAux(AstType* lhs, AstType* rhs, AstUnionType* result,
804 RangeType::Limits* lims, Zone* zone) { 794 int size, AstRangeType::Limits* lims, Zone* zone) {
805 if (lhs->IsUnion()) { 795 if (lhs->IsUnion()) {
806 for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) { 796 for (int i = 0, n = lhs->AsUnion()->Length(); i < n; ++i) {
807 size = 797 size =
808 IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, lims, zone); 798 IntersectAux(lhs->AsUnion()->Get(i), rhs, result, size, lims, zone);
809 } 799 }
810 return size; 800 return size;
811 } 801 }
812 if (rhs->IsUnion()) { 802 if (rhs->IsUnion()) {
813 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) { 803 for (int i = 0, n = rhs->AsUnion()->Length(); i < n; ++i) {
814 size = 804 size =
815 IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, lims, zone); 805 IntersectAux(lhs, rhs->AsUnion()->Get(i), result, size, lims, zone);
816 } 806 }
817 return size; 807 return size;
818 } 808 }
819 809
820 if (!BitsetType::SemanticIsInhabited(lhs->BitsetLub() & rhs->BitsetLub())) { 810 if (!AstBitsetType::SemanticIsInhabited(lhs->BitsetLub() &
811 rhs->BitsetLub())) {
821 return size; 812 return size;
822 } 813 }
823 814
824 if (lhs->IsRange()) { 815 if (lhs->IsRange()) {
825 if (rhs->IsBitset()) { 816 if (rhs->IsBitset()) {
826 RangeType::Limits lim = IntersectRangeAndBitset(lhs, rhs, zone); 817 AstRangeType::Limits lim = IntersectRangeAndBitset(lhs, rhs, zone);
827 818
828 if (!lim.IsEmpty()) { 819 if (!lim.IsEmpty()) {
829 *lims = RangeType::Limits::Union(lim, *lims); 820 *lims = AstRangeType::Limits::Union(lim, *lims);
830 } 821 }
831 return size; 822 return size;
832 } 823 }
833 if (rhs->IsClass()) { 824 if (rhs->IsClass()) {
834 *lims = 825 *lims = AstRangeType::Limits::Union(AstRangeType::Limits(lhs->AsRange()),
835 RangeType::Limits::Union(RangeType::Limits(lhs->AsRange()), *lims); 826 *lims);
836 } 827 }
837 if (rhs->IsConstant() && Contains(lhs->AsRange(), rhs->AsConstant())) { 828 if (rhs->IsConstant() && Contains(lhs->AsRange(), rhs->AsConstant())) {
838 return AddToUnion(rhs, result, size, zone); 829 return AddToUnion(rhs, result, size, zone);
839 } 830 }
840 if (rhs->IsRange()) { 831 if (rhs->IsRange()) {
841 RangeType::Limits lim = RangeType::Limits::Intersect( 832 AstRangeType::Limits lim =
842 RangeType::Limits(lhs->AsRange()), RangeType::Limits(rhs->AsRange())); 833 AstRangeType::Limits::Intersect(AstRangeType::Limits(lhs->AsRange()),
834 AstRangeType::Limits(rhs->AsRange()));
843 if (!lim.IsEmpty()) { 835 if (!lim.IsEmpty()) {
844 *lims = RangeType::Limits::Union(lim, *lims); 836 *lims = AstRangeType::Limits::Union(lim, *lims);
845 } 837 }
846 } 838 }
847 return size; 839 return size;
848 } 840 }
849 if (rhs->IsRange()) { 841 if (rhs->IsRange()) {
850 // This case is handled symmetrically above. 842 // This case is handled symmetrically above.
851 return IntersectAux(rhs, lhs, result, size, lims, zone); 843 return IntersectAux(rhs, lhs, result, size, lims, zone);
852 } 844 }
853 if (lhs->IsBitset() || rhs->IsBitset()) { 845 if (lhs->IsBitset() || rhs->IsBitset()) {
854 return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, zone); 846 return AddToUnion(lhs->IsBitset() ? rhs : lhs, result, size, zone);
855 } 847 }
856 if (lhs->IsClass() != rhs->IsClass()) { 848 if (lhs->IsClass() != rhs->IsClass()) {
857 return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, zone); 849 return AddToUnion(lhs->IsClass() ? rhs : lhs, result, size, zone);
858 } 850 }
859 if (lhs->SimplyEquals(rhs)) { 851 if (lhs->SimplyEquals(rhs)) {
860 return AddToUnion(lhs, result, size, zone); 852 return AddToUnion(lhs, result, size, zone);
861 } 853 }
862 return size; 854 return size;
863 } 855 }
864 856
865
866 // Make sure that we produce a well-formed range and bitset: 857 // Make sure that we produce a well-formed range and bitset:
867 // If the range is non-empty, the number bits in the bitset should be 858 // If the range is non-empty, the number bits in the bitset should be
868 // clear. Moreover, if we have a canonical range (such as Signed32), 859 // clear. Moreover, if we have a canonical range (such as Signed32),
869 // we want to produce a bitset rather than a range. 860 // we want to produce a bitset rather than a range.
870 Type* Type::NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone) { 861 AstType* AstType::NormalizeRangeAndBitset(AstType* range, bitset* bits,
862 Zone* zone) {
871 // Fast path: If the bitset does not mention numbers, we can just keep the 863 // Fast path: If the bitset does not mention numbers, we can just keep the
872 // range. 864 // range.
873 bitset number_bits = BitsetType::NumberBits(*bits); 865 bitset number_bits = AstBitsetType::NumberBits(*bits);
874 if (number_bits == 0) { 866 if (number_bits == 0) {
875 return range; 867 return range;
876 } 868 }
877 869
878 // If the range is semantically contained within the bitset, return None and 870 // If the range is semantically contained within the bitset, return None and
879 // leave the bitset untouched. 871 // leave the bitset untouched.
880 bitset range_lub = SEMANTIC(range->BitsetLub()); 872 bitset range_lub = AST_SEMANTIC(range->BitsetLub());
881 if (BitsetType::Is(range_lub, *bits)) { 873 if (AstBitsetType::Is(range_lub, *bits)) {
882 return None(); 874 return None();
883 } 875 }
884 876
885 // Slow path: reconcile the bitset range and the range. 877 // Slow path: reconcile the bitset range and the range.
886 double bitset_min = BitsetType::Min(number_bits); 878 double bitset_min = AstBitsetType::Min(number_bits);
887 double bitset_max = BitsetType::Max(number_bits); 879 double bitset_max = AstBitsetType::Max(number_bits);
888 880
889 double range_min = range->Min(); 881 double range_min = range->Min();
890 double range_max = range->Max(); 882 double range_max = range->Max();
891 883
892 // Remove the number bits from the bitset, they would just confuse us now. 884 // Remove the number bits from the bitset, they would just confuse us now.
893 // NOTE: bits contains OtherNumber iff bits contains PlainNumber, in which 885 // NOTE: bits contains OtherNumber iff bits contains PlainNumber, in which
894 // case we already returned after the subtype check above. 886 // case we already returned after the subtype check above.
895 *bits &= ~number_bits; 887 *bits &= ~number_bits;
896 888
897 if (range_min <= bitset_min && range_max >= bitset_max) { 889 if (range_min <= bitset_min && range_max >= bitset_max) {
898 // Bitset is contained within the range, just return the range. 890 // Bitset is contained within the range, just return the range.
899 return range; 891 return range;
900 } 892 }
901 893
902 if (bitset_min < range_min) { 894 if (bitset_min < range_min) {
903 range_min = bitset_min; 895 range_min = bitset_min;
904 } 896 }
905 if (bitset_max > range_max) { 897 if (bitset_max > range_max) {
906 range_max = bitset_max; 898 range_max = bitset_max;
907 } 899 }
908 return RangeType::New(range_min, range_max, BitsetType::kNone, zone); 900 return AstRangeType::New(range_min, range_max, AstBitsetType::kNone, zone);
909 } 901 }
910 902
911 Type* Type::Union(Type* type1, Type* type2, Zone* zone) { 903 AstType* AstType::Union(AstType* type1, AstType* type2, Zone* zone) {
912 // Fast case: bit sets. 904 // Fast case: bit sets.
913 if (type1->IsBitset() && type2->IsBitset()) { 905 if (type1->IsBitset() && type2->IsBitset()) {
914 return BitsetType::New(type1->AsBitset() | type2->AsBitset()); 906 return AstBitsetType::New(type1->AsBitset() | type2->AsBitset());
915 } 907 }
916 908
917 // Fast case: top or bottom types. 909 // Fast case: top or bottom types.
918 if (type1->IsAny() || type2->IsNone()) return type1; 910 if (type1->IsAny() || type2->IsNone()) return type1;
919 if (type2->IsAny() || type1->IsNone()) return type2; 911 if (type2->IsAny() || type1->IsNone()) return type2;
920 912
921 // Semi-fast case. 913 // Semi-fast case.
922 if (type1->Is(type2)) return type2; 914 if (type1->Is(type2)) return type2;
923 if (type2->Is(type1)) return type1; 915 if (type2->Is(type1)) return type1;
924 916
925 // Figure out the representation of the result. 917 // Figure out the representation of the result.
926 // The rest of the method should not change this representation and 918 // The rest of the method should not change this representation and
927 // it should not make any decisions based on representations (i.e., 919 // it should not make any decisions based on representations (i.e.,
928 // it should only use the semantic part of types). 920 // it should only use the semantic part of types).
929 const bitset representation = 921 const bitset representation =
930 type1->Representation() | type2->Representation(); 922 type1->Representation() | type2->Representation();
931 923
932 // Slow case: create union. 924 // Slow case: create union.
933 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1; 925 int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
934 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1; 926 int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
935 if (!AddIsSafe(size1, size2)) return Any(); 927 if (!AddIsSafe(size1, size2)) return Any();
936 int size = size1 + size2; 928 int size = size1 + size2;
937 if (!AddIsSafe(size, 2)) return Any(); 929 if (!AddIsSafe(size, 2)) return Any();
938 size += 2; 930 size += 2;
939 Type* result_type = UnionType::New(size, zone); 931 AstType* result_type = AstUnionType::New(size, zone);
940 UnionType* result = result_type->AsUnion(); 932 AstUnionType* result = result_type->AsUnion();
941 size = 0; 933 size = 0;
942 934
943 // Compute the new bitset. 935 // Compute the new bitset.
944 bitset new_bitset = SEMANTIC(type1->BitsetGlb() | type2->BitsetGlb()); 936 bitset new_bitset = AST_SEMANTIC(type1->BitsetGlb() | type2->BitsetGlb());
945 937
946 // Deal with ranges. 938 // Deal with ranges.
947 Type* range = None(); 939 AstType* range = None();
948 Type* range1 = type1->GetRange(); 940 AstType* range1 = type1->GetRange();
949 Type* range2 = type2->GetRange(); 941 AstType* range2 = type2->GetRange();
950 if (range1 != NULL && range2 != NULL) { 942 if (range1 != NULL && range2 != NULL) {
951 RangeType::Limits lims = 943 AstRangeType::Limits lims =
952 RangeType::Limits::Union(RangeType::Limits(range1->AsRange()), 944 AstRangeType::Limits::Union(AstRangeType::Limits(range1->AsRange()),
953 RangeType::Limits(range2->AsRange())); 945 AstRangeType::Limits(range2->AsRange()));
954 Type* union_range = RangeType::New(lims, representation, zone); 946 AstType* union_range = AstRangeType::New(lims, representation, zone);
955 range = NormalizeRangeAndBitset(union_range, &new_bitset, zone); 947 range = NormalizeRangeAndBitset(union_range, &new_bitset, zone);
956 } else if (range1 != NULL) { 948 } else if (range1 != NULL) {
957 range = NormalizeRangeAndBitset(range1, &new_bitset, zone); 949 range = NormalizeRangeAndBitset(range1, &new_bitset, zone);
958 } else if (range2 != NULL) { 950 } else if (range2 != NULL) {
959 range = NormalizeRangeAndBitset(range2, &new_bitset, zone); 951 range = NormalizeRangeAndBitset(range2, &new_bitset, zone);
960 } 952 }
961 new_bitset = SEMANTIC(new_bitset) | representation; 953 new_bitset = AST_SEMANTIC(new_bitset) | representation;
962 Type* bits = BitsetType::New(new_bitset); 954 AstType* bits = AstBitsetType::New(new_bitset);
963 result->Set(size++, bits); 955 result->Set(size++, bits);
964 if (!range->IsNone()) result->Set(size++, range); 956 if (!range->IsNone()) result->Set(size++, range);
965 957
966 size = AddToUnion(type1, result, size, zone); 958 size = AddToUnion(type1, result, size, zone);
967 size = AddToUnion(type2, result, size, zone); 959 size = AddToUnion(type2, result, size, zone);
968 return NormalizeUnion(result_type, size, zone); 960 return NormalizeUnion(result_type, size, zone);
969 } 961 }
970 962
971
972 // Add [type] to [result] unless [type] is bitset, range, or already subsumed. 963 // Add [type] to [result] unless [type] is bitset, range, or already subsumed.
973 // Return new size of [result]. 964 // Return new size of [result].
974 int Type::AddToUnion(Type* type, UnionType* result, int size, Zone* zone) { 965 int AstType::AddToUnion(AstType* type, AstUnionType* result, int size,
966 Zone* zone) {
975 if (type->IsBitset() || type->IsRange()) return size; 967 if (type->IsBitset() || type->IsRange()) return size;
976 if (type->IsUnion()) { 968 if (type->IsUnion()) {
977 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { 969 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) {
978 size = AddToUnion(type->AsUnion()->Get(i), result, size, zone); 970 size = AddToUnion(type->AsUnion()->Get(i), result, size, zone);
979 } 971 }
980 return size; 972 return size;
981 } 973 }
982 for (int i = 0; i < size; ++i) { 974 for (int i = 0; i < size; ++i) {
983 if (type->SemanticIs(result->Get(i))) return size; 975 if (type->SemanticIs(result->Get(i))) return size;
984 } 976 }
985 result->Set(size++, type); 977 result->Set(size++, type);
986 return size; 978 return size;
987 } 979 }
988 980
989 Type* Type::NormalizeUnion(Type* union_type, int size, Zone* zone) { 981 AstType* AstType::NormalizeUnion(AstType* union_type, int size, Zone* zone) {
990 UnionType* unioned = union_type->AsUnion(); 982 AstUnionType* unioned = union_type->AsUnion();
991 DCHECK(size >= 1); 983 DCHECK(size >= 1);
992 DCHECK(unioned->Get(0)->IsBitset()); 984 DCHECK(unioned->Get(0)->IsBitset());
993 // If the union has just one element, return it. 985 // If the union has just one element, return it.
994 if (size == 1) { 986 if (size == 1) {
995 return unioned->Get(0); 987 return unioned->Get(0);
996 } 988 }
997 bitset bits = unioned->Get(0)->AsBitset(); 989 bitset bits = unioned->Get(0)->AsBitset();
998 // If the union only consists of a range, we can get rid of the union. 990 // If the union only consists of a range, we can get rid of the union.
999 if (size == 2 && SEMANTIC(bits) == BitsetType::kNone) { 991 if (size == 2 && AST_SEMANTIC(bits) == AstBitsetType::kNone) {
1000 bitset representation = REPRESENTATION(bits); 992 bitset representation = AST_REPRESENTATION(bits);
1001 if (representation == unioned->Get(1)->Representation()) { 993 if (representation == unioned->Get(1)->Representation()) {
1002 return unioned->Get(1); 994 return unioned->Get(1);
1003 } 995 }
1004 if (unioned->Get(1)->IsRange()) { 996 if (unioned->Get(1)->IsRange()) {
1005 return RangeType::New(unioned->Get(1)->AsRange()->Min(), 997 return AstRangeType::New(unioned->Get(1)->AsRange()->Min(),
1006 unioned->Get(1)->AsRange()->Max(), 998 unioned->Get(1)->AsRange()->Max(),
1007 unioned->Get(0)->AsBitset(), zone); 999 unioned->Get(0)->AsBitset(), zone);
1008 } 1000 }
1009 } 1001 }
1010 unioned->Shrink(size); 1002 unioned->Shrink(size);
1011 SLOW_DCHECK(unioned->Wellformed()); 1003 SLOW_DCHECK(unioned->Wellformed());
1012 return union_type; 1004 return union_type;
1013 } 1005 }
1014 1006
1015
1016 // ----------------------------------------------------------------------------- 1007 // -----------------------------------------------------------------------------
1017 // Component extraction 1008 // Component extraction
1018 1009
1019 // static 1010 // static
1020 Type* Type::Representation(Type* t, Zone* zone) { 1011 AstType* AstType::Representation(AstType* t, Zone* zone) {
1021 return BitsetType::New(t->Representation()); 1012 return AstBitsetType::New(t->Representation());
1022 } 1013 }
1023 1014
1024
1025 // static 1015 // static
1026 Type* Type::Semantic(Type* t, Zone* zone) { 1016 AstType* AstType::Semantic(AstType* t, Zone* zone) {
1027 return Intersect(t, BitsetType::New(BitsetType::kSemantic), zone); 1017 return Intersect(t, AstBitsetType::New(AstBitsetType::kSemantic), zone);
1028 } 1018 }
1029 1019
1030
1031 // ----------------------------------------------------------------------------- 1020 // -----------------------------------------------------------------------------
1032 // Iteration. 1021 // Iteration.
1033 1022
1034 int Type::NumClasses() { 1023 int AstType::NumClasses() {
1035 DisallowHeapAllocation no_allocation; 1024 DisallowHeapAllocation no_allocation;
1036 if (this->IsClass()) { 1025 if (this->IsClass()) {
1037 return 1; 1026 return 1;
1038 } else if (this->IsUnion()) { 1027 } else if (this->IsUnion()) {
1039 int result = 0; 1028 int result = 0;
1040 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 1029 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
1041 if (this->AsUnion()->Get(i)->IsClass()) ++result; 1030 if (this->AsUnion()->Get(i)->IsClass()) ++result;
1042 } 1031 }
1043 return result; 1032 return result;
1044 } else { 1033 } else {
1045 return 0; 1034 return 0;
1046 } 1035 }
1047 } 1036 }
1048 1037
1049 int Type::NumConstants() { 1038 int AstType::NumConstants() {
1050 DisallowHeapAllocation no_allocation; 1039 DisallowHeapAllocation no_allocation;
1051 if (this->IsConstant()) { 1040 if (this->IsConstant()) {
1052 return 1; 1041 return 1;
1053 } else if (this->IsUnion()) { 1042 } else if (this->IsUnion()) {
1054 int result = 0; 1043 int result = 0;
1055 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 1044 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
1056 if (this->AsUnion()->Get(i)->IsConstant()) ++result; 1045 if (this->AsUnion()->Get(i)->IsConstant()) ++result;
1057 } 1046 }
1058 return result; 1047 return result;
1059 } else { 1048 } else {
1060 return 0; 1049 return 0;
1061 } 1050 }
1062 } 1051 }
1063 1052
1064 template <class T> 1053 template <class T>
1065 Type* Type::Iterator<T>::get_type() { 1054 AstType* AstType::Iterator<T>::get_type() {
1066 DCHECK(!Done()); 1055 DCHECK(!Done());
1067 return type_->IsUnion() ? type_->AsUnion()->Get(index_) : type_; 1056 return type_->IsUnion() ? type_->AsUnion()->Get(index_) : type_;
1068 } 1057 }
1069 1058
1070
1071 // C++ cannot specialise nested templates, so we have to go through this 1059 // C++ cannot specialise nested templates, so we have to go through this
1072 // contortion with an auxiliary template to simulate it. 1060 // contortion with an auxiliary template to simulate it.
1073 template <class T> 1061 template <class T>
1074 struct TypeImplIteratorAux { 1062 struct TypeImplIteratorAux {
1075 static bool matches(Type* type); 1063 static bool matches(AstType* type);
1076 static i::Handle<T> current(Type* type); 1064 static i::Handle<T> current(AstType* type);
1077 }; 1065 };
1078 1066
1079 template <> 1067 template <>
1080 struct TypeImplIteratorAux<i::Map> { 1068 struct TypeImplIteratorAux<i::Map> {
1081 static bool matches(Type* type) { return type->IsClass(); } 1069 static bool matches(AstType* type) { return type->IsClass(); }
1082 static i::Handle<i::Map> current(Type* type) { 1070 static i::Handle<i::Map> current(AstType* type) {
1083 return type->AsClass()->Map(); 1071 return type->AsClass()->Map();
1084 } 1072 }
1085 }; 1073 };
1086 1074
1087 template <> 1075 template <>
1088 struct TypeImplIteratorAux<i::Object> { 1076 struct TypeImplIteratorAux<i::Object> {
1089 static bool matches(Type* type) { return type->IsConstant(); } 1077 static bool matches(AstType* type) { return type->IsConstant(); }
1090 static i::Handle<i::Object> current(Type* type) { 1078 static i::Handle<i::Object> current(AstType* type) {
1091 return type->AsConstant()->Value(); 1079 return type->AsConstant()->Value();
1092 } 1080 }
1093 }; 1081 };
1094 1082
1095 template <class T> 1083 template <class T>
1096 bool Type::Iterator<T>::matches(Type* type) { 1084 bool AstType::Iterator<T>::matches(AstType* type) {
1097 return TypeImplIteratorAux<T>::matches(type); 1085 return TypeImplIteratorAux<T>::matches(type);
1098 } 1086 }
1099 1087
1100 template <class T> 1088 template <class T>
1101 i::Handle<T> Type::Iterator<T>::Current() { 1089 i::Handle<T> AstType::Iterator<T>::Current() {
1102 return TypeImplIteratorAux<T>::current(get_type()); 1090 return TypeImplIteratorAux<T>::current(get_type());
1103 } 1091 }
1104 1092
1105 template <class T> 1093 template <class T>
1106 void Type::Iterator<T>::Advance() { 1094 void AstType::Iterator<T>::Advance() {
1107 DisallowHeapAllocation no_allocation; 1095 DisallowHeapAllocation no_allocation;
1108 ++index_; 1096 ++index_;
1109 if (type_->IsUnion()) { 1097 if (type_->IsUnion()) {
1110 for (int n = type_->AsUnion()->Length(); index_ < n; ++index_) { 1098 for (int n = type_->AsUnion()->Length(); index_ < n; ++index_) {
1111 if (matches(type_->AsUnion()->Get(index_))) return; 1099 if (matches(type_->AsUnion()->Get(index_))) return;
1112 } 1100 }
1113 } else if (index_ == 0 && matches(type_)) { 1101 } else if (index_ == 0 && matches(type_)) {
1114 return; 1102 return;
1115 } 1103 }
1116 index_ = -1; 1104 index_ = -1;
1117 } 1105 }
1118 1106
1119
1120 // ----------------------------------------------------------------------------- 1107 // -----------------------------------------------------------------------------
1121 // Printing. 1108 // Printing.
1122 1109
1123 const char* BitsetType::Name(bitset bits) { 1110 const char* AstBitsetType::Name(bitset bits) {
1124 switch (bits) { 1111 switch (bits) {
1125 case REPRESENTATION(kAny): return "Any"; 1112 case AST_REPRESENTATION(kAny):
1126 #define RETURN_NAMED_REPRESENTATION_TYPE(type, value) \ 1113 return "Any";
1127 case REPRESENTATION(k##type): return #type; 1114 #define RETURN_NAMED_REPRESENTATION_TYPE(type, value) \
1128 REPRESENTATION_BITSET_TYPE_LIST(RETURN_NAMED_REPRESENTATION_TYPE) 1115 case AST_REPRESENTATION(k##type): \
1129 #undef RETURN_NAMED_REPRESENTATION_TYPE 1116 return #type;
1117 AST_REPRESENTATION_BITSET_TYPE_LIST(RETURN_NAMED_REPRESENTATION_TYPE)
1118 #undef RETURN_NAMED_REPRESENTATION_TYPE
1130 1119
1131 #define RETURN_NAMED_SEMANTIC_TYPE(type, value) \ 1120 #define RETURN_NAMED_SEMANTIC_TYPE(type, value) \
1132 case SEMANTIC(k##type): return #type; 1121 case AST_SEMANTIC(k##type): \
1133 SEMANTIC_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE) 1122 return #type;
1134 INTERNAL_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE) 1123 AST_SEMANTIC_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE)
1135 #undef RETURN_NAMED_SEMANTIC_TYPE 1124 AST_INTERNAL_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE)
1125 #undef RETURN_NAMED_SEMANTIC_TYPE
1136 1126
1137 default: 1127 default:
1138 return NULL; 1128 return NULL;
1139 } 1129 }
1140 } 1130 }
1141 1131
1142 void BitsetType::Print(std::ostream& os, // NOLINT 1132 void AstBitsetType::Print(std::ostream& os, // NOLINT
1143 bitset bits) { 1133 bitset bits) {
1144 DisallowHeapAllocation no_allocation; 1134 DisallowHeapAllocation no_allocation;
1145 const char* name = Name(bits); 1135 const char* name = Name(bits);
1146 if (name != NULL) { 1136 if (name != NULL) {
1147 os << name; 1137 os << name;
1148 return; 1138 return;
1149 } 1139 }
1150 1140
1151 // clang-format off 1141 // clang-format off
1152 static const bitset named_bitsets[] = { 1142 static const bitset named_bitsets[] = {
1153 #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), 1143 #define BITSET_CONSTANT(type, value) AST_REPRESENTATION(k##type),
1154 REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) 1144 AST_REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT)
1155 #undef BITSET_CONSTANT 1145 #undef BITSET_CONSTANT
1156 1146
1157 #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), 1147 #define BITSET_CONSTANT(type, value) AST_SEMANTIC(k##type),
1158 INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT) 1148 AST_INTERNAL_BITSET_TYPE_LIST(BITSET_CONSTANT)
1159 SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) 1149 AST_SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT)
1160 #undef BITSET_CONSTANT 1150 #undef BITSET_CONSTANT
1161 }; 1151 };
1162 // clang-format on 1152 // clang-format on
1163 1153
1164 bool is_first = true; 1154 bool is_first = true;
1165 os << "("; 1155 os << "(";
1166 for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) { 1156 for (int i(arraysize(named_bitsets) - 1); bits != 0 && i >= 0; --i) {
1167 bitset subset = named_bitsets[i]; 1157 bitset subset = named_bitsets[i];
1168 if ((bits & subset) == subset) { 1158 if ((bits & subset) == subset) {
1169 if (!is_first) os << " | "; 1159 if (!is_first) os << " | ";
1170 is_first = false; 1160 is_first = false;
1171 os << Name(subset); 1161 os << Name(subset);
1172 bits -= subset; 1162 bits -= subset;
1173 } 1163 }
1174 } 1164 }
1175 DCHECK(bits == 0); 1165 DCHECK(bits == 0);
1176 os << ")"; 1166 os << ")";
1177 } 1167 }
1178 1168
1179 void Type::PrintTo(std::ostream& os, PrintDimension dim) { 1169 void AstType::PrintTo(std::ostream& os, PrintDimension dim) {
1180 DisallowHeapAllocation no_allocation; 1170 DisallowHeapAllocation no_allocation;
1181 if (dim != REPRESENTATION_DIM) { 1171 if (dim != REPRESENTATION_DIM) {
1182 if (this->IsBitset()) { 1172 if (this->IsBitset()) {
1183 BitsetType::Print(os, SEMANTIC(this->AsBitset())); 1173 AstBitsetType::Print(os, AST_SEMANTIC(this->AsBitset()));
1184 } else if (this->IsClass()) { 1174 } else if (this->IsClass()) {
1185 os << "Class(" << static_cast<void*>(*this->AsClass()->Map()) << " < "; 1175 os << "Class(" << static_cast<void*>(*this->AsClass()->Map()) << " < ";
1186 BitsetType::New(BitsetType::Lub(this))->PrintTo(os, dim); 1176 AstBitsetType::New(AstBitsetType::Lub(this))->PrintTo(os, dim);
1187 os << ")"; 1177 os << ")";
1188 } else if (this->IsConstant()) { 1178 } else if (this->IsConstant()) {
1189 os << "Constant(" << Brief(*this->AsConstant()->Value()) << ")"; 1179 os << "Constant(" << Brief(*this->AsConstant()->Value()) << ")";
1190 } else if (this->IsRange()) { 1180 } else if (this->IsRange()) {
1191 std::ostream::fmtflags saved_flags = os.setf(std::ios::fixed); 1181 std::ostream::fmtflags saved_flags = os.setf(std::ios::fixed);
1192 std::streamsize saved_precision = os.precision(0); 1182 std::streamsize saved_precision = os.precision(0);
1193 os << "Range(" << this->AsRange()->Min() << ", " << this->AsRange()->Max() 1183 os << "Range(" << this->AsRange()->Min() << ", " << this->AsRange()->Max()
1194 << ")"; 1184 << ")";
1195 os.flags(saved_flags); 1185 os.flags(saved_flags);
1196 os.precision(saved_precision); 1186 os.precision(saved_precision);
1197 } else if (this->IsContext()) { 1187 } else if (this->IsContext()) {
1198 os << "Context("; 1188 os << "Context(";
1199 this->AsContext()->Outer()->PrintTo(os, dim); 1189 this->AsContext()->Outer()->PrintTo(os, dim);
1200 os << ")"; 1190 os << ")";
1201 } else if (this->IsUnion()) { 1191 } else if (this->IsUnion()) {
1202 os << "("; 1192 os << "(";
1203 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { 1193 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) {
1204 Type* type_i = this->AsUnion()->Get(i); 1194 AstType* type_i = this->AsUnion()->Get(i);
1205 if (i > 0) os << " | "; 1195 if (i > 0) os << " | ";
1206 type_i->PrintTo(os, dim); 1196 type_i->PrintTo(os, dim);
1207 } 1197 }
1208 os << ")"; 1198 os << ")";
1209 } else if (this->IsArray()) { 1199 } else if (this->IsArray()) {
1210 os << "Array("; 1200 os << "Array(";
1211 AsArray()->Element()->PrintTo(os, dim); 1201 AsArray()->Element()->PrintTo(os, dim);
1212 os << ")"; 1202 os << ")";
1213 } else if (this->IsFunction()) { 1203 } else if (this->IsFunction()) {
1214 if (!this->AsFunction()->Receiver()->IsAny()) { 1204 if (!this->AsFunction()->Receiver()->IsAny()) {
1215 this->AsFunction()->Receiver()->PrintTo(os, dim); 1205 this->AsFunction()->Receiver()->PrintTo(os, dim);
1216 os << "."; 1206 os << ".";
1217 } 1207 }
1218 os << "("; 1208 os << "(";
1219 for (int i = 0; i < this->AsFunction()->Arity(); ++i) { 1209 for (int i = 0; i < this->AsFunction()->Arity(); ++i) {
1220 if (i > 0) os << ", "; 1210 if (i > 0) os << ", ";
1221 this->AsFunction()->Parameter(i)->PrintTo(os, dim); 1211 this->AsFunction()->Parameter(i)->PrintTo(os, dim);
1222 } 1212 }
1223 os << ")->"; 1213 os << ")->";
1224 this->AsFunction()->Result()->PrintTo(os, dim); 1214 this->AsFunction()->Result()->PrintTo(os, dim);
1225 } else if (this->IsTuple()) { 1215 } else if (this->IsTuple()) {
1226 os << "<"; 1216 os << "<";
1227 for (int i = 0, n = this->AsTuple()->Arity(); i < n; ++i) { 1217 for (int i = 0, n = this->AsTuple()->Arity(); i < n; ++i) {
1228 Type* type_i = this->AsTuple()->Element(i); 1218 AstType* type_i = this->AsTuple()->Element(i);
1229 if (i > 0) os << ", "; 1219 if (i > 0) os << ", ";
1230 type_i->PrintTo(os, dim); 1220 type_i->PrintTo(os, dim);
1231 } 1221 }
1232 os << ">"; 1222 os << ">";
1233 } else { 1223 } else {
1234 UNREACHABLE(); 1224 UNREACHABLE();
1235 } 1225 }
1236 } 1226 }
1237 if (dim == BOTH_DIMS) os << "/"; 1227 if (dim == BOTH_DIMS) os << "/";
1238 if (dim != SEMANTIC_DIM) { 1228 if (dim != SEMANTIC_DIM) {
1239 BitsetType::Print(os, REPRESENTATION(this->BitsetLub())); 1229 AstBitsetType::Print(os, AST_REPRESENTATION(this->BitsetLub()));
1240 } 1230 }
1241 } 1231 }
1242 1232
1243
1244 #ifdef DEBUG 1233 #ifdef DEBUG
1245 void Type::Print() { 1234 void AstType::Print() {
1246 OFStream os(stdout); 1235 OFStream os(stdout);
1247 PrintTo(os); 1236 PrintTo(os);
1248 os << std::endl; 1237 os << std::endl;
1249 } 1238 }
1250 void BitsetType::Print(bitset bits) { 1239 void AstBitsetType::Print(bitset bits) {
1251 OFStream os(stdout); 1240 OFStream os(stdout);
1252 Print(os, bits); 1241 Print(os, bits);
1253 os << std::endl; 1242 os << std::endl;
1254 } 1243 }
1255 #endif 1244 #endif
1256 1245
1257 BitsetType::bitset BitsetType::SignedSmall() { 1246 AstBitsetType::bitset AstBitsetType::SignedSmall() {
1258 return i::SmiValuesAre31Bits() ? kSigned31 : kSigned32; 1247 return i::SmiValuesAre31Bits() ? kSigned31 : kSigned32;
1259 } 1248 }
1260 1249
1261 BitsetType::bitset BitsetType::UnsignedSmall() { 1250 AstBitsetType::bitset AstBitsetType::UnsignedSmall() {
1262 return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31; 1251 return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31;
1263 } 1252 }
1264 1253
1265 #define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \ 1254 #define CONSTRUCT_SIMD_TYPE(NAME, Name, name, lane_count, lane_type) \
1266 Type* Type::Name(Isolate* isolate, Zone* zone) { \ 1255 AstType* AstType::Name(Isolate* isolate, Zone* zone) { \
1267 return Class(i::handle(isolate->heap()->name##_map()), zone); \ 1256 return Class(i::handle(isolate->heap()->name##_map()), zone); \
1268 } 1257 }
1269 SIMD128_TYPES(CONSTRUCT_SIMD_TYPE) 1258 SIMD128_TYPES(CONSTRUCT_SIMD_TYPE)
1270 #undef CONSTRUCT_SIMD_TYPE 1259 #undef CONSTRUCT_SIMD_TYPE
1271 1260
1272 // ----------------------------------------------------------------------------- 1261 // -----------------------------------------------------------------------------
1273 // Instantiations. 1262 // Instantiations.
1274 1263
1275 template class Type::Iterator<i::Map>; 1264 template class AstType::Iterator<i::Map>;
1276 template class Type::Iterator<i::Object>; 1265 template class AstType::Iterator<i::Object>;
1277 1266
1278 } // namespace internal 1267 } // namespace internal
1279 } // namespace v8 1268 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/ast-types.h ('k') | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698