Argyrios Kyrtzidis | e0ac745 | 2011-11-04 15:58:08 +0000 | [diff] [blame] | 1 | //===--- TransGCCalls.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 | #include "clang/Sema/SemaDiagnostic.h" |
| 13 | |
| 14 | using namespace clang; |
| 15 | using namespace arcmt; |
| 16 | using namespace trans; |
| 17 | |
| 18 | namespace { |
| 19 | |
| 20 | class GCCollectableCallsChecker : |
| 21 | public RecursiveASTVisitor<GCCollectableCallsChecker> { |
| 22 | MigrationContext &MigrateCtx; |
| 23 | ParentMap &PMap; |
| 24 | IdentifierInfo *NSMakeCollectableII; |
| 25 | |
| 26 | public: |
| 27 | GCCollectableCallsChecker(MigrationContext &ctx, ParentMap &map) |
| 28 | : MigrateCtx(ctx), PMap(map) { |
| 29 | NSMakeCollectableII = |
| 30 | &MigrateCtx.getPass().Ctx.Idents.get("NSMakeCollectable"); |
| 31 | } |
| 32 | |
| 33 | bool VisitCallExpr(CallExpr *E) { |
| 34 | Expr *CEE = E->getCallee()->IgnoreParenImpCasts(); |
| 35 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) { |
| 36 | if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(DRE->getDecl())) { |
| 37 | if (FD->getDeclContext()->getRedeclContext()->isFileContext() && |
| 38 | FD->getIdentifier() == NSMakeCollectableII) { |
| 39 | TransformActions &TA = MigrateCtx.getPass().TA; |
| 40 | Transaction Trans(TA); |
| 41 | TA.clearDiagnostic(diag::err_unavailable, |
| 42 | diag::err_unavailable_message, |
Argyrios Kyrtzidis | 0d579b6 | 2011-11-04 15:58:13 +0000 | [diff] [blame^] | 43 | diag::err_ovl_deleted_call, // ObjC++ |
Argyrios Kyrtzidis | e0ac745 | 2011-11-04 15:58:08 +0000 | [diff] [blame] | 44 | DRE->getSourceRange()); |
| 45 | TA.replace(DRE->getSourceRange(), "CFBridgingRelease"); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | } // anonymous namespace |
| 55 | |
| 56 | void GCCollectableCallsTraverser::traverseBody(BodyContext &BodyCtx) { |
| 57 | GCCollectableCallsChecker(BodyCtx.getMigrationContext(), |
| 58 | BodyCtx.getParentMap()) |
| 59 | .TraverseStmt(BodyCtx.getTopStmt()); |
| 60 | } |