9#ifndef LLVM_SUPPORT_YAMLTRAITS_H
10#define LLVM_SUPPORT_YAMLTRAITS_H
33#include <system_error>
49struct EmptyContext {};
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 {
180struct BlockScalarTraits {
216template <
typename T>
struct TaggedScalarTraits {
246template<
typename T,
typename EnableIf =
void>
247struct SequenceTraits {
259template<
typename T,
typename EnableIf =
void>
260struct SequenceElementTraits {
268struct DocumentListTraits {
278struct CustomMappingTraits {
300template <
typename T>
struct PolymorphicTraits {
314struct has_ScalarEnumerationTraits
316 using Signature_enumeration = void (*)(
class IO&,
T&);
318 template <
typename U>
319 static char test(SameType<Signature_enumeration, &U::enumeration>*);
321 template <
typename U>
322 static double test(...);
324 static bool const value =
325 (
sizeof(test<ScalarEnumerationTraits<T>>(
nullptr)) == 1);
330struct has_ScalarBitSetTraits
332 using Signature_bitset = void (*)(
class IO&,
T&);
334 template <
typename U>
335 static char test(SameType<Signature_bitset, &U::bitset>*);
337 template <
typename U>
338 static double test(...);
340 static bool const value = (
sizeof(test<ScalarBitSetTraits<T>>(
nullptr)) == 1);
345struct has_ScalarTraits
347 using Signature_input = StringRef (*)(StringRef,
void*,
T&);
348 using Signature_output = void (*)(
const T&,
void*, raw_ostream&);
349 using Signature_mustQuote = QuotingType (*)(StringRef);
351 template <
typename U>
352 static char test(SameType<Signature_input, &U::input> *,
353 SameType<Signature_output, &U::output> *,
354 SameType<Signature_mustQuote, &U::mustQuote> *);
356 template <
typename U>
357 static double test(...);
359 static bool const value =
360 (
sizeof(test<ScalarTraits<T>>(
nullptr,
nullptr,
nullptr)) == 1);
365struct has_BlockScalarTraits
367 using Signature_input = StringRef (*)(StringRef,
void *,
T &);
368 using Signature_output = void (*)(
const T &,
void *, raw_ostream &);
370 template <
typename U>
371 static char test(SameType<Signature_input, &U::input> *,
372 SameType<Signature_output, &U::output> *);
374 template <
typename U>
375 static double test(...);
377 static bool const value =
378 (
sizeof(test<BlockScalarTraits<T>>(
nullptr,
nullptr)) == 1);
382template <
class T>
struct has_TaggedScalarTraits {
383 using Signature_input = StringRef (*)(StringRef, StringRef,
void *,
T &);
384 using Signature_output = void (*)(
const T &,
void *, raw_ostream &,
386 using Signature_mustQuote = QuotingType (*)(
const T &, StringRef);
388 template <
typename U>
389 static char test(SameType<Signature_input, &U::input> *,
390 SameType<Signature_output, &U::output> *,
391 SameType<Signature_mustQuote, &U::mustQuote> *);
393 template <
typename U>
static double test(...);
395 static bool const value =
396 (
sizeof(test<TaggedScalarTraits<T>>(
nullptr,
nullptr,
nullptr)) == 1);
400template <
class T,
class Context>
struct has_MappingTraits {
401 using Signature_mapping = void (*)(
class IO &,
T &, Context &);
403 template <
typename U>
404 static char test(SameType<Signature_mapping, &U::mapping>*);
406 template <
typename U>
407 static double test(...);
409 static bool const value =
410 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
414template <
class T>
struct has_MappingTraits<
T, EmptyContext> {
415 using Signature_mapping = void (*)(
class IO &,
T &);
417 template <
typename U>
418 static char test(SameType<Signature_mapping, &U::mapping> *);
420 template <
typename U>
static double test(...);
422 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
426template <
class T,
class Context>
struct has_MappingValidateTraits {
427 using Signature_validate = std::string (*)(
class IO &,
T &, Context &);
429 template <
typename U>
430 static char test(SameType<Signature_validate, &U::validate>*);
432 template <
typename U>
433 static double test(...);
435 static bool const value =
436 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
440template <
class T>
struct has_MappingValidateTraits<
T, EmptyContext> {
441 using Signature_validate = std::string (*)(
class IO &,
T &);
443 template <
typename U>
444 static char test(SameType<Signature_validate, &U::validate> *);
446 template <
typename U>
static double test(...);
448 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
452template <
class T,
class Context>
struct has_MappingEnumInputTraits {
453 using Signature_validate = void (*)(
class IO &,
T &);
455 template <
typename U>
456 static char test(SameType<Signature_validate, &U::enumInput> *);
458 template <
typename U>
static double test(...);
460 static bool const value =
461 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
465template <
class T>
struct has_MappingEnumInputTraits<
T, EmptyContext> {
466 using Signature_validate = void (*)(
class IO &,
T &);
468 template <
typename U>
469 static char test(SameType<Signature_validate, &U::enumInput> *);
471 template <
typename U>
static double test(...);
473 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
478struct has_SequenceMethodTraits
480 using Signature_size = size_t (*)(
class IO&,
T&);
482 template <
typename U>
483 static char test(SameType<Signature_size, &U::size>*);
485 template <
typename U>
486 static double test(...);
488 static bool const value = (
sizeof(test<SequenceTraits<T>>(
nullptr)) == 1);
493struct has_CustomMappingTraits
495 using Signature_input = void (*)(IO &io, StringRef key,
T &
v);
497 template <
typename U>
498 static char test(SameType<Signature_input, &U::inputOne>*);
500 template <
typename U>
501 static double test(...);
503 static bool const value =
504 (
sizeof(test<CustomMappingTraits<T>>(
nullptr)) == 1);
510template <
typename T,
bool Enabled = std::is_
class_v<T>>
class has_FlowTraits {
512 static const bool value =
false;
519struct has_FlowTraits<
T,
true>
525 static char (&
f(SameType<bool Fallback::*, &C::flow>*))[1];
528 static char (&
f(...))[2];
530 static bool const value =
sizeof(f<Derived>(
nullptr)) == 2;
535struct has_SequenceTraits :
public std::integral_constant<bool,
536 has_SequenceMethodTraits<T>::value > { };
540struct has_DocumentListTraits
542 using Signature_size = size_t (*)(
class IO &,
T &);
544 template <
typename U>
545 static char test(SameType<Signature_size, &U::size>*);
547 template <
typename U>
548 static double test(...);
550 static bool const value = (
sizeof(test<DocumentListTraits<T>>(
nullptr))==1);
553template <
class T>
struct has_PolymorphicTraits {
554 using Signature_getKind =
NodeKind (*)(
const T &);
556 template <
typename U>
557 static char test(SameType<Signature_getKind, &U::getKind> *);
559 template <
typename U>
static double test(...);
561 static bool const value = (
sizeof(test<PolymorphicTraits<T>>(
nullptr)) == 1);
564inline bool isNumeric(StringRef S) {
565 const auto skipDigits = [](StringRef Input) {
566 return Input.ltrim(
"0123456789");
571 if (S.empty() || S ==
"+" || S ==
"-")
574 if (S ==
".nan" || S ==
".NaN" || S ==
".NAN")
578 StringRef
Tail = (S.front() ==
'-' || S.front() ==
'+') ? S.drop_front() : S;
588 if (S.starts_with(
"0o"))
589 return S.size() > 2 &&
592 if (S.starts_with(
"0x"))
593 return S.size() > 2 && S.drop_front(2).find_first_not_of(
602 if (S.starts_with(
".") &&
604 (S.size() > 1 && std::strchr(
"0123456789", S[1]) ==
nullptr)))
607 if (S.starts_with(
"E") || S.starts_with(
"e"))
623 if (S.front() ==
'.') {
626 }
else if (S.front() ==
'e' || S.front() ==
'E') {
627 State = FoundExponent;
633 if (State == FoundDot) {
638 if (S.front() ==
'e' || S.front() ==
'E') {
639 State = FoundExponent;
646 assert(State == FoundExponent &&
"Should have found exponent at this point.");
650 if (S.front() ==
'+' || S.front() ==
'-') {
656 return skipDigits(S).empty();
659inline bool isNull(StringRef S) {
660 return S ==
"null" || S ==
"Null" || S ==
"NULL" || S ==
"~";
663inline bool isBool(StringRef S) {
665 return S ==
"true" || S ==
"True" || S ==
"TRUE" || S ==
"false" ||
666 S ==
"False" || S ==
"FALSE";
678inline QuotingType needsQuotes(StringRef S,
bool ForcePreserveAsString =
true) {
680 return QuotingType::Single;
682 QuotingType MaxQuotingNeeded = QuotingType::None;
683 if (isSpace(
static_cast<unsigned char>(S.front())) ||
684 isSpace(
static_cast<unsigned char>(S.back())))
685 MaxQuotingNeeded = QuotingType::Single;
686 if (ForcePreserveAsString) {
688 MaxQuotingNeeded = QuotingType::Single;
690 MaxQuotingNeeded = QuotingType::Single;
692 MaxQuotingNeeded = QuotingType::Single;
698 if (std::strchr(R
"(-?:\,[]{}#&*!|>'"%@`)", S[0]) != nullptr)
699 MaxQuotingNeeded = QuotingType::Single;
701 for (
unsigned char C : S) {
722 return QuotingType::Double;
725 return QuotingType::Double;
736 return QuotingType::Double;
740 return QuotingType::Double;
743 MaxQuotingNeeded = QuotingType::Single;
748 return MaxQuotingNeeded;
751template <
typename T,
typename Context>
753 :
public std::integral_constant<bool,
754 !has_ScalarEnumerationTraits<T>::value &&
755 !has_ScalarBitSetTraits<T>::value &&
756 !has_ScalarTraits<T>::value &&
757 !has_BlockScalarTraits<T>::value &&
758 !has_TaggedScalarTraits<T>::value &&
759 !has_MappingTraits<T, Context>::value &&
760 !has_SequenceTraits<T>::value &&
761 !has_CustomMappingTraits<T>::value &&
762 !has_DocumentListTraits<T>::value &&
763 !has_PolymorphicTraits<T>::value> {};
765template <
typename T,
typename Context>
766struct validatedMappingTraits
767 :
public std::integral_constant<
768 bool, has_MappingTraits<T, Context>::value &&
769 has_MappingValidateTraits<T, Context>::value> {};
771template <
typename T,
typename Context>
772struct unvalidatedMappingTraits
773 :
public std::integral_constant<
774 bool, has_MappingTraits<T, Context>::value &&
775 !has_MappingValidateTraits<T, Context>::value> {};
780 IO(
void *Ctxt =
nullptr);
783 virtual bool outputting()
const = 0;
785 virtual unsigned beginSequence() = 0;
786 virtual bool preflightElement(
unsigned,
void *&) = 0;
787 virtual void postflightElement(
void*) = 0;
788 virtual void endSequence() = 0;
789 virtual bool canElideEmptySequence() = 0;
791 virtual unsigned beginFlowSequence() = 0;
792 virtual bool preflightFlowElement(
unsigned,
void *&) = 0;
793 virtual void postflightFlowElement(
void*) = 0;
794 virtual void endFlowSequence() = 0;
796 virtual bool mapTag(StringRef Tag,
bool Default=
false) = 0;
797 virtual void beginMapping() = 0;
798 virtual void endMapping() = 0;
799 virtual bool preflightKey(
const char*,
bool,
bool,
bool &,
void *&) = 0;
800 virtual void postflightKey(
void*) = 0;
801 virtual std::vector<StringRef> keys() = 0;
803 virtual void beginFlowMapping() = 0;
804 virtual void endFlowMapping() = 0;
806 virtual void beginEnumScalar() = 0;
807 virtual bool matchEnumScalar(
const char*,
bool) = 0;
808 virtual bool matchEnumFallback() = 0;
809 virtual void endEnumScalar() = 0;
811 virtual bool beginBitSetScalar(
bool &) = 0;
812 virtual bool bitSetMatch(
const char*,
bool) = 0;
813 virtual void endBitSetScalar() = 0;
815 virtual void scalarString(StringRef &, QuotingType) = 0;
816 virtual void blockScalarString(StringRef &) = 0;
817 virtual void scalarTag(std::string &) = 0;
821 virtual void setError(
const Twine &) = 0;
822 virtual void setAllowUnknownKeys(
bool Allow);
824 template <
typename T>
825 void enumCase(
T &Val,
const char* Str,
const T ConstVal) {
826 if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
832 template <
typename T>
833 void enumCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
834 if ( matchEnumScalar(Str, outputting() && Val ==
static_cast<T>(ConstVal)) ) {
839 template <
typename FBT,
typename T>
840 void enumFallback(
T &Val) {
841 if (matchEnumFallback()) {
842 EmptyContext Context;
844 FBT Res =
static_cast<typename FBT::BaseType
>(Val);
845 yamlize(*
this, Res,
true, Context);
846 Val =
static_cast<T>(
static_cast<typename FBT::BaseType
>(Res));
850 template <
typename T>
851 void bitSetCase(
T &Val,
const char* Str,
const T ConstVal) {
852 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
853 Val =
static_cast<T>(Val | ConstVal);
858 template <
typename T>
859 void bitSetCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
860 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
861 Val =
static_cast<T>(Val | ConstVal);
865 template <
typename T>
866 void maskedBitSetCase(
T &Val,
const char *Str,
T ConstVal,
T Mask) {
867 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
868 Val = Val | ConstVal;
871 template <
typename T>
872 void maskedBitSetCase(
T &Val,
const char *Str,
uint32_t ConstVal,
874 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
875 Val = Val | ConstVal;
878 void *getContext()
const;
879 void setContext(
void *);
881 template <
typename T>
void mapRequired(
const char *Key,
T &Val) {
883 this->processKey(Key, Val,
true, Ctx);
886 template <
typename T,
typename Context>
887 void mapRequired(
const char *Key,
T &Val, Context &Ctx) {
888 this->processKey(Key, Val,
true, Ctx);
891 template <
typename T>
void mapOptional(
const char *Key,
T &Val) {
893 mapOptionalWithContext(Key, Val, Ctx);
896 template <
typename T,
typename DefaultT>
899 mapOptionalWithContext(Key, Val,
Default, Ctx);
902 template <
typename T,
typename Context>
903 std::enable_if_t<has_SequenceTraits<T>::value,
void>
904 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
906 if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
908 this->processKey(Key, Val,
false, Ctx);
911 template <
typename T,
typename Context>
912 void mapOptionalWithContext(
const char *Key, std::optional<T> &Val,
914 this->processKeyWithDefault(Key, Val, std::optional<T>(),
918 template <
typename T,
typename Context>
919 std::enable_if_t<!has_SequenceTraits<T>::value,
void>
920 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
921 this->processKey(Key, Val,
false, Ctx);
924 template <
typename T,
typename Context,
typename DefaultT>
925 void mapOptionalWithContext(
const char *Key,
T &Val,
const DefaultT &
Default,
927 static_assert(std::is_convertible<DefaultT, T>::value,
928 "Default type must be implicitly convertible to value type!");
929 this->processKeyWithDefault(Key, Val,
static_cast<const T &
>(
Default),
934 template <
typename T,
typename Context>
935 void processKeyWithDefault(
const char *Key, std::optional<T> &Val,
936 const std::optional<T> &DefaultValue,
937 bool Required, Context &Ctx);
939 template <
typename T,
typename Context>
940 void processKeyWithDefault(
const char *Key,
T &Val,
const T &DefaultValue,
941 bool Required, Context &Ctx) {
944 const bool sameAsDefault = outputting() && Val == DefaultValue;
945 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
947 yamlize(*
this, Val, Required, Ctx);
948 this->postflightKey(SaveInfo);
956 template <
typename T,
typename Context>
957 void processKey(
const char *Key,
T &Val,
bool Required, Context &Ctx) {
960 if ( this->preflightKey(Key, Required,
false, UseDefault, SaveInfo) ) {
961 yamlize(*
this, Val, Required, Ctx);
962 this->postflightKey(SaveInfo);
972template <
typename T,
typename Context>
973void doMapping(IO &io,
T &Val, Context &Ctx) {
974 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
977template <
typename T>
void doMapping(IO &io,
T &Val, EmptyContext &Ctx) {
978 MappingTraits<T>::mapping(io, Val);
984std::enable_if_t<has_ScalarEnumerationTraits<T>::value,
void>
985yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
986 io.beginEnumScalar();
987 ScalarEnumerationTraits<T>::enumeration(io, Val);
992std::enable_if_t<has_ScalarBitSetTraits<T>::value,
void>
993yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
995 if ( io.beginBitSetScalar(DoClear) ) {
998 ScalarBitSetTraits<T>::bitset(io, Val);
999 io.endBitSetScalar();
1003template <
typename T>
1004std::enable_if_t<has_ScalarTraits<T>::value,
void> yamlize(IO &io,
T &Val,
bool,
1005 EmptyContext &Ctx) {
1006 if ( io.outputting() ) {
1007 SmallString<128> Storage;
1008 raw_svector_ostream Buffer(Storage);
1009 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
1010 StringRef Str = Buffer.str();
1011 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1015 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1016 StringRef
Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
1018 io.setError(Twine(Result));
1023template <
typename T>
1024std::enable_if_t<has_BlockScalarTraits<T>::value,
void>
1025yamlize(IO &
YamlIO,
T &Val,
bool, EmptyContext &Ctx) {
1026 if (
YamlIO.outputting()) {
1027 std::string Storage;
1028 raw_string_ostream Buffer(Storage);
1029 BlockScalarTraits<T>::output(Val,
YamlIO.getContext(), Buffer);
1030 StringRef Str(Storage);
1031 YamlIO.blockScalarString(Str);
1034 YamlIO.blockScalarString(Str);
1036 BlockScalarTraits<T>::input(Str,
YamlIO.getContext(), Val);
1038 YamlIO.setError(Twine(Result));
1042template <
typename T>
1043std::enable_if_t<has_TaggedScalarTraits<T>::value,
void>
1044yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1045 if (io.outputting()) {
1046 std::string ScalarStorage, TagStorage;
1047 raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage);
1048 TaggedScalarTraits<T>::output(Val, io.getContext(), ScalarBuffer,
1050 io.scalarTag(TagStorage);
1051 StringRef ScalarStr(ScalarStorage);
1052 io.scalarString(ScalarStr,
1053 TaggedScalarTraits<T>::mustQuote(Val, ScalarStr));
1058 io.scalarString(Str, QuotingType::None);
1060 TaggedScalarTraits<T>::input(Str,
Tag, io.getContext(), Val);
1062 io.setError(Twine(Result));
1069template <
typename T,
typename Context>
1070std::string doValidate(IO &io,
T &Val, Context &Ctx) {
1071 return MappingContextTraits<T, Context>::validate(io, Val, Ctx);
1074template <
typename T> std::string doValidate(IO &io,
T &Val, EmptyContext &) {
1075 return MappingTraits<T>::validate(io, Val);
1080template <
typename T,
typename Context>
1081std::enable_if_t<validatedMappingTraits<T, Context>::value,
void>
1082yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1083 if (has_FlowTraits<MappingTraits<T>>
::value)
1084 io.beginFlowMapping();
1087 if (io.outputting()) {
1088 std::string Err = detail::doValidate(io, Val, Ctx);
1090 errs() << Err <<
"\n";
1091 assert(Err.empty() &&
"invalid struct trying to be written as yaml");
1094 detail::doMapping(io, Val, Ctx);
1095 if (!io.outputting()) {
1096 std::string Err = detail::doValidate(io, Val, Ctx);
1100 if (has_FlowTraits<MappingTraits<T>>
::value)
1101 io.endFlowMapping();
1106template <
typename T,
typename Context>
1107std::enable_if_t<!has_MappingEnumInputTraits<T, Context>::value,
bool>
1108yamlizeMappingEnumInput(IO &io,
T &Val) {
1112template <
typename T,
typename Context>
1113std::enable_if_t<has_MappingEnumInputTraits<T, Context>::value,
bool>
1114yamlizeMappingEnumInput(IO &io,
T &Val) {
1115 if (io.outputting())
1118 io.beginEnumScalar();
1119 MappingTraits<T>::enumInput(io, Val);
1120 bool Matched = !io.matchEnumFallback();
1125template <
typename T,
typename Context>
1126std::enable_if_t<unvalidatedMappingTraits<T, Context>::value,
void>
1127yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1128 if (yamlizeMappingEnumInput<T, Context>(io, Val))
1130 if (has_FlowTraits<MappingTraits<T>>
::value) {
1131 io.beginFlowMapping();
1132 detail::doMapping(io, Val, Ctx);
1133 io.endFlowMapping();
1136 detail::doMapping(io, Val, Ctx);
1141template <
typename T>
1142std::enable_if_t<has_CustomMappingTraits<T>::value,
void>
1143yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1144 if ( io.outputting() ) {
1146 CustomMappingTraits<T>::output(io, Val);
1150 for (StringRef key : io.keys())
1151 CustomMappingTraits<T>::inputOne(io, key, Val);
1156template <
typename T>
1157std::enable_if_t<has_PolymorphicTraits<T>::value,
void>
1158yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1159 switch (io.outputting() ? PolymorphicTraits<T>::getKind(Val)
1160 : io.getNodeKind()) {
1161 case NodeKind::Scalar:
1162 return yamlize(io, PolymorphicTraits<T>::getAsScalar(Val),
true, Ctx);
1164 return yamlize(io, PolymorphicTraits<T>::getAsMap(Val),
true, Ctx);
1165 case NodeKind::Sequence:
1166 return yamlize(io, PolymorphicTraits<T>::getAsSequence(Val),
true, Ctx);
1170template <
typename T>
1171std::enable_if_t<missingTraits<T, EmptyContext>::value,
void>
1172yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1173 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1176template <
typename T,
typename Context>
1177std::enable_if_t<has_SequenceTraits<T>::value,
void>
1178yamlize(IO &io,
T &Seq,
bool, Context &Ctx) {
1179 if ( has_FlowTraits< SequenceTraits<T>>
::value ) {
1180 unsigned incnt = io.beginFlowSequence();
1181 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1182 for(
unsigned i=0; i <
count; ++i) {
1184 if ( io.preflightFlowElement(i, SaveInfo) ) {
1185 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1186 io.postflightFlowElement(SaveInfo);
1189 io.endFlowSequence();
1192 unsigned incnt = io.beginSequence();
1193 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1194 for(
unsigned i=0; i <
count; ++i) {
1196 if ( io.preflightElement(i, SaveInfo) ) {
1197 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1198 io.postflightElement(SaveInfo);
1206struct ScalarTraits<
bool> {
1207 static void output(
const bool &,
void* , raw_ostream &);
1208 static StringRef input(StringRef,
void *,
bool &);
1209 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1213struct ScalarTraits<StringRef> {
1214 static void output(
const StringRef &,
void *, raw_ostream &);
1215 static StringRef input(StringRef,
void *, StringRef &);
1216 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1221 static void output(
const std::string &,
void *, raw_ostream &);
1222 static StringRef input(StringRef,
void *, std::string &);
1223 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1228 static void output(
const uint8_t &,
void *, raw_ostream &);
1229 static StringRef input(StringRef,
void *,
uint8_t &);
1230 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1235 static void output(
const uint16_t &,
void *, raw_ostream &);
1236 static StringRef input(StringRef,
void *,
uint16_t &);
1237 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1242 static void output(
const uint32_t &,
void *, raw_ostream &);
1243 static StringRef input(StringRef,
void *,
uint32_t &);
1244 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1249 static void output(
const uint64_t &,
void *, raw_ostream &);
1250 static StringRef input(StringRef,
void *,
uint64_t &);
1251 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1255struct ScalarTraits<int8_t> {
1256 static void output(
const int8_t &,
void *, raw_ostream &);
1257 static StringRef input(StringRef,
void *, int8_t &);
1258 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1262struct ScalarTraits<int16_t> {
1263 static void output(
const int16_t &,
void *, raw_ostream &);
1264 static StringRef input(StringRef,
void *, int16_t &);
1265 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1269struct ScalarTraits<int32_t> {
1270 static void output(
const int32_t &,
void *, raw_ostream &);
1271 static StringRef input(StringRef,
void *, int32_t &);
1272 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1276struct ScalarTraits<int64_t> {
1277 static void output(
const int64_t &,
void *, raw_ostream &);
1278 static StringRef input(StringRef,
void *, int64_t &);
1279 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1283struct ScalarTraits<float> {
1284 static void output(
const float &,
void *, raw_ostream &);
1285 static StringRef input(StringRef,
void *,
float &);
1286 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1290struct ScalarTraits<double> {
1291 static void output(
const double &,
void *, raw_ostream &);
1292 static StringRef input(StringRef,
void *,
double &);
1293 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1299template <
typename value_type, llvm::endianness endian,
size_t alignment>
1300struct ScalarTraits<support::detail::packed_endian_specific_integral<
1301 value_type, endian, alignment>,
1302 std::enable_if_t<has_ScalarTraits<value_type>::value>> {
1304 support::detail::packed_endian_specific_integral<value_type,
endian,
1307 static void output(
const endian_type &
E,
void *Ctx, raw_ostream &Stream) {
1308 ScalarTraits<value_type>::output(
static_cast<value_type
>(
E), Ctx, Stream);
1311 static StringRef input(StringRef Str,
void *Ctx, endian_type &
E) {
1313 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1314 E =
static_cast<endian_type
>(
V);
1318 static QuotingType mustQuote(StringRef Str) {
1319 return ScalarTraits<value_type>::mustQuote(Str);
1323template <
typename value_type, llvm::endianness endian,
size_t alignment>
1324struct ScalarEnumerationTraits<
1325 support::detail::packed_endian_specific_integral<value_type, endian,
1327 std::enable_if_t<has_ScalarEnumerationTraits<value_type>::value>> {
1329 support::detail::packed_endian_specific_integral<value_type,
endian,
1332 static void enumeration(IO &io, endian_type &
E) {
1334 ScalarEnumerationTraits<value_type>::enumeration(io, V);
1339template <
typename value_type, llvm::endianness endian,
size_t alignment>
1340struct ScalarBitSetTraits<
1341 support::detail::packed_endian_specific_integral<value_type, endian,
1343 std::enable_if_t<has_ScalarBitSetTraits<value_type>::value>> {
1345 support::detail::packed_endian_specific_integral<value_type,
endian,
1347 static void bitset(IO &io, endian_type &
E) {
1349 ScalarBitSetTraits<value_type>::bitset(io, V);
1356template <
typename TNorm,
typename TFinal>
1357struct MappingNormalization {
1358 MappingNormalization(IO &i_o, TFinal &Obj)
1359 : io(i_o), BufPtr(nullptr),
Result(Obj) {
1360 if ( io.outputting() ) {
1361 BufPtr =
new (&Buffer) TNorm(io, Obj);
1364 BufPtr =
new (&Buffer) TNorm(io);
1368 ~MappingNormalization() {
1369 if ( ! io.outputting() ) {
1370 Result = BufPtr->denormalize(io);
1375 TNorm* operator->() {
return BufPtr; }
1378 using Storage = AlignedCharArrayUnion<TNorm>;
1388template <
typename TNorm,
typename TFinal>
1389struct MappingNormalizationHeap {
1390 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *
allocator)
1392 if ( io.outputting() ) {
1393 BufPtr =
new (&Buffer) TNorm(io, Obj);
1397 new (BufPtr) TNorm(io);
1399 BufPtr =
new TNorm(io);
1403 ~MappingNormalizationHeap() {
1404 if ( io.outputting() ) {
1408 Result = BufPtr->denormalize(io);
1412 TNorm* operator->() {
return BufPtr; }
1415 using Storage = AlignedCharArrayUnion<TNorm>;
1419 TNorm *BufPtr =
nullptr;
1435class Input :
public IO {
1440 Input(StringRef InputContent,
1441 void *Ctxt =
nullptr,
1443 void *DiagHandlerCtxt =
nullptr);
1444 Input(MemoryBufferRef Input,
1445 void *Ctxt =
nullptr,
1447 void *DiagHandlerCtxt =
nullptr);
1451 std::error_code
error();
1454 bool outputting()
const override;
1455 bool mapTag(StringRef,
bool)
override;
1456 void beginMapping()
override;
1457 void endMapping()
override;
1458 bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&)
override;
1459 void postflightKey(
void *)
override;
1460 std::vector<StringRef> keys()
override;
1461 void beginFlowMapping()
override;
1462 void endFlowMapping()
override;
1463 unsigned beginSequence()
override;
1464 void endSequence()
override;
1465 bool preflightElement(
unsigned index,
void *&)
override;
1466 void postflightElement(
void *)
override;
1467 unsigned beginFlowSequence()
override;
1468 bool preflightFlowElement(
unsigned ,
void *&)
override;
1469 void postflightFlowElement(
void *)
override;
1470 void endFlowSequence()
override;
1471 void beginEnumScalar()
override;
1472 bool matchEnumScalar(
const char*,
bool)
override;
1473 bool matchEnumFallback()
override;
1474 void endEnumScalar()
override;
1475 bool beginBitSetScalar(
bool &)
override;
1476 bool bitSetMatch(
const char *,
bool )
override;
1477 void endBitSetScalar()
override;
1478 void scalarString(StringRef &, QuotingType)
override;
1479 void blockScalarString(StringRef &)
override;
1480 void scalarTag(std::string &)
override;
1482 void setError(
const Twine &message)
override;
1483 bool canElideEmptySequence()
override;
1487 HNode(
Node *n) : _node(n) {}
1489 static bool classof(
const HNode *) {
return true; }
1494 class EmptyHNode :
public HNode {
1496 EmptyHNode(
Node *n) : HNode(n) { }
1498 static bool classof(
const HNode *n) {
return NullNode::classof(n->_node); }
1500 static bool classof(
const EmptyHNode *) {
return true; }
1503 class ScalarHNode :
public HNode {
1505 ScalarHNode(
Node *n, StringRef s) : HNode(n), _value(s) { }
1507 StringRef
value()
const {
return _value; }
1509 static bool classof(
const HNode *n) {
1510 return ScalarNode::classof(n->_node) ||
1511 BlockScalarNode::classof(n->_node);
1514 static bool classof(
const ScalarHNode *) {
return true; }
1520 class MapHNode :
public HNode {
1522 MapHNode(
Node *n) : HNode(n) { }
1524 static bool classof(
const HNode *n) {
1525 return MappingNode::classof(n->_node);
1528 static bool classof(
const MapHNode *) {
return true; }
1530 using NameToNodeAndLoc = StringMap<std::pair<HNode *, SMRange>>;
1532 NameToNodeAndLoc Mapping;
1533 SmallVector<std::string, 6> ValidKeys;
1536 class SequenceHNode :
public HNode {
1538 SequenceHNode(
Node *n) : HNode(n) { }
1540 static bool classof(
const HNode *n) {
1541 return SequenceNode::classof(n->_node);
1544 static bool classof(
const SequenceHNode *) {
return true; }
1546 std::vector<HNode *> Entries;
1549 Input::HNode *createHNodes(
Node *node);
1550 void setError(HNode *hnode,
const Twine &message);
1551 void setError(
Node *node,
const Twine &message);
1552 void setError(
const SMRange &
Range,
const Twine &message);
1554 void reportWarning(HNode *hnode,
const Twine &message);
1555 void reportWarning(
Node *hnode,
const Twine &message);
1556 void reportWarning(
const SMRange &
Range,
const Twine &message);
1559 void releaseHNodeBuffers();
1564 bool setCurrentDocument();
1565 bool nextDocument();
1568 const Node *getCurrentNode()
const;
1570 void setAllowUnknownKeys(
bool Allow)
override;
1574 std::unique_ptr<llvm::yaml::Stream> Strm;
1575 HNode *TopNode =
nullptr;
1578 SpecificBumpPtrAllocator<EmptyHNode> EmptyHNodeAllocator;
1579 SpecificBumpPtrAllocator<ScalarHNode> ScalarHNodeAllocator;
1580 SpecificBumpPtrAllocator<MapHNode> MapHNodeAllocator;
1581 SpecificBumpPtrAllocator<SequenceHNode> SequenceHNodeAllocator;
1582 document_iterator DocIterator;
1584 HNode *CurrentNode =
nullptr;
1585 bool ScalarMatchFound =
false;
1586 bool AllowUnknownKeys =
false;
1593class Output :
public IO {
1595 Output(raw_ostream &,
void *Ctxt =
nullptr,
int WrapColumn = 70);
1603 void setWriteDefaultValues(
bool Write) { WriteDefaultValues =
Write; }
1605 bool outputting()
const override;
1606 bool mapTag(StringRef,
bool)
override;
1607 void beginMapping()
override;
1608 void endMapping()
override;
1609 bool preflightKey(
const char *key,
bool,
bool,
bool &,
void *&)
override;
1610 void postflightKey(
void *)
override;
1611 std::vector<StringRef> keys()
override;
1612 void beginFlowMapping()
override;
1613 void endFlowMapping()
override;
1614 unsigned beginSequence()
override;
1615 void endSequence()
override;
1616 bool preflightElement(
unsigned,
void *&)
override;
1617 void postflightElement(
void *)
override;
1618 unsigned beginFlowSequence()
override;
1619 bool preflightFlowElement(
unsigned,
void *&)
override;
1620 void postflightFlowElement(
void *)
override;
1621 void endFlowSequence()
override;
1622 void beginEnumScalar()
override;
1623 bool matchEnumScalar(
const char*,
bool)
override;
1624 bool matchEnumFallback()
override;
1625 void endEnumScalar()
override;
1626 bool beginBitSetScalar(
bool &)
override;
1627 bool bitSetMatch(
const char *,
bool )
override;
1628 void endBitSetScalar()
override;
1629 void scalarString(StringRef &, QuotingType)
override;
1630 void blockScalarString(StringRef &)
override;
1631 void scalarTag(std::string &)
override;
1633 void setError(
const Twine &message)
override;
1634 bool canElideEmptySequence()
override;
1638 void beginDocuments();
1639 bool preflightDocument(
unsigned);
1640 void postflightDocument();
1641 void endDocuments();
1644 void output(StringRef s);
1645 void output(StringRef, QuotingType);
1646 void outputUpToEndOfLine(StringRef s);
1647 void newLineCheck(
bool EmptySequence =
false);
1648 void outputNewLine();
1649 void paddedKey(StringRef key);
1650 void flowKey(StringRef Key);
1655 inFlowSeqFirstElement,
1656 inFlowSeqOtherElement,
1663 static bool inSeqAnyElement(InState State);
1664 static bool inFlowSeqAnyElement(InState State);
1665 static bool inMapAnyKey(InState State);
1666 static bool inFlowMapAnyKey(InState State);
1670 SmallVector<InState, 8> StateStack;
1672 int ColumnAtFlowStart = 0;
1673 int ColumnAtMapFlowStart = 0;
1674 bool NeedBitValueComma =
false;
1675 bool NeedFlowSequenceComma =
false;
1676 bool EnumerationMatchFound =
false;
1677 bool WriteDefaultValues =
false;
1679 StringRef PaddingBeforeContainer;
1682template <
typename T,
typename Context>
1683void IO::processKeyWithDefault(
const char *Key, std::optional<T> &Val,
1684 const std::optional<T> &DefaultValue,
1685 bool Required, Context &Ctx) {
1686 assert(!DefaultValue &&
"std::optional<T> shouldn't have a value!");
1688 bool UseDefault =
true;
1689 const bool sameAsDefault = outputting() && !Val;
1690 if (!outputting() && !Val)
1693 this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) {
1699 bool IsNone =
false;
1701 if (
const auto *
Node =
1702 dyn_cast<ScalarNode>(((Input *)
this)->getCurrentNode()))
1705 IsNone =
Node->getRawValue().rtrim(
' ') ==
"<none>";
1710 yamlize(*
this, *Val, Required, Ctx);
1711 this->postflightKey(SaveInfo);
1726#define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1728 _type() = default; \
1729 _type(const _base v) : value(v) {} \
1730 _type(const _type &v) = default; \
1731 _type &operator=(const _type &rhs) = default; \
1732 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1733 operator const _base & () const { return value; } \
1734 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1735 bool operator==(const _base &rhs) const { return value == rhs; } \
1736 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1738 using BaseType = _base; \
1751struct ScalarTraits<Hex8> {
1752 static void output(
const Hex8 &,
void *, raw_ostream &);
1753 static StringRef input(StringRef,
void *, Hex8 &);
1754 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1758struct ScalarTraits<Hex16> {
1759 static void output(
const Hex16 &,
void *, raw_ostream &);
1760 static StringRef input(StringRef,
void *, Hex16 &);
1761 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1765struct ScalarTraits<Hex32> {
1766 static void output(
const Hex32 &,
void *, raw_ostream &);
1767 static StringRef input(StringRef,
void *, Hex32 &);
1768 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1772struct ScalarTraits<Hex64> {
1773 static void output(
const Hex64 &,
void *, raw_ostream &);
1774 static StringRef input(StringRef,
void *, Hex64 &);
1775 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1778template <>
struct ScalarTraits<VersionTuple> {
1780 static StringRef input(StringRef,
void *, VersionTuple &);
1781 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1785template <
typename T>
1786inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
1790 while ( yin.setCurrentDocument() ) {
1791 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i),
true, Ctx);
1801template <
typename T>
1802inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Input &>
1805 yin.setCurrentDocument();
1806 yamlize(yin, docMap,
true, Ctx);
1812template <
typename T>
1813inline std::enable_if_t<has_SequenceTraits<T>::value, Input &>
1816 if (yin.setCurrentDocument())
1817 yamlize(yin, docSeq,
true, Ctx);
1822template <
typename T>
1823inline std::enable_if_t<has_BlockScalarTraits<T>::value, Input &>
1826 if (
In.setCurrentDocument())
1827 yamlize(In, Val,
true, Ctx);
1832template <
typename T>
1833inline std::enable_if_t<has_CustomMappingTraits<T>::value, Input &>
1836 if (
In.setCurrentDocument())
1837 yamlize(In, Val,
true, Ctx);
1842template <
typename T>
1843inline std::enable_if_t<has_PolymorphicTraits<T>::value, Input &>
1846 if (
In.setCurrentDocument())
1847 yamlize(In, Val,
true, Ctx);
1852template <
typename T>
1853inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Input &>
1855 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1860template <
typename T>
1861inline std::enable_if_t<has_DocumentListTraits<T>::value, Output &>
1864 yout.beginDocuments();
1865 const size_t count = DocumentListTraits<T>::size(yout, docList);
1866 for(
size_t i=0; i <
count; ++i) {
1867 if ( yout.preflightDocument(i) ) {
1868 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i),
true,
1870 yout.postflightDocument();
1873 yout.endDocuments();
1878template <
typename T>
1879inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
1882 yout.beginDocuments();
1883 if ( yout.preflightDocument(0) ) {
1884 yamlize(yout, map,
true, Ctx);
1885 yout.postflightDocument();
1887 yout.endDocuments();
1892template <
typename T>
1893inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
1896 yout.beginDocuments();
1897 if ( yout.preflightDocument(0) ) {
1898 yamlize(yout,
seq,
true, Ctx);
1899 yout.postflightDocument();
1901 yout.endDocuments();
1906template <
typename T>
1907inline std::enable_if_t<has_BlockScalarTraits<T>::value, Output &>
1910 Out.beginDocuments();
1911 if (Out.preflightDocument(0)) {
1912 yamlize(Out, Val,
true, Ctx);
1913 Out.postflightDocument();
1920template <
typename T>
1921inline std::enable_if_t<has_CustomMappingTraits<T>::value, Output &>
1924 Out.beginDocuments();
1925 if (Out.preflightDocument(0)) {
1926 yamlize(Out, Val,
true, Ctx);
1927 Out.postflightDocument();
1935template <
typename T>
1936inline std::enable_if_t<has_PolymorphicTraits<T>::value, Output &>
1939 Out.beginDocuments();
1940 if (Out.preflightDocument(0)) {
1943 assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar &&
"plain scalar documents are not supported");
1944 yamlize(Out, Val,
true, Ctx);
1945 Out.postflightDocument();
1952template <
typename T>
1953inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Output &>
1955 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1959template <
bool B>
struct IsFlowSequenceBase {};
1960template <>
struct IsFlowSequenceBase<
true> {
static const bool flow =
true; };
1962template <
typename T,
typename U =
void>
1963struct IsResizable : std::false_type {};
1965template <
typename T>
1966struct IsResizable<
T,
std::void_t<decltype(std::declval<T>().resize(0))>>
1967 :
public std::true_type {};
1969template <
typename T,
bool B>
struct IsResizableBase {
1970 using type =
typename T::value_type;
1972 static type &element(IO &io,
T &seq,
size_t index) {
1973 if (index >=
seq.size())
1974 seq.resize(index + 1);
1979template <
typename T>
struct IsResizableBase<
T,
false> {
1980 using type =
typename T::value_type;
1982 static type &element(IO &io,
T &seq,
size_t index) {
1983 if (index >=
seq.size()) {
1984 io.setError(Twine(
"value sequence extends beyond static size (") +
1985 Twine(
seq.size()) +
")");
1992template <
typename T,
bool Flow>
1993struct SequenceTraitsImpl
1994 : IsFlowSequenceBase<Flow>, IsResizableBase<T, IsResizable<T>::value> {
1995 static size_t size(IO &io,
T &seq) {
return seq.size(); }
2000template <
bool>
struct CheckIsBool {
static const bool value =
true; };
2004template <
typename T>
2005struct SequenceTraits<
2007 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2008 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
2009template <
typename T,
size_t N>
2010struct SequenceTraits<
2012 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2013 : SequenceTraitsImpl<std::array<T, N>, SequenceElementTraits<T>::flow> {};
2014template <
typename T,
unsigned N>
2015struct SequenceTraits<
2017 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2018 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
2019template <
typename T>
2020struct SequenceTraits<
2022 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2023 : SequenceTraitsImpl<SmallVectorImpl<T>, SequenceElementTraits<T>::flow> {};
2024template <
typename T>
2025struct SequenceTraits<
2027 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2028 : SequenceTraitsImpl<MutableArrayRef<T>, SequenceElementTraits<T>::flow> {};
2031template <
typename T>
2032struct SequenceElementTraits<
T,
std::enable_if_t<std::is_fundamental_v<T>>> {
2033 static const bool flow =
true;
2037template<>
struct SequenceElementTraits<
std::
string> {
2038 static const bool flow =
false;
2040template<>
struct SequenceElementTraits<StringRef> {
2041 static const bool flow =
false;
2043template<>
struct SequenceElementTraits<
std::pair<std::string, std::string>> {
2044 static const bool flow =
false;
2048template <
typename T>
struct StdMapStringCustomMappingTraitsImpl {
2049 using map_type = std::map<std::string, T>;
2051 static void inputOne(IO &io, StringRef key, map_type &v) {
2052 io.mapRequired(key.str().c_str(), v[std::string(key)]);
2055 static void output(IO &io, map_type &v) {
2057 io.mapRequired(
p.first.c_str(),
p.second);
2064#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW) \
2068 !std::is_fundamental_v<TYPE> && !std::is_same_v<TYPE, std::string> && \
2069 !std::is_same_v<TYPE, llvm::StringRef>, \
2070 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
2071 template <> struct SequenceElementTraits<TYPE> { \
2072 static const bool flow = FLOW; \
2079#define LLVM_YAML_IS_SEQUENCE_VECTOR(type) \
2080 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)
2084#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type) \
2085 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)
2087#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type) \
2090 template <> struct LLVM_ABI MappingTraits<Type> { \
2091 static void mapping(IO &IO, Type &Obj); \
2096#define LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(Type) \
2099 template <> struct MappingTraits<Type> { \
2100 static void mapping(IO &IO, Type &Obj); \
2105#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type) \
2108 template <> struct LLVM_ABI ScalarEnumerationTraits<Type> { \
2109 static void enumeration(IO &io, Type &Value); \
2114#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type) \
2117 template <> struct LLVM_ABI ScalarBitSetTraits<Type> { \
2118 static void bitset(IO &IO, Type &Options); \
2123#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote) \
2126 template <> struct LLVM_ABI ScalarTraits<Type> { \
2127 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
2128 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
2129 static QuotingType mustQuote(StringRef) { return MustQuote; } \
2136#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
2139 template <unsigned N> \
2140 struct DocumentListTraits<SmallVector<_type, N>> \
2141 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
2143 struct DocumentListTraits<std::vector<_type>> \
2144 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
2150#define LLVM_YAML_IS_STRING_MAP(_type) \
2154 struct CustomMappingTraits<std::map<std::string, _type>> \
2155 : public StdMapStringCustomMappingTraitsImpl<_type> {}; \
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))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 >
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.