diff options
author | Steve Naroff <snaroff@apple.com> | 2007-11-08 14:30:50 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-11-08 14:30:50 +0000 |
commit | 9698464266660346fa2da1bddc3e6404a9819b25 (patch) | |
tree | 85e02cf17495f7ff42cb28d0e7926fae6b548dd9 /Driver/RewriteTest.cpp | |
parent | 8b0c2f659d350118cceee33c211a3dd5e3138ac2 (diff) |
Rewrite RewriteObjCStringLiteral(). This version is simpler (and unlike the previous one, works:-)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43890 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteTest.cpp')
-rw-r--r-- | Driver/RewriteTest.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index d5657694c5..b985e03cb5 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -38,6 +38,7 @@ namespace { FunctionDecl *MsgSendFunctionDecl; FunctionDecl *GetClassFunctionDecl; FunctionDecl *SelGetUidFunctionDecl; + FunctionDecl *CFStringFunctionDecl; // ObjC string constant support. FileVarDecl *ConstantStringClassReference; @@ -52,6 +53,7 @@ namespace { MsgSendFunctionDecl = 0; GetClassFunctionDecl = 0; SelGetUidFunctionDecl = 0; + CFStringFunctionDecl = 0; ConstantStringClassReference = 0; NSStringRecord = 0; Rewrite.setSourceMgr(Context->SourceMgr); @@ -107,7 +109,8 @@ namespace { Expr **args, unsigned nargs); void SynthMsgSendFunctionDecl(); void SynthGetClassFunctionDecl(); - + void SynthCFStringFunctionDecl(); + // Metadata emission. void RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl, std::string &Result); @@ -780,7 +783,36 @@ void RewriteTest::SynthGetClassFunctionDecl() { 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 @@ Stmt *RewriteTest::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) { Rewrite.ReplaceStmt(Exp, cast); delete Exp; return cast; +#endif } Stmt *RewriteTest::RewriteMessageExpr(ObjCMessageExpr *Exp) { |