ARCMT.h revision 1824d54df85a462ada812dadda18130f951d40f3
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"
148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#include "clang/Frontend/CompilerInvocation.h"
158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace clang {
178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  class ASTContext;
1878ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  class DiagnosticConsumer;
198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallnamespace arcmt {
218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  class MigrationPass;
228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
238f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \brief Creates an AST with the provided CompilerInvocation but with these
248f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// changes:
258f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall///   -if a PCH/PTH is set, the original header is used instead
268f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall///   -Automatic Reference Counting mode is enabled
278f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall///
288f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// It then checks the AST and produces errors/warning for ARC migration issues
298f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// that the user needs to handle manually.
308f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall///
317ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param emitPremigrationARCErrors if true all ARC errors will get emitted
327ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// even if the migrator can fix them, but the function will still return false
337ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// if all ARC errors can be fixed.
347ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis///
357ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param plistOut if non-empty, it is the file path to store the plist with
367ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// the pre-migration ARC diagnostics.
377ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis///
388f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \returns false if no error is produced, true otherwise.
398f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool checkForManualIssues(CompilerInvocation &CI,
401f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor                          const FrontendInputFile &Input,
4178ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie                          DiagnosticConsumer *DiagClient,
427ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis                          bool emitPremigrationARCErrors = false,
43686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                          StringRef plistOut = StringRef());
448f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
458f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \brief Works similar to checkForManualIssues but instead of checking, it
468f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// applies automatic modifications to source files to conform to ARC.
478f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall///
488f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall/// \returns false if no error is produced, true otherwise.
498f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallbool applyTransformations(CompilerInvocation &origCI,
501f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor                          const FrontendInputFile &Input,
5178ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie                          DiagnosticConsumer *DiagClient);
528f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
5369325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// \brief Applies automatic modifications and produces temporary files
541824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko/// and metadata into the \p outputDir path.
5569325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis///
567ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param emitPremigrationARCErrors if true all ARC errors will get emitted
577ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// even if the migrator can fix them, but the function will still return false
587ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// if all ARC errors can be fixed.
597ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis///
607ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// \param plistOut if non-empty, it is the file path to store the plist with
617ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis/// the pre-migration ARC diagnostics.
627ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis///
6369325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// \returns false if no error is produced, true otherwise.
6469325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidisbool migrateWithTemporaryFiles(CompilerInvocation &origCI,
651f6b2b5c82b2d2d3935b0db76352a04e9877b73fDouglas Gregor                               const FrontendInputFile &Input,
6678ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie                               DiagnosticConsumer *DiagClient,
67686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               StringRef outputDir,
687ee2049278b98d42709380054eb83f4952af1200Argyrios Kyrtzidis                               bool emitPremigrationARCErrors,
69686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               StringRef plistOut);
7069325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis
711824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko/// \brief Get the set of file remappings from the \p outputDir path that
7269325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// migrateWithTemporaryFiles produced.
7369325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis///
7469325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis/// \returns false if no error is produced, true otherwise.
7569325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidisbool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
76686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                       StringRef outputDir,
7778ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie                       DiagnosticConsumer *DiagClient);
7869325d5b7cfecf1b3128745efc33612aedf1b8b4Argyrios Kyrtzidis
7930660a898545416f0fea2d717f16f75640001e38Ted Kremenek/// \brief Get the set of file remappings from a list of files with remapping
8030660a898545416f0fea2d717f16f75640001e38Ted Kremenek/// info.
8130660a898545416f0fea2d717f16f75640001e38Ted Kremenek///
8230660a898545416f0fea2d717f16f75640001e38Ted Kremenek/// \returns false if no error is produced, true otherwise.
8330660a898545416f0fea2d717f16f75640001e38Ted Kremenekbool getFileRemappingsFromFileList(
8430660a898545416f0fea2d717f16f75640001e38Ted Kremenek                        std::vector<std::pair<std::string,std::string> > &remap,
8530660a898545416f0fea2d717f16f75640001e38Ted Kremenek                        ArrayRef<StringRef> remapFiles,
8630660a898545416f0fea2d717f16f75640001e38Ted Kremenek                        DiagnosticConsumer *DiagClient);
8730660a898545416f0fea2d717f16f75640001e38Ted Kremenek
888f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCalltypedef void (*TransformFn)(MigrationPass &pass);
898f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
90bbdfad581fa300fa0d162d968ec14de3c95fc760Fariborz Jahanianstd::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
91bbdfad581fa300fa0d162d968ec14de3c95fc760Fariborz Jahanian                                               bool NoFinalizeRemoval);
928f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
938f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallclass MigrationProcess {
948f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  CompilerInvocation OrigCI;
9578ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  DiagnosticConsumer *DiagClient;
968f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  FileRemapper Remapper;
978f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
988f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCallpublic:
9978ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
100686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                   StringRef outputDir = StringRef());
1018f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
1028f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  class RewriteListener {
1038f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  public:
1048f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall    virtual ~RewriteListener();
1058f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
1068f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall    virtual void start(ASTContext &Ctx) { }
1078f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall    virtual void finish() { }
1088f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
109686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    virtual void insert(SourceLocation loc, StringRef text) { }
1108f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall    virtual void remove(CharSourceRange range) { }
1118f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  };
1128f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
1138f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
1148f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
1158f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall  FileRemapper &getRemapper() { return Remapper; }
1168f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall};
1178f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
1188f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall} // end namespace arcmt
1198f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
1208f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall}  // end namespace clang
1218f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall
1228f0e8d22960d56f8390f4971e2c0f2f0a0884602John McCall#endif
123