Home | History | Annotate | Download | only in ARCMigrate
      1 //===-- ARCMT.h - ARC Migration Rewriter ------------------------*- 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_ARCMIGRATE_ARCMT_H
     11 #define LLVM_CLANG_ARCMIGRATE_ARCMT_H
     12 
     13 #include "clang/ARCMigrate/FileRemapper.h"
     14 #include "clang/Frontend/CompilerInvocation.h"
     15 
     16 namespace clang {
     17   class ASTContext;
     18   class DiagnosticConsumer;
     19 
     20 namespace arcmt {
     21   class MigrationPass;
     22 
     23 /// \brief Creates an AST with the provided CompilerInvocation but with these
     24 /// changes:
     25 ///   -if a PCH/PTH is set, the original header is used instead
     26 ///   -Automatic Reference Counting mode is enabled
     27 ///
     28 /// It then checks the AST and produces errors/warning for ARC migration issues
     29 /// that the user needs to handle manually.
     30 ///
     31 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
     32 /// even if the migrator can fix them, but the function will still return false
     33 /// if all ARC errors can be fixed.
     34 ///
     35 /// \param plistOut if non-empty, it is the file path to store the plist with
     36 /// the pre-migration ARC diagnostics.
     37 ///
     38 /// \returns false if no error is produced, true otherwise.
     39 bool checkForManualIssues(CompilerInvocation &CI,
     40                           const FrontendInputFile &Input,
     41                           DiagnosticConsumer *DiagClient,
     42                           bool emitPremigrationARCErrors = false,
     43                           StringRef plistOut = StringRef());
     44 
     45 /// \brief Works similar to checkForManualIssues but instead of checking, it
     46 /// applies automatic modifications to source files to conform to ARC.
     47 ///
     48 /// \returns false if no error is produced, true otherwise.
     49 bool applyTransformations(CompilerInvocation &origCI,
     50                           const FrontendInputFile &Input,
     51                           DiagnosticConsumer *DiagClient);
     52 
     53 /// \brief Applies automatic modifications and produces temporary files
     54 /// and metadata into the \arg outputDir path.
     55 ///
     56 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
     57 /// even if the migrator can fix them, but the function will still return false
     58 /// if all ARC errors can be fixed.
     59 ///
     60 /// \param plistOut if non-empty, it is the file path to store the plist with
     61 /// the pre-migration ARC diagnostics.
     62 ///
     63 /// \returns false if no error is produced, true otherwise.
     64 bool migrateWithTemporaryFiles(CompilerInvocation &origCI,
     65                                const FrontendInputFile &Input,
     66                                DiagnosticConsumer *DiagClient,
     67                                StringRef outputDir,
     68                                bool emitPremigrationARCErrors,
     69                                StringRef plistOut);
     70 
     71 /// \brief Get the set of file remappings from the \arg outputDir path that
     72 /// migrateWithTemporaryFiles produced.
     73 ///
     74 /// \returns false if no error is produced, true otherwise.
     75 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
     76                        StringRef outputDir,
     77                        DiagnosticConsumer *DiagClient);
     78 
     79 /// \brief Get the set of file remappings from a list of files with remapping
     80 /// info.
     81 ///
     82 /// \returns false if no error is produced, true otherwise.
     83 bool getFileRemappingsFromFileList(
     84                         std::vector<std::pair<std::string,std::string> > &remap,
     85                         ArrayRef<StringRef> remapFiles,
     86                         DiagnosticConsumer *DiagClient);
     87 
     88 typedef void (*TransformFn)(MigrationPass &pass);
     89 
     90 std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
     91                                                bool NoFinalizeRemoval);
     92 
     93 class MigrationProcess {
     94   CompilerInvocation OrigCI;
     95   DiagnosticConsumer *DiagClient;
     96   FileRemapper Remapper;
     97 
     98 public:
     99   MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
    100                    StringRef outputDir = StringRef());
    101 
    102   class RewriteListener {
    103   public:
    104     virtual ~RewriteListener();
    105 
    106     virtual void start(ASTContext &Ctx) { }
    107     virtual void finish() { }
    108 
    109     virtual void insert(SourceLocation loc, StringRef text) { }
    110     virtual void remove(CharSourceRange range) { }
    111   };
    112 
    113   bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
    114 
    115   FileRemapper &getRemapper() { return Remapper; }
    116 };
    117 
    118 } // end namespace arcmt
    119 
    120 }  // end namespace clang
    121 
    122 #endif
    123