]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/ARCMigrate/ARCMT.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / include / clang / ARCMigrate / ARCMT.h
1 //===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H
11 #define LLVM_CLANG_ARCMIGRATE_ARCMT_H
12
13 #include "clang/ARCMigrate/FileRemapper.h"
14 #include "clang/Frontend/CompilerInvocation.h"
15
16 namespace clang {
17   class ASTContext;
18   class DiagnosticConsumer;
19
20 namespace arcmt {
21   class MigrationPass;
22
23 /// \brief Creates an AST with the provided CompilerInvocation but with these
24 /// changes:
25 ///   -if a PCH/PTH is set, the original header is used instead
26 ///   -Automatic Reference Counting mode is enabled
27 ///
28 /// It then checks the AST and produces errors/warning for ARC migration issues
29 /// that the user needs to handle manually.
30 ///
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.
34 ///
35 /// \param plistOut if non-empty, it is the file path to store the plist with
36 /// the pre-migration ARC diagnostics.
37 ///
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());
44
45 /// \brief Works similar to checkForManualIssues but instead of checking, it
46 /// applies automatic modifications to source files to conform to ARC.
47 ///
48 /// \returns false if no error is produced, true otherwise.
49 bool applyTransformations(CompilerInvocation &origCI,
50                           StringRef Filename, InputKind Kind,
51                           DiagnosticConsumer *DiagClient);
52
53 /// \brief Applies automatic modifications and produces temporary files
54 /// and metadata into the \arg outputDir path.
55 ///
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.
59 ///
60 /// \param plistOut if non-empty, it is the file path to store the plist with
61 /// the pre-migration ARC diagnostics.
62 ///
63 /// \returns false if no error is produced, true otherwise.
64 bool migrateWithTemporaryFiles(CompilerInvocation &origCI,
65                                StringRef Filename, InputKind Kind,
66                                DiagnosticConsumer *DiagClient,
67                                StringRef outputDir,
68                                bool emitPremigrationARCErrors,
69                                StringRef plistOut);
70
71 /// \brief Get the set of file remappings from the \arg outputDir path that
72 /// migrateWithTemporaryFiles produced.
73 ///
74 /// \returns false if no error is produced, true otherwise.
75 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
76                        StringRef outputDir,
77                        DiagnosticConsumer *DiagClient);
78
79 typedef void (*TransformFn)(MigrationPass &pass);
80
81 std::vector<TransformFn> getAllTransformations();
82
83 class MigrationProcess {
84   CompilerInvocation OrigCI;
85   DiagnosticConsumer *DiagClient;
86   FileRemapper Remapper;
87
88 public:
89   MigrationProcess(const CompilerInvocation &CI, DiagnosticConsumer *diagClient,
90                    StringRef outputDir = StringRef());
91
92   class RewriteListener {
93   public:
94     virtual ~RewriteListener();
95
96     virtual void start(ASTContext &Ctx) { }
97     virtual void finish() { }
98
99     virtual void insert(SourceLocation loc, StringRef text) { }
100     virtual void remove(CharSourceRange range) { }
101   };
102
103   bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
104
105   FileRemapper &getRemapper() { return Remapper; }
106 };
107
108 } // end namespace arcmt
109
110 }  // end namespace clang
111
112 #endif