Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / v8 / src / types.cc
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "types.h"
29 #include "string-stream.h"
30
31 namespace v8 {
32 namespace internal {
33
34 template<class Config>
35 int TypeImpl<Config>::NumClasses() {
36   if (this->IsClass()) {
37     return 1;
38   } else if (this->IsUnion()) {
39     UnionedHandle unioned = this->AsUnion();
40     int result = 0;
41     for (int i = 0; i < Config::union_length(unioned); ++i) {
42       if (Config::union_get(unioned, i)->IsClass()) ++result;
43     }
44     return result;
45   } else {
46     return 0;
47   }
48 }
49
50
51 template<class Config>
52 int TypeImpl<Config>::NumConstants() {
53   if (this->IsConstant()) {
54     return 1;
55   } else if (this->IsUnion()) {
56     UnionedHandle unioned = this->AsUnion();
57     int result = 0;
58     for (int i = 0; i < Config::union_length(unioned); ++i) {
59       if (Config::union_get(unioned, i)->IsConstant()) ++result;
60     }
61     return result;
62   } else {
63     return 0;
64   }
65 }
66
67
68 template<class Config> template<class T>
69 typename TypeImpl<Config>::TypeHandle
70 TypeImpl<Config>::Iterator<T>::get_type() {
71   ASSERT(!Done());
72   return type_->IsUnion() ? Config::union_get(type_->AsUnion(), index_) : type_;
73 }
74
75
76 // C++ cannot specialise nested templates, so we have to go through this
77 // contortion with an auxiliary template to simulate it.
78 template<class Config, class T>
79 struct TypeImplIteratorAux {
80   static bool matches(typename TypeImpl<Config>::TypeHandle type);
81   static i::Handle<T> current(typename TypeImpl<Config>::TypeHandle type);
82 };
83
84 template<class Config>
85 struct TypeImplIteratorAux<Config, i::Map> {
86   static bool matches(typename TypeImpl<Config>::TypeHandle type) {
87     return type->IsClass();
88   }
89   static i::Handle<i::Map> current(typename TypeImpl<Config>::TypeHandle type) {
90     return type->AsClass();
91   }
92 };
93
94 template<class Config>
95 struct TypeImplIteratorAux<Config, i::Object> {
96   static bool matches(typename TypeImpl<Config>::TypeHandle type) {
97     return type->IsConstant();
98   }
99   static i::Handle<i::Object> current(
100       typename TypeImpl<Config>::TypeHandle type) {
101     return type->AsConstant();
102   }
103 };
104
105 template<class Config> template<class T>
106 bool TypeImpl<Config>::Iterator<T>::matches(TypeHandle type) {
107   return TypeImplIteratorAux<Config, T>::matches(type);
108 }
109
110 template<class Config> template<class T>
111 i::Handle<T> TypeImpl<Config>::Iterator<T>::Current() {
112   return TypeImplIteratorAux<Config, T>::current(get_type());
113 }
114
115
116 template<class Config> template<class T>
117 void TypeImpl<Config>::Iterator<T>::Advance() {
118   ++index_;
119   if (type_->IsUnion()) {
120     UnionedHandle unioned = type_->AsUnion();
121     for (; index_ < Config::union_length(unioned); ++index_) {
122       if (matches(Config::union_get(unioned, index_))) return;
123     }
124   } else if (index_ == 0 && matches(type_)) {
125     return;
126   }
127   index_ = -1;
128 }
129
130
131 // Get the smallest bitset subsuming this type.
132 template<class Config>
133 int TypeImpl<Config>::LubBitset() {
134   if (this->IsBitset()) {
135     return this->AsBitset();
136   } else if (this->IsUnion()) {
137     UnionedHandle unioned = this->AsUnion();
138     int bitset = kNone;
139     for (int i = 0; i < Config::union_length(unioned); ++i) {
140       bitset |= Config::union_get(unioned, i)->LubBitset();
141     }
142     return bitset;
143   } else if (this->IsClass()) {
144     int bitset = Config::lub_bitset(this);
145     return bitset ? bitset : LubBitset(*this->AsClass());
146   } else {
147     int bitset = Config::lub_bitset(this);
148     return bitset ? bitset : LubBitset(*this->AsConstant());
149   }
150 }
151
152
153 template<class Config>
154 int TypeImpl<Config>::LubBitset(i::Object* value) {
155   if (value->IsSmi()) return kSignedSmall & kTaggedInt;
156   i::Map* map = i::HeapObject::cast(value)->map();
157   if (map->instance_type() == HEAP_NUMBER_TYPE) {
158     int32_t i;
159     uint32_t u;
160     return kTaggedPtr & (
161         value->ToInt32(&i) ? (Smi::IsValid(i) ? kSignedSmall : kOtherSigned32) :
162         value->ToUint32(&u) ? kUnsigned32 : kFloat);
163   }
164   if (map->instance_type() == ODDBALL_TYPE) {
165     if (value->IsUndefined()) return kUndefined;
166     if (value->IsNull()) return kNull;
167     if (value->IsBoolean()) return kBoolean;
168     if (value->IsTheHole()) return kAny;  // TODO(rossberg): kNone?
169     if (value->IsUninitialized()) return kNone;
170     UNREACHABLE();
171   }
172   return LubBitset(map);
173 }
174
175
176 template<class Config>
177 int TypeImpl<Config>::LubBitset(i::Map* map) {
178   switch (map->instance_type()) {
179     case STRING_TYPE:
180     case ASCII_STRING_TYPE:
181     case CONS_STRING_TYPE:
182     case CONS_ASCII_STRING_TYPE:
183     case SLICED_STRING_TYPE:
184     case SLICED_ASCII_STRING_TYPE:
185     case EXTERNAL_STRING_TYPE:
186     case EXTERNAL_ASCII_STRING_TYPE:
187     case EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
188     case SHORT_EXTERNAL_STRING_TYPE:
189     case SHORT_EXTERNAL_ASCII_STRING_TYPE:
190     case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
191     case INTERNALIZED_STRING_TYPE:
192     case ASCII_INTERNALIZED_STRING_TYPE:
193     case CONS_INTERNALIZED_STRING_TYPE:
194     case CONS_ASCII_INTERNALIZED_STRING_TYPE:
195     case EXTERNAL_INTERNALIZED_STRING_TYPE:
196     case EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE:
197     case EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
198     case SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE:
199     case SHORT_EXTERNAL_ASCII_INTERNALIZED_STRING_TYPE:
200     case SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE:
201       return kString;
202     case SYMBOL_TYPE:
203       return kSymbol;
204     case ODDBALL_TYPE:
205       return kOddball;
206     case HEAP_NUMBER_TYPE:
207       return kFloat & kTaggedPtr;
208     case FLOAT32x4_TYPE:
209       return kFloat32x4 & kTaggedPtr;
210     case INT32x4_TYPE:
211       return kInt32x4 & kTaggedPtr;
212     case JS_VALUE_TYPE:
213     case JS_DATE_TYPE:
214     case JS_OBJECT_TYPE:
215     case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
216     case JS_GENERATOR_OBJECT_TYPE:
217     case JS_MODULE_TYPE:
218     case JS_GLOBAL_OBJECT_TYPE:
219     case JS_BUILTINS_OBJECT_TYPE:
220     case JS_GLOBAL_PROXY_TYPE:
221     case JS_ARRAY_BUFFER_TYPE:
222     case JS_TYPED_ARRAY_TYPE:
223     case JS_DATA_VIEW_TYPE:
224     case JS_SET_TYPE:
225     case JS_MAP_TYPE:
226     case JS_WEAK_MAP_TYPE:
227     case JS_WEAK_SET_TYPE:
228       if (map->is_undetectable()) return kUndetectable;
229       return kOtherObject;
230     case JS_ARRAY_TYPE:
231       return kArray;
232     case JS_FUNCTION_TYPE:
233       return kFunction;
234     case JS_REGEXP_TYPE:
235       return kRegExp;
236     case JS_PROXY_TYPE:
237     case JS_FUNCTION_PROXY_TYPE:
238       return kProxy;
239     case MAP_TYPE:
240       // When compiling stub templates, the meta map is used as a place holder
241       // for the actual map with which the template is later instantiated.
242       // We treat it as a kind of type variable whose upper bound is Any.
243       // TODO(rossberg): for caching of CompareNilIC stubs to work correctly,
244       // we must exclude Undetectable here. This makes no sense, really,
245       // because it means that the template isn't actually parametric.
246       // Also, it doesn't apply elsewhere. 8-(
247       // We ought to find a cleaner solution for compiling stubs parameterised
248       // over type or class variables, esp ones with bounds...
249       return kDetectable;
250     case DECLARED_ACCESSOR_INFO_TYPE:
251     case EXECUTABLE_ACCESSOR_INFO_TYPE:
252     case ACCESSOR_PAIR_TYPE:
253     case FIXED_ARRAY_TYPE:
254       return kInternal & kTaggedPtr;
255     default:
256       UNREACHABLE();
257       return kNone;
258   }
259 }
260
261
262 // Get the largest bitset subsumed by this type.
263 template<class Config>
264 int TypeImpl<Config>::GlbBitset() {
265   if (this->IsBitset()) {
266     return this->AsBitset();
267   } else if (this->IsUnion()) {
268     // All but the first are non-bitsets and thus would yield kNone anyway.
269     return Config::union_get(this->AsUnion(), 0)->GlbBitset();
270   } else {
271     return kNone;
272   }
273 }
274
275
276 // Most precise _current_ type of a value (usually its class).
277 template<class Config>
278 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::OfCurrently(
279     i::Handle<i::Object> value, Region* region) {
280   if (value->IsSmi() ||
281       i::HeapObject::cast(*value)->map()->instance_type() == HEAP_NUMBER_TYPE ||
282       i::HeapObject::cast(*value)->map()->instance_type() == ODDBALL_TYPE) {
283     return Of(value, region);
284   }
285   return Class(i::handle(i::HeapObject::cast(*value)->map()), region);
286 }
287
288
289 // Check this <= that.
290 template<class Config>
291 bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
292   // Fast path for bitsets.
293   if (this->IsNone()) return true;
294   if (that->IsBitset()) {
295     return (this->LubBitset() | that->AsBitset()) == that->AsBitset();
296   }
297
298   if (that->IsClass()) {
299     return this->IsClass() && *this->AsClass() == *that->AsClass();
300   }
301   if (that->IsConstant()) {
302     return this->IsConstant() && *this->AsConstant() == *that->AsConstant();
303   }
304
305   // (T1 \/ ... \/ Tn) <= T  <=>  (T1 <= T) /\ ... /\ (Tn <= T)
306   if (this->IsUnion()) {
307     UnionedHandle unioned = this->AsUnion();
308     for (int i = 0; i < Config::union_length(unioned); ++i) {
309       TypeHandle this_i = Config::union_get(unioned, i);
310       if (!this_i->Is(that)) return false;
311     }
312     return true;
313   }
314
315   // T <= (T1 \/ ... \/ Tn)  <=>  (T <= T1) \/ ... \/ (T <= Tn)
316   // (iff T is not a union)
317   ASSERT(!this->IsUnion());
318   if (that->IsUnion()) {
319     UnionedHandle unioned = that->AsUnion();
320     for (int i = 0; i < Config::union_length(unioned); ++i) {
321       TypeHandle that_i = Config::union_get(unioned, i);
322       if (this->Is(that_i)) return true;
323       if (this->IsBitset()) break;  // Fast fail, only first field is a bitset.
324     }
325     return false;
326   }
327
328   return false;
329 }
330
331
332 template<class Config>
333 bool TypeImpl<Config>::IsCurrently(TypeImpl* that) {
334   return this->Is(that) ||
335       (this->IsConstant() && that->IsClass() &&
336        this->AsConstant()->IsHeapObject() &&
337        i::HeapObject::cast(*this->AsConstant())->map() == *that->AsClass());
338 }
339
340
341 // Check this overlaps that.
342 template<class Config>
343 bool TypeImpl<Config>::Maybe(TypeImpl* that) {
344   // (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T)
345   if (this->IsUnion()) {
346     UnionedHandle unioned = this->AsUnion();
347     for (int i = 0; i < Config::union_length(unioned); ++i) {
348       TypeHandle this_i = Config::union_get(unioned, i);
349       if (this_i->Maybe(that)) return true;
350     }
351     return false;
352   }
353
354   // T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn)
355   if (that->IsUnion()) {
356     UnionedHandle unioned = that->AsUnion();
357     for (int i = 0; i < Config::union_length(unioned); ++i) {
358       TypeHandle that_i = Config::union_get(unioned, i);
359       if (this->Maybe(that_i)) return true;
360     }
361     return false;
362   }
363
364   ASSERT(!this->IsUnion() && !that->IsUnion());
365   if (this->IsBitset()) {
366     return IsInhabited(this->AsBitset() & that->LubBitset());
367   }
368   if (that->IsBitset()) {
369     return IsInhabited(this->LubBitset() & that->AsBitset());
370   }
371   if (this->IsClass()) {
372     return that->IsClass() && *this->AsClass() == *that->AsClass();
373   }
374   if (this->IsConstant()) {
375     return that->IsConstant() && *this->AsConstant() == *that->AsConstant();
376   }
377
378   return false;
379 }
380
381
382 template<class Config>
383 bool TypeImpl<Config>::InUnion(UnionedHandle unioned, int current_size) {
384   ASSERT(!this->IsUnion());
385   for (int i = 0; i < current_size; ++i) {
386     TypeHandle type = Config::union_get(unioned, i);
387     if (this->Is(type)) return true;
388   }
389   return false;
390 }
391
392
393 // Get non-bitsets from this which are not subsumed by union, store at unioned,
394 // starting at index. Returns updated index.
395 template<class Config>
396 int TypeImpl<Config>::ExtendUnion(
397     UnionedHandle result, TypeHandle type, int current_size) {
398   int old_size = current_size;
399   if (type->IsClass() || type->IsConstant()) {
400     if (!type->InUnion(result, old_size)) {
401       Config::union_set(result, current_size++, type);
402     }
403   } else if (type->IsUnion()) {
404     UnionedHandle unioned = type->AsUnion();
405     for (int i = 0; i < Config::union_length(unioned); ++i) {
406       TypeHandle type = Config::union_get(unioned, i);
407       ASSERT(i == 0 ||
408              !(type->IsBitset() || type->Is(Config::union_get(unioned, 0))));
409       if (!type->IsBitset() && !type->InUnion(result, old_size)) {
410         Config::union_set(result, current_size++, type);
411       }
412     }
413   }
414   return current_size;
415 }
416
417
418 // Union is O(1) on simple bit unions, but O(n*m) on structured unions.
419 // TODO(rossberg): Should we use object sets somehow? Is it worth it?
420 template<class Config>
421 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union(
422     TypeHandle type1, TypeHandle type2, Region* region) {
423   // Fast case: bit sets.
424   if (type1->IsBitset() && type2->IsBitset()) {
425     return Config::from_bitset(type1->AsBitset() | type2->AsBitset(), region);
426   }
427
428   // Fast case: top or bottom types.
429   if (type1->IsAny() || type2->IsNone()) return type1;
430   if (type2->IsAny() || type1->IsNone()) return type2;
431
432   // Semi-fast case: Unioned objects are neither involved nor produced.
433   if (!(type1->IsUnion() || type2->IsUnion())) {
434     if (type1->Is(type2)) return type2;
435     if (type2->Is(type1)) return type1;
436   }
437
438   // Slow case: may need to produce a Unioned object.
439   int size = 0;
440   if (!type1->IsBitset()) {
441     size += (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1);
442   }
443   if (!type2->IsBitset()) {
444     size += (type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1);
445   }
446   int bitset = type1->GlbBitset() | type2->GlbBitset();
447   if (bitset != kNone) ++size;
448   ASSERT(size >= 1);
449   UnionedHandle unioned = Config::union_create(size, region);
450
451   size = 0;
452   if (bitset != kNone) {
453     Config::union_set(unioned, size++, Config::from_bitset(bitset, region));
454   }
455   size = ExtendUnion(unioned, type1, size);
456   size = ExtendUnion(unioned, type2, size);
457
458   if (size == 1) {
459     return Config::union_get(unioned, 0);
460   } else {
461     Config::union_shrink(unioned, size);
462     return Config::from_union(unioned);
463   }
464 }
465
466
467 // Get non-bitsets from type which are also in other, store at unioned,
468 // starting at index. Returns updated index.
469 template<class Config>
470 int TypeImpl<Config>::ExtendIntersection(
471     UnionedHandle result, TypeHandle type, TypeHandle other, int current_size) {
472   int old_size = current_size;
473   if (type->IsClass() || type->IsConstant()) {
474     if (type->Is(other) && !type->InUnion(result, old_size)) {
475       Config::union_set(result, current_size++, type);
476     }
477   } else if (type->IsUnion()) {
478     UnionedHandle unioned = type->AsUnion();
479     for (int i = 0; i < Config::union_length(unioned); ++i) {
480       TypeHandle type = Config::union_get(unioned, i);
481       ASSERT(i == 0 ||
482              !(type->IsBitset() || type->Is(Config::union_get(unioned, 0))));
483       if (!type->IsBitset() && type->Is(other) &&
484           !type->InUnion(result, old_size)) {
485         Config::union_set(result, current_size++, type);
486       }
487     }
488   }
489   return current_size;
490 }
491
492
493 // Intersection is O(1) on simple bit unions, but O(n*m) on structured unions.
494 // TODO(rossberg): Should we use object sets somehow? Is it worth it?
495 template<class Config>
496 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect(
497     TypeHandle type1, TypeHandle type2, Region* region) {
498   // Fast case: bit sets.
499   if (type1->IsBitset() && type2->IsBitset()) {
500     return Config::from_bitset(type1->AsBitset() & type2->AsBitset(), region);
501   }
502
503   // Fast case: top or bottom types.
504   if (type1->IsNone() || type2->IsAny()) return type1;
505   if (type2->IsNone() || type1->IsAny()) return type2;
506
507   // Semi-fast case: Unioned objects are neither involved nor produced.
508   if (!(type1->IsUnion() || type2->IsUnion())) {
509     if (type1->Is(type2)) return type1;
510     if (type2->Is(type1)) return type2;
511   }
512
513   // Slow case: may need to produce a Unioned object.
514   int size = 0;
515   if (!type1->IsBitset()) {
516     size += (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1);
517   }
518   if (!type2->IsBitset()) {
519     size += (type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1);
520   }
521   int bitset = type1->GlbBitset() & type2->GlbBitset();
522   if (bitset != kNone) ++size;
523   ASSERT(size >= 1);
524   UnionedHandle unioned = Config::union_create(size, region);
525
526   size = 0;
527   if (bitset != kNone) {
528     Config::union_set(unioned, size++, Config::from_bitset(bitset, region));
529   }
530   size = ExtendIntersection(unioned, type1, type2, size);
531   size = ExtendIntersection(unioned, type2, type1, size);
532
533   if (size == 0) {
534     return None(region);
535   } else if (size == 1) {
536     return Config::union_get(unioned, 0);
537   } else {
538     Config::union_shrink(unioned, size);
539     return Config::from_union(unioned);
540   }
541 }
542
543
544 template<class Config>
545 template<class OtherType>
546 typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert(
547     typename OtherType::TypeHandle type, Region* region) {
548   if (type->IsBitset()) {
549     return Config::from_bitset(type->AsBitset(), region);
550   } else if (type->IsClass()) {
551     return Config::from_class(type->AsClass(), type->LubBitset(), region);
552   } else if (type->IsConstant()) {
553     return Config::from_constant(type->AsConstant(), type->LubBitset(), region);
554   } else {
555     ASSERT(type->IsUnion());
556     typename OtherType::UnionedHandle unioned = type->AsUnion();
557     int length = OtherType::UnionLength(unioned);
558     UnionedHandle new_unioned = Config::union_create(length, region);
559     for (int i = 0; i < length; ++i) {
560       Config::union_set(new_unioned, i,
561           Convert<OtherType>(OtherType::UnionGet(unioned, i), region));
562     }
563     return Config::from_union(new_unioned);
564   }
565 }
566
567
568 // TODO(rossberg): this does not belong here.
569 Representation Representation::FromType(Type* type) {
570   if (type->Is(Type::None())) return Representation::None();
571   if (type->Is(Type::SignedSmall())) return Representation::Smi();
572   if (type->Is(Type::Signed32())) return Representation::Integer32();
573   if (type->Is(Type::Number())) return Representation::Double();
574   if (type->Is(Type::Float32x4())) return Representation::Float32x4();
575   if (type->Is(Type::Int32x4())) return Representation::Int32x4();
576   return Representation::Tagged();
577 }
578
579
580 #ifdef OBJECT_PRINT
581 template<class Config>
582 void TypeImpl<Config>::TypePrint(PrintDimension dim) {
583   TypePrint(stdout, dim);
584   PrintF(stdout, "\n");
585   Flush(stdout);
586 }
587
588
589 template<class Config>
590 const char* TypeImpl<Config>::bitset_name(int bitset) {
591   switch (bitset) {
592     case kAny & kRepresentation: return "Any";
593     #define PRINT_COMPOSED_TYPE(type, value) \
594     case k##type & kRepresentation: return #type;
595     REPRESENTATION_BITSET_TYPE_LIST(PRINT_COMPOSED_TYPE)
596     #undef PRINT_COMPOSED_TYPE
597
598     #define PRINT_COMPOSED_TYPE(type, value) \
599     case k##type & kSemantic: return #type;
600     SEMANTIC_BITSET_TYPE_LIST(PRINT_COMPOSED_TYPE)
601     #undef PRINT_COMPOSED_TYPE
602
603     default:
604       return NULL;
605   }
606 }
607
608
609 template<class Config>
610 void TypeImpl<Config>::BitsetTypePrint(FILE* out, int bitset) {
611   const char* name = bitset_name(bitset);
612   if (name != NULL) {
613     PrintF(out, "%s", name);
614   } else {
615     static const int named_bitsets[] = {
616       #define BITSET_CONSTANT(type, value) k##type & kRepresentation,
617       REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT)
618       #undef BITSET_CONSTANT
619
620       #define BITSET_CONSTANT(type, value) k##type & kSemantic,
621       SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT)
622       #undef BITSET_CONSTANT
623     };
624
625     bool is_first = true;
626     PrintF(out, "(");
627     for (int i(ARRAY_SIZE(named_bitsets) - 1); bitset != 0 && i >= 0; --i) {
628       int subset = named_bitsets[i];
629       if ((bitset & subset) == subset) {
630         if (!is_first) PrintF(out, " | ");
631         is_first = false;
632         PrintF(out, "%s", bitset_name(subset));
633         bitset -= subset;
634       }
635     }
636     ASSERT(bitset == 0);
637     PrintF(out, ")");
638   }
639 }
640
641
642 template<class Config>
643 void TypeImpl<Config>::TypePrint(FILE* out, PrintDimension dim) {
644   if (this->IsBitset()) {
645     int bitset = this->AsBitset();
646     switch (dim) {
647       case BOTH_DIMS:
648         BitsetTypePrint(out, bitset & kSemantic);
649         PrintF(out, "/");
650         BitsetTypePrint(out, bitset & kRepresentation);
651         break;
652       case SEMANTIC_DIM:
653         BitsetTypePrint(out, bitset & kSemantic);
654         break;
655       case REPRESENTATION_DIM:
656         BitsetTypePrint(out, bitset & kRepresentation);
657         break;
658     }
659   } else if (this->IsConstant()) {
660     PrintF(out, "Constant(%p : ", static_cast<void*>(*this->AsConstant()));
661     Config::from_bitset(this->LubBitset())->TypePrint(out, dim);
662     PrintF(out, ")");
663   } else if (this->IsClass()) {
664     PrintF(out, "Class(%p < ", static_cast<void*>(*this->AsClass()));
665     Config::from_bitset(this->LubBitset())->TypePrint(out, dim);
666     PrintF(out, ")");
667   } else if (this->IsUnion()) {
668     PrintF(out, "(");
669     UnionedHandle unioned = this->AsUnion();
670     for (int i = 0; i < Config::union_length(unioned); ++i) {
671       TypeHandle type_i = Config::union_get(unioned, i);
672       if (i > 0) PrintF(out, " | ");
673       type_i->TypePrint(out, dim);
674     }
675     PrintF(out, ")");
676   }
677 }
678 #endif
679
680
681 template class TypeImpl<ZoneTypeConfig>;
682 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>;
683 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>;
684
685 template class TypeImpl<HeapTypeConfig>;
686 template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>;
687 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>;
688
689 template TypeImpl<ZoneTypeConfig>::TypeHandle
690   TypeImpl<ZoneTypeConfig>::Convert<HeapType>(
691     TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*);
692 template TypeImpl<HeapTypeConfig>::TypeHandle
693   TypeImpl<HeapTypeConfig>::Convert<Type>(
694     TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*);
695
696
697 } }  // namespace v8::internal