Transforms.h revision 7707c75ff98e26aa939557e3bf80490556c00ae4
1//===-- 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); 34void makeAssignARCSafe(MigrationPass &pass); 35void removeRetainReleaseDealloc(MigrationPass &pass); 36void removeZeroOutPropsInDealloc(MigrationPass &pass); 37void changeIvarsOfAssignProperties(MigrationPass &pass); 38void rewriteBlockObjCVariable(MigrationPass &pass); 39void rewriteUnusedInitDelegate(MigrationPass &pass); 40 41void removeEmptyStatementsAndDealloc(MigrationPass &pass); 42 43//===----------------------------------------------------------------------===// 44// Helpers. 45//===----------------------------------------------------------------------===// 46 47/// \brief 'Loc' is the end of a statement range. This returns the location 48/// immediately after the semicolon following the statement. 49/// If no semicolon is found or the location is inside a macro, the returned 50/// source location will be invalid. 51SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx); 52 53bool hasSideEffects(Expr *E, ASTContext &Ctx); 54 55template <typename BODY_TRANS> 56class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > { 57 MigrationPass &Pass; 58 59public: 60 BodyTransform(MigrationPass &pass) : Pass(pass) { } 61 62 void handleBody(Decl *D) { 63 Stmt *body = D->getBody(); 64 if (body) { 65 BODY_TRANS(D, Pass).transformBody(body); 66 } 67 } 68 69 bool TraverseBlockDecl(BlockDecl *D) { 70 handleBody(D); 71 return true; 72 } 73 bool TraverseObjCMethodDecl(ObjCMethodDecl *D) { 74 if (D->isThisDeclarationADefinition()) 75 handleBody(D); 76 return true; 77 } 78 bool TraverseFunctionDecl(FunctionDecl *D) { 79 if (D->isThisDeclarationADefinition()) 80 handleBody(D); 81 return true; 82 } 83}; 84 85typedef llvm::DenseSet<Expr *> ExprSet; 86 87void clearRefsIn(Stmt *S, ExprSet &refs); 88template <typename iterator> 89void clearRefsIn(iterator begin, iterator end, ExprSet &refs) { 90 for (; begin != end; ++begin) 91 clearRefsIn(*begin, refs); 92} 93 94void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs); 95 96void collectRemovables(Stmt *S, ExprSet &exprs); 97 98} // end namespace trans 99 100} // end namespace arcmt 101 102} // end namespace clang 103 104#endif 105