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,
102 virtual std::unique_ptr<FrontendAction>
create() = 0;
112 template <
typename T>
144 template <
typename FactoryT>
158 const Twine &FileName =
"input.cc",
159 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
160 std::make_shared<PCHContainerOperations>());
180 std::unique_ptr<FrontendAction> ToolAction,
const Twine &Code,
181 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
182 const Twine &ToolName =
"clang-tool",
183 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
184 std::make_shared<PCHContainerOperations>(),
189 std::unique_ptr<FrontendAction> ToolAction,
const Twine &Code,
191 const std::vector<std::string> &Args,
const Twine &FileName =
"input.cc",
192 const Twine &ToolName =
"clang-tool",
193 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
194 std::make_shared<PCHContainerOperations>());
204 std::unique_ptr<ASTUnit>
206 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
207 std::make_shared<PCHContainerOperations>());
223 StringRef Code,
const std::vector<std::string> &Args,
224 StringRef FileName =
"input.cc", StringRef ToolName =
"clang-tool",
225 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
226 std::make_shared<PCHContainerOperations>(),
245 std::unique_ptr<FrontendAction> FAction,
FileManager *Files,
246 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
247 std::make_shared<PCHContainerOperations>());
256 ToolInvocation(std::vector<std::string> CommandLine, ToolAction *Action,
258 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
264 this->DiagConsumer = DiagConsumer;
272 void mapVirtualFile(StringRef FilePath, StringRef Content);
282 bool runInvocation(
const char *BinaryName,
284 std::shared_ptr<CompilerInvocation> Invocation,
285 std::shared_ptr<PCHContainerOperations> PCHContainerOps);
287 std::vector<std::string> CommandLine;
291 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
293 llvm::StringMap<StringRef> MappedFileContents;
320 std::shared_ptr<PCHContainerOperations> PCHContainerOps =
321 std::make_shared<PCHContainerOperations>(),
323 llvm::vfs::getRealFileSystem(),
330 this->DiagConsumer = DiagConsumer;
337 void mapVirtualFile(StringRef FilePath, StringRef Content);
346 void clearArgumentsAdjusters();
354 int run(ToolAction *Action);
358 int buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs);
363 void setRestoreWorkingDir(
bool RestoreCWD);
367 void setPrintErrorMessage(
bool PrintErrorMessage);
378 std::vector<std::string> SourcePaths;
379 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
386 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
388 llvm::StringSet<> SeenWorkingDirectories;
394 bool RestoreCWD =
true;
395 bool PrintErrorMessage =
true;
398 template <
typename T>
402 std::unique_ptr<FrontendAction>
create()
override {
403 return std::make_unique<T>();
407 return std::unique_ptr<FrontendActionFactory>(
408 new SimpleFrontendActionFactory);
411 template <
typename FactoryT>
416 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
418 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
420 std::unique_ptr<FrontendAction>
create()
override {
421 return std::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
428 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
430 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
432 std::unique_ptr<ASTConsumer>
434 return ConsumerFactory->newASTConsumer();
446 void EndSourceFileAction()
override {
453 FactoryT *ConsumerFactory;
456 FactoryT *ConsumerFactory;
460 return std::unique_ptr<FrontendActionFactory>(
461 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
503 StringRef InvokedAs);
507 const llvm::opt::ArgStringList &CC1Args);
513 #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 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.