aboutsummaryrefslogtreecommitdiff
path: root/lib/ARCMigrate/TransGCCalls.cpp
blob: 71dc6dc357d77dec7c9ae66908143d6deb9585d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//===--- TransGCCalls.cpp - Tranformations to ARC mode --------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "Transforms.h"
#include "Internals.h"
#include "clang/Sema/SemaDiagnostic.h"

using namespace clang;
using namespace arcmt;
using namespace trans;

namespace {

class GCCollectableCallsChecker :
                         public RecursiveASTVisitor<GCCollectableCallsChecker> {
  MigrationContext &MigrateCtx;
  ParentMap &PMap;
  IdentifierInfo *NSMakeCollectableII;

public:
  GCCollectableCallsChecker(MigrationContext &ctx, ParentMap &map)
    : MigrateCtx(ctx), PMap(map) {
    NSMakeCollectableII =
        &MigrateCtx.getPass().Ctx.Idents.get("NSMakeCollectable");
  }

  bool VisitCallExpr(CallExpr *E) {
    Expr *CEE = E->getCallee()->IgnoreParenImpCasts();
    if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
      if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(DRE->getDecl())) {
        if (FD->getDeclContext()->getRedeclContext()->isFileContext() &&
            FD->getIdentifier() == NSMakeCollectableII) {
          TransformActions &TA = MigrateCtx.getPass().TA;
          Transaction Trans(TA);
          TA.clearDiagnostic(diag::err_unavailable,
                             diag::err_unavailable_message,
                             DRE->getSourceRange());
          TA.replace(DRE->getSourceRange(), "CFBridgingRelease");
        }
      }
    }

    return true;
  }
};

} // anonymous namespace

void GCCollectableCallsTraverser::traverseBody(BodyContext &BodyCtx) {
  GCCollectableCallsChecker(BodyCtx.getMigrationContext(),
                            BodyCtx.getParentMap())
                                            .TraverseStmt(BodyCtx.getTopStmt());
}