]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/ARCMigrate/ARCMT.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.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 DiagnosticClient;
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 /// \returns false if no error is produced, true otherwise.
32 bool checkForManualIssues(CompilerInvocation &CI,
33                           llvm::StringRef Filename, InputKind Kind,
34                           DiagnosticClient *DiagClient);
35
36 /// \brief Works similar to checkForManualIssues but instead of checking, it
37 /// applies automatic modifications to source files to conform to ARC.
38 ///
39 /// \returns false if no error is produced, true otherwise.
40 bool applyTransformations(CompilerInvocation &origCI,
41                           llvm::StringRef Filename, InputKind Kind,
42                           DiagnosticClient *DiagClient);
43
44 /// \brief Applies automatic modifications and produces temporary files
45 /// and metadata into the \arg outputDir path.
46 ///
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);
52
53 /// \brief Get the set of file remappings from the \arg outputDir path that
54 /// migrateWithTemporaryFiles produced.
55 ///
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);
60
61 typedef void (*TransformFn)(MigrationPass &pass);
62
63 std::vector<TransformFn> getAllTransformations();
64
65 class MigrationProcess {
66   CompilerInvocation OrigCI;
67   DiagnosticClient *DiagClient;
68   FileRemapper Remapper;
69
70 public:
71   MigrationProcess(const CompilerInvocation &CI, DiagnosticClient *diagClient,
72                    llvm::StringRef outputDir = llvm::StringRef());
73
74   class RewriteListener {
75   public:
76     virtual ~RewriteListener();
77
78     virtual void start(ASTContext &Ctx) { }
79     virtual void finish() { }
80
81     virtual void insert(SourceLocation loc, llvm::StringRef text) { }
82     virtual void remove(CharSourceRange range) { }
83   };
84
85   bool applyTransform(TransformFn trans, RewriteListener *listener = 0);
86
87   FileRemapper &getRemapper() { return Remapper; }
88 };
89
90 } // end namespace arcmt
91
92 }  // end namespace clang
93
94 #endif