OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <iomanip> | 5 #include <iomanip> |
6 | 6 |
7 #include "src/types.h" | 7 #include "src/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" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // a bitset. | 139 // a bitset. |
140 int bitset = type->AsUnion()->Get(0)->BitsetLub(); | 140 int bitset = type->AsUnion()->Get(0)->BitsetLub(); |
141 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { | 141 for (int i = 0, n = type->AsUnion()->Length(); i < n; ++i) { |
142 // Other elements only contribute their semantic part. | 142 // Other elements only contribute their semantic part. |
143 bitset |= SEMANTIC(type->AsUnion()->Get(i)->BitsetLub()); | 143 bitset |= SEMANTIC(type->AsUnion()->Get(i)->BitsetLub()); |
144 } | 144 } |
145 return bitset; | 145 return bitset; |
146 } | 146 } |
147 if (type->IsConstant()) return type->AsConstant()->Lub(); | 147 if (type->IsConstant()) return type->AsConstant()->Lub(); |
148 if (type->IsRange()) return type->AsRange()->Lub(); | 148 if (type->IsRange()) return type->AsRange()->Lub(); |
149 if (type->IsArray()) return kOtherObject; | |
150 if (type->IsFunction()) return kFunction; | |
151 if (type->IsTuple()) return kOtherInternal; | 149 if (type->IsTuple()) return kOtherInternal; |
152 UNREACHABLE(); | 150 UNREACHABLE(); |
153 return kNone; | 151 return kNone; |
154 } | 152 } |
155 | 153 |
156 Type::bitset BitsetType::Lub(i::Map* map) { | 154 Type::bitset BitsetType::Lub(i::Map* map) { |
157 DisallowHeapAllocation no_allocation; | 155 DisallowHeapAllocation no_allocation; |
158 switch (map->instance_type()) { | 156 switch (map->instance_type()) { |
159 case STRING_TYPE: | 157 case STRING_TYPE: |
160 case ONE_BYTE_STRING_TYPE: | 158 case ONE_BYTE_STRING_TYPE: |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 402 |
405 // ----------------------------------------------------------------------------- | 403 // ----------------------------------------------------------------------------- |
406 // Predicates. | 404 // Predicates. |
407 | 405 |
408 bool Type::SimplyEquals(Type* that) { | 406 bool Type::SimplyEquals(Type* that) { |
409 DisallowHeapAllocation no_allocation; | 407 DisallowHeapAllocation no_allocation; |
410 if (this->IsConstant()) { | 408 if (this->IsConstant()) { |
411 return that->IsConstant() | 409 return that->IsConstant() |
412 && *this->AsConstant()->Value() == *that->AsConstant()->Value(); | 410 && *this->AsConstant()->Value() == *that->AsConstant()->Value(); |
413 } | 411 } |
414 if (this->IsArray()) { | |
415 return that->IsArray() | |
416 && this->AsArray()->Element()->Equals(that->AsArray()->Element()); | |
417 } | |
418 if (this->IsFunction()) { | |
419 if (!that->IsFunction()) return false; | |
420 FunctionType* this_fun = this->AsFunction(); | |
421 FunctionType* that_fun = that->AsFunction(); | |
422 if (this_fun->Arity() != that_fun->Arity() || | |
423 !this_fun->Result()->Equals(that_fun->Result()) || | |
424 !this_fun->Receiver()->Equals(that_fun->Receiver())) { | |
425 return false; | |
426 } | |
427 for (int i = 0, n = this_fun->Arity(); i < n; ++i) { | |
428 if (!this_fun->Parameter(i)->Equals(that_fun->Parameter(i))) return false; | |
429 } | |
430 return true; | |
431 } | |
432 if (this->IsTuple()) { | 412 if (this->IsTuple()) { |
433 if (!that->IsTuple()) return false; | 413 if (!that->IsTuple()) return false; |
434 TupleType* this_tuple = this->AsTuple(); | 414 TupleType* this_tuple = this->AsTuple(); |
435 TupleType* that_tuple = that->AsTuple(); | 415 TupleType* that_tuple = that->AsTuple(); |
436 if (this_tuple->Arity() != that_tuple->Arity()) { | 416 if (this_tuple->Arity() != that_tuple->Arity()) { |
437 return false; | 417 return false; |
438 } | 418 } |
439 for (int i = 0, n = this_tuple->Arity(); i < n; ++i) { | 419 for (int i = 0, n = this_tuple->Arity(); i < n; ++i) { |
440 if (!this_tuple->Element(i)->Equals(that_tuple->Element(i))) return false; | 420 if (!this_tuple->Element(i)->Equals(that_tuple->Element(i))) return false; |
441 } | 421 } |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 os.flags(saved_flags); | 1083 os.flags(saved_flags); |
1104 os.precision(saved_precision); | 1084 os.precision(saved_precision); |
1105 } else if (this->IsUnion()) { | 1085 } else if (this->IsUnion()) { |
1106 os << "("; | 1086 os << "("; |
1107 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { | 1087 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { |
1108 Type* type_i = this->AsUnion()->Get(i); | 1088 Type* type_i = this->AsUnion()->Get(i); |
1109 if (i > 0) os << " | "; | 1089 if (i > 0) os << " | "; |
1110 type_i->PrintTo(os, dim); | 1090 type_i->PrintTo(os, dim); |
1111 } | 1091 } |
1112 os << ")"; | 1092 os << ")"; |
1113 } else if (this->IsArray()) { | |
1114 os << "Array("; | |
1115 AsArray()->Element()->PrintTo(os, dim); | |
1116 os << ")"; | |
1117 } else if (this->IsFunction()) { | |
1118 if (!this->AsFunction()->Receiver()->IsAny()) { | |
1119 this->AsFunction()->Receiver()->PrintTo(os, dim); | |
1120 os << "."; | |
1121 } | |
1122 os << "("; | |
1123 for (int i = 0; i < this->AsFunction()->Arity(); ++i) { | |
1124 if (i > 0) os << ", "; | |
1125 this->AsFunction()->Parameter(i)->PrintTo(os, dim); | |
1126 } | |
1127 os << ")->"; | |
1128 this->AsFunction()->Result()->PrintTo(os, dim); | |
1129 } else if (this->IsTuple()) { | 1093 } else if (this->IsTuple()) { |
1130 os << "<"; | 1094 os << "<"; |
1131 for (int i = 0, n = this->AsTuple()->Arity(); i < n; ++i) { | 1095 for (int i = 0, n = this->AsTuple()->Arity(); i < n; ++i) { |
1132 Type* type_i = this->AsTuple()->Element(i); | 1096 Type* type_i = this->AsTuple()->Element(i); |
1133 if (i > 0) os << ", "; | 1097 if (i > 0) os << ", "; |
1134 type_i->PrintTo(os, dim); | 1098 type_i->PrintTo(os, dim); |
1135 } | 1099 } |
1136 os << ">"; | 1100 os << ">"; |
1137 } else { | 1101 } else { |
1138 UNREACHABLE(); | 1102 UNREACHABLE(); |
(...skipping 27 matching lines...) Expand all Loading... |
1166 return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31; | 1130 return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31; |
1167 } | 1131 } |
1168 | 1132 |
1169 // ----------------------------------------------------------------------------- | 1133 // ----------------------------------------------------------------------------- |
1170 // Instantiations. | 1134 // Instantiations. |
1171 | 1135 |
1172 template class Type::Iterator<i::Object>; | 1136 template class Type::Iterator<i::Object>; |
1173 | 1137 |
1174 } // namespace internal | 1138 } // namespace internal |
1175 } // namespace v8 | 1139 } // namespace v8 |
OLD | NEW |