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 std::error_code
error() = 0;
823 virtual void setAllowUnknownKeys(
bool Allow);
825 template <
typename T>
826 void enumCase(
T &Val,
const char* Str,
const T ConstVal) {
827 if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
833 template <
typename T>
834 void enumCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
835 if ( matchEnumScalar(Str, outputting() && Val ==
static_cast<T>(ConstVal)) ) {
840 template <
typename FBT,
typename T>
841 void enumFallback(
T &Val) {
842 if (matchEnumFallback()) {
843 EmptyContext Context;
845 FBT Res =
static_cast<typename FBT::BaseType
>(Val);
846 yamlize(*
this, Res,
true, Context);
847 Val =
static_cast<T>(
static_cast<typename FBT::BaseType
>(Res));
851 template <
typename T>
852 void bitSetCase(
T &Val,
const char* Str,
const T ConstVal) {
853 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
854 Val =
static_cast<T>(Val | ConstVal);
859 template <
typename T>
860 void bitSetCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
861 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
862 Val =
static_cast<T>(Val | ConstVal);
866 template <
typename T>
867 void maskedBitSetCase(
T &Val,
const char *Str,
T ConstVal,
T Mask) {
868 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
869 Val = Val | ConstVal;
872 template <
typename T>
873 void maskedBitSetCase(
T &Val,
const char *Str,
uint32_t ConstVal,
875 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
876 Val = Val | ConstVal;
879 void *getContext()
const;
880 void setContext(
void *);
882 template <
typename T>
void mapRequired(
const char *Key,
T &Val) {
884 this->processKey(Key, Val,
true, Ctx);
887 template <
typename T,
typename Context>
888 void mapRequired(
const char *Key,
T &Val, Context &Ctx) {
889 this->processKey(Key, Val,
true, Ctx);
892 template <
typename T>
void mapOptional(
const char *Key,
T &Val) {
894 mapOptionalWithContext(Key, Val, Ctx);
897 template <
typename T,
typename DefaultT>
900 mapOptionalWithContext(Key, Val,
Default, Ctx);
903 template <
typename T,
typename Context>
904 std::enable_if_t<has_SequenceTraits<T>::value,
void>
905 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
907 if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
909 this->processKey(Key, Val,
false, Ctx);
912 template <
typename T,
typename Context>
913 void mapOptionalWithContext(
const char *Key, std::optional<T> &Val,
915 this->processKeyWithDefault(Key, Val, std::optional<T>(),
919 template <
typename T,
typename Context>
920 std::enable_if_t<!has_SequenceTraits<T>::value,
void>
921 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
922 this->processKey(Key, Val,
false, Ctx);
925 template <
typename T,
typename Context,
typename DefaultT>
926 void mapOptionalWithContext(
const char *Key,
T &Val,
const DefaultT &
Default,
928 static_assert(std::is_convertible<DefaultT, T>::value,
929 "Default type must be implicitly convertible to value type!");
930 this->processKeyWithDefault(Key, Val,
static_cast<const T &
>(
Default),
935 template <
typename T,
typename Context>
936 void processKeyWithDefault(
const char *Key, std::optional<T> &Val,
937 const std::optional<T> &DefaultValue,
938 bool Required, Context &Ctx);
940 template <
typename T,
typename Context>
941 void processKeyWithDefault(
const char *Key,
T &Val,
const T &DefaultValue,
942 bool Required, Context &Ctx) {
945 const bool sameAsDefault = outputting() && Val == DefaultValue;
946 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
948 yamlize(*
this, Val, Required, Ctx);
949 this->postflightKey(SaveInfo);
957 template <
typename T,
typename Context>
958 void processKey(
const char *Key,
T &Val,
bool Required, Context &Ctx) {
961 if ( this->preflightKey(Key, Required,
false, UseDefault, SaveInfo) ) {
962 yamlize(*
this, Val, Required, Ctx);
963 this->postflightKey(SaveInfo);
973template <
typename T,
typename Context>
974void doMapping(IO &io,
T &Val, Context &Ctx) {
975 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
978template <
typename T>
void doMapping(IO &io,
T &Val, EmptyContext &Ctx) {
979 MappingTraits<T>::mapping(io, Val);
985std::enable_if_t<has_ScalarEnumerationTraits<T>::value,
void>
986yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
987 io.beginEnumScalar();
988 ScalarEnumerationTraits<T>::enumeration(io, Val);
993std::enable_if_t<has_ScalarBitSetTraits<T>::value,
void>
994yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
996 if ( io.beginBitSetScalar(DoClear) ) {
999 ScalarBitSetTraits<T>::bitset(io, Val);
1000 io.endBitSetScalar();
1004template <
typename T>
1005std::enable_if_t<has_ScalarTraits<T>::value,
void> yamlize(IO &io,
T &Val,
bool,
1006 EmptyContext &Ctx) {
1007 if ( io.outputting() ) {
1008 SmallString<128> Storage;
1009 raw_svector_ostream Buffer(Storage);
1010 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
1011 StringRef Str = Buffer.str();
1012 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1016 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1017 StringRef
Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
1019 io.setError(Twine(Result));
1024template <
typename T>
1025std::enable_if_t<has_BlockScalarTraits<T>::value,
void>
1026yamlize(IO &
YamlIO,
T &Val,
bool, EmptyContext &Ctx) {
1027 if (
YamlIO.outputting()) {
1028 std::string Storage;
1029 raw_string_ostream Buffer(Storage);
1030 BlockScalarTraits<T>::output(Val,
YamlIO.getContext(), Buffer);
1031 StringRef Str(Storage);
1032 YamlIO.blockScalarString(Str);
1035 YamlIO.blockScalarString(Str);
1037 BlockScalarTraits<T>::input(Str,
YamlIO.getContext(), Val);
1039 YamlIO.setError(Twine(Result));
1043template <
typename T>
1044std::enable_if_t<has_TaggedScalarTraits<T>::value,
void>
1045yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1046 if (io.outputting()) {
1047 std::string ScalarStorage, TagStorage;
1048 raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage);
1049 TaggedScalarTraits<T>::output(Val, io.getContext(), ScalarBuffer,
1051 io.scalarTag(TagStorage);
1052 StringRef ScalarStr(ScalarStorage);
1053 io.scalarString(ScalarStr,
1054 TaggedScalarTraits<T>::mustQuote(Val, ScalarStr));
1059 io.scalarString(Str, QuotingType::None);
1061 TaggedScalarTraits<T>::input(Str,
Tag, io.getContext(), Val);
1063 io.setError(Twine(Result));
1070template <
typename T,
typename Context>
1071std::string doValidate(IO &io,
T &Val, Context &Ctx) {
1072 return MappingContextTraits<T, Context>::validate(io, Val, Ctx);
1075template <
typename T> std::string doValidate(IO &io,
T &Val, EmptyContext &) {
1076 return MappingTraits<T>::validate(io, Val);
1081template <
typename T,
typename Context>
1082std::enable_if_t<validatedMappingTraits<T, Context>::value,
void>
1083yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1084 if (has_FlowTraits<MappingTraits<T>>
::value)
1085 io.beginFlowMapping();
1088 if (io.outputting()) {
1089 std::string Err = detail::doValidate(io, Val, Ctx);
1091 errs() << Err <<
"\n";
1092 assert(Err.empty() &&
"invalid struct trying to be written as yaml");
1095 detail::doMapping(io, Val, Ctx);
1096 if (!io.outputting()) {
1097 std::string Err = detail::doValidate(io, Val, Ctx);
1101 if (has_FlowTraits<MappingTraits<T>>
::value)
1102 io.endFlowMapping();
1107template <
typename T,
typename Context>
1108std::enable_if_t<!has_MappingEnumInputTraits<T, Context>::value,
bool>
1109yamlizeMappingEnumInput(IO &io,
T &Val) {
1113template <
typename T,
typename Context>
1114std::enable_if_t<has_MappingEnumInputTraits<T, Context>::value,
bool>
1115yamlizeMappingEnumInput(IO &io,
T &Val) {
1116 if (io.outputting())
1119 io.beginEnumScalar();
1120 MappingTraits<T>::enumInput(io, Val);
1121 bool Matched = !io.matchEnumFallback();
1126template <
typename T,
typename Context>
1127std::enable_if_t<unvalidatedMappingTraits<T, Context>::value,
void>
1128yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1129 if (yamlizeMappingEnumInput<T, Context>(io, Val))
1131 if (has_FlowTraits<MappingTraits<T>>
::value) {
1132 io.beginFlowMapping();
1133 detail::doMapping(io, Val, Ctx);
1134 io.endFlowMapping();
1137 detail::doMapping(io, Val, Ctx);
1142template <
typename T>
1143std::enable_if_t<has_CustomMappingTraits<T>::value,
void>
1144yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1145 if ( io.outputting() ) {
1147 CustomMappingTraits<T>::output(io, Val);
1151 for (StringRef key : io.keys())
1152 CustomMappingTraits<T>::inputOne(io, key, Val);
1157template <
typename T>
1158std::enable_if_t<has_PolymorphicTraits<T>::value,
void>
1159yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1160 switch (io.outputting() ? PolymorphicTraits<T>::getKind(Val)
1161 : io.getNodeKind()) {
1162 case NodeKind::Scalar:
1163 return yamlize(io, PolymorphicTraits<T>::getAsScalar(Val),
true, Ctx);
1165 return yamlize(io, PolymorphicTraits<T>::getAsMap(Val),
true, Ctx);
1166 case NodeKind::Sequence:
1167 return yamlize(io, PolymorphicTraits<T>::getAsSequence(Val),
true, Ctx);
1171template <
typename T>
1172std::enable_if_t<missingTraits<T, EmptyContext>::value,
void>
1173yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1174 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1177template <
typename T,
typename Context>
1178std::enable_if_t<has_SequenceTraits<T>::value,
void>
1179yamlize(IO &io,
T &Seq,
bool, Context &Ctx) {
1180 if ( has_FlowTraits< SequenceTraits<T>>
::value ) {
1181 unsigned incnt = io.beginFlowSequence();
1182 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1183 for(
unsigned i=0; i <
count; ++i) {
1185 if ( io.preflightFlowElement(i, SaveInfo) ) {
1186 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1187 io.postflightFlowElement(SaveInfo);
1190 io.endFlowSequence();
1193 unsigned incnt = io.beginSequence();
1194 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1195 for(
unsigned i=0; i <
count; ++i) {
1197 if ( io.preflightElement(i, SaveInfo) ) {
1198 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1199 io.postflightElement(SaveInfo);
1207struct ScalarTraits<
bool> {
1208 static void output(
const bool &,
void* , raw_ostream &);
1209 static StringRef input(StringRef,
void *,
bool &);
1210 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1214struct ScalarTraits<StringRef> {
1215 static void output(
const StringRef &,
void *, raw_ostream &);
1216 static StringRef input(StringRef,
void *, StringRef &);
1217 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1222 static void output(
const std::string &,
void *, raw_ostream &);
1223 static StringRef input(StringRef,
void *, std::string &);
1224 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1229 static void output(
const uint8_t &,
void *, raw_ostream &);
1230 static StringRef input(StringRef,
void *,
uint8_t &);
1231 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1236 static void output(
const uint16_t &,
void *, raw_ostream &);
1237 static StringRef input(StringRef,
void *,
uint16_t &);
1238 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1243 static void output(
const uint32_t &,
void *, raw_ostream &);
1244 static StringRef input(StringRef,
void *,
uint32_t &);
1245 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1250 static void output(
const uint64_t &,
void *, raw_ostream &);
1251 static StringRef input(StringRef,
void *,
uint64_t &);
1252 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1256struct ScalarTraits<int8_t> {
1257 static void output(
const int8_t &,
void *, raw_ostream &);
1258 static StringRef input(StringRef,
void *, int8_t &);
1259 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1263struct ScalarTraits<int16_t> {
1264 static void output(
const int16_t &,
void *, raw_ostream &);
1265 static StringRef input(StringRef,
void *, int16_t &);
1266 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1270struct ScalarTraits<int32_t> {
1271 static void output(
const int32_t &,
void *, raw_ostream &);
1272 static StringRef input(StringRef,
void *, int32_t &);
1273 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1277struct ScalarTraits<int64_t> {
1278 static void output(
const int64_t &,
void *, raw_ostream &);
1279 static StringRef input(StringRef,
void *, int64_t &);
1280 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1284struct ScalarTraits<float> {
1285 static void output(
const float &,
void *, raw_ostream &);
1286 static StringRef input(StringRef,
void *,
float &);
1287 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1291struct ScalarTraits<double> {
1292 static void output(
const double &,
void *, raw_ostream &);
1293 static StringRef input(StringRef,
void *,
double &);
1294 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1300template <
typename value_type, llvm::endianness endian,
size_t alignment>
1301struct ScalarTraits<support::detail::packed_endian_specific_integral<
1302 value_type, endian, alignment>,
1303 std::enable_if_t<has_ScalarTraits<value_type>::value>> {
1305 support::detail::packed_endian_specific_integral<value_type,
endian,
1308 static void output(
const endian_type &
E,
void *Ctx, raw_ostream &Stream) {
1309 ScalarTraits<value_type>::output(
static_cast<value_type
>(
E), Ctx, Stream);
1312 static StringRef input(StringRef Str,
void *Ctx, endian_type &
E) {
1314 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1315 E =
static_cast<endian_type
>(
V);
1319 static QuotingType mustQuote(StringRef Str) {
1320 return ScalarTraits<value_type>::mustQuote(Str);
1324template <
typename value_type, llvm::endianness endian,
size_t alignment>
1325struct ScalarEnumerationTraits<
1326 support::detail::packed_endian_specific_integral<value_type, endian,
1328 std::enable_if_t<has_ScalarEnumerationTraits<value_type>::value>> {
1330 support::detail::packed_endian_specific_integral<value_type,
endian,
1333 static void enumeration(IO &io, endian_type &
E) {
1335 ScalarEnumerationTraits<value_type>::enumeration(io, V);
1340template <
typename value_type, llvm::endianness endian,
size_t alignment>
1341struct ScalarBitSetTraits<
1342 support::detail::packed_endian_specific_integral<value_type, endian,
1344 std::enable_if_t<has_ScalarBitSetTraits<value_type>::value>> {
1346 support::detail::packed_endian_specific_integral<value_type,
endian,
1348 static void bitset(IO &io, endian_type &
E) {
1350 ScalarBitSetTraits<value_type>::bitset(io, V);
1357template <
typename TNorm,
typename TFinal>
1358struct MappingNormalization {
1359 MappingNormalization(IO &i_o, TFinal &Obj)
1360 : io(i_o), BufPtr(nullptr),
Result(Obj) {
1361 if ( io.outputting() ) {
1362 BufPtr =
new (&Buffer) TNorm(io, Obj);
1365 BufPtr =
new (&Buffer) TNorm(io);
1369 ~MappingNormalization() {
1370 if ( ! io.outputting() ) {
1371 Result = BufPtr->denormalize(io);
1376 TNorm* operator->() {
return BufPtr; }
1379 using Storage = AlignedCharArrayUnion<TNorm>;
1389template <
typename TNorm,
typename TFinal>
1390struct MappingNormalizationHeap {
1391 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *
allocator)
1393 if ( io.outputting() ) {
1394 BufPtr =
new (&Buffer) TNorm(io, Obj);
1398 new (BufPtr) TNorm(io);
1400 BufPtr =
new TNorm(io);
1404 ~MappingNormalizationHeap() {
1405 if ( io.outputting() ) {
1409 Result = BufPtr->denormalize(io);
1413 TNorm* operator->() {
return BufPtr; }
1416 using Storage = AlignedCharArrayUnion<TNorm>;
1420 TNorm *BufPtr =
nullptr;
1436class Input :
public IO {
1441 Input(StringRef InputContent,
1442 void *Ctxt =
nullptr,
1444 void *DiagHandlerCtxt =
nullptr);
1445 Input(MemoryBufferRef Input,
1446 void *Ctxt =
nullptr,
1448 void *DiagHandlerCtxt =
nullptr);
1452 std::error_code
error()
override;
1455 bool outputting()
const override;
1456 bool mapTag(StringRef,
bool)
override;
1457 void beginMapping()
override;
1458 void endMapping()
override;
1459 bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&)
override;
1460 void postflightKey(
void *)
override;
1461 std::vector<StringRef> keys()
override;
1462 void beginFlowMapping()
override;
1463 void endFlowMapping()
override;
1464 unsigned beginSequence()
override;
1465 void endSequence()
override;
1466 bool preflightElement(
unsigned index,
void *&)
override;
1467 void postflightElement(
void *)
override;
1468 unsigned beginFlowSequence()
override;
1469 bool preflightFlowElement(
unsigned ,
void *&)
override;
1470 void postflightFlowElement(
void *)
override;
1471 void endFlowSequence()
override;
1472 void beginEnumScalar()
override;
1473 bool matchEnumScalar(
const char*,
bool)
override;
1474 bool matchEnumFallback()
override;
1475 void endEnumScalar()
override;
1476 bool beginBitSetScalar(
bool &)
override;
1477 bool bitSetMatch(
const char *,
bool )
override;
1478 void endBitSetScalar()
override;
1479 void scalarString(StringRef &, QuotingType)
override;
1480 void blockScalarString(StringRef &)
override;
1481 void scalarTag(std::string &)
override;
1483 void setError(
const Twine &message)
override;
1484 bool canElideEmptySequence()
override;
1488 HNode(
Node *n) : _node(n) {}
1490 static bool classof(
const HNode *) {
return true; }
1495 class EmptyHNode :
public HNode {
1497 EmptyHNode(
Node *n) : HNode(n) { }
1499 static bool classof(
const HNode *n) {
return NullNode::classof(n->_node); }
1501 static bool classof(
const EmptyHNode *) {
return true; }
1504 class ScalarHNode :
public HNode {
1506 ScalarHNode(
Node *n, StringRef s) : HNode(n), _value(s) { }
1508 StringRef
value()
const {
return _value; }
1510 static bool classof(
const HNode *n) {
1511 return ScalarNode::classof(n->_node) ||
1512 BlockScalarNode::classof(n->_node);
1515 static bool classof(
const ScalarHNode *) {
return true; }
1521 class MapHNode :
public HNode {
1523 MapHNode(
Node *n) : HNode(n) { }
1525 static bool classof(
const HNode *n) {
1526 return MappingNode::classof(n->_node);
1529 static bool classof(
const MapHNode *) {
return true; }
1531 using NameToNodeAndLoc = StringMap<std::pair<HNode *, SMRange>>;
1533 NameToNodeAndLoc Mapping;
1534 SmallVector<std::string, 6> ValidKeys;
1537 class SequenceHNode :
public HNode {
1539 SequenceHNode(
Node *n) : HNode(n) { }
1541 static bool classof(
const HNode *n) {
1542 return SequenceNode::classof(n->_node);
1545 static bool classof(
const SequenceHNode *) {
return true; }
1547 std::vector<HNode *> Entries;
1550 Input::HNode *createHNodes(
Node *node);
1551 void setError(HNode *hnode,
const Twine &message);
1552 void setError(
Node *node,
const Twine &message);
1553 void setError(
const SMRange &
Range,
const Twine &message);
1555 void reportWarning(HNode *hnode,
const Twine &message);
1556 void reportWarning(
Node *hnode,
const Twine &message);
1557 void reportWarning(
const SMRange &
Range,
const Twine &message);
1560 void releaseHNodeBuffers();
1565 bool setCurrentDocument();
1566 bool nextDocument();
1569 const Node *getCurrentNode()
const;
1571 void setAllowUnknownKeys(
bool Allow)
override;
1575 std::unique_ptr<llvm::yaml::Stream> Strm;
1576 HNode *TopNode =
nullptr;
1579 SpecificBumpPtrAllocator<EmptyHNode> EmptyHNodeAllocator;
1580 SpecificBumpPtrAllocator<ScalarHNode> ScalarHNodeAllocator;
1581 SpecificBumpPtrAllocator<MapHNode> MapHNodeAllocator;
1582 SpecificBumpPtrAllocator<SequenceHNode> SequenceHNodeAllocator;
1583 document_iterator DocIterator;
1585 HNode *CurrentNode =
nullptr;
1586 bool ScalarMatchFound =
false;
1587 bool AllowUnknownKeys =
false;
1594class Output :
public IO {
1596 Output(raw_ostream &,
void *Ctxt =
nullptr,
int WrapColumn = 70);
1604 void setWriteDefaultValues(
bool Write) { WriteDefaultValues =
Write; }
1606 bool outputting()
const override;
1607 bool mapTag(StringRef,
bool)
override;
1608 void beginMapping()
override;
1609 void endMapping()
override;
1610 bool preflightKey(
const char *key,
bool,
bool,
bool &,
void *&)
override;
1611 void postflightKey(
void *)
override;
1612 std::vector<StringRef> keys()
override;
1613 void beginFlowMapping()
override;
1614 void endFlowMapping()
override;
1615 unsigned beginSequence()
override;
1616 void endSequence()
override;
1617 bool preflightElement(
unsigned,
void *&)
override;
1618 void postflightElement(
void *)
override;
1619 unsigned beginFlowSequence()
override;
1620 bool preflightFlowElement(
unsigned,
void *&)
override;
1621 void postflightFlowElement(
void *)
override;
1622 void endFlowSequence()
override;
1623 void beginEnumScalar()
override;
1624 bool matchEnumScalar(
const char*,
bool)
override;
1625 bool matchEnumFallback()
override;
1626 void endEnumScalar()
override;
1627 bool beginBitSetScalar(
bool &)
override;
1628 bool bitSetMatch(
const char *,
bool )
override;
1629 void endBitSetScalar()
override;
1630 void scalarString(StringRef &, QuotingType)
override;
1631 void blockScalarString(StringRef &)
override;
1632 void scalarTag(std::string &)
override;
1634 void setError(
const Twine &message)
override;
1635 std::error_code
error()
override;
1636 bool canElideEmptySequence()
override;
1640 void beginDocuments();
1641 bool preflightDocument(
unsigned);
1642 void postflightDocument();
1643 void endDocuments();
1646 void output(StringRef s);
1647 void output(StringRef, QuotingType);
1648 void outputUpToEndOfLine(StringRef s);
1649 void newLineCheck(
bool EmptySequence =
false);
1650 void outputNewLine();
1651 void paddedKey(StringRef key);
1652 void flowKey(StringRef Key);
1657 inFlowSeqFirstElement,
1658 inFlowSeqOtherElement,
1665 static bool inSeqAnyElement(InState State);
1666 static bool inFlowSeqAnyElement(InState State);
1667 static bool inMapAnyKey(InState State);
1668 static bool inFlowMapAnyKey(InState State);
1672 SmallVector<InState, 8> StateStack;
1674 int ColumnAtFlowStart = 0;
1675 int ColumnAtMapFlowStart = 0;
1676 bool NeedBitValueComma =
false;
1677 bool NeedFlowSequenceComma =
false;
1678 bool EnumerationMatchFound =
false;
1679 bool WriteDefaultValues =
false;
1681 StringRef PaddingBeforeContainer;
1684template <
typename T,
typename Context>
1685void IO::processKeyWithDefault(
const char *Key, std::optional<T> &Val,
1686 const std::optional<T> &DefaultValue,
1687 bool Required, Context &Ctx) {
1688 assert(!DefaultValue &&
"std::optional<T> shouldn't have a value!");
1690 bool UseDefault =
true;
1691 const bool sameAsDefault = outputting() && !Val;
1692 if (!outputting() && !Val)
1695 this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) {
1701 bool IsNone =
false;
1703 if (
const auto *
Node =
1704 dyn_cast<ScalarNode>(((Input *)
this)->getCurrentNode()))
1707 IsNone =
Node->getRawValue().rtrim(
' ') ==
"<none>";
1712 yamlize(*
this, *Val, Required, Ctx);
1713 this->postflightKey(SaveInfo);
1728#define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1730 _type() = default; \
1731 _type(const _base v) : value(v) {} \
1732 _type(const _type &v) = default; \
1733 _type &operator=(const _type &rhs) = default; \
1734 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1735 operator const _base & () const { return value; } \
1736 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1737 bool operator==(const _base &rhs) const { return value == rhs; } \
1738 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1740 using BaseType = _base; \
1753struct ScalarTraits<Hex8> {
1754 static void output(
const Hex8 &,
void *, raw_ostream &);
1755 static StringRef input(StringRef,
void *, Hex8 &);
1756 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1760struct ScalarTraits<Hex16> {
1761 static void output(
const Hex16 &,
void *, raw_ostream &);
1762 static StringRef input(StringRef,
void *, Hex16 &);
1763 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1767struct ScalarTraits<Hex32> {
1768 static void output(
const Hex32 &,
void *, raw_ostream &);
1769 static StringRef input(StringRef,
void *, Hex32 &);
1770 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1774struct ScalarTraits<Hex64> {
1775 static void output(
const Hex64 &,
void *, raw_ostream &);
1776 static StringRef input(StringRef,
void *, Hex64 &);
1777 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1780template <>
struct ScalarTraits<VersionTuple> {
1782 static StringRef input(StringRef,
void *, VersionTuple &);
1783 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1787template <
typename T>
1788inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
1792 while ( yin.setCurrentDocument() ) {
1793 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i),
true, Ctx);
1803template <
typename T>
1804inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Input &>
1807 yin.setCurrentDocument();
1808 yamlize(yin, docMap,
true, Ctx);
1814template <
typename T>
1815inline std::enable_if_t<has_SequenceTraits<T>::value, Input &>
1818 if (yin.setCurrentDocument())
1819 yamlize(yin, docSeq,
true, Ctx);
1824template <
typename T>
1825inline std::enable_if_t<has_BlockScalarTraits<T>::value, Input &>
1828 if (
In.setCurrentDocument())
1829 yamlize(In, Val,
true, Ctx);
1834template <
typename T>
1835inline std::enable_if_t<has_CustomMappingTraits<T>::value, Input &>
1838 if (
In.setCurrentDocument())
1839 yamlize(In, Val,
true, Ctx);
1844template <
typename T>
1845inline std::enable_if_t<has_PolymorphicTraits<T>::value, Input &>
1848 if (
In.setCurrentDocument())
1849 yamlize(In, Val,
true, Ctx);
1854template <
typename T>
1855inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Input &>
1857 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1862template <
typename T>
1863inline std::enable_if_t<has_DocumentListTraits<T>::value, Output &>
1866 yout.beginDocuments();
1867 const size_t count = DocumentListTraits<T>::size(yout, docList);
1868 for(
size_t i=0; i <
count; ++i) {
1869 if ( yout.preflightDocument(i) ) {
1870 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i),
true,
1872 yout.postflightDocument();
1875 yout.endDocuments();
1880template <
typename T>
1881inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
1884 yout.beginDocuments();
1885 if ( yout.preflightDocument(0) ) {
1886 yamlize(yout, map,
true, Ctx);
1887 yout.postflightDocument();
1889 yout.endDocuments();
1894template <
typename T>
1895inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
1898 yout.beginDocuments();
1899 if ( yout.preflightDocument(0) ) {
1900 yamlize(yout,
seq,
true, Ctx);
1901 yout.postflightDocument();
1903 yout.endDocuments();
1908template <
typename T>
1909inline std::enable_if_t<has_BlockScalarTraits<T>::value, Output &>
1912 Out.beginDocuments();
1913 if (Out.preflightDocument(0)) {
1914 yamlize(Out, Val,
true, Ctx);
1915 Out.postflightDocument();
1922template <
typename T>
1923inline std::enable_if_t<has_CustomMappingTraits<T>::value, Output &>
1926 Out.beginDocuments();
1927 if (Out.preflightDocument(0)) {
1928 yamlize(Out, Val,
true, Ctx);
1929 Out.postflightDocument();
1937template <
typename T>
1938inline std::enable_if_t<has_PolymorphicTraits<T>::value, Output &>
1941 Out.beginDocuments();
1942 if (Out.preflightDocument(0)) {
1945 assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar &&
"plain scalar documents are not supported");
1946 yamlize(Out, Val,
true, Ctx);
1947 Out.postflightDocument();
1954template <
typename T>
1955inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Output &>
1957 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1961template <
bool B>
struct IsFlowSequenceBase {};
1962template <>
struct IsFlowSequenceBase<
true> {
static const bool flow =
true; };
1964template <
typename T,
typename U =
void>
1965struct IsResizable : std::false_type {};
1967template <
typename T>
1968struct IsResizable<
T,
std::void_t<decltype(std::declval<T>().resize(0))>>
1969 :
public std::true_type {};
1971template <
typename T,
bool B>
struct IsResizableBase {
1972 using type =
typename T::value_type;
1974 static type &element(IO &io,
T &seq,
size_t index) {
1975 if (index >=
seq.size())
1976 seq.resize(index + 1);
1981template <
typename T>
struct IsResizableBase<
T,
false> {
1982 using type =
typename T::value_type;
1984 static type &element(IO &io,
T &seq,
size_t index) {
1985 if (index >=
seq.size()) {
1986 io.setError(Twine(
"value sequence extends beyond static size (") +
1987 Twine(
seq.size()) +
")");
1994template <
typename T,
bool Flow>
1995struct SequenceTraitsImpl
1996 : IsFlowSequenceBase<Flow>, IsResizableBase<T, IsResizable<T>::value> {
1997 static size_t size(IO &io,
T &seq) {
return seq.size(); }
2002template <
bool>
struct CheckIsBool {
static const bool value =
true; };
2006template <
typename T>
2007struct SequenceTraits<
2009 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2010 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
2011template <
typename T,
size_t N>
2012struct SequenceTraits<
2014 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2015 : SequenceTraitsImpl<std::array<T, N>, SequenceElementTraits<T>::flow> {};
2016template <
typename T,
unsigned N>
2017struct SequenceTraits<
2019 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2020 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
2021template <
typename T>
2022struct SequenceTraits<
2024 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2025 : SequenceTraitsImpl<SmallVectorImpl<T>, SequenceElementTraits<T>::flow> {};
2026template <
typename T>
2027struct SequenceTraits<
2029 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2030 : SequenceTraitsImpl<MutableArrayRef<T>, SequenceElementTraits<T>::flow> {};
2033template <
typename T>
2034struct SequenceElementTraits<
T,
std::enable_if_t<std::is_fundamental_v<T>>> {
2035 static const bool flow =
true;
2039template<>
struct SequenceElementTraits<
std::
string> {
2040 static const bool flow =
false;
2042template<>
struct SequenceElementTraits<StringRef> {
2043 static const bool flow =
false;
2045template<>
struct SequenceElementTraits<
std::pair<std::string, std::string>> {
2046 static const bool flow =
false;
2050template <
typename T>
struct StdMapStringCustomMappingTraitsImpl {
2051 using map_type = std::map<std::string, T>;
2053 static void inputOne(IO &io, StringRef key, map_type &v) {
2054 io.mapRequired(key.str().c_str(), v[std::string(key)]);
2057 static void output(IO &io, map_type &v) {
2059 io.mapRequired(
p.first.c_str(),
p.second);
2066#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW) \
2070 !std::is_fundamental_v<TYPE> && !std::is_same_v<TYPE, std::string> && \
2071 !std::is_same_v<TYPE, llvm::StringRef>, \
2072 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
2073 template <> struct SequenceElementTraits<TYPE> { \
2074 static const bool flow = FLOW; \
2081#define LLVM_YAML_IS_SEQUENCE_VECTOR(type) \
2082 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)
2086#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type) \
2087 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)
2089#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type) \
2092 template <> struct LLVM_ABI MappingTraits<Type> { \
2093 static void mapping(IO &IO, Type &Obj); \
2098#define LLVM_YAML_DECLARE_MAPPING_TRAITS_PRIVATE(Type) \
2101 template <> struct MappingTraits<Type> { \
2102 static void mapping(IO &IO, Type &Obj); \
2107#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type) \
2110 template <> struct LLVM_ABI ScalarEnumerationTraits<Type> { \
2111 static void enumeration(IO &io, Type &Value); \
2116#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type) \
2119 template <> struct LLVM_ABI ScalarBitSetTraits<Type> { \
2120 static void bitset(IO &IO, Type &Options); \
2125#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote) \
2128 template <> struct LLVM_ABI ScalarTraits<Type> { \
2129 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
2130 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
2131 static QuotingType mustQuote(StringRef) { return MustQuote; } \
2138#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
2141 template <unsigned N> \
2142 struct DocumentListTraits<SmallVector<_type, N>> \
2143 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
2145 struct DocumentListTraits<std::vector<_type>> \
2146 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
2152#define LLVM_YAML_IS_STRING_MAP(_type) \
2156 struct CustomMappingTraits<std::map<std::string, _type>> \
2157 : 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.