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/Frontend/CompilerInvocation.h"
18 class DiagnosticConsumer;
23 /// \brief Creates an AST with the provided CompilerInvocation but with these
25 /// -if a PCH/PTH is set, the original header is used instead
26 /// -Automatic Reference Counting mode is enabled
28 /// It then checks the AST and produces errors/warning for ARC migration issues
29 /// that the user needs to handle manually.
31 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
32 /// even if the migrator can fix them, but the function will still return false
33 /// if all ARC errors can be fixed.
35 /// \param plistOut if non-empty, it is the file path to store the plist with
36 /// the pre-migration ARC diagnostics.
38 /// \returns false if no error is produced, true otherwise.
39 bool checkForManualIssues(CompilerInvocation &CI,
40 StringRef Filename, InputKind Kind,
41 DiagnosticConsumer *DiagClient,
42 bool emitPremigrationARCErrors = false,
43 StringRef plistOut = StringRef());
45 /// \brief Works similar to checkForManualIssues but instead of checking, it
46 /// applies automatic modifications to source files to conform to ARC.
48 /// \returns false if no error is produced, true otherwise.
49 bool applyTransformations(CompilerInvocation &origCI,
50 StringRef Filename, InputKind Kind,
51 DiagnosticConsumer *DiagClient);
53 /// \brief Applies automatic modifications and produces temporary files
54 /// and metadata into the \arg outputDir path.
56 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
57 /// even if the migrator can fix them, but the function will still return false
58 /// if all ARC errors can be fixed.
60 /// \param plistOut if non-empty, it is the file path to store the plist with
61 /// the pre-migration ARC diagnostics.
63 /// \returns false if no error is produced, true otherwise.
64 bool migrateWithTemporaryFiles(CompilerInvocation &origCI,
65 StringRef Filename, InputKind Kind,
66 DiagnosticConsumer *DiagClient,
68 bool emitPremigrationARCErrors,
71 /// \brief Get the set of file remappings from the \arg outputDir path that
72 /// migrateWithTemporaryFiles produced.
74 /// \returns false if no error is produced, true otherwise.
75 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
77 DiagnosticConsumer *DiagClient);
79 typedef void (*TransformFn)(MigrationPass &pass);
81 std::vector<TransformFn> getAllTransformations();
83 class MigrationProcess {
84 CompilerInvocation OrigCI;
85 DiagnosticConsumer *DiagClient;
86 FileRemapper Remapper;
89 MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
90 StringRef outputDir = StringRef());
92 class RewriteListener {
94 virtual ~RewriteListener();
96 virtual void start(ASTContext &Ctx) { }
97 virtual void finish() { }
99 virtual void insert(SourceLocation loc, StringRef text) { }
100 virtual void remove(CharSourceRange range) { }
103 bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
105 FileRemapper &getRemapper() { return Remapper; }
108 } // end namespace arcmt
110 } // end namespace clang