29#ifndef LLVM_CLANG_TOOLING_TOOLING_H
30#define LLVM_CLANG_TOOLING_TOOLING_H
39#include "llvm/ADT/ArrayRef.h"
40#include "llvm/ADT/IntrusiveRefCntPtr.h"
41#include "llvm/ADT/StringMap.h"
42#include "llvm/ADT/StringRef.h"
43#include "llvm/ADT/StringSet.h"
44#include "llvm/ADT/Twine.h"
45#include "llvm/Option/Option.h"
46#include "llvm/Support/VirtualFileSystem.h"
54class CompilerInstance;
55class CompilerInvocation;
56class DiagnosticConsumer;
57class DiagnosticsEngine;
67class CompilationDatabase;
73const llvm::opt::ArgStringList *
75 driver::Compilation *Compilation);
89 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
104 bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
106 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
110 virtual std::unique_ptr<FrontendAction>
create() = 0;
152template <
typename FactoryT>
154 FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks =
nullptr);
165bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction,
const Twine &Code,
167 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
168 std::make_shared<PCHContainerOperations>());
188 std::unique_ptr<FrontendAction>
ToolAction,
const Twine &Code,
189 const std::vector<std::string> &Args,
const Twine &
FileName =
"input.cc",
190 const Twine &ToolName =
"clang-tool",
191 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
192 std::make_shared<PCHContainerOperations>(),
197 std::unique_ptr<FrontendAction>
ToolAction,
const Twine &Code,
199 const std::vector<std::string> &Args,
const Twine &
FileName =
"input.cc",
200 const Twine &ToolName =
"clang-tool",
201 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
202 std::make_shared<PCHContainerOperations>());
212std::unique_ptr<ASTUnit>
214 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
215 std::make_shared<PCHContainerOperations>());
235 StringRef Code,
const std::vector<std::string> &Args,
236 StringRef
FileName =
"input.cc", StringRef ToolName =
"clang-tool",
237 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
238 std::make_shared<PCHContainerOperations>(),
243 llvm::vfs::getRealFileSystem(),
261 std::unique_ptr<FrontendAction> FAction,
FileManager *Files,
262 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
263 std::make_shared<PCHContainerOperations>());
274 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
284 this->DiagConsumer = DiagConsumer;
289 this->DiagOpts = DiagOpts;
298 bool runInvocation(
const char *BinaryName,
300 std::shared_ptr<CompilerInvocation> Invocation,
301 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
303 std::vector<std::string> CommandLine;
307 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
335 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
336 std::make_shared<PCHContainerOperations>(),
338 llvm::vfs::getRealFileSystem(),
345 this->DiagConsumer = DiagConsumer;
373 int buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs);
388 std::vector<std::string> SourcePaths;
389 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
396 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
398 llvm::StringSet<> SeenWorkingDirectories;
404 bool PrintErrorMessage =
true;
411 std::unique_ptr<FrontendAction> create()
override {
412 return std::make_unique<T>();
416 return std::unique_ptr<FrontendActionFactory>(
417 new SimpleFrontendActionFactory);
420template <
typename FactoryT>
425 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
427 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
429 std::unique_ptr<FrontendAction> create()
override {
430 return std::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
437 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
439 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
441 std::unique_ptr<ASTConsumer>
443 return ConsumerFactory->newASTConsumer();
448 if (!ASTFrontendAction::BeginSourceFileAction(CI))
455 void EndSourceFileAction()
override {
458 ASTFrontendAction::EndSourceFileAction();
462 FactoryT *ConsumerFactory;
465 FactoryT *ConsumerFactory;
469 return std::unique_ptr<FrontendActionFactory>(
470 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
512 StringRef InvokedAs);
516 llvm::StringRef WorkingDir,
517 llvm::cl::TokenizerCallback Tokenizer,
518 llvm::vfs::FileSystem &FS);
523 const char *
const BinaryName);
Defines the clang::FileManager interface and associated types.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Abstract base class to use for AST consumer-based frontend actions.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
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...
Options for controlling the compiler diagnostics engine.
Concrete class used by the front-end to report problems and issues.
Implements support for file system lookup, file system caching, and directory search management.
Compilation - A set of tasks to perform for a single driver invocation.
The JSON file list parser is used to communicate input to InstallAPI.
CaptureDiagsKind
Enumerates the available kinds for capturing diagnostics.