Patch to create protocol conforming class types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42856 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index 6608330..a6c2bc6 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -610,6 +610,31 @@
return QualType(Decl->TypeForDecl, 0);
}
+/// getObjcQualifiedInterfaceType - Return a
+/// ObjcQualifiedInterfaceType type for the given interface decl and
+/// the conforming protocol list.
+QualType ASTContext::getObjcQualifiedInterfaceType(ObjcInterfaceDecl *Decl,
+ ObjcProtocolDecl **Protocols, unsigned NumProtocols) {
+ ObjcInterfaceType *IType =
+ cast<ObjcInterfaceType>(getObjcInterfaceType(Decl));
+
+ llvm::FoldingSetNodeID ID;
+ ObjcQualifiedInterfaceType::Profile(ID, IType, Protocols, NumProtocols);
+
+ void *InsertPos = 0;
+ if (ObjcQualifiedInterfaceType *QT =
+ ObjcQualifiedInterfaceTypes.FindNodeOrInsertPos(ID, InsertPos))
+ return QualType(QT, 0);
+
+ // No Match;
+ ObjcQualifiedInterfaceType *QType = new ObjcQualifiedInterfaceType(IType);
+ for (unsigned i = 0; i != NumProtocols; i++)
+ QType->setProtocols(Protocols[i]);
+ Types.push_back(QType);
+ ObjcQualifiedInterfaceTypes.InsertNode(QType, InsertPos);
+ return QualType(QType, 0);
+}
+
/// getTypeOfExpr - Unlike many "get<Type>" functions, we can't unique
/// TypeOfExpr AST's (since expression's are never shared). For example,
/// multiple declarations that refer to "typeof(x)" all contain different
diff --git a/AST/Type.cpp b/AST/Type.cpp
index de840cf..7deee66 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -618,6 +618,19 @@
Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic());
}
+void ObjcQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
+ ObjcInterfaceType *interfaceType,
+ ObjcProtocolDecl **protocols,
+ unsigned NumProtocols) {
+ ID.AddPointer(interfaceType);
+ for (unsigned i = 0; i != NumProtocols; i++)
+ ID.AddPointer(protocols[i]);
+}
+
+void ObjcQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
+ Profile(ID, getInterfaceType(), &Protocols[0], getNumProtocols());
+}
+
/// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
/// potentially looking through *all* consequtive typedefs. This returns the
/// sum of the type qualifiers, so if you have:
@@ -843,6 +856,18 @@
InnerString = getDecl()->getIdentifier()->getName() + InnerString;
}
+void ObjcQualifiedInterfaceType::getAsStringInternal(
+ std::string &InnerString) const {
+ InnerString = getInterfaceType()->getDecl()->getName() + '<';
+ int num = getNumProtocols();
+ for (int i = 0; i < num; i++) {
+ InnerString += getProtocols(i)->getName();
+ if (i < num-1)
+ InnerString += ',';
+ }
+ InnerString += '>';
+}
+
void TagType::getAsStringInternal(std::string &InnerString) const {
if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'.
InnerString = ' ' + InnerString;