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