clang  5.0.0
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
clang::tooling Namespace Reference

Namespaces

 fixit
 

Classes

class  CommonOptionsParser
 A parser for options common to all command-line Clang tools. More...
 
struct  CompileCommand
 Specifies the working directory and command of a compilation. More...
 
class  CompilationDatabase
 Interface for compilation databases. More...
 
class  CompilationDatabasePlugin
 Interface for compilation database plugins. More...
 
class  FixedCompilationDatabase
 A compilation database that returns a single compile command line. More...
 
struct  DiagnosticMessage
 Represents the diagnostic message with the error message associated and the information on the location of the problem. More...
 
struct  Diagnostic
 Represents the diagnostic with the level of severity and possible fixes to be applied. More...
 
struct  TranslationUnitDiagnostics
 Collection of Diagnostics generated from a single translation unit. More...
 
class  Range
 A source range independent of the SourceManager. More...
 
class  Replacement
 A text replacement. More...
 
class  ReplacementError
 Carries extra error information in replacement-related llvm::Error, e.g. More...
 
class  Replacements
 Maintains a set of replacements that are conflict-free. More...
 
struct  TranslationUnitReplacements
 Collection of Replacements generated from a single translation unit. More...
 
struct  PathComparator
 
class  FileMatchTrie
 A trie to efficiently match against the entries of the compilation database in order of matching suffix length. More...
 
class  JSONCompilationDatabase
 
class  AtomicChange
 An atomic change is used to create and group a set of source edits, e.g. More...
 
class  RecursiveSymbolVisitor
 Traverses the AST and visits the occurrence of each named symbol in the given nodes. More...
 
class  RenamingAction
 
class  QualifiedRenamingAction
 Rename all symbols identified by the given USRs. More...
 
struct  USRFindingAction
 
class  RefactoringTool
 A tool to run refactorings. More...
 
class  RefactoringCallback
 Base class for RefactoringCallbacks. More...
 
class  ASTMatchRefactorer
 Adaptor between ast_matchers::MatchFinder and tooling::RefactoringTool. More...
 
class  ReplaceStmtWithText
 Replace the text of the statement bound to FromId with the text in ToText. More...
 
class  ReplaceNodeWithTemplate
 Replace the text of an AST node bound to FromId with the result of evaluating the template in ToTemplate. More...
 
class  ReplaceStmtWithStmt
 Replace the text of the statement bound to FromId with the text of the statement bound to ToId. More...
 
class  ReplaceIfStmtWithItsBody
 Replace an if-statement bound to Id with the outdented text of its body, choosing the consequent or the alternative based on whether PickTrueBranch is true. More...
 
class  ToolAction
 Interface to process a clang::CompilerInvocation. More...
 
class  FrontendActionFactory
 Interface to generate clang::FrontendActions. More...
 
class  SourceFileCallbacks
 Callbacks called before and after each source file processed by a FrontendAction created by the FrontedActionFactory returned by newFrontendActionFactory. More...
 
class  ToolInvocation
 Utility to run a FrontendAction in a single clang invocation. More...
 
class  ClangTool
 Utility to run a FrontendAction over a set of files. More...
 
class  FileMatchTrieNode
 A node of the FileMatchTrie. More...
 
class  RenamingASTConsumer
 
class  USRSymbolRenamer
 
class  NamedDeclFindingConsumer
 
class  RefactoringASTConsumer
 

Typedefs

typedef std::vector< std::string > CommandLineArguments
 A sequence of command line arguments. More...
 
typedef std::function
< CommandLineArguments(const
CommandLineArguments
&, StringRef Filename)> 
ArgumentsAdjuster
 A prototype of a command line adjuster. More...
 
typedef llvm::Registry
< CompilationDatabasePlugin
CompilationDatabasePluginRegistry
 
typedef std::vector< std::pair
< std::string, std::string > > 
FileContentMappings
 The first part of the pair is the filename, the second part the file-content. More...
 

Enumerations

enum  ArgumentInsertPosition { ArgumentInsertPosition::BEGIN, ArgumentInsertPosition::END }
 
enum  replacement_error { replacement_error::fail_to_apply = 0, replacement_error::wrong_file_path, replacement_error::overlap_conflict, replacement_error::insert_conflict }
 
enum  JSONCommandLineSyntax { JSONCommandLineSyntax::Windows, JSONCommandLineSyntax::Gnu, JSONCommandLineSyntax::AutoDetect }
 A JSON based compilation database. More...
 

Functions

ArgumentsAdjuster getClangSyntaxOnlyAdjuster ()
 Gets an argument adjuster that converts input command line arguments to the "syntax check only" variant. More...
 
ArgumentsAdjuster getClangStripOutputAdjuster ()
 Gets an argument adjuster which removes output-related command line arguments. More...
 
ArgumentsAdjuster getClangStripDependencyFileAdjuster ()
 Gets an argument adjuster which removes dependency-file related command line arguments. More...
 
ArgumentsAdjuster getInsertArgumentAdjuster (const CommandLineArguments &Extra, ArgumentInsertPosition Pos)
 Gets an argument adjuster which inserts Extra arguments in the specified position. More...
 
ArgumentsAdjuster getInsertArgumentAdjuster (const char *Extra, ArgumentInsertPosition Pos=ArgumentInsertPosition::END)
 Gets an argument adjuster which inserts an Extra argument in the specified position. More...
 
ArgumentsAdjuster combineAdjusters (ArgumentsAdjuster First, ArgumentsAdjuster Second)
 Gets an argument adjuster which adjusts the arguments in sequence with the First adjuster and then with the Second one. More...
 
std::string replaceNestedName (const NestedNameSpecifier *Use, const DeclContext *UseContext, const NamedDecl *FromDecl, StringRef ReplacementString)
 Emulate a lookup to replace one nested name specifier with another using as few additional namespace qualifications as possible. More...
 
bool operator< (const Replacement &LHS, const Replacement &RHS)
 Less-than operator between two Replacements. More...
 
bool operator== (const Replacement &LHS, const Replacement &RHS)
 Equal-to operator between two Replacements. More...
 
bool applyAllReplacements (const Replacements &Replaces, Rewriter &Rewrite)
 Apply all replacements in Replaces to the Rewriter Rewrite. More...
 
llvm::Expected< std::string > applyAllReplacements (StringRef Code, const Replacements &Replaces)
 Applies all replacements in Replaces to Code. More...
 
std::vector< RangecalculateRangesAfterReplacements (const Replacements &Replaces, const std::vector< Range > &Ranges)
 Calculates the new ranges after Replaces are applied. More...
 
std::map< std::string,
Replacements
groupReplacementsByFile (FileManager &FileMgr, const std::map< std::string, Replacements > &FileToReplaces)
 If there are multiple <File, Replacements> pairs with the same file entry, we only keep one pair and discard the rest. More...
 
const NamedDeclgetNamedDeclAt (const ASTContext &Context, const SourceLocation Point)
 
const NamedDeclgetNamedDeclFor (const ASTContext &Context, const std::string &Name)
 
std::string getUSRForDecl (const Decl *Decl)
 
std::vector
< tooling::AtomicChange
createRenameAtomicChanges (llvm::ArrayRef< std::string > USRs, llvm::StringRef NewName, Decl *TranslationUnitDecl)
 Create atomic changes for renaming all symbol references which are identified by the USRs set to a given new name. More...
 
std::vector< SourceLocationgetLocationsOfUSRs (const std::vector< std::string > &USRs, llvm::StringRef PrevName, Decl *Decl)
 
bool formatAndApplyAllReplacements (const std::map< std::string, Replacements > &FileToReplaces, Rewriter &Rewrite, StringRef Style="file")
 Groups Replaces by the file path and applies each group of Replacements on the related file in Rewriter. More...
 
template<typename T >
std::unique_ptr
< FrontendActionFactory
newFrontendActionFactory ()
 Returns a new FrontendActionFactory for a given type. More...
 
template<typename FactoryT >
std::unique_ptr
< FrontendActionFactory
newFrontendActionFactory (FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks=nullptr)
 Returns a new FrontendActionFactory for any type that provides an implementation of newASTConsumer(). More...
 
bool runToolOnCode (clang::FrontendAction *ToolAction, const Twine &Code, const Twine &FileName="input.cc", std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >())
 Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag. More...
 
bool runToolOnCodeWithArgs (clang::FrontendAction *ToolAction, const Twine &Code, const std::vector< std::string > &Args, const Twine &FileName="input.cc", const Twine &ToolName="clang-tool", std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >(), const FileContentMappings &VirtualMappedFiles=FileContentMappings())
 Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag and with additional other flags. More...
 
std::unique_ptr< ASTUnitbuildASTFromCode (const Twine &Code, const Twine &FileName="input.cc", std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >())
 Builds an AST for 'Code'. More...
 
std::unique_ptr< ASTUnitbuildASTFromCodeWithArgs (const Twine &Code, const std::vector< std::string > &Args, const Twine &FileName="input.cc", const Twine &ToolName="clang-tool", std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >(), ArgumentsAdjuster Adjuster=getClangStripDependencyFileAdjuster())
 Builds an AST for 'Code' with additional flags. More...
 
std::string getAbsolutePath (StringRef File)
 Returns the absolute path of File, by prepending it with the current directory if File is not absolute. More...
 
void addTargetAndModeForProgramName (std::vector< std::string > &CommandLine, StringRef InvokedAs)
 Changes CommandLine to contain implicit flags that would have been defined had the compiler driver been invoked through the path InvokedAs. More...
 
clang::CompilerInvocationnewInvocation (clang::DiagnosticsEngine *Diagnostics, const llvm::opt::ArgStringList &CC1Args)
 Creates a CompilerInvocation. More...
 
static int getRangeSize (const SourceManager &Sources, const CharSourceRange &Range, const LangOptions &LangOpts)
 
static std::string getReplacementErrString (replacement_error Err)
 
static std::vector< RangecombineAndSortRanges (std::vector< Range > Ranges)
 
static
CompilationDatabasePluginRegistry::Add
< JSONCompilationDatabasePlugin > 
X ("json-compilation-database","Reads JSON formatted compilation databases")
 
static std::vector< std::string > nodeToCommandLine (JSONCommandLineSyntax Syntax, const std::vector< llvm::yaml::ScalarNode * > &Nodes)
 
std::vector< SourceLocationgetLocationsOfUSRs (const std::vector< std::string > &USRs, StringRef PrevName, Decl *Decl)
 
static Replacement replaceStmtWithText (SourceManager &Sources, const Stmt &From, StringRef Text)
 
static Replacement replaceStmtWithStmt (SourceManager &Sources, const Stmt &From, const Stmt &To)
 
static clang::driver::DrivernewDriver (clang::DiagnosticsEngine *Diagnostics, const char *BinaryName, IntrusiveRefCntPtr< vfs::FileSystem > VFS)
 Builds a clang driver initialized for running clang tools. More...
 
static const
llvm::opt::ArgStringList * 
getCC1Arguments (clang::DiagnosticsEngine *Diagnostics, clang::driver::Compilation *Compilation)
 Retrieves the clang CC1 specific flags out of the compilation's jobs. More...
 
static std::vector< std::string > getSyntaxOnlyToolArgs (const Twine &ToolName, const std::vector< std::string > &ExtraArgs, StringRef FileName)
 
static void injectResourceDir (CommandLineArguments &Args, const char *Argv0, void *MainAddr)
 

Variables

volatile int JSONAnchorSource = 0
 
static int LLVM_ATTRIBUTE_UNUSED JSONAnchorDest = JSONAnchorSource
 
static const char *const InvalidLocation = ""
 

Typedef Documentation

A prototype of a command line adjuster.

Command line argument adjuster is responsible for command line arguments modification before the arguments are used to run a frontend action.

Definition at line 37 of file ArgumentsAdjusters.h.

typedef std::vector<std::string> clang::tooling::CommandLineArguments

A sequence of command line arguments.

Definition at line 30 of file ArgumentsAdjusters.h.

Definition at line 19 of file CompilationDatabasePluginRegistry.h.

typedef std::vector<std::pair<std::string, std::string> > clang::tooling::FileContentMappings

The first part of the pair is the filename, the second part the file-content.

Definition at line 159 of file Tooling.h.

Enumeration Type Documentation

Enumerator
BEGIN 
END 

Definition at line 51 of file ArgumentsAdjusters.h.

A JSON based compilation database.

JSON compilation database files must contain a list of JSON objects which provide the command lines in the attributes 'directory', 'command', 'arguments' and 'file': [ { "directory": "<working directory of the compile>", "command": "<compile command line>", "file": "<path to source file>" }, { "directory": "<working directory of the compile>", "arguments": ["<raw>", "<command>" "<line>" "<parameters>"], "file": "<path to source file>" }, ... ] Each object entry defines one compile action. The specified file is considered to be the main source file for the translation unit.

'command' is a full command line that will be unescaped.

'arguments' is a list of command line arguments that will not be unescaped.

JSON compilation databases can for example be generated in CMake projects by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS.

Enumerator
Windows 
Gnu 
AutoDetect 

Definition at line 58 of file JSONCompilationDatabase.h.

Enumerator
fail_to_apply 
wrong_file_path 
overlap_conflict 
insert_conflict 

Definition at line 143 of file Replacement.h.

Function Documentation

void clang::tooling::addTargetAndModeForProgramName ( std::vector< std::string > &  CommandLine,
StringRef  InvokedAs 
)

Changes CommandLine to contain implicit flags that would have been defined had the compiler driver been invoked through the path InvokedAs.

For example, when called with InvokedAs set to i686-linux-android-g++, the arguments '-target', 'i686-linux-android,–driver-mode=g++` will be inserted after the first argument in CommandLine.

This function will not add new -target or --driver-mode flags if they are already present in CommandLine (even if they have different settings than would have been inserted).

Precondition
llvm::InitializeAllTargets() has been called.
Parameters
CommandLinethe command line used to invoke the compiler driver or Clang tool, including the path to the executable as CommandLine[0].
InvokedAsthe path to the driver used to infer implicit flags.
Note
This will not set CommandLine[0] to InvokedAs. The tooling infrastructure expects that CommandLine[0] is a tool path relative to which the builtin headers can be found.

Definition at line 177 of file Tooling.cpp.

References clang::driver::ToolChain::getTargetAndModeFromProgramName(), and Token.

bool clang::tooling::applyAllReplacements ( const Replacements &  Replaces,
Rewriter &  Rewrite 
)

Apply all replacements in Replaces to the Rewriter Rewrite.

Replacement applications happen independently of the success of other applications.

Returns
true if all replacements apply. false otherwise.

Definition at line 541 of file Replacement.cpp.

References E, I, clang::tooling::Replacements::rbegin(), clang::tooling::Replacements::rend(), and Result.

Referenced by clang::tooling::RefactoringTool::applyAllReplacements(), formatAndApplyAllReplacements(), clang::format::processReplacements(), and clang::format::reformat().

llvm::Expected< std::string > clang::tooling::applyAllReplacements ( StringRef  Code,
const Replacements &  Replaces 
)

Applies all replacements in Replaces to Code.

This completely ignores the path stored in each replacement. If all replacements are applied successfully, this returns the code with replacements applied; otherwise, an llvm::Error carrying llvm::StringError is returned (the Error message can be converted to string using llvm::toString() and 'std::error_code<tt>in theError` should be ignored).

Definition at line 553 of file Replacement.cpp.

References clang::SrcMgr::C_User, clang::SourceManager::createFileID(), E, clang::tooling::Replacements::empty(), fail_to_apply, clang::Rewriter::getEditBuffer(), clang::FileManager::getFile(), I, ID, clang::tooling::Replacements::rbegin(), clang::tooling::Replacements::rend(), Result, clang::format::SourceMgr(), and clang::RewriteBuffer::write().

std::unique_ptr< ASTUnit > clang::tooling::buildASTFromCode ( const Twine &  Code,
const Twine &  FileName = "input.cc",
std::shared_ptr< PCHContainerOperations >  PCHContainerOps = std::make_shared<PCHContainerOperations>() 
)

Builds an AST for 'Code'.

Parameters
CodeC++ code.
FileNameThe file name which 'Code' will be mapped as.
PCHContainerOpsThe PCHContainerOperations for loading and creating clang modules.
Returns
The resulting AST or null if an error occurred.

Definition at line 506 of file Tooling.cpp.

References buildASTFromCodeWithArgs().

std::unique_ptr< ASTUnit > clang::tooling::buildASTFromCodeWithArgs ( const Twine &  Code,
const std::vector< std::string > &  Args,
const Twine &  FileName = "input.cc",
const Twine &  ToolName = "clang-tool",
std::shared_ptr< PCHContainerOperations >  PCHContainerOps = std::make_shared<PCHContainerOperations>(),
ArgumentsAdjuster  Adjuster = getClangStripDependencyFileAdjuster() 
)

Builds an AST for 'Code' with additional flags.

Parameters
CodeC++ code.
ArgsAdditional flags to pass on.
FileNameThe file name which 'Code' will be mapped as.
ToolNameThe name of the binary running the tool. Standard library header paths will be resolved relative to this.
PCHContainerOpsThe PCHContainerOperations for loading and creating clang modules.
AdjusterA function to filter the command line arguments as specified.
Returns
The resulting AST or null if an error occurred.

Definition at line 512 of file Tooling.cpp.

References Action, ASTs, clang::vfs::getRealFileSystem(), and getSyntaxOnlyToolArgs().

Referenced by buildASTFromCode().

std::vector< Range > clang::tooling::calculateRangesAfterReplacements ( const Replacements &  Replaces,
const std::vector< Range > &  Ranges 
)

Calculates the new ranges after Replaces are applied.

These include both the original Ranges and the affected ranges of Replaces in the new code.

Precondition
Replacements must be for the same file.
Returns
The new ranges after Replaces are applied. The new ranges will be sorted and non-overlapping.

Definition at line 489 of file Replacement.cpp.

References clang::tooling::Replacements::add(), clang::tooling::Replacements::begin(), combineAndSortRanges(), clang::tooling::Replacements::empty(), clang::tooling::Replacements::getAffectedRanges(), clang::tooling::Replacements::merge(), and Replacement.

Referenced by clang::format::reformat().

ArgumentsAdjuster clang::tooling::combineAdjusters ( ArgumentsAdjuster  First,
ArgumentsAdjuster  Second 
)

Gets an argument adjuster which adjusts the arguments in sequence with the First adjuster and then with the Second one.

Definition at line 97 of file ArgumentsAdjusters.cpp.

Referenced by clang::tooling::ClangTool::appendArgumentsAdjuster().

static std::vector<Range> clang::tooling::combineAndSortRanges ( std::vector< Range >  Ranges)
static
std::vector< tooling::AtomicChange > clang::tooling::createRenameAtomicChanges ( llvm::ArrayRef< std::string >  USRs,
llvm::StringRef  NewName,
Decl *  TranslationUnitDecl 
)

Create atomic changes for renaming all symbol references which are identified by the USRs set to a given new name.

Parameters
USRsThe set containing USRs of a particular old symbol.
NewNameThe new name to replace old symbol name.
TranslationUnitDeclThe translation unit declaration.
Returns
Atomic changes for renaming.

Definition at line 403 of file USRLocFinder.cpp.

References End, Finder, clang::Decl::getASTContext(), clang::ASTContext::getSourceManager(), clang::tooling::AtomicChange::replace(), replaceNestedName(), Text, and clang::threadSafety::sx::toString().

Referenced by clang::tooling::USRSymbolRenamer::HandleTranslationUnit().

bool clang::tooling::formatAndApplyAllReplacements ( const std::map< std::string, Replacements > &  FileToReplaces,
Rewriter &  Rewrite,
StringRef  Style = "file" 
)

Groups Replaces by the file path and applies each group of Replacements on the related file in Rewriter.

In addition to applying given Replacements, this function also formats the changed code.

Precondition
Replacements must be conflict-free.

FileToReplaces will be deduplicated with groupReplacementsByFile before application.

Replacement applications happen independently of the success of other applications.

Parameters
[in]FileToReplacesReplacements (grouped by files) to apply.
[in]RewriteThe Rewritter to apply replacements on.
[in]StyleThe style name used for reformatting. See getStyle in "include/clang/Format/Format.h" for all possible style forms.
Returns
true if all replacements applied and formatted. false otherwise.

Definition at line 70 of file Refactoring.cpp.

References applyAllReplacements(), clang::SrcMgr::C_User, FilePath, clang::format::formatReplacements(), clang::SourceManager::getBufferData(), clang::FileManager::getFile(), clang::SourceManager::getFileManager(), clang::SourceManager::getOrCreateFileID(), clang::Rewriter::getSourceMgr(), clang::format::getStyle(), groupReplacementsByFile(), ID, Result, SM, and clang::threadSafety::sx::toString().

std::string clang::tooling::getAbsolutePath ( StringRef  File)

Returns the absolute path of File, by prepending it with the current directory if File is not absolute.

Otherwise returns File. If 'File' starts with "./", the returned path will not contain the "./". Otherwise, the returned path will contain the literal path-concatenation of the current directory and File.

The difference to llvm::sys::fs::make_absolute is the canonicalization this does by removing "./" and computing native paths.

Parameters
FileEither an absolute or relative path.

Definition at line 162 of file Tooling.cpp.

Referenced by clang::tooling::CompilationDatabase::autoDetectFromDirectory(), clang::tooling::CompilationDatabase::autoDetectFromSource(), and clang::tooling::ClangTool::run().

static const llvm::opt::ArgStringList* clang::tooling::getCC1Arguments ( clang::DiagnosticsEngine Diagnostics,
clang::driver::Compilation Compilation 
)
static
ArgumentsAdjuster clang::tooling::getClangStripDependencyFileAdjuster ( )

Gets an argument adjuster which removes dependency-file related command line arguments.

Definition at line 54 of file ArgumentsAdjusters.cpp.

Referenced by clang::tooling::ClangTool::ClangTool(), and runToolOnCodeWithArgs().

ArgumentsAdjuster clang::tooling::getClangStripOutputAdjuster ( )

Gets an argument adjuster which removes output-related command line arguments.

Definition at line 36 of file ArgumentsAdjusters.cpp.

Referenced by clang::tooling::ClangTool::ClangTool().

ArgumentsAdjuster clang::tooling::getClangSyntaxOnlyAdjuster ( )

Gets an argument adjuster that converts input command line arguments to the "syntax check only" variant.

Add -fsyntax-only option to the command line arguments.

Definition at line 21 of file ArgumentsAdjusters.cpp.

Referenced by clang::tooling::ClangTool::ClangTool().

ArgumentsAdjuster clang::tooling::getInsertArgumentAdjuster ( const CommandLineArguments &  Extra,
ArgumentInsertPosition  Pos 
)

Gets an argument adjuster which inserts Extra arguments in the specified position.

Definition at line 74 of file ArgumentsAdjusters.cpp.

References END, and I.

Referenced by getInsertArgumentAdjuster().

ArgumentsAdjuster clang::tooling::getInsertArgumentAdjuster ( const char *  Extra,
ArgumentInsertPosition  Pos = ArgumentInsertPosition::END 
)

Gets an argument adjuster which inserts an Extra argument in the specified position.

Definition at line 92 of file ArgumentsAdjusters.cpp.

References getInsertArgumentAdjuster().

std::vector<SourceLocation> clang::tooling::getLocationsOfUSRs ( const std::vector< std::string > &  USRs,
llvm::StringRef  PrevName,
Decl *  Decl 
)
std::vector<SourceLocation> clang::tooling::getLocationsOfUSRs ( const std::vector< std::string > &  USRs,
StringRef  PrevName,
Decl *  Decl 
)

Definition at line 395 of file USRLocFinder.cpp.

References clang::Decl::getASTContext().

const NamedDecl * clang::tooling::getNamedDeclAt ( const ASTContext &  Context,
const SourceLocation  Point 
)
const NamedDecl * clang::tooling::getNamedDeclFor ( const ASTContext &  Context,
const std::string &  Name 
)

Definition at line 128 of file USRFinder.cpp.

References clang::ASTContext::getTranslationUnitDecl().

static int clang::tooling::getRangeSize ( const SourceManager &  Sources,
const CharSourceRange &  Range,
const LangOptions &  LangOpts 
)
static
static std::string clang::tooling::getReplacementErrString ( replacement_error  Err)
static
static std::vector<std::string> clang::tooling::getSyntaxOnlyToolArgs ( const Twine &  ToolName,
const std::vector< std::string > &  ExtraArgs,
StringRef  FileName 
)
static

Definition at line 115 of file Tooling.cpp.

Referenced by buildASTFromCodeWithArgs(), and runToolOnCodeWithArgs().

std::string clang::tooling::getUSRForDecl ( const Decl *  Decl)

Definition at line 135 of file USRFinder.cpp.

References clang::index::generateUSRForDecl().

std::map< std::string, Replacements > clang::tooling::groupReplacementsByFile ( FileManager &  FileMgr,
const std::map< std::string, Replacements > &  FileToReplaces 
)

If there are multiple <File, Replacements> pairs with the same file entry, we only keep one pair and discard the rest.

If a file does not exist, its corresponding replacements will be ignored.

Definition at line 584 of file Replacement.cpp.

References clang::FileManager::getFile(), and Result.

Referenced by clang::tooling::RefactoringTool::applyAllReplacements(), and formatAndApplyAllReplacements().

static void clang::tooling::injectResourceDir ( CommandLineArguments &  Args,
const char *  Argv0,
void *  MainAddr 
)
static
static clang::driver::Driver* clang::tooling::newDriver ( clang::DiagnosticsEngine Diagnostics,
const char *  BinaryName,
IntrusiveRefCntPtr< vfs::FileSystem >  VFS 
)
static

Builds a clang driver initialized for running clang tools.

Definition at line 53 of file Tooling.cpp.

References clang::driver::Driver::setTitle().

Referenced by clang::tooling::ToolInvocation::run().

template<typename T >
std::unique_ptr< FrontendActionFactory > clang::tooling::newFrontendActionFactory ( )

Returns a new FrontendActionFactory for a given type.

T must derive from clang::FrontendAction.

Example: FrontendActionFactory *Factory = newFrontendActionFactory<clang::SyntaxOnlyAction>();

Definition at line 358 of file Tooling.h.

References clang::serialized_diags::create().

template<typename FactoryT >
std::unique_ptr< FrontendActionFactory > clang::tooling::newFrontendActionFactory ( FactoryT *  ConsumerFactory,
SourceFileCallbacks *  Callbacks = nullptr 
)
inline

Returns a new FrontendActionFactory for any type that provides an implementation of newASTConsumer().

FactoryT must implement: ASTConsumer *newASTConsumer().

Example: struct ProvidesASTConsumers { clang::ASTConsumer *newASTConsumer(); } Factory; std::unique_ptr<FrontendActionFactory> FactoryAdapter( newFrontendActionFactory(&Factory));

Definition at line 369 of file Tooling.h.

References clang::FrontendAction::BeginSourceFileAction(), clang::serialized_diags::create(), clang::FrontendAction::EndSourceFileAction(), clang::tooling::SourceFileCallbacks::handleBeginSource(), and clang::tooling::SourceFileCallbacks::handleEndSource().

clang::CompilerInvocation * clang::tooling::newInvocation ( clang::DiagnosticsEngine Diagnostics,
const llvm::opt::ArgStringList &  CC1Args 
)

Creates a CompilerInvocation.

Returns a clang build invocation initialized from the CC1 flags.

Definition at line 93 of file Tooling.cpp.

References clang::CompilerInvocation::CreateFromArgs().

Referenced by clang::tooling::ToolInvocation::run().

static std::vector<std::string> clang::tooling::nodeToCommandLine ( JSONCommandLineSyntax  Syntax,
const std::vector< llvm::yaml::ScalarNode * > &  Nodes 
)
static

Definition at line 237 of file JSONCompilationDatabase.cpp.

References getValue(), and Node.

bool clang::tooling::operator< ( const Replacement LHS,
const Replacement RHS 
)
bool clang::tooling::operator== ( const Replacement LHS,
const Replacement RHS 
)
std::string clang::tooling::replaceNestedName ( const NestedNameSpecifier Use,
const DeclContext UseContext,
const NamedDecl FromDecl,
StringRef  ReplacementString 
)

Emulate a lookup to replace one nested name specifier with another using as few additional namespace qualifications as possible.

This does not perform a full C++ lookup so ADL will not work.

Parameters
UseThe nested name to be replaced.
UseContextThe context in which the nested name is contained. This will be used to minimize namespace qualifications.
FromDeclThe declaration to which the nested name points.
ReplacementStringThe replacement nested name. Must be fully qualified including a leading "::".
Returns
The new name to be inserted in place of the current nested name.

Definition at line 117 of file Lookup.cpp.

References FromDecl, getBestNamespaceSubstr(), clang::Decl::getDeclContext(), isFullyQualified(), and usingFromDifferentCanonicalNamespace().

Referenced by createRenameAtomicChanges().

static Replacement clang::tooling::replaceStmtWithStmt ( SourceManager &  Sources,
const Stmt &  From,
const Stmt &  To 
)
static
static Replacement clang::tooling::replaceStmtWithText ( SourceManager &  Sources,
const Stmt &  From,
StringRef  Text 
)
static
bool clang::tooling::runToolOnCode ( clang::FrontendAction ToolAction,
const Twine &  Code,
const Twine &  FileName = "input.cc",
std::shared_ptr< PCHContainerOperations >  PCHContainerOps = std::make_shared<PCHContainerOperations>() 
)

Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag.

Parameters
ToolActionThe action to run over the code.
CodeC++ code.
FileNameThe file name which 'Code' will be mapped as.
PCHContainerOpsThe PCHContainerOperations for loading and creating clang modules.
Returns
- True if 'ToolAction' was successfully executed.

Definition at line 106 of file Tooling.cpp.

References runToolOnCodeWithArgs().

bool clang::tooling::runToolOnCodeWithArgs ( clang::FrontendAction ToolAction,
const Twine &  Code,
const std::vector< std::string > &  Args,
const Twine &  FileName = "input.cc",
const Twine &  ToolName = "clang-tool",
std::shared_ptr< PCHContainerOperations >  PCHContainerOps = std::make_shared<PCHContainerOperations>(),
const FileContentMappings &  VirtualMappedFiles = FileContentMappings() 
)

Runs (and deletes) the tool on 'Code' with the -fsyntax-only flag and with additional other flags.

Parameters
ToolActionThe action to run over the code.
CodeC++ code.
ArgsAdditional flags to pass on.
FileNameThe file name which 'Code' will be mapped as.
ToolNameThe name of the binary running the tool. Standard library header paths will be resolved relative to this.
PCHContainerOpsThe PCHContainerOperations for loading and creating clang modules.
Returns
- True if 'ToolAction' was successfully executed.

Definition at line 126 of file Tooling.cpp.

References getClangStripDependencyFileAdjuster(), clang::vfs::getRealFileSystem(), and getSyntaxOnlyToolArgs().

Referenced by runToolOnCode().

static CompilationDatabasePluginRegistry::Add<JSONCompilationDatabasePlugin> clang::tooling::X ( "json-compilation-database"  ,
"Reads JSON formatted compilation databases"   
)
static

Variable Documentation

const char* const clang::tooling::InvalidLocation = ""
static

Definition at line 31 of file Replacement.cpp.

Referenced by clang::tooling::Replacement::isApplicable().

int LLVM_ATTRIBUTE_UNUSED clang::tooling::JSONAnchorDest = JSONAnchorSource
static

Definition at line 343 of file CompilationDatabase.cpp.

volatile int clang::tooling::JSONAnchorSource = 0

Definition at line 163 of file JSONCompilationDatabase.cpp.