1224135Sdim//===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===// 2224135Sdim// 3224135Sdim// The LLVM Compiler Infrastructure 4224135Sdim// 5224135Sdim// This file is distributed under the University of Illinois Open Source 6224135Sdim// License. See LICENSE.TXT for details. 7224135Sdim// 8224135Sdim//===----------------------------------------------------------------------===// 9224135Sdim 10224135Sdim#ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H 11224135Sdim#define LLVM_CLANG_ARCMIGRATE_ARCMT_H 12224135Sdim 13224135Sdim#include "clang/ARCMigrate/FileRemapper.h" 14252723Sdim#include "clang/Basic/SourceLocation.h" 15224135Sdim#include "clang/Frontend/CompilerInvocation.h" 16224135Sdim 17224135Sdimnamespace clang { 18224135Sdim class ASTContext; 19226890Sdim class DiagnosticConsumer; 20224135Sdim 21224135Sdimnamespace arcmt { 22224135Sdim class MigrationPass; 23224135Sdim 24224135Sdim/// \brief Creates an AST with the provided CompilerInvocation but with these 25224135Sdim/// changes: 26224135Sdim/// -if a PCH/PTH is set, the original header is used instead 27224135Sdim/// -Automatic Reference Counting mode is enabled 28224135Sdim/// 29224135Sdim/// It then checks the AST and produces errors/warning for ARC migration issues 30224135Sdim/// that the user needs to handle manually. 31224135Sdim/// 32226890Sdim/// \param emitPremigrationARCErrors if true all ARC errors will get emitted 33226890Sdim/// even if the migrator can fix them, but the function will still return false 34226890Sdim/// if all ARC errors can be fixed. 35226890Sdim/// 36226890Sdim/// \param plistOut if non-empty, it is the file path to store the plist with 37226890Sdim/// the pre-migration ARC diagnostics. 38226890Sdim/// 39224135Sdim/// \returns false if no error is produced, true otherwise. 40224135Sdimbool checkForManualIssues(CompilerInvocation &CI, 41235633Sdim const FrontendInputFile &Input, 42226890Sdim DiagnosticConsumer *DiagClient, 43226890Sdim bool emitPremigrationARCErrors = false, 44226890Sdim StringRef plistOut = StringRef()); 45224135Sdim 46224135Sdim/// \brief Works similar to checkForManualIssues but instead of checking, it 47224135Sdim/// applies automatic modifications to source files to conform to ARC. 48224135Sdim/// 49224135Sdim/// \returns false if no error is produced, true otherwise. 50224135Sdimbool applyTransformations(CompilerInvocation &origCI, 51235633Sdim const FrontendInputFile &Input, 52226890Sdim DiagnosticConsumer *DiagClient); 53224135Sdim 54224135Sdim/// \brief Applies automatic modifications and produces temporary files 55245431Sdim/// and metadata into the \p outputDir path. 56224135Sdim/// 57226890Sdim/// \param emitPremigrationARCErrors if true all ARC errors will get emitted 58226890Sdim/// even if the migrator can fix them, but the function will still return false 59226890Sdim/// if all ARC errors can be fixed. 60226890Sdim/// 61226890Sdim/// \param plistOut if non-empty, it is the file path to store the plist with 62226890Sdim/// the pre-migration ARC diagnostics. 63226890Sdim/// 64224135Sdim/// \returns false if no error is produced, true otherwise. 65224135Sdimbool migrateWithTemporaryFiles(CompilerInvocation &origCI, 66235633Sdim const FrontendInputFile &Input, 67226890Sdim DiagnosticConsumer *DiagClient, 68226890Sdim StringRef outputDir, 69226890Sdim bool emitPremigrationARCErrors, 70226890Sdim StringRef plistOut); 71224135Sdim 72245431Sdim/// \brief Get the set of file remappings from the \p outputDir path that 73224135Sdim/// migrateWithTemporaryFiles produced. 74224135Sdim/// 75224135Sdim/// \returns false if no error is produced, true otherwise. 76224135Sdimbool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap, 77226890Sdim StringRef outputDir, 78226890Sdim DiagnosticConsumer *DiagClient); 79224135Sdim 80235633Sdim/// \brief Get the set of file remappings from a list of files with remapping 81235633Sdim/// info. 82235633Sdim/// 83235633Sdim/// \returns false if no error is produced, true otherwise. 84235633Sdimbool getFileRemappingsFromFileList( 85235633Sdim std::vector<std::pair<std::string,std::string> > &remap, 86235633Sdim ArrayRef<StringRef> remapFiles, 87235633Sdim DiagnosticConsumer *DiagClient); 88235633Sdim 89224135Sdimtypedef void (*TransformFn)(MigrationPass &pass); 90224135Sdim 91235633Sdimstd::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode, 92235633Sdim bool NoFinalizeRemoval); 93224135Sdim 94224135Sdimclass MigrationProcess { 95224135Sdim CompilerInvocation OrigCI; 96226890Sdim DiagnosticConsumer *DiagClient; 97224135Sdim FileRemapper Remapper; 98224135Sdim 99224135Sdimpublic: 100263509Sdim bool HadARCErrors; 101263509Sdim 102226890Sdim MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient, 103226890Sdim StringRef outputDir = StringRef()); 104224135Sdim 105224135Sdim class RewriteListener { 106224135Sdim public: 107224135Sdim virtual ~RewriteListener(); 108224135Sdim 109224135Sdim virtual void start(ASTContext &Ctx) { } 110224135Sdim virtual void finish() { } 111224135Sdim 112226890Sdim virtual void insert(SourceLocation loc, StringRef text) { } 113224135Sdim virtual void remove(CharSourceRange range) { } 114224135Sdim }; 115224135Sdim 116224135Sdim bool applyTransform(TransformFn trans, RewriteListener *listener = 0); 117224135Sdim 118224135Sdim FileRemapper &getRemapper() { return Remapper; } 119224135Sdim}; 120224135Sdim 121224135Sdim} // end namespace arcmt 122224135Sdim 123224135Sdim} // end namespace clang 124224135Sdim 125224135Sdim#endif 126