14#ifndef LLVM_SUPPORT_FORMATPROVIDERS_H
15#define LLVM_SUPPORT_FORMATPROVIDERS_H
32 :
public is_one_of<T, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
33 int64_t, uint64_t, int, unsigned, long, unsigned long,
34 long long, unsigned long long> {};
47 :
public std::bool_constant<std::is_pointer_v<T> && !is_cstring<T>::value> {
57 std::optional<size_t> Result;
59 Result = std::nullopt;
60 else if (Str.getAsInteger(10, Prec)) {
61 assert(
false &&
"Invalid precision specifier");
62 Result = std::nullopt;
64 assert(Prec < 100 &&
"Precision out of range");
65 Result = std::min<size_t>(99u, Prec);
71 if (!Str.starts_with_insensitive(
"x"))
74 if (Str.consume_front(
"x-"))
76 if (Str.consume_front(
"X-"))
78 if (Str.consume_front(
"x+") || Str.consume_front(
"x"))
80 if (!Str.consume_front(
"X+"))
81 Str.consume_front(
"X");
87 Str.consumeInteger(10,
Default);
124 T,
std::enable_if_t<support::detail::use_integral_formatter<T>::value>>
138 bool NonNegativePlus = Style.consume_front(
'+');
141 if (Style.consume_front(
"N") || Style.consume_front(
"n"))
143 else if (Style.consume_front(
"D") || Style.consume_front(
"d"))
146 Style.consumeInteger(10, Digits);
147 assert(Style.empty() &&
"Invalid integral format style!");
180 T,
std::enable_if_t<support::detail::use_pointer_formatter<T>::value>>
189 write_hex(Stream,
reinterpret_cast<std::uintptr_t
>(V), HS, Digits);
206 T,
std::enable_if_t<support::detail::use_string_formatter<T>::value>> {
209 if (!Style.empty() && Style.getAsInteger(10,
N)) {
210 assert(
false &&
"Style is not a valid integer");
239 T,
std::enable_if_t<support::detail::use_char_formatter<T>::value>> {
245 int X =
static_cast<int>(V);
270 Stream << StringSwitch<const char *>(Style)
271 .Case(
"Y",
B ?
"YES" :
"NO")
272 .Case(
"y",
B ?
"yes" :
"no")
273 .CaseLower(
"D",
B ?
"1" :
"0")
274 .Case(
"T",
B ?
"TRUE" :
"FALSE")
275 .Cases({
"t",
""},
B ?
"true" :
"false")
305 T,
std::enable_if_t<support::detail::use_double_formatter<T>::value>>
309 if (Style.consume_front(
"P") || Style.consume_front(
"p"))
311 else if (Style.consume_front(
"F") || Style.consume_front(
"f"))
313 else if (Style.consume_front(
"E"))
315 else if (Style.consume_front(
"e"))
324 write_double(Stream,
static_cast<double>(V), S, Precision);
330template <
typename IterT>
331using IterValue =
typename std::iterator_traits<IterT>::value_type;
333template <
typename IterT>
335 :
public std::bool_constant<
336 !support::detail::uses_missing_provider<IterValue<IterT>>::value> {};
364 using value =
typename std::iterator_traits<IterT>::value_type;
370 if (Style.front() != Indicator)
372 Style = Style.drop_front();
374 assert(
false &&
"Invalid range style");
378 for (
const char *
D : std::array<const char *, 3>{
"[]",
"<>",
"()"}) {
379 if (Style.front() !=
D[0])
381 size_t End = Style.find_first_of(
D[1]);
383 assert(
false &&
"Missing range option end delimeter!");
387 Style = Style.drop_front(End + 1);
390 assert(
false &&
"Invalid range style!");
394 static std::pair<StringRef, StringRef> parseOptions(
StringRef Style) {
395 StringRef Sep = consumeOneOption(Style,
'$',
", ");
396 StringRef Args = consumeOneOption(Style,
'@',
"");
397 assert(Style.empty() &&
"Unexpected text in range option string!");
403 "Range value_type does not have a format provider!");
408 std::tie(Sep, ArgStyle) = parseOptions(Style);
409 auto Begin = V.begin();
413 Adapter.format(Stream, ArgStyle);
416 while (Begin != End) {
419 Adapter.format(Stream, ArgStyle);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
static size_t consumeNumHexDigits(StringRef &Str, HexPrintStyle Style, size_t Default)
static std::optional< size_t > parseNumericPrecision(StringRef Str)
static std::optional< HexPrintStyle > consumeHexStyle(StringRef &Str)
typename std::iterator_traits< IterT >::value_type IterValue
std::enable_if_t< uses_format_member< T >::value, T > build_format_adapter(T &&Item)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void write_integer(raw_ostream &S, unsigned int N, size_t MinDigits, IntegerStyle Style, bool NonNegativePlus=false)
LLVM_ABI size_t getDefaultPrecision(FloatStyle Style)
std::disjunction< std::is_same< T, Ts >... > is_one_of
traits class for checking whether type T is one of any of the given types in the variadic list.
LLVM_ABI void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, std::optional< size_t > Width=std::nullopt)
LLVM_ABI void write_double(raw_ostream &S, double D, FloatStyle Style, std::optional< size_t > Precision=std::nullopt)
@ Default
The result values are uniform if and only if all operands are uniform.
LLVM_ABI bool isPrefixedHexStyle(HexPrintStyle S)
Implement std::hash so that hash_code can be used in STL containers.