Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame^] | 1 | //===--- TransDeallocMethod.cpp - Tranformations to ARC mode --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Transforms.h" |
| 11 | #include "Internals.h" |
| 12 | |
| 13 | using namespace clang; |
| 14 | using namespace arcmt; |
| 15 | using namespace trans; |
| 16 | using llvm::StringRef; |
| 17 | |
| 18 | void trans::removeDeallocMethod(MigrationPass &pass) { |
| 19 | ASTContext &Ctx = pass.Ctx; |
| 20 | TransformActions &TA = pass.TA; |
| 21 | DeclContext *DC = Ctx.getTranslationUnitDecl(); |
| 22 | ObjCMethodDecl *DeallocMethodDecl = 0; |
| 23 | IdentifierInfo *II = &Ctx.Idents.get("dealloc"); |
| 24 | |
| 25 | for (DeclContext::decl_iterator |
| 26 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { |
| 27 | Decl *D = *I; |
| 28 | if (ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(D)) { |
| 29 | DeallocMethodDecl = 0; |
| 30 | for (ObjCImplementationDecl::instmeth_iterator |
| 31 | I = IMD->instmeth_begin(), E = IMD->instmeth_end(); |
| 32 | I != E; ++I) { |
| 33 | ObjCMethodDecl *OMD = *I; |
| 34 | if (OMD->isInstanceMethod() && |
| 35 | OMD->getSelector() == Ctx.Selectors.getSelector(0, &II)) { |
| 36 | DeallocMethodDecl = OMD; |
| 37 | break; |
| 38 | } |
| 39 | } |
| 40 | if (DeallocMethodDecl && |
| 41 | DeallocMethodDecl->getCompoundBody()->body_empty()) { |
| 42 | Transaction Trans(TA); |
| 43 | TA.remove(DeallocMethodDecl->getSourceRange()); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |