clang 19.0.0git
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
16namespace clang {
17 class ASTContext;
18 class DiagnosticConsumer;
19 class PCHContainerOperations;
20
21namespace 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.
40bool
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.
51bool
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.
78bool 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
91typedef void (*TransformFn)(MigrationPass &pass);
92
93std::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
102public:
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
Defines the clang::SourceLocation class and associated facilities.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Represents a character-granular source range.
Helper class for holding the data necessary to invoke the compiler.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1745
An input file for the front end.
Encodes a location in the source.
virtual void start(ASTContext &Ctx)
Definition: ARCMT.h:114
virtual void remove(CharSourceRange range)
Definition: ARCMT.h:118
virtual ~RewriteListener()
Anchor for VTable.
Definition: ARCMT.cpp:505
virtual void insert(SourceLocation loc, StringRef text)
Definition: ARCMT.h:117
FileRemapper & getRemapper()
Definition: ARCMT.h:123
bool applyTransform(TransformFn trans, RewriteListener *listener=nullptr)
Definition: ARCMT.cpp:522
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:400
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:2208
std::vector< TransformFn > getAllTransformations(LangOptions::GCMode OrigGCMode, bool NoFinalizeRemoval)
Definition: Transforms.cpp:581
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:390
void(* TransformFn)(MigrationPass &pass)
Definition: ARCMT.h:91
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:382
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:235
The JSON file list parser is used to communicate input to InstallAPI.