clang 20.0.0git
|
The following three functions are a low-level part of the RewriteRule API. More...
Functions | |
EditGenerator | injectEdits (ASTEdit E) |
Helper function to construct an EditGenerator . | |
EditGenerator | injectEdits (EditGenerator G) |
RewriteRule | makeRule (ast_matchers::internal::DynTypedMatcher M, EditGenerator Edits) |
template<typename MetadataT > | |
RewriteRuleWith< MetadataT > | makeRule (ast_matchers::internal::DynTypedMatcher M, EditGenerator Edits, Generator< MetadataT > Metadata) |
EditGenerator | makeEditGenerator (EditGenerator Edits) |
EditGenerator | makeEditGenerator (llvm::SmallVector< ASTEdit, 1 > Edits) |
EditGenerator | makeEditGenerator (ASTEdit Edit) |
ast_matchers::internal::DynTypedMatcher | buildMatcher (const RewriteRuleBase &Rule) |
Builds a single matcher for the rule, covering all of the rule's cases. | |
std::vector< ast_matchers::internal::DynTypedMatcher > | buildMatchers (const RewriteRuleBase &Rule) |
Builds a set of matchers that cover the rule. | |
SourceLocation | getRuleMatchLoc (const ast_matchers::MatchFinder::MatchResult &Result) |
Gets the beginning location of the source matched by a rewrite rule. | |
size_t | findSelectedCase (const ast_matchers::MatchFinder::MatchResult &Result, const RewriteRuleBase &Rule) |
Returns the index of the Case of Rule that was selected in the match result. | |
Stencil | makeStencil (llvm::StringRef Text) |
Convenience function to construct a Stencil . | |
Stencil | makeStencil (RangeSelector Selector) |
Stencil | makeStencil (Stencil S) |
llvm::Expected< SmallVector< Edit, 1 > > | rewriteDescendants (const Decl &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result) |
The following overload set is a version of rewriteDescendants that operates directly on the AST, rather than generating a Transformer combinator. | |
llvm::Expected< SmallVector< Edit, 1 > > | rewriteDescendants (const Stmt &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result) |
llvm::Expected< SmallVector< Edit, 1 > > | rewriteDescendants (const TypeLoc &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result) |
llvm::Expected< SmallVector< Edit, 1 > > | rewriteDescendants (const DynTypedNode &Node, RewriteRule Rule, const ast_matchers::MatchFinder::MatchResult &Result) |
The following three functions are a low-level part of the RewriteRule API.
We expose them for use in implementing the fixtures that interpret RewriteRule, like Transformer and TransfomerTidy, or for more advanced users.
DynTypedMatcher clang::transformer::detail::buildMatcher | ( | const RewriteRuleBase & | Rule | ) |
Builds a single matcher for the rule, covering all of the rule's cases.
Only supports Rules whose cases' matchers share the same base "kind" (Stmt
, Decl
, etc.) Deprecated: use buildMatchers
instead, which supports mixing matchers of different kinds.
Definition at line 442 of file RewriteRule.cpp.
References buildMatchers().
std::vector< DynTypedMatcher > clang::transformer::detail::buildMatchers | ( | const RewriteRuleBase & | Rule | ) |
Builds a set of matchers that cover the rule.
One matcher is built for each distinct node matcher base kind: Stmt, Decl, etc. Node-matchers for QualType
and Type
are not permitted, since such nodes carry no source location information and are therefore not relevant for rewriting. If any such matchers are included, will return an empty vector.
Definition at line 410 of file RewriteRule.cpp.
References hasValidKind(), clang::transformer::RootID, taggedMatchers(), and clang::TK_AsIs.
Referenced by buildMatcher().
size_t clang::transformer::detail::findSelectedCase | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
const RewriteRuleBase & | Rule | ||
) |
Returns the index of the Case
of Rule
that was selected in the match result.
Assumes a matcher built with buildMatcher
.
Definition at line 465 of file RewriteRule.cpp.
SourceLocation clang::transformer::detail::getRuleMatchLoc | ( | const ast_matchers::MatchFinder::MatchResult & | Result | ) |
Gets the beginning location of the source matched by a rewrite rule.
If the match occurs within a macro expansion, returns the beginning of the expansion point. Result
must come from the matching of a rewrite rule.
Definition at line 448 of file RewriteRule.cpp.
References clang::tooling::getFileRangeForEdit(), clang::CharSourceRange::getTokenRange(), and clang::transformer::RootID.
|
inline |
Helper function to construct an EditGenerator
.
Overloaded for common cases so that user doesn't need to specify which factory function to use. This pattern gives benefits similar to implicit constructors, while maintaing a higher degree of explicitness.
Definition at line 168 of file RewriteRule.h.
References E, and clang::transformer::edit().
Referenced by clang::transformer::flatten().
|
inline |
Definition at line 169 of file RewriteRule.h.
EditGenerator clang::transformer::detail::makeEditGenerator | ( | ASTEdit | Edit | ) |
Definition at line 190 of file RewriteRule.cpp.
References clang::transformer::edit().
|
inline |
Definition at line 318 of file RewriteRule.h.
Referenced by clang::transformer::makeRule().
EditGenerator clang::transformer::detail::makeEditGenerator | ( | llvm::SmallVector< ASTEdit, 1 > | Edits | ) |
Definition at line 186 of file RewriteRule.cpp.
References clang::transformer::editList().
RewriteRule clang::transformer::detail::makeRule | ( | ast_matchers::internal::DynTypedMatcher | M, |
EditGenerator | Edits | ||
) |
Referenced by clang::transformer::makeRule().
RewriteRuleWith< MetadataT > clang::transformer::detail::makeRule | ( | ast_matchers::internal::DynTypedMatcher | M, |
EditGenerator | Edits, | ||
Generator< MetadataT > | Metadata | ||
) |
Definition at line 309 of file RewriteRule.h.
References clang::transformer::RewriteRuleBase::Cases, and clang::transformer::RewriteRuleWith< MetadataT >::Metadata.
Stencil clang::transformer::detail::makeStencil | ( | llvm::StringRef | Text | ) |
Convenience function to construct a Stencil
.
Overloaded for common cases so that user doesn't need to specify which factory function to use. This pattern gives benefits similar to implicit constructors, while maintaing a higher degree of explicitness.
Referenced by clang::transformer::access(), clang::transformer::cat(), and clang::transformer::ifBound().
Stencil clang::transformer::detail::makeStencil | ( | RangeSelector | Selector | ) |
Definition at line 430 of file Stencil.cpp.
llvm::Expected< SmallVector< clang::transformer::Edit, 1 > > clang::transformer::detail::rewriteDescendants | ( | const Decl & | Node, |
RewriteRule | Rule, | ||
const ast_matchers::MatchFinder::MatchResult & | Result | ||
) |
The following overload set is a version of rewriteDescendants
that operates directly on the AST, rather than generating a Transformer combinator.
It applies Rule
to all descendants of Node
, although not Node
itself. Rule
can refer to nodes bound in Result
.
For example, assuming that "body" is bound to a function body in MatchResult Results
, this will produce edits to change all appearances of x
in that body to 3
.
Definition at line 310 of file RewriteRule.cpp.
References Node, and rewriteDescendantsImpl().
Referenced by clang::transformer::rewriteDescendants().
llvm::Expected< SmallVector< clang::transformer::Edit, 1 > > clang::transformer::detail::rewriteDescendants | ( | const DynTypedNode & | Node, |
RewriteRule | Rule, | ||
const ast_matchers::MatchFinder::MatchResult & | Result | ||
) |
Definition at line 328 of file RewriteRule.cpp.
References clang::ASTNodeKind::asStringRef(), clang::DynTypedNode::get(), clang::DynTypedNode::getNodeKind(), Node, and rewriteDescendantsImpl().
llvm::Expected< SmallVector< clang::transformer::Edit, 1 > > clang::transformer::detail::rewriteDescendants | ( | const Stmt & | Node, |
RewriteRule | Rule, | ||
const ast_matchers::MatchFinder::MatchResult & | Result | ||
) |
Definition at line 316 of file RewriteRule.cpp.
References Node, and rewriteDescendantsImpl().
llvm::Expected< SmallVector< clang::transformer::Edit, 1 > > clang::transformer::detail::rewriteDescendants | ( | const TypeLoc & | Node, |
RewriteRule | Rule, | ||
const ast_matchers::MatchFinder::MatchResult & | Result | ||
) |
Definition at line 322 of file RewriteRule.cpp.
References Node, and rewriteDescendantsImpl().