clang 20.0.0git
|
Namespaces | |
namespace | dependencies |
namespace | detail |
namespace | fixit |
namespace | internal |
namespace | stdlib |
namespace | traits |
Classes | |
class | AllTUsToolExecutor |
Executes given frontend actions on all files/TUs in the compilation database. More... | |
class | AllTUsToolExecutorPlugin |
struct | ApplyChangesSpec |
class | ArgumentsAdjustingCompilations |
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... | |
struct | FileByteRange |
Represents a range within a specific source file. 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 | 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 | 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 RewriteRule , as defined by the arguments of the constructor. More... | |
struct | TransformerResult |
struct | TransformerResult< void > |
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. | |
using | ArgumentsAdjuster = std::function< CommandLineArguments(const CommandLineArguments &, StringRef Filename)> |
A prototype of a command line adjuster. | |
using | CompilationDatabasePluginRegistry = llvm::Registry< CompilationDatabasePlugin > |
using | AtomicChanges = std::vector< AtomicChange > |
using | RefactoringActionRules = std::vector< std::unique_ptr< RefactoringActionRule > > |
A set of refactoring action rules that should have unique initiation requirements. | |
using | SymbolOccurrences = std::vector< SymbolOccurrence > |
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. | |
Enumerations | |
enum class | ArgumentInsertPosition { BEGIN , END } |
enum class | replacement_error { fail_to_apply = 0 , wrong_file_path , overlap_conflict , insert_conflict } |
enum class | IncludeDirective { Include , Import } |
enum class | JSONCommandLineSyntax { Windows , Gnu , AutoDetect } |
A JSON based compilation database. More... | |
enum class | SourceSelectionKind { None , ContainsSelection , ContainsSelectionStart , ContainsSelectionEnd , InsideSelection } |
Functions | |
ArgumentsAdjuster | getClangSyntaxOnlyAdjuster () |
Gets an argument adjuster that converts input command line arguments to the "syntax check only" variant. | |
ArgumentsAdjuster | getClangStripOutputAdjuster () |
Gets an argument adjuster which removes output-related command line arguments. | |
ArgumentsAdjuster | getClangStripDependencyFileAdjuster () |
Gets an argument adjuster which removes dependency-file related command line arguments. | |
ArgumentsAdjuster | getInsertArgumentAdjuster (const CommandLineArguments &Extra, ArgumentInsertPosition Pos) |
Gets an argument adjuster which inserts Extra arguments in the specified position. | |
ArgumentsAdjuster | getInsertArgumentAdjuster (const char *Extra, ArgumentInsertPosition Pos=ArgumentInsertPosition::END) |
Gets an argument adjuster which inserts an Extra argument in the specified position. | |
ArgumentsAdjuster | getStripPluginsAdjuster () |
Gets an argument adjuster which strips plugin related command line arguments. | |
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. | |
tooling::CompileCommand | transferCompileCommand (tooling::CompileCommand, StringRef Filename) |
Transforms a compile command so that it applies the same configuration to a different file. | |
std::unique_ptr< CompilationDatabase > | inferMissingCompileCommands (std::unique_ptr< CompilationDatabase >) |
Returns a wrapped CompilationDatabase that defers to the provided one, but getCompileCommands() will infer commands for unknown files. | |
std::unique_ptr< CompilationDatabase > | 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. | |
std::unique_ptr< CompilationDatabase > | expandResponseFiles (std::unique_ptr< CompilationDatabase > Base, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS) |
Returns a wrapped CompilationDatabase that will expand all rsp(response) files on commandline returned by underlying database. | |
const llvm::StringMap< Replacements > * | selectFirstFix (const Diagnostic &D) |
Get the first fix to apply for this diagnostic. | |
bool | operator< (const Replacement &LHS, const Replacement &RHS) |
Less-than operator between two Replacements. | |
bool | operator== (const Replacement &LHS, const Replacement &RHS) |
Equal-to operator between two Replacements. | |
bool | operator!= (const Replacement &LHS, const Replacement &RHS) |
bool | applyAllReplacements (const Replacements &Replaces, Rewriter &Rewrite) |
Apply all replacements in Replaces to the Rewriter Rewrite . | |
llvm::Expected< std::string > | applyAllReplacements (StringRef Code, const Replacements &Replaces) |
Applies all replacements in Replaces to Code . | |
std::vector< Range > | calculateRangesAfterReplacements (const Replacements &Replaces, const std::vector< Range > &Ranges) |
Calculates the new ranges after Replaces are applied. | |
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. | |
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. | |
bool | isSelfContainedHeader (FileEntryRef FE, const SourceManager &SM, const HeaderSearch &HeaderInfo) |
Returns true if the given physical file is a self-contained header. | |
bool | codeContainsImports (llvm::StringRef Code) |
This scans the given source code to see if it contains #import(s). | |
std::optional< llvm::StringRef > | parseIWYUPragma (const char *Text) |
If Text begins an Include-What-You-Use directive, returns it. | |
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 . | |
std::optional< SelectedASTNode > | findSelectedASTNodes (const ASTContext &Context, SourceRange SelectionRange) |
Traverses the given ASTContext and creates a tree of selected AST nodes. | |
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 . | |
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. | |
std::vector< std::unique_ptr< RefactoringAction > > | createRefactoringActions () |
Returns the list of all the available refactoring actions. | |
template<typename RuleType , typename... RequirementTypes> | |
std::unique_ptr< RefactoringActionRule > | createRefactoringActionRule (const RequirementTypes &... Requirements) |
Creates a new refactoring action rule that constructs and invokes the RuleType rule when all of the requirements are satisfied. | |
template<typename OptionType > | |
std::shared_ptr< OptionType > | createRefactoringOption () |
Constructs a refactoring option of the given type. | |
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. | |
const NamedDecl * | getNamedDeclAt (const ASTContext &Context, const SourceLocation Point) |
const NamedDecl * | getNamedDeclFor (const ASTContext &Context, const std::string &Name) |
std::string | getUSRForDecl (const Decl *Decl) |
const NamedDecl * | getCanonicalSymbolDeclaration (const NamedDecl *FoundDecl) |
Returns the canonical declaration that best represents a symbol that can be renamed. | |
std::vector< std::string > | getUSRsForDeclaration (const NamedDecl *ND, ASTContext &Context) |
Returns the set of USRs that correspond to the given declaration. | |
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. | |
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. | |
const llvm::opt::ArgStringList * | getCC1Arguments (DiagnosticsEngine *Diagnostics, driver::Compilation *Compilation) |
Retrieves the flags of the -cc1 job in Compilation that has only source files as its inputs. | |
template<typename T > | |
std::unique_ptr< FrontendActionFactory > | newFrontendActionFactory () |
Returns a new FrontendActionFactory for a given type. | |
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(). | |
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. | |
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. | |
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< ASTUnit > | buildASTFromCode (StringRef Code, StringRef FileName="input.cc", std::shared_ptr< PCHContainerOperations > PCHContainerOps=std::make_shared< PCHContainerOperations >()) |
Builds an AST for 'Code'. | |
std::unique_ptr< ASTUnit > | 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(), const FileContentMappings &VirtualMappedFiles=FileContentMappings(), DiagnosticConsumer *DiagConsumer=nullptr) |
Builds an AST for 'Code' with additional flags. | |
std::string | getAbsolutePath (StringRef File) |
Returns the absolute path of File , by prepending it with the current directory if File is not absolute. | |
llvm::Expected< std::string > | getAbsolutePath (llvm::vfs::FileSystem &FS, StringRef File) |
An overload of getAbsolutePath that works over the provided FS . | |
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. | |
void | addExpandedResponseFiles (std::vector< std::string > &CommandLine, llvm::StringRef WorkingDir, llvm::cl::TokenizerCallback Tokenizer, llvm::vfs::FileSystem &FS) |
Helper function that expands response files in command line. | |
CompilerInvocation * | newInvocation (DiagnosticsEngine *Diagnostics, ArrayRef< const char * > CC1Args, const char *const BinaryName) |
Creates a CompilerInvocation . | |
CharSourceRange | maybeExtendRange (CharSourceRange Range, tok::TokenKind Terminator, ASTContext &Context) |
Extends Range to include the token Terminator , if it immediately follows the end of the range. | |
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 . | |
CharSourceRange | getAssociatedRange (const Decl &D, ASTContext &Context) |
Returns the logical source range of the node extended to include associated comments and whitespace before and after the node, and associated terminators. | |
StringRef | getText (CharSourceRange Range, const ASTContext &Context) |
Returns the source-code text in the specified range. | |
template<typename T > | |
StringRef | getText (const T &Node, const ASTContext &Context) |
Returns the source-code text corresponding to Node . | |
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. | |
llvm::Error | validateEditRange (const CharSourceRange &Range, const SourceManager &SM) |
Determines whether Range is one that can be edited by a rewrite; generally, one that starts and ends within a particular file. | |
llvm::Error | validateRange (const CharSourceRange &Range, const SourceManager &SM, bool AllowSystemHeaders) |
Determines whether Range is one that can be read from. | |
std::optional< CharSourceRange > | getFileRangeForEdit (const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion=true) |
Attempts to resolve the given range to one that can be edited by a rewrite; generally, one that starts and ends within a particular file. | |
std::optional< CharSourceRange > | getFileRangeForEdit (const CharSourceRange &EditRange, const ASTContext &Context, bool IncludeMacroExpansion=true) |
std::optional< CharSourceRange > | getFileRange (const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion) |
Attempts to resolve the given range to one that starts and ends in a particular file. | |
std::optional< CharSourceRange > | getFileRange (const CharSourceRange &EditRange, const ASTContext &Context, bool IncludeMacroExpansion) |
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< AllTUsToolExecutorPlugin > | X ("all-TUs", "Runs FrontendActions on all TUs in the compilation database. " "Tool results are stored in memory.") |
static StringRef | getDriverMode (const CommandLineArguments &Args) |
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. | |
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< StandaloneToolExecutorPlugin > | X ("standalone", "Runs FrontendActions on a set of files provided " "via positional arguments.") |
Code analysis utilities. | |
Ignores implicit object-construction expressions in addition to the normal implicit expressions that are ignored. | |
const Expr * | reallyIgnoreImplicit (const Expr &E) |
bool | mayEverNeedParens (const Expr &E) |
Determines whether printing this expression in any expression requires parentheses to preserve its meaning. | |
bool | needParensBeforeDotOrArrow (const Expr &E) |
Determines whether printing this expression to the left of a dot or arrow operator requires a parentheses to preserve its meaning. | |
bool | needParensAfterUnaryOperator (const Expr &E) |
Determines whether printing this expression to the right of a unary operator requires a parentheses to preserve its meaning. | |
bool | isKnownPointerLikeType (QualType Ty, ASTContext &Context) |
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 |
Basic code-string generation utilities. | |
enum class | PLTClass : bool { Value , Pointer } |
Specifies how to classify pointer-like types – like values or like pointers – with regard to generating member-access syntax. More... | |
std::optional< std::string > | buildParens (const Expr &E, const ASTContext &Context) |
Builds source for an expression, adding parens if needed for unambiguous parsing. | |
std::optional< std::string > | buildDereference (const Expr &E, const ASTContext &Context) |
Builds idiomatic source for the dereferencing of E : prefix with * but simplify when it already begins with & . | |
std::optional< std::string > | buildAddressOf (const Expr &E, const ASTContext &Context) |
Builds idiomatic source for taking the address of E : prefix with & but simplify when it already begins with * . | |
std::optional< std::string > | buildDot (const Expr &E, const ASTContext &Context) |
Adds a dot to the end of the given expression, but adds parentheses when needed by the syntax, and simplifies to -> when possible, e.g.: | |
std::optional< std::string > | buildArrow (const Expr &E, const ASTContext &Context) |
Adds an arrow to the end of the given expression, but adds parentheses when needed by the syntax, and simplifies to . | |
std::optional< std::string > | buildAccess (const Expr &E, ASTContext &Context, PLTClass Classification=PLTClass::Pointer) |
Adds an appropriate access operator (. | |
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 35 of file ArgumentsAdjusters.h.
using clang::tooling::AtomicChanges = typedef std::vector<AtomicChange> |
Definition at line 154 of file AtomicChange.h.
using clang::tooling::CommandLineArguments = typedef std::vector<std::string> |
A sequence of command line arguments.
Definition at line 29 of file ArgumentsAdjusters.h.
using clang::tooling::CompilationDatabasePluginRegistry = typedef llvm::Registry<CompilationDatabasePlugin> |
Definition at line 39 of file CompilationDatabasePluginRegistry.h.
using clang::tooling::FileContentMappings = typedef std::vector<std::pair<std::string, std::string> > |
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 44 of file RefactoringActionRules.h.
using clang::tooling::SymbolOccurrences = typedef std::vector<SymbolOccurrence> |
Definition at line 86 of file SymbolOccurrences.h.
using clang::tooling::ToolExecutorPluginRegistry = typedef llvm::Registry<ToolExecutorPlugin> |
Definition at line 18 of file ToolExecutorPluginRegistry.h.
|
strong |
Enumerator | |
---|---|
BEGIN | |
END |
Definition at line 50 of file ArgumentsAdjusters.h.
|
strong |
Enumerator | |
---|---|
Include | |
Import |
Definition at line 48 of file HeaderIncludes.h.
|
strong |
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.
|
strong |
Specifies how to classify pointer-like types – like values or like pointers – with regard to generating member-access syntax.
Enumerator | |
---|---|
Value | |
Pointer |
Definition at line 97 of file SourceCodeBuilders.h.
|
strong |
Enumerator | |
---|---|
fail_to_apply | |
wrong_file_path | |
overlap_conflict | |
insert_conflict |
Definition at line 145 of file Replacement.h.
|
strong |
Definition at line 26 of file ASTSelection.h.
void clang::tooling::addExpandedResponseFiles | ( | std::vector< std::string > & | CommandLine, |
llvm::StringRef | WorkingDir, | ||
llvm::cl::TokenizerCallback | Tokenizer, | ||
llvm::vfs::FileSystem & | FS | ||
) |
Helper function that expands response files in command line.
Definition at line 308 of file Tooling.cpp.
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).
llvm::InitializeAllTargets()
has been called.CommandLine | the command line used to invoke the compiler driver or Clang tool, including the path to the executable as CommandLine [0]. |
InvokedAs | the path to the driver used to infer implicit flags. |
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 271 of file Tooling.cpp.
References clang::driver::getDriverOptTable(), and clang::driver::ToolChain::getTargetAndModeFromProgramName().
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.
Definition at line 568 of file Replacement.cpp.
References E, clang::tooling::Replacements::rbegin(), clang::tooling::Replacements::rend(), and clang::Rewrite.
Referenced by clang::tooling::RefactoringTool::applyAllReplacements(), applyAtomicChanges(), and formatAndApplyAllReplacements().
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_codein the
Error` should be ignored).
Definition at line 580 of file Replacement.cpp.
References clang::tooling::Replacement::apply(), clang::SrcMgr::C_User, clang::SourceManager::createFileID(), E, clang::tooling::Replacements::empty(), clang::FileManager::getOptionalFileRef(), ID, clang::tooling::Replacements::rbegin(), clang::tooling::Replacements::rend(), and clang::Rewrite.
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.
llvm::toString()
and the error_code should be ignored). Definition at line 301 of file AtomicChange.cpp.
References clang::tooling::Replacements::add(), applyAllReplacements(), clang::tooling::ApplyChangesSpec::Cleanup, clang::format::cleanupAroundReplacements(), clang::format::FormatStyle::ColumnLimit, clang::tooling::ApplyChangesSpec::Format, clang::tooling::Replacements::getAffectedRanges(), make_string_error(), clang::tooling::Replacements::merge(), clang::format::reformat(), clang::format::sortIncludes(), and clang::tooling::ApplyChangesSpec::Style.
std::optional< std::string > clang::tooling::buildAccess | ( | const Expr & | E, |
ASTContext & | Context, | ||
PLTClass | Classification = PLTClass::Pointer |
||
) |
Adds an appropriate access operator (.
, ->
or nothing, in the case of implicit this
) to the end of the given expression. Adds parentheses when needed by the syntax and simplifies when possible. If PLTypeClass
is Pointer
, for known pointer-like types (see isKnownPointerLikeType
), treats operator->
and operator*
like the built-in ->
and *
operators.
x
becomes x->
or x.
, depending on E
's type a+b
becomes (a+b)->
or (a+b).
, depending on E
's type &a
becomes a.
*a
becomes a->
Definition at line 213 of file SourceCodeBuilders.cpp.
References buildAccessForPointer(), buildAccessForValue(), E, clang::Expr::getType(), clang::Expr::IgnoreImplicitAsWritten(), clang::Type::isAnyPointerType(), clang::Expr::isImplicitCXXThis(), maybeGetOperatorObjectArg(), and treatLikePointer().
std::optional< std::string > clang::tooling::buildAddressOf | ( | const Expr & | E, |
const ASTContext & | Context | ||
) |
Builds idiomatic source for taking the address of E
: prefix with &
but simplify when it already begins with *
.
Definition at line 106 of file SourceCodeBuilders.cpp.
References E, getText(), clang::Expr::isImplicitCXXThis(), needParensAfterUnaryOperator(), and Text.
std::optional< std::string > clang::tooling::buildArrow | ( | const Expr & | E, |
const ASTContext & | Context | ||
) |
Adds an arrow to the end of the given expression, but adds parentheses when needed by the syntax, and simplifies to .
when possible, e.g.:
x
becomes x->
&a
becomes a.
a+b
becomes (a+b)->
DEPRECATED. Use buildAccess
.
Definition at line 185 of file SourceCodeBuilders.cpp.
References buildAccessForPointer(), and E.
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'.
Code | C++ code. |
FileName | The file name which 'Code' will be mapped as. |
PCHContainerOps | The PCHContainerOperations for loading and creating clang modules. |
Definition at line 682 of file Tooling.cpp.
References buildASTFromCodeWithArgs(), and clang::FileName.
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() , |
||
const FileContentMappings & | VirtualMappedFiles = FileContentMappings() , |
||
DiagnosticConsumer * | DiagConsumer = nullptr |
||
) |
Builds an AST for 'Code' with additional flags.
Code | C++ code. |
Args | Additional flags to pass on. |
FileName | The file name which 'Code' will be mapped as. |
ToolName | The name of the binary running the tool. Standard library header paths will be resolved relative to this. |
PCHContainerOps | The PCHContainerOperations for loading and creating clang modules. |
Adjuster | A function to filter the command line arguments as specified. |
Definition at line 688 of file Tooling.cpp.
References clang::FileName, getSyntaxOnlyToolArgs(), clang::tooling::ToolInvocation::run(), and clang::tooling::ToolInvocation::setDiagnosticConsumer().
Referenced by buildASTFromCode().
std::optional< std::string > clang::tooling::buildDereference | ( | const Expr & | E, |
const ASTContext & | Context | ||
) |
Builds idiomatic source for the dereferencing of E
: prefix with *
but simplify when it already begins with &
.
Definition at line 86 of file SourceCodeBuilders.cpp.
References E, getText(), needParensAfterUnaryOperator(), and Text.
std::optional< std::string > clang::tooling::buildDot | ( | const Expr & | E, |
const ASTContext & | Context | ||
) |
Adds a dot to the end of the given expression, but adds parentheses when needed by the syntax, and simplifies to ->
when possible, e.g.:
x
becomes x.
*a
becomes a->
a+b
becomes (a+b).
DEPRECATED. Use buildAccess
.
Definition at line 180 of file SourceCodeBuilders.cpp.
References buildAccessForValue(), and E.
std::optional< std::string > clang::tooling::buildParens | ( | const Expr & | E, |
const ASTContext & | Context | ||
) |
Builds source for an expression, adding parens if needed for unambiguous parsing.
Definition at line 75 of file SourceCodeBuilders.cpp.
References E, getText(), mayEverNeedParens(), and Text.
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.
Replaces
are applied. The new ranges will be sorted and non-overlapping. Definition at line 511 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().
bool clang::tooling::codeContainsImports | ( | llvm::StringRef | Code | ) |
This scans the given source code to see if it contains #import(s).
Definition at line 83 of file HeaderAnalysis.cpp.
References clang::Line.
Referenced by isSelfContainedHeader().
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 142 of file ArgumentsAdjusters.cpp.
References clang::File, and clang::First.
Referenced by clang::tooling::ClangTool::appendArgumentsAdjuster(), and getDefaultArgumentsAdjusters().
|
static |
Takes each atomic change and inserts its replacements into the set of replacements that belong to the appropriate file.
Definition at line 145 of file RenamingAction.cpp.
References clang::CharSourceRange::getCharRange(), clang::tooling::SymbolName::getNamePieces(), clang::tooling::AtomicChange::replace(), and SM.
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 88 of file Execution.cpp.
References Category, and clang::tooling::internal::createExecutorFromCommandLineArgsImpl().
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:
Definition at line 118 of file RefactoringActionRulesInternal.h.
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.
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.
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.
USRs | The set containing USRs of a particular old symbol. |
NewName | The new name to replace old symbol name. |
TranslationUnitDecl | The translation unit declaration. |
Definition at line 529 of file USRLocFinder.cpp.
References clang::TranslationUnitDecl::getASTContext(), clang::ASTContext::getLangOpts(), clang::ASTContext::getSourceManager(), clang::Lexer::getSourceText(), clang::CharSourceRange::getTokenRange(), clang::tooling::AtomicChange::replace(), replaceNestedName(), SM, and Text.
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 122 of file RenamingAction.cpp.
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) | |||
) |
llvm::cl::opt< std::string > clang::tooling::ExecutorName | ( | "executor" | , |
llvm::cl::desc("The name of the executor to use.") | , | ||
llvm::cl::init("standalone") | |||
) |
std::unique_ptr< CompilationDatabase > clang::tooling::expandResponseFiles | ( | std::unique_ptr< CompilationDatabase > | Base, |
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > | FS | ||
) |
Returns a wrapped CompilationDatabase that will expand all rsp(response) files on commandline returned by underlying database.
Definition at line 67 of file ExpandResponseFilesCompilationDatabase.cpp.
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(".*") | |||
) |
std::optional< SelectedASTNode > clang::tooling::findSelectedASTNodes | ( | const ASTContext & | Context, |
SourceRange | SelectionRange | ||
) |
Traverses the given ASTContext and creates a tree of selected AST nodes.
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().
Referenced by clang::tooling::ASTSelectionRequirement::evaluate().
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.
FileToReplaces will be deduplicated with groupReplacementsByFile
before application.
Replacement applications happen independently of the success of other applications.
[in] | FileToReplaces | Replacements (grouped by files) to apply. |
[in] | Rewrite | The Rewritter to apply replacements on. |
[in] | Style | The style name used for reformatting. See getStyle in "include/clang/Format/Format.h" for all possible style forms. |
Definition at line 69 of file Refactoring.cpp.
References applyAllReplacements(), clang::SrcMgr::C_User, clang::format::formatReplacements(), clang::FileManager::getFileRef(), clang::format::getStyle(), groupReplacementsByFile(), ID, clang::Result, clang::Rewrite, and SM.
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 254 of file Tooling.cpp.
References clang::File.
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.
File | Either an absolute or relative path. |
Definition at line 267 of file Tooling.cpp.
References clang::File, and getAbsolutePath().
Referenced by clang::tooling::CompilationDatabase::autoDetectFromDirectory(), clang::tooling::CompilationDatabase::autoDetectFromSource(), getAbsolutePath(), and clang::tooling::ClangTool::run().
CharSourceRange clang::tooling::getAssociatedRange | ( | const Decl & | D, |
ASTContext & | Context | ||
) |
Returns the logical source range of the node extended to include associated comments and whitespace before and after the node, and associated terminators.
The returned range consists of file locations, if valid file locations can be found for the associated content; otherwise, an invalid range is returned.
Note that parsing comments is disabled by default. In order to select a range containing associated comments, you may need to invoke the tool with -fparse-all-comments
.
Definition at line 412 of file SourceCode.cpp.
References atOrBeforeSeparation(), clang::Decl::attrs(), clang::Decl::getASTContext(), clang::Decl::getEndLoc(), getEntityEndLoc(), clang::ASTContext::getLangOpts(), clang::Attr::getLocation(), clang::ASTContext::getRawCommentForDeclNoCache(), clang::ASTContext::getSourceManager(), clang::Decl::getSourceRange(), getTerminators(), clang::CharSourceRange::getTokenRange(), clang::Invalid, clang::SourceLocation::isInvalid(), clang::Lexer::makeFileCharRange(), skipWhitespaceAndNewline(), SM, and clang::T.
Returns the canonical declaration that best represents a symbol that can be renamed.
The following canonicalization rules are currently used:
Definition at line 41 of file USRFindingAction.cpp.
Referenced by clang::tooling::RenameOccurrences::initiate().
const llvm::opt::ArgStringList * clang::tooling::getCC1Arguments | ( | DiagnosticsEngine * | Diagnostics, |
driver::Compilation * | Compilation | ||
) |
Retrieves the flags of the -cc1
job in Compilation
that has only source files as its inputs.
Returns nullptr if there are no such jobs or multiple of them. Note that offloading jobs are ignored.
Definition at line 133 of file Tooling.cpp.
References Cmd, clang::driver::Compilation::getJobs(), ignoreExtraCC1Commands(), clang::driver::JobList::Print(), and clang::DiagnosticsEngine::Report().
Referenced by clang::tooling::ToolInvocation::run().
ArgumentsAdjuster clang::tooling::getClangStripDependencyFileAdjuster | ( | ) |
Gets an argument adjuster which removes dependency-file related command line arguments.
Definition at line 90 of file ArgumentsAdjusters.cpp.
References getDriverMode().
Referenced by clang::tooling::ClangTool::ClangTool(), getDefaultArgumentsAdjusters(), and runToolOnCodeWithArgs().
ArgumentsAdjuster clang::tooling::getClangStripOutputAdjuster | ( | ) |
Gets an argument adjuster which removes output-related command line arguments.
Definition at line 72 of file ArgumentsAdjusters.cpp.
Referenced by clang::tooling::ClangTool::ClangTool(), and getDefaultArgumentsAdjusters().
ArgumentsAdjuster clang::tooling::getClangSyntaxOnlyAdjuster | ( | ) |
Gets an argument adjuster that converts input command line arguments to the "syntax check only" variant.
Add -fsyntax-only option and drop options that triggers output generation.
Definition at line 35 of file ArgumentsAdjusters.cpp.
References getInsertArgumentAdjuster().
Referenced by clang::tooling::ClangTool::ClangTool(), and getDefaultArgumentsAdjusters().
|
static |
Definition at line 22 of file StandaloneExecution.cpp.
References combineAdjusters(), getClangStripDependencyFileAdjuster(), getClangStripOutputAdjuster(), and getClangSyntaxOnlyAdjuster().
Referenced by clang::tooling::AllTUsToolExecutor::execute().
|
static |
Definition at line 24 of file ArgumentsAdjusters.cpp.
Referenced by getClangStripDependencyFileAdjuster().
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 34 of file SourceCode.h.
References clang::CharSourceRange::getTokenRange(), maybeExtendRange(), and Node.
Referenced by getExtendedText(), clang::transformer::node(), and clang::transformer::statement().
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:
then
Definition at line 84 of file SourceCode.h.
References getExtendedRange(), getText(), and Node.
|
inline |
Definition at line 137 of file SourceCode.h.
References getFileRange().
std::optional< CharSourceRange > clang::tooling::getFileRange | ( | const CharSourceRange & | EditRange, |
const SourceManager & | SM, | ||
const LangOptions & | LangOpts, | ||
bool | IncludeMacroExpansion | ||
) |
Attempts to resolve the given range to one that starts and ends in a particular file.
If IncludeMacroExpansion
is true, a limited set of cases involving source locations in macro expansions is supported. For example, if we're looking to get the range of the int literal 3, and we have the following definition: #define DO_NOTHING(x) x foo(DO_NOTHING(3)) the returned range will hold the source text DO_NOTHING(3)
.
Definition at line 185 of file SourceCode.cpp.
References getRange(), Range, SM, and validateRange().
Referenced by getFileRange().
|
inline |
Definition at line 117 of file SourceCode.h.
References getFileRangeForEdit().
std::optional< CharSourceRange > clang::tooling::getFileRangeForEdit | ( | const CharSourceRange & | EditRange, |
const SourceManager & | SM, | ||
const LangOptions & | LangOpts, | ||
bool | IncludeMacroExpansion = true |
||
) |
Attempts to resolve the given range to one that can be edited by a rewrite; generally, one that starts and ends within a particular file.
If a value is returned, it satisfies validateEditRange
.
If IncludeMacroExpansion
is true, a limited set of cases involving source locations in macro expansions is supported. For example, if we're looking to rewrite the int literal 3 to 6, and we have the following definition: #define DO_NOTHING(x) x then foo(DO_NOTHING(3)) will be rewritten to foo(6)
Definition at line 174 of file SourceCode.cpp.
References getRange(), Range, SM, and validateEditRange().
Referenced by getFileRangeForEdit(), clang::transformer::detail::getRuleMatchLoc(), and translateEdits().
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 137 of file ArgumentsAdjusters.cpp.
References getInsertArgumentAdjuster().
ArgumentsAdjuster clang::tooling::getInsertArgumentAdjuster | ( | const CommandLineArguments & | Extra, |
ArgumentInsertPosition | Pos | ||
) |
Gets an argument adjuster which inserts Extra
arguments in the specified position.
Definition at line 119 of file ArgumentsAdjusters.cpp.
References END.
Referenced by getClangSyntaxOnlyAdjuster(), getInsertArgumentAdjuster(), and injectResourceDir().
const NamedDecl * clang::tooling::getNamedDeclAt | ( | const ASTContext & | Context, |
const SourceLocation | Point | ||
) |
Definition at line 77 of file USRFinder.cpp.
References clang::SourceLocation::isValid(), and SM.
Referenced by clang::tooling::RenameOccurrences::initiate().
const NamedDecl * clang::tooling::getNamedDeclFor | ( | const ASTContext & | Context, |
const std::string & | Name | ||
) |
Definition at line 128 of file USRFinder.cpp.
Referenced by clang::tooling::QualifiedRenameRule::initiate().
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.
Definition at line 521 of file USRLocFinder.cpp.
References clang::Decl::getASTContext().
ArgumentsAdjuster clang::tooling::getStripPluginsAdjuster | ( | ) |
Gets an argument adjuster which strips plugin related command line arguments.
Definition at line 153 of file ArgumentsAdjusters.cpp.
References E.
StringRef clang::tooling::getText | ( | CharSourceRange | Range, |
const ASTContext & | Context | ||
) |
Returns the source-code text in the specified range.
Definition at line 31 of file SourceCode.cpp.
References clang::ASTContext::getLangOpts(), clang::ASTContext::getSourceManager(), and clang::Lexer::getSourceText().
Referenced by buildAccessForPointer(), buildAccessForValue(), buildAddressOf(), buildDereference(), buildParens(), getExtendedText(), getText(), and clang::transformer::name().
StringRef clang::tooling::getText | ( | const T & | Node, |
const ASTContext & | Context | ||
) |
Returns the source-code text corresponding to Node
.
Definition at line 56 of file SourceCode.h.
References getText(), clang::CharSourceRange::getTokenRange(), and Node.
std::string clang::tooling::getUSRForDecl | ( | const Decl * | Decl | ) |
Definition at line 135 of file USRFinder.cpp.
References clang::index::generateUSRForDecl().
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 217 of file USRFindingAction.cpp.
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 612 of file Replacement.cpp.
References clang::FileManager::getFile().
Referenced by clang::tooling::RefactoringTool::applyAllReplacements(), and formatAndApplyAllReplacements().
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 538 of file InterpolatingCompilationDatabase.cpp.
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.
bool clang::tooling::isKnownPointerLikeType | ( | QualType | Ty, |
ASTContext & | Context | ||
) |
Definition at line 65 of file SourceCodeBuilders.cpp.
References clang::ast_matchers::cxxRecordDecl, clang::ast_matchers::hasAnyName, clang::ast_matchers::hasDeclaration(), clang::ast_matchers::match(), clang::ast_matchers::recordType, and clang::ast_matchers::type.
Referenced by treatLikePointer().
bool clang::tooling::isSelfContainedHeader | ( | FileEntryRef | FE, |
const SourceManager & | SM, | ||
const HeaderSearch & | HeaderInfo | ||
) |
Returns true if the given physical file is a self-contained header.
A header is considered self-contained if This function can be expensive as it may scan the source code to find out dont-include-me pattern heuristically.
Definition at line 69 of file HeaderAnalysis.cpp.
References codeContainsImports(), clang::HeaderSearch::hasFileBeenImported(), clang::HeaderSearch::isFileMultipleIncludeGuarded(), and SM.
|
static |
Definition at line 15 of file StandaloneExecution.cpp.
Referenced by applyAtomicChanges(), clang::tooling::AllTUsToolExecutorPlugin::create(), clang::tooling::StandaloneToolExecutorPlugin::create(), clang::tooling::AllTUsToolExecutor::execute(), and clang::tooling::StandaloneToolExecutor::execute().
CharSourceRange clang::tooling::maybeExtendRange | ( | CharSourceRange | Range, |
tok::TokenKind | Terminator, | ||
ASTContext & | Context | ||
) |
Extends Range
to include the token Terminator
, if it immediately follows the end of the range.
Otherwise, returns Range
unchanged.
Definition at line 37 of file SourceCode.cpp.
References clang::Lexer::getAsCharRange(), clang::CharSourceRange::getEnd(), clang::ASTContext::getLangOpts(), clang::Token::getLocation(), clang::Lexer::getRawToken(), clang::ASTContext::getSourceManager(), clang::CharSourceRange::getTokenRange(), clang::Token::is(), clang::CharSourceRange::isInvalid(), and Range.
Referenced by getExtendedRange().
Determines whether printing this expression in any expression requires parentheses to preserve its meaning.
This analyses is necessarily conservative because it lacks information about the target context.
Definition at line 32 of file SourceCodeBuilders.cpp.
References E, and reallyIgnoreImplicit().
Referenced by buildParens(), and needParensBeforeDotOrArrow().
Determines whether printing this expression to the right of a unary operator requires a parentheses to preserve its meaning.
Definition at line 52 of file SourceCodeBuilders.cpp.
References E, and reallyIgnoreImplicit().
Referenced by buildAddressOf(), and buildDereference().
Determines whether printing this expression to the left of a dot or arrow operator requires a parentheses to preserve its meaning.
Given that dot/arrow are (effectively) the highest precedence, this is equivalent to asking whether it ever needs parens.
Definition at line 39 of file SourceCodeBuilders.h.
References E, and mayEverNeedParens().
Referenced by buildAccessForPointer(), and buildAccessForValue().
std::unique_ptr< FrontendActionFactory > clang::tooling::newFrontendActionFactory | ( | ) |
Returns a new FrontendActionFactory for a given type.
T must derive from clang::FrontendAction.
Example: std::unique_ptr<FrontendActionFactory> Factory = newFrontendActionFactory<clang::SyntaxOnlyAction>();
|
inline |
Returns a new FrontendActionFactory for any type that provides an implementation of newASTConsumer().
FactoryT must implement: ASTConsumer *newASTConsumer().
Example: struct ProvidesASTConsumers { std::unique_ptr<clang::ASTConsumer> newASTConsumer(); } Factory; std::unique_ptr<FrontendActionFactory> FactoryAdapter( newFrontendActionFactory(&Factory));
Definition at line 413 of file Tooling.h.
References clang::tooling::SourceFileCallbacks::handleBeginSource(), and clang::tooling::SourceFileCallbacks::handleEndSource().
CompilerInvocation * clang::tooling::newInvocation | ( | DiagnosticsEngine * | Diagnostics, |
ArrayRef< const char * > | CC1Args, | ||
const char *const | BinaryName | ||
) |
Creates a CompilerInvocation
.
Returns a clang build invocation initialized from the CC1 flags.
Definition at line 171 of file Tooling.cpp.
References clang::CompilerInvocation::CreateFromArgs(), clang::FrontendOptions::DisableFree, clang::CompilerInvocation::getCodeGenOpts(), and clang::CompilerInvocation::getFrontendOpts().
Referenced by clang::tooling::ToolInvocation::run().
|
inline |
Definition at line 205 of file Replacement.h.
bool clang::tooling::operator< | ( | const Replacement & | LHS, |
const Replacement & | RHS | ||
) |
Less-than operator between two Replacements.
Definition at line 98 of file Replacement.cpp.
References clang::tooling::Replacement::getFilePath(), clang::tooling::Replacement::getLength(), clang::tooling::Replacement::getOffset(), and clang::tooling::Replacement::getReplacementText().
bool clang::tooling::operator== | ( | const Replacement & | LHS, |
const Replacement & | RHS | ||
) |
Equal-to operator between two Replacements.
Definition at line 110 of file Replacement.cpp.
References clang::tooling::Replacement::getFilePath(), clang::tooling::Replacement::getLength(), clang::tooling::Replacement::getOffset(), and clang::tooling::Replacement::getReplacementText().
std::optional< StringRef > clang::tooling::parseIWYUPragma | ( | const char * | Text | ) |
If Text begins an Include-What-You-Use directive, returns it.
Given "// IWYU pragma: keep", returns "keep". Input is a null-terminated char* as provided by SM.getCharacterData(). (This should not be StringRef as we do not want to scan for its length). For multi-line comments, we return only the first line.
Definition at line 95 of file HeaderAnalysis.cpp.
References Text.
Definition at line 22 of file SourceCodeBuilders.cpp.
References E, clang::Stmt::getSourceRange(), and clang::Expr::IgnoreImplicit().
Referenced by mayEverNeedParens(), and needParensAfterUnaryOperator().
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.
Use | The nested name to be replaced. |
UseLoc | The location of name to be replaced. |
UseContext | The context in which the nested name is contained. This will be used to minimize namespace qualifications. |
FromDecl | The declaration to which the nested name points. |
ReplacementString | The replacement nested name. Must be fully qualified including a leading "::". |
Definition at line 185 of file Lookup.cpp.
References disambiguateSpellingInScope(), FromDecl, getBestNamespaceSubstr(), clang::Decl::getDeclContext(), isFullyQualified(), and usingFromDifferentCanonicalNamespace().
Referenced by createRenameAtomicChanges().
|
static |
Definition at line 77 of file RefactoringCallbacks.cpp.
References clang::Stmt::getSourceRange(), clang::Lexer::getSourceText(), clang::CharSourceRange::getTokenRange(), and replaceStmtWithText().
Referenced by clang::tooling::ReplaceStmtWithStmt::run(), and clang::tooling::ReplaceIfStmtWithItsBody::run().
|
static |
Definition at line 72 of file RefactoringCallbacks.cpp.
References clang::Stmt::getSourceRange(), clang::CharSourceRange::getTokenRange(), and Text.
Referenced by replaceStmtWithStmt(), and clang::tooling::ReplaceIfStmtWithItsBody::run().
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.
ToolAction | The action to run over the code. |
Code | C++ code. |
FileName | The file name which 'Code' will be mapped as. |
PCHContainerOps | The PCHContainerOperations for loading and creating clang modules. |
Definition at line 183 of file Tooling.cpp.
References clang::FileName, and runToolOnCodeWithArgs().
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.
ToolAction | The action to run over the code. |
Code | C++ code. |
Args | Additional flags to pass on. |
FileName | The file name which 'Code' will be mapped as. |
ToolName | The name of the binary running the tool. Standard library header paths will be resolved relative to this. |
PCHContainerOps | The PCHContainerOperations for loading and creating clang modules. |
Definition at line 227 of file Tooling.cpp.
References clang::FileName, and runToolOnCodeWithArgs().
Referenced by runToolOnCode(), and runToolOnCodeWithArgs().
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>() |
||
) |
Definition at line 209 of file Tooling.cpp.
References clang::FileName, getClangStripDependencyFileAdjuster(), getSyntaxOnlyToolArgs(), and clang::tooling::ToolInvocation::run().
const llvm::StringMap< Replacements > * clang::tooling::selectFirstFix | ( | const Diagnostic & | D | ) |
Get the first fix to apply for this diagnostic.
Definition at line 60 of file Diagnostic.cpp.
tooling::CompileCommand clang::tooling::transferCompileCommand | ( | tooling::CompileCommand | Cmd, |
StringRef | Filename | ||
) |
Transforms a compile command so that it applies the same configuration to a different file.
Most args are left intact, but tweaks may be needed to certain flags (-x, -std etc).
The output command will always end in {"--", Filename}.
Definition at line 542 of file InterpolatingCompilationDatabase.cpp.
llvm::Error clang::tooling::validateEditRange | ( | const CharSourceRange & | Range, |
const SourceManager & | SM | ||
) |
Determines whether Range
is one that can be edited by a rewrite; generally, one that starts and ends within a particular file.
Definition at line 84 of file SourceCode.cpp.
References SM, and validateRange().
Referenced by getFileRangeForEdit().
llvm::Error clang::tooling::validateRange | ( | const CharSourceRange & | Range, |
const SourceManager & | SM, | ||
bool | AllowSystemHeaders | ||
) |
Determines whether Range
is one that can be read from.
If AllowSystemHeaders
is false, a range that falls within a system header fails validation.
Definition at line 53 of file SourceCode.cpp.
References SM.
Referenced by getFileRange(), and validateEditRange().
|
static |
|
static |
|
static |
Definition at line 101 of file Execution.cpp.
volatile int clang::tooling::AllTUsToolExecutorAnchorSource = 0 |
Definition at line 177 of file AllTUsExecution.cpp.
|
extern |
Referenced by clang::tooling::AllTUsToolExecutorPlugin::create().
|
extern |
|
extern |
Referenced by clang::tooling::AllTUsToolExecutor::execute().
|
static |
Definition at line 413 of file CompilationDatabase.cpp.
volatile int clang::tooling::JSONAnchorSource = 0 |
Definition at line 187 of file JSONCompilationDatabase.cpp.
|
static |
Definition at line 99 of file Execution.cpp.
volatile int clang::tooling::StandaloneToolExecutorAnchorSource = 0 |
Definition at line 89 of file StandaloneExecution.cpp.