[cfe-commits] r43890 - /cfe/trunk/Driver/RewriteTest.cpp
Steve Naroff
snaroff at apple.com
Thu Nov 8 06:31:14 PST 2007
Author: snaroff
Date: Thu Nov 8 08:30:50 2007
New Revision: 43890
URL: http://llvm.org/viewvc/llvm-project?rev=43890&view=rev
Log:
Rewrite RewriteObjCStringLiteral(). This version is simpler (and unlike the previous one, works:-)
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=43890&r1=43889&r2=43890&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Thu Nov 8 08:30:50 2007
@@ -38,6 +38,7 @@
FunctionDecl *MsgSendFunctionDecl;
FunctionDecl *GetClassFunctionDecl;
FunctionDecl *SelGetUidFunctionDecl;
+ FunctionDecl *CFStringFunctionDecl;
// ObjC string constant support.
FileVarDecl *ConstantStringClassReference;
@@ -52,6 +53,7 @@
MsgSendFunctionDecl = 0;
GetClassFunctionDecl = 0;
SelGetUidFunctionDecl = 0;
+ CFStringFunctionDecl = 0;
ConstantStringClassReference = 0;
NSStringRecord = 0;
Rewrite.setSourceMgr(Context->SourceMgr);
@@ -107,7 +109,8 @@
Expr **args, unsigned nargs);
void SynthMsgSendFunctionDecl();
void SynthGetClassFunctionDecl();
-
+ void SynthCFStringFunctionDecl();
+
// Metadata emission.
void RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl,
std::string &Result);
@@ -780,7 +783,36 @@
FunctionDecl::Extern, false, 0);
}
+// SynthCFStringFunctionDecl - id __builtin___CFStringMakeConstantString(const char *name);
+void RewriteTest::SynthCFStringFunctionDecl() {
+ IdentifierInfo *getClassIdent = &Context->Idents.get("__builtin___CFStringMakeConstantString");
+ llvm::SmallVector<QualType, 16> ArgTys;
+ ArgTys.push_back(Context->getPointerType(
+ Context->CharTy.getQualifiedType(QualType::Const)));
+ QualType getClassType = Context->getFunctionType(Context->getObjcIdType(),
+ &ArgTys[0], ArgTys.size(),
+ false /*isVariadic*/);
+ CFStringFunctionDecl = new FunctionDecl(SourceLocation(),
+ getClassIdent, getClassType,
+ FunctionDecl::Extern, false, 0);
+}
+
Stmt *RewriteTest::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) {
+#if 1
+ // This rewrite is specific to GCC, which has builtin support for CFString.
+ if (!CFStringFunctionDecl)
+ SynthCFStringFunctionDecl();
+ // Create a call to __builtin___CFStringMakeConstantString("cstr").
+ llvm::SmallVector<Expr*, 8> StrExpr;
+ StrExpr.push_back(Exp->getString());
+ CallExpr *call = SynthesizeCallToFunctionDecl(CFStringFunctionDecl,
+ &StrExpr[0], StrExpr.size());
+ // cast to NSConstantString *
+ CastExpr *cast = new CastExpr(Exp->getType(), call, SourceLocation());
+ Rewrite.ReplaceStmt(Exp, cast);
+ delete Exp;
+ return cast;
+#else
assert(ConstantStringClassReference && "Can't find constant string reference");
llvm::SmallVector<Expr*, 4> InitExprs;
@@ -818,6 +850,7 @@
Rewrite.ReplaceStmt(Exp, cast);
delete Exp;
return cast;
+#endif
}
Stmt *RewriteTest::RewriteMessageExpr(ObjCMessageExpr *Exp) {
More information about the cfe-commits
mailing list