9#ifndef LLVM_CLANG_TOOLING_TRANSFORMER_TRANSFORMER_H_
10#define LLVM_CLANG_TOOLING_TRANSFORMER_TRANSFORMER_H_
15#include "llvm/Support/Error.h"
31 virtual std::vector<ast_matchers::internal::DynTypedMatcher>
77 [Consumer =
std::move(Consumer)](
82 Consumer(
Result.takeError());
90 template <
typename MetadataT>
94 llvm::Expected<TransformerResult<llvm::type_identity_t<MetadataT>>>)>
106 std::unique_ptr<detail::TransformerImpl> Impl;
123 if constexpr (!std::is_void_v<T>) {
124 auto Metadata = Rule.Metadata[SelectedCase]->eval(
Match);
126 return Metadata.takeError();
127 Result.Metadata = std::move(*Metadata);
129 return llvm::Error::success();
143 : Rule(
std::move(R)), Consumer(
std::move(Consumer)) {
144 assert(llvm::all_of(Rule.Cases,
146 ->
bool { return !!Case.Edits; }) &&
147 "edit generator must be provided for each rule");
148 if constexpr (!std::is_void_v<T>)
149 assert(llvm::all_of(Rule.Metadata,
151 ->
bool { return !!Metadata; }) &&
152 "metadata generator must be provided for each rule");
158 auto Transformations = Rule.Cases[I].Edits(
Result);
159 if (!Transformations) {
160 Consumer(Transformations.takeError());
165 if (!Transformations->empty()) {
168 Changes = std::move(*
C);
170 Consumer(
C.takeError());
173 }
else if (std::is_void<T>::value) {
178 TransformerResult<T> RewriteResult;
180 Consumer(std::move(E));
184 RewriteResult.Changes = llvm::MutableArrayRef<AtomicChange>(Changes);
185 Consumer(std::move(RewriteResult));
188 std::vector<ast_matchers::internal::DynTypedMatcher>
195template <
typename MetadataT>
201 : Impl(
std::make_unique<
detail::WithMetadataImpl<MetadataT>>(
202 std::move(Rule),
std::move(Consumer))) {}
Defines the RewriteRule class and related functions for creating, modifying and interpreting RewriteR...
Called when the Match registered for it was successfully found in the AST.
A class to allow finding matches over the Clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
@ Match
This is not an overload because the signature exactly matches an existing declaration.
@ Result
The result type of a method or function.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
int const char * function
Contains all information for a given match.