aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-10-29 21:23:59 +0000
committerSteve Naroff <snaroff@apple.com>2008-10-29 21:23:59 +0000
commitfdc0372eda30952b03f3fd4269dbc4b2acfdfa55 (patch)
tree4b6892a4f0e029a9b36f19819d32f688fe5308c3
parent2a72f7b592d9966fb0cccd989780b6821aaf0368 (diff)
Convert SynthBlockInitExpr() from text->AST based implementation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58396 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/RewriteObjC.cpp44
1 files changed, 28 insertions, 16 deletions
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp
index 68ad0e6583..2384ddd45a 100644
--- a/Driver/RewriteObjC.cpp
+++ b/Driver/RewriteObjC.cpp
@@ -3750,47 +3750,59 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp) {
llvm::SmallVector<Expr*, 4> InitExprs;
+ // Initialize the block function.
FD = SynthBlockInitFunctionDecl(Func.c_str());
DeclRefExpr *Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
CastExpr *castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg,
Context->VoidPtrTy, SourceLocation());
InitExprs.push_back(castExpr);
-#if 0
- // Initialize the block function.
- Init += "((void*)" + Func;
if (ImportedBlockDecls.size()) {
std::string Buf = "__" + FuncName + "_block_copy_" + BlockNumber;
- Init += ",(void*)" + Buf;
+ FD = SynthBlockInitFunctionDecl(Buf.c_str());
+ Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
+ castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg,
+ Context->VoidPtrTy, SourceLocation());
+ InitExprs.push_back(castExpr);
+
Buf = "__" + FuncName + "_block_dispose_" + BlockNumber;
- Init += ",(void*)" + Buf;
+ FD = SynthBlockInitFunctionDecl(Buf.c_str());
+ Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
+ castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg,
+ Context->VoidPtrTy, SourceLocation());
+ InitExprs.push_back(castExpr);
}
// Add initializers for any closure decl refs.
if (BlockDeclRefs.size()) {
+ Expr *Exp;
// Output all "by copy" declarations.
for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(),
E = BlockByCopyDecls.end(); I != E; ++I) {
- Init += ",";
if (isObjCType((*I)->getType())) {
- Init += "[[";
- Init += (*I)->getName();
- Init += " retain] autorelease]";
+ // FIXME: Conform to ABI ([[obj retain] autorelease]).
+ FD = SynthBlockInitFunctionDecl((*I)->getName());
+ Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
} else if (isBlockPointerType((*I)->getType())) {
- Init += "(void *)";
- Init += (*I)->getName();
+ FD = SynthBlockInitFunctionDecl((*I)->getName());
+ Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
+ Exp = new CStyleCastExpr(Context->VoidPtrTy, Arg,
+ Context->VoidPtrTy, SourceLocation());
} else {
- Init += (*I)->getName();
+ FD = SynthBlockInitFunctionDecl((*I)->getName());
+ Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
}
+ InitExprs.push_back(Exp);
}
// Output all "by ref" declarations.
for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(),
E = BlockByRefDecls.end(); I != E; ++I) {
- Init += ",&";
- Init += (*I)->getName();
+ FD = SynthBlockInitFunctionDecl((*I)->getName());
+ Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
+ Exp = new UnaryOperator(Exp, UnaryOperator::AddrOf,
+ Context->getPointerType(Exp->getType()),
+ SourceLocation());
}
}
- Init += ")";
-#endif
NewRep = new CallExpr(DRE, &InitExprs[0], InitExprs.size(),
FType, SourceLocation());
NewRep = new UnaryOperator(NewRep, UnaryOperator::AddrOf,