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;
20 class PCHContainerOperations;
25 /// \brief Creates an AST with the provided CompilerInvocation but with these
27 /// -if a PCH/PTH is set, the original header is used instead
28 /// -Automatic Reference Counting mode is enabled
30 /// It then checks the AST and produces errors/warning for ARC migration issues
31 /// that the user needs to handle manually.
33 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
34 /// even if the migrator can fix them, but the function will still return false
35 /// if all ARC errors can be fixed.
37 /// \param plistOut if non-empty, it is the file path to store the plist with
38 /// the pre-migration ARC diagnostics.
40 /// \returns false if no error is produced, true otherwise.
42 checkForManualIssues(CompilerInvocation &CI, const FrontendInputFile &Input,
43 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
44 DiagnosticConsumer *DiagClient,
45 bool emitPremigrationARCErrors = false,
46 StringRef plistOut = StringRef());
48 /// \brief Works similar to checkForManualIssues but instead of checking, it
49 /// applies automatic modifications to source files to conform to ARC.
51 /// \returns false if no error is produced, true otherwise.
53 applyTransformations(CompilerInvocation &origCI,
54 const FrontendInputFile &Input,
55 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
56 DiagnosticConsumer *DiagClient);
58 /// \brief Applies automatic modifications and produces temporary files
59 /// and metadata into the \p outputDir path.
61 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
62 /// even if the migrator can fix them, but the function will still return false
63 /// if all ARC errors can be fixed.
65 /// \param plistOut if non-empty, it is the file path to store the plist with
66 /// the pre-migration ARC diagnostics.
68 /// \returns false if no error is produced, true otherwise.
69 bool migrateWithTemporaryFiles(
70 CompilerInvocation &origCI, const FrontendInputFile &Input,
71 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
72 DiagnosticConsumer *DiagClient, StringRef outputDir,
73 bool emitPremigrationARCErrors, StringRef plistOut);
75 /// \brief Get the set of file remappings from the \p outputDir path that
76 /// migrateWithTemporaryFiles produced.
78 /// \returns false if no error is produced, true otherwise.
79 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
81 DiagnosticConsumer *DiagClient);
83 /// \brief Get the set of file remappings from a list of files with remapping
86 /// \returns false if no error is produced, true otherwise.
87 bool getFileRemappingsFromFileList(
88 std::vector<std::pair<std::string,std::string> > &remap,
89 ArrayRef<StringRef> remapFiles,
90 DiagnosticConsumer *DiagClient);
92 typedef void (*TransformFn)(MigrationPass &pass);
94 std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
95 bool NoFinalizeRemoval);
97 class MigrationProcess {
98 CompilerInvocation OrigCI;
99 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
100 DiagnosticConsumer *DiagClient;
101 FileRemapper Remapper;
106 MigrationProcess(const CompilerInvocation &CI,
107 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
108 DiagnosticConsumer *diagClient,
109 StringRef outputDir = StringRef());
111 class RewriteListener {
113 virtual ~RewriteListener();
115 virtual void start(ASTContext &Ctx) { }
116 virtual void finish() { }
118 virtual void insert(SourceLocation loc, StringRef text) { }
119 virtual void remove(CharSourceRange range) { }
122 bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr);
124 FileRemapper &getRemapper() { return Remapper; }
127 } // end namespace arcmt
129 } // end namespace clang