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;
67 class CompilationDatabase;
79 runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
81 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
96 bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
98 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
114 template <
typename T>
146 template <
typename FactoryT>
160 const Twine &FileName =
"input.cc",
161 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
162 std::make_shared<PCHContainerOperations>());
183 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
184 const Twine &ToolName =
"clang-tool",
185 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
186 std::make_shared<PCHContainerOperations>(),
193 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
194 const Twine &ToolName =
"clang-tool",
195 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
196 std::make_shared<PCHContainerOperations>());
206 std::unique_ptr<ASTUnit>
208 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
209 std::make_shared<PCHContainerOperations>());
225 StringRef Code,
const std::vector<std::string> &Args,
226 StringRef FileName =
"input.cc", StringRef ToolName =
"clang-tool",
227 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
228 std::make_shared<PCHContainerOperations>(),
247 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
248 std::make_shared<PCHContainerOperations>());
257 ToolInvocation(std::vector<std::string> CommandLine, ToolAction *Action,
259 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
265 this->DiagConsumer = DiagConsumer;
273 void mapVirtualFile(StringRef FilePath, StringRef Content);
283 bool runInvocation(
const char *BinaryName,
285 std::shared_ptr<CompilerInvocation> Invocation,
286 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
288 std::vector<std::string> CommandLine;
292 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
294 llvm::StringMap<StringRef> MappedFileContents;
319 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
320 std::make_shared<PCHContainerOperations>(),
322 llvm::vfs::getRealFileSystem());
328 this->DiagConsumer = DiagConsumer;
335 void mapVirtualFile(StringRef FilePath, StringRef Content);
344 void clearArgumentsAdjusters();
352 int run(ToolAction *Action);
356 int buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs);
361 void setRestoreWorkingDir(
bool RestoreCWD);
365 void setPrintErrorMessage(
bool PrintErrorMessage);
376 std::vector<std::string> SourcePaths;
377 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
384 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
386 llvm::StringSet<> SeenWorkingDirectories;
392 bool RestoreCWD =
true;
393 bool PrintErrorMessage =
true;
396 template <
typename T>
403 return std::unique_ptr<FrontendActionFactory>(
404 new SimpleFrontendActionFactory);
407 template <
typename FactoryT>
412 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
414 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
417 return new ConsumerFactoryAdaptor(ConsumerFactory, Callbacks);
423 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
425 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
427 std::unique_ptr<ASTConsumer>
429 return ConsumerFactory->newASTConsumer();
441 void EndSourceFileAction()
override {
448 FactoryT *ConsumerFactory;
451 FactoryT *ConsumerFactory;
455 return std::unique_ptr<FrontendActionFactory>(
456 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
498 StringRef InvokedAs);
502 const llvm::opt::ArgStringList &CC1Args);
508 #endif // LLVM_CLANG_TOOLING_TOOLING_H
Implements support for file system lookup, file system caching, and directory search management...
Defines the clang::FileManager interface and associated types.
Abstract base class for actions which can be performed by the frontend.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Abstract base class to use for AST consumer-based frontend actions.
Dataflow Directional Tag Classes.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Helper class for holding the data necessary to invoke the compiler.
Compilation - A set of tasks to perform for a single driver invocation.
virtual bool BeginSourceFileAction(CompilerInstance &CI)
Callback at the start of processing a single input.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
This class handles loading and caching of source files into memory.