clang 20.0.0git
Public Types | Public Member Functions | List of all members
clang::tooling::Transformer Class Reference

Handles the matcher and callback registration for a single RewriteRule, as defined by the arguments of the constructor. More...

#include "clang/Tooling/Transformer/Transformer.h"

Inheritance diagram for clang::tooling::Transformer:
Inheritance graph
[legend]

Public Types

using ChangeSetConsumer = std::function< void(Expected< llvm::MutableArrayRef< AtomicChange > > Changes)>
 Provides the set of changes to the consumer.
 

Public Member Functions

 Transformer (transformer::RewriteRuleWith< void > Rule, ChangeSetConsumer Consumer)
 
template<typename MetadataT >
 Transformer (transformer::RewriteRuleWith< MetadataT > Rule, std::function< void(llvm::Expected< TransformerResult< typename detail::type_identity< MetadataT >::type > >)> Consumer)
 
void registerMatchers (ast_matchers::MatchFinder *MatchFinder)
 N.B.
 
void run (const ast_matchers::MatchFinder::MatchResult &Result) override
 Not called directly by users – called by the framework, via base class pointer.
 
- Public Member Functions inherited from clang::ast_matchers::MatchFinder::MatchCallback
virtual ~MatchCallback ()
 
virtual void run (const MatchResult &Result)=0
 Called on every match by the MatchFinder.
 
virtual void onStartOfTranslationUnit ()
 Called at the start of each translation unit.
 
virtual void onEndOfTranslationUnit ()
 Called at the end of each translation unit.
 
virtual StringRef getID () const
 An id used to group the matchers.
 
virtual std::optional< TraversalKindgetCheckTraversalKind () const
 TraversalKind to use while matching and processing the result nodes.
 

Detailed Description

Handles the matcher and callback registration for a single RewriteRule, as defined by the arguments of the constructor.

Definition at line 63 of file Transformer.h.

Member Typedef Documentation

◆ ChangeSetConsumer

Provides the set of changes to the consumer.

The callback is free to move or destructively consume the changes as needed.

We use MutableArrayRef as an abstraction to provide decoupling, and we expect the majority of consumers to copy or move the individual values into a separate data structure.

Definition at line 71 of file Transformer.h.

Constructor & Destructor Documentation

◆ Transformer() [1/2]

clang::tooling::Transformer::Transformer ( transformer::RewriteRuleWith< void >  Rule,
ChangeSetConsumer  Consumer 
)
inlineexplicit
Parameters
Consumerreceives all rewrites for a single match, or an error. Will not necessarily be called for each match; for example, if the rule generates no edits but does not fail. Note that clients are responsible for handling the case that independent AtomicChanges conflict with each other.

Definition at line 79 of file Transformer.h.

References clang::Result.

◆ Transformer() [2/2]

template<typename MetadataT >
clang::tooling::Transformer::Transformer ( transformer::RewriteRuleWith< MetadataT >  Rule,
std::function< void(llvm::Expected< TransformerResult< typename detail::type_identity< MetadataT >::type > >)>  Consumer 
)
explicit
Parameters
Consumerreceives all rewrites and the associated metadata for a single match, or an error. Will always be called for each match, even if the rule generates no edits. Note that clients are responsible for handling the case that independent AtomicChanges conflict with each other.

Definition at line 201 of file Transformer.h.

Member Function Documentation

◆ registerMatchers()

void clang::tooling::Transformer::registerMatchers ( ast_matchers::MatchFinder MatchFinder)

N.B.

Passes this pointer to MatchFinder. So, this object should not be moved after this call.

Definition at line 71 of file Transformer.cpp.

References clang::ast_matchers::MatchFinder::addDynamicMatcher().

◆ run()

void clang::tooling::Transformer::run ( const ast_matchers::MatchFinder::MatchResult Result)
overridevirtual

Not called directly by users – called by the framework, via base class pointer.

Implements clang::ast_matchers::MatchFinder::MatchCallback.

Definition at line 76 of file Transformer.cpp.

References clang::Result.


The documentation for this class was generated from the following files: