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

Namespaces

 dependencies
 
 detail
 The following three functions are a low-level part of the RewriteRule API.
 
 fixit
 
 internal
 
 stencil
 
 traits
 

Classes

class  AllTUsToolExecutor
 Executes given frontend actions on all files/TUs in the compilation database. More...
 
class  AllTUsToolExecutorPlugin
 
struct  ApplyChangesSpec
 
class  ArgumentsAdjustingCompilations
 
struct  ASTEdit
 
class  ASTMatchRefactorer
 Adaptor between ast_matchers::MatchFinder and tooling::RefactoringTool. More...
 
class  ASTSelectionRequirement
 An AST selection requirement is satisfied when any portion of the AST overlaps with the selection range. More...
 
class  AtomicChange
 An atomic change is used to create and group a set of source edits, e.g. More...
 
class  ClangTool
 Utility to run a FrontendAction over a set of files. More...
 
class  CodeRangeASTSelection
 An AST selection value that corresponds to a selection of a set of statements that belong to one body of code (like one function). More...
 
class  CodeRangeASTSelectionRequirement
 A selection requirement that is satisfied when the selection range overlaps with a number of neighbouring statements in the AST. More...
 
class  CommonOptionsParser
 A parser for options common to all command-line Clang tools. More...
 
class  CompilationDatabase
 Interface for compilation databases. More...
 
class  CompilationDatabasePlugin
 Interface for compilation database plugins. More...
 
struct  CompileCommand
 Specifies the working directory and command of a compilation. More...
 
struct  Diagnostic
 Represents the diagnostic with the level of severity and possible fixes to be applied. More...
 
struct  DiagnosticMessage
 Represents the diagnostic message with the error message associated and the information on the location of the problem. More...
 
class  ExecutionContext
 The context of an execution, including the information about compilation and results. More...
 
class  ExtractFunction
 An "Extract Function" refactoring moves code into a new function that's then called from the place where the original code was. More...
 
class  ExtractionSemicolonPolicy
 Determines which semicolons should be inserted during extraction. More...
 
class  FileMatchTrie
 A trie to efficiently match against the entries of the compilation database in order of matching suffix length. More...
 
class  FileMatchTrieNode
 A node of the FileMatchTrie. More...
 
class  FindSymbolOccurrencesRefactoringRule
 A type of refactoring action rule that finds a set of symbol occurrences that reference a particular symbol. More...
 
class  FixedCompilationDatabase
 A compilation database that returns a single compile command line. More...
 
class  FrontendActionFactory
 Interface to generate clang::FrontendActions. More...
 
class  HeaderIncludes
 Generates replacements for inserting or deleting #include directives in a file. More...
 
class  IncludeCategoryManager
 This class manages priorities of C++ #include categories and calculates priorities for headers. More...
 
struct  IncludeStyle
 Style for sorting and grouping C++ #include directives. More...
 
class  InMemoryToolResults
 Stores the key-value results in memory. More...
 
class  JSONCompilationDatabase
 
class  NamedDeclFindingConsumer
 
class  OptionalRefactoringOption
 A refactoring option that stores a value of type T. More...
 
class  OptionRequirement
 A requirement that evaluates to the value of the given OptionType when the OptionType is a required option. More...
 
struct  PathComparator
 
class  QualifiedRenameRule
 
class  QualifiedRenamingAction
 Rename all symbols identified by the given USRs. More...
 
class  Range
 A source range independent of the SourceManager. More...
 
class  RecursiveSymbolVisitor
 Traverses the AST and visits the occurrence of each named symbol in the given nodes. More...
 
class  RefactoringAction
 A refactoring action is a class that defines a set of related refactoring action rules. More...
 
class  RefactoringActionRule
 A refactoring action rule is a wrapper class around a specific refactoring action rule (SourceChangeRefactoringRule, etc) that, in addition to invoking the action, describes the requirements that determine when the action can be initiated. More...
 
class  RefactoringActionRuleBase
 A common refactoring action rule interface that defines the 'invoke' function that performs the refactoring operation (either fully or partially). More...
 
class  RefactoringActionRuleRequirement
 A refactoring action rule requirement determines when a refactoring action rule can be invoked. More...
 
class  RefactoringASTConsumer
 
class  RefactoringCallback
 Base class for RefactoringCallbacks. More...
 
struct  RefactoringDescriptor
 
class  RefactoringOption
 A refactoring option is an interface that describes a value that has an impact on the outcome of a refactoring. More...
 
class  RefactoringOptionsRequirement
 A base class for any requirement that requires some refactoring options. More...
 
class  RefactoringOptionVisitor
 An interface that declares functions that handle different refactoring option types. More...
 
class  RefactoringResultConsumer
 An abstract interface that consumes the various refactoring results that can be produced by refactoring actions. More...
 
class  RefactoringRuleContext
 The refactoring rule context stores all of the inputs that might be needed by a refactoring action rule. More...
 
class  RefactoringTool
 A tool to run refactorings. More...
 
class  RenameOccurrences
 
class  RenamingAction
 
class  RenamingASTConsumer
 
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  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...
 
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  ReplaceStmtWithText
 Replace the text of the statement bound to FromId with the text in ToText. More...
 
class  RequiredRefactoringOption
 A required refactoring option that stores a value of type T. More...
 
struct  RewriteRule
 Description of a source-code transformation. More...
 
struct  SelectedASTNode
 Represents a selected AST node. More...
 
class  SourceChangeRefactoringRule
 A type of refactoring action rule that produces source replacements in the form of atomic changes. More...
 
class  SourceFileCallbacks
 Callbacks called before and after each source file processed by a FrontendAction created by the FrontedActionFactory returned by newFrontendActionFactory. More...
 
class  SourceRangeSelectionRequirement
 A selection requirement that is satisfied when any portion of the source text is selected. More...
 
class  SourceSelectionRequirement
 A base class for any requirement that expects some part of the source to be selected in an editor (or the refactoring tool with the -selection option). More...
 
class  StandaloneToolExecutor
 A standalone executor that runs FrontendActions on a given set of TUs in sequence. More...
 
class  StandaloneToolExecutorPlugin
 
class  Stencil
 A sequence of code fragments, references to parameters and code-generation operations that together can be evaluated to (a fragment of) source code, given a match result. More...
 
class  StencilPart
 A copyable facade for a std::unique_ptr<StencilPartInterface>. More...
 
class  StencilPartInterface
 A stencil is represented as a sequence of "parts" that can each individually generate a code string based on a match result. More...
 
class  SymbolName
 A name of a symbol. More...
 
class  SymbolOccurrence
 An occurrence of a symbol in the source. More...
 
class  ToolAction
 Interface to process a clang::CompilerInvocation. More...
 
class  ToolExecutor
 Interface for executing clang frontend actions. More...
 
class  ToolExecutorPlugin
 Interface for factories that create specific executors. More...
 
class  ToolInvocation
 Utility to run a FrontendAction in a single clang invocation. More...
 
class  ToolResults
 An abstraction for the result of a tool execution. More...
 
class  Transformer
 Handles the matcher and callback registration for a single rewrite rule, as defined by the arguments of the constructor. More...
 
struct  TranslationUnitDiagnostics
 Collection of Diagnostics generated from a single translation unit. More...
 
struct  TranslationUnitReplacements
 Collection of Replacements generated from a single translation unit. More...
 
struct  USRFindingAction
 
class  USRSymbolRenamer
 

Typedefs

using CommandLineArguments = std::vector< std::string >
 A sequence of command line arguments. More...
 
using ArgumentsAdjuster = std::function< CommandLineArguments(const CommandLineArguments &, StringRef Filename)>
 A prototype of a command line adjuster. More...
 
using CompilationDatabasePluginRegistry = llvm::Registry< CompilationDatabasePlugin >
 
using AtomicChanges = std::vector< AtomicChange >
 
using RangeSelector = std::function< Expected< CharSourceRange >(const ast_matchers::MatchFinder::MatchResult &)>
 
using RefactoringActionRules = std::vector< std::unique_ptr< RefactoringActionRule > >
 A set of refactoring action rules that should have unique initiation requirements. More...
 
using SymbolOccurrences = std::vector< SymbolOccurrence >
 
using TextGenerator = std::function< Expected< std::string >(const ast_matchers::MatchFinder::MatchResult &)>
 
using ToolExecutorPluginRegistry = llvm::Registry< ToolExecutorPlugin >
 
using FileContentMappings = std::vector< std::pair< std::string, std::string > >
 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...
 
enum  SourceSelectionKind {
  SourceSelectionKind::None, SourceSelectionKind::ContainsSelection, SourceSelectionKind::ContainsSelectionStart, SourceSelectionKind::ContainsSelectionEnd,
  SourceSelectionKind::InsideSelection
}
 
enum  IncludeFormat { IncludeFormat::Quoted, IncludeFormat::Angled }
 Format of the path in an include directive – angle brackets or quotes. 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 getStripPluginsAdjuster ()
 Gets an argument adjuster which strips plugin related command line arguments. 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::unique_ptr< CompilationDatabaseinferMissingCompileCommands (std::unique_ptr< CompilationDatabase >)
 Returns a wrapped CompilationDatabase that defers to the provided one, but getCompileCommands() will infer commands for unknown files. More...
 
std::unique_ptr< CompilationDatabaseinferTargetAndDriverMode (std::unique_ptr< CompilationDatabase > Base)
 Returns a wrapped CompilationDatabase that will add -target and -mode flags to commandline when they can be deduced from argv[0] of commandline returned by underlying database. More...
 
const llvm::StringMap< Replacements > * selectFirstFix (const Diagnostic &D)
 Get the first fix to apply for this diagnostic. More...
 
std::string replaceNestedName (const NestedNameSpecifier *Use, SourceLocation UseLoc, 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, ReplacementsgroupReplacementsByFile (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...
 
llvm::Expected< std::unique_ptr< ToolExecutor > > createExecutorFromCommandLineArgs (int &argc, const char **argv, llvm::cl::OptionCategory &Category, const char *Overview=nullptr)
 This creates a ToolExecutor that is in the global registry based on commandline arguments. More...
 
Optional< SelectedASTNodefindSelectedASTNodes (const ASTContext &Context, SourceRange SelectionRange)
 Traverses the given ASTContext and creates a tree of selected AST nodes. More...
 
llvm::Expected< std::string > applyAtomicChanges (llvm::StringRef FilePath, llvm::StringRef Code, llvm::ArrayRef< AtomicChange > Changes, const ApplyChangesSpec &Spec)
 Applies all AtomicChanges in Changes to the Code. More...
 
RangeSelector charRange (CharSourceRange R)
 
RangeSelector range (RangeSelector Begin, RangeSelector End)
 Selects from the start of Begin and to the end of End. More...
 
RangeSelector range (std::string BeginID, std::string EndID)
 Convenience version of range where end-points are bound nodes. More...
 
RangeSelector before (RangeSelector Selector)
 Selects the (empty) range [B,B) when Selector selects the range [B,E). More...
 
RangeSelector after (RangeSelector Selector)
 Selects the the point immediately following Selector. More...
 
RangeSelector node (std::string ID)
 Selects a node, including trailing semicolon (for non-expression statements). More...
 
RangeSelector statement (std::string ID)
 Selects a node, including trailing semicolon (always). More...
 
RangeSelector member (std::string ID)
 Given a MemberExpr, selects the member token. More...
 
RangeSelector name (std::string ID)
 Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name's token. More...
 
RangeSelector callArgs (std::string ID)
 
RangeSelector statements (std::string ID)
 
RangeSelector initListElements (std::string ID)
 
RangeSelector expansion (RangeSelector S)
 Selects the range from which S was expanded (possibly along with other source), if S is an expansion, and S itself, otherwise. More...
 
std::vector< std::unique_ptr< RefactoringAction > > createRefactoringActions ()
 Returns the list of all the available refactoring actions. More...
 
template<typename RuleType , typename... RequirementTypes>
std::unique_ptr< RefactoringActionRulecreateRefactoringActionRule (const RequirementTypes &... Requirements)
 Creates a new refactoring action rule that constructs and invokes the RuleType rule when all of the requirements are satisfied. More...
 
template<typename OptionType >
std::shared_ptr< OptionType > createRefactoringOption ()
 Constructs a refactoring option of the given type. More...
 
llvm::Expected< std::vector< AtomicChange > > createRenameReplacements (const SymbolOccurrences &Occurrences, const SourceManager &SM, const SymbolName &NewName)
 Returns source replacements that correspond to the rename of the given symbol occurrences. More...
 
const NamedDeclgetNamedDeclAt (const ASTContext &Context, const SourceLocation Point)
 
const NamedDeclgetNamedDeclFor (const ASTContext &Context, const std::string &Name)
 
std::string getUSRForDecl (const Decl *Decl)
 
const NamedDeclgetCanonicalSymbolDeclaration (const NamedDecl *FoundDecl)
 Returns the canonical declaration that best represents a symbol that can be renamed. More...
 
std::vector< std::string > getUSRsForDeclaration (const NamedDecl *ND, ASTContext &Context)
 Returns the set of USRs that correspond to the given declaration. More...
 
std::vector< tooling::AtomicChangecreateRenameAtomicChanges (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...
 
SymbolOccurrences getOccurrencesOfUSRs (ArrayRef< std::string > USRs, StringRef PrevName, Decl *Decl)
 Finds the symbol occurrences for the symbol that's identified by the given USR set. More...
 
CharSourceRange maybeExtendRange (CharSourceRange Range, tok::TokenKind Next, ASTContext &Context)
 Extends Range to include the token Next, if it immediately follows the end of the range. More...
 
template<typename T >
CharSourceRange getExtendedRange (const T &Node, tok::TokenKind Next, ASTContext &Context)
 Returns the source range spanning the node, extended to include Next, if it immediately follows Node. More...
 
StringRef getText (CharSourceRange Range, const ASTContext &Context)
 Returns the source-code text in the specified range. More...
 
template<typename T >
StringRef getText (const T &Node, const ASTContext &Context)
 Returns the source-code text corresponding to Node. More...
 
template<typename T >
StringRef getExtendedText (const T &Node, tok::TokenKind Next, ASTContext &Context)
 Returns the source text of the node, extended to include Next, if it immediately follows the node. More...
 
llvm::Optional< CharSourceRangegetRangeForEdit (const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts)
 
llvm::Optional< CharSourceRangegetRangeForEdit (const CharSourceRange &EditRange, const ASTContext &Context)
 
bool operator== (const Stencil &A, const Stencil &B)
 
bool operator!= (const Stencil &A, const Stencil &B)
 
TextGenerator text (std::string M)
 Wraps a string as a TextGenerator. More...
 
RewriteRule makeRule (ast_matchers::internal::DynTypedMatcher M, SmallVector< ASTEdit, 1 > Edits, TextGenerator Explanation=nullptr)
 Convenience function for constructing a simple RewriteRule. More...
 
RewriteRule makeRule (ast_matchers::internal::DynTypedMatcher M, ASTEdit Edit, TextGenerator Explanation=nullptr)
 Convenience overload of makeRule for common case of only one edit. More...
 
void addInclude (RewriteRule &Rule, llvm::StringRef Header, IncludeFormat Format=IncludeFormat::Quoted)
 For every case in Rule, adds an include directive for the given header. More...
 
RewriteRule applyFirst (ArrayRef< RewriteRule > Rules)
 Applies the first rule whose pattern matches; other rules are ignored. More...
 
ASTEdit change (RangeSelector Target, TextGenerator Replacement)
 Replaces a portion of the source text with Replacement. More...
 
ASTEdit change (TextGenerator Replacement)
 Replaces the entirety of a RewriteRule's match with Replacement. More...
 
ASTEdit insertBefore (RangeSelector S, TextGenerator Replacement)
 Inserts Replacement before S, leaving the source selected by unchanged. More...
 
ASTEdit insertAfter (RangeSelector S, TextGenerator Replacement)
 Inserts Replacement after S, leaving the source selected by unchanged. More...
 
ASTEdit remove (RangeSelector S)
 Removes the source selected by S. More...
 
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< FrontendActionFactorynewFrontendActionFactory ()
 Returns a new FrontendActionFactory for a given type. More...
 
template<typename FactoryT >
std::unique_ptr< FrontendActionFactorynewFrontendActionFactory (FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks=nullptr)
 Returns a new FrontendActionFactory for any type that provides an implementation of newASTConsumer(). More...
 
bool runToolOnCode (std::unique_ptr< 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 (std::unique_ptr< 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...
 
bool runToolOnCodeWithArgs (std::unique_ptr< FrontendAction > ToolAction, const Twine &Code, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, 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 >())
 
std::unique_ptr< ASTUnitbuildASTFromCode (StringRef Code, StringRef FileName="input.cc", std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >())
 Builds an AST for 'Code'. More...
 
std::unique_ptr< ASTUnitbuildASTFromCodeWithArgs (StringRef Code, const std::vector< std::string > &Args, StringRef FileName="input.cc", StringRef 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...
 
llvm::Expected< std::string > getAbsolutePath (llvm::vfs::FileSystem &FS, StringRef File)
 An overload of getAbsolutePath that works over the provided FS. 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...
 
CompilerInvocationnewInvocation (DiagnosticsEngine *Diagnostics, const llvm::opt::ArgStringList &CC1Args)
 Creates a CompilerInvocation. More...
 
llvm::cl::opt< std::string > Filter ("filter", llvm::cl::desc("Only process files that match this filter. " "This flag only applies to all-TUs."), llvm::cl::init(".*"))
 
llvm::cl::opt< unsigned > ExecutorConcurrency ("execute-concurrency", llvm::cl::desc("The number of threads used to process all files in " "parallel. Set to 0 for hardware concurrency. " "This flag only applies to all-TUs."), llvm::cl::init(0))
 
static ToolExecutorPluginRegistry::Add< AllTUsToolExecutorPluginX ("all-TUs", "Runs FrontendActions on all TUs in the compilation database. " "Tool results are stored in memory.")
 
llvm::cl::opt< std::string > ExecutorName ("executor", llvm::cl::desc("The name of the executor to use."), llvm::cl::init("standalone"))
 
static void convertChangesToFileReplacements (ArrayRef< AtomicChange > AtomicChanges, std::map< std::string, tooling::Replacements > *FileToReplaces)
 Takes each atomic change and inserts its replacements into the set of replacements that belong to the appropriate file. More...
 
static Replacement replaceStmtWithText (SourceManager &Sources, const Stmt &From, StringRef Text)
 
static Replacement replaceStmtWithStmt (SourceManager &Sources, const Stmt &From, const Stmt &To)
 
static llvm::Error make_string_error (const llvm::Twine &Message)
 
static ArgumentsAdjuster getDefaultArgumentsAdjusters ()
 
static ToolExecutorPluginRegistry::Add< StandaloneToolExecutorPluginX ("standalone", "Runs FrontendActions on a set of files provided " "via positional arguments.")
 

Variables

llvm::cl::opt< unsigned > ExecutorConcurrency
 
llvm::cl::opt< std::string > Filter
 
llvm::cl::opt< std::string > ExecutorName
 
volatile int AllTUsToolExecutorAnchorSource = 0
 
volatile int JSONAnchorSource = 0
 
static int LLVM_ATTRIBUTE_UNUSED JSONAnchorDest = JSONAnchorSource
 
volatile int StandaloneToolExecutorAnchorSource = 0
 
static int LLVM_ATTRIBUTE_UNUSED StandaloneToolExecutorAnchorDest
 
static int LLVM_ATTRIBUTE_UNUSED AllTUsToolExecutorAnchorDest
 

Typedef Documentation

◆ ArgumentsAdjuster

using clang::tooling::ArgumentsAdjuster = typedef std::function<CommandLineArguments( const CommandLineArguments &, StringRef Filename)>

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 36 of file ArgumentsAdjusters.h.

◆ AtomicChanges

using clang::tooling::AtomicChanges = typedef std::vector<AtomicChange>

Definition at line 140 of file AtomicChange.h.

◆ CommandLineArguments

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

A sequence of command line arguments.

Definition at line 29 of file ArgumentsAdjusters.h.

◆ CompilationDatabasePluginRegistry

Definition at line 40 of file CompilationDatabasePluginRegistry.h.

◆ FileContentMappings

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

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

Definition at line 164 of file Tooling.h.

◆ RangeSelector

Definition at line 27 of file RangeSelector.h.

◆ RefactoringActionRules

using clang::tooling::RefactoringActionRules = typedef std::vector<std::unique_ptr<RefactoringActionRule> >

A set of refactoring action rules that should have unique initiation requirements.

Definition at line 45 of file RefactoringActionRules.h.

◆ SymbolOccurrences

Definition at line 85 of file SymbolOccurrences.h.

◆ TextGenerator

using clang::tooling::TextGenerator = typedef std::function<Expected<std::string>( const ast_matchers::MatchFinder::MatchResult &)>

Definition at line 39 of file Transformer.h.

◆ ToolExecutorPluginRegistry

Definition at line 18 of file ToolExecutorPluginRegistry.h.

Enumeration Type Documentation

◆ ArgumentInsertPosition

Enumerator
BEGIN 
END 

Definition at line 50 of file ArgumentsAdjusters.h.

◆ IncludeFormat

Format of the path in an include directive – angle brackets or quotes.

Enumerator
Quoted 
Angled 

Definition at line 90 of file Transformer.h.

◆ JSONCommandLineSyntax

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 60 of file JSONCompilationDatabase.h.

◆ replacement_error

Enumerator
fail_to_apply 
wrong_file_path 
overlap_conflict 
insert_conflict 

Definition at line 145 of file Replacement.h.

◆ SourceSelectionKind

Enumerator
None 

A node that's not selected.

ContainsSelection 

A node that's considered to be selected because the whole selection range is inside of its source range.

ContainsSelectionStart 

A node that's considered to be selected because the start of the selection range is inside its source range.

ContainsSelectionEnd 

A node that's considered to be selected because the end of the selection range is inside its source range.

InsideSelection 

A node that's considered to be selected because the node is entirely in the selection range.

Definition at line 23 of file ASTSelection.h.

Function Documentation

◆ addInclude()

void clang::tooling::addInclude ( RewriteRule Rule,
llvm::StringRef  Header,
IncludeFormat  Format = IncludeFormat::Quoted 
)

For every case in Rule, adds an include directive for the given header.

The common use is assumed to be a rule with only one case. For example, to replace a function call and add headers corresponding to the new code, one could write:

auto R = makeRule(callExpr(callee(functionDecl(hasName("foo")))),
change(text("bar()")));
AddInclude(R, "path/to/bar_header.h");
AddInclude(R, "vector", IncludeFormat::Angled);

Referenced by makeRule().

◆ addTargetAndModeForProgramName()

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 217 of file Tooling.cpp.

Referenced by newFrontendActionFactory().

◆ after()

RangeSelector clang::tooling::after ( RangeSelector  Selector)

Selects the the point immediately following Selector.

That is, the (empty) range [E,E), when Selector selects either

  • the CharRange [B,E) or
  • the TokenRange [B,E'] where the token at E' spans the range [E,E').

Definition at line 116 of file RangeSelector.cpp.

References clang::CharSourceRange::getCharRange(), and clang::Lexer::getLocForEndOfToken().

Referenced by charRange(), clang::edit::Commit::insertBefore(), and clang::edit::Commit::insertWrap().

◆ applyAllReplacements() [1/2]

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 567 of file Replacement.cpp.

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

Referenced by clang::tooling::RefactoringTool::applyAllReplacements(), applyAtomicChanges(), clang::tooling::Replacements::operator==(), and clang::format::processReplacements().

◆ applyAllReplacements() [2/2]

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 579 of file Replacement.cpp.

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

◆ applyAtomicChanges()

llvm::Expected< std::string > clang::tooling::applyAtomicChanges ( llvm::StringRef  FilePath,
llvm::StringRef  Code,
llvm::ArrayRef< AtomicChange Changes,
const ApplyChangesSpec Spec 
)

Applies all AtomicChanges in Changes to the Code.

This completely ignores the file path in each change and replaces them with FilePath, i.e. callers are responsible for ensuring all changes are for the same file.

Returns
The changed code if all changes are applied successfully; otherwise, an llvm::Error carrying llvm::StringError is returned (the Error message can be converted to string with llvm::toString() and the error_code should be ignored).

Definition at line 295 of file AtomicChange.cpp.

References clang::tooling::Replacements::add(), applyAllReplacements(), clang::tooling::ApplyChangesSpec::Cleanup, clang::format::cleanupAroundReplacements(), clang::tooling::ApplyChangesSpec::Format, clang::tooling::Replacements::getAffectedRanges(), clang::format::make_string_error(), clang::tooling::Replacements::merge(), clang::format::reformat(), clang::format::sortIncludes(), clang::tooling::ApplyChangesSpec::Style, and toString().

◆ applyFirst()

RewriteRule clang::tooling::applyFirst ( ArrayRef< RewriteRule Rules)

Applies the first rule whose pattern matches; other rules are ignored.

If the matchers are independent then order doesn't matter. In that case, applyFirst is simply joining the set of rules into one.

Definition at line 113 of file Transformer.cpp.

References clang::tooling::RewriteRule::Cases.

Referenced by makeRule().

◆ before()

RangeSelector clang::tooling::before ( RangeSelector  Selector)

Selects the (empty) range [B,B) when Selector selects the range [B,E).

Definition at line 107 of file RangeSelector.cpp.

References clang::CharSourceRange::getCharRange().

Referenced by charRange(), clang::CodeGen::CodeGenFunction::createBasicBlock(), clang::edit::Commit::insertBefore(), and clang::edit::Commit::insertWrap().

◆ buildASTFromCode()

std::unique_ptr< ASTUnit > clang::tooling::buildASTFromCode ( StringRef  Code,
StringRef  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 586 of file Tooling.cpp.

References buildASTFromCodeWithArgs().

◆ buildASTFromCodeWithArgs()

std::unique_ptr< ASTUnit > clang::tooling::buildASTFromCodeWithArgs ( StringRef  Code,
const std::vector< std::string > &  Args,
StringRef  FileName = "input.cc",
StringRef  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 592 of file Tooling.cpp.

References getSyntaxOnlyToolArgs().

Referenced by buildASTFromCode().

◆ calculateRangesAfterReplacements()

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 510 of file Replacement.cpp.

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

◆ callArgs()

RangeSelector clang::tooling::callArgs ( std::string  ID)

◆ change() [1/2]

ASTEdit clang::tooling::change ( RangeSelector  Target,
TextGenerator  Replacement 
)

Replaces a portion of the source text with Replacement.

Definition at line 64 of file Transformer.cpp.

Referenced by change(), and makeRule().

◆ change() [2/2]

ASTEdit clang::tooling::change ( TextGenerator  Replacement)
inline

Replaces the entirety of a RewriteRule's match with Replacement.

For example, to replace a function call, one could write:

change(text("bar()")))

Definition at line 213 of file Transformer.h.

References change(), node(), and clang::tooling::RewriteRule::RootID.

◆ charRange()

RangeSelector clang::tooling::charRange ( CharSourceRange  R)
inline

◆ combineAdjusters()

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 103 of file ArgumentsAdjusters.cpp.

Referenced by clang::tooling::ClangTool::appendArgumentsAdjuster(), clang::tooling::ArgumentsAdjustingCompilations::getAllCompileCommands(), and getDefaultArgumentsAdjusters().

◆ convertChangesToFileReplacements()

static void clang::tooling::convertChangesToFileReplacements ( ArrayRef< AtomicChange AtomicChanges,
std::map< std::string, tooling::Replacements > *  FileToReplaces 
)
static

Takes each atomic change and inserts its replacements into the set of replacements that belong to the appropriate file.

Definition at line 168 of file RenamingAction.cpp.

References clang::tooling::AtomicChange::getReplacements(), and toString().

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

◆ createExecutorFromCommandLineArgs()

llvm::Expected< std::unique_ptr< ToolExecutor > > clang::tooling::createExecutorFromCommandLineArgs ( int &  argc,
const char **  argv,
llvm::cl::OptionCategory &  Category,
const char *  Overview = nullptr 
)

This creates a ToolExecutor that is in the global registry based on commandline arguments.

This picks the right executor based on the --executor option. This parses the commandline arguments with CommonOptionsParser, so caller does not need to parse again.

By default, this creates a StandaloneToolExecutor ("standalone") if --executor is not provided.

Definition at line 90 of file Execution.cpp.

References AllTUsToolExecutorAnchorSource, clang::tooling::internal::createExecutorFromCommandLineArgsImpl(), and StandaloneToolExecutorAnchorSource.

Referenced by clang::tooling::ToolExecutorPlugin::~ToolExecutorPlugin().

◆ createRefactoringActionRule()

template<typename RuleType , typename... RequirementTypes>
std::unique_ptr< RefactoringActionRule > clang::tooling::createRefactoringActionRule ( const RequirementTypes &...  Requirements)

Creates a new refactoring action rule that constructs and invokes the RuleType rule when all of the requirements are satisfied.

This function takes in a list of values whose type derives from RefactoringActionRuleRequirement. These values describe the initiation requirements that have to be satisfied by the refactoring engine before the provided action rule can be constructed and invoked. The engine verifies that the requirements are satisfied by evaluating them (using the 'evaluate' member function) and checking that the results don't contain any errors. Once all requirements are satisfied, the provided refactoring rule is constructed by passing in the values returned by the requirements' evaluate functions as arguments to the constructor. The rule is then invoked immediately after construction.

The separation of requirements, their evaluation and the invocation of the refactoring action rule allows the refactoring clients to:

  • Disable refactoring action rules whose requirements are not supported.
  • Gather the set of options and define a command-line / visual interface that allows users to input these options without ever invoking the action.

Definition at line 118 of file RefactoringActionRulesInternal.h.

◆ createRefactoringActions()

std::vector< std::unique_ptr< RefactoringAction > > clang::tooling::createRefactoringActions ( )

Returns the list of all the available refactoring actions.

Definition at line 98 of file RefactoringActions.cpp.

Referenced by clang::tooling::RefactoringAction::~RefactoringAction().

◆ createRefactoringOption()

template<typename OptionType >
std::shared_ptr<OptionType> clang::tooling::createRefactoringOption ( )

Constructs a refactoring option of the given type.

The ownership of options is shared among requirements that use it because one option can be used by multiple rules in a refactoring action.

Definition at line 54 of file RefactoringOption.h.

◆ createRenameAtomicChanges()

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 511 of file USRLocFinder.cpp.

Referenced by clang::tooling::QualifiedRenameRule::describe(), and clang::tooling::USRSymbolRenamer::HandleTranslationUnit().

◆ createRenameReplacements()

Expected< std::vector< AtomicChange > > clang::tooling::createRenameReplacements ( const SymbolOccurrences Occurrences,
const SourceManager SM,
const SymbolName NewName 
)

Returns source replacements that correspond to the rename of the given symbol occurrences.

Definition at line 145 of file RenamingAction.cpp.

◆ ExecutorConcurrency()

llvm::cl::opt<unsigned> clang::tooling::ExecutorConcurrency ( "execute-concurrency"  ,
llvm::cl::desc("The number of threads used to process all files in " "parallel. Set to 0 for hardware concurrency. " "This flag only applies to all-TUs.")  ,
llvm::cl::init(0)   
)

◆ ExecutorName()

llvm::cl::opt<std::string> clang::tooling::ExecutorName ( "executor"  ,
llvm::cl::desc("The name of the executor to use.")  ,
llvm::cl::init("standalone")   
)

◆ expansion()

RangeSelector clang::tooling::expansion ( RangeSelector  S)

Selects the range from which S was expanded (possibly along with other source), if S is an expansion, and S itself, otherwise.

Corresponds to SourceManager::getExpansionRange.

Definition at line 289 of file RangeSelector.cpp.

Referenced by charRange().

◆ Filter()

llvm::cl::opt<std::string> clang::tooling::Filter ( "filter"  ,
llvm::cl::desc("Only process files that match this filter. " "This flag only applies to all-TUs.")  ,
llvm::cl::init(".*")   
)

◆ findSelectedASTNodes()

Optional< SelectedASTNode > clang::tooling::findSelectedASTNodes ( const ASTContext Context,
SourceRange  SelectionRange 
)

Traverses the given ASTContext and creates a tree of selected AST nodes.

Returns
None if no nodes are selected in the AST, or a selected AST node that corresponds to the TranslationUnitDecl otherwise.

Definition at line 183 of file ASTSelection.cpp.

References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), clang::SourceManager::getFileID(), clang::ASTContext::getSourceManager(), clang::ASTContext::getTranslationUnitDecl(), clang::SourceLocation::isPairOfFileLocations(), and clang::SourceRange::isValid().

◆ formatAndApplyAllReplacements()

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 69 of file Refactoring.cpp.

References clang::tooling::RefactoringTool::applyAllReplacements(), clang::SrcMgr::C_User, clang::format::formatReplacements(), clang::SourceManager::getBufferData(), clang::FileManager::getFile(), clang::SourceManager::getFileManager(), clang::SourceManager::getOrCreateFileID(), clang::Rewriter::getSourceMgr(), clang::format::getStyle(), groupReplacementsByFile(), SM, and toString().

◆ getAbsolutePath() [1/2]

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 213 of file Tooling.cpp.

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

◆ getAbsolutePath() [2/2]

llvm::Expected< std::string > clang::tooling::getAbsolutePath ( llvm::vfs::FileSystem &  FS,
StringRef  File 
)

An overload of getAbsolutePath that works over the provided FS.

Definition at line 198 of file Tooling.cpp.

Referenced by newFrontendActionFactory().

◆ getCanonicalSymbolDeclaration()

const NamedDecl * clang::tooling::getCanonicalSymbolDeclaration ( const NamedDecl FoundDecl)

Returns the canonical declaration that best represents a symbol that can be renamed.

The following canonicalization rules are currently used:

  • A constructor is canonicalized to its class.
  • A destructor is canonicalized to its class.

Definition at line 41 of file USRFindingAction.cpp.

Referenced by clang::tooling::RenameOccurrences::initiate().

◆ getClangStripDependencyFileAdjuster()

ArgumentsAdjuster clang::tooling::getClangStripDependencyFileAdjuster ( )

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

Definition at line 60 of file ArgumentsAdjusters.cpp.

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

◆ getClangStripOutputAdjuster()

ArgumentsAdjuster clang::tooling::getClangStripOutputAdjuster ( )

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

Definition at line 42 of file ArgumentsAdjusters.cpp.

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

◆ getClangSyntaxOnlyAdjuster()

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 23 of file ArgumentsAdjusters.cpp.

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

◆ getDefaultArgumentsAdjusters()

static ArgumentsAdjuster clang::tooling::getDefaultArgumentsAdjusters ( )
static

◆ getExtendedRange()

template<typename T >
CharSourceRange clang::tooling::getExtendedRange ( const T &  Node,
tok::TokenKind  Next,
ASTContext Context 
)

Returns the source range spanning the node, extended to include Next, if it immediately follows Node.

Otherwise, returns the normal range of Node. See comments on getExtendedText() for examples.

Definition at line 32 of file SourceCode.h.

Referenced by node(), and statement().

◆ getExtendedText()

template<typename T >
StringRef clang::tooling::getExtendedText ( const T &  Node,
tok::TokenKind  Next,
ASTContext Context 
)

Returns the source text of the node, extended to include Next, if it immediately follows the node.

Otherwise, returns the text of just Node.

For example, given statements S1 and S2 below:

{
// S1:
if (!x) return foo();
// S2:
if (!x) { return 3; }
}

then

getText(S1, Context) = "if (!x) return foo()"
getExtendedText(S1, tok::TokenKind::semi, Context)
= "if (!x) return foo();"
getExtendedText(*S1.getThen(), tok::TokenKind::semi, Context)
= "return foo();"
getExtendedText(*S2.getThen(), tok::TokenKind::semi, Context)
= getText(S2, Context) = "{ return 3; }"

Definition at line 71 of file SourceCode.h.

◆ getInsertArgumentAdjuster() [1/2]

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

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

Definition at line 80 of file ArgumentsAdjusters.cpp.

References END.

Referenced by clang::tooling::ArgumentsAdjustingCompilations::getAllCompileCommands(), and getInsertArgumentAdjuster().

◆ getInsertArgumentAdjuster() [2/2]

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 98 of file ArgumentsAdjusters.cpp.

References getInsertArgumentAdjuster().

◆ getNamedDeclAt()

const NamedDecl * clang::tooling::getNamedDeclAt ( const ASTContext Context,
const SourceLocation  Point 
)

Definition at line 76 of file USRFinder.cpp.

Referenced by clang::tooling::RenameOccurrences::initiate().

◆ getNamedDeclFor()

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

Definition at line 127 of file USRFinder.cpp.

Referenced by clang::tooling::QualifiedRenameRule::initiate().

◆ getOccurrencesOfUSRs()

SymbolOccurrences clang::tooling::getOccurrencesOfUSRs ( ArrayRef< std::string >  USRs,
StringRef  PrevName,
Decl Decl 
)

Finds the symbol occurrences for the symbol that's identified by the given USR set.

Returns
SymbolOccurrences that can be converted to AtomicChanges when renaming.

Definition at line 503 of file USRLocFinder.cpp.

◆ getRangeForEdit() [1/2]

llvm::Optional< CharSourceRange > clang::tooling::getRangeForEdit ( const CharSourceRange EditRange,
const SourceManager SM,
const LangOptions LangOpts 
)

◆ getRangeForEdit() [2/2]

llvm::Optional<CharSourceRange> clang::tooling::getRangeForEdit ( const CharSourceRange EditRange,
const ASTContext Context 
)
inline

◆ getStripPluginsAdjuster()

ArgumentsAdjuster clang::tooling::getStripPluginsAdjuster ( )

Gets an argument adjuster which strips plugin related command line arguments.

Definition at line 114 of file ArgumentsAdjusters.cpp.

◆ getText() [1/2]

StringRef clang::tooling::getText ( CharSourceRange  Range,
const ASTContext Context 
)

Returns the source-code text in the specified range.

Definition at line 17 of file SourceCode.cpp.

Referenced by evalData(), getText(), and name().

◆ getText() [2/2]

template<typename T >
StringRef clang::tooling::getText ( const T &  Node,
const ASTContext Context 
)

Returns the source-code text corresponding to Node.

Definition at line 43 of file SourceCode.h.

References getText(), and clang::CharSourceRange::getTokenRange().

◆ getUSRForDecl()

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

Definition at line 134 of file USRFinder.cpp.

References clang::index::generateUSRForDecl().

◆ getUSRsForDeclaration()

std::vector< std::string > clang::tooling::getUSRsForDeclaration ( const NamedDecl ND,
ASTContext Context 
)

Returns the set of USRs that correspond to the given declaration.

Definition at line 176 of file USRFindingAction.cpp.

Referenced by clang::tooling::QualifiedRenameRule::describe().

◆ groupReplacementsByFile()

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 611 of file Replacement.cpp.

References clang::FileManager::getFile().

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

◆ inferMissingCompileCommands()

std::unique_ptr< CompilationDatabase > clang::tooling::inferMissingCompileCommands ( std::unique_ptr< CompilationDatabase Inner)

Returns a wrapped CompilationDatabase that defers to the provided one, but getCompileCommands() will infer commands for unknown files.

The return value of getAllFiles() or getAllCompileCommands() is unchanged. See InterpolatingCompilationDatabase.cpp for details on heuristics.

Definition at line 539 of file InterpolatingCompilationDatabase.cpp.

◆ inferTargetAndDriverMode()

std::unique_ptr< CompilationDatabase > clang::tooling::inferTargetAndDriverMode ( std::unique_ptr< CompilationDatabase Base)

Returns a wrapped CompilationDatabase that will add -target and -mode flags to commandline when they can be deduced from argv[0] of commandline returned by underlying database.

Definition at line 52 of file GuessTargetAndModeCompilationDatabase.cpp.

◆ initListElements()

RangeSelector clang::tooling::initListElements ( std::string  ID)

Definition at line 285 of file RangeSelector.cpp.

Referenced by charRange().

◆ insertAfter()

ASTEdit clang::tooling::insertAfter ( RangeSelector  S,
TextGenerator  Replacement 
)
inline

Inserts Replacement after S, leaving the source selected by unchanged.

Definition at line 225 of file Transformer.h.

◆ insertBefore()

ASTEdit clang::tooling::insertBefore ( RangeSelector  S,
TextGenerator  Replacement 
)
inline

Inserts Replacement before S, leaving the source selected by unchanged.

Definition at line 219 of file Transformer.h.

◆ make_string_error()

static llvm::Error clang::tooling::make_string_error ( const llvm::Twine &  Message)
static

◆ makeRule() [1/2]

RewriteRule clang::tooling::makeRule ( ast_matchers::internal::DynTypedMatcher  M,
SmallVector< ASTEdit, 1 >  Edits,
TextGenerator  Explanation = nullptr 
)

Convenience function for constructing a simple RewriteRule.

Referenced by makeRule().

◆ makeRule() [2/2]

RewriteRule clang::tooling::makeRule ( ast_matchers::internal::DynTypedMatcher  M,
ASTEdit  Edit,
TextGenerator  Explanation = nullptr 
)
inline

Convenience overload of makeRule for common case of only one edit.

Definition at line 142 of file Transformer.h.

References addInclude(), applyFirst(), change(), makeRule(), Quoted, and clang::Target.

◆ maybeExtendRange()

CharSourceRange clang::tooling::maybeExtendRange ( CharSourceRange  Range,
tok::TokenKind  Next,
ASTContext Context 
)

Extends Range to include the token Next, if it immediately follows the end of the range.

Otherwise, returns Range unchanged.

Definition at line 23 of file SourceCode.cpp.

◆ member()

RangeSelector clang::tooling::member ( std::string  ID)

Given a MemberExpr, selects the member token.

ID is the node's binding in the match result.

Definition at line 172 of file RangeSelector.cpp.

References getNode(), clang::CharSourceRange::getTokenRange(), Node, and typeError().

Referenced by charRange(), findRetainCycleOwner(), and isExplicitMemberSpecialization().

◆ name()

RangeSelector clang::tooling::name ( std::string  ID)

Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name's token.

Only selects the final identifier of a qualified name, but not any qualifiers or template arguments. For example, for ::foo::bar::baz and ::foo::bar::baz<int>, it selects only baz.

Parameters
IDis the node's binding in the match result.

Definition at line 184 of file RangeSelector.cpp.

References clang::ast_type_traits::DynTypedNode::get(), clang::CharSourceRange::getCharRange(), clang::CompoundStmt::getLBracLoc(), clang::SourceLocation::getLocWithOffset(), getNode(), clang::ast_type_traits::DynTypedNode::getNodeKind(), clang::CompoundStmt::getRBracLoc(), getText(), clang::CharSourceRange::getTokenRange(), missingPropertyError(), Node, clang::ast_matchers::MatchFinder::MatchResult::Nodes, and typeError().

Referenced by charRange(), createLoadInstBefore(), clang::Sema::Diag(), emitArraySubscriptGEP(), clang::CodeGen::CodeGenFunction::EmitBlockLiteral(), clang::CodeGen::CodeGenFunction::emitByrefStructureInit(), clang::CodeGen::CodeGenVTables::EmitThunks(), clang::CodeGen::CodeGenFunction::GenerateBlockFunction(), clang::ento::BugReporter::getAnalyzerOptions(), clang::CodeGen::CodeGenFunction::getCleanupKind(), getFunctionSourceLocation(), clang::Selector::getInstTypeMethodFamily(), clang::NamedDecl::getObjCFStringFormattingFamily(), clang::CodeGen::CodeGenModule::getTerminateFn(), handleObjCOwnershipTypeAttr(), clang::CodeGen::ConstantInitFuture::installInGlobal(), clang::NSAPI::isNSNumberLiteralSelector(), clang::NSAPI::isSubclassOfNSClass(), mangleAArch64VectorBase(), MigrateBlockOrFunctionPointerTypeVariable(), clang::ento::CheckerManager::setCurrentCheckerName(), clang::ObjCDeclSpec::setGetterName(), clang::ObjCDeclSpec::setSetterName(), startsWithWord(), and clang::CodeGen::ConstantInitBuilderBase::~ConstantInitBuilderBase().

◆ newFrontendActionFactory() [1/2]

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 398 of file Tooling.h.

References clang::serialized_diags::create().

◆ newFrontendActionFactory() [2/2]

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 411 of file Tooling.h.

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

Referenced by clang::tooling::SourceFileCallbacks::handleEndSource().

◆ newInvocation()

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

Creates a CompilerInvocation.

Returns a clang build invocation initialized from the CC1 flags.

Definition at line 117 of file Tooling.cpp.

References clang::CompilerInvocation::CreateFromArgs().

Referenced by newFrontendActionFactory(), and clang::tooling::ToolInvocation::run().

◆ node()

RangeSelector clang::tooling::node ( std::string  ID)

◆ operator!=()

bool clang::tooling::operator!= ( const Stencil A,
const Stencil B 
)
inline

Definition at line 135 of file Stencil.h.

◆ operator<()

bool clang::tooling::operator< ( const Replacement LHS,
const Replacement RHS 
)

◆ operator==() [1/2]

bool clang::tooling::operator== ( const Stencil A,
const Stencil B 
)
inline

Definition at line 131 of file Stencil.h.

◆ operator==() [2/2]

bool clang::tooling::operator== ( const Replacement LHS,
const Replacement RHS 
)

◆ range() [1/2]

RangeSelector clang::tooling::range ( RangeSelector  Begin,
RangeSelector  End 
)

◆ range() [2/2]

RangeSelector clang::tooling::range ( std::string  BeginID,
std::string  EndID 
)

Convenience version of range where end-points are bound nodes.

Definition at line 168 of file RangeSelector.cpp.

References node(), and range().

◆ remove()

ASTEdit clang::tooling::remove ( RangeSelector  S)
inline

◆ replaceNestedName()

std::string clang::tooling::replaceNestedName ( const NestedNameSpecifier Use,
SourceLocation  UseLoc,
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.
UseLocThe location of 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 183 of file Lookup.cpp.

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

◆ replaceStmtWithStmt()

static Replacement clang::tooling::replaceStmtWithStmt ( SourceManager Sources,
const Stmt From,
const Stmt To 
)
static

◆ replaceStmtWithText()

static Replacement clang::tooling::replaceStmtWithText ( SourceManager Sources,
const Stmt From,
StringRef  Text 
)
static

◆ runToolOnCode()

bool clang::tooling::runToolOnCode ( std::unique_ptr< 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 127 of file Tooling.cpp.

References runToolOnCodeWithArgs().

Referenced by clang::tooling::SourceFileCallbacks::handleEndSource().

◆ runToolOnCodeWithArgs() [1/2]

bool clang::tooling::runToolOnCodeWithArgs ( std::unique_ptr< 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 171 of file Tooling.cpp.

Referenced by runToolOnCode().

◆ runToolOnCodeWithArgs() [2/2]

bool clang::tooling::runToolOnCodeWithArgs ( std::unique_ptr< FrontendAction ToolAction,
const Twine &  Code,
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem >  VFS,
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>() 
)

◆ selectFirstFix()

const llvm::StringMap< Replacements > * clang::tooling::selectFirstFix ( const Diagnostic D)

Get the first fix to apply for this diagnostic.

Returns
nullptr if no fixes are attached to the diagnostic.

Definition at line 49 of file Diagnostic.cpp.

References clang::tooling::DiagnosticMessage::Fix, clang::tooling::Diagnostic::Message, and clang::tooling::Diagnostic::Notes.

◆ statement()

RangeSelector clang::tooling::statement ( std::string  ID)

Selects a node, including trailing semicolon (always).

Useful for selecting expression statements. ID is the node's binding in the match result.

Definition at line 140 of file RangeSelector.cpp.

References getExtendedRange(), getNode(), and Node.

Referenced by charRange(), and clang::tooling::stencil::sNode().

◆ statements()

RangeSelector clang::tooling::statements ( std::string  ID)

◆ text()

TextGenerator clang::tooling::text ( std::string  M)
inline

Wraps a string as a TextGenerator.

Definition at line 42 of file Transformer.h.

Referenced by clang::tooling::stencil::cat().

◆ X() [1/2]

static ToolExecutorPluginRegistry::Add<StandaloneToolExecutorPlugin> clang::tooling::X ( "standalone"  ,
"Runs FrontendActions on a set of files provided " "via positional arguments."   
)
static

◆ X() [2/2]

static ToolExecutorPluginRegistry::Add<AllTUsToolExecutorPlugin> clang::tooling::X ( "all-TUs"  ,
"Runs FrontendActions on all TUs in the compilation database. " "Tool results are stored in memory."   
)
static

Variable Documentation

◆ AllTUsToolExecutorAnchorDest

int LLVM_ATTRIBUTE_UNUSED clang::tooling::AllTUsToolExecutorAnchorDest
static
Initial value:

Definition at line 103 of file Execution.cpp.

◆ AllTUsToolExecutorAnchorSource

volatile int clang::tooling::AllTUsToolExecutorAnchorSource = 0

Definition at line 176 of file AllTUsExecution.cpp.

Referenced by createExecutorFromCommandLineArgs().

◆ ExecutorConcurrency

llvm::cl::opt<unsigned> clang::tooling::ExecutorConcurrency

◆ ExecutorName

llvm::cl::opt<std::string> clang::tooling::ExecutorName

◆ Filter

llvm::cl::opt<std::string> clang::tooling::Filter

◆ JSONAnchorDest

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

Definition at line 417 of file CompilationDatabase.cpp.

◆ JSONAnchorSource

volatile int clang::tooling::JSONAnchorSource = 0

◆ StandaloneToolExecutorAnchorDest

int LLVM_ATTRIBUTE_UNUSED clang::tooling::StandaloneToolExecutorAnchorDest
static
Initial value:

Definition at line 101 of file Execution.cpp.

◆ StandaloneToolExecutorAnchorSource

volatile int clang::tooling::StandaloneToolExecutorAnchorSource = 0

Definition at line 89 of file StandaloneExecution.cpp.

Referenced by createExecutorFromCommandLineArgs().