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>
82 [Consumer =
std::move(Consumer)](
87 Consumer(
Result.takeError());
95 template <
typename MetadataT>
111 std::unique_ptr<detail::TransformerImpl> Impl;
128 if constexpr (!std::is_void_v<T>) {
129 auto Metadata = Rule.Metadata[SelectedCase]->eval(Match);
131 return Metadata.takeError();
132 Result.Metadata = std::move(*Metadata);
134 return llvm::Error::success();
148 : Rule(
std::move(R)), Consumer(
std::move(Consumer)) {
149 assert(llvm::all_of(Rule.Cases,
151 ->
bool { return !!Case.Edits; }) &&
152 "edit generator must be provided for each rule");
153 if constexpr (!std::is_void_v<T>)
154 assert(llvm::all_of(Rule.Metadata,
156 ->
bool { return !!Metadata; }) &&
157 "metadata generator must be provided for each rule");
163 auto Transformations = Rule.Cases[I].Edits(
Result);
164 if (!Transformations) {
165 Consumer(Transformations.takeError());
170 if (!Transformations->empty()) {
173 Changes = std::move(*
C);
175 Consumer(
C.takeError());
178 }
else if (std::is_void<T>::value) {
183 TransformerResult<T> RewriteResult;
185 Consumer(std::move(
E));
190 Consumer(std::move(RewriteResult));
193 std::vector<ast_matchers::internal::DynTypedMatcher>
194 buildMatchers() const final {
200template <
typename MetadataT>
206 : Impl(
std::make_unique<detail::WithMetadataImpl<MetadataT>>(
207 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.
@ Result
The result type of a method or function.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
Contains all information for a given match.