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 DiagnosticClient;
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 /// \returns false if no error is produced, true otherwise.
32 bool checkForManualIssues(CompilerInvocation &CI,
33 llvm::StringRef Filename, InputKind Kind,
34 DiagnosticClient *DiagClient);
36 /// \brief Works similar to checkForManualIssues but instead of checking, it
37 /// applies automatic modifications to source files to conform to ARC.
39 /// \returns false if no error is produced, true otherwise.
40 bool applyTransformations(CompilerInvocation &origCI,
41 llvm::StringRef Filename, InputKind Kind,
42 DiagnosticClient *DiagClient);
44 /// \brief Applies automatic modifications and produces temporary files
45 /// and metadata into the \arg outputDir path.
47 /// \returns false if no error is produced, true otherwise.
48 bool migrateWithTemporaryFiles(CompilerInvocation &origCI,
49 llvm::StringRef Filename, InputKind Kind,
50 DiagnosticClient *DiagClient,
51 llvm::StringRef outputDir);
53 /// \brief Get the set of file remappings from the \arg outputDir path that
54 /// migrateWithTemporaryFiles produced.
56 /// \returns false if no error is produced, true otherwise.
57 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
58 llvm::StringRef outputDir,
59 DiagnosticClient *DiagClient);
61 typedef void (*TransformFn)(MigrationPass &pass);
63 std::vector<TransformFn> getAllTransformations();
65 class MigrationProcess {
66 CompilerInvocation OrigCI;
67 DiagnosticClient *DiagClient;
68 FileRemapper Remapper;
71 MigrationProcess(const CompilerInvocation &CI, DiagnosticClient *diagClient,
72 llvm::StringRef outputDir = llvm::StringRef());
74 class RewriteListener {
76 virtual ~RewriteListener();
78 virtual void start(ASTContext &Ctx) { }
79 virtual void finish() { }
81 virtual void insert(SourceLocation loc, llvm::StringRef text) { }
82 virtual void remove(CharSourceRange range) { }
85 bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
87 FileRemapper &getRemapper() { return Remapper; }
90 } // end namespace arcmt
92 } // end namespace clang