[cfe-commits] r60450 - /cfe/trunk/Driver/RewriteObjC.cpp
Steve Naroff
snaroff at apple.com
Tue Dec 2 16:56:34 PST 2008
Author: snaroff
Date: Tue Dec 2 18:56:33 2008
New Revision: 60450
URL: http://llvm.org/viewvc/llvm-project?rev=60450&view=rev
Log:
More support for rewriting property getter/setters.
Modified:
cfe/trunk/Driver/RewriteObjC.cpp
Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=60450&r1=60449&r2=60450&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Tue Dec 2 18:56:33 2008
@@ -104,6 +104,9 @@
llvm::DenseMap<BlockExpr *, std::string> RewrittenBlockExprs;
+ // This maps a synthesized message expr back to the original property.
+ llvm::DenseMap<Stmt *, ObjCPropertyRefExpr *> PropMsgExprs;
+
FunctionDecl *CurFunctionDef;
VarDecl *GlobalVarDecl;
@@ -193,6 +196,8 @@
Stmt *RewriteFunctionBodyOrGlobalInitializer(Stmt *S);
Stmt *RewriteAtEncode(ObjCEncodeExpr *Exp);
Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, SourceLocation OrigStart);
+ Stmt *RewritePropertyRefExpr(ObjCPropertyRefExpr *PropRefExpr);
+ Stmt *RewritePropertySetter(BinaryOperator *BinOp, ObjCPropertyRefExpr *PRE);
Stmt *RewriteAtSelector(ObjCSelectorExpr *Exp);
Stmt *RewriteMessageExpr(ObjCMessageExpr *Exp);
Stmt *RewriteObjCStringLiteral(ObjCStringLiteral *Exp);
@@ -650,7 +655,7 @@
// Synthesize an explicit cast to initialize the ivar.
// FIXME: deal with code generation implications for various property
// attributes (copy, retain, nonatomic).
- // See objc-act.c:objc_synthesize_new_getter() for details.
+ // See objc-act.c:objc_synthesize_new_setter() for details.
Setr += getIvarAccessString(ClassDecl, OID) + " = ";
Setr += OID->getNameAsCString();
Setr += "; }";
@@ -984,6 +989,35 @@
ReplaceText(ClassDecl->getAtEndLoc(), 0, "// ", 3);
}
+Stmt *RewriteObjC::RewritePropertySetter(BinaryOperator *BinOp,
+ ObjCPropertyRefExpr *PRE) {
+ // FIXME: Fill in the transform.
+ return BinOp;
+}
+
+Stmt *RewriteObjC::RewritePropertyRefExpr(ObjCPropertyRefExpr *PropRefExpr) {
+ // Synthesize a ObjCMessageExpr from a ObjCPropertyRefExpr.
+ // This allows us to reuse all the fun and games in SynthMessageExpr().
+ ObjCMessageExpr *MsgExpr;
+ ObjCPropertyDecl *PDecl = PropRefExpr->getProperty();
+
+ MsgExpr = new ObjCMessageExpr(PropRefExpr->getBase(),
+ PDecl->getGetterName(), PDecl->getType(),
+ PDecl->getGetterMethodDecl(),
+ SourceLocation(), SourceLocation(),
+ 0, 0);
+
+ Stmt *ReplacingStmt = SynthMessageExpr(MsgExpr);
+
+ // Now do the actual rewrite.
+ ReplaceStmt(PropRefExpr, ReplacingStmt);
+ PropMsgExprs[ReplacingStmt] = PropRefExpr;
+
+ // delete PropRefExpr; elsewhere...
+ delete MsgExpr;
+ return ReplacingStmt;
+}
+
Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV,
SourceLocation OrigStart) {
ObjCIvarDecl *D = IV->getDecl();
@@ -3986,6 +4020,15 @@
if (ObjCIvarRefExpr *IvarRefExpr = dyn_cast<ObjCIvarRefExpr>(S))
return RewriteObjCIvarRefExpr(IvarRefExpr, OrigStmtRange.getBegin());
+ if (ObjCPropertyRefExpr *PropRefExpr = dyn_cast<ObjCPropertyRefExpr>(S))
+ return RewritePropertyRefExpr(PropRefExpr);
+
+ if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(S)) {
+ if (BinOp->isAssignmentOp()) {
+ if (ObjCPropertyRefExpr *PRE = PropMsgExprs[BinOp->getLHS()])
+ return RewritePropertySetter(BinOp, PRE);
+ }
+ }
if (ObjCSelectorExpr *AtSelector = dyn_cast<ObjCSelectorExpr>(S))
return RewriteAtSelector(AtSelector);
More information about the cfe-commits
mailing list