- Add rewrite rule for @class.

- Add setter/getter to ObjcClassDecl.
- Predefined key runtime functions.

llvm-svn: 43257
This commit is contained in:
Steve Naroff 2007-10-23 20:20:08 +00:00
parent 5d7032bb08
commit e670dbb9e6
4 changed files with 56 additions and 2 deletions

View File

@ -44,6 +44,7 @@ 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();

View File

@ -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.

View File

@ -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>"; };

View File

@ -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; }
};