diff options
author | Steve Naroff <snaroff@apple.com> | 2007-10-23 20:20:08 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-10-23 20:20:08 +0000 |
commit | 7e15891fc89256fc013bd1003676ad3197b85c25 (patch) | |
tree | d1c5405cc00852896011a485a5fe83dd170ce1dc | |
parent | deef51838bcf0a1a94832a083fb69ddecd008e8c (diff) |
- 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
-rw-r--r-- | Driver/RewriteTest.cpp | 36 | ||||
-rw-r--r-- | Lex/Preprocessor.cpp | 17 | ||||
-rw-r--r-- | clang.xcodeproj/project.pbxproj | 2 | ||||
-rw-r--r-- | include/clang/AST/DeclObjC.h | 3 |
4 files changed, 56 insertions, 2 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index cf812a284f..7cf1342591 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -44,7 +44,8 @@ namespace { void RewriteFunctionBody(Stmt *S); void RewriteAtEncode(ObjCEncodeExpr *Exp); - + void RewriteForwardClassDecl(ObjcClassDecl *Dcl); + void WriteObjcClassMetaData(ObjcImplementationDecl *IDecl); void WriteObjcMetaData(); @@ -105,6 +106,8 @@ void RewriteTest::HandleDeclInMainFile(Decl *D) { 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 @@ void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { 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 c1f14a9b9b..6380544376 100644 --- a/Lex/Preprocessor.cpp +++ b/Lex/Preprocessor.cpp @@ -392,6 +392,23 @@ static void InitializePredefinedMacros(Preprocessor &PP, 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 b086e54ce3..267202c41d 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 b5d211f308..40a2d9643c 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -355,6 +355,9 @@ public: 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; } }; |