clang  10.0.0svn
Classes | Functions
clang::transformer::detail Namespace Reference

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::CasefindSelectedCase (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...
 

Detailed Description

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.

Function Documentation

◆ buildMatcher()

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 140 of file RewriteRule.cpp.

References buildMatchers().

◆ 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 114 of file RewriteRule.cpp.

References clang::transformer::RewriteRule::Cases, and hasValidKind().

Referenced by buildMatcher().

◆ findSelectedCase()

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 164 of file RewriteRule.cpp.

References clang::transformer::RewriteRule::Cases, and clang::transformer::RewriteRule::RootID.

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

◆ getRuleMatchLoc()

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 146 of file RewriteRule.cpp.

References clang::tooling::getRangeForEdit(), clang::CharSourceRange::getTokenRange(), and clang::transformer::RewriteRule::RootID.

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

◆ translateEdits()

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().