From: Argyrios Kyrtzidis Date: Thu, 23 Jun 2011 21:21:33 +0000 (+0000) Subject: [arcmt] Fully migrate ObjC++ classes, rdar://9660007. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1094a0621c3bf91141f7cd9684ca80b357ae61e;p=clang [arcmt] Fully migrate ObjC++ classes, rdar://9660007. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133763 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/TransAutoreleasePool.cpp b/lib/ARCMigrate/TransAutoreleasePool.cpp index 602ac0cd02..5b8485432c 100644 --- a/lib/ARCMigrate/TransAutoreleasePool.cpp +++ b/lib/ARCMigrate/TransAutoreleasePool.cpp @@ -69,8 +69,8 @@ namespace { class AutoreleasePoolRewriter : public RecursiveASTVisitor { 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; diff --git a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp index f03ab5a6f4..c177363b18 100644 --- a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp +++ b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp @@ -31,7 +31,6 @@ namespace { class RetainReleaseDeallocRemover : public RecursiveASTVisitor { - Decl *Dcl; Stmt *Body; MigrationPass &Pass; @@ -39,8 +38,8 @@ class RetainReleaseDeallocRemover : llvm::OwningPtr 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; diff --git a/lib/ARCMigrate/TransUnusedInitDelegate.cpp b/lib/ARCMigrate/TransUnusedInitDelegate.cpp index 2fa18a3d62..1019ab4ff1 100644 --- a/lib/ARCMigrate/TransUnusedInitDelegate.cpp +++ b/lib/ARCMigrate/TransUnusedInitDelegate.cpp @@ -32,15 +32,14 @@ using llvm::StringRef; namespace { class UnusedInitRewriter : public RecursiveASTVisitor { - 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; diff --git a/lib/ARCMigrate/Transforms.h b/lib/ARCMigrate/Transforms.h index 06d7f2befe..21064973bf 100644 --- a/lib/ARCMigrate/Transforms.h +++ b/lib/ARCMigrate/Transforms.h @@ -59,25 +59,8 @@ class BodyTransform : public RecursiveASTVisitor > { 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 index 0000000000..ab402e41cf --- /dev/null +++ b/test/ARCMT/cxx-rewrite.mm @@ -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 index 0000000000..145ccd39e8 --- /dev/null +++ b/test/ARCMT/cxx-rewrite.mm.result @@ -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; +}