1 //===-- Transforms.h - Tranformations to ARC mode ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LIB_ARCMIGRATE_TRANSFORMS_H
11 #define LLVM_CLANG_LIB_ARCMIGRATE_TRANSFORMS_H
13 #include "clang/AST/RecursiveASTVisitor.h"
14 #include "llvm/ADT/DenseSet.h"
28 //===----------------------------------------------------------------------===//
30 //===----------------------------------------------------------------------===//
32 void rewriteAutoreleasePool(MigrationPass &pass);
33 void rewriteUnbridgedCasts(MigrationPass &pass);
34 void makeAssignARCSafe(MigrationPass &pass);
35 void removeRetainReleaseDealloc(MigrationPass &pass);
36 void removeZeroOutPropsInDealloc(MigrationPass &pass);
37 void rewriteProperties(MigrationPass &pass);
38 void rewriteBlockObjCVariable(MigrationPass &pass);
39 void rewriteUnusedInitDelegate(MigrationPass &pass);
40 void checkAPIUses(MigrationPass &pass);
42 void removeEmptyStatementsAndDealloc(MigrationPass &pass);
44 //===----------------------------------------------------------------------===//
46 //===----------------------------------------------------------------------===//
48 /// \brief Determine whether we can add weak to the given type.
49 bool canApplyWeak(ASTContext &Ctx, QualType type);
51 /// \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.
55 SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx);
57 /// \brief \arg Loc is the end of a statement range. This returns the location
58 /// of the semicolon following the statement.
59 /// If no semicolon is found or the location is inside a macro, the returned
60 /// source location will be invalid.
61 SourceLocation findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx);
63 bool hasSideEffects(Expr *E, ASTContext &Ctx);
64 bool isGlobalVar(Expr *E);
65 /// \brief Returns "nil" or "0" if 'nil' macro is not actually defined.
66 StringRef getNilString(ASTContext &Ctx);
68 template <typename BODY_TRANS>
69 class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {
73 BodyTransform(MigrationPass &pass) : Pass(pass) { }
75 bool TraverseStmt(Stmt *rootS) {
77 BODY_TRANS(Pass).transformBody(rootS);
82 typedef llvm::DenseSet<Expr *> ExprSet;
84 void clearRefsIn(Stmt *S, ExprSet &refs);
85 template <typename iterator>
86 void clearRefsIn(iterator begin, iterator end, ExprSet &refs) {
87 for (; begin != end; ++begin)
88 clearRefsIn(*begin, refs);
91 void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs);
93 void collectRemovables(Stmt *S, ExprSet &exprs);
95 } // end namespace trans
97 } // end namespace arcmt
99 } // end namespace clang