From: Steve Naroff Date: Mon, 5 Nov 2007 14:50:49 +0000 (+0000) Subject: Rewrite @selector(sel). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b42f8415bcfb84c208fd577458ce1bbc2cd800fe;p=clang Rewrite @selector(sel). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43705 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 58de9f60c1..dfe3d4e93b 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -85,6 +85,7 @@ namespace { // 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 @@ Stmt *RewriteTest::RewriteFunctionBody(Stmt *S) { // Handle specific things. if (ObjCEncodeExpr *AtEncode = dyn_cast(S)) return RewriteAtEncode(AtEncode); + + if (ObjCSelectorExpr *AtSelector = dyn_cast(S)) + return RewriteAtSelector(AtSelector); if (ObjCStringLiteral *AtString = dyn_cast(S)) return RewriteObjCStringLiteral(AtString); @@ -414,6 +418,22 @@ Stmt *RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) { return Replacement; } +Stmt *RewriteTest::RewriteAtSelector(ObjCSelectorExpr *Exp) { + assert(SelGetUidFunctionDecl && "Can't find sel_registerName() decl"); + // Create a call to sel_registerName("selName"). + llvm::SmallVector 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.