1 //===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H
11 #define LLVM_CLANG_ARCMIGRATE_ARCMT_H
13 #include "clang/ARCMigrate/FileRemapper.h"
14 #include "clang/Basic/SourceLocation.h"
15 #include "clang/Frontend/CompilerInvocation.h"
19 class DiagnosticConsumer;
24 /// \brief Creates an AST with the provided CompilerInvocation but with these
26 /// -if a PCH/PTH is set, the original header is used instead
27 /// -Automatic Reference Counting mode is enabled
29 /// It then checks the AST and produces errors/warning for ARC migration issues
30 /// that the user needs to handle manually.
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.
36 /// \param plistOut if non-empty, it is the file path to store the plist with
37 /// the pre-migration ARC diagnostics.
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());
46 /// \brief Works similar to checkForManualIssues but instead of checking, it
47 /// applies automatic modifications to source files to conform to ARC.
49 /// \returns false if no error is produced, true otherwise.
50 bool applyTransformations(CompilerInvocation &origCI,
51 const FrontendInputFile &Input,
52 DiagnosticConsumer *DiagClient);
54 /// \brief Applies automatic modifications and produces temporary files
55 /// and metadata into the \p outputDir path.
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.
61 /// \param plistOut if non-empty, it is the file path to store the plist with
62 /// the pre-migration ARC diagnostics.
64 /// \returns false if no error is produced, true otherwise.
65 bool migrateWithTemporaryFiles(CompilerInvocation &origCI,
66 const FrontendInputFile &Input,
67 DiagnosticConsumer *DiagClient,
69 bool emitPremigrationARCErrors,
72 /// \brief Get the set of file remappings from the \p outputDir path that
73 /// migrateWithTemporaryFiles produced.
75 /// \returns false if no error is produced, true otherwise.
76 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
78 DiagnosticConsumer *DiagClient);
80 /// \brief Get the set of file remappings from a list of files with remapping
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);
89 typedef void (*TransformFn)(MigrationPass &pass);
91 std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
92 bool NoFinalizeRemoval);
94 class MigrationProcess {
95 CompilerInvocation OrigCI;
96 DiagnosticConsumer *DiagClient;
97 FileRemapper Remapper;
102 MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
103 StringRef outputDir = StringRef());
105 class RewriteListener {
107 virtual ~RewriteListener();
109 virtual void start(ASTContext &Ctx) { }
110 virtual void finish() { }
112 virtual void insert(SourceLocation loc, StringRef text) { }
113 virtual void remove(CharSourceRange range) { }
116 bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
118 FileRemapper &getRemapper() { return Remapper; }
121 } // end namespace arcmt
123 } // end namespace clang