18f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===// 28f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// 38f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// The LLVM Compiler Infrastructure 48f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// 58f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// This file is distributed under the University of Illinois Open Source 68f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// License. See LICENSE.TXT for details. 78f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall// 88f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall//===----------------------------------------------------------------------===// 98f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H 118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#define LLVM_CLANG_ARCMIGRATE_ARCMT_H 128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "clang/ARCMigrate/FileRemapper.h" 14dc7b641574a733624489bd87fc7061771edf2113Douglas Gregor#include "clang/Basic/SourceLocation.h" 1530a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Frontend/CompilerInvocation.h" 168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace clang { 188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall class ASTContext; 1978ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie class DiagnosticConsumer; 208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace arcmt { 228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall class MigrationPass; 238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \brief Creates an AST with the provided CompilerInvocation but with these 258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// changes: 268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// -if a PCH/PTH is set, the original header is used instead 278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// -Automatic Reference Counting mode is enabled 288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// 298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// It then checks the AST and produces errors/warning for ARC migration issues 308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// that the user needs to handle manually. 318f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// 327ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param emitPremigrationARCErrors if true all ARC errors will get emitted 337ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// even if the migrator can fix them, but the function will still return false 347ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// if all ARC errors can be fixed. 357ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// 367ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param plistOut if non-empty, it is the file path to store the plist with 377ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// the pre-migration ARC diagnostics. 387ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// 398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \returns false if no error is produced, true otherwise. 408f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool checkForManualIssues(CompilerInvocation &CI, 411f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor const FrontendInputFile &Input, 4278ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *DiagClient, 437ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis bool emitPremigrationARCErrors = false, 44686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef plistOut = StringRef()); 458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \brief Works similar to checkForManualIssues but instead of checking, it 478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// applies automatic modifications to source files to conform to ARC. 488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// 498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \returns false if no error is produced, true otherwise. 508f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool applyTransformations(CompilerInvocation &origCI, 511f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor const FrontendInputFile &Input, 5278ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *DiagClient); 538f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 5469325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// \brief Applies automatic modifications and produces temporary files 551824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko/// and metadata into the \p outputDir path. 5669325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// 577ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param emitPremigrationARCErrors if true all ARC errors will get emitted 587ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// even if the migrator can fix them, but the function will still return false 597ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// if all ARC errors can be fixed. 607ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// 617ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param plistOut if non-empty, it is the file path to store the plist with 627ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// the pre-migration ARC diagnostics. 637ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// 6469325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// \returns false if no error is produced, true otherwise. 6569325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidisbool migrateWithTemporaryFiles(CompilerInvocation &origCI, 661f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor const FrontendInputFile &Input, 6778ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *DiagClient, 68686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef outputDir, 697ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis bool emitPremigrationARCErrors, 70686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef plistOut); 7169325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis 721824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko/// \brief Get the set of file remappings from the \p outputDir path that 7369325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// migrateWithTemporaryFiles produced. 7469325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// 7569325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// \returns false if no error is produced, true otherwise. 7669325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidisbool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap, 77686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef outputDir, 7878ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *DiagClient); 7969325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis 8030660a898545416f0fea2d717f16f75640001e38Ted Kremenek/// \brief Get the set of file remappings from a list of files with remapping 8130660a898545416f0fea2d717f16f75640001e38Ted Kremenek/// info. 8230660a898545416f0fea2d717f16f75640001e38Ted Kremenek/// 8330660a898545416f0fea2d717f16f75640001e38Ted Kremenek/// \returns false if no error is produced, true otherwise. 8430660a898545416f0fea2d717f16f75640001e38Ted Kremenekbool getFileRemappingsFromFileList( 8530660a898545416f0fea2d717f16f75640001e38Ted Kremenek std::vector<std::pair<std::string,std::string> > &remap, 8630660a898545416f0fea2d717f16f75640001e38Ted Kremenek ArrayRef<StringRef> remapFiles, 8730660a898545416f0fea2d717f16f75640001e38Ted Kremenek DiagnosticConsumer *DiagClient); 8830660a898545416f0fea2d717f16f75640001e38Ted Kremenek 898f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCalltypedef void (*TransformFn)(MigrationPass &pass); 908f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 91bbdfad581fa300fa0d162d968ec14de3c95fc760Fariborz Jahanianstd::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode, 92bbdfad581fa300fa0d162d968ec14de3c95fc760Fariborz Jahanian bool NoFinalizeRemoval); 938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 948f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallclass MigrationProcess { 958f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall CompilerInvocation OrigCI; 9678ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *DiagClient; 978f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall FileRemapper Remapper; 988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 998f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallpublic: 1000474cfdba79f8a89016fbcdc4f7d8aabe00f9456Argyrios Kyrtzidis bool HadARCErrors; 1010474cfdba79f8a89016fbcdc4f7d8aabe00f9456Argyrios Kyrtzidis 10278ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient, 103686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef outputDir = StringRef()); 1048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1058f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall class RewriteListener { 1068f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall public: 1078f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall virtual ~RewriteListener(); 1088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1098f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall virtual void start(ASTContext &Ctx) { } 1108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall virtual void finish() { } 1118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 112686775deca8b8685eb90801495880e3abdd844c2Chris Lattner virtual void insert(SourceLocation loc, StringRef text) { } 1138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall virtual void remove(CharSourceRange range) { } 1148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall }; 1158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr); 1178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall FileRemapper &getRemapper() { return Remapper; } 1198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall}; 1208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} // end namespace arcmt 1228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} // end namespace clang 1248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall 1258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#endif 126