clang
10.0.0git
|
The following three functions are a low-level part of the RewriteRule API. More...
Classes | |
struct | Transformation |
A source "transformation," represented by a character range in the source to be replaced and a corresponding replacement string. More... | |
Functions | |
ast_matchers::internal::DynTypedMatcher | buildMatcher (const RewriteRule &Rule) |
Builds a single matcher for the rule, covering all of the rule's cases. More... | |
std::vector< ast_matchers::internal::DynTypedMatcher > | buildMatchers (const RewriteRule &Rule) |
Builds a set of matchers that cover the rule (one for each distinct node matcher base kind: Stmt, Decl, etc.). More... | |
SourceLocation | getRuleMatchLoc (const ast_matchers::MatchFinder::MatchResult &Result) |
Gets the beginning location of the source matched by a rewrite rule. More... | |
const RewriteRule::Case & | findSelectedCase (const ast_matchers::MatchFinder::MatchResult &Result, const RewriteRule &Rule) |
Returns the Case of Rule that was selected in the match result. More... | |
Expected< SmallVector< Transformation, 1 > > | translateEdits (const ast_matchers::MatchFinder::MatchResult &Result, llvm::ArrayRef< ASTEdit > Edits) |
Attempts to translate Edits , which are in terms of AST nodes bound in the match Result , into Transformations, which are in terms of the source code text. More... | |
Stencil | makeStencil (llvm::StringRef Text) |
Convenience function to construct a Stencil . More... | |
Stencil | makeStencil (RangeSelector Selector) |
Stencil | makeStencil (Stencil S) |
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 RewriteRule & | 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 162 of file RewriteRule.cpp.
References buildMatchers().
std::vector< DynTypedMatcher > clang::transformer::detail::buildMatchers | ( | const RewriteRule & | Rule | ) |
Builds a set of matchers that cover the rule (one 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 136 of file RewriteRule.cpp.
References clang::transformer::RewriteRule::Cases, and hasValidKind().
Referenced by buildMatcher().
const RewriteRule::Case & clang::transformer::detail::findSelectedCase | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
const RewriteRule & | Rule | ||
) |
Returns the Case
of Rule
that was selected in the match result.
Assumes a matcher built with buildMatcher
.
Definition at line 186 of file RewriteRule.cpp.
References clang::transformer::RewriteRule::Cases, and clang::transformer::RewriteRule::RootID.
Referenced by clang::tooling::Transformer::run().
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 168 of file RewriteRule.cpp.
References clang::tooling::getRangeForEdit(), clang::CharSourceRange::getTokenRange(), and clang::transformer::RewriteRule::RootID.
Referenced by clang::tooling::Transformer::run().
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::cat().
Stencil clang::transformer::detail::makeStencil | ( | RangeSelector | Selector | ) |
Definition at line 299 of file Stencil.cpp.
References clang::transformer::selection(), clang::transformer::text(), and Text.
Expected< SmallVector< transformer::detail::Transformation, 1 > > clang::transformer::detail::translateEdits | ( | const ast_matchers::MatchFinder::MatchResult & | Result, |
llvm::ArrayRef< ASTEdit > | Edits | ||
) |
Attempts to translate Edits
, which are in terms of AST nodes bound in the match Result
, into Transformations, which are in terms of the source code text.
Returns an empty vector if any of the edits apply to portions of the source that are ineligible for rewriting (certain interactions with macros, for example). Fails if any invariants are violated relating to bound nodes in the match. However, it does not fail in the case of conflicting edits – conflict handling is left to clients. We recommend use of the AtomicChange
or Replacements
classes for assistance in detecting such conflicts.
Definition at line 33 of file RewriteRule.cpp.
References clang::tooling::getRangeForEdit(), clang::transformer::detail::Transformation::Range, and clang::transformer::detail::Transformation::Replacement.
Referenced by clang::tooling::Transformer::run().