clang  6.0.0svn
ARCMT.h
Go to the documentation of this file.
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 
16 
17 namespace clang {
18  class ASTContext;
19  class DiagnosticConsumer;
20  class PCHContainerOperations;
21 
22 namespace arcmt {
23  class MigrationPass;
24 
25 /// \brief Creates an AST with the provided CompilerInvocation but with these
26 /// changes:
27 /// -if a PCH/PTH is set, the original header is used instead
28 /// -Automatic Reference Counting mode is enabled
29 ///
30 /// It then checks the AST and produces errors/warning for ARC migration issues
31 /// that the user needs to handle manually.
32 ///
33 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
34 /// even if the migrator can fix them, but the function will still return false
35 /// if all ARC errors can be fixed.
36 ///
37 /// \param plistOut if non-empty, it is the file path to store the plist with
38 /// the pre-migration ARC diagnostics.
39 ///
40 /// \returns false if no error is produced, true otherwise.
41 bool
43  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
44  DiagnosticConsumer *DiagClient,
45  bool emitPremigrationARCErrors = false,
46  StringRef plistOut = StringRef());
47 
48 /// \brief Works similar to checkForManualIssues but instead of checking, it
49 /// applies automatic modifications to source files to conform to ARC.
50 ///
51 /// \returns false if no error is produced, true otherwise.
52 bool
54  const FrontendInputFile &Input,
55  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
56  DiagnosticConsumer *DiagClient);
57 
58 /// \brief Applies automatic modifications and produces temporary files
59 /// and metadata into the \p outputDir path.
60 ///
61 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
62 /// even if the migrator can fix them, but the function will still return false
63 /// if all ARC errors can be fixed.
64 ///
65 /// \param plistOut if non-empty, it is the file path to store the plist with
66 /// the pre-migration ARC diagnostics.
67 ///
68 /// \returns false if no error is produced, true otherwise.
70  CompilerInvocation &origCI, const FrontendInputFile &Input,
71  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
72  DiagnosticConsumer *DiagClient, StringRef outputDir,
73  bool emitPremigrationARCErrors, StringRef plistOut);
74 
75 /// \brief Get the set of file remappings from the \p outputDir path that
76 /// migrateWithTemporaryFiles produced.
77 ///
78 /// \returns false if no error is produced, true otherwise.
79 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
80  StringRef outputDir,
81  DiagnosticConsumer *DiagClient);
82 
83 /// \brief Get the set of file remappings from a list of files with remapping
84 /// info.
85 ///
86 /// \returns false if no error is produced, true otherwise.
88  std::vector<std::pair<std::string,std::string> > &remap,
89  ArrayRef<StringRef> remapFiles,
90  DiagnosticConsumer *DiagClient);
91 
92 typedef void (*TransformFn)(MigrationPass &pass);
93 
94 std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
95  bool NoFinalizeRemoval);
96 
98  CompilerInvocation OrigCI;
99  std::shared_ptr<PCHContainerOperations> PCHContainerOps;
100  DiagnosticConsumer *DiagClient;
101  FileRemapper Remapper;
102 
103 public:
105 
107  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
108  DiagnosticConsumer *diagClient,
109  StringRef outputDir = StringRef());
110 
112  public:
113  virtual ~RewriteListener();
114 
115  virtual void start(ASTContext &Ctx) { }
116  virtual void finish() { }
117 
118  virtual void insert(SourceLocation loc, StringRef text) { }
119  virtual void remove(CharSourceRange range) { }
120  };
121 
122  bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr);
123 
124  FileRemapper &getRemapper() { return Remapper; }
125 };
126 
127 } // end namespace arcmt
128 
129 } // end namespace clang
130 
131 #endif
bool applyTransformations(CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagClient)
Works similar to checkForManualIssues but instead of checking, it applies automatic modifications to ...
Definition: ARCMT.cpp:386
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1397
virtual ~RewriteListener()
Anchor for VTable.
Definition: ARCMT.cpp:507
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
Represents a character-granular source range.
bool checkForManualIssues(CompilerInvocation &CI, const FrontendInputFile &Input, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagClient, bool emitPremigrationARCErrors=false, StringRef plistOut=StringRef())
Creates an AST with the provided CompilerInvocation but with these changes: -if a PCH/PTH is set...
Definition: ARCMT.cpp:239
MigrationProcess(const CompilerInvocation &CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *diagClient, StringRef outputDir=StringRef())
Definition: ARCMT.cpp:509
An input file for the front end.
virtual void insert(SourceLocation loc, StringRef text)
Definition: ARCMT.h:118
Encodes a location in the source.
bool migrateWithTemporaryFiles(CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *DiagClient, StringRef outputDir, bool emitPremigrationARCErrors, StringRef plistOut)
Applies automatic modifications and produces temporary files and metadata into the outputDir path...
Definition: ARCMT.cpp:394
void(* TransformFn)(MigrationPass &pass)
Definition: ARCMT.h:92
Dataflow Directional Tag Classes.
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
Definition: Transforms.cpp:582
Helper class for holding the data necessary to invoke the compiler.
virtual void start(ASTContext &Ctx)
Definition: ARCMT.h:115
bool getFileRemappingsFromFileList(std::vector< std::pair< std::string, std::string > > &remap, ArrayRef< StringRef > remapFiles, DiagnosticConsumer *DiagClient)
Get the set of file remappings from a list of files with remapping info.
Definition: ObjCMT.cpp:2215
Defines the clang::SourceLocation class and associated facilities.
FileRemapper & getRemapper()
Definition: ARCMT.h:124
bool applyTransform(TransformFn trans, RewriteListener *listener=nullptr)
Definition: ARCMT.cpp:524
bool getFileRemappings(std::vector< std::pair< std::string, std::string > > &remap, StringRef outputDir, DiagnosticConsumer *DiagClient)
Get the set of file remappings from the outputDir path that migrateWithTemporaryFiles produced...
Definition: ARCMT.cpp:404