clang API Documentation

Public Member Functions
clang::tooling::ClangTool Class Reference

Utility to run a FrontendAction over a set of files. More...

#include <Tooling.h>

Inheritance diagram for clang::tooling::ClangTool:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 ClangTool (const CompilationDatabase &Compilations, ArrayRef< std::string > SourcePaths)
 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)
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.
FileManagergetFiles ()
 Returns the file manager used in the tool.

Detailed Description

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.

Definition at line 244 of file Tooling.h.


Constructor & Destructor Documentation

clang::tooling::ClangTool::ClangTool ( const CompilationDatabase Compilations,
ArrayRef< std::string >  SourcePaths 
)

Constructs a clang tool to run over a list of files.

Parameters:
CompilationsThe CompilationDatabase which contains the compile command lines for the given source paths.
SourcePathsThe source files to run over. If a source files is not found in Compilations, it is skipped.

Definition at line 270 of file Tooling.cpp.

References appendArgumentsAdjuster().

Definition at line 278 of file Tooling.cpp.


Member Function Documentation

Append a command line arguments adjuster to the adjuster chain.

Parameters:
AdjusterAn argument adjuster, which will be run on the output of previous argument adjusters.

Definition at line 284 of file Tooling.cpp.

Referenced by ClangTool().

int clang::tooling::ClangTool::buildASTs ( std::vector< std::unique_ptr< ASTUnit >> &  ASTs)

Create an AST for each file specified in the command line and append them to ASTs.

Definition at line 393 of file Tooling.cpp.

References Action, ASTs, and run().

Clear the command line arguments adjuster chain.

Definition at line 288 of file Tooling.cpp.

Returns the file manager used in the tool.

The file manager is shared between all translation units.

Definition at line 289 of file Tooling.h.

Referenced by clang::tooling::RefactoringTool::runAndSave().

void clang::tooling::ClangTool::mapVirtualFile ( StringRef  FilePath,
StringRef  Content 
)

Map a virtual file to be used while running the tool.

Parameters:
FilePathThe path at which the content will be mapped.
ContentA null terminated buffer of the file's content.

Definition at line 280 of file Tooling.cpp.

Runs an action over all files specified in the command line.

Parameters:
ActionTool action.

Definition at line 292 of file Tooling.cpp.

References clang::tooling::CompileCommand::CommandLine, CommandLine, clang::tooling::CompileCommand::Directory, clang::tooling::getAbsolutePath(), and clang::tooling::CompilationDatabase::getCompileCommands().

Referenced by buildASTs(), and clang::tooling::RefactoringTool::runAndSave().

Set a DiagnosticConsumer to use during parsing.

Definition at line 258 of file Tooling.h.


The documentation for this class was generated from the following files: