[cfe-commits] r43257 - in /cfe/trunk: Driver/RewriteTest.cpp Lex/Preprocessor.cpp clang.xcodeproj/project.pbxproj include/clang/AST/DeclObjC.h

Steve Naroff snaroff at apple.com
Tue Oct 23 13:20:08 PDT 2007


Author: snaroff
Date: Tue Oct 23 15:20:08 2007
New Revision: 43257

URL: http://llvm.org/viewvc/llvm-project?rev=43257&view=rev
Log:

- Add rewrite rule for @class.
- Add setter/getter to ObjcClassDecl.
- Predefined key runtime functions.


Modified:
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/Lex/Preprocessor.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/AST/DeclObjC.h

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43257&r1=43256&r2=43257&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Tue Oct 23 15:20:08 2007
@@ -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();
   

Modified: cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Preprocessor.cpp?rev=43257&r1=43256&r2=43257&view=diff

==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Tue Oct 23 15:20:08 2007
@@ -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.

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43257&r1=43256&r2=43257&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Oct 23 15:20:08 2007
@@ -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>"; };

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=43257&r1=43256&r2=43257&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Tue Oct 23 15:20:08 2007
@@ -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; }
 };





More information about the cfe-commits mailing list