blob: 9c3faae395b8d45a0b09b4b46f720b9448549cfa [file] [log] [blame]
Argyrios Kyrtzidise0ac7452011-11-04 15:58:08 +00001//===--- 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
14using namespace clang;
15using namespace arcmt;
16using namespace trans;
17
18namespace {
19
20class GCCollectableCallsChecker :
21 public RecursiveASTVisitor<GCCollectableCallsChecker> {
22 MigrationContext &MigrateCtx;
23 ParentMap &PMap;
24 IdentifierInfo *NSMakeCollectableII;
25
26public:
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 Kyrtzidis0d579b62011-11-04 15:58:13 +000043 diag::err_ovl_deleted_call, // ObjC++
Argyrios Kyrtzidise0ac7452011-11-04 15:58:08 +000044 DRE->getSourceRange());
45 TA.replace(DRE->getSourceRange(), "CFBridgingRelease");
46 }
47 }
48 }
49
50 return true;
51 }
52};
53
54} // anonymous namespace
55
56void GCCollectableCallsTraverser::traverseBody(BodyContext &BodyCtx) {
57 GCCollectableCallsChecker(BodyCtx.getMigrationContext(),
58 BodyCtx.getParentMap())
59 .TraverseStmt(BodyCtx.getTopStmt());
60}