[cfe-commits] r43274 - in /cfe/trunk: Driver/RewriteTest.cpp clang.xcodeproj/project.pbxproj
Steve Naroff
snaroff at apple.com
Tue Oct 23 16:50:29 PDT 2007
Author: snaroff
Date: Tue Oct 23 18:50:29 2007
New Revision: 43274
URL: http://llvm.org/viewvc/llvm-project?rev=43274&view=rev
Log:
Add some plumbing to rewrite message expressions (still under construction).
Modified:
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43274&r1=43273&r2=43274&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Tue Oct 23 18:50:29 2007
@@ -16,6 +16,7 @@
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/IdentifierTable.h"
using namespace clang;
@@ -28,12 +29,17 @@
SourceLocation LastIncLoc;
llvm::SmallVector<ObjcImplementationDecl *, 8> ClassImplementation;
llvm::SmallVector<ObjcCategoryImplDecl *, 8> CategoryImplementation;
+
+ FunctionDecl *MsgSendFunctionDecl;
+ FunctionDecl *GetClassFunctionDecl;
+
static const int OBJC_ABI_VERSION =7 ;
public:
void Initialize(ASTContext &context, unsigned mainFileID) {
Context = &context;
SM = &Context->SourceMgr;
MainFileID = mainFileID;
+ MsgSendFunctionDecl = 0;
Rewrite.setSourceMgr(Context->SourceMgr);
}
@@ -45,6 +51,7 @@
void RewriteFunctionBody(Stmt *S);
void RewriteAtEncode(ObjCEncodeExpr *Exp);
void RewriteForwardClassDecl(ObjcClassDecl *Dcl);
+ void RewriteMessageExpr(ObjCMessageExpr *Exp);
void WriteObjcClassMetaData(ObjcImplementationDecl *IDecl);
void WriteObjcMetaData();
@@ -65,6 +72,13 @@
// If this is for a builtin, ignore it.
if (Loc.isInvalid()) return;
+ // Look for built-in declarations that we need to refer during the rewrite.
+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ if (FD->getIdentifier() == &Context->Idents.get("objc_msgSend"))
+ MsgSendFunctionDecl = FD;
+ else if (FD->getIdentifier() == &Context->Idents.get("objc_getClass"))
+ GetClassFunctionDecl = FD;
+ }
if (SM->getDecomposedFileLoc(Loc).first == MainFileID)
return HandleDeclInMainFile(D);
@@ -113,15 +127,19 @@
void RewriteTest::RewriteFunctionBody(Stmt *S) {
- // Handle specific things.
- if (ObjCEncodeExpr *AtEncode = dyn_cast<ObjCEncodeExpr>(S))
- return RewriteAtEncode(AtEncode);
-
// Otherwise, just rewrite all children.
for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
CI != E; ++CI)
if (*CI)
RewriteFunctionBody(*CI);
+
+ // Handle specific things.
+ if (ObjCEncodeExpr *AtEncode = dyn_cast<ObjCEncodeExpr>(S))
+ return RewriteAtEncode(AtEncode);
+
+ if (ObjCMessageExpr *MessExpr = dyn_cast<ObjCMessageExpr>(S))
+ return RewriteMessageExpr(MessExpr);
+
}
void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) {
@@ -133,6 +151,33 @@
delete Replacement;
}
+
+void RewriteTest::RewriteMessageExpr(ObjCMessageExpr *Exp) {
+ assert(MsgSendFunctionDecl && "Can't find objc_msgSend() decl");
+ //Exp->dumpPretty();
+ //printf("\n");
+
+ // Synthesize a call to objc_msgSend().
+
+ // Get the type, we will need to reference it in a couple spots.
+ QualType msgSendType = MsgSendFunctionDecl->getType();
+
+ // Create a reference to the objc_msgSend() declaration.
+ DeclRefExpr *DRE = new DeclRefExpr(MsgSendFunctionDecl, msgSendType,
+ SourceLocation());
+
+ // Now, we cast the reference to a pointer to the objc_msgSend type.
+ QualType pToFunc = Context->getPointerType(msgSendType);
+ ImplicitCastExpr *ICE = new ImplicitCastExpr(pToFunc, DRE);
+
+ const FunctionType *FT = msgSendType->getAsFunctionType();
+ CallExpr *CE = new CallExpr(ICE, 0, 0, FT->getResultType(),
+ SourceLocation());
+ Rewrite.ReplaceStmt(Exp, CE);
+ //Exp->dump();
+ //CE->dump();
+}
+
void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl *ClassDecl) {
int numDecls = ClassDecl->getNumForwardDecls();
ObjcInterfaceDecl **ForwardDecls = ClassDecl->getForwardDecls();
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43274&r1=43273&r2=43274&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Oct 23 18:50:29 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; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; 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>"; };
@@ -750,7 +750,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
More information about the cfe-commits
mailing list