30 #ifndef LLVM_CLANG_TOOLING_TOOLING_H 31 #define LLVM_CLANG_TOOLING_TOOLING_H 40 #include "llvm/ADT/ArrayRef.h" 41 #include "llvm/ADT/IntrusiveRefCntPtr.h" 42 #include "llvm/ADT/StringMap.h" 43 #include "llvm/ADT/StringRef.h" 44 #include "llvm/ADT/StringSet.h" 45 #include "llvm/ADT/Twine.h" 46 #include "llvm/Option/Option.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 const Twine &Code,
const std::vector<std::string> &Args,
227 const Twine &FileName =
"input.cc",
const Twine &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>(),
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);
368 std::vector<std::string> SourcePaths;
369 std::shared_ptr<PCHContainerOperations> PCHContainerOps;
376 std::vector<std::pair<StringRef, StringRef>> MappedFileContents;
378 llvm::StringSet<> SeenWorkingDirectories;
385 template <
typename T>
392 return std::unique_ptr<FrontendActionFactory>(
393 new SimpleFrontendActionFactory);
396 template <
typename FactoryT>
401 explicit FrontendActionFactoryAdapter(FactoryT *ConsumerFactory,
403 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
406 return new ConsumerFactoryAdaptor(ConsumerFactory, Callbacks);
412 ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,
414 : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
416 std::unique_ptr<ASTConsumer>
418 return ConsumerFactory->newASTConsumer();
430 void EndSourceFileAction()
override {
437 FactoryT *ConsumerFactory;
440 FactoryT *ConsumerFactory;
444 return std::unique_ptr<FrontendActionFactory>(
445 new FrontendActionFactoryAdapter(ConsumerFactory, Callbacks));
483 StringRef InvokedAs);
487 const llvm::opt::ArgStringList &CC1Args);
493 #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.
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
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.
Defines the virtual file system interface vfs::FileSystem.
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.