]> granicus.if.org Git - clang/commitdiff
[arcmt] Fully migrate ObjC++ classes, rdar://9660007.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 23 Jun 2011 21:21:33 +0000 (21:21 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 23 Jun 2011 21:21:33 +0000 (21:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133763 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/TransAutoreleasePool.cpp
lib/ARCMigrate/TransRetainReleaseDealloc.cpp
lib/ARCMigrate/TransUnusedInitDelegate.cpp
lib/ARCMigrate/Transforms.h
test/ARCMT/cxx-rewrite.mm [new file with mode: 0644]
test/ARCMT/cxx-rewrite.mm.result [new file with mode: 0644]

index 602ac0cd02500edabb7f31fee9ccf7d29652375e..5b8485432c52f50c390168a677d40e00ca9fd1aa 100644 (file)
@@ -69,8 +69,8 @@ namespace {
 class AutoreleasePoolRewriter
                          : public RecursiveASTVisitor<AutoreleasePoolRewriter> {
 public:
-  AutoreleasePoolRewriter(Decl *D, MigrationPass &pass)
-    : Dcl(D), Body(0), Pass(pass) {
+  AutoreleasePoolRewriter(MigrationPass &pass)
+    : Body(0), Pass(pass) {
     PoolII = &pass.Ctx.Idents.get("NSAutoreleasePool");
     DrainSel = pass.Ctx.Selectors.getNullarySelector(
                                                  &pass.Ctx.Idents.get("drain"));
@@ -411,7 +411,6 @@ private:
     return S;
   }
 
-  Decl *Dcl;
   Stmt *Body;
   MigrationPass &Pass;
 
index f03ab5a6f4bc064812f6a974229d4aab4fa05f3d..c177363b18e2b42a48058aa4a5b58e7464cc6360 100644 (file)
@@ -31,7 +31,6 @@ namespace {
 
 class RetainReleaseDeallocRemover :
                        public RecursiveASTVisitor<RetainReleaseDeallocRemover> {
-  Decl *Dcl;
   Stmt *Body;
   MigrationPass &Pass;
 
@@ -39,8 +38,8 @@ class RetainReleaseDeallocRemover :
   llvm::OwningPtr<ParentMap> StmtMap;
 
 public:
-  RetainReleaseDeallocRemover(Decl *D, MigrationPass &pass)
-    : Dcl(D), Body(0), Pass(pass) { }
+  RetainReleaseDeallocRemover(MigrationPass &pass)
+    : Body(0), Pass(pass) { }
 
   void transformBody(Stmt *body) {
     Body = body;
index 2fa18a3d6256ccd3386f5fee8750cf9ebd5f83ee..1019ab4ff1f6ea9d423039300c808d99445b09bf 100644 (file)
@@ -32,15 +32,14 @@ using llvm::StringRef;
 namespace {
 
 class UnusedInitRewriter : public RecursiveASTVisitor<UnusedInitRewriter> {
-  Decl *Dcl;
   Stmt *Body;
   MigrationPass &Pass;
 
   ExprSet Removables;
 
 public:
-  UnusedInitRewriter(Decl *D, MigrationPass &pass)
-    : Dcl(D), Body(0), Pass(pass) { }
+  UnusedInitRewriter(MigrationPass &pass)
+    : Body(0), Pass(pass) { }
 
   void transformBody(Stmt *body) {
     Body = body;
index 06d7f2befec0d7f908e70f31504a7a53e84be228..21064973bf71607eb25e6eca6d52950fdc30a856 100644 (file)
@@ -59,25 +59,8 @@ class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {
 public:
   BodyTransform(MigrationPass &pass) : Pass(pass) { }
 
-  void handleBody(Decl *D) {
-    Stmt *body = D->getBody();
-    if (body) {
-      BODY_TRANS(D, Pass).transformBody(body);
-    }
-  }
-
-  bool TraverseBlockDecl(BlockDecl *D) {
-    handleBody(D);
-    return true;
-  }
-  bool TraverseObjCMethodDecl(ObjCMethodDecl *D) {
-    if (D->isThisDeclarationADefinition())
-      handleBody(D);
-    return true;
-  }
-  bool TraverseFunctionDecl(FunctionDecl *D) {
-    if (D->isThisDeclarationADefinition())
-      handleBody(D);
+  bool TraverseStmt(Stmt *rootS) {
+    BODY_TRANS(Pass).transformBody(rootS);
     return true;
   }
 };
diff --git a/test/ARCMT/cxx-rewrite.mm b/test/ARCMT/cxx-rewrite.mm
new file mode 100644 (file)
index 0000000..ab402e4
--- /dev/null
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c++ %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+
+#include "Common.h"
+
+@interface NSString : NSObject
++(id)string;
+@end
+
+struct foo {
+    NSString *s;
+    foo(NSString *s): s([s retain]){
+        NSAutoreleasePool *pool = [NSAutoreleasePool new];
+        [[NSString string] autorelease];
+        [pool drain];
+    }
+    ~foo(){ [s release]; }
+private:
+    foo(foo const &);
+    foo &operator=(foo const &);
+};
+
+int main(){
+    NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+    foo f([[NSString string] autorelease]);
+
+    [pool drain];
+    return 0;
+}
diff --git a/test/ARCMT/cxx-rewrite.mm.result b/test/ARCMT/cxx-rewrite.mm.result
new file mode 100644 (file)
index 0000000..145ccd3
--- /dev/null
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -x objective-c++ %s.result
+// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fsyntax-only -x objective-c++ %s > %t
+// RUN: diff %t %s.result
+
+#include "Common.h"
+
+@interface NSString : NSObject
++(id)string;
+@end
+
+struct foo {
+    NSString *s;
+    foo(NSString *s): s(s){
+        @autoreleasepool {
+            [NSString string];
+        }
+    }
+    ~foo(){ s; }
+private:
+    foo(foo const &);
+    foo &operator=(foo const &);
+};
+
+int main(){
+    @autoreleasepool {
+
+        foo f([NSString string]);
+
+    }
+    return 0;
+}