blob: d52fba013078dfd1fd9f8647e596fb4003257d5e [file] [log] [blame]
Argyrios Kyrtzidise5b475c2011-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 Kyrtzidise5b475c2011-06-21 20:20:39 +000034void makeAssignARCSafe(MigrationPass &pass);
35void removeRetainReleaseDealloc(MigrationPass &pass);
Argyrios Kyrtzidise5b475c2011-06-21 20:20:39 +000036void removeZeroOutPropsInDealloc(MigrationPass &pass);
37void changeIvarsOfAssignProperties(MigrationPass &pass);
38void rewriteBlockObjCVariable(MigrationPass &pass);
Argyrios Kyrtzidise5b475c2011-06-21 20:20:39 +000039void rewriteUnusedInitDelegate(MigrationPass &pass);
40
Argyrios Kyrtzidise5acb842011-06-21 20:20:42 +000041void removeEmptyStatementsAndDealloc(MigrationPass &pass);
42
Argyrios Kyrtzidise5b475c2011-06-21 20:20:39 +000043//===----------------------------------------------------------------------===//
44// Helpers.
45//===----------------------------------------------------------------------===//
46
Argyrios Kyrtzidisce9b7392011-07-12 22:05:17 +000047/// \brief Determine whether we can add weak to the given type.
48bool canApplyWeak(ASTContext &Ctx, QualType type);
49
Argyrios Kyrtzidise5b475c2011-06-21 20:20:39 +000050/// \brief 'Loc' is the end of a statement range. This returns the location
51/// immediately after the semicolon following the statement.
52/// If no semicolon is found or the location is inside a macro, the returned
53/// source location will be invalid.
54SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx);
55
56bool hasSideEffects(Expr *E, ASTContext &Ctx);
57
58template <typename BODY_TRANS>
59class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {
60 MigrationPass &Pass;
61
62public:
63 BodyTransform(MigrationPass &pass) : Pass(pass) { }
64
Argyrios Kyrtzidis0b2bd862011-06-23 21:21:33 +000065 bool TraverseStmt(Stmt *rootS) {
66 BODY_TRANS(Pass).transformBody(rootS);
Argyrios Kyrtzidise5b475c2011-06-21 20:20:39 +000067 return true;
68 }
69};
70
71typedef llvm::DenseSet<Expr *> ExprSet;
72
73void clearRefsIn(Stmt *S, ExprSet &refs);
74template <typename iterator>
75void clearRefsIn(iterator begin, iterator end, ExprSet &refs) {
76 for (; begin != end; ++begin)
77 clearRefsIn(*begin, refs);
78}
79
80void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs);
81
82void collectRemovables(Stmt *S, ExprSet &exprs);
83
84} // end namespace trans
85
86} // end namespace arcmt
87
88} // end namespace clang
89
90#endif