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); |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 34 | void makeAssignARCSafe(MigrationPass &pass); |
| 35 | void removeRetainReleaseDealloc(MigrationPass &pass); |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 36 | void removeZeroOutPropsInDealloc(MigrationPass &pass); |
Argyrios Kyrtzidis | 14c4b44 | 2011-07-13 19:22:00 +0000 | [diff] [blame] | 37 | void rewriteProperties(MigrationPass &pass); |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 38 | void rewriteBlockObjCVariable(MigrationPass &pass); |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 39 | void rewriteUnusedInitDelegate(MigrationPass &pass); |
Argyrios Kyrtzidis | fd10398 | 2011-07-18 07:44:45 +0000 | [diff] [blame] | 40 | void checkAPIUses(MigrationPass &pass); |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 41 | |
Argyrios Kyrtzidis | fd3455a | 2011-06-21 20:20:42 +0000 | [diff] [blame] | 42 | void removeEmptyStatementsAndDealloc(MigrationPass &pass); |
| 43 | |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 44 | //===----------------------------------------------------------------------===// |
| 45 | // Helpers. |
| 46 | //===----------------------------------------------------------------------===// |
| 47 | |
Argyrios Kyrtzidis | 86625b5 | 2011-07-12 22:05:17 +0000 | [diff] [blame] | 48 | /// \brief Determine whether we can add weak to the given type. |
| 49 | bool canApplyWeak(ASTContext &Ctx, QualType type); |
| 50 | |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 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); |
| 56 | |
| 57 | bool hasSideEffects(Expr *E, ASTContext &Ctx); |
Argyrios Kyrtzidis | 2c18ca0 | 2011-07-14 23:32:04 +0000 | [diff] [blame] | 58 | bool isGlobalVar(Expr *E); |
Argyrios Kyrtzidis | 18fd0c6 | 2011-07-27 05:28:18 +0000 | [diff] [blame^] | 59 | /// \brief Returns "nil" or "0" if 'nil' macro is not actually defined. |
| 60 | StringRef getNilString(ASTContext &Ctx); |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 61 | |
| 62 | template <typename BODY_TRANS> |
| 63 | class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > { |
| 64 | MigrationPass &Pass; |
| 65 | |
| 66 | public: |
| 67 | BodyTransform(MigrationPass &pass) : Pass(pass) { } |
| 68 | |
Argyrios Kyrtzidis | b1094a0 | 2011-06-23 21:21:33 +0000 | [diff] [blame] | 69 | bool TraverseStmt(Stmt *rootS) { |
Argyrios Kyrtzidis | fd10398 | 2011-07-18 07:44:45 +0000 | [diff] [blame] | 70 | if (rootS) |
| 71 | BODY_TRANS(Pass).transformBody(rootS); |
Argyrios Kyrtzidis | 7196d06 | 2011-06-21 20:20:39 +0000 | [diff] [blame] | 72 | return true; |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | typedef llvm::DenseSet<Expr *> ExprSet; |
| 77 | |
| 78 | void clearRefsIn(Stmt *S, ExprSet &refs); |
| 79 | template <typename iterator> |
| 80 | void clearRefsIn(iterator begin, iterator end, ExprSet &refs) { |
| 81 | for (; begin != end; ++begin) |
| 82 | clearRefsIn(*begin, refs); |
| 83 | } |
| 84 | |
| 85 | void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs); |
| 86 | |
| 87 | void collectRemovables(Stmt *S, ExprSet &exprs); |
| 88 | |
| 89 | } // end namespace trans |
| 90 | |
| 91 | } // end namespace arcmt |
| 92 | |
| 93 | } // end namespace clang |
| 94 | |
| 95 | #endif |