@@ -999,9 +999,8 @@ class TypeRefBuilder {
999
999
}
1000
1000
1001
1001
// /
1002
- // / Dumping typerefs, field declarations, associated types
1002
+ // / Dumping typerefs, field declarations, builtin types, captures, multi-payload enums
1003
1003
// /
1004
-
1005
1004
void dumpTypeRef (RemoteRef<char > MangledName, std::ostream &stream,
1006
1005
bool printTypeName = false );
1007
1006
FieldTypeCollectionResult collectFieldTypes (llvm::Optional<std::string> forMangledTypeName);
@@ -1012,43 +1011,151 @@ class TypeRefBuilder {
1012
1011
void dumpCaptureSection (std::ostream &stream);
1013
1012
void dumpMultiPayloadEnumSection (std::ostream &stream);
1014
1013
1015
- // /
1016
- // / Extraction of protocol conformances
1017
- // /
1018
-
1019
1014
private:
1020
- // / Reader of protocol descriptors from Images
1015
+ struct ContextNameInfo {
1016
+ std::string name;
1017
+ uintptr_t descriptorAddress;
1018
+ bool isAnonymous;
1019
+
1020
+ ~ContextNameInfo () {}
1021
+ };
1022
+
1021
1023
template <template <typename Runtime> class ObjCInteropKind ,
1022
1024
unsigned PointerSize>
1023
- struct ProtocolConformanceDescriptorReader {
1025
+ struct QualifiedContextNameReader {
1024
1026
std::string Error;
1025
1027
ByteReader OpaqueByteReader;
1026
1028
StringReader OpaqueStringReader;
1027
1029
PointerReader OpaquePointerReader;
1028
1030
DynamicSymbolResolver OpaqueDynamicSymbolResolver;
1029
1031
1030
- ProtocolConformanceDescriptorReader (ByteReader byteReader,
1031
- StringReader stringReader,
1032
- PointerReader pointerReader,
1033
- DynamicSymbolResolver dynamicSymbolResolver)
1032
+ QualifiedContextNameReader (ByteReader byteReader,
1033
+ StringReader stringReader,
1034
+ PointerReader pointerReader,
1035
+ DynamicSymbolResolver dynamicSymbolResolver)
1034
1036
: Error(" " ), OpaqueByteReader(byteReader),
1035
1037
OpaqueStringReader (stringReader),
1036
1038
OpaquePointerReader(pointerReader),
1037
1039
OpaqueDynamicSymbolResolver(dynamicSymbolResolver) {}
1038
1040
1039
- struct ContextNameInfo {
1040
- std::string name;
1041
- uintptr_t descriptorAddress;
1042
- bool isAnonymous;
1041
+ llvm::Optional<std::string> readProtocolNameFromProtocolDescriptor (
1042
+ uintptr_t protocolDescriptorAddress) {
1043
+ std::string protocolName;
1044
+ auto protocolDescriptorBytes = OpaqueByteReader (
1045
+ remote::RemoteAddress (protocolDescriptorAddress),
1046
+ sizeof (ExternalProtocolDescriptor<ObjCInteropKind, PointerSize>));
1047
+ if (!protocolDescriptorBytes.get ()) {
1048
+ Error = " Error reading protocol descriptor." ;
1049
+ return llvm::None;
1050
+ }
1051
+ const ExternalProtocolDescriptor<ObjCInteropKind, PointerSize>
1052
+ *protocolDescriptor =
1053
+ (const ExternalProtocolDescriptor<ObjCInteropKind, PointerSize> *)
1054
+ protocolDescriptorBytes.get ();
1043
1055
1044
- ~ContextNameInfo () {}
1045
- };
1056
+ // Compute the address of the protocol descriptor's name field and read
1057
+ // the offset
1058
+ auto protocolNameOffsetAddress = detail::applyRelativeOffset (
1059
+ (const char *)protocolDescriptorAddress,
1060
+ (int32_t )protocolDescriptor->getNameOffset ());
1061
+ auto protocolNameOffsetBytes = OpaqueByteReader (
1062
+ remote::RemoteAddress (protocolNameOffsetAddress), sizeof (uint32_t ));
1063
+ if (!protocolNameOffsetBytes.get ()) {
1064
+ Error = " Failed to read type name offset in a protocol descriptor." ;
1065
+ return llvm::None;
1066
+ }
1067
+ auto protocolNameOffset = (const uint32_t *)protocolNameOffsetBytes.get ();
1046
1068
1047
- bool isModuleDescriptor (
1048
- const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
1049
- *contextDescriptor) {
1050
- return isa<ExternalModuleContextDescriptor<ObjCInteropKind, PointerSize>>(
1051
- contextDescriptor);
1069
+ // Using the offset above, compute the address of the name field itsel
1070
+ // and read it.
1071
+ auto protocolNameAddress =
1072
+ detail::applyRelativeOffset ((const char *)protocolNameOffsetAddress,
1073
+ (int32_t )*protocolNameOffset);
1074
+ OpaqueStringReader (remote::RemoteAddress (protocolNameAddress),
1075
+ protocolName);
1076
+ return protocolName;
1077
+ }
1078
+
1079
+ llvm::Optional<std::string> readTypeNameFromTypeDescriptor (
1080
+ const ExternalTypeContextDescriptor<ObjCInteropKind, PointerSize>
1081
+ *typeDescriptor,
1082
+ uintptr_t typeDescriptorAddress) {
1083
+ auto typeNameOffsetAddress =
1084
+ detail::applyRelativeOffset ((const char *)typeDescriptorAddress,
1085
+ (int32_t )typeDescriptor->getNameOffset ());
1086
+ auto typeNameOffsetBytes = OpaqueByteReader (
1087
+ remote::RemoteAddress (typeNameOffsetAddress), sizeof (uint32_t ));
1088
+ if (!typeNameOffsetBytes.get ()) {
1089
+ Error = " Failed to read type name offset in a type descriptor." ;
1090
+ return llvm::None;
1091
+ }
1092
+ auto typeNameOffset = (const uint32_t *)typeNameOffsetBytes.get ();
1093
+ auto typeNameAddress = detail::applyRelativeOffset (
1094
+ (const char *)typeNameOffsetAddress, (int32_t )*typeNameOffset);
1095
+ std::string typeName;
1096
+ OpaqueStringReader (remote::RemoteAddress (typeNameAddress), typeName);
1097
+ return typeName;
1098
+ }
1099
+
1100
+ llvm::Optional<std::string> readModuleNameFromModuleDescriptor (
1101
+ const ExternalModuleContextDescriptor<ObjCInteropKind, PointerSize>
1102
+ *moduleDescriptor,
1103
+ uintptr_t moduleDescriptorAddress) {
1104
+ auto parentNameOffsetAddress = detail::applyRelativeOffset (
1105
+ (const char *)moduleDescriptorAddress,
1106
+ (int32_t )moduleDescriptor->getNameOffset ());
1107
+ auto parentNameOffsetBytes = OpaqueByteReader (
1108
+ remote::RemoteAddress (parentNameOffsetAddress), sizeof (uint32_t ));
1109
+ if (!parentNameOffsetBytes.get ()) {
1110
+ Error = " Failed to read parent name offset in a module descriptor." ;
1111
+ return llvm::None;
1112
+ }
1113
+ auto parentNameOffset = (const uint32_t *)parentNameOffsetBytes.get ();
1114
+ auto parentNameAddress = detail::applyRelativeOffset (
1115
+ (const char *)parentNameOffsetAddress, (int32_t )*parentNameOffset);
1116
+ std::string parentName;
1117
+ OpaqueStringReader (remote::RemoteAddress (parentNameAddress), parentName);
1118
+ return parentName;
1119
+ }
1120
+
1121
+ llvm::Optional<std::string> readAnonymousNameFromAnonymousDescriptor (
1122
+ const ExternalAnonymousContextDescriptor<ObjCInteropKind, PointerSize>
1123
+ *anonymousDescriptor,
1124
+ uintptr_t anonymousDescriptorAddress) {
1125
+ if (!anonymousDescriptor->hasMangledName ()) {
1126
+ std::stringstream stream;
1127
+ stream << " (unknown context at $" << std::hex
1128
+ << anonymousDescriptorAddress << " )" ;
1129
+ return stream.str ();
1130
+ }
1131
+ return llvm::None;
1132
+ }
1133
+
1134
+ llvm::Optional<std::string>
1135
+ readFullyQualifiedProtocolNameFromProtocolDescriptor (
1136
+ uintptr_t protocolDescriptorAddress) {
1137
+ llvm::Optional<std::string> protocolName =
1138
+ readProtocolNameFromProtocolDescriptor (protocolDescriptorAddress);
1139
+
1140
+ // Read the protocol conformance descriptor itself
1141
+ auto protocolContextDescriptorBytes = OpaqueByteReader (
1142
+ remote::RemoteAddress (protocolDescriptorAddress),
1143
+ sizeof (ExternalContextDescriptor<ObjCInteropKind, PointerSize>));
1144
+ if (!protocolContextDescriptorBytes.get ()) {
1145
+ // Error = "Failed to read context (protocol) descriptor.";
1146
+ return llvm::None;
1147
+ }
1148
+ const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
1149
+ *protocolDescriptor =
1150
+ (const ExternalContextDescriptor<ObjCInteropKind, PointerSize> *)
1151
+ protocolContextDescriptorBytes.get ();
1152
+
1153
+ std::vector<ContextNameInfo> contextNameChain;
1154
+ contextNameChain.push_back (ContextNameInfo{
1155
+ protocolName.getValue (), protocolDescriptorAddress, false });
1156
+ getParentContextChain (protocolDescriptorAddress, protocolDescriptor,
1157
+ contextNameChain);
1158
+ return constructFullyQualifiedNameFromContextChain (contextNameChain);
1052
1159
}
1053
1160
1054
1161
uintptr_t getParentDescriptorAddress (
@@ -1105,6 +1212,13 @@ class TypeRefBuilder {
1105
1212
}
1106
1213
}
1107
1214
1215
+ bool isModuleDescriptor (
1216
+ const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
1217
+ *contextDescriptor) {
1218
+ return isa<ExternalModuleContextDescriptor<ObjCInteropKind, PointerSize>>(
1219
+ contextDescriptor);
1220
+ }
1221
+
1108
1222
void getParentContextChain (
1109
1223
uintptr_t contextDescriptorAddress,
1110
1224
const ExternalContextDescriptor<ObjCInteropKind, PointerSize>
@@ -1166,61 +1280,6 @@ class TypeRefBuilder {
1166
1280
return ;
1167
1281
}
1168
1282
1169
- llvm::Optional<std::string> readTypeNameFromTypeDescriptor (
1170
- const ExternalTypeContextDescriptor<ObjCInteropKind, PointerSize>
1171
- *typeDescriptor,
1172
- uintptr_t typeDescriptorAddress) {
1173
- auto typeNameOffsetAddress =
1174
- detail::applyRelativeOffset ((const char *)typeDescriptorAddress,
1175
- (int32_t )typeDescriptor->getNameOffset ());
1176
- auto typeNameOffsetBytes = OpaqueByteReader (
1177
- remote::RemoteAddress (typeNameOffsetAddress), sizeof (uint32_t ));
1178
- if (!typeNameOffsetBytes.get ()) {
1179
- Error = " Failed to read type name offset in a type descriptor." ;
1180
- return llvm::None;
1181
- }
1182
- auto typeNameOffset = (const uint32_t *)typeNameOffsetBytes.get ();
1183
- auto typeNameAddress = detail::applyRelativeOffset (
1184
- (const char *)typeNameOffsetAddress, (int32_t )*typeNameOffset);
1185
- std::string typeName;
1186
- OpaqueStringReader (remote::RemoteAddress (typeNameAddress), typeName);
1187
- return typeName;
1188
- }
1189
-
1190
- llvm::Optional<std::string> readModuleNameFromModuleDescriptor (
1191
- const ExternalModuleContextDescriptor<ObjCInteropKind, PointerSize>
1192
- *moduleDescriptor,
1193
- uintptr_t moduleDescriptorAddress) {
1194
- auto parentNameOffsetAddress = detail::applyRelativeOffset (
1195
- (const char *)moduleDescriptorAddress,
1196
- (int32_t )moduleDescriptor->getNameOffset ());
1197
- auto parentNameOffsetBytes = OpaqueByteReader (
1198
- remote::RemoteAddress (parentNameOffsetAddress), sizeof (uint32_t ));
1199
- if (!parentNameOffsetBytes.get ()) {
1200
- Error = " Failed to read parent name offset in a module descriptor." ;
1201
- return llvm::None;
1202
- }
1203
- auto parentNameOffset = (const uint32_t *)parentNameOffsetBytes.get ();
1204
- auto parentNameAddress = detail::applyRelativeOffset (
1205
- (const char *)parentNameOffsetAddress, (int32_t )*parentNameOffset);
1206
- std::string parentName;
1207
- OpaqueStringReader (remote::RemoteAddress (parentNameAddress), parentName);
1208
- return parentName;
1209
- }
1210
-
1211
- llvm::Optional<std::string> readAnonymousNameFromAnonymousDescriptor (
1212
- const ExternalAnonymousContextDescriptor<ObjCInteropKind, PointerSize>
1213
- *anonymousDescriptor,
1214
- uintptr_t anonymousDescriptorAddress) {
1215
- if (!anonymousDescriptor->hasMangledName ()) {
1216
- std::stringstream stream;
1217
- stream << " (unknown context at $" << std::hex
1218
- << anonymousDescriptorAddress << " )" ;
1219
- return stream.str ();
1220
- }
1221
- return llvm::None;
1222
- }
1223
-
1224
1283
std::string constructFullyQualifiedNameFromContextChain (
1225
1284
const std::vector<ContextNameInfo> &contextNameChain) {
1226
1285
std::string newQualifiedTypeName = " " ;
@@ -1271,44 +1330,30 @@ class TypeRefBuilder {
1271
1330
1272
1331
return newQualifiedTypeName;
1273
1332
}
1333
+ };
1274
1334
1275
- llvm::Optional<std::string> readProtocolNameFromProtocolDescriptor (
1276
- uintptr_t protocolDescriptorAddress) {
1277
- std::string protocolName;
1278
- auto protocolDescriptorBytes = OpaqueByteReader (
1279
- remote::RemoteAddress (protocolDescriptorAddress),
1280
- sizeof (ExternalProtocolDescriptor<ObjCInteropKind, PointerSize>));
1281
- if (!protocolDescriptorBytes.get ()) {
1282
- Error = " Error reading protocol descriptor." ;
1283
- return llvm::None;
1284
- }
1285
- const ExternalProtocolDescriptor<ObjCInteropKind, PointerSize>
1286
- *protocolDescriptor =
1287
- (const ExternalProtocolDescriptor<ObjCInteropKind, PointerSize> *)
1288
- protocolDescriptorBytes.get ();
1289
-
1290
- // Compute the address of the protocol descriptor's name field and read
1291
- // the offset
1292
- auto protocolNameOffsetAddress = detail::applyRelativeOffset (
1293
- (const char *)protocolDescriptorAddress,
1294
- (int32_t )protocolDescriptor->getNameOffset ());
1295
- auto protocolNameOffsetBytes = OpaqueByteReader (
1296
- remote::RemoteAddress (protocolNameOffsetAddress), sizeof (uint32_t ));
1297
- if (!protocolNameOffsetBytes.get ()) {
1298
- Error = " Failed to read type name offset in a protocol descriptor." ;
1299
- return llvm::None;
1300
- }
1301
- auto protocolNameOffset = (const uint32_t *)protocolNameOffsetBytes.get ();
1335
+ // /
1336
+ // / Extraction of protocol conformances
1337
+ // /
1338
+ private:
1339
+ // / Reader of protocol descriptors from Images
1340
+ template <template <typename Runtime> class ObjCInteropKind ,
1341
+ unsigned PointerSize>
1342
+ struct ProtocolConformanceDescriptorReader {
1343
+ std::string Error;
1344
+ PointerReader OpaquePointerReader;
1345
+ ByteReader OpaqueByteReader;
1346
+ DynamicSymbolResolver OpaqueDynamicSymbolResolver;
1347
+ QualifiedContextNameReader<ObjCInteropKind, PointerSize> NameReader;
1302
1348
1303
- // Using the offset above, compute the address of the name field itsel
1304
- // and read it.
1305
- auto protocolNameAddress =
1306
- detail::applyRelativeOffset ((const char *)protocolNameOffsetAddress,
1307
- (int32_t )*protocolNameOffset);
1308
- OpaqueStringReader (remote::RemoteAddress (protocolNameAddress),
1309
- protocolName);
1310
- return protocolName;
1311
- }
1349
+ ProtocolConformanceDescriptorReader (ByteReader byteReader,
1350
+ StringReader stringReader,
1351
+ PointerReader pointerReader,
1352
+ DynamicSymbolResolver dynamicSymbolResolver)
1353
+ : Error(" " ),
1354
+ OpaquePointerReader (pointerReader), OpaqueByteReader(byteReader),
1355
+ OpaqueDynamicSymbolResolver(dynamicSymbolResolver),
1356
+ NameReader(byteReader, stringReader, pointerReader, dynamicSymbolResolver) {}
1312
1357
1313
1358
// / Extract conforming type's name from a Conformance Descriptor
1314
1359
// / Returns a pair of (mangledTypeName, fullyQualifiedTypeName)
@@ -1389,7 +1434,7 @@ class TypeRefBuilder {
1389
1434
return llvm::None;
1390
1435
}
1391
1436
1392
- auto optionalTypeName = readTypeNameFromTypeDescriptor (
1437
+ auto optionalTypeName = NameReader. readTypeNameFromTypeDescriptor (
1393
1438
typeDescriptor, contextTypeDescriptorAddress);
1394
1439
if (!optionalTypeName.hasValue ())
1395
1440
return llvm::None;
@@ -1399,10 +1444,10 @@ class TypeRefBuilder {
1399
1444
std::vector<ContextNameInfo> contextNameChain;
1400
1445
contextNameChain.push_back (
1401
1446
ContextNameInfo{typeName, contextTypeDescriptorAddress, false });
1402
- getParentContextChain (contextTypeDescriptorAddress, contextDescriptor,
1447
+ NameReader. getParentContextChain (contextTypeDescriptorAddress, contextDescriptor,
1403
1448
contextNameChain);
1404
1449
std::string fullyQualifiedName =
1405
- constructFullyQualifiedNameFromContextChain (contextNameChain);
1450
+ NameReader. constructFullyQualifiedNameFromContextChain (contextNameChain);
1406
1451
return std::make_pair (mangledTypeName, fullyQualifiedName);
1407
1452
}
1408
1453
@@ -1435,7 +1480,7 @@ class TypeRefBuilder {
1435
1480
[&](uintptr_t protocolDescriptorAddress)
1436
1481
-> llvm::Optional<std::string> {
1437
1482
auto protocolName =
1438
- readProtocolNameFromProtocolDescriptor (protocolDescriptorAddress);
1483
+ NameReader. readProtocolNameFromProtocolDescriptor (protocolDescriptorAddress);
1439
1484
1440
1485
// Read the protocol conformance descriptor itself
1441
1486
auto protocolContextDescriptorBytes = OpaqueByteReader (
@@ -1453,9 +1498,9 @@ class TypeRefBuilder {
1453
1498
std::vector<ContextNameInfo> contextNameChain;
1454
1499
contextNameChain.push_back (ContextNameInfo{
1455
1500
protocolName.getValue (), protocolDescriptorAddress, false });
1456
- getParentContextChain (protocolDescriptorAddress, protocolDescriptor,
1501
+ NameReader. getParentContextChain (protocolDescriptorAddress, protocolDescriptor,
1457
1502
contextNameChain);
1458
- return constructFullyQualifiedNameFromContextChain (contextNameChain);
1503
+ return NameReader. constructFullyQualifiedNameFromContextChain (contextNameChain);
1459
1504
};
1460
1505
1461
1506
// Set low bit indicates that this is an indirect
0 commit comments