Go to the documentation of this file.
29 #ifndef LLVM_CLANG_TOOLING_TOOLING_H
30 #define LLVM_CLANG_TOOLING_TOOLING_H
38 #include "llvm/ADT/ArrayRef.h"
39 #include "llvm/ADT/IntrusiveRefCntPtr.h"
40 #include "llvm/ADT/StringMap.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/ADT/StringSet.h"
43 #include "llvm/ADT/Twine.h"
44 #include "llvm/Option/Option.h"
45 #include "llvm/Support/VirtualFileSystem.h"
53 class CompilerInstance;
54 class CompilerInvocation;
55 class DiagnosticConsumer;
56 class DiagnosticsEngine;
66 class CompilationDatabase;
72 const llvm::opt::ArgStringList *
74 driver::Compilation *Compilation);
88 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
103 bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
105 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
109 virtual std::unique_ptr<FrontendAction>
create() = 0;
119 template <
typename T>
151 template <
typename FactoryT>
153 FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks =
nullptr);
164 bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction,
const Twine &Code,
165 const Twine &FileName =
"input.cc",
166 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
167 std::make_shared<PCHContainerOperations>());
187 std::unique_ptr<FrontendAction>
ToolAction,
const Twine &Code,
188 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
189 const Twine &ToolName =
"clang-tool",
190 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
191 std::make_shared<PCHContainerOperations>(),
196 std::unique_ptr<FrontendAction>
ToolAction,
const Twine &Code,
198 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
199 const Twine &ToolName =
"clang-tool",
200 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
201 std::make_shared<PCHContainerOperations>());
211 std::unique_ptr<ASTUnit>
213 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
214 std::make_shared<PCHContainerOperations>());
230 StringRef Code,
const std::vector<std::string> &Args,
231 StringRef FileName =
"input.cc", StringRef ToolName =
"clang-tool",
232 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
233 std::make_shared<PCHContainerOperations>(),
253 std::unique_ptr<FrontendAction> FAction,
FileManager *Files,
254 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
255 std::make_shared<PCHContainerOperations>());
266 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
273 this->DiagConsumer = DiagConsumer;
278 this->DiagOpts = DiagOpts;
287 bool runInvocation(
const char *BinaryName,
289 std::shared_ptr<CompilerInvocation> Invocation,
290 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
292 std::vector<std::string> CommandLine;
296 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
324 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
325 std::make_shared<PCHContainerOperations>(),
327 llvm::vfs::getRealFileSystem(),
334 this->DiagConsumer = DiagConsumer;
362 int buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs);
382 std::vector<std::string> SourcePaths;
383 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
390 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
392 llvm::StringSet<> SeenWorkingDirectories;
398 bool RestoreCWD =
true;
399 bool PrintErrorMessage =
true;
402 template <
typename T>
406 std::unique_ptr<FrontendAction>
create()
override {
407 return std::make_unique<T>();
411 return std::unique_ptr<FrontendActionFactory>(
412 new SimpleFrontendActionFactory);
415 template <
typename FactoryT>
420 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
422 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
424 std::unique_ptr<FrontendAction>
create()
override {
425 return std::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
432 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
434 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
436 std::unique_ptr<ASTConsumer>
438 return ConsumerFactory->newASTConsumer();
450 void EndSourceFileAction()
override {
457 FactoryT *ConsumerFactory;
460 FactoryT *ConsumerFactory;
464 return std::unique_ptr<FrontendActionFactory>(
465 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
507 StringRef InvokedAs);
512 const char *
const BinaryName);
518 #endif // LLVM_CLANG_TOOLING_TOOLING_H
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Concrete class used by the front-end to report problems and issues.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Compilation - A set of tasks to perform for a single driver invocation.
Implements support for file system lookup, file system caching, and directory search management.
Helper class for holding the data necessary to invoke the compiler.
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
Abstract base class to use for AST consumer-based frontend actions.
Options for controlling the compiler diagnostics engine.