| 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 "src/types.h" | 5 #include "src/types.h" |
| 6 | 6 |
| 7 #include "src/string-stream.h" | 7 #include "src/string-stream.h" |
| 8 #include "src/types-inl.h" | 8 #include "src/types-inl.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 SEMANTIC_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE) | 854 SEMANTIC_BITSET_TYPE_LIST(RETURN_NAMED_SEMANTIC_TYPE) |
| 855 #undef RETURN_NAMED_SEMANTIC_TYPE | 855 #undef RETURN_NAMED_SEMANTIC_TYPE |
| 856 | 856 |
| 857 default: | 857 default: |
| 858 return NULL; | 858 return NULL; |
| 859 } | 859 } |
| 860 } | 860 } |
| 861 | 861 |
| 862 | 862 |
| 863 template<class Config> | 863 template<class Config> |
| 864 void TypeImpl<Config>::BitsetType::PrintTo(StringStream* stream, int bitset) { | 864 OStream& TypeImpl<Config>::BitsetType::Print(OStream& os, // NOLINT |
| 865 int bitset) { |
| 865 DisallowHeapAllocation no_allocation; | 866 DisallowHeapAllocation no_allocation; |
| 866 const char* name = Name(bitset); | 867 const char* name = Name(bitset); |
| 867 if (name != NULL) { | 868 if (name != NULL) return os << name; |
| 868 stream->Add("%s", name); | |
| 869 } else { | |
| 870 static const int named_bitsets[] = { | |
| 871 #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), | |
| 872 REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) | |
| 873 #undef BITSET_CONSTANT | |
| 874 | 869 |
| 875 #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), | 870 static const int named_bitsets[] = { |
| 876 SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) | 871 #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), |
| 877 #undef BITSET_CONSTANT | 872 REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) |
| 878 }; | 873 #undef BITSET_CONSTANT |
| 879 | 874 |
| 880 bool is_first = true; | 875 #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), |
| 881 stream->Add("("); | 876 SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) |
| 882 for (int i(ARRAY_SIZE(named_bitsets) - 1); bitset != 0 && i >= 0; --i) { | 877 #undef BITSET_CONSTANT |
| 883 int subset = named_bitsets[i]; | 878 }; |
| 884 if ((bitset & subset) == subset) { | 879 |
| 885 if (!is_first) stream->Add(" | "); | 880 bool is_first = true; |
| 886 is_first = false; | 881 os << "("; |
| 887 stream->Add("%s", Name(subset)); | 882 for (int i(ARRAY_SIZE(named_bitsets) - 1); bitset != 0 && i >= 0; --i) { |
| 888 bitset -= subset; | 883 int subset = named_bitsets[i]; |
| 889 } | 884 if ((bitset & subset) == subset) { |
| 885 if (!is_first) os << " | "; |
| 886 is_first = false; |
| 887 os << Name(subset); |
| 888 bitset -= subset; |
| 890 } | 889 } |
| 891 ASSERT(bitset == 0); | |
| 892 stream->Add(")"); | |
| 893 } | 890 } |
| 891 ASSERT(bitset == 0); |
| 892 return os << ")"; |
| 894 } | 893 } |
| 895 | 894 |
| 896 | 895 |
| 897 template<class Config> | 896 template <class Config> |
| 898 void TypeImpl<Config>::PrintTo(StringStream* stream, PrintDimension dim) { | 897 OStream& TypeImpl<Config>::PrintTo(OStream& os, PrintDimension dim) { // NOLINT |
| 899 DisallowHeapAllocation no_allocation; | 898 DisallowHeapAllocation no_allocation; |
| 900 if (dim != REPRESENTATION_DIM) { | 899 if (dim != REPRESENTATION_DIM) { |
| 901 if (this->IsBitset()) { | 900 if (this->IsBitset()) { |
| 902 BitsetType::PrintTo(stream, SEMANTIC(this->AsBitset())); | 901 BitsetType::Print(os, SEMANTIC(this->AsBitset())); |
| 903 } else if (this->IsClass()) { | 902 } else if (this->IsClass()) { |
| 904 stream->Add("Class(%p < ", static_cast<void*>(*this->AsClass()->Map())); | 903 os << "Class(" << static_cast<void*>(*this->AsClass()->Map()) << " < "; |
| 905 BitsetType::New(BitsetType::Lub(this))->PrintTo(stream, dim); | 904 return BitsetType::New(BitsetType::Lub(this))->PrintTo(os, dim) << ")"; |
| 906 stream->Add(")"); | |
| 907 return; | |
| 908 } else if (this->IsConstant()) { | 905 } else if (this->IsConstant()) { |
| 909 stream->Add("Constant(%p : ", | 906 os << "Constant(" << static_cast<void*>(*this->AsConstant()->Value()) |
| 910 static_cast<void*>(*this->AsConstant()->Value())); | 907 << " : "; |
| 911 BitsetType::New(BitsetType::Lub(this))->PrintTo(stream, dim); | 908 return BitsetType::New(BitsetType::Lub(this))->PrintTo(os, dim) << ")"; |
| 912 stream->Add(")"); | |
| 913 return; | |
| 914 } else if (this->IsContext()) { | 909 } else if (this->IsContext()) { |
| 915 stream->Add("Context("); | 910 os << "Context("; |
| 916 this->AsContext()->Outer()->PrintTo(stream, dim); | 911 this->AsContext()->Outer()->PrintTo(os, dim) << ")"; |
| 917 stream->Add(")"); | |
| 918 } else if (this->IsUnion()) { | 912 } else if (this->IsUnion()) { |
| 919 stream->Add("("); | 913 os << "("; |
| 920 UnionHandle unioned = handle(this->AsUnion()); | 914 UnionHandle unioned = handle(this->AsUnion()); |
| 921 for (int i = 0; i < unioned->Length(); ++i) { | 915 for (int i = 0; i < unioned->Length(); ++i) { |
| 922 TypeHandle type_i = unioned->Get(i); | 916 TypeHandle type_i = unioned->Get(i); |
| 923 if (i > 0) stream->Add(" | "); | 917 if (i > 0) os << " | "; |
| 924 type_i->PrintTo(stream, dim); | 918 type_i->PrintTo(os, dim); |
| 925 } | 919 } |
| 926 stream->Add(")"); | 920 return os << ")"; |
| 927 return; | |
| 928 } else if (this->IsArray()) { | 921 } else if (this->IsArray()) { |
| 929 stream->Add("Array("); | 922 os << "Array("; |
| 930 AsArray()->Element()->PrintTo(stream, dim); | 923 AsArray()->Element()->PrintTo(os, dim) << ")"; |
| 931 stream->Add(")"); | |
| 932 } else if (this->IsFunction()) { | 924 } else if (this->IsFunction()) { |
| 933 if (!this->AsFunction()->Receiver()->IsAny()) { | 925 if (!this->AsFunction()->Receiver()->IsAny()) { |
| 934 this->AsFunction()->Receiver()->PrintTo(stream, dim); | 926 this->AsFunction()->Receiver()->PrintTo(os, dim) << "."; |
| 935 stream->Add("."); | |
| 936 } | 927 } |
| 937 stream->Add("("); | 928 os << "("; |
| 938 for (int i = 0; i < this->AsFunction()->Arity(); ++i) { | 929 for (int i = 0; i < this->AsFunction()->Arity(); ++i) { |
| 939 if (i > 0) stream->Add(", "); | 930 if (i > 0) os << ", "; |
| 940 this->AsFunction()->Parameter(i)->PrintTo(stream, dim); | 931 this->AsFunction()->Parameter(i)->PrintTo(os, dim); |
| 941 } | 932 } |
| 942 stream->Add(")->"); | 933 os << ")->"; |
| 943 this->AsFunction()->Result()->PrintTo(stream, dim); | 934 this->AsFunction()->Result()->PrintTo(os, dim); |
| 944 } else { | 935 } else { |
| 945 UNREACHABLE(); | 936 UNREACHABLE(); |
| 946 } | 937 } |
| 947 } | 938 } |
| 948 if (dim == BOTH_DIMS) { | 939 if (dim == BOTH_DIMS) os << "/"; |
| 949 stream->Add("/"); | 940 if (dim != SEMANTIC_DIM) { |
| 941 BitsetType::Print(os, REPRESENTATION(this->BitsetLub())); |
| 950 } | 942 } |
| 951 if (dim != SEMANTIC_DIM) { | 943 return os; |
| 952 BitsetType::PrintTo(stream, REPRESENTATION(this->BitsetLub())); | |
| 953 } | |
| 954 } | 944 } |
| 955 | 945 |
| 956 | 946 |
| 957 template<class Config> | |
| 958 void TypeImpl<Config>::TypePrint(FILE* out, PrintDimension dim) { | |
| 959 HeapStringAllocator allocator; | |
| 960 StringStream stream(&allocator); | |
| 961 PrintTo(&stream, dim); | |
| 962 stream.OutputToFile(out); | |
| 963 } | |
| 964 | |
| 965 | |
| 966 template<class Config> | |
| 967 void TypeImpl<Config>::TypePrint(PrintDimension dim) { | |
| 968 TypePrint(stdout, dim); | |
| 969 PrintF(stdout, "\n"); | |
| 970 Flush(stdout); | |
| 971 } | |
| 972 | |
| 973 | |
| 974 // ----------------------------------------------------------------------------- | 947 // ----------------------------------------------------------------------------- |
| 975 // Instantiations. | 948 // Instantiations. |
| 976 | 949 |
| 977 template class TypeImpl<ZoneTypeConfig>; | 950 template class TypeImpl<ZoneTypeConfig>; |
| 978 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>; | 951 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Map>; |
| 979 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>; | 952 template class TypeImpl<ZoneTypeConfig>::Iterator<i::Object>; |
| 980 | 953 |
| 981 template class TypeImpl<HeapTypeConfig>; | 954 template class TypeImpl<HeapTypeConfig>; |
| 982 template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>; | 955 template class TypeImpl<HeapTypeConfig>::Iterator<i::Map>; |
| 983 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 956 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
| 984 | 957 |
| 985 template TypeImpl<ZoneTypeConfig>::TypeHandle | 958 template TypeImpl<ZoneTypeConfig>::TypeHandle |
| 986 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 959 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
| 987 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 960 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
| 988 template TypeImpl<HeapTypeConfig>::TypeHandle | 961 template TypeImpl<HeapTypeConfig>::TypeHandle |
| 989 TypeImpl<HeapTypeConfig>::Convert<Type>( | 962 TypeImpl<HeapTypeConfig>::Convert<Type>( |
| 990 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 963 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
| 991 | 964 |
| 992 } } // namespace v8::internal | 965 } } // namespace v8::internal |
| OLD | NEW |