15 #ifndef LLVM_SUPPORT_FORMATPROVIDERS_H
16 #define LLVM_SUPPORT_FORMATPROVIDERS_H
24 #include <type_traits>
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<T, char>::value> {};
42 :
public std::integral_constant<bool,
43 is_one_of<T, char *, const char *>::value> {
48 :
public std::integral_constant<
49 bool, is_one_of<T, llvm::StringRef, std::string>::value ||
50 is_cstring<T>::value> {};
54 :
public std::integral_constant<bool, std::is_pointer<T>::value &&
55 !is_cstring<T>::value> {};
59 :
public std::integral_constant<bool, std::is_floating_point<T>::value> {};
69 assert(
false &&
"Invalid precision specifier");
72 assert(Prec < 100 &&
"Precision out of range");
73 Result = std::min<size_t>(99u, Prec);
126 template <
typename T>
128 T, typename std::enable_if<detail::use_integral_formatter<T>::value>::type>
135 if (consumeHexStyle(Style, HS)) {
136 Digits = consumeNumHexDigits(Style, HS, 0);
148 assert(Style.
empty() &&
"Invalid integral format style!");
175 template <
typename T>
177 T, typename std::enable_if<detail::use_pointer_formatter<T>::value>::type>
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);
200 template <
typename T>
202 T, typename std::enable_if<detail::use_string_formatter<T>::value>::type> {
206 assert(
false &&
"Style is not a valid integer");
222 template <
typename T>
224 T, typename std::enable_if<detail::use_char_formatter<T>::value>::type> {
230 int X =
static_cast<int>(V);
255 Stream << StringSwitch<const char *>(
Style)
256 .Case(
"Y", B ?
"YES" :
"NO")
257 .Case(
"y", B ?
"yes" :
"no")
258 .CaseLower(
"D", B ?
"1" :
"0")
259 .Case(
"T", B ?
"TRUE" :
"FALSE")
260 .Cases(
"t",
"", B ?
"true" :
"false")
261 .Default(B ?
"1" :
"0");
288 template <
typename T>
290 T, typename std::enable_if<detail::use_double_formatter<T>::value>::type>
309 write_double(Stream, static_cast<double>(V), S, Precision);
314 template <
typename IterT>
315 using IterValue =
typename std::iterator_traits<IterT>::value_type;
317 template <
typename IterT>
319 :
public std::integral_constant<
320 bool, !uses_missing_provider<IterValue<IterT>>::value> {};
347 using value =
typename std::iterator_traits<IterT>::value_type;
348 using reference =
typename std::iterator_traits<IterT>::reference;
354 if (Style.
front() != Indicator)
358 assert(
false &&
"Invalid range style");
362 std::vector<const char *> Delims = {
"[]",
"<>",
"()"};
363 for (
const char *
D : Delims) {
364 if (Style.
front() !=
D[0])
368 assert(
false &&
"Missing range option end delimeter!");
375 assert(
false &&
"Invalid range style!");
379 static std::pair<StringRef, StringRef> parseOptions(
StringRef Style) {
380 StringRef Sep = consumeOneOption(Style,
'$',
", ");
382 assert(Style.
empty() &&
"Unexpected text in range option string!");
383 return std::make_pair(Sep, Args);
388 "Range value_type does not have a format provider!");
393 std::tie(Sep, ArgStyle) = parseOptions(Style);
394 auto Begin = V.
begin();
399 Adapter.format(Stream, ArgStyle);
402 while (Begin !=
End) {
406 Adapter.format(Stream, ArgStyle);
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
static bool consumeHexStyle(StringRef &Str, HexPrintStyle &Style)
void write_double(raw_ostream &S, double D, FloatStyle Style, Optional< size_t > Precision=None)
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
size_t getDefaultPrecision(FloatStyle Style)
LLVM_ATTRIBUTE_ALWAYS_INLINE bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
bool isPrefixedHexStyle(HexPrintStyle S)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
LLVM_NODISCARD char front() const
front - Get the first character in the string.
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static const unsigned End
A range adaptor for a pair of iterators.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
typename std::iterator_traits< IterT >::value_type IterValue
void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, Optional< size_t > Width=None)
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::enable_if< uses_format_member< T >::value, T >::type build_format_adapter(T &&Item)
This class implements an extremely fast bulk output stream that can only output to a stream...
static Optional< size_t > parseNumericPrecision(StringRef Str)
StringRef - Represent a constant reference to a string, i.e.
LLVM_NODISCARD bool startswith_lower(StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.
void write_integer(raw_ostream &S, unsigned int N, size_t MinDigits, IntegerStyle Style)
static size_t consumeNumHexDigits(StringRef &Str, HexPrintStyle Style, size_t Default)