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"
53class CompilerInstance;
54class CompilerInvocation;
55class DiagnosticConsumer;
56class DiagnosticsEngine;
66class CompilationDatabase;
72const 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;
151template <
typename FactoryT>
153 FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks =
nullptr);
164bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction,
const Twine &Code,
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>());
211std::unique_ptr<ASTUnit>
213 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
214 std::make_shared<PCHContainerOperations>());
234 StringRef Code,
const std::vector<std::string> &Args,
235 StringRef
FileName =
"input.cc", StringRef ToolName =
"clang-tool",
236 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
237 std::make_shared<PCHContainerOperations>(),
242 llvm::vfs::getRealFileSystem());
259 std::unique_ptr<FrontendAction> FAction,
FileManager *Files,
260 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
261 std::make_shared<PCHContainerOperations>());
272 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
282 this->DiagConsumer = DiagConsumer;
287 this->DiagOpts = DiagOpts;
296 bool runInvocation(
const char *BinaryName,
298 std::shared_ptr<CompilerInvocation> Invocation,
299 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
301 std::vector<std::string> CommandLine;
305 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
333 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
334 std::make_shared<PCHContainerOperations>(),
336 llvm::vfs::getRealFileSystem(),
343 this->DiagConsumer = DiagConsumer;
371 int buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs);
386 std::vector<std::string> SourcePaths;
387 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
394 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
396 llvm::StringSet<> SeenWorkingDirectories;
402 bool PrintErrorMessage =
true;
409 std::unique_ptr<FrontendAction> create()
override {
410 return std::make_unique<T>();
414 return std::unique_ptr<FrontendActionFactory>(
415 new SimpleFrontendActionFactory);
418template <
typename FactoryT>
423 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
425 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
427 std::unique_ptr<FrontendAction> create()
override {
428 return std::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
435 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
437 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
439 std::unique_ptr<ASTConsumer>
441 return ConsumerFactory->newASTConsumer();
446 if (!ASTFrontendAction::BeginSourceFileAction(CI))
453 void EndSourceFileAction()
override {
456 ASTFrontendAction::EndSourceFileAction();
460 FactoryT *ConsumerFactory;
463 FactoryT *ConsumerFactory;
467 return std::unique_ptr<FrontendActionFactory>(
468 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
510 StringRef InvokedAs);
514 llvm::StringRef WorkingDir,
515 llvm::cl::TokenizerCallback Tokenizer,
516 llvm::vfs::FileSystem &FS);
521 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.