@@ -99,9 +99,7 @@ class FrontendActionFactory : public ToolAction {
99
99
DiagnosticConsumer *DiagConsumer) override ;
100
100
101
101
// / Returns a new clang::FrontendAction.
102
- // /
103
- // / The caller takes ownership of the returned action.
104
- virtual FrontendAction *create () = 0;
102
+ virtual std::unique_ptr<FrontendAction> create () = 0;
105
103
};
106
104
107
105
// / Returns a new FrontendActionFactory for a given type.
@@ -161,6 +159,14 @@ bool runToolOnCode(FrontendAction *ToolAction, const Twine &Code,
161
159
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
162
160
std::make_shared<PCHContainerOperations>());
163
161
162
+ inline bool
163
+ runToolOnCode (std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
164
+ const Twine &FileName = " input.cc" ,
165
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
166
+ std::make_shared<PCHContainerOperations>()) {
167
+ return runToolOnCode (ToolAction.release (), Code, FileName, PCHContainerOps);
168
+ }
169
+
164
170
// / The first part of the pair is the filename, the second part the
165
171
// / file-content.
166
172
using FileContentMappings = std::vector<std::pair<std::string, std::string>>;
@@ -186,6 +192,17 @@ bool runToolOnCodeWithArgs(
186
192
std::make_shared<PCHContainerOperations>(),
187
193
const FileContentMappings &VirtualMappedFiles = FileContentMappings());
188
194
195
+ inline bool runToolOnCodeWithArgs (
196
+ std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
197
+ const std::vector<std::string> &Args, const Twine &FileName = " input.cc" ,
198
+ const Twine &ToolName = " clang-tool" ,
199
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
200
+ std::make_shared<PCHContainerOperations>(),
201
+ const FileContentMappings &VirtualMappedFiles = FileContentMappings()) {
202
+ return runToolOnCodeWithArgs (ToolAction.release (), Code, Args, FileName,
203
+ ToolName, PCHContainerOps, VirtualMappedFiles);
204
+ }
205
+
189
206
// Similar to the overload except this takes a VFS.
190
207
bool runToolOnCodeWithArgs (
191
208
FrontendAction *ToolAction, const Twine &Code,
@@ -195,6 +212,17 @@ bool runToolOnCodeWithArgs(
195
212
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
196
213
std::make_shared<PCHContainerOperations>());
197
214
215
+ inline bool runToolOnCodeWithArgs (
216
+ std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
217
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
218
+ const std::vector<std::string> &Args, const Twine &FileName = " input.cc" ,
219
+ const Twine &ToolName = " clang-tool" ,
220
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
221
+ std::make_shared<PCHContainerOperations>()) {
222
+ return runToolOnCodeWithArgs (ToolAction.release (), Code, VFS, Args, FileName,
223
+ ToolName, PCHContainerOps);
224
+ }
225
+
198
226
// / Builds an AST for 'Code'.
199
227
// /
200
228
// / \param Code C++ code.
@@ -247,6 +275,13 @@ class ToolInvocation {
247
275
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
248
276
std::make_shared<PCHContainerOperations>());
249
277
278
+ ToolInvocation (std::vector<std::string> CommandLine,
279
+ std::unique_ptr<FrontendAction> FAction, FileManager *Files,
280
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps =
281
+ std::make_shared<PCHContainerOperations>())
282
+ : ToolInvocation(std::move(CommandLine), FAction.release(), Files,
283
+ PCHContainerOps) {}
284
+
250
285
// / Create a tool invocation.
251
286
// /
252
287
// / \param CommandLine The command line arguments to clang.
@@ -397,7 +432,9 @@ template <typename T>
397
432
std::unique_ptr<FrontendActionFactory> newFrontendActionFactory () {
398
433
class SimpleFrontendActionFactory : public FrontendActionFactory {
399
434
public:
400
- FrontendAction *create () override { return new T; }
435
+ std::unique_ptr<FrontendAction> create () override {
436
+ return std::make_unique<T>();
437
+ }
401
438
};
402
439
403
440
return std::unique_ptr<FrontendActionFactory>(
@@ -413,8 +450,9 @@ inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
413
450
SourceFileCallbacks *Callbacks)
414
451
: ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
415
452
416
- FrontendAction *create () override {
417
- return new ConsumerFactoryAdaptor (ConsumerFactory, Callbacks);
453
+ std::unique_ptr<FrontendAction> create () override {
454
+ return std::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
455
+ Callbacks);
418
456
}
419
457
420
458
private:
0 commit comments