LLVM: include/llvm/Support/FormatProviders.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_SUPPORT_FORMATPROVIDERS_H
15#define LLVM_SUPPORT_FORMATPROVIDERS_H
16
22
23#include
24#include
25#include <type_traits>
26
27namespace llvm {
30template
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> {};
35
36template
38
39template
41
42template
44
45template
47 : public std::bool_constant<std::is_pointer_v && !is_cstring::value> {
48};
49
50template
52
54protected:
56 size_t Prec;
57 std::optional<size_t> Result;
58 if (Str.empty())
59 Result = std::nullopt;
60 else if (Str.getAsInteger(10, Prec)) {
61 assert(false && "Invalid precision specifier");
62 Result = std::nullopt;
63 } else {
64 assert(Prec < 100 && "Precision out of range");
65 Result = std::min<size_t>(99u, Prec);
66 }
67 return Result;
68 }
69
71 if (!Str.starts_with_insensitive("x"))
72 return std::nullopt;
73
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");
83 }
84
87 Str.consumeInteger(10, Default);
91 }
92};
93}
94}
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119template
121 T, std::enable_if_t<support::detail::use_integral_formatter::value>>
123private:
124public:
126 size_t Digits = 0;
127 if (std::optional HS = consumeHexStyle(Style)) {
129 write_hex(Stream, V, *HS, Digits);
130 return;
131 }
132
134 if (Style.consume_front("N") || Style.consume_front("n"))
136 else if (Style.consume_front("D") || Style.consume_front("d"))
138
139 Style.consumeInteger(10, Digits);
140 assert(Style.empty() && "Invalid integral format style!");
142 }
143};
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167template
169 T, std::enable_if_t<support::detail::use_pointer_formatter::value>>
171private:
172public:
175 if (std::optional consumed = consumeHexStyle(Style))
176 HS = *consumed;
178 write_hex(Stream, reinterpret_caststd::uintptr\_t\(V), HS, Digits);
179 }
180};
181
182
183
184
185
186
187
188
189
190
191
192
193template
195 T, std::enable_if_t<support::detail::use_string_formatter::value>> {
198 if (!Style.empty() && Style.getAsInteger(10, N)) {
199 assert(false && "Style is not a valid integer");
200 }
203 }
204};
205
206
207
208
209
216
217
218
219
220
221
222
223
224
225
226template
228 T, std::enable_if_t<support::detail::use_char_formatter::value>> {
231 if (Style.empty())
232 Stream << V;
233 else {
234 int X = static_cast<int>(V);
236 }
237 }
238};
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
259 Stream << StringSwitch<const char *>(Style)
260 .Case("Y", B ? "YES" : "NO")
261 .Case("y", B ? "yes" : "no")
262 .CaseLower("D", B ? "1" : "0")
263 .Case("T", B ? "TRUE" : "FALSE")
264 .Cases({"t", ""}, B ? "true" : "false")
266 }
267};
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292template
294 T, std::enable_if_t<support::detail::use_double_formatter::value>>
298 if (Style.consume_front("P") || Style.consume_front("p"))
300 else if (Style.consume_front("F") || Style.consume_front("f"))
302 else if (Style.consume_front("E"))
304 else if (Style.consume_front("e"))
306 else
308
310 if (!Precision)
312
313 write_double(Stream, static_cast<double>(V), S, Precision);
314 }
315};
316
317namespace support {
319template
320using IterValue = typename std::iterator_traits::value_type;
321
322template
324 : public std::bool_constant<
325 !support::detail::uses_missing_provider<IterValue>::value> {};
326}
327}
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
353 using value = typename std::iterator_traits::value_type;
354
357 if (Style.empty())
359 if (Style.front() != Indicator)
361 Style = Style.drop_front();
362 if (Style.empty()) {
363 assert(false && "Invalid range style");
365 }
366
367 for (const char *D : std::array<const char *, 3>{"[]", "<>", "()"}) {
368 if (Style.front() != D[0])
369 continue;
370 size_t End = Style.find_first_of(D[1]);
372 assert(false && "Missing range option end delimeter!");
374 }
375 StringRef Result = Style.slice(1, End);
376 Style = Style.drop_front(End + 1);
377 return Result;
378 }
379 assert(false && "Invalid range style!");
381 }
382
383 static std::pair<StringRef, StringRef> parseOptions(StringRef Style) {
384 StringRef Sep = consumeOneOption(Style, '$', ", ");
385 StringRef Args = consumeOneOption(Style, '@', "");
386 assert(Style.empty() && "Unexpected text in range option string!");
387 return {Sep, Args};
388 }
389
390public:
392 "Range value_type does not have a format provider!");
397 std::tie(Sep, ArgStyle) = parseOptions(Style);
398 auto Begin = V.begin();
399 auto End = V.end();
400 if (Begin != End) {
402 Adapter.format(Stream, ArgStyle);
403 ++Begin;
404 }
405 while (Begin != End) {
406 Stream << Sep;
408 Adapter.format(Stream, ArgStyle);
409 ++Begin;
410 }
411 }
412};
413}
414
415#endif
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...
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
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...
static void format(const llvm::iterator_range< IterT > &V, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:393
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition FormatProviders.h:53
static size_t consumeNumHexDigits(StringRef &Str, HexPrintStyle Style, size_t Default)
Definition FormatProviders.h:85
static std::optional< size_t > parseNumericPrecision(StringRef Str)
Definition FormatProviders.h:55
static std::optional< HexPrintStyle > consumeHexStyle(StringRef &Str)
Definition FormatProviders.h:70
typename std::iterator_traits< IterT >::value_type IterValue
Definition FormatProviders.h:320
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)
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.
static void format(const char &V, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:229
static void format(const T &V, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:296
static void format(const T &V, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:125
static void format(const T &V, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:173
static void format(const T &V, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:196
static void format(const Twine &V, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:211
static void format(const bool &B, llvm::raw_ostream &Stream, StringRef Style)
Definition FormatProviders.h:257
Definition FormatProviders.h:40
Definition FormatProviders.h:325
Definition FormatProviders.h:37
Definition FormatProviders.h:51
Definition FormatProviders.h:34
Definition FormatProviders.h:47
Definition FormatProviders.h:43