Home | History | Annotate | Download | only in ARCMigrate
      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 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);
     41 
     42 void removeEmptyStatementsAndDealloc(MigrationPass &pass);
     43 
     44 //===----------------------------------------------------------------------===//
     45 // Helpers.
     46 //===----------------------------------------------------------------------===//
     47 
     48 /// \brief Determine whether we can add weak to the given type.
     49 bool canApplyWeak(ASTContext &Ctx, QualType type);
     50 
     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);
     58 bool isGlobalVar(Expr *E);
     59 
     60 
     61 template <typename BODY_TRANS>
     62 class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {
     63   MigrationPass &Pass;
     64 
     65 public:
     66   BodyTransform(MigrationPass &pass) : Pass(pass) { }
     67 
     68   bool TraverseStmt(Stmt *rootS) {
     69     if (rootS)
     70       BODY_TRANS(Pass).transformBody(rootS);
     71     return true;
     72   }
     73 };
     74 
     75 typedef llvm::DenseSet<Expr *> ExprSet;
     76 
     77 void clearRefsIn(Stmt *S, ExprSet &refs);
     78 template <typename iterator>
     79 void clearRefsIn(iterator begin, iterator end, ExprSet &refs) {
     80   for (; begin != end; ++begin)
     81     clearRefsIn(*begin, refs);
     82 }
     83 
     84 void collectRefs(ValueDecl *D, Stmt *S, ExprSet &refs);
     85 
     86 void collectRemovables(Stmt *S, ExprSet &exprs);
     87 
     88 } // end namespace trans
     89 
     90 } // end namespace arcmt
     91 
     92 } // end namespace clang
     93 
     94 #endif
     95