[cfe-commits] r43705 - /cfe/trunk/Driver/RewriteTest.cpp
Steve Naroff
snaroff at apple.com
Mon Nov 5 06:50:49 PST 2007
Author: snaroff
Date: Mon Nov 5 08:50:49 2007
New Revision: 43705
URL: http://llvm.org/viewvc/llvm-project?rev=43705&view=rev
Log:
Rewrite @selector(sel).
Modified:
cfe/trunk/Driver/RewriteTest.cpp
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43705&r1=43704&r2=43705&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Mon Nov 5 08:50:49 2007
@@ -85,6 +85,7 @@
// Expression Rewriting.
Stmt *RewriteFunctionBody(Stmt *S);
Stmt *RewriteAtEncode(ObjCEncodeExpr *Exp);
+ Stmt *RewriteAtSelector(ObjCSelectorExpr *Exp);
Stmt *RewriteMessageExpr(ObjCMessageExpr *Exp);
Stmt *RewriteObjCStringLiteral(ObjCStringLiteral *Exp);
CallExpr *SynthesizeCallToFunctionDecl(FunctionDecl *FD,
@@ -374,6 +375,9 @@
// Handle specific things.
if (ObjCEncodeExpr *AtEncode = dyn_cast<ObjCEncodeExpr>(S))
return RewriteAtEncode(AtEncode);
+
+ if (ObjCSelectorExpr *AtSelector = dyn_cast<ObjCSelectorExpr>(S))
+ return RewriteAtSelector(AtSelector);
if (ObjCStringLiteral *AtString = dyn_cast<ObjCStringLiteral>(S))
return RewriteObjCStringLiteral(AtString);
@@ -414,6 +418,22 @@
return Replacement;
}
+Stmt *RewriteTest::RewriteAtSelector(ObjCSelectorExpr *Exp) {
+ assert(SelGetUidFunctionDecl && "Can't find sel_registerName() decl");
+ // Create a call to sel_registerName("selName").
+ llvm::SmallVector<Expr*, 8> SelExprs;
+ QualType argType = Context->getPointerType(Context->CharTy);
+ SelExprs.push_back(new StringLiteral(Exp->getSelector().getName().c_str(),
+ Exp->getSelector().getName().size(),
+ false, argType, SourceLocation(),
+ SourceLocation()));
+ CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl,
+ &SelExprs[0], SelExprs.size());
+ Rewrite.ReplaceStmt(Exp, SelExp);
+ delete Exp;
+ return SelExp;
+}
+
CallExpr *RewriteTest::SynthesizeCallToFunctionDecl(
FunctionDecl *FD, Expr **args, unsigned nargs) {
// Get the type, we will need to reference it in a couple spots.
More information about the cfe-commits
mailing list