]> granicus.if.org Git - clang/commitdiff
Extend RewriteTest::RewriteObjCIvarRefExpr() to cope with static typing (when using...
authorSteve Naroff <snaroff@apple.com>
Thu, 15 Nov 2007 11:33:00 +0000 (11:33 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 15 Nov 2007 11:33:00 +0000 (11:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44170 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp

index 5dc36923fcb4c266edb6d097db2a136ecb37e828..a768d17b3a582842953cbd2a450fb56068143ef1 100644 (file)
@@ -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<ObjcInterfaceType>(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;
+  }
 }
 
 //===----------------------------------------------------------------------===//