Reflection: ProtocolTypeRefs now store a mangled name

This is better for field metadata lookups. Clients that want the
module name and decl name can demangle, just like they do with
NominalTypeRefs.
This commit is contained in:
Slava Pestov
2016-04-25 14:56:50 -07:00
parent 00e0c89b30
commit c0c02a3148
6 changed files with 50 additions and 35 deletions

View File

@@ -222,27 +222,20 @@ public:
};
class ProtocolTypeRef final : public TypeRef {
std::string ModuleName;
std::string Name;
std::string MangledName;
public:
ProtocolTypeRef(const std::string &ModuleName,
const std::string &Name)
: TypeRef(TypeRefKind::Protocol), ModuleName(ModuleName), Name(Name) {}
ProtocolTypeRef(const std::string &MangledName)
: TypeRef(TypeRefKind::Protocol), MangledName(MangledName) {}
template <typename Allocator>
static const ProtocolTypeRef *
create(Allocator &A, const std::string &ModuleName,
const std::string &Name) {
return A.template makeTypeRef<ProtocolTypeRef>(ModuleName, Name);
create(Allocator &A, const std::string &MangledName) {
return A.template makeTypeRef<ProtocolTypeRef>(MangledName);
}
const std::string &getName() const {
return Name;
}
const std::string &getModuleName() const {
return ModuleName;
const std::string &getMangledName() const {
return MangledName;
}
static bool classof(const TypeRef *TR) {
@@ -250,8 +243,7 @@ public:
}
bool operator==(const ProtocolTypeRef &Other) const {
return ModuleName.compare(Other.ModuleName) == 0 &&
Name.compare(Other.Name) == 0;
return MangledName == Other.MangledName;
}
bool operator!=(const ProtocolTypeRef &Other) const {
return !(*this == Other);

View File

@@ -151,9 +151,10 @@ public:
return FunctionTypeRef::create(*this, args, result, flags);
}
const ProtocolTypeRef *createProtocolType(const std::string &moduleName,
const std::string &protocolName) {
return ProtocolTypeRef::create(*this, moduleName, protocolName);
const ProtocolTypeRef *createProtocolType(const std::string &mangledName,
const std::string &moduleName,
const std::string &name) {
return ProtocolTypeRef::create(*this, mangledName);
}
const ProtocolCompositionTypeRef *