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>());
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);
276 this->DiagConsumer = DiagConsumer;
281 this->DiagOpts = DiagOpts;
290 bool runInvocation(
const char *BinaryName,
292 std::shared_ptr<CompilerInvocation> Invocation,
293 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
295 std::vector<std::string> CommandLine;
299 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
327 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
328 std::make_shared<PCHContainerOperations>(),
330 llvm::vfs::getRealFileSystem(),
337 this->DiagConsumer = DiagConsumer;
365 int buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs);
380 std::vector<std::string> SourcePaths;
381 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
388 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
390 llvm::StringSet<> SeenWorkingDirectories;
396 bool PrintErrorMessage =
true;
403 std::unique_ptr<FrontendAction> create()
override {
404 return std::make_unique<T>();
408 return std::unique_ptr<FrontendActionFactory>(
409 new SimpleFrontendActionFactory);
412template <
typename FactoryT>
417 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
419 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
421 std::unique_ptr<FrontendAction> create()
override {
422 return std::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
429 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
431 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
433 std::unique_ptr<ASTConsumer>
435 return ConsumerFactory->newASTConsumer();
440 if (!ASTFrontendAction::BeginSourceFileAction(CI))
447 void EndSourceFileAction()
override {
450 ASTFrontendAction::EndSourceFileAction();
454 FactoryT *ConsumerFactory;
457 FactoryT *ConsumerFactory;
461 return std::unique_ptr<FrontendActionFactory>(
462 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
504 StringRef InvokedAs);
508 llvm::StringRef WorkingDir,
509 llvm::cl::TokenizerCallback Tokenizer,
510 llvm::vfs::FileSystem &FS);
515 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.