30 #ifndef LLVM_CLANG_TOOLING_TOOLING_H 31 #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" 54 class CompilerInstance;
55 class CompilerInvocation;
56 class DiagnosticConsumer;
57 class DiagnosticsEngine;
68 class CompilationDatabase;
80 runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
82 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
97 bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
99 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
115 template <
typename T>
147 template <
typename FactoryT>
161 const Twine &FileName =
"input.cc",
162 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
163 std::make_shared<PCHContainerOperations>());
184 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
185 const Twine &ToolName =
"clang-tool",
186 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
187 std::make_shared<PCHContainerOperations>(),
194 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
195 const Twine &ToolName =
"clang-tool",
196 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
197 std::make_shared<PCHContainerOperations>());
207 std::unique_ptr<ASTUnit>
209 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
210 std::make_shared<PCHContainerOperations>());
226 StringRef Code,
const std::vector<std::string> &Args,
227 StringRef FileName =
"input.cc", StringRef ToolName =
"clang-tool",
228 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
229 std::make_shared<PCHContainerOperations>(),
248 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
249 std::make_shared<PCHContainerOperations>());
258 ToolInvocation(std::vector<std::string> CommandLine, ToolAction *Action,
260 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
266 this->DiagConsumer = DiagConsumer;
274 void mapVirtualFile(StringRef FilePath, StringRef Content);
284 bool runInvocation(
const char *BinaryName,
286 std::shared_ptr<CompilerInvocation> Invocation,
287 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
289 std::vector<std::string> CommandLine;
293 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
295 llvm::StringMap<StringRef> MappedFileContents;
320 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
321 std::make_shared<PCHContainerOperations>(),
323 llvm::vfs::getRealFileSystem());
329 this->DiagConsumer = DiagConsumer;
336 void mapVirtualFile(StringRef FilePath, StringRef Content);
345 void clearArgumentsAdjusters();
353 int run(ToolAction *Action);
357 int buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs);
362 void setRestoreWorkingDir(
bool RestoreCWD);
373 std::vector<std::string> SourcePaths;
374 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
381 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
383 llvm::StringSet<> SeenWorkingDirectories;
389 bool RestoreCWD =
true;
392 template <
typename T>
399 return std::unique_ptr<FrontendActionFactory>(
400 new SimpleFrontendActionFactory);
403 template <
typename FactoryT>
408 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
410 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
413 return new ConsumerFactoryAdaptor(ConsumerFactory, Callbacks);
419 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
421 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
423 std::unique_ptr<ASTConsumer>
425 return ConsumerFactory->newASTConsumer();
437 void EndSourceFileAction()
override {
444 FactoryT *ConsumerFactory;
447 FactoryT *ConsumerFactory;
451 return std::unique_ptr<FrontendActionFactory>(
452 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
494 StringRef InvokedAs);
498 const llvm::opt::ArgStringList &CC1Args);
504 #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.