From: Steve Naroff Date: Thu, 15 Nov 2007 11:33:00 +0000 (+0000) Subject: Extend RewriteTest::RewriteObjCIvarRefExpr() to cope with static typing (when using... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2a689b0bd0cda7bc1522dc0057f01f0897e6d3d;p=clang Extend RewriteTest::RewriteObjCIvarRefExpr() to cope with static typing (when using -> on a type which corresponds to the implementation type). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44170 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 5dc36923fc..a768d17b3a 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -594,9 +594,27 @@ Stmt *RewriteTest::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) { Rewrite.ReplaceStmt(IV, Replacement); delete IV; return Replacement; - } - else + } else { + if (CurMethodDecl) { + if (const PointerType *pType = IV->getBase()->getType()->getAsPointerType()) { + ObjcInterfaceType *intT = dyn_cast(pType->getPointeeType()); + if (CurMethodDecl->getClassInterface() == intT->getDecl()) { + IdentifierInfo *II = intT->getDecl()->getIdentifier(); + RecordDecl *RD = new RecordDecl(Decl::Struct, SourceLocation(), + II, 0); + QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); + + CastExpr *castExpr = new CastExpr(castT, IV->getBase(), SourceLocation()); + // Don't forget the parens to enforce the proper binding. + ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), castExpr); + Rewrite.ReplaceStmt(IV->getBase(), PE); + delete IV->getBase(); + return PE; + } + } + } return IV; + } } //===----------------------------------------------------------------------===//