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 inline PHKind getEmptyKey() {
72 return static_cast<PHKind>(CharInfo::getEmptyKey());
74 static inline PHKind getTombstoneKey() {
75 return static_cast<PHKind>(CharInfo::getTombstoneKey());
77 static unsigned getHashValue(
const PHKind &val) {
78 return CharInfo::getHashValue(
static_cast<char>(val));
81 static bool isEqual(
const PHKind &lhs,
const PHKind &rhs) {
86 llvm::SmallDenseMap<PHKind, std::string, 4, PHKindInfo> builtinSubstMap;
87 llvm::StringMap<std::string> customSubstMap;
123 static std::pair<FmtReplacement, StringRef> splitFmtSegment(StringRef
fmt);
124 static std::vector<FmtReplacement> parseFormatString(StringRef
fmt);
135 template <
typename... Ts>
136 std::vector<llvm::support::detail::format_adapter *>
138 return std::vector<llvm::support::detail::format_adapter *>{&items...};
144 std::vector<llvm::support::detail::format_adapter *>
adapters;
158 void format(llvm::raw_ostream &s)
const;
162 llvm::raw_string_ostream s(result);
167 template <
unsigned N>
170 llvm::raw_svector_ostream s(result);
175 template <
unsigned N>
180 operator std::string()
const {
return str(); }
183 template <
typename Tuple>
193 parameters(std::move(params)) {
194 adapters.reserve(std::tuple_size<Tuple>::value);
201 :
FmtObjectBase(std::move(that)), parameters(std::move(that.parameters)) {
202 adapters.reserve(that.adapters.size());
210 std::declval<std::string>()));
261 template <
typename... Ts>
264 decltype(std::make_tuple(llvm::support::detail::build_format_adapter(
265 std::forward<Ts>(vals))...))> {
266 using ParamTuple = decltype(std::make_tuple(
267 llvm::support::detail::build_format_adapter(std::forward<Ts>(vals))...));
270 std::make_tuple(llvm::support::detail::build_format_adapter(
271 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)
std::vector< llvm::support::detail::format_adapter * > adapters
FmtObjectBase(StringRef fmt, const FmtContext *ctx, size_t numParams)
void format(llvm::raw_ostream &s) const
const FmtContext * context
FmtObjectBase(FmtObjectBase &&that)
SmallString< N > sstr() const
std::vector< FmtReplacement > replacements
FmtObjectBase(const FmtObjectBase &that)=delete
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)
decltype(llvm::support::detail::build_format_adapter(std::declval< 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::build_format_adapter(std::forward< Ts >(vals))...))>
Formats text by substituting placeholders in format string with replacement parameters.
Include the generated interface declarations.
std::vector< llvm::support::detail::format_adapter * > operator()(Ts &...items)
Struct representing a replacement segment for the formatted string.
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)