9#ifndef LLVM_SUPPORT_YAMLTRAITS_H
10#define LLVM_SUPPORT_YAMLTRAITS_H
34#include <system_error>
50struct EmptyContext {};
62template <
class T>
struct MappingTraits {
85template <
class T,
class Context>
struct MappingContextTraits {
107template <
typename T,
typename Enable =
void>
struct ScalarEnumerationTraits {
123template <
typename T,
typename Enable =
void>
struct ScalarBitSetTraits {
149template <
typename T,
typename Enable =
void>
struct ScalarTraits {
179template <
typename T>
struct BlockScalarTraits {
215template <
typename T>
struct TaggedScalarTraits {
245template <
typename T,
typename EnableIf =
void>
struct SequenceTraits {
257template <
typename T,
typename EnableIf =
void>
struct SequenceElementTraits {
264template <
typename T>
struct DocumentListTraits {
273template <
typename T>
struct CustomMappingTraits {
295template <
typename T>
struct PolymorphicTraits {
304template <
typename T>
struct MissingTrait;
307template <
class T>
struct has_ScalarEnumerationTraits {
308 using Signature_enumeration = void (*)(
class IO &,
T &);
310 template <
typename U>
311 static char test(SameType<Signature_enumeration, &U::enumeration> *);
313 template <
typename U>
static double test(...);
315 static bool const value =
316 (
sizeof(test<ScalarEnumerationTraits<T>>(
nullptr)) == 1);
320template <
class T>
struct has_ScalarBitSetTraits {
321 using Signature_bitset = void (*)(
class IO &,
T &);
323 template <
typename U>
324 static char test(SameType<Signature_bitset, &U::bitset> *);
326 template <
typename U>
static double test(...);
328 static bool const value = (
sizeof(test<ScalarBitSetTraits<T>>(
nullptr)) == 1);
332template <
class T>
struct has_ScalarTraits {
333 using Signature_input = StringRef (*)(StringRef,
void *,
T &);
334 using Signature_output = void (*)(
const T &,
void *, raw_ostream &);
335 using Signature_mustQuote = QuotingType (*)(StringRef);
337 template <
typename U>
338 static char test(SameType<Signature_input, &U::input> *,
339 SameType<Signature_output, &U::output> *,
340 SameType<Signature_mustQuote, &U::mustQuote> *);
342 template <
typename U>
static double test(...);
344 static bool const value =
345 (
sizeof(test<ScalarTraits<T>>(
nullptr,
nullptr,
nullptr)) == 1);
349template <
class T>
struct has_BlockScalarTraits {
350 using Signature_input = StringRef (*)(StringRef,
void *,
T &);
351 using Signature_output = void (*)(
const T &,
void *, raw_ostream &);
353 template <
typename U>
354 static char test(SameType<Signature_input, &U::input> *,
355 SameType<Signature_output, &U::output> *);
357 template <
typename U>
static double test(...);
359 static bool const value =
360 (
sizeof(test<BlockScalarTraits<T>>(
nullptr,
nullptr)) == 1);
364template <
class T>
struct has_TaggedScalarTraits {
365 using Signature_input = StringRef (*)(StringRef, StringRef,
void *,
T &);
366 using Signature_output = void (*)(
const T &,
void *, raw_ostream &,
368 using Signature_mustQuote = QuotingType (*)(
const T &, StringRef);
370 template <
typename U>
371 static char test(SameType<Signature_input, &U::input> *,
372 SameType<Signature_output, &U::output> *,
373 SameType<Signature_mustQuote, &U::mustQuote> *);
375 template <
typename U>
static double test(...);
377 static bool const value =
378 (
sizeof(test<TaggedScalarTraits<T>>(
nullptr,
nullptr,
nullptr)) == 1);
382template <
class T,
class Context>
struct has_MappingTraits {
383 using Signature_mapping = void (*)(
class IO &,
T &,
Context &);
385 template <
typename U>
386 static char test(SameType<Signature_mapping, &U::mapping> *);
388 template <
typename U>
static double test(...);
390 static bool const value =
391 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
395template <
class T>
struct has_MappingTraits<
T, EmptyContext> {
396 using Signature_mapping = void (*)(
class IO &,
T &);
398 template <
typename U>
399 static char test(SameType<Signature_mapping, &U::mapping> *);
401 template <
typename U>
static double test(...);
403 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
407template <
class T,
class Context>
struct has_MappingValidateTraits {
408 using Signature_validate = std::string (*)(
class IO &,
T &,
Context &);
410 template <
typename U>
411 static char test(SameType<Signature_validate, &U::validate> *);
413 template <
typename U>
static double test(...);
415 static bool const value =
416 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
420template <
class T>
struct has_MappingValidateTraits<
T, EmptyContext> {
421 using Signature_validate = std::string (*)(
class IO &,
T &);
423 template <
typename U>
424 static char test(SameType<Signature_validate, &U::validate> *);
426 template <
typename U>
static double test(...);
428 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
432template <
class T,
class Context>
struct has_MappingEnumInputTraits {
433 using Signature_validate = void (*)(
class IO &,
T &);
435 template <
typename U>
436 static char test(SameType<Signature_validate, &U::enumInput> *);
438 template <
typename U>
static double test(...);
440 static bool const value =
441 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
445template <
class T>
struct has_MappingEnumInputTraits<
T, EmptyContext> {
446 using Signature_validate = void (*)(
class IO &,
T &);
448 template <
typename U>
449 static char test(SameType<Signature_validate, &U::enumInput> *);
451 template <
typename U>
static double test(...);
453 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
457template <
class T>
struct has_SequenceMethodTraits {
458 using Signature_size = size_t (*)(
class IO &,
T &);
460 template <
typename U>
static char test(SameType<Signature_size, &U::size> *);
462 template <
typename U>
static double test(...);
464 static bool const value = (
sizeof(test<SequenceTraits<T>>(
nullptr)) == 1);
468template <
class T>
struct has_CustomMappingTraits {
469 using Signature_input = void (*)(IO &io, StringRef key,
T &
v);
471 template <
typename U>
472 static char test(SameType<Signature_input, &U::inputOne> *);
474 template <
typename U>
static double test(...);
476 static bool const value =
477 (
sizeof(test<CustomMappingTraits<T>>(
nullptr)) == 1);
483template <
typename T,
bool Enabled = std::is_
class_v<T>>
class has_FlowTraits {
485 static const bool value =
false;
491template <
class T>
struct has_FlowTraits<
T,
true> {
497 template <
typename C>
498 static char (&
f(SameType<bool Fallback::*, &C::flow> *))[1];
500 template <
typename C>
static char (&
f(...))[2];
502 static bool const value =
sizeof(f<Derived>(
nullptr)) == 2;
507struct has_SequenceTraits
508 :
public std::integral_constant<bool, has_SequenceMethodTraits<T>::value> {
512template <
class T>
struct has_DocumentListTraits {
513 using Signature_size = size_t (*)(
class IO &,
T &);
515 template <
typename U>
static char test(SameType<Signature_size, &U::size> *);
517 template <
typename U>
static double test(...);
519 static bool const value = (
sizeof(test<DocumentListTraits<T>>(
nullptr)) == 1);
522template <
class T>
struct has_PolymorphicTraits {
523 using Signature_getKind =
NodeKind (*)(
const T &);
525 template <
typename U>
526 static char test(SameType<Signature_getKind, &U::getKind> *);
528 template <
typename U>
static double test(...);
530 static bool const value = (
sizeof(test<PolymorphicTraits<T>>(
nullptr)) == 1);
533inline bool isNumeric(StringRef S) {
534 const auto skipDigits = [](StringRef Input) {
535 return Input.ltrim(
"0123456789");
540 if (S.empty() || S ==
"+" || S ==
"-")
543 if (S ==
".nan" || S ==
".NaN" || S ==
".NAN")
547 StringRef
Tail = (S.front() ==
'-' || S.front() ==
'+') ? S.drop_front() : S;
557 if (S.starts_with(
"0o"))
558 return S.size() > 2 &&
561 if (S.starts_with(
"0x"))
562 return S.size() > 2 && S.drop_front(2).find_first_not_of(
571 if (S.starts_with(
".") &&
573 (S.size() > 1 && std::strchr(
"0123456789", S[1]) ==
nullptr)))
576 if (S.starts_with(
"E") || S.starts_with(
"e"))
592 if (S.front() ==
'.') {
595 }
else if (S.front() ==
'e' || S.front() ==
'E') {
596 State = FoundExponent;
602 if (State == FoundDot) {
607 if (S.front() ==
'e' || S.front() ==
'E') {
608 State = FoundExponent;
615 assert(State == FoundExponent &&
"Should have found exponent at this point.");
619 if (S.front() ==
'+' || S.front() ==
'-') {
625 return skipDigits(S).empty();
628inline bool isNull(StringRef S) {
629 return S ==
"null" || S ==
"Null" || S ==
"NULL" || S ==
"~";
632inline bool isBool(StringRef S) {
634 return S ==
"true" || S ==
"True" || S ==
"TRUE" || S ==
"false" ||
635 S ==
"False" || S ==
"FALSE";
647inline QuotingType needsQuotes(StringRef S,
bool ForcePreserveAsString =
true) {
649 return QuotingType::Single;
651 QuotingType MaxQuotingNeeded = QuotingType::None;
652 if (isSpace(
static_cast<unsigned char>(S.front())) ||
653 isSpace(
static_cast<unsigned char>(S.back())))
654 MaxQuotingNeeded = QuotingType::Single;
655 if (ForcePreserveAsString) {
657 MaxQuotingNeeded = QuotingType::Single;
659 MaxQuotingNeeded = QuotingType::Single;
661 MaxQuotingNeeded = QuotingType::Single;
667 if (std::strchr(R
"(-?:\,[]{}#&*!|>'"%@`)", S[0]) != nullptr)
668 MaxQuotingNeeded = QuotingType::Single;
670 for (
unsigned char C : S) {
691 return QuotingType::Double;
694 return QuotingType::Double;
705 return QuotingType::Double;
709 return QuotingType::Double;
712 MaxQuotingNeeded = QuotingType::Single;
717 return MaxQuotingNeeded;
720template <
typename T,
typename Context>
722 :
public std::integral_constant<bool,
723 !has_ScalarEnumerationTraits<T>::value &&
724 !has_ScalarBitSetTraits<T>::value &&
725 !has_ScalarTraits<T>::value &&
726 !has_BlockScalarTraits<T>::value &&
727 !has_TaggedScalarTraits<T>::value &&
728 !has_MappingTraits<T, Context>::value &&
729 !has_SequenceTraits<T>::value &&
730 !has_CustomMappingTraits<T>::value &&
731 !has_DocumentListTraits<T>::value &&
732 !has_PolymorphicTraits<T>::value> {};
734template <
typename T,
typename Context>
735struct validatedMappingTraits
736 :
public std::integral_constant<
737 bool, has_MappingTraits<T, Context>::value &&
738 has_MappingValidateTraits<T, Context>::value> {};
740template <
typename T,
typename Context>
741struct unvalidatedMappingTraits
742 :
public std::integral_constant<
743 bool, has_MappingTraits<T, Context>::value &&
744 !has_MappingValidateTraits<T, Context>::value> {};
749 IO(
void *Ctxt =
nullptr);
752 virtual bool outputting()
const = 0;
754 virtual unsigned beginSequence() = 0;
755 virtual bool preflightElement(
unsigned,
void *&) = 0;
756 virtual void postflightElement(
void *) = 0;
757 virtual void endSequence() = 0;
758 virtual bool canElideEmptySequence() = 0;
760 virtual unsigned beginFlowSequence() = 0;
761 virtual bool preflightFlowElement(
unsigned,
void *&) = 0;
762 virtual void postflightFlowElement(
void *) = 0;
763 virtual void endFlowSequence() = 0;
765 virtual bool mapTag(StringRef Tag,
bool Default =
false) = 0;
766 virtual void beginMapping() = 0;
767 virtual void endMapping() = 0;
768 virtual bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&) = 0;
769 virtual void postflightKey(
void *) = 0;
770 virtual std::vector<StringRef> keys() = 0;
772 virtual void beginFlowMapping() = 0;
773 virtual void endFlowMapping() = 0;
775 virtual void beginEnumScalar() = 0;
776 virtual bool matchEnumScalar(
const char *,
bool) = 0;
777 virtual bool matchEnumFallback() = 0;
778 virtual void endEnumScalar() = 0;
780 virtual bool beginBitSetScalar(
bool &) = 0;
781 virtual bool bitSetMatch(
const char *,
bool) = 0;
782 virtual void endBitSetScalar() = 0;
784 virtual void scalarString(StringRef &, QuotingType) = 0;
785 virtual void blockScalarString(StringRef &) = 0;
786 virtual void scalarTag(std::string &) = 0;
790 virtual void setError(
const Twine &) = 0;
791 virtual std::error_code
error() = 0;
792 virtual void setAllowUnknownKeys(
bool Allow);
794 template <
typename T>
795 void enumCase(
T &Val,
const char *Str,
const T ConstVal) {
796 if (matchEnumScalar(Str, outputting() && Val == ConstVal)) {
802 template <
typename T>
803 void enumCase(
T &Val,
const char *Str,
const uint32_t ConstVal) {
804 if (matchEnumScalar(Str, outputting() && Val ==
static_cast<T>(ConstVal))) {
809 template <
typename FBT,
typename T>
void enumFallback(
T &Val) {
810 if (matchEnumFallback()) {
813 FBT Res =
static_cast<typename FBT::BaseType
>(Val);
814 yamlize(*
this, Res,
true, Context);
815 Val =
static_cast<T>(
static_cast<typename FBT::BaseType
>(Res));
819 template <
typename T>
820 void bitSetCase(
T &Val,
const char *Str,
const T ConstVal) {
821 if (bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal)) {
822 Val =
static_cast<T>(Val | ConstVal);
827 template <
typename T>
828 void bitSetCase(
T &Val,
const char *Str,
const uint32_t ConstVal) {
829 if (bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal)) {
830 Val =
static_cast<T>(Val | ConstVal);
834 template <
typename T>
835 void maskedBitSetCase(
T &Val,
const char *Str,
T ConstVal,
T Mask) {
836 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
837 Val = Val | ConstVal;
840 template <
typename T>
841 void maskedBitSetCase(
T &Val,
const char *Str,
uint32_t ConstVal,
843 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
844 Val = Val | ConstVal;
847 void *getContext()
const;
848 void setContext(
void *);
850 template <
typename T>
void mapRequired(
const char *Key,
T &Val) {
852 this->processKey(Key, Val,
true, Ctx);
855 template <
typename T,
typename Context>
856 void mapRequired(
const char *Key,
T &Val, Context &Ctx) {
857 this->processKey(Key, Val,
true, Ctx);
860 template <
typename T>
void mapOptional(
const char *Key,
T &Val) {
862 mapOptionalWithContext(Key, Val, Ctx);
865 template <
typename T,
typename DefaultT>
868 mapOptionalWithContext(Key, Val,
Default, Ctx);
871 template <
typename T,
typename Context>
872 void mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
873 if constexpr (has_SequenceTraits<T>::value) {
875 if (this->canElideEmptySequence() && Val.begin() == Val.end())
878 this->processKey(Key, Val,
false, Ctx);
881 template <
typename T,
typename Context>
882 void mapOptionalWithContext(
const char *Key, std::optional<T> &Val,
884 this->processKeyWithDefault(Key, Val, std::optional<T>(),
888 template <
typename T,
typename Context,
typename DefaultT>
889 void mapOptionalWithContext(
const char *Key,
T &Val,
const DefaultT &
Default,
891 static_assert(std::is_convertible<DefaultT, T>::value,
892 "Default type must be implicitly convertible to value type!");
893 this->processKeyWithDefault(Key, Val,
static_cast<const T &
>(
Default),
898 template <
typename T,
typename Context>
899 void processKeyWithDefault(
const char *Key, std::optional<T> &Val,
900 const std::optional<T> &DefaultValue,
901 bool Required, Context &Ctx);
903 template <
typename T,
typename Context>
904 void processKeyWithDefault(
const char *Key,
T &Val,
const T &DefaultValue,
905 bool Required, Context &Ctx) {
908 const bool sameAsDefault = outputting() && Val == DefaultValue;
909 if (this->preflightKey(Key, Required, sameAsDefault, UseDefault,
911 yamlize(*
this, Val, Required, Ctx);
912 this->postflightKey(SaveInfo);
919 template <
typename T,
typename Context>
920 void processKey(
const char *Key,
T &Val,
bool Required, Context &Ctx) {
923 if (this->preflightKey(Key, Required,
false, UseDefault, SaveInfo)) {
924 yamlize(*
this, Val, Required, Ctx);
925 this->postflightKey(SaveInfo);
935template <
typename T,
typename Context>
936void doMapping(IO &io,
T &Val, Context &Ctx) {
937 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
940template <
typename T>
void doMapping(IO &io,
T &Val, EmptyContext &Ctx) {
941 MappingTraits<T>::mapping(io, Val);
947std::enable_if_t<has_ScalarEnumerationTraits<T>::value,
void>
948yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
949 io.beginEnumScalar();
950 ScalarEnumerationTraits<T>::enumeration(io, Val);
955std::enable_if_t<has_ScalarBitSetTraits<T>::value,
void>
956yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
958 if (io.beginBitSetScalar(DoClear)) {
961 ScalarBitSetTraits<T>::bitset(io, Val);
962 io.endBitSetScalar();
967std::enable_if_t<has_ScalarTraits<T>::value,
void> yamlize(IO &io,
T &Val,
bool,
969 if (io.outputting()) {
970 SmallString<128> Storage;
971 raw_svector_ostream Buffer(Storage);
972 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
973 StringRef Str = Buffer.str();
974 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
977 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
978 StringRef
Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
980 io.setError(Twine(Result));
986std::enable_if_t<has_BlockScalarTraits<T>::value,
void>
987yamlize(IO &
YamlIO,
T &Val,
bool, EmptyContext &Ctx) {
988 if (
YamlIO.outputting()) {
990 raw_string_ostream Buffer(Storage);
991 BlockScalarTraits<T>::output(Val,
YamlIO.getContext(), Buffer);
992 StringRef Str(Storage);
993 YamlIO.blockScalarString(Str);
996 YamlIO.blockScalarString(Str);
998 BlockScalarTraits<T>::input(Str,
YamlIO.getContext(), Val);
1000 YamlIO.setError(Twine(Result));
1004template <
typename T>
1005std::enable_if_t<has_TaggedScalarTraits<T>::value,
void>
1006yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1007 if (io.outputting()) {
1008 std::string ScalarStorage, TagStorage;
1009 raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage);
1010 TaggedScalarTraits<T>::output(Val, io.getContext(), ScalarBuffer,
1012 io.scalarTag(TagStorage);
1013 StringRef ScalarStr(ScalarStorage);
1014 io.scalarString(ScalarStr,
1015 TaggedScalarTraits<T>::mustQuote(Val, ScalarStr));
1020 io.scalarString(Str, QuotingType::None);
1022 TaggedScalarTraits<T>::input(Str,
Tag, io.getContext(), Val);
1024 io.setError(Twine(Result));
1031template <
typename T,
typename Context>
1032std::string doValidate(IO &io,
T &Val, Context &Ctx) {
1033 return MappingContextTraits<T, Context>::validate(io, Val, Ctx);
1036template <
typename T> std::string doValidate(IO &io,
T &Val, EmptyContext &) {
1037 return MappingTraits<T>::validate(io, Val);
1042template <
typename T,
typename Context>
1043std::enable_if_t<validatedMappingTraits<T, Context>::value,
void>
1044yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1045 if (has_FlowTraits<MappingTraits<T>>
::value)
1046 io.beginFlowMapping();
1049 if (io.outputting()) {
1050 std::string Err = detail::doValidate(io, Val, Ctx);
1052 errs() << Err <<
"\n";
1053 assert(Err.empty() &&
"invalid struct trying to be written as yaml");
1056 detail::doMapping(io, Val, Ctx);
1057 if (!io.outputting()) {
1058 std::string Err = detail::doValidate(io, Val, Ctx);
1062 if (has_FlowTraits<MappingTraits<T>>
::value)
1063 io.endFlowMapping();
1068template <
typename T,
typename Context>
1069bool yamlizeMappingEnumInput(IO &io,
T &Val) {
1070 if constexpr (has_MappingEnumInputTraits<T, Context>::value) {
1071 if (io.outputting())
1074 io.beginEnumScalar();
1075 MappingTraits<T>::enumInput(io, Val);
1076 bool Matched = !io.matchEnumFallback();
1083template <
typename T,
typename Context>
1084std::enable_if_t<unvalidatedMappingTraits<T, Context>::value,
void>
1085yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1086 if (yamlizeMappingEnumInput<T, Context>(io, Val))
1088 if (has_FlowTraits<MappingTraits<T>>
::value) {
1089 io.beginFlowMapping();
1090 detail::doMapping(io, Val, Ctx);
1091 io.endFlowMapping();
1094 detail::doMapping(io, Val, Ctx);
1099template <
typename T>
1100std::enable_if_t<has_CustomMappingTraits<T>::value,
void>
1101yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1102 if (io.outputting()) {
1104 CustomMappingTraits<T>::output(io, Val);
1108 for (StringRef key : io.keys())
1109 CustomMappingTraits<T>::inputOne(io, key, Val);
1114template <
typename T>
1115std::enable_if_t<has_PolymorphicTraits<T>::value,
void>
1116yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1117 switch (io.outputting() ? PolymorphicTraits<T>::getKind(Val)
1118 : io.getNodeKind()) {
1119 case NodeKind::Scalar:
1120 return yamlize(io, PolymorphicTraits<T>::getAsScalar(Val),
true, Ctx);
1122 return yamlize(io, PolymorphicTraits<T>::getAsMap(Val),
true, Ctx);
1123 case NodeKind::Sequence:
1124 return yamlize(io, PolymorphicTraits<T>::getAsSequence(Val),
true, Ctx);
1128template <
typename T>
1129std::enable_if_t<missingTraits<T, EmptyContext>::value,
void>
1130yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1131 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1134template <
typename T,
typename Context>
1135std::enable_if_t<has_SequenceTraits<T>::value,
void>
1136yamlize(IO &io,
T &Seq,
bool, Context &Ctx) {
1137 if (has_FlowTraits<SequenceTraits<T>>
::value) {
1138 unsigned incnt = io.beginFlowSequence();
1139 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1140 for (
unsigned i = 0; i <
count; ++i) {
1142 if (io.preflightFlowElement(i, SaveInfo)) {
1143 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1144 io.postflightFlowElement(SaveInfo);
1147 io.endFlowSequence();
1149 unsigned incnt = io.beginSequence();
1150 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1151 for (
unsigned i = 0; i <
count; ++i) {
1153 if (io.preflightElement(i, SaveInfo)) {
1154 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1155 io.postflightElement(SaveInfo);
1162template <>
struct ScalarTraits<
bool> {
1163 LLVM_ABI static void output(
const bool &,
void *, raw_ostream &);
1164 LLVM_ABI static StringRef input(StringRef,
void *,
bool &);
1165 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1168template <>
struct ScalarTraits<StringRef> {
1169 LLVM_ABI static void output(
const StringRef &,
void *, raw_ostream &);
1170 LLVM_ABI static StringRef input(StringRef,
void *, StringRef &);
1171 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1174template <>
struct ScalarTraits<
std::
string> {
1175 LLVM_ABI static void output(
const std::string &,
void *, raw_ostream &);
1176 LLVM_ABI static StringRef input(StringRef,
void *, std::string &);
1177 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1180template <>
struct ScalarTraits<
uint8_t> {
1183 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1186template <>
struct ScalarTraits<
uint16_t> {
1189 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1192template <>
struct ScalarTraits<
uint32_t> {
1195 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1198template <>
struct ScalarTraits<
uint64_t> {
1201 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1204template <>
struct ScalarTraits<int8_t> {
1205 LLVM_ABI static void output(
const int8_t &,
void *, raw_ostream &);
1206 LLVM_ABI static StringRef input(StringRef,
void *, int8_t &);
1207 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1210template <>
struct ScalarTraits<int16_t> {
1211 LLVM_ABI static void output(
const int16_t &,
void *, raw_ostream &);
1212 LLVM_ABI static StringRef input(StringRef,
void *, int16_t &);
1213 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1216template <>
struct ScalarTraits<int32_t> {
1217 LLVM_ABI static void output(
const int32_t &,
void *, raw_ostream &);
1218 LLVM_ABI static StringRef input(StringRef,
void *, int32_t &);
1219 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1222template <>
struct ScalarTraits<int64_t> {
1223 LLVM_ABI static void output(
const int64_t &,
void *, raw_ostream &);
1224 LLVM_ABI static StringRef input(StringRef,
void *, int64_t &);
1225 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1228template <>
struct ScalarTraits<float> {
1229 LLVM_ABI static void output(
const float &,
void *, raw_ostream &);
1230 LLVM_ABI static StringRef input(StringRef,
void *,
float &);
1231 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1234template <>
struct ScalarTraits<double> {
1235 LLVM_ABI static void output(
const double &,
void *, raw_ostream &);
1236 LLVM_ABI static StringRef input(StringRef,
void *,
double &);
1237 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1243template <
typename value_type, llvm::endianness endian,
size_t alignment>
1244struct ScalarTraits<support::detail::packed_endian_specific_integral<
1245 value_type, endian, alignment>,
1246 std::enable_if_t<has_ScalarTraits<value_type>::value>> {
1248 support::detail::packed_endian_specific_integral<value_type,
endian,
1251 static void output(
const endian_type &
E,
void *Ctx, raw_ostream &Stream) {
1252 ScalarTraits<value_type>::output(
static_cast<value_type
>(
E), Ctx, Stream);
1255 static StringRef input(StringRef Str,
void *Ctx, endian_type &
E) {
1257 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1258 E =
static_cast<endian_type
>(
V);
1262 static QuotingType mustQuote(StringRef Str) {
1263 return ScalarTraits<value_type>::mustQuote(Str);
1267template <
typename value_type, llvm::endianness endian,
size_t alignment>
1268struct ScalarEnumerationTraits<
1269 support::detail::packed_endian_specific_integral<value_type, endian,
1271 std::enable_if_t<has_ScalarEnumerationTraits<value_type>::value>> {
1273 support::detail::packed_endian_specific_integral<value_type,
endian,
1276 static void enumeration(IO &io, endian_type &
E) {
1278 ScalarEnumerationTraits<value_type>::enumeration(io, V);
1283template <
typename value_type, llvm::endianness endian,
size_t alignment>
1284struct ScalarBitSetTraits<
1285 support::detail::packed_endian_specific_integral<value_type, endian,
1287 std::enable_if_t<has_ScalarBitSetTraits<value_type>::value>> {
1289 support::detail::packed_endian_specific_integral<value_type,
endian,
1291 static void bitset(IO &io, endian_type &
E) {
1293 ScalarBitSetTraits<value_type>::bitset(io, V);
1300template <
typename TNorm,
typename TFinal>
struct MappingNormalization {
1301 MappingNormalization(IO &i_o, TFinal &Obj)
1302 : io(i_o), BufPtr(nullptr),
Result(Obj) {
1303 if (io.outputting()) {
1304 BufPtr =
new (&Buffer) TNorm(io, Obj);
1306 BufPtr =
new (&Buffer) TNorm(io);
1310 ~MappingNormalization() {
1311 if (!io.outputting()) {
1312 Result = BufPtr->denormalize(io);
1317 TNorm *operator->() {
return BufPtr; }
1320 using Storage = AlignedCharArrayUnion<TNorm>;
1330template <
typename TNorm,
typename TFinal>
struct MappingNormalizationHeap {
1331 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *
allocator)
1333 if (io.outputting()) {
1334 BufPtr =
new (&Buffer) TNorm(io, Obj);
1337 new (BufPtr) TNorm(io);
1339 BufPtr =
new TNorm(io);
1343 ~MappingNormalizationHeap() {
1344 if (io.outputting()) {
1347 Result = BufPtr->denormalize(io);
1351 TNorm *operator->() {
return BufPtr; }
1354 using Storage = AlignedCharArrayUnion<TNorm>;
1358 TNorm *BufPtr =
nullptr;
1379 Input(StringRef InputContent,
void *Ctxt =
nullptr,
1381 void *DiagHandlerCtxt =
nullptr);
1382 Input(MemoryBufferRef Input,
void *Ctxt =
nullptr,
1384 void *DiagHandlerCtxt =
nullptr);
1388 std::error_code
error()
override;
1391 bool outputting()
const override;
1392 bool mapTag(StringRef,
bool)
override;
1393 void beginMapping()
override;
1394 void endMapping()
override;
1395 bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&)
override;
1396 void postflightKey(
void *)
override;
1397 std::vector<StringRef> keys()
override;
1398 void beginFlowMapping()
override;
1399 void endFlowMapping()
override;
1400 unsigned beginSequence()
override;
1401 void endSequence()
override;
1402 bool preflightElement(
unsigned index,
void *&)
override;
1403 void postflightElement(
void *)
override;
1404 unsigned beginFlowSequence()
override;
1405 bool preflightFlowElement(
unsigned,
void *&)
override;
1406 void postflightFlowElement(
void *)
override;
1407 void endFlowSequence()
override;
1408 void beginEnumScalar()
override;
1409 bool matchEnumScalar(
const char *,
bool)
override;
1410 bool matchEnumFallback()
override;
1411 void endEnumScalar()
override;
1412 bool beginBitSetScalar(
bool &)
override;
1413 bool bitSetMatch(
const char *,
bool)
override;
1414 void endBitSetScalar()
override;
1415 void scalarString(StringRef &, QuotingType)
override;
1416 void blockScalarString(StringRef &)
override;
1417 void scalarTag(std::string &)
override;
1419 void setError(
const Twine &message)
override;
1420 bool canElideEmptySequence()
override;
1424 HNode(
Node *n) : _node(n) {}
1426 static bool classof(
const HNode *) {
return true; }
1431 class EmptyHNode :
public HNode {
1433 EmptyHNode(
Node *n) : HNode(n) {}
1435 static bool classof(
const HNode *n) {
return NullNode::classof(n->_node); }
1437 static bool classof(
const EmptyHNode *) {
return true; }
1440 class ScalarHNode :
public HNode {
1442 ScalarHNode(
Node *n, StringRef s) : HNode(n), _value(s) {}
1444 StringRef
value()
const {
return _value; }
1446 static bool classof(
const HNode *n) {
1447 return ScalarNode::classof(n->_node) ||
1448 BlockScalarNode::classof(n->_node);
1451 static bool classof(
const ScalarHNode *) {
return true; }
1457 class MapHNode :
public HNode {
1459 MapHNode(
Node *n) : HNode(n) {}
1461 static bool classof(
const HNode *n) {
1462 return MappingNode::classof(n->_node);
1465 static bool classof(
const MapHNode *) {
return true; }
1467 using NameToNodeAndLoc = StringMap<std::pair<HNode *, SMRange>>;
1469 NameToNodeAndLoc Mapping;
1470 SmallVector<std::string, 6> ValidKeys;
1473 class SequenceHNode :
public HNode {
1475 SequenceHNode(
Node *n) : HNode(n) {}
1477 static bool classof(
const HNode *n) {
1478 return SequenceNode::classof(n->_node);
1481 static bool classof(
const SequenceHNode *) {
return true; }
1483 std::vector<HNode *> Entries;
1486 Input::HNode *createHNodes(
Node *node);
1487 void setError(HNode *hnode,
const Twine &message);
1488 void setError(
Node *node,
const Twine &message);
1489 void setError(
const SMRange &
Range,
const Twine &message);
1491 void reportWarning(HNode *hnode,
const Twine &message);
1492 void reportWarning(
Node *hnode,
const Twine &message);
1493 void reportWarning(
const SMRange &
Range,
const Twine &message);
1496 void releaseHNodeBuffers();
1501 bool setCurrentDocument();
1502 bool nextDocument();
1505 const Node *getCurrentNode()
const;
1507 void setAllowUnknownKeys(
bool Allow)
override;
1511 std::unique_ptr<llvm::yaml::Stream> Strm;
1512 HNode *TopNode =
nullptr;
1515 SpecificBumpPtrAllocator<EmptyHNode> EmptyHNodeAllocator;
1516 SpecificBumpPtrAllocator<ScalarHNode> ScalarHNodeAllocator;
1517 SpecificBumpPtrAllocator<MapHNode> MapHNodeAllocator;
1518 SpecificBumpPtrAllocator<SequenceHNode> SequenceHNodeAllocator;
1519 document_iterator DocIterator;
1521 HNode *CurrentNode =
nullptr;
1522 bool ScalarMatchFound =
false;
1523 bool AllowUnknownKeys =
false;
1532 Output(raw_ostream &,
void *Ctxt =
nullptr,
int WrapColumn = 70);
1540 void setWriteDefaultValues(
bool Write) { WriteDefaultValues =
Write; }
1542 bool outputting()
const override;
1543 bool mapTag(StringRef,
bool)
override;
1544 void beginMapping()
override;
1545 void endMapping()
override;
1546 bool preflightKey(
const char *key,
bool,
bool,
bool &,
void *&)
override;
1547 void postflightKey(
void *)
override;
1548 std::vector<StringRef> keys()
override;
1549 void beginFlowMapping()
override;
1550 void endFlowMapping()
override;
1551 unsigned beginSequence()
override;
1552 void endSequence()
override;
1553 bool preflightElement(
unsigned,
void *&)
override;
1554 void postflightElement(
void *)
override;
1555 unsigned beginFlowSequence()
override;
1556 bool preflightFlowElement(
unsigned,
void *&)
override;
1557 void postflightFlowElement(
void *)
override;
1558 void endFlowSequence()
override;
1559 void beginEnumScalar()
override;
1560 bool matchEnumScalar(
const char *,
bool)
override;
1561 bool matchEnumFallback()
override;
1562 void endEnumScalar()
override;
1563 bool beginBitSetScalar(
bool &)
override;
1564 bool bitSetMatch(
const char *,
bool)
override;
1565 void endBitSetScalar()
override;
1566 void scalarString(StringRef &, QuotingType)
override;
1567 void blockScalarString(StringRef &)
override;
1568 void scalarTag(std::string &)
override;
1570 void setError(
const Twine &message)
override;
1571 std::error_code
error()
override;
1572 bool canElideEmptySequence()
override;
1576 void beginDocuments();
1577 bool preflightDocument(
unsigned);
1578 void postflightDocument();
1579 void endDocuments();
1582 void output(StringRef s);
1583 void output(StringRef, QuotingType);
1584 void outputUpToEndOfLine(StringRef s);
1585 void newLineCheck(
bool EmptySequence =
false);
1586 void outputNewLine();
1587 void paddedKey(StringRef key);
1588 void flowKey(StringRef Key);
1593 inFlowSeqFirstElement,
1594 inFlowSeqOtherElement,
1601 static bool inSeqAnyElement(InState State);
1602 static bool inFlowSeqAnyElement(InState State);
1603 static bool inMapAnyKey(InState State);
1604 static bool inFlowMapAnyKey(InState State);
1608 SmallVector<InState, 8> StateStack;
1610 int ColumnAtFlowStart = 0;
1611 int ColumnAtMapFlowStart = 0;
1612 bool NeedBitValueComma =
false;
1613 bool NeedFlowSequenceComma =
false;
1614 bool EnumerationMatchFound =
false;
1615 bool WriteDefaultValues =
false;
1617 StringRef PaddingBeforeContainer;
1620template <
typename T,
typename Context>
1621void IO::processKeyWithDefault(
const char *Key, std::optional<T> &Val,
1622 const std::optional<T> &DefaultValue,
1624 assert(!DefaultValue &&
"std::optional<T> shouldn't have a value!");
1626 bool UseDefault =
true;
1627 const bool sameAsDefault = outputting() && !Val;
1628 if (!outputting() && !Val)
1631 this->preflightKey(Key,
Required, sameAsDefault, UseDefault, SaveInfo)) {
1637 bool IsNone =
false;
1639 if (
const auto *
Node =
1640 dyn_cast<ScalarNode>(((Input *)
this)->getCurrentNode()))
1643 IsNone =
Node->getRawValue().rtrim(
' ') ==
"<none>";
1648 yamlize(*
this, *Val,
Required, Ctx);
1649 this->postflightKey(SaveInfo);
1664#define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1666 _type() = default; \
1667 _type(const _base v) : value(v) {} \
1668 _type(const _type &v) = default; \
1669 _type &operator=(const _type &rhs) = default; \
1670 _type &operator=(const _base &rhs) { \
1674 operator const _base &() const { return value; } \
1675 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1676 bool operator==(const _base &rhs) const { return value == rhs; } \
1677 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1679 using BaseType = _base; \
1691template <>
struct ScalarTraits<Hex8> {
1692 LLVM_ABI static void output(
const Hex8 &,
void *, raw_ostream &);
1693 LLVM_ABI static StringRef input(StringRef,
void *, Hex8 &);
1694 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1697template <>
struct ScalarTraits<Hex16> {
1698 LLVM_ABI static void output(
const Hex16 &,
void *, raw_ostream &);
1699 LLVM_ABI static StringRef input(StringRef,
void *, Hex16 &);
1700 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1703template <>
struct ScalarTraits<Hex32> {
1704 LLVM_ABI static void output(
const Hex32 &,
void *, raw_ostream &);
1705 LLVM_ABI static StringRef input(StringRef,
void *, Hex32 &);
1706 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1709template <>
struct ScalarTraits<Hex64> {
1710 LLVM_ABI static void output(
const Hex64 &,
void *, raw_ostream &);
1711 LLVM_ABI static StringRef input(StringRef,
void *, Hex64 &);
1712 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1715template <>
struct ScalarTraits<VersionTuple> {
1716 LLVM_ABI static void output(
const VersionTuple &Value,
void *,
1718 LLVM_ABI static StringRef input(StringRef,
void *, VersionTuple &);
1719 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1723template <
typename T>
1724inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
1728 while (yin.setCurrentDocument()) {
1729 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i),
true, Ctx);
1739template <
typename T>
1740inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Input &>
1743 yin.setCurrentDocument();
1744 yamlize(yin, docMap,
true, Ctx);
1750template <
typename T>
1751inline std::enable_if_t<has_SequenceTraits<T>::value, Input &>
1754 if (yin.setCurrentDocument())
1755 yamlize(yin, docSeq,
true, Ctx);
1760template <
typename T>
1761inline std::enable_if_t<has_BlockScalarTraits<T>::value, Input &>
1764 if (
In.setCurrentDocument())
1765 yamlize(In, Val,
true, Ctx);
1770template <
typename T>
1771inline std::enable_if_t<has_CustomMappingTraits<T>::value, Input &>
1774 if (
In.setCurrentDocument())
1775 yamlize(In, Val,
true, Ctx);
1780template <
typename T>
1781inline std::enable_if_t<has_PolymorphicTraits<T>::value, Input &>
1784 if (
In.setCurrentDocument())
1785 yamlize(In, Val,
true, Ctx);
1790template <
typename T>
1791inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Input &>
1793 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1798template <
typename T>
1799inline std::enable_if_t<has_DocumentListTraits<T>::value, Output &>
1802 yout.beginDocuments();
1803 const size_t count = DocumentListTraits<T>::size(yout, docList);
1804 for (
size_t i = 0; i <
count; ++i) {
1805 if (yout.preflightDocument(i)) {
1806 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i),
true,
1808 yout.postflightDocument();
1811 yout.endDocuments();
1816template <
typename T>
1817inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
1820 yout.beginDocuments();
1821 if (yout.preflightDocument(0)) {
1822 yamlize(yout, map,
true, Ctx);
1823 yout.postflightDocument();
1825 yout.endDocuments();
1830template <
typename T>
1831inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
1834 yout.beginDocuments();
1835 if (yout.preflightDocument(0)) {
1836 yamlize(yout,
seq,
true, Ctx);
1837 yout.postflightDocument();
1839 yout.endDocuments();
1844template <
typename T>
1845inline std::enable_if_t<has_BlockScalarTraits<T>::value, Output &>
1848 Out.beginDocuments();
1849 if (Out.preflightDocument(0)) {
1850 yamlize(Out, Val,
true, Ctx);
1851 Out.postflightDocument();
1858template <
typename T>
1859inline std::enable_if_t<has_CustomMappingTraits<T>::value, Output &>
1862 Out.beginDocuments();
1863 if (Out.preflightDocument(0)) {
1864 yamlize(Out, Val,
true, Ctx);
1865 Out.postflightDocument();
1873template <
typename T>
1874inline std::enable_if_t<has_PolymorphicTraits<T>::value, Output &>
1877 Out.beginDocuments();
1878 if (Out.preflightDocument(0)) {
1881 assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar &&
1882 "plain scalar documents are not supported");
1883 yamlize(Out, Val,
true, Ctx);
1884 Out.postflightDocument();
1891template <
typename T>
1892inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Output &>
1894 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1898template <
bool B>
struct IsFlowSequenceBase {};
1899template <>
struct IsFlowSequenceBase<
true> {
1900 static const bool flow =
true;
1903template <
typename T,
typename U =
void>
1904struct IsResizable : std::false_type {};
1906template <
typename T>
1907struct IsResizable<
T,
std::void_t<decltype(std::declval<T>().resize(0))>>
1908 :
public std::true_type {};
1910template <
typename T,
bool B>
struct IsResizableBase {
1911 using type =
typename T::value_type;
1913 static type &element(IO &io,
T &seq,
size_t index) {
1914 if (index >=
seq.size())
1915 seq.resize(index + 1);
1920template <
typename T>
struct IsResizableBase<
T,
false> {
1921 using type =
typename T::value_type;
1923 static type &element(IO &io,
T &seq,
size_t index) {
1924 if (index >=
seq.size()) {
1925 io.setError(Twine(
"value sequence extends beyond static size (") +
1926 Twine(
seq.size()) +
")");
1933template <
typename T,
bool Flow>
1934struct SequenceTraitsImpl : IsFlowSequenceBase<Flow>,
1935 IsResizableBase<T, IsResizable<T>::value> {
1936 static size_t size(IO &io,
T &seq) {
return seq.size(); }
1941template <
bool>
struct CheckIsBool {
1942 static const bool value =
true;
1947template <
typename T>
1948struct SequenceTraits<
1950 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1951 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
1952template <
typename T,
size_t N>
1953struct SequenceTraits<
1955 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1956 : SequenceTraitsImpl<std::array<T, N>, SequenceElementTraits<T>::flow> {};
1957template <
typename T,
unsigned N>
1958struct SequenceTraits<
1960 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1961 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
1962template <
typename T>
1963struct SequenceTraits<
1965 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1966 : SequenceTraitsImpl<SmallVectorImpl<T>, SequenceElementTraits<T>::flow> {};
1967template <
typename T>
1968struct SequenceTraits<
1970 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1971 : SequenceTraitsImpl<MutableArrayRef<T>, SequenceElementTraits<T>::flow> {};
1974template <
typename T>
1975struct SequenceElementTraits<
T,
std::enable_if_t<std::is_fundamental_v<T>>> {
1976 static const bool flow =
true;
1980template <>
struct SequenceElementTraits<
std::
string> {
1981 static const bool flow =
false;
1983template <>
struct SequenceElementTraits<StringRef> {
1984 static const bool flow =
false;
1986template <>
struct SequenceElementTraits<
std::pair<std::string, std::string>> {
1987 static const bool flow =
false;
1991template <
typename T>
struct StdMapStringCustomMappingTraitsImpl {
1992 using map_type = std::map<std::string, T>;
1994 static void inputOne(IO &io, StringRef key, map_type &v) {
1995 io.mapRequired(key.str().c_str(), v[std::string(key)]);
1998 static void output(IO &io, map_type &v) {
2000 io.mapRequired(
p.first.c_str(),
p.second);
2007#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW) \
2011 !std::is_fundamental_v<TYPE> && !std::is_same_v<TYPE, std::string> && \
2012 !std::is_same_v<TYPE, llvm::StringRef>, \
2013 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
2014 template <> struct SequenceElementTraits<TYPE> { \
2015 static const bool flow = FLOW; \
2022#define LLVM_YAML_IS_SEQUENCE_VECTOR(type) \
2023 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)
2027#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type) \
2028 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)
2030#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type) \
2033 template <> struct LLVM_ABI MappingTraits<Type> { \
2034 static void mapping(IO &IO, Type &Obj); \
2039#define LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(Type) \
2042 template <> struct MappingTraits<Type> { \
2043 static void mapping(IO &IO, Type &Obj); \
2048#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type) \
2051 template <> struct LLVM_ABI ScalarEnumerationTraits<Type> { \
2052 static void enumeration(IO &io, Type &Value); \
2057#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type) \
2060 template <> struct LLVM_ABI ScalarBitSetTraits<Type> { \
2061 static void bitset(IO &IO, Type &Options); \
2066#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote) \
2069 template <> struct LLVM_ABI ScalarTraits<Type> { \
2070 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
2071 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
2072 static QuotingType mustQuote(StringRef) { return MustQuote; } \
2079#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
2082 template <unsigned N> \
2083 struct DocumentListTraits<SmallVector<_type, N>> \
2084 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
2086 struct DocumentListTraits<std::vector<_type>> \
2087 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
2093#define LLVM_YAML_IS_STRING_MAP(_type) \
2097 struct CustomMappingTraits<std::map<std::string, _type>> \
2098 : public StdMapStringCustomMappingTraitsImpl<_type> {}; \
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file defines the BumpPtrAllocator interface.
This file implements the BitVector class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Given that RA is a live value
static void mapOptional(yaml::IO &IO, const char *Key, EndianType &Val, typename EndianType::value_type Default)
Perform an optional yaml-mapping of an endian-aware type EndianType.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallVector class.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type)
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
static constexpr size_t npos
This class implements an extremely fast bulk output stream that can only output to a stream.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ C
The default llvm calling convention, compatible with C.
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
ScaledNumber< DigitsT > operator>>(const ScaledNumber< DigitsT > &L, int16_t Shift)
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
@ Default
The result values are uniform if and only if all operands are uniform.
Implement std::hash so that hash_code can be used in STL containers.
Determine the kind of a node from its type.