15#ifndef MLIR_TABLEGEN_FORMAT_H_
16#define MLIR_TABLEGEN_FORMAT_H_
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/Support/FormatVariadic.h"
63 std::optional<StringRef>
getSubstFor(StringRef placeholder)
const;
71 static unsigned getHashValue(
const PHKind &val) {
72 return CharInfo::getHashValue(
static_cast<char>(val));
75 static bool isEqual(
const PHKind &
lhs,
const PHKind &
rhs) {
80 llvm::SmallDenseMap<PHKind, std::string, 4, PHKindInfo> builtinSubstMap;
81 llvm::StringMap<std::string> customSubstMap;
117 static std::pair<FmtReplacement, StringRef> splitFmtSegment(StringRef
fmt);
118 static std::vector<FmtReplacement> parseFormatString(StringRef
fmt);
129 template <
typename... Ts>
130 std::vector<llvm::support::detail::FormatFunctorRef>
132 return std::vector<llvm::support::detail::FormatFunctorRef>{items...};
138 std::vector<llvm::support::detail::FormatFunctorRef>
adapters;
152 void format(llvm::raw_ostream &s)
const;
156 llvm::raw_string_ostream s(
result);
161 template <
unsigned N>
164 llvm::raw_svector_ostream s(
result);
169 template <
unsigned N>
174 operator std::string()
const {
return str(); }
177template <
typename Tuple>
187 parameters(std::move(params)) {
188 adapters.reserve(std::tuple_size<Tuple>::value);
195 :
FmtObjectBase(std::move(that)), parameters(std::move(that.parameters)) {
196 adapters.reserve(that.adapters.size());
254template <
typename... Ts>
257 llvm::support::detail::FormatFunctor(std::forward<Ts>(vals))...))> {
258 using ParamTuple =
decltype(std::make_tuple(
259 llvm::support::detail::FormatFunctor(std::forward<Ts>(vals))...));
263 llvm::support::detail::FormatFunctor(std::forward<Ts>(vals))...));
Format context containing substitutions for special placeholders.
FmtContext & withBuilder(Twine subst)
static PHKind getPlaceHolderKind(StringRef str)
std::optional< StringRef > getSubstFor(PHKind placeholder) const
FmtContext & withSelf(Twine subst)
FmtContext & addSubst(StringRef placeholder, const Twine &subst)
FmtObjectBase(StringRef fmt, const FmtContext *ctx, size_t numParams)
void format(llvm::raw_ostream &s) const
const FmtContext * context
FmtObjectBase(FmtObjectBase &&that)
std::vector< llvm::support::detail::FormatFunctorRef > adapters
std::vector< FmtReplacement > replacements
FmtObjectBase(const FmtObjectBase &that)=delete
SmallString< N > sstr() const
FmtObject(FmtObject const &that)=delete
FmtObject(StringRef fmt, const FmtContext *ctx, Tuple &¶ms)
FmtObject(FmtObject &&that)
FmtStrVecObject(StringRef fmt, const FmtContext *ctx, ArrayRef< std::string > params)
llvm::support::detail::FormatFunctor< std::string > StrFormatAdapter
FmtStrVecObject(FmtStrVecObject const &that)=delete
auto tgfmt(StringRef fmt, const FmtContext *ctx, Ts &&...vals) -> FmtObject< decltype(std::make_tuple(llvm::support::detail::FormatFunctor(std::forward< Ts >(vals))...))>
Formats text by substituting placeholders in format string with replacement parameters.
FmtStrVecObject tgfmtv(StringRef fmt, const FmtContext *ctx, ArrayRef< std::string > params)
Like tgfmt, but take replacement parameters as an array of strings instead.
Include the generated interface declarations.
llvm::DenseMapInfo< T, Enable > DenseMapInfo
std::vector< llvm::support::detail::FormatFunctorRef > operator()(Ts &...items)
FmtReplacement(StringRef literal)
FmtReplacement(StringRef spec, size_t index)
static constexpr size_t kUnset
FmtContext::PHKind placeholder
FmtReplacement(StringRef spec, FmtContext::PHKind placeholder)
FmtReplacement(StringRef spec, size_t index, size_t end)