clang  9.0.0svn
ARCMT.h
Go to the documentation of this file.
1 //===-- ARCMT.h - ARC Migration Rewriter ------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_ARCMIGRATE_ARCMT_H
10 #define LLVM_CLANG_ARCMIGRATE_ARCMT_H
11 
15 
16 namespace clang {
17  class ASTContext;
18  class DiagnosticConsumer;
19  class PCHContainerOperations;
20 
21 namespace arcmt {
22  class MigrationPass;
23 
24 /// Creates an AST with the provided CompilerInvocation but with these
25 /// changes:
26 /// -if a PCH/PTH is set, the original header is used instead
27 /// -Automatic Reference Counting mode is enabled
28 ///
29 /// It then checks the AST and produces errors/warning for ARC migration issues
30 /// that the user needs to handle manually.
31 ///
32 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
33 /// even if the migrator can fix them, but the function will still return false
34 /// if all ARC errors can be fixed.
35 ///
36 /// \param plistOut if non-empty, it is the file path to store the plist with
37 /// the pre-migration ARC diagnostics.
38 ///
39 /// \returns false if no error is produced, true otherwise.
40 bool
42  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
43  DiagnosticConsumer *DiagClient,
44  bool emitPremigrationARCErrors = false,
45  StringRef plistOut = StringRef());
46 
47 /// Works similar to checkForManualIssues but instead of checking, it
48 /// applies automatic modifications to source files to conform to ARC.
49 ///
50 /// \returns false if no error is produced, true otherwise.
51 bool
53  const FrontendInputFile &Input,
54  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
55  DiagnosticConsumer *DiagClient);
56 
57 /// Applies automatic modifications and produces temporary files
58 /// and metadata into the \p outputDir path.
59 ///
60 /// \param emitPremigrationARCErrors if true all ARC errors will get emitted
61 /// even if the migrator can fix them, but the function will still return false
62 /// if all ARC errors can be fixed.
63 ///
64 /// \param plistOut if non-empty, it is the file path to store the plist with
65 /// the pre-migration ARC diagnostics.
66 ///
67 /// \returns false if no error is produced, true otherwise.
69  CompilerInvocation &origCI, const FrontendInputFile &Input,
70  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
71  DiagnosticConsumer *DiagClient, StringRef outputDir,
72  bool emitPremigrationARCErrors, StringRef plistOut);
73 
74 /// Get the set of file remappings from the \p outputDir path that
75 /// migrateWithTemporaryFiles produced.
76 ///
77 /// \returns false if no error is produced, true otherwise.
78 bool getFileRemappings(std::vector<std::pair<std::string,std::string> > &remap,
79  StringRef outputDir,
80  DiagnosticConsumer *DiagClient);
81 
82 /// Get the set of file remappings from a list of files with remapping
83 /// info.
84 ///
85 /// \returns false if no error is produced, true otherwise.
87  std::vector<std::pair<std::string,std::string> > &remap,
88  ArrayRef<StringRef> remapFiles,
89  DiagnosticConsumer *DiagClient);
90 
91 typedef void (*TransformFn)(MigrationPass &pass);
92 
93 std::vector<TransformFn> getAllTransformations(LangOptions::GCMode OrigGCMode,
94  bool NoFinalizeRemoval);
95 
97  CompilerInvocation OrigCI;
98  std::shared_ptr<PCHContainerOperations> PCHContainerOps;
99  DiagnosticConsumer *DiagClient;
100  FileRemapper Remapper;
101 
102 public:
104 
106  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
107  DiagnosticConsumer *diagClient,
108  StringRef outputDir = StringRef());
109 
111  public:
112  virtual ~RewriteListener();
113 
114  virtual void start(ASTContext &Ctx) { }
115  virtual void finish() { }
116 
117  virtual void insert(SourceLocation loc, StringRef text) { }
118  virtual void remove(CharSourceRange range) { }
119  };
120 
121  bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr);
122 
123  FileRemapper &getRemapper() { return Remapper; }
124 };
125 
126 } // end namespace arcmt
127 
128 } // end namespace clang
129 
130 #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:383
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1489
virtual ~RewriteListener()
Anchor for VTable.
Definition: ARCMT.cpp:504
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
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:236
MigrationProcess(const CompilerInvocation &CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticConsumer *diagClient, StringRef outputDir=StringRef())
Definition: ARCMT.cpp:506
An input file for the front end.
virtual void insert(SourceLocation loc, StringRef text)
Definition: ARCMT.h:117
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:391
void(* TransformFn)(MigrationPass &pass)
Definition: ARCMT.h:91
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:114
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:2229
Defines the clang::SourceLocation class and associated facilities.
FileRemapper & getRemapper()
Definition: ARCMT.h:123
bool applyTransform(TransformFn trans, RewriteListener *listener=nullptr)
Definition: ARCMT.cpp:521
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:401