- Add rewrite rule for @class.
- Add setter/getter to ObjcClassDecl.
- Predefined key runtime functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43257 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index cf812a2..7cf1342 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -44,7 +44,8 @@
void RewriteFunctionBody(Stmt *S);
void RewriteAtEncode(ObjCEncodeExpr *Exp);
-
+ void RewriteForwardClassDecl(ObjcClassDecl *Dcl);
+
void WriteObjcClassMetaData(ObjcImplementationDecl *IDecl);
void WriteObjcMetaData();
@@ -105,6 +106,8 @@
ClassImplementation.push_back(CI);
else if (ObjcCategoryImplDecl *CI = dyn_cast<ObjcCategoryImplDecl>(D))
CategoryImplementation.push_back(CI);
+ else if (ObjcClassDecl *CD = dyn_cast<ObjcClassDecl>(D))
+ RewriteForwardClassDecl(CD);
// Nothing yet.
}
@@ -130,6 +133,37 @@
delete Replacement;
}
+void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl *ClassDecl) {
+ int numDecls = ClassDecl->getNumForwardDecls();
+ ObjcInterfaceDecl **ForwardDecls = ClassDecl->getForwardDecls();
+
+ // Get the start location and compute the semi location.
+ SourceLocation startLoc = ClassDecl->getLocation();
+ const char *startBuf = SM->getCharacterData(startLoc);
+ const char *semiPtr = startBuf;
+ while (semiPtr && (*semiPtr != ';')) semiPtr++;
+
+ // Translate to typedef's that forward reference structs with the same name
+ // as the class. As a convenience, we include the original declaration
+ // as a comment.
+ std::string typedefString;
+ typedefString += "// ";
+ typedefString.append(startBuf, semiPtr-startBuf+1);
+ typedefString += "\n";
+ for (int i = 0; i < numDecls; i++) {
+ ObjcInterfaceDecl *ForwardDecl = ForwardDecls[i];
+ typedefString += "typedef struct ";
+ typedefString += ForwardDecl->getName();
+ typedefString += " ";
+ typedefString += ForwardDecl->getName();
+ typedefString += ";\n";
+ }
+
+ // Replace the @class with typedefs corresponding to the classes.
+ Rewrite.ReplaceText(startLoc, semiPtr-startBuf+1,
+ typedefString.c_str(), typedefString.size());
+}
+
void RewriteTest::WriteObjcClassMetaData(ObjcImplementationDecl *IDecl) {
ObjcInterfaceDecl *CDecl = IDecl->getClassInterface();
diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp
index c1f14a9..6380544 100644
--- a/Lex/Preprocessor.cpp
+++ b/Lex/Preprocessor.cpp
@@ -392,6 +392,23 @@
DefineBuiltinMacro(Buf, "NO=(BOOL)0");
DefineBuiltinMacro(Buf, "Nil=0");
DefineBuiltinMacro(Buf, "nil=0");
+ ObjcType = "OBJC_EXPORT const char *sel_getName(SEL sel);\n";
+ Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
+ ObjcType = "OBJC_EXPORT SEL sel_getUid(const char *str);\n";
+ Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
+
+ // Predefine ObjC primitive functions, traditionally declared in
+ // <objc/objc-runtime.h>. Unlike the declarations above, we don't protect
+ // these with a header guard (since multiple identical function declarations
+ // don't result in an error.
+ ObjcType = "OBJC_EXPORT id objc_getClass(const char *name);\n";
+ Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
+ ObjcType = "OBJC_EXPORT id objc_getMetaClass(const char *name);\n";
+ Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
+ ObjcType = "OBJC_EXPORT id objc_msgSend(id self, SEL op, ...);\n";
+ Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
+ ObjcType = "OBJC_EXPORT id objc_msgSendSuper(struct objc_super *super, SEL op, ...);\n";
+ Buf.insert(Buf.end(), ObjcType, ObjcType+strlen(ObjcType));
}
// Add __builtin_va_list typedef.
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index b086e54..267202c 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -243,7 +243,7 @@
84AF36A00CB17A3B00C820A5 /* DeclObjC.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DeclObjC.h; path = clang/AST/DeclObjC.h; sourceTree = "<group>"; };
84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
- 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index b5d211f..40a2d96 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -355,6 +355,9 @@
assert(idx < NumForwardDecls && "index out of range");
ForwardDecls[idx] = OID;
}
+ ObjcInterfaceDecl** getForwardDecls() const { return ForwardDecls; }
+ int getNumForwardDecls() const { return NumForwardDecls; }
+
static bool classof(const Decl *D) { return D->getKind() == ObjcClass; }
static bool classof(const ObjcClassDecl *D) { return true; }
};