const TypeRef * TypeRefBuilder:: lookupTypeWitness(const std::string &MangledTypeName, const std::string &Member, const StringRef Protocol) { TypeRefID key; key.addString(MangledTypeName); key.addString(Member); key.addString(Protocol); auto found = AssociatedTypeCache.find(key); if (found != AssociatedTypeCache.end()) return found->second; // Cache missed - we need to look through all of the assocty sections // for all images that we've been notified about. for (auto &Info : ReflectionInfos) { uint64_t TypeRefOffset = Info.AssociatedType.SectionOffset - Info.TypeReference.SectionOffset; uint64_t NameOffset = Info.AssociatedType.SectionOffset - Info.ReflectionString.SectionOffset; for (const auto &AssocTyDescriptor : Info.AssociatedType.Metadata) { if (!reflectionNameMatches(Dem, AssocTyDescriptor.getMangledConformingTypeName(TypeRefOffset), MangledTypeName)) continue; if (!reflectionNameMatches(Dem, AssocTyDescriptor.getMangledProtocolTypeName(TypeRefOffset), Protocol)) continue; for (auto &AssocTy : AssocTyDescriptor) { if (Member.compare(AssocTy.getName(NameOffset)) != 0) continue; auto SubstitutedTypeName = AssocTy.getMangledSubstitutedTypeName(TypeRefOffset); auto Demangled = Dem.demangleType(SubstitutedTypeName); auto *TypeWitness = swift::Demangle::decodeMangledType(*this, Demangled); AssociatedTypeCache.insert(std::make_pair(key, TypeWitness)); return TypeWitness; } } } return nullptr; }
const TypeRef * TypeRefBuilder:: lookupTypeWitness(const std::string &MangledTypeName, const std::string &Member, const TypeRef *Protocol) { TypeRefID key; key.addString(MangledTypeName); key.addString(Member); key.addPointer(Protocol); auto found = AssociatedTypeCache.find(key); if (found != AssociatedTypeCache.end()) return found->second; // Cache missed - we need to look through all of the assocty sections // for all images that we've been notified about. for (auto &Info : ReflectionInfos) { for (const auto &AssocTyDescriptor : Info.assocty) { std::string ConformingTypeName(AssocTyDescriptor.ConformingTypeName); if (ConformingTypeName.compare(MangledTypeName) != 0) continue; std::string ProtocolMangledName(AssocTyDescriptor.ProtocolTypeName); Demangle::Demangler Dem; auto DemangledProto = Dem.demangleType(ProtocolMangledName); auto TR = swift::remote::decodeMangledType(*this, DemangledProto); if (Protocol != TR) continue; for (auto &AssocTy : AssocTyDescriptor) { if (Member.compare(AssocTy.getName()) != 0) continue; auto SubstitutedTypeName = AssocTy.getMangledSubstitutedTypeName(); auto Demangled = Dem.demangleType(SubstitutedTypeName); auto *TypeWitness = swift::remote::decodeMangledType(*this, Demangled); AssociatedTypeCache.insert(std::make_pair(key, TypeWitness)); return TypeWitness; } } } return nullptr; }