clang 17.0.0git
|
Utility to run a FrontendAction over a set of files. More...
#include "clang/Tooling/Tooling.h"
Public Member Functions | |
ClangTool (const CompilationDatabase &Compilations, ArrayRef< std::string > SourcePaths, std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >(), IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS=llvm::vfs::getRealFileSystem(), IntrusiveRefCntPtr< FileManager > Files=nullptr) | |
Constructs a clang tool to run over a list of files. | |
~ClangTool () | |
void | setDiagnosticConsumer (DiagnosticConsumer *DiagConsumer) |
Set a DiagnosticConsumer to use during parsing. | |
void | mapVirtualFile (StringRef FilePath, StringRef Content) |
Map a virtual file to be used while running the tool. | |
void | appendArgumentsAdjuster (ArgumentsAdjuster Adjuster) |
Append a command line arguments adjuster to the adjuster chain. | |
void | clearArgumentsAdjusters () |
Clear the command line arguments adjuster chain. | |
int | run (ToolAction *Action) |
Runs an action over all files specified in the command line. | |
int | buildASTs (std::vector< std::unique_ptr< ASTUnit > > &ASTs) |
Create an AST for each file specified in the command line and append them to ASTs. | |
void | setRestoreWorkingDir (bool RestoreCWD) |
Sets whether working directory should be restored after calling run(). | |
void | setPrintErrorMessage (bool PrintErrorMessage) |
Sets whether an error message should be printed out if an action fails. | |
FileManager & | getFiles () |
Returns the file manager used in the tool. | |
llvm::ArrayRef< std::string > | getSourcePaths () const |
Utility to run a FrontendAction over a set of files.
This class is written to be usable for command line utilities. By default the class uses ClangSyntaxOnlyAdjuster to modify command line arguments before the arguments are used to run a frontend action. One could install an additional command line arguments adjuster by calling the appendArgumentsAdjuster() method.
ClangTool::ClangTool | ( | const CompilationDatabase & | Compilations, |
ArrayRef< std::string > | SourcePaths, | ||
std::shared_ptr< PCHContainerOperations > | PCHContainerOps = std::make_shared<PCHContainerOperations>() , |
||
IntrusiveRefCntPtr< llvm::vfs::FileSystem > | BaseFS = llvm::vfs::getRealFileSystem() , |
||
IntrusiveRefCntPtr< FileManager > | Files = nullptr |
||
) |
Constructs a clang tool to run over a list of files.
Compilations | The CompilationDatabase which contains the compile command lines for the given source paths. |
SourcePaths | The source files to run over. If a source files is not found in Compilations, it is skipped. |
PCHContainerOps | The PCHContainerOperations for loading and creating clang modules. |
BaseFS | VFS used for all underlying file accesses when running the tool. |
Files | The file manager to use for underlying file operations when running the tool. |
Definition at line 466 of file Tooling.cpp.
References appendArgumentsAdjuster(), clang::tooling::getClangStripDependencyFileAdjuster(), clang::tooling::getClangStripOutputAdjuster(), and clang::tooling::getClangSyntaxOnlyAdjuster().
|
default |
void ClangTool::appendArgumentsAdjuster | ( | ArgumentsAdjuster | Adjuster | ) |
Append a command line arguments adjuster to the adjuster chain.
Adjuster | An argument adjuster, which will be run on the output of previous argument adjusters. |
Definition at line 491 of file Tooling.cpp.
References clang::tooling::combineAdjusters().
Referenced by ClangTool(), clang::tooling::AllTUsToolExecutor::execute(), and clang::tooling::StandaloneToolExecutor::execute().
Create an AST for each file specified in the command line and append them to ASTs.
Definition at line 660 of file Tooling.cpp.
References run().
void ClangTool::clearArgumentsAdjusters | ( | ) |
Clear the command line arguments adjuster chain.
Definition at line 495 of file Tooling.cpp.
Referenced by clang::tooling::StandaloneToolExecutor::StandaloneToolExecutor().
|
inline |
Returns the file manager used in the tool.
The file manager is shared between all translation units.
Definition at line 376 of file Tooling.h.
Referenced by clang::tooling::StandaloneToolExecutor::getFiles(), and clang::tooling::RefactoringTool::runAndSave().
|
inline |
Definition at line 378 of file Tooling.h.
Referenced by clang::tooling::StandaloneToolExecutor::getSourcePaths().
void ClangTool::mapVirtualFile | ( | StringRef | FilePath, |
StringRef | Content | ||
) |
Map a virtual file to be used while running the tool.
FilePath | The path at which the content will be mapped. |
Content | A null terminated buffer of the file's content. |
Definition at line 487 of file Tooling.cpp.
Referenced by clang::tooling::StandaloneToolExecutor::mapVirtualFile().
int ClangTool::run | ( | ToolAction * | Action | ) |
Runs an action over all files specified in the command line.
Action | Tool action. |
Definition at line 512 of file Tooling.cpp.
References clang::tooling::CompileCommand::CommandLine, clang::tooling::CompileCommand::Directory, clang::File, clang::tooling::CompileCommand::Filename, clang::tooling::getAbsolutePath(), clang::tooling::CompilationDatabase::getCompileCommands(), and injectResourceDir().
Referenced by buildASTs(), clang::tooling::StandaloneToolExecutor::execute(), and clang::tooling::RefactoringTool::runAndSave().
|
inline |
Set a DiagnosticConsumer
to use during parsing.
Definition at line 333 of file Tooling.h.
Referenced by clang::tooling::StandaloneToolExecutor::setDiagnosticConsumer().
void ClangTool::setPrintErrorMessage | ( | bool | PrintErrorMessage | ) |
Sets whether an error message should be printed out if an action fails.
By default, if an action fails, a message is printed out to stderr.
Definition at line 669 of file Tooling.cpp.
void ClangTool::setRestoreWorkingDir | ( | bool | RestoreCWD | ) |
Sets whether working directory should be restored after calling run().
By default, working directory is restored. However, it could be useful to turn this off when running on multiple threads to avoid the raciness.
Definition at line 665 of file Tooling.cpp.