Encode Class, SEL and Objective-C objects.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43540 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index 93ec288..ec7cd7b 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -152,6 +152,9 @@
BuiltinVaListType = QualType();
ObjcIdType = QualType();
IdStructType = 0;
+ ObjcClassType = QualType();
+ ClassStructType = 0;
+
ObjcConstantStringType = QualType();
// void * type
@@ -1008,9 +1011,15 @@
S += encoding;
} else if (const PointerType *PT = T->getAsPointerType()) {
QualType PointeeTy = PT->getPointeeType();
- if (isObjcIdType(PointeeTy)) {
+ if (isObjcIdType(PointeeTy) || PointeeTy->isObjcInterfaceType()) {
S += '@';
return;
+ } else if (isObjcClassType(PointeeTy)) {
+ S += '#';
+ return;
+ } else if (isObjcSelType(PointeeTy)) {
+ S += ':';
+ return;
}
if (PointeeTy->isCharType()) {
@@ -1086,6 +1095,20 @@
ProtoStructType = TD->getUnderlyingType()->getAsStructureType();
}
+void ASTContext::setObjcClassType(TypedefDecl *TD)
+{
+ assert(ObjcClassType.isNull() && "'Class' type already set!");
+
+ ObjcClassType = getTypedefType(TD);
+
+ // typedef struct objc_class *Class;
+ const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType();
+ assert(ptr && "'Class' incorrectly typed");
+ const RecordType *rec = ptr->getPointeeType()->getAsStructureType();
+ assert(rec && "'Class' incorrectly typed");
+ ClassStructType = rec;
+}
+
void ASTContext::setObjcConstantStringInterface(ObjcInterfaceDecl *Decl) {
assert(ObjcConstantStringType.isNull() &&
"'NSConstantString' type already set!");