14#ifndef LLVM_SUPPORT_FORMATPROVIDERS_H
15#define LLVM_SUPPORT_FORMATPROVIDERS_H
31 :
public std::integral_constant<
32 bool, 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>::value> {};
38 :
public std::integral_constant<bool, std::is_same_v<T, char>> {};
42 :
public std::integral_constant<bool,
43 is_one_of<T, char *, const char *>::value> {
48 :
public std::integral_constant<bool,
49 std::is_convertible_v<T, llvm::StringRef>> {
54 :
public std::integral_constant<bool, std::is_pointer_v<T> &&
55 !is_cstring<T>::value> {};
59 :
public std::integral_constant<bool, std::is_floating_point_v<T>> {};
65 std::optional<size_t> Result;
67 Result = std::nullopt;
68 else if (Str.getAsInteger(10, Prec)) {
69 assert(
false &&
"Invalid precision specifier");
70 Result = std::nullopt;
72 assert(Prec < 100 &&
"Precision out of range");
73 Result = std::min<size_t>(99u, Prec);
79 if (!Str.starts_with_insensitive(
"x"))
82 if (Str.consume_front(
"x-"))
84 else if (Str.consume_front(
"X-"))
86 else if (Str.consume_front(
"x+") || Str.consume_front(
"x"))
88 else if (Str.consume_front(
"X+") || Str.consume_front(
"X"))
95 Str.consumeInteger(10,
Default);
128 T,
std::enable_if_t<detail::use_integral_formatter<T>::value>>
135 if (consumeHexStyle(Style, HS)) {
136 Digits = consumeNumHexDigits(Style, HS, 0);
142 if (Style.consume_front(
"N") || Style.consume_front(
"n"))
144 else if (Style.consume_front(
"D") || Style.consume_front(
"d"))
147 Style.consumeInteger(10, Digits);
148 assert(Style.empty() &&
"Invalid integral format style!");
177 T,
std::enable_if_t<detail::use_pointer_formatter<T>::value>>
183 consumeHexStyle(Style, HS);
184 size_t Digits = consumeNumHexDigits(Style, HS,
sizeof(
void *) * 2);
185 write_hex(Stream,
reinterpret_cast<std::uintptr_t
>(V), HS, Digits);
202 T,
std::enable_if_t<detail::use_string_formatter<T>::value>> {
205 if (!Style.empty() && Style.getAsInteger(10,
N)) {
206 assert(
false &&
"Style is not a valid integer");
235 std::enable_if_t<detail::use_char_formatter<T>::value>> {
241 int X =
static_cast<int>(V);
266 Stream << StringSwitch<const char *>(Style)
267 .Case(
"Y",
B ?
"YES" :
"NO")
268 .Case(
"y",
B ?
"yes" :
"no")
269 .CaseLower(
"D",
B ?
"1" :
"0")
270 .Case(
"T",
B ?
"TRUE" :
"FALSE")
271 .Cases(
"t",
"",
B ?
"true" :
"false")
272 .Default(
B ?
"1" :
"0");
301 std::enable_if_t<detail::use_double_formatter<T>::value>>
305 if (Style.consume_front(
"P") || Style.consume_front(
"p"))
307 else if (Style.consume_front(
"F") || Style.consume_front(
"f"))
309 else if (Style.consume_front(
"E"))
311 else if (Style.consume_front(
"e"))
316 std::optional<size_t> Precision = parseNumericPrecision(Style);
320 write_double(Stream,
static_cast<double>(V), S, Precision);
325template <
typename IterT>
326using IterValue =
typename std::iterator_traits<IterT>::value_type;
328template <
typename IterT>
330 :
public std::integral_constant<
331 bool, !uses_missing_provider<IterValue<IterT>>::value> {};
358 using value =
typename std::iterator_traits<IterT>::value_type;
364 if (Style.front() != Indicator)
366 Style = Style.drop_front();
368 assert(
false &&
"Invalid range style");
372 for (
const char *
D : std::array<const char *, 3>{
"[]",
"<>",
"()"}) {
373 if (Style.front() !=
D[0])
375 size_t End = Style.find_first_of(
D[1]);
377 assert(
false &&
"Missing range option end delimeter!");
381 Style = Style.drop_front(
End + 1);
384 assert(
false &&
"Invalid range style!");
388 static std::pair<StringRef, StringRef> parseOptions(
StringRef Style) {
389 StringRef Sep = consumeOneOption(Style,
'$',
", ");
390 StringRef Args = consumeOneOption(Style,
'@',
"");
391 assert(Style.empty() &&
"Unexpected text in range option string!");
392 return std::make_pair(Sep, Args);
397 "Range value_type does not have a format provider!");
402 std::tie(Sep, ArgStyle) = parseOptions(Style);
403 auto Begin = V.begin();
407 Adapter.format(Stream, ArgStyle);
410 while (Begin !=
End) {
413 Adapter.format(Stream, ArgStyle);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static constexpr size_t npos
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static bool consumeHexStyle(StringRef &Str, HexPrintStyle &Style)
static std::optional< size_t > parseNumericPrecision(StringRef Str)
static size_t consumeNumHexDigits(StringRef &Str, HexPrintStyle Style, size_t Default)
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
std::enable_if_t< uses_format_member< T >::value, T > build_format_adapter(T &&Item)
typename std::iterator_traits< IterT >::value_type IterValue
This is an optimization pass for GlobalISel generic memory operations.
void write_integer(raw_ostream &S, unsigned int N, size_t MinDigits, IntegerStyle Style)
size_t getDefaultPrecision(FloatStyle Style)
void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, std::optional< size_t > Width=std::nullopt)
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.
bool isPrefixedHexStyle(HexPrintStyle S)
Implement std::hash so that hash_code can be used in STL containers.