blob: 150893e6434bbb9fd7b19f4f08d8019286dec70e [file] [log] [blame]
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +00001//===-- Transforms.h - Tranformations to ARC mode ---------------*- C++ -*-===//
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#ifndef LLVM_CLANG_LIB_ARCMIGRATE_TRANSFORMS_H
11#define LLVM_CLANG_LIB_ARCMIGRATE_TRANSFORMS_H
12
13#include "clang/AST/RecursiveASTVisitor.h"
14#include "llvm/ADT/DenseSet.h"
15
16namespace clang {
17 class Decl;
18 class Stmt;
19 class BlockDecl;
20 class ObjCMethodDecl;
21 class FunctionDecl;
22
23namespace arcmt {
24 class MigrationPass;
25
26namespace trans {
27
28//===----------------------------------------------------------------------===//
29// Transformations.
30//===----------------------------------------------------------------------===//
31
32void rewriteAutoreleasePool(MigrationPass &pass);
33void rewriteUnbridgedCasts(MigrationPass &pass);
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000034void makeAssignARCSafe(MigrationPass &pass);
35void removeRetainReleaseDealloc(MigrationPass &pass);
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000036void removeZeroOutPropsInDealloc(MigrationPass &pass);
Argyrios Kyrtzidis14c4b442011-07-13 19:22:00 +000037void rewriteProperties(MigrationPass &pass);
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000038void rewriteBlockObjCVariable(MigrationPass &pass);
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000039void rewriteUnusedInitDelegate(MigrationPass &pass);
Argyrios Kyrtzidisfd103982011-07-18 07:44:45 +000040void checkAPIUses(MigrationPass &pass);
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000041
Argyrios Kyrtzidisfd3455a2011-06-21 20:20:42 +000042void removeEmptyStatementsAndDealloc(MigrationPass &pass);
43
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000044//===----------------------------------------------------------------------===//
45// Helpers.
46//===----------------------------------------------------------------------===//
47
Argyrios Kyrtzidis86625b52011-07-12 22:05:17 +000048/// \brief Determine whether we can add weak to the given type.
49bool canApplyWeak(ASTContext &Ctx, QualType type);
50
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000051/// \brief 'Loc' is the end of a statement range. This returns the location
52/// immediately after the semicolon following the statement.
53/// If no semicolon is found or the location is inside a macro, the returned
54/// source location will be invalid.
55SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx);
56
57bool hasSideEffects(Expr *E, ASTContext &Ctx);
Argyrios Kyrtzidis2c18ca02011-07-14 23:32:04 +000058bool isGlobalVar(Expr *E);
59
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000060
61template <typename BODY_TRANS>
62class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {
63 MigrationPass &Pass;
64
65public:
66 BodyTransform(MigrationPass &pass) : Pass(pass) { }
67
Argyrios Kyrtzidisb1094a02011-06-23 21:21:33 +000068 bool TraverseStmt(Stmt *rootS) {
Argyrios Kyrtzidisfd103982011-07-18 07:44:45 +000069 if (rootS)
70 BODY_TRANS(Pass).transformBody(rootS);
Argyrios Kyrtzidis7196d062011-06-21 20:20:39 +000071 return true;
72 }
73};
74
75typedef llvm::DenseSet<Expr *> ExprSet;
76
77void clearRefsIn(Stmt *S, ExprSet &refs);
78template <typename iterator>
79void clearRefsIn(iterator begin, iterator end, ExprSet &refs) {
80 for (; begin != end; ++begin)
81 clearRefsIn(*begin, refs);
82}
83
84void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs);
85
86void collectRemovables(Stmt *S, ExprSet &exprs);
87
88} // end namespace trans
89
90} // end namespace arcmt
91
92} // end namespace clang
93
94#endif