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