[cfe-commits] r44156 - in /cfe/trunk: Driver/RewriteTest.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h
Steve Naroff
snaroff at apple.com
Wed Nov 14 18:58:25 PST 2007
Author: snaroff
Date: Wed Nov 14 20:58:25 2007
New Revision: 44156
URL: http://llvm.org/viewvc/llvm-project?rev=44156&view=rev
Log:
- Implement ivar rewrite (patch by Fariborz).
- RewriteMessageExpr()...make implicit casts explicit with synthesizing call (removing warnings when calling objc_msgSend()).
Modified:
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=44156&r1=44155&r2=44156&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Wed Nov 14 20:58:25 2007
@@ -103,6 +103,7 @@
// Expression Rewriting.
Stmt *RewriteFunctionBodyOrGlobalInitializer(Stmt *S);
Stmt *RewriteAtEncode(ObjCEncodeExpr *Exp);
+ Stmt *RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV);
Stmt *RewriteAtSelector(ObjCSelectorExpr *Exp);
Stmt *RewriteMessageExpr(ObjCMessageExpr *Exp);
Stmt *RewriteObjCStringLiteral(ObjCStringLiteral *Exp);
@@ -565,6 +566,19 @@
Rewrite.ReplaceText(ClassDecl->getAtEndLoc(), 0, "// ", 3);
}
+Stmt *RewriteTest::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
+ ObjcIvarDecl *D = IV->getDecl();
+ if (IV->isFreeIvar()) {
+ Expr *Replacement = new MemberExpr(IV->getBase(), true, D,
+ IV->getLocation());
+ Rewrite.ReplaceStmt(IV, Replacement);
+ delete IV;
+ return Replacement;
+ }
+ else
+ return IV;
+}
+
//===----------------------------------------------------------------------===//
// Function Body / Expression rewriting
//===----------------------------------------------------------------------===//
@@ -582,6 +596,9 @@
// Handle specific things.
if (ObjCEncodeExpr *AtEncode = dyn_cast<ObjCEncodeExpr>(S))
return RewriteAtEncode(AtEncode);
+
+ if (ObjCIvarRefExpr *IvarRefExpr = dyn_cast<ObjCIvarRefExpr>(S))
+ return RewriteObjCIvarRefExpr(IvarRefExpr);
if (ObjCSelectorExpr *AtSelector = dyn_cast<ObjCSelectorExpr>(S))
return RewriteAtSelector(AtSelector);
@@ -1063,14 +1080,11 @@
// Now push any user supplied arguments.
for (unsigned i = 0; i < Exp->getNumArgs(); i++) {
Expr *userExpr = Exp->getArg(i);
-#if 0
- // Make sure we cast "self" to "id".
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(userExpr)) {
- if (!strcmp(DRE->getDecl()->getName(), "self"))
- userExpr = new CastExpr(Context->getObjcIdType(), userExpr,
- SourceLocation());
- }
-#endif
+ // Make all implicit casts explicit...ICE comes in handy:-)
+ if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(userExpr)) {
+ // Reuse the ICE type, it is exactly what the doctor ordered.
+ userExpr = new CastExpr(ICE->getType(), userExpr, SourceLocation());
+ }
MsgExprs.push_back(userExpr);
// We've transferred the ownership to MsgExprs. Null out the argument in
// the original expression, since we will delete it below.
@@ -1088,8 +1102,6 @@
// Push any user argument types.
for (int i = 0; i < mDecl->getNumParams(); i++) {
QualType t = mDecl->getParamDecl(i)->getType();
- if (t == Context->getObjcClassType())
- t = Context->getObjcIdType(); // Convert "Class"->"id"
ArgTypes.push_back(t);
}
returnType = mDecl->getResultType();
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44156&r1=44155&r2=44156&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Nov 14 20:58:25 2007
@@ -85,8 +85,12 @@
if (CurMethodDecl) {
ObjcInterfaceDecl *IFace = CurMethodDecl->getClassInterface();
ObjcInterfaceDecl *clsDeclared;
- if (ObjcIvarDecl *IV = IFace->lookupInstanceVariable(&II, clsDeclared))
- return new ObjCIvarRefExpr(IV, IV->getType(), Loc);
+ if (ObjcIvarDecl *IV = IFace->lookupInstanceVariable(&II, clsDeclared)) {
+ IdentifierInfo &II = Context.Idents.get("self");
+ ExprResult SelfExpr = ActOnIdentifierExpr(S, Loc, II, false);
+ return new ObjCIvarRefExpr(IV, IV->getType(), Loc,
+ static_cast<Expr*>(SelfExpr.Val), true, true);
+ }
}
// If this name wasn't predeclared and if this is not a function call,
// diagnose the problem.
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=44156&r1=44155&r2=44156&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Nov 14 20:58:25 2007
@@ -1256,18 +1256,23 @@
class ObjcIvarDecl *D;
SourceLocation Loc;
Expr *Base;
- bool IsArrow; // True if this is "X->F", false if this is "X.F".
+ bool IsArrow:1; // True if this is "X->F", false if this is "X.F".
+ bool IsFreeIvar:1; // True if ivar reference has no base (self assumed).
public:
ObjCIvarRefExpr(ObjcIvarDecl *d, QualType t, SourceLocation l, Expr *base=0,
- bool arrow = false) :
- Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow) {}
+ bool arrow = false, bool freeIvar = false) :
+ Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow),
+ IsFreeIvar(freeIvar) {}
ObjcIvarDecl *getDecl() { return D; }
const ObjcIvarDecl *getDecl() const { return D; }
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
Expr *const getBase() const { return Base; }
const bool isArrow() const { return IsArrow; }
+ const bool isFreeIvar() const { return IsFreeIvar; }
+
+ SourceLocation getLocation() const { return Loc; }
static bool classof(const Stmt *T) {
return T->getStmtClass() == ObjCIvarRefExprClass;
More information about the cfe-commits
mailing list