Index: src/types.cc |
diff --git a/src/types.cc b/src/types.cc |
index 804ea5ece64d8a12941040014fb2300d5e59c2bd..38efa962bab238a1dd33004b5578a2ecd5c0bc87 100644 |
--- a/src/types.cc |
+++ b/src/types.cc |
@@ -15,10 +15,10 @@ int TypeImpl<Config>::NumClasses() { |
if (this->IsClass()) { |
return 1; |
} else if (this->IsUnion()) { |
- UnionedHandle unioned = this->AsUnion(); |
+ StructHandle unioned = this->AsUnion(); |
int result = 0; |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- if (Config::union_get(unioned, i)->IsClass()) ++result; |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ if (Config::struct_get(unioned, i)->IsClass()) ++result; |
} |
return result; |
} else { |
@@ -32,10 +32,10 @@ int TypeImpl<Config>::NumConstants() { |
if (this->IsConstant()) { |
return 1; |
} else if (this->IsUnion()) { |
- UnionedHandle unioned = this->AsUnion(); |
+ StructHandle unioned = this->AsUnion(); |
int result = 0; |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- if (Config::union_get(unioned, i)->IsConstant()) ++result; |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ if (Config::struct_get(unioned, i)->IsConstant()) ++result; |
} |
return result; |
} else { |
@@ -48,7 +48,8 @@ template<class Config> template<class T> |
typename TypeImpl<Config>::TypeHandle |
TypeImpl<Config>::Iterator<T>::get_type() { |
ASSERT(!Done()); |
- return type_->IsUnion() ? Config::union_get(type_->AsUnion(), index_) : type_; |
+ return type_->IsUnion() |
+ ? Config::struct_get(type_->AsUnion(), index_) : type_; |
} |
@@ -96,9 +97,9 @@ template<class Config> template<class T> |
void TypeImpl<Config>::Iterator<T>::Advance() { |
++index_; |
if (type_->IsUnion()) { |
- UnionedHandle unioned = type_->AsUnion(); |
- for (; index_ < Config::union_length(unioned); ++index_) { |
- if (matches(Config::union_get(unioned, index_))) return; |
+ StructHandle unioned = type_->AsUnion(); |
+ for (; index_ < Config::struct_length(unioned); ++index_) { |
+ if (matches(Config::struct_get(unioned, index_))) return; |
} |
} else if (index_ == 0 && matches(type_)) { |
return; |
@@ -113,10 +114,10 @@ int TypeImpl<Config>::LubBitset() { |
if (this->IsBitset()) { |
return this->AsBitset(); |
} else if (this->IsUnion()) { |
- UnionedHandle unioned = this->AsUnion(); |
+ StructHandle unioned = this->AsUnion(); |
int bitset = kNone; |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- bitset |= Config::union_get(unioned, i)->LubBitset(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ bitset |= Config::struct_get(unioned, i)->LubBitset(); |
} |
return bitset; |
} else if (this->IsClass()) { |
@@ -239,7 +240,7 @@ int TypeImpl<Config>::GlbBitset() { |
return this->AsBitset(); |
} else if (this->IsUnion()) { |
// All but the first are non-bitsets and thus would yield kNone anyway. |
- return Config::union_get(this->AsUnion(), 0)->GlbBitset(); |
+ return Config::struct_get(this->AsUnion(), 0)->GlbBitset(); |
} else { |
return kNone; |
} |
@@ -277,9 +278,9 @@ bool TypeImpl<Config>::SlowIs(TypeImpl* that) { |
// (T1 \/ ... \/ Tn) <= T <=> (T1 <= T) /\ ... /\ (Tn <= T) |
if (this->IsUnion()) { |
- UnionedHandle unioned = this->AsUnion(); |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- TypeHandle this_i = Config::union_get(unioned, i); |
+ StructHandle unioned = this->AsUnion(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ TypeHandle this_i = Config::struct_get(unioned, i); |
if (!this_i->Is(that)) return false; |
} |
return true; |
@@ -289,9 +290,9 @@ bool TypeImpl<Config>::SlowIs(TypeImpl* that) { |
// (iff T is not a union) |
ASSERT(!this->IsUnion()); |
if (that->IsUnion()) { |
- UnionedHandle unioned = that->AsUnion(); |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- TypeHandle that_i = Config::union_get(unioned, i); |
+ StructHandle unioned = that->AsUnion(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ TypeHandle that_i = Config::struct_get(unioned, i); |
if (this->Is(that_i)) return true; |
if (this->IsBitset()) break; // Fast fail, only first field is a bitset. |
} |
@@ -324,9 +325,9 @@ bool TypeImpl<Config>::Maybe(TypeImpl* that) { |
// (T1 \/ ... \/ Tn) overlaps T <=> (T1 overlaps T) \/ ... \/ (Tn overlaps T) |
if (this->IsUnion()) { |
- UnionedHandle unioned = this->AsUnion(); |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- TypeHandle this_i = Config::union_get(unioned, i); |
+ StructHandle unioned = this->AsUnion(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ TypeHandle this_i = Config::struct_get(unioned, i); |
if (this_i->Maybe(that)) return true; |
} |
return false; |
@@ -334,9 +335,9 @@ bool TypeImpl<Config>::Maybe(TypeImpl* that) { |
// T overlaps (T1 \/ ... \/ Tn) <=> (T overlaps T1) \/ ... \/ (T overlaps Tn) |
if (that->IsUnion()) { |
- UnionedHandle unioned = that->AsUnion(); |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- TypeHandle that_i = Config::union_get(unioned, i); |
+ StructHandle unioned = that->AsUnion(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ TypeHandle that_i = Config::struct_get(unioned, i); |
if (this->Maybe(that_i)) return true; |
} |
return false; |
@@ -372,34 +373,34 @@ bool TypeImpl<Config>::NowContains(i::Object* value) { |
template<class Config> |
-bool TypeImpl<Config>::InUnion(UnionedHandle unioned, int current_size) { |
+bool TypeImpl<Config>::InUnion(StructHandle unioned, int current_size) { |
ASSERT(!this->IsUnion()); |
for (int i = 0; i < current_size; ++i) { |
- TypeHandle type = Config::union_get(unioned, i); |
+ TypeHandle type = Config::struct_get(unioned, i); |
if (this->Is(type)) return true; |
} |
return false; |
} |
-// Get non-bitsets from this which are not subsumed by union, store at unioned, |
+// Get non-bitsets from this which are not subsumed by union, store at result, |
// starting at index. Returns updated index. |
template<class Config> |
int TypeImpl<Config>::ExtendUnion( |
- UnionedHandle result, TypeHandle type, int current_size) { |
+ StructHandle result, TypeHandle type, int current_size) { |
int old_size = current_size; |
if (type->IsClass() || type->IsConstant()) { |
if (!type->InUnion(result, old_size)) { |
- Config::union_set(result, current_size++, type); |
+ Config::struct_set(result, current_size++, type); |
} |
} else if (type->IsUnion()) { |
- UnionedHandle unioned = type->AsUnion(); |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- TypeHandle type = Config::union_get(unioned, i); |
+ StructHandle unioned = type->AsUnion(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ TypeHandle type = Config::struct_get(unioned, i); |
ASSERT(i == 0 || |
- !(type->IsBitset() || type->Is(Config::union_get(unioned, 0)))); |
+ !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); |
if (!type->IsBitset() && !type->InUnion(result, old_size)) { |
- Config::union_set(result, current_size++, type); |
+ Config::struct_set(result, current_size++, type); |
} |
} |
} |
@@ -408,7 +409,6 @@ int TypeImpl<Config>::ExtendUnion( |
// Union is O(1) on simple bit unions, but O(n*m) on structured unions. |
-// TODO(rossberg): Should we use object sets somehow? Is it worth it? |
template<class Config> |
typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( |
TypeHandle type1, TypeHandle type2, Region* region) { |
@@ -430,51 +430,51 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Union( |
// Slow case: may need to produce a Unioned object. |
int size = 0; |
if (!type1->IsBitset()) { |
- size += (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1); |
+ size += (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1); |
} |
if (!type2->IsBitset()) { |
- size += (type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1); |
+ size += (type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1); |
} |
int bitset = type1->GlbBitset() | type2->GlbBitset(); |
if (IsInhabited(bitset)) ++size; |
ASSERT(size >= 1); |
- UnionedHandle unioned = Config::union_create(size, region); |
+ StructHandle unioned = Config::struct_create(kUnionTag, size, region); |
size = 0; |
if (IsInhabited(bitset)) { |
- Config::union_set(unioned, size++, Config::from_bitset(bitset, region)); |
+ Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); |
} |
size = ExtendUnion(unioned, type1, size); |
size = ExtendUnion(unioned, type2, size); |
if (size == 1) { |
- return Config::union_get(unioned, 0); |
+ return Config::struct_get(unioned, 0); |
} else { |
- Config::union_shrink(unioned, size); |
- return Config::from_union(unioned); |
+ Config::struct_shrink(unioned, size); |
+ return Config::from_struct(unioned); |
} |
} |
-// Get non-bitsets from type which are also in other, store at unioned, |
+// Get non-bitsets from type which are also in other, store at result, |
// starting at index. Returns updated index. |
template<class Config> |
int TypeImpl<Config>::ExtendIntersection( |
- UnionedHandle result, TypeHandle type, TypeHandle other, int current_size) { |
+ StructHandle result, TypeHandle type, TypeHandle other, int current_size) { |
int old_size = current_size; |
if (type->IsClass() || type->IsConstant()) { |
if (type->Is(other) && !type->InUnion(result, old_size)) { |
- Config::union_set(result, current_size++, type); |
+ Config::struct_set(result, current_size++, type); |
} |
} else if (type->IsUnion()) { |
- UnionedHandle unioned = type->AsUnion(); |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- TypeHandle type = Config::union_get(unioned, i); |
+ StructHandle unioned = type->AsUnion(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ TypeHandle type = Config::struct_get(unioned, i); |
ASSERT(i == 0 || |
- !(type->IsBitset() || type->Is(Config::union_get(unioned, 0)))); |
+ !(type->IsBitset() || type->Is(Config::struct_get(unioned, 0)))); |
if (!type->IsBitset() && type->Is(other) && |
!type->InUnion(result, old_size)) { |
- Config::union_set(result, current_size++, type); |
+ Config::struct_set(result, current_size++, type); |
} |
} |
} |
@@ -505,20 +505,20 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect( |
// Slow case: may need to produce a Unioned object. |
int size = INT_MAX; |
if (!type1->IsBitset()) { |
- size = (type1->IsUnion() ? Config::union_length(type1->AsUnion()) : 1); |
+ size = (type1->IsUnion() ? Config::struct_length(type1->AsUnion()) : 1); |
} |
if (!type2->IsBitset()) { |
size = Min(size, |
- type2->IsUnion() ? Config::union_length(type2->AsUnion()) : 1); |
+ type2->IsUnion() ? Config::struct_length(type2->AsUnion()) : 1); |
} |
int bitset = type1->GlbBitset() & type2->GlbBitset(); |
if (IsInhabited(bitset)) ++size; |
ASSERT(size >= 1); |
- UnionedHandle unioned = Config::union_create(size, region); |
+ StructHandle unioned = Config::struct_create(kUnionTag, size, region); |
size = 0; |
if (IsInhabited(bitset)) { |
- Config::union_set(unioned, size++, Config::from_bitset(bitset, region)); |
+ Config::struct_set(unioned, size++, Config::from_bitset(bitset, region)); |
} |
size = ExtendIntersection(unioned, type1, type2, size); |
size = ExtendIntersection(unioned, type2, type1, size); |
@@ -526,10 +526,10 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Intersect( |
if (size == 0) { |
return None(region); |
} else if (size == 1) { |
- return Config::union_get(unioned, 0); |
+ return Config::struct_get(unioned, 0); |
} else { |
- Config::union_shrink(unioned, size); |
- return Config::from_union(unioned); |
+ Config::struct_shrink(unioned, size); |
+ return Config::from_struct(unioned); |
} |
} |
@@ -546,14 +546,14 @@ typename TypeImpl<Config>::TypeHandle TypeImpl<Config>::Convert( |
return Config::from_constant(type->AsConstant(), type->LubBitset(), region); |
} else { |
ASSERT(type->IsUnion()); |
- typename OtherType::UnionedHandle unioned = type->AsUnion(); |
- int length = OtherType::UnionLength(unioned); |
- UnionedHandle new_unioned = Config::union_create(length, region); |
+ typename OtherType::StructHandle unioned = type->AsUnion(); |
+ int length = OtherType::StructLength(unioned); |
+ StructHandle new_unioned = Config::struct_create(kUnionTag, length, region); |
for (int i = 0; i < length; ++i) { |
- Config::union_set(new_unioned, i, |
- Convert<OtherType>(OtherType::UnionGet(unioned, i), region)); |
+ Config::struct_set(new_unioned, i, |
+ Convert<OtherType>(OtherType::StructGet(unioned, i), region)); |
} |
- return Config::from_union(new_unioned); |
+ return Config::from_struct(new_unioned); |
} |
} |
@@ -657,9 +657,9 @@ void TypeImpl<Config>::TypePrint(FILE* out, PrintDimension dim) { |
PrintF(out, ")"); |
} else if (this->IsUnion()) { |
PrintF(out, "("); |
- UnionedHandle unioned = this->AsUnion(); |
- for (int i = 0; i < Config::union_length(unioned); ++i) { |
- TypeHandle type_i = Config::union_get(unioned, i); |
+ StructHandle unioned = this->AsUnion(); |
+ for (int i = 0; i < Config::struct_length(unioned); ++i) { |
+ TypeHandle type_i = Config::struct_get(unioned, i); |
if (i > 0) PrintF(out, " | "); |
type_i->TypePrint(out, dim); |
} |