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