@@ -772,7 +772,8 @@ class TypeRefBuilder {
772
772
773
773
private:
774
774
// / Reader of protocol descriptors from Images
775
- template <unsigned PointerSize>
775
+ template <template <typename Runtime> class ObjCInteropKind ,
776
+ unsigned PointerSize>
776
777
struct ProtocolConformanceDescriptorReader {
777
778
std::string Error;
778
779
ByteReader OpaqueByteReader;
@@ -789,16 +790,17 @@ class TypeRefBuilder {
789
790
llvm::Optional<std::string>
790
791
getParentContextName (uintptr_t contextDescriptorAddress) {
791
792
llvm::Optional<std::string> optionalParentContextName;
792
- auto contextTypeDescriptorBytes =
793
- OpaqueByteReader ( remote::RemoteAddress (contextDescriptorAddress),
794
- sizeof (ExternalContextDescriptor<PointerSize>));
793
+ auto contextTypeDescriptorBytes = OpaqueByteReader (
794
+ remote::RemoteAddress (contextDescriptorAddress),
795
+ sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
795
796
if (!contextTypeDescriptorBytes.get ()) {
796
797
Error = " Failed to read context descriptor." ;
797
798
return llvm::None;
798
799
}
799
- const ExternalContextDescriptor<PointerSize> *contextDescriptor =
800
- (const ExternalContextDescriptor<PointerSize> *)
801
- contextTypeDescriptorBytes.get ();
800
+ const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
801
+ *contextDescriptor =
802
+ (const ExternalContextDescriptor<ObjCInteropKind, PointerSize> *)
803
+ contextTypeDescriptorBytes.get ();
802
804
803
805
auto parentOffsetAddress = detail::applyRelativeOffset (
804
806
(const char *)contextDescriptorAddress,
@@ -817,28 +819,30 @@ class TypeRefBuilder {
817
819
auto readContextParentName =
818
820
[&](uintptr_t descriptorAddress) -> llvm::Optional<std::string> {
819
821
llvm::Optional<std::string> optionalParentName;
820
- auto parentContextDescriptorBytes =
821
- OpaqueByteReader ( remote::RemoteAddress (descriptorAddress),
822
- sizeof (ExternalContextDescriptor<PointerSize>));
822
+ auto parentContextDescriptorBytes = OpaqueByteReader (
823
+ remote::RemoteAddress (descriptorAddress),
824
+ sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
823
825
if (!parentContextDescriptorBytes.get ()) {
824
826
Error = " Failed to read context descriptor." ;
825
827
return llvm::None;
826
828
}
827
- const ExternalContextDescriptor<PointerSize> *parentContextDescriptor =
828
- (const ExternalContextDescriptor<PointerSize> *)
829
+ const ExternalContextDescriptor<ObjCInteropKind,
830
+ PointerSize> *parentContextDescriptor =
831
+ (const ExternalContextDescriptor<ObjCInteropKind, PointerSize> *)
829
832
parentContextDescriptorBytes.get ();
830
833
831
- if (auto moduleDescriptor =
832
- dyn_cast< ExternalModuleContextDescriptor<PointerSize>>(
833
- parentContextDescriptor)) {
834
+ if (auto moduleDescriptor = dyn_cast<
835
+ ExternalModuleContextDescriptor<ObjCInteropKind, PointerSize>>(
836
+ parentContextDescriptor)) {
834
837
auto moduleDescriptorName = readModuleNameFromModuleDescriptor (
835
838
moduleDescriptor, parentTargetAddress);
836
839
if (!moduleDescriptorName.hasValue ())
837
840
return llvm::None;
838
841
else
839
842
optionalParentName = moduleDescriptorName;
840
843
} else if (auto typeDescriptor =
841
- dyn_cast<ExternalTypeContextDescriptor<PointerSize>>(
844
+ dyn_cast<ExternalTypeContextDescriptor<ObjCInteropKind,
845
+ PointerSize>>(
842
846
parentContextDescriptor)) {
843
847
auto typeDescriptorName = readTypeNameFromTypeDescriptor (
844
848
typeDescriptor, parentTargetAddress);
@@ -890,7 +894,8 @@ class TypeRefBuilder {
890
894
}
891
895
892
896
llvm::Optional<std::string> readTypeNameFromTypeDescriptor (
893
- const ExternalTypeContextDescriptor<PointerSize> *typeDescriptor,
897
+ const ExternalTypeContextDescriptor<ObjCInteropKind, PointerSize>
898
+ *typeDescriptor,
894
899
uintptr_t typeDescriptorAddress) {
895
900
auto typeNameOffsetAddress =
896
901
detail::applyRelativeOffset ((const char *)typeDescriptorAddress,
@@ -910,7 +915,8 @@ class TypeRefBuilder {
910
915
}
911
916
912
917
llvm::Optional<std::string> readModuleNameFromModuleDescriptor (
913
- const ExternalModuleContextDescriptor<PointerSize> *moduleDescriptor,
918
+ const ExternalModuleContextDescriptor<ObjCInteropKind, PointerSize>
919
+ *moduleDescriptor,
914
920
uintptr_t moduleDescriptorAddress) {
915
921
auto parentNameOffsetAddress = detail::applyRelativeOffset (
916
922
(const char *)moduleDescriptorAddress,
@@ -932,16 +938,17 @@ class TypeRefBuilder {
932
938
llvm::Optional<std::string> readProtocolNameFromProtocolDescriptor (
933
939
uintptr_t protocolDescriptorAddress) {
934
940
std::string protocolName;
935
- auto protocolDescriptorBytes =
936
- OpaqueByteReader ( remote::RemoteAddress (protocolDescriptorAddress),
937
- sizeof (ExternalProtocolDescriptor<PointerSize>));
941
+ auto protocolDescriptorBytes = OpaqueByteReader (
942
+ remote::RemoteAddress (protocolDescriptorAddress),
943
+ sizeof (ExternalProtocolDescriptor<ObjCInteropKind, PointerSize>));
938
944
if (!protocolDescriptorBytes.get ()) {
939
945
Error = " Error reading protocol descriptor." ;
940
946
return llvm::None;
941
947
}
942
- const ExternalProtocolDescriptor<PointerSize> *protocolDescriptor =
943
- (const ExternalProtocolDescriptor<PointerSize> *)
944
- protocolDescriptorBytes.get ();
948
+ const ExternalProtocolDescriptor<ObjCInteropKind, PointerSize>
949
+ *protocolDescriptor =
950
+ (const ExternalProtocolDescriptor<ObjCInteropKind, PointerSize> *)
951
+ protocolDescriptorBytes.get ();
945
952
946
953
// Compute the address of the protocol descriptor's name field and read
947
954
// the offset
@@ -969,8 +976,8 @@ class TypeRefBuilder {
969
976
// / Extract conforming type's name from a Conformance Descriptor
970
977
llvm::Optional<std::string> getConformingTypeName (
971
978
const uintptr_t conformanceDescriptorAddress,
972
- const ExternalProtocolConformanceDescriptor<PointerSize>
973
- &conformanceDescriptor) {
979
+ const ExternalProtocolConformanceDescriptor<
980
+ ObjCInteropKind, PointerSize> &conformanceDescriptor) {
974
981
std::string typeName;
975
982
// Compute the address of the type descriptor as follows:
976
983
// - Compute the address of the TypeRef field in the protocol
@@ -998,19 +1005,20 @@ class TypeRefBuilder {
998
1005
(const char *)contextDescriptorFieldAddress,
999
1006
(int32_t )*contextDescriptorOffset);
1000
1007
1001
- auto contextTypeDescriptorBytes =
1002
- OpaqueByteReader ( remote::RemoteAddress (contextTypeDescriptorAddress),
1003
- sizeof (ExternalContextDescriptor<PointerSize>));
1008
+ auto contextTypeDescriptorBytes = OpaqueByteReader (
1009
+ remote::RemoteAddress (contextTypeDescriptorAddress),
1010
+ sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
1004
1011
if (!contextTypeDescriptorBytes.get ()) {
1005
1012
Error = " Failed to read context descriptor." ;
1006
1013
return llvm::None;
1007
1014
}
1008
- const ExternalContextDescriptor<PointerSize> *contextDescriptor =
1009
- (const ExternalContextDescriptor<PointerSize> *)
1010
- contextTypeDescriptorBytes.get ();
1015
+ const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
1016
+ *contextDescriptor =
1017
+ (const ExternalContextDescriptor<ObjCInteropKind, PointerSize> *)
1018
+ contextTypeDescriptorBytes.get ();
1011
1019
1012
1020
auto typeDescriptor =
1013
- dyn_cast<ExternalTypeContextDescriptor<PointerSize>>(
1021
+ dyn_cast<ExternalTypeContextDescriptor<ObjCInteropKind, PointerSize>>(
1014
1022
contextDescriptor);
1015
1023
if (!typeDescriptor) {
1016
1024
Error = " Unexpected type of context descriptor." ;
@@ -1037,8 +1045,8 @@ class TypeRefBuilder {
1037
1045
// / Extract protocol name from a Conformance Descriptor
1038
1046
llvm::Optional<std::string> getConformanceProtocolName (
1039
1047
const uintptr_t conformanceDescriptorAddress,
1040
- const ExternalProtocolConformanceDescriptor<PointerSize>
1041
- &conformanceDescriptor) {
1048
+ const ExternalProtocolConformanceDescriptor<
1049
+ ObjCInteropKind, PointerSize> &conformanceDescriptor) {
1042
1050
llvm::Optional<std::string> protocolName;
1043
1051
auto protocolDescriptorFieldAddress = detail::applyRelativeOffset (
1044
1052
(const char *)conformanceDescriptorAddress,
@@ -1113,25 +1121,27 @@ class TypeRefBuilder {
1113
1121
readConformanceDescriptor (RemoteRef<void > conformanceRecordRef,
1114
1122
const std::unordered_map<std::string, std::string>
1115
1123
&typeNameToManglingMap) {
1116
- const ExternalProtocolConformanceRecord<PointerSize> *CD =
1117
- (const ExternalProtocolConformanceRecord<PointerSize> *)
1118
- conformanceRecordRef.getLocalBuffer ();
1124
+ const ExternalProtocolConformanceRecord<ObjCInteropKind,
1125
+ PointerSize> *CD =
1126
+ (const ExternalProtocolConformanceRecord<ObjCInteropKind, PointerSize>
1127
+ *)conformanceRecordRef.getLocalBuffer ();
1119
1128
// Read the Protocol Conformance Descriptor by getting its address from
1120
1129
// the conformance record.
1121
1130
auto conformanceDescriptorAddress = (uintptr_t )CD->getRelative (
1122
1131
(void *)conformanceRecordRef.getAddressData ());
1123
1132
1124
1133
auto descriptorBytes = OpaqueByteReader (
1125
1134
remote::RemoteAddress (conformanceDescriptorAddress),
1126
- sizeof (ExternalProtocolConformanceDescriptor<PointerSize>));
1135
+ sizeof (ExternalProtocolConformanceDescriptor<ObjCInteropKind,
1136
+ PointerSize>));
1127
1137
if (!descriptorBytes.get ()) {
1128
1138
Error = " Failed to read protocol conformance descriptor." ;
1129
1139
return llvm::None;
1130
1140
}
1131
- const ExternalProtocolConformanceDescriptor<PointerSize>
1141
+ const ExternalProtocolConformanceDescriptor<ObjCInteropKind, PointerSize>
1132
1142
*conformanceDescriptorPtr =
1133
- (const ExternalProtocolConformanceDescriptor<PointerSize> *)
1134
- descriptorBytes.get ();
1143
+ (const ExternalProtocolConformanceDescriptor<
1144
+ ObjCInteropKind, PointerSize> *) descriptorBytes.get ();
1135
1145
1136
1146
auto optionalConformingTypeName = getConformingTypeName (
1137
1147
conformanceDescriptorAddress, *conformanceDescriptorPtr);
@@ -1159,7 +1169,8 @@ class TypeRefBuilder {
1159
1169
};
1160
1170
1161
1171
public:
1162
- template <unsigned PointerSize>
1172
+ template <template <typename Runtime> class ObjCInteropKind ,
1173
+ unsigned PointerSize>
1163
1174
void dumpConformanceSection (std::ostream &stream) {
1164
1175
// The Fields section has gathered info on types that includes their mangled
1165
1176
// names. Use that to build a dictionary from a type's demangled name to its
@@ -1180,8 +1191,9 @@ class TypeRefBuilder {
1180
1191
1181
1192
// Collect all conformances and aggregate them per-conforming-type.
1182
1193
std::unordered_map<std::string, std::vector<std::string>> typeConformances;
1183
- ProtocolConformanceDescriptorReader<PointerSize> conformanceReader (
1184
- OpaqueByteReader, OpaqueStringReader, OpaquePointerReader);
1194
+ ProtocolConformanceDescriptorReader<ObjCInteropKind, PointerSize>
1195
+ conformanceReader (OpaqueByteReader, OpaqueStringReader,
1196
+ OpaquePointerReader);
1185
1197
for (const auto §ion : ReflectionInfos) {
1186
1198
auto ConformanceBegin = section.Conformance .startAddress ();
1187
1199
auto ConformanceEnd = section.Conformance .endAddress ();
@@ -1224,7 +1236,8 @@ class TypeRefBuilder {
1224
1236
}
1225
1237
}
1226
1238
1227
- template <unsigned PointerSize>
1239
+ template <template <typename Runtime> class ObjCInteropKind ,
1240
+ unsigned PointerSize>
1228
1241
void dumpAllSections (std::ostream &stream) {
1229
1242
stream << " FIELDS:\n " ;
1230
1243
stream << " =======\n " ;
@@ -1244,7 +1257,7 @@ class TypeRefBuilder {
1244
1257
stream << " \n " ;
1245
1258
stream << " CONFORMANCES:\n " ;
1246
1259
stream << " =============\n " ;
1247
- dumpConformanceSection<PointerSize>(stream);
1260
+ dumpConformanceSection<ObjCInteropKind, PointerSize>(stream);
1248
1261
stream << " \n " ;
1249
1262
}
1250
1263
};
0 commit comments