@@ -241,8 +241,7 @@ struct FieldTypeInfo {
241
241
struct ProtocolConformanceInfo {
242
242
std::string typeName;
243
243
std::string protocolName;
244
- // TODO:
245
- // std::string mangledTypeName;
244
+ std::string mangledTypeName;
246
245
};
247
246
248
247
// / An implementation of MetadataReader's BuilderType concept for
@@ -833,16 +832,16 @@ class TypeRefBuilder {
833
832
dyn_cast<ExternalModuleContextDescriptor<PointerSize>>(
834
833
parentContextDescriptor)) {
835
834
auto moduleDescriptorName = readModuleNameFromModuleDescriptor (
836
- moduleDescriptor, parentTargetAddress);
835
+ moduleDescriptor, parentTargetAddress);
837
836
if (!moduleDescriptorName.hasValue ())
838
837
return llvm::None;
839
838
else
840
839
optionalParentName = moduleDescriptorName;
841
840
} else if (auto typeDescriptor =
842
841
dyn_cast<ExternalTypeContextDescriptor<PointerSize>>(
843
842
parentContextDescriptor)) {
844
- auto typeDescriptorName = readTypeNameFromTypeDescriptor (typeDescriptor,
845
- parentTargetAddress);
843
+ auto typeDescriptorName = readTypeNameFromTypeDescriptor (
844
+ typeDescriptor, parentTargetAddress);
846
845
if (!typeDescriptorName.hasValue ())
847
846
return llvm::None;
848
847
else
@@ -1020,10 +1019,10 @@ class TypeRefBuilder {
1020
1019
1021
1020
auto optionalTypeName = readTypeNameFromTypeDescriptor (
1022
1021
typeDescriptor, contextTypeDescriptorAddress);
1023
- if (!optionalTypeName.hasValue ())
1024
- return llvm::None;
1025
- else
1026
- typeName = optionalTypeName.getValue ();
1022
+ if (!optionalTypeName.hasValue ())
1023
+ return llvm::None;
1024
+ else
1025
+ typeName = optionalTypeName.getValue ();
1027
1026
1028
1027
// Prepend the parent context name
1029
1028
auto optionalParentName =
@@ -1111,7 +1110,9 @@ class TypeRefBuilder {
1111
1110
1112
1111
// / Given the address of a conformance descriptor, attempt to read it.
1113
1112
llvm::Optional<ProtocolConformanceInfo>
1114
- readConformanceDescriptor (RemoteRef<void > conformanceRecordRef) {
1113
+ readConformanceDescriptor (RemoteRef<void > conformanceRecordRef,
1114
+ const std::unordered_map<std::string, std::string>
1115
+ &typeNameToManglingMap) {
1115
1116
const ExternalProtocolConformanceRecord<PointerSize> *CD =
1116
1117
(const ExternalProtocolConformanceRecord<PointerSize> *)
1117
1118
conformanceRecordRef.getLocalBuffer ();
@@ -1142,39 +1143,68 @@ class TypeRefBuilder {
1142
1143
if (!optionalConformanceProtocol.hasValue ())
1143
1144
return llvm::None;
1144
1145
1146
+ std::string mangledTypeName;
1147
+ auto it =
1148
+ typeNameToManglingMap.find (optionalConformingTypeName.getValue ());
1149
+ if (it != typeNameToManglingMap.end ()) {
1150
+ mangledTypeName = it->second ;
1151
+ } else {
1152
+ mangledTypeName = " " ;
1153
+ }
1154
+
1145
1155
return ProtocolConformanceInfo{optionalConformingTypeName.getValue (),
1146
- optionalConformanceProtocol.getValue ()};
1156
+ optionalConformanceProtocol.getValue (),
1157
+ mangledTypeName};
1147
1158
}
1148
1159
};
1149
1160
1150
1161
public:
1151
1162
template <unsigned PointerSize>
1152
1163
void dumpConformanceSection (std::ostream &stream) {
1164
+ // The Fields section has gathered info on types that includes their mangled
1165
+ // names. Use that to build a dictionary from a type's demangled name to its
1166
+ // mangeled name
1167
+ std::unordered_map<std::string, std::string> typeNameToManglingMap;
1168
+ for (const auto §ion : ReflectionInfos) {
1169
+ for (auto descriptor : section.Field ) {
1170
+ auto TypeRef = readTypeRef (descriptor, descriptor->MangledTypeName );
1171
+ auto OptionalMangledTypeName = normalizeReflectionName (TypeRef);
1172
+ auto TypeName = nodeToString (demangleTypeRef (TypeRef));
1173
+ clearNodeFactory ();
1174
+ if (OptionalMangledTypeName.hasValue ()) {
1175
+ typeNameToManglingMap[TypeName] =
1176
+ " $s" + OptionalMangledTypeName.getValue ();
1177
+ }
1178
+ }
1179
+ }
1180
+
1153
1181
// Collect all conformances and aggregate them per-conforming-type.
1154
1182
std::unordered_map<std::string, std::vector<std::string>> typeConformances;
1155
1183
ProtocolConformanceDescriptorReader<PointerSize> conformanceReader (
1156
1184
OpaqueByteReader, OpaqueStringReader, OpaquePointerReader);
1157
-
1158
1185
for (const auto §ion : ReflectionInfos) {
1159
1186
auto ConformanceBegin = section.Conformance .startAddress ();
1160
1187
auto ConformanceEnd = section.Conformance .endAddress ();
1161
1188
for (auto conformanceAddr = ConformanceBegin;
1162
1189
conformanceAddr != ConformanceEnd;
1163
1190
conformanceAddr = conformanceAddr.atByteOffset (4 )) {
1164
1191
auto optionalConformanceInfo =
1165
- conformanceReader.readConformanceDescriptor (conformanceAddr);
1192
+ conformanceReader.readConformanceDescriptor (conformanceAddr,
1193
+ typeNameToManglingMap);
1166
1194
if (!optionalConformanceInfo.hasValue ()) {
1167
1195
stream << " Error reading conformance descriptor: "
1168
1196
<< conformanceReader.Error << " \n " ;
1169
1197
continue ;
1170
1198
}
1171
1199
auto conformanceInfo = optionalConformanceInfo.getValue ();
1172
- if (typeConformances.count (conformanceInfo.typeName ) != 0 ) {
1173
- typeConformances[conformanceInfo.typeName ].push_back (
1200
+ auto typeConformancesKey = conformanceInfo.mangledTypeName + " (" +
1201
+ conformanceInfo.typeName + " )" ;
1202
+ if (typeConformances.count (typeConformancesKey) != 0 ) {
1203
+ typeConformances[typeConformancesKey].push_back (
1174
1204
conformanceInfo.protocolName );
1175
1205
} else {
1176
1206
typeConformances.emplace (
1177
- conformanceInfo. typeName ,
1207
+ typeConformancesKey ,
1178
1208
std::vector<std::string>{conformanceInfo.protocolName });
1179
1209
}
1180
1210
}
0 commit comments