1224135Sdim//===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===//
2224135Sdim//
3224135Sdim//                     The LLVM Compiler Infrastructure
4224135Sdim//
5224135Sdim// This file is distributed under the University of Illinois Open Source
6224135Sdim// License. See LICENSE.TXT for details.
7224135Sdim//
8224135Sdim//===----------------------------------------------------------------------===//
9224135Sdim
10224135Sdim#ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H
11224135Sdim#define LLVM_CLANG_ARCMIGRATE_ARCMT_H
12224135Sdim
13224135Sdim#include "clang/ARCMigrate/FileRemapper.h"
14249423Sdim#include "clang/Basic/SourceLocation.h"
15224135Sdim#include "clang/Frontend/CompilerInvocation.h"
16224135Sdim
17224135Sdimnamespace clang {
18224135Sdim  class ASTContext;
19226633Sdim  class DiagnosticConsumer;
20224135Sdim
21224135Sdimnamespace arcmt {
22224135Sdim  class MigrationPass;
23224135Sdim
24224135Sdim/// \brief Creates an AST with the provided CompilerInvocation but with these
25224135Sdim/// changes:
26224135Sdim///   -if a PCH/PTH is set, the original header is used instead
27224135Sdim///   -Automatic Reference Counting mode is enabled
28224135Sdim///
29224135Sdim/// It then checks the AST and produces errors/warning for ARC migration issues
30224135Sdim/// that the user needs to handle manually.
31224135Sdim///
32226633Sdim/// \param emitPremigrationARCErrors if true all ARC errors will get emitted
33226633Sdim/// even if the migrator can fix them, but the function will still return false
34226633Sdim/// if all ARC errors can be fixed.
35226633Sdim///
36226633Sdim/// \param plistOut if non-empty, it is the file path to store the plist with
37226633Sdim/// the pre-migration ARC diagnostics.
38226633Sdim///
39224135Sdim/// \returns false if no error is produced, true otherwise.
40224135Sdimbool checkForManualIssues(CompilerInvocation &CI,
41234353Sdim                          const FrontendInputFile &Input,
42226633Sdim                          DiagnosticConsumer *DiagClient,
43226633Sdim                          bool emitPremigrationARCErrors = false,
44226633Sdim                          StringRef plistOut = StringRef());
45224135Sdim
46224135Sdim/// \brief Works similar to checkForManualIssues but instead of checking, it
47224135Sdim/// applies automatic modifications to source files to conform to ARC.
48224135Sdim///
49224135Sdim/// \returns false if no error is produced, true otherwise.
50224135Sdimbool applyTransformations(CompilerInvocation &origCI,
51234353Sdim                          const FrontendInputFile &Input,
52226633Sdim                          DiagnosticConsumer *DiagClient);
53224135Sdim
54224135Sdim/// \brief Applies automatic modifications and produces temporary files
55243830Sdim/// and metadata into the \p outputDir path.
56224135Sdim///
57226633Sdim/// \param emitPremigrationARCErrors if true all ARC errors will get emitted
58226633Sdim/// even if the migrator can fix them, but the function will still return false
59226633Sdim/// if all ARC errors can be fixed.
60226633Sdim///
61226633Sdim/// \param plistOut if non-empty, it is the file path to store the plist with
62226633Sdim/// the pre-migration ARC diagnostics.
63226633Sdim///
64224135Sdim/// \returns false if no error is produced, true otherwise.
65224135Sdimbool migrateWithTemporaryFiles(CompilerInvocation &origCI,
66234353Sdim                               const FrontendInputFile &Input,
67226633Sdim                               DiagnosticConsumer *DiagClient,
68226633Sdim                               StringRef outputDir,
69226633Sdim                               bool emitPremigrationARCErrors,
70226633Sdim                               StringRef plistOut);
71224135Sdim
72243830Sdim/// \brief Get the set of file remappings from the \p outputDir path that
73224135Sdim/// migrateWithTemporaryFiles produced.
74224135Sdim///
75224135Sdim/// \returns false if no error is produced, true otherwise.
76224135Sdimbool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
77226633Sdim                       StringRef outputDir,
78226633Sdim                       DiagnosticConsumer *DiagClient);
79224135Sdim
80234353Sdim/// \brief Get the set of file remappings from a list of files with remapping
81234353Sdim/// info.
82234353Sdim///
83234353Sdim/// \returns false if no error is produced, true otherwise.
84234353Sdimbool getFileRemappingsFromFileList(
85234353Sdim                        std::vector<std::pair<std::string,std::string> > &remap,
86234353Sdim                        ArrayRef<StringRef> remapFiles,
87234353Sdim                        DiagnosticConsumer *DiagClient);
88234353Sdim
89224135Sdimtypedef void (*TransformFn)(MigrationPass &pass);
90224135Sdim
91234353Sdimstd::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
92234353Sdim                                               bool NoFinalizeRemoval);
93224135Sdim
94224135Sdimclass MigrationProcess {
95224135Sdim  CompilerInvocation OrigCI;
96226633Sdim  DiagnosticConsumer *DiagClient;
97224135Sdim  FileRemapper Remapper;
98224135Sdim
99224135Sdimpublic:
100263508Sdim  bool HadARCErrors;
101263508Sdim
102226633Sdim  MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
103226633Sdim                   StringRef outputDir = StringRef());
104224135Sdim
105224135Sdim  class RewriteListener {
106224135Sdim  public:
107224135Sdim    virtual ~RewriteListener();
108224135Sdim
109224135Sdim    virtual void start(ASTContext &Ctx) { }
110224135Sdim    virtual void finish() { }
111224135Sdim
112226633Sdim    virtual void insert(SourceLocation loc, StringRef text) { }
113224135Sdim    virtual void remove(CharSourceRange range) { }
114224135Sdim  };
115224135Sdim
116224135Sdim  bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
117224135Sdim
118224135Sdim  FileRemapper &getRemapper() { return Remapper; }
119224135Sdim};
120224135Sdim
121224135Sdim} // end namespace arcmt
122224135Sdim
123224135Sdim}  // end namespace clang
124224135Sdim
125224135Sdim#endif
126