blob: a7c3c1e9d64b2a0bbd956a6c266d1c0d731f3f12 [file] [log] [blame]
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +00001//===--- 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
13using namespace clang;
14using namespace arcmt;
15using namespace trans;
16using llvm::StringRef;
17
18void 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}