9#ifndef LLVM_SUPPORT_YAMLTRAITS_H
10#define LLVM_SUPPORT_YAMLTRAITS_H
32#include <system_error>
48struct EmptyContext {};
84template <
class T,
class Context>
struct MappingContextTraits {
106template <
typename T,
typename Enable =
void>
struct ScalarEnumerationTraits {
122template <
typename T,
typename Enable =
void>
struct ScalarBitSetTraits {
148template <
typename T,
typename Enable =
void>
struct ScalarTraits {
179struct BlockScalarTraits {
215template <
typename T>
struct TaggedScalarTraits {
245template<
typename T,
typename EnableIf =
void>
246struct SequenceTraits {
258template<
typename T,
typename EnableIf =
void>
259struct SequenceElementTraits {
267struct DocumentListTraits {
277struct CustomMappingTraits {
299template <
typename T>
struct PolymorphicTraits {
313struct has_ScalarEnumerationTraits
315 using Signature_enumeration = void (*)(
class IO&,
T&);
317 template <
typename U>
318 static char test(SameType<Signature_enumeration, &U::enumeration>*);
320 template <
typename U>
321 static double test(...);
323 static bool const value =
324 (
sizeof(test<ScalarEnumerationTraits<T>>(
nullptr)) == 1);
329struct has_ScalarBitSetTraits
331 using Signature_bitset = void (*)(
class IO&,
T&);
333 template <
typename U>
334 static char test(SameType<Signature_bitset, &U::bitset>*);
336 template <
typename U>
337 static double test(...);
339 static bool const value = (
sizeof(test<ScalarBitSetTraits<T>>(
nullptr)) == 1);
344struct has_ScalarTraits
346 using Signature_input = StringRef (*)(StringRef,
void*,
T&);
347 using Signature_output = void (*)(
const T&,
void*, raw_ostream&);
348 using Signature_mustQuote = QuotingType (*)(StringRef);
350 template <
typename U>
351 static char test(SameType<Signature_input, &U::input> *,
352 SameType<Signature_output, &U::output> *,
353 SameType<Signature_mustQuote, &U::mustQuote> *);
355 template <
typename U>
356 static double test(...);
358 static bool const value =
359 (
sizeof(test<ScalarTraits<T>>(
nullptr,
nullptr,
nullptr)) == 1);
364struct has_BlockScalarTraits
366 using Signature_input = StringRef (*)(StringRef,
void *,
T &);
367 using Signature_output = void (*)(
const T &,
void *, raw_ostream &);
369 template <
typename U>
370 static char test(SameType<Signature_input, &U::input> *,
371 SameType<Signature_output, &U::output> *);
373 template <
typename U>
374 static double test(...);
376 static bool const value =
377 (
sizeof(test<BlockScalarTraits<T>>(
nullptr,
nullptr)) == 1);
381template <
class T>
struct has_TaggedScalarTraits {
382 using Signature_input = StringRef (*)(StringRef, StringRef,
void *,
T &);
383 using Signature_output = void (*)(
const T &,
void *, raw_ostream &,
385 using Signature_mustQuote = QuotingType (*)(
const T &, StringRef);
387 template <
typename U>
388 static char test(SameType<Signature_input, &U::input> *,
389 SameType<Signature_output, &U::output> *,
390 SameType<Signature_mustQuote, &U::mustQuote> *);
392 template <
typename U>
static double test(...);
394 static bool const value =
395 (
sizeof(test<TaggedScalarTraits<T>>(
nullptr,
nullptr,
nullptr)) == 1);
399template <
class T,
class Context>
struct has_MappingTraits {
400 using Signature_mapping = void (*)(
class IO &,
T &,
Context &);
402 template <
typename U>
403 static char test(SameType<Signature_mapping, &U::mapping>*);
405 template <
typename U>
406 static double test(...);
408 static bool const value =
409 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
413template <
class T>
struct has_MappingTraits<
T, EmptyContext> {
414 using Signature_mapping = void (*)(
class IO &,
T &);
416 template <
typename U>
417 static char test(SameType<Signature_mapping, &U::mapping> *);
419 template <
typename U>
static double test(...);
421 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
425template <
class T,
class Context>
struct has_MappingValidateTraits {
426 using Signature_validate = std::string (*)(
class IO &,
T &,
Context &);
428 template <
typename U>
429 static char test(SameType<Signature_validate, &U::validate>*);
431 template <
typename U>
432 static double test(...);
434 static bool const value =
435 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
439template <
class T>
struct has_MappingValidateTraits<
T, EmptyContext> {
440 using Signature_validate = std::string (*)(
class IO &,
T &);
442 template <
typename U>
443 static char test(SameType<Signature_validate, &U::validate> *);
445 template <
typename U>
static double test(...);
447 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
451template <
class T,
class Context>
struct has_MappingEnumInputTraits {
452 using Signature_validate = void (*)(
class IO &,
T &);
454 template <
typename U>
455 static char test(SameType<Signature_validate, &U::enumInput> *);
457 template <
typename U>
static double test(...);
459 static bool const value =
460 (
sizeof(test<MappingContextTraits<T, Context>>(
nullptr)) == 1);
464template <
class T>
struct has_MappingEnumInputTraits<
T, EmptyContext> {
465 using Signature_validate = void (*)(
class IO &,
T &);
467 template <
typename U>
468 static char test(SameType<Signature_validate, &U::enumInput> *);
470 template <
typename U>
static double test(...);
472 static bool const value = (
sizeof(test<MappingTraits<T>>(
nullptr)) == 1);
477struct has_SequenceMethodTraits
479 using Signature_size = size_t (*)(
class IO&,
T&);
481 template <
typename U>
482 static char test(SameType<Signature_size, &U::size>*);
484 template <
typename U>
485 static double test(...);
487 static bool const value = (
sizeof(test<SequenceTraits<T>>(
nullptr)) == 1);
492struct has_CustomMappingTraits
494 using Signature_input = void (*)(IO &io, StringRef key,
T &
v);
496 template <
typename U>
497 static char test(SameType<Signature_input, &U::inputOne>*);
499 template <
typename U>
500 static double test(...);
502 static bool const value =
503 (
sizeof(test<CustomMappingTraits<T>>(
nullptr)) == 1);
509template <
typename T,
bool Enabled = std::is_
class_v<T>>
class has_FlowTraits {
511 static const bool value =
false;
518struct has_FlowTraits<
T,
true>
524 static char (&
f(SameType<bool Fallback::*, &C::flow>*))[1];
527 static char (&
f(...))[2];
529 static bool const value =
sizeof(f<Derived>(
nullptr)) == 2;
534struct has_SequenceTraits :
public std::integral_constant<bool,
535 has_SequenceMethodTraits<T>::value > { };
539struct has_DocumentListTraits
541 using Signature_size = size_t (*)(
class IO &,
T &);
543 template <
typename U>
544 static char test(SameType<Signature_size, &U::size>*);
546 template <
typename U>
547 static double test(...);
549 static bool const value = (
sizeof(test<DocumentListTraits<T>>(
nullptr))==1);
552template <
class T>
struct has_PolymorphicTraits {
553 using Signature_getKind =
NodeKind (*)(
const T &);
555 template <
typename U>
556 static char test(SameType<Signature_getKind, &U::getKind> *);
558 template <
typename U>
static double test(...);
560 static bool const value = (
sizeof(test<PolymorphicTraits<T>>(
nullptr)) == 1);
563inline bool isNumeric(StringRef S) {
564 const auto skipDigits = [](StringRef Input) {
565 return Input.ltrim(
"0123456789");
570 if (S.empty() || S.equals(
"+") || S.equals(
"-"))
573 if (S.equals(
".nan") || S.equals(
".NaN") || S.equals(
".NAN"))
577 StringRef
Tail = (S.front() ==
'-' || S.front() ==
'+') ? S.drop_front() : S;
581 if (
Tail.equals(
".inf") ||
Tail.equals(
".Inf") ||
Tail.equals(
".INF"))
587 if (S.starts_with(
"0o"))
588 return S.size() > 2 &&
591 if (S.starts_with(
"0x"))
592 return S.size() > 2 && S.drop_front(2).find_first_not_of(
601 if (S.starts_with(
".") &&
603 (S.size() > 1 && std::strchr(
"0123456789", S[1]) ==
nullptr)))
606 if (S.starts_with(
"E") || S.starts_with(
"e"))
622 if (S.front() ==
'.') {
625 }
else if (S.front() ==
'e' || S.front() ==
'E') {
626 State = FoundExponent;
632 if (State == FoundDot) {
637 if (S.front() ==
'e' || S.front() ==
'E') {
638 State = FoundExponent;
645 assert(State == FoundExponent &&
"Should have found exponent at this point.");
649 if (S.front() ==
'+' || S.front() ==
'-') {
655 return skipDigits(S).empty();
658inline bool isNull(StringRef S) {
659 return S.equals(
"null") || S.equals(
"Null") || S.equals(
"NULL") ||
663inline bool isBool(StringRef S) {
665 return S.equals(
"true") || S.equals(
"True") || S.equals(
"TRUE") ||
666 S.equals(
"false") || S.equals(
"False") || S.equals(
"FALSE");
674inline QuotingType needsQuotes(StringRef S) {
676 return QuotingType::Single;
678 QuotingType MaxQuotingNeeded = QuotingType::None;
679 if (isSpace(
static_cast<unsigned char>(S.front())) ||
680 isSpace(
static_cast<unsigned char>(S.back())))
681 MaxQuotingNeeded = QuotingType::Single;
683 MaxQuotingNeeded = QuotingType::Single;
685 MaxQuotingNeeded = QuotingType::Single;
687 MaxQuotingNeeded = QuotingType::Single;
692 if (std::strchr(R
"(-?:\,[]{}#&*!|>'"%@`)", S[0]) != nullptr)
693 MaxQuotingNeeded = QuotingType::Single;
695 for (
unsigned char C : S) {
716 return QuotingType::Double;
719 return QuotingType::Double;
730 return QuotingType::Double;
734 return QuotingType::Double;
737 MaxQuotingNeeded = QuotingType::Single;
742 return MaxQuotingNeeded;
745template <
typename T,
typename Context>
747 :
public std::integral_constant<bool,
748 !has_ScalarEnumerationTraits<T>::value &&
749 !has_ScalarBitSetTraits<T>::value &&
750 !has_ScalarTraits<T>::value &&
751 !has_BlockScalarTraits<T>::value &&
752 !has_TaggedScalarTraits<T>::value &&
753 !has_MappingTraits<T, Context>::value &&
754 !has_SequenceTraits<T>::value &&
755 !has_CustomMappingTraits<T>::value &&
756 !has_DocumentListTraits<T>::value &&
757 !has_PolymorphicTraits<T>::value> {};
759template <
typename T,
typename Context>
760struct validatedMappingTraits
761 :
public std::integral_constant<
762 bool, has_MappingTraits<T, Context>::value &&
763 has_MappingValidateTraits<T, Context>::value> {};
765template <
typename T,
typename Context>
766struct unvalidatedMappingTraits
767 :
public std::integral_constant<
768 bool, has_MappingTraits<T, Context>::value &&
769 !has_MappingValidateTraits<T, Context>::value> {};
774 IO(
void *Ctxt =
nullptr);
777 virtual bool outputting()
const = 0;
779 virtual unsigned beginSequence() = 0;
780 virtual bool preflightElement(
unsigned,
void *&) = 0;
781 virtual void postflightElement(
void*) = 0;
782 virtual void endSequence() = 0;
783 virtual bool canElideEmptySequence() = 0;
785 virtual unsigned beginFlowSequence() = 0;
786 virtual bool preflightFlowElement(
unsigned,
void *&) = 0;
787 virtual void postflightFlowElement(
void*) = 0;
788 virtual void endFlowSequence() = 0;
790 virtual bool mapTag(StringRef Tag,
bool Default=
false) = 0;
791 virtual void beginMapping() = 0;
792 virtual void endMapping() = 0;
793 virtual bool preflightKey(
const char*,
bool,
bool,
bool &,
void *&) = 0;
794 virtual void postflightKey(
void*) = 0;
795 virtual std::vector<StringRef> keys() = 0;
797 virtual void beginFlowMapping() = 0;
798 virtual void endFlowMapping() = 0;
800 virtual void beginEnumScalar() = 0;
801 virtual bool matchEnumScalar(
const char*,
bool) = 0;
802 virtual bool matchEnumFallback() = 0;
803 virtual void endEnumScalar() = 0;
805 virtual bool beginBitSetScalar(
bool &) = 0;
806 virtual bool bitSetMatch(
const char*,
bool) = 0;
807 virtual void endBitSetScalar() = 0;
809 virtual void scalarString(StringRef &, QuotingType) = 0;
810 virtual void blockScalarString(StringRef &) = 0;
811 virtual void scalarTag(std::string &) = 0;
815 virtual void setError(
const Twine &) = 0;
816 virtual void setAllowUnknownKeys(
bool Allow);
818 template <
typename T>
819 void enumCase(
T &Val,
const char* Str,
const T ConstVal) {
820 if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
826 template <
typename T>
827 void enumCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
828 if ( matchEnumScalar(Str, outputting() && Val ==
static_cast<T>(ConstVal)) ) {
833 template <
typename FBT,
typename T>
834 void enumFallback(
T &Val) {
835 if (matchEnumFallback()) {
838 FBT Res =
static_cast<typename FBT::BaseType
>(Val);
839 yamlize(*
this, Res,
true, Context);
840 Val =
static_cast<T>(
static_cast<typename FBT::BaseType
>(Res));
844 template <
typename T>
845 void bitSetCase(
T &Val,
const char* Str,
const T ConstVal) {
846 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
847 Val =
static_cast<T>(Val | ConstVal);
852 template <
typename T>
853 void bitSetCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
854 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
855 Val =
static_cast<T>(Val | ConstVal);
859 template <
typename T>
860 void maskedBitSetCase(
T &Val,
const char *Str,
T ConstVal,
T Mask) {
861 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
862 Val = Val | ConstVal;
865 template <
typename T>
866 void maskedBitSetCase(
T &Val,
const char *Str,
uint32_t ConstVal,
868 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
869 Val = Val | ConstVal;
872 void *getContext()
const;
873 void setContext(
void *);
875 template <
typename T>
void mapRequired(
const char *Key,
T &Val) {
877 this->processKey(Key, Val,
true, Ctx);
880 template <
typename T,
typename Context>
881 void mapRequired(
const char *Key,
T &Val, Context &Ctx) {
882 this->processKey(Key, Val,
true, Ctx);
885 template <
typename T>
void mapOptional(
const char *Key,
T &Val) {
887 mapOptionalWithContext(Key, Val, Ctx);
890 template <
typename T,
typename DefaultT>
893 mapOptionalWithContext(Key, Val,
Default, Ctx);
896 template <
typename T,
typename Context>
897 std::enable_if_t<has_SequenceTraits<T>::value,
void>
898 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
900 if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
902 this->processKey(Key, Val,
false, Ctx);
905 template <
typename T,
typename Context>
906 void mapOptionalWithContext(
const char *Key, std::optional<T> &Val,
908 this->processKeyWithDefault(Key, Val, std::optional<T>(),
912 template <
typename T,
typename Context>
913 std::enable_if_t<!has_SequenceTraits<T>::value,
void>
914 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
915 this->processKey(Key, Val,
false, Ctx);
918 template <
typename T,
typename Context,
typename DefaultT>
919 void mapOptionalWithContext(
const char *Key,
T &Val,
const DefaultT &
Default,
921 static_assert(std::is_convertible<DefaultT, T>::value,
922 "Default type must be implicitly convertible to value type!");
923 this->processKeyWithDefault(Key, Val,
static_cast<const T &
>(
Default),
928 template <
typename T,
typename Context>
929 void processKeyWithDefault(
const char *Key, std::optional<T> &Val,
930 const std::optional<T> &DefaultValue,
931 bool Required, Context &Ctx);
933 template <
typename T,
typename Context>
934 void processKeyWithDefault(
const char *Key,
T &Val,
const T &DefaultValue,
935 bool Required, Context &Ctx) {
938 const bool sameAsDefault = outputting() && Val == DefaultValue;
939 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
941 yamlize(*
this, Val, Required, Ctx);
942 this->postflightKey(SaveInfo);
950 template <
typename T,
typename Context>
951 void processKey(
const char *Key,
T &Val,
bool Required, Context &Ctx) {
954 if ( this->preflightKey(Key, Required,
false, UseDefault, SaveInfo) ) {
955 yamlize(*
this, Val, Required, Ctx);
956 this->postflightKey(SaveInfo);
966template <
typename T,
typename Context>
967void doMapping(IO &io,
T &Val, Context &Ctx) {
968 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
971template <
typename T>
void doMapping(IO &io,
T &Val, EmptyContext &Ctx) {
972 MappingTraits<T>::mapping(io, Val);
978std::enable_if_t<has_ScalarEnumerationTraits<T>::value,
void>
979yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
980 io.beginEnumScalar();
981 ScalarEnumerationTraits<T>::enumeration(io, Val);
986std::enable_if_t<has_ScalarBitSetTraits<T>::value,
void>
987yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
989 if ( io.beginBitSetScalar(DoClear) ) {
992 ScalarBitSetTraits<T>::bitset(io, Val);
993 io.endBitSetScalar();
998std::enable_if_t<has_ScalarTraits<T>::value,
void> yamlize(IO &io,
T &Val,
bool,
1000 if ( io.outputting() ) {
1001 SmallString<128> Storage;
1002 raw_svector_ostream Buffer(Storage);
1003 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
1004 StringRef Str = Buffer.str();
1005 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1009 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1010 StringRef
Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
1012 io.setError(Twine(Result));
1017template <
typename T>
1018std::enable_if_t<has_BlockScalarTraits<T>::value,
void>
1019yamlize(IO &
YamlIO,
T &Val,
bool, EmptyContext &Ctx) {
1020 if (
YamlIO.outputting()) {
1021 std::string Storage;
1022 raw_string_ostream Buffer(Storage);
1023 BlockScalarTraits<T>::output(Val,
YamlIO.getContext(), Buffer);
1024 StringRef Str = Buffer.str();
1025 YamlIO.blockScalarString(Str);
1028 YamlIO.blockScalarString(Str);
1030 BlockScalarTraits<T>::input(Str,
YamlIO.getContext(), Val);
1032 YamlIO.setError(Twine(Result));
1036template <
typename T>
1037std::enable_if_t<has_TaggedScalarTraits<T>::value,
void>
1038yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1039 if (io.outputting()) {
1040 std::string ScalarStorage, TagStorage;
1041 raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage);
1042 TaggedScalarTraits<T>::output(Val, io.getContext(), ScalarBuffer,
1044 io.scalarTag(TagBuffer.str());
1045 StringRef ScalarStr = ScalarBuffer.str();
1046 io.scalarString(ScalarStr,
1047 TaggedScalarTraits<T>::mustQuote(Val, ScalarStr));
1052 io.scalarString(Str, QuotingType::None);
1054 TaggedScalarTraits<T>::input(Str,
Tag, io.getContext(), Val);
1056 io.setError(Twine(Result));
1061template <
typename T,
typename Context>
1062std::enable_if_t<validatedMappingTraits<T, Context>::value,
void>
1063yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1064 if (has_FlowTraits<MappingTraits<T>>
::value)
1065 io.beginFlowMapping();
1068 if (io.outputting()) {
1069 std::string Err = MappingTraits<T>::validate(io, Val);
1071 errs() << Err <<
"\n";
1072 assert(Err.empty() &&
"invalid struct trying to be written as yaml");
1075 detail::doMapping(io, Val, Ctx);
1076 if (!io.outputting()) {
1077 std::string Err = MappingTraits<T>::validate(io, Val);
1081 if (has_FlowTraits<MappingTraits<T>>
::value)
1082 io.endFlowMapping();
1087template <
typename T,
typename Context>
1088std::enable_if_t<!has_MappingEnumInputTraits<T, Context>::value,
bool>
1089yamlizeMappingEnumInput(IO &io,
T &Val) {
1093template <
typename T,
typename Context>
1094std::enable_if_t<has_MappingEnumInputTraits<T, Context>::value,
bool>
1095yamlizeMappingEnumInput(IO &io,
T &Val) {
1096 if (io.outputting())
1099 io.beginEnumScalar();
1100 MappingTraits<T>::enumInput(io, Val);
1101 bool Matched = !io.matchEnumFallback();
1106template <
typename T,
typename Context>
1107std::enable_if_t<unvalidatedMappingTraits<T, Context>::value,
void>
1108yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1109 if (yamlizeMappingEnumInput<T, Context>(io, Val))
1111 if (has_FlowTraits<MappingTraits<T>>
::value) {
1112 io.beginFlowMapping();
1113 detail::doMapping(io, Val, Ctx);
1114 io.endFlowMapping();
1117 detail::doMapping(io, Val, Ctx);
1122template <
typename T>
1123std::enable_if_t<has_CustomMappingTraits<T>::value,
void>
1124yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1125 if ( io.outputting() ) {
1127 CustomMappingTraits<T>::output(io, Val);
1131 for (StringRef key : io.keys())
1132 CustomMappingTraits<T>::inputOne(io, key, Val);
1137template <
typename T>
1138std::enable_if_t<has_PolymorphicTraits<T>::value,
void>
1139yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1140 switch (io.outputting() ? PolymorphicTraits<T>::getKind(Val)
1141 : io.getNodeKind()) {
1142 case NodeKind::Scalar:
1143 return yamlize(io, PolymorphicTraits<T>::getAsScalar(Val),
true, Ctx);
1145 return yamlize(io, PolymorphicTraits<T>::getAsMap(Val),
true, Ctx);
1146 case NodeKind::Sequence:
1147 return yamlize(io, PolymorphicTraits<T>::getAsSequence(Val),
true, Ctx);
1151template <
typename T>
1152std::enable_if_t<missingTraits<T, EmptyContext>::value,
void>
1153yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1154 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1157template <
typename T,
typename Context>
1158std::enable_if_t<has_SequenceTraits<T>::value,
void>
1159yamlize(IO &io,
T &Seq,
bool, Context &Ctx) {
1160 if ( has_FlowTraits< SequenceTraits<T>>
::value ) {
1161 unsigned incnt = io.beginFlowSequence();
1162 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1163 for(
unsigned i=0; i <
count; ++i) {
1165 if ( io.preflightFlowElement(i, SaveInfo) ) {
1166 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1167 io.postflightFlowElement(SaveInfo);
1170 io.endFlowSequence();
1173 unsigned incnt = io.beginSequence();
1174 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1175 for(
unsigned i=0; i <
count; ++i) {
1177 if ( io.preflightElement(i, SaveInfo) ) {
1178 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1179 io.postflightElement(SaveInfo);
1187struct ScalarTraits<
bool> {
1188 static void output(
const bool &,
void* , raw_ostream &);
1189 static StringRef input(StringRef,
void *,
bool &);
1190 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1194struct ScalarTraits<StringRef> {
1195 static void output(
const StringRef &,
void *, raw_ostream &);
1196 static StringRef input(StringRef,
void *, StringRef &);
1197 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1202 static void output(
const std::string &,
void *, raw_ostream &);
1203 static StringRef input(StringRef,
void *, std::string &);
1204 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1208struct ScalarTraits<uint8_t> {
1209 static void output(
const uint8_t &,
void *, raw_ostream &);
1210 static StringRef input(StringRef,
void *, uint8_t &);
1211 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1216 static void output(
const uint16_t &,
void *, raw_ostream &);
1217 static StringRef input(StringRef,
void *,
uint16_t &);
1218 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1223 static void output(
const uint32_t &,
void *, raw_ostream &);
1224 static StringRef input(StringRef,
void *,
uint32_t &);
1225 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1230 static void output(
const uint64_t &,
void *, raw_ostream &);
1231 static StringRef input(StringRef,
void *,
uint64_t &);
1232 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1236struct ScalarTraits<int8_t> {
1237 static void output(
const int8_t &,
void *, raw_ostream &);
1238 static StringRef input(StringRef,
void *, int8_t &);
1239 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1243struct ScalarTraits<int16_t> {
1244 static void output(
const int16_t &,
void *, raw_ostream &);
1245 static StringRef input(StringRef,
void *, int16_t &);
1246 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1250struct ScalarTraits<int32_t> {
1251 static void output(
const int32_t &,
void *, raw_ostream &);
1252 static StringRef input(StringRef,
void *, int32_t &);
1253 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1257struct ScalarTraits<int64_t> {
1258 static void output(
const int64_t &,
void *, raw_ostream &);
1259 static StringRef input(StringRef,
void *, int64_t &);
1260 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1264struct ScalarTraits<float> {
1265 static void output(
const float &,
void *, raw_ostream &);
1266 static StringRef input(StringRef,
void *,
float &);
1267 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1271struct ScalarTraits<double> {
1272 static void output(
const double &,
void *, raw_ostream &);
1273 static StringRef input(StringRef,
void *,
double &);
1274 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1280template <
typename value_type, llvm::endianness endian,
size_t alignment>
1281struct ScalarTraits<support::detail::packed_endian_specific_integral<
1282 value_type, endian, alignment>,
1283 std::enable_if_t<has_ScalarTraits<value_type>::value>> {
1285 support::detail::packed_endian_specific_integral<value_type,
endian,
1288 static void output(
const endian_type &
E,
void *Ctx, raw_ostream &Stream) {
1289 ScalarTraits<value_type>::output(
static_cast<value_type
>(
E), Ctx, Stream);
1292 static StringRef input(StringRef Str,
void *Ctx, endian_type &
E) {
1294 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1295 E =
static_cast<endian_type
>(
V);
1299 static QuotingType mustQuote(StringRef Str) {
1300 return ScalarTraits<value_type>::mustQuote(Str);
1304template <
typename value_type, llvm::endianness endian,
size_t alignment>
1305struct ScalarEnumerationTraits<
1306 support::detail::packed_endian_specific_integral<value_type, endian,
1308 std::enable_if_t<has_ScalarEnumerationTraits<value_type>::value>> {
1310 support::detail::packed_endian_specific_integral<value_type,
endian,
1313 static void enumeration(IO &io, endian_type &
E) {
1315 ScalarEnumerationTraits<value_type>::enumeration(io, V);
1320template <
typename value_type, llvm::endianness endian,
size_t alignment>
1321struct ScalarBitSetTraits<
1322 support::detail::packed_endian_specific_integral<value_type, endian,
1324 std::enable_if_t<has_ScalarBitSetTraits<value_type>::value>> {
1326 support::detail::packed_endian_specific_integral<value_type,
endian,
1328 static void bitset(IO &io, endian_type &
E) {
1330 ScalarBitSetTraits<value_type>::bitset(io, V);
1337template <
typename TNorm,
typename TFinal>
1338struct MappingNormalization {
1339 MappingNormalization(IO &i_o, TFinal &Obj)
1340 : io(i_o), BufPtr(nullptr),
Result(Obj) {
1341 if ( io.outputting() ) {
1342 BufPtr =
new (&Buffer) TNorm(io, Obj);
1345 BufPtr =
new (&Buffer) TNorm(io);
1349 ~MappingNormalization() {
1350 if ( ! io.outputting() ) {
1351 Result = BufPtr->denormalize(io);
1356 TNorm* operator->() {
return BufPtr; }
1359 using Storage = AlignedCharArrayUnion<TNorm>;
1369template <
typename TNorm,
typename TFinal>
1370struct MappingNormalizationHeap {
1371 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *
allocator)
1373 if ( io.outputting() ) {
1374 BufPtr =
new (&Buffer) TNorm(io, Obj);
1378 new (BufPtr) TNorm(io);
1380 BufPtr =
new TNorm(io);
1384 ~MappingNormalizationHeap() {
1385 if ( io.outputting() ) {
1389 Result = BufPtr->denormalize(io);
1393 TNorm* operator->() {
return BufPtr; }
1396 using Storage = AlignedCharArrayUnion<TNorm>;
1400 TNorm *BufPtr =
nullptr;
1416class Input :
public IO {
1421 Input(StringRef InputContent,
1422 void *Ctxt =
nullptr,
1424 void *DiagHandlerCtxt =
nullptr);
1425 Input(MemoryBufferRef Input,
1426 void *Ctxt =
nullptr,
1428 void *DiagHandlerCtxt =
nullptr);
1432 std::error_code
error();
1435 bool outputting()
const override;
1436 bool mapTag(StringRef,
bool)
override;
1437 void beginMapping()
override;
1438 void endMapping()
override;
1439 bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&)
override;
1440 void postflightKey(
void *)
override;
1441 std::vector<StringRef> keys()
override;
1442 void beginFlowMapping()
override;
1443 void endFlowMapping()
override;
1444 unsigned beginSequence()
override;
1445 void endSequence()
override;
1446 bool preflightElement(
unsigned index,
void *&)
override;
1447 void postflightElement(
void *)
override;
1448 unsigned beginFlowSequence()
override;
1449 bool preflightFlowElement(
unsigned ,
void *&)
override;
1450 void postflightFlowElement(
void *)
override;
1451 void endFlowSequence()
override;
1452 void beginEnumScalar()
override;
1453 bool matchEnumScalar(
const char*,
bool)
override;
1454 bool matchEnumFallback()
override;
1455 void endEnumScalar()
override;
1456 bool beginBitSetScalar(
bool &)
override;
1457 bool bitSetMatch(
const char *,
bool )
override;
1458 void endBitSetScalar()
override;
1459 void scalarString(StringRef &, QuotingType)
override;
1460 void blockScalarString(StringRef &)
override;
1461 void scalarTag(std::string &)
override;
1463 void setError(
const Twine &message)
override;
1464 bool canElideEmptySequence()
override;
1468 HNode(
Node *n) : _node(n) {}
1470 static bool classof(
const HNode *) {
return true; }
1475 class EmptyHNode :
public HNode {
1477 EmptyHNode(
Node *n) : HNode(n) { }
1479 static bool classof(
const HNode *n) {
return NullNode::classof(n->_node); }
1481 static bool classof(
const EmptyHNode *) {
return true; }
1484 class ScalarHNode :
public HNode {
1486 ScalarHNode(
Node *n, StringRef s) : HNode(n), _value(s) { }
1488 StringRef
value()
const {
return _value; }
1490 static bool classof(
const HNode *n) {
1491 return ScalarNode::classof(n->_node) ||
1492 BlockScalarNode::classof(n->_node);
1495 static bool classof(
const ScalarHNode *) {
return true; }
1501 class MapHNode :
public HNode {
1503 MapHNode(
Node *n) : HNode(n) { }
1505 static bool classof(
const HNode *n) {
1506 return MappingNode::classof(n->_node);
1509 static bool classof(
const MapHNode *) {
return true; }
1511 using NameToNodeAndLoc = StringMap<std::pair<HNode *, SMRange>>;
1513 NameToNodeAndLoc Mapping;
1514 SmallVector<std::string, 6> ValidKeys;
1517 class SequenceHNode :
public HNode {
1519 SequenceHNode(
Node *n) : HNode(n) { }
1521 static bool classof(
const HNode *n) {
1522 return SequenceNode::classof(n->_node);
1525 static bool classof(
const SequenceHNode *) {
return true; }
1527 std::vector<HNode *> Entries;
1530 Input::HNode *createHNodes(
Node *node);
1531 void setError(HNode *hnode,
const Twine &message);
1532 void setError(
Node *node,
const Twine &message);
1533 void setError(
const SMRange &Range,
const Twine &message);
1535 void reportWarning(HNode *hnode,
const Twine &message);
1536 void reportWarning(
Node *hnode,
const Twine &message);
1537 void reportWarning(
const SMRange &Range,
const Twine &message);
1540 void releaseHNodeBuffers();
1545 bool setCurrentDocument();
1546 bool nextDocument();
1549 const Node *getCurrentNode()
const;
1551 void setAllowUnknownKeys(
bool Allow)
override;
1555 std::unique_ptr<llvm::yaml::Stream> Strm;
1556 HNode *TopNode =
nullptr;
1559 SpecificBumpPtrAllocator<EmptyHNode> EmptyHNodeAllocator;
1560 SpecificBumpPtrAllocator<ScalarHNode> ScalarHNodeAllocator;
1561 SpecificBumpPtrAllocator<MapHNode> MapHNodeAllocator;
1562 SpecificBumpPtrAllocator<SequenceHNode> SequenceHNodeAllocator;
1563 document_iterator DocIterator;
1565 HNode *CurrentNode =
nullptr;
1566 bool ScalarMatchFound =
false;
1567 bool AllowUnknownKeys =
false;
1574class Output :
public IO {
1576 Output(raw_ostream &,
void *Ctxt =
nullptr,
int WrapColumn = 70);
1584 void setWriteDefaultValues(
bool Write) { WriteDefaultValues =
Write; }
1586 bool outputting()
const override;
1587 bool mapTag(StringRef,
bool)
override;
1588 void beginMapping()
override;
1589 void endMapping()
override;
1590 bool preflightKey(
const char *key,
bool,
bool,
bool &,
void *&)
override;
1591 void postflightKey(
void *)
override;
1592 std::vector<StringRef> keys()
override;
1593 void beginFlowMapping()
override;
1594 void endFlowMapping()
override;
1595 unsigned beginSequence()
override;
1596 void endSequence()
override;
1597 bool preflightElement(
unsigned,
void *&)
override;
1598 void postflightElement(
void *)
override;
1599 unsigned beginFlowSequence()
override;
1600 bool preflightFlowElement(
unsigned,
void *&)
override;
1601 void postflightFlowElement(
void *)
override;
1602 void endFlowSequence()
override;
1603 void beginEnumScalar()
override;
1604 bool matchEnumScalar(
const char*,
bool)
override;
1605 bool matchEnumFallback()
override;
1606 void endEnumScalar()
override;
1607 bool beginBitSetScalar(
bool &)
override;
1608 bool bitSetMatch(
const char *,
bool )
override;
1609 void endBitSetScalar()
override;
1610 void scalarString(StringRef &, QuotingType)
override;
1611 void blockScalarString(StringRef &)
override;
1612 void scalarTag(std::string &)
override;
1614 void setError(
const Twine &message)
override;
1615 bool canElideEmptySequence()
override;
1619 void beginDocuments();
1620 bool preflightDocument(
unsigned);
1621 void postflightDocument();
1622 void endDocuments();
1625 void output(StringRef s);
1626 void outputUpToEndOfLine(StringRef s);
1627 void newLineCheck(
bool EmptySequence =
false);
1628 void outputNewLine();
1629 void paddedKey(StringRef key);
1630 void flowKey(StringRef Key);
1635 inFlowSeqFirstElement,
1636 inFlowSeqOtherElement,
1643 static bool inSeqAnyElement(InState State);
1644 static bool inFlowSeqAnyElement(InState State);
1645 static bool inMapAnyKey(InState State);
1646 static bool inFlowMapAnyKey(InState State);
1650 SmallVector<InState, 8> StateStack;
1652 int ColumnAtFlowStart = 0;
1653 int ColumnAtMapFlowStart = 0;
1654 bool NeedBitValueComma =
false;
1655 bool NeedFlowSequenceComma =
false;
1656 bool EnumerationMatchFound =
false;
1657 bool WriteDefaultValues =
false;
1659 StringRef PaddingBeforeContainer;
1662template <
typename T,
typename Context>
1663void IO::processKeyWithDefault(
const char *Key, std::optional<T> &Val,
1664 const std::optional<T> &DefaultValue,
1665 bool Required, Context &Ctx) {
1666 assert(!DefaultValue &&
"std::optional<T> shouldn't have a value!");
1668 bool UseDefault =
true;
1669 const bool sameAsDefault = outputting() && !Val;
1670 if (!outputting() && !Val)
1673 this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) {
1679 bool IsNone =
false;
1681 if (
const auto *
Node =
1682 dyn_cast<ScalarNode>(((Input *)
this)->getCurrentNode()))
1685 IsNone =
Node->getRawValue().rtrim(
' ') ==
"<none>";
1690 yamlize(*
this, *Val, Required, Ctx);
1691 this->postflightKey(SaveInfo);
1706#define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1708 _type() = default; \
1709 _type(const _base v) : value(v) {} \
1710 _type(const _type &v) = default; \
1711 _type &operator=(const _type &rhs) = default; \
1712 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1713 operator const _base & () const { return value; } \
1714 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1715 bool operator==(const _base &rhs) const { return value == rhs; } \
1716 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1718 using BaseType = _base; \
1731struct ScalarTraits<Hex8> {
1732 static void output(
const Hex8 &,
void *, raw_ostream &);
1733 static StringRef input(StringRef,
void *, Hex8 &);
1734 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1738struct ScalarTraits<Hex16> {
1739 static void output(
const Hex16 &,
void *, raw_ostream &);
1740 static StringRef input(StringRef,
void *, Hex16 &);
1741 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1745struct ScalarTraits<Hex32> {
1746 static void output(
const Hex32 &,
void *, raw_ostream &);
1747 static StringRef input(StringRef,
void *, Hex32 &);
1748 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1752struct ScalarTraits<Hex64> {
1753 static void output(
const Hex64 &,
void *, raw_ostream &);
1754 static StringRef input(StringRef,
void *, Hex64 &);
1755 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1758template <>
struct ScalarTraits<VersionTuple> {
1760 static StringRef input(StringRef,
void *, VersionTuple &);
1761 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1765template <
typename T>
1766inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
1770 while ( yin.setCurrentDocument() ) {
1771 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i),
true, Ctx);
1781template <
typename T>
1782inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Input &>
1785 yin.setCurrentDocument();
1786 yamlize(yin, docMap,
true, Ctx);
1792template <
typename T>
1793inline std::enable_if_t<has_SequenceTraits<T>::value, Input &>
1796 if (yin.setCurrentDocument())
1797 yamlize(yin, docSeq,
true, Ctx);
1802template <
typename T>
1803inline std::enable_if_t<has_BlockScalarTraits<T>::value, Input &>
1806 if (
In.setCurrentDocument())
1807 yamlize(In, Val,
true, Ctx);
1812template <
typename T>
1813inline std::enable_if_t<has_CustomMappingTraits<T>::value, Input &>
1816 if (
In.setCurrentDocument())
1817 yamlize(In, Val,
true, Ctx);
1822template <
typename T>
1823inline std::enable_if_t<has_PolymorphicTraits<T>::value, Input &>
1826 if (
In.setCurrentDocument())
1827 yamlize(In, Val,
true, Ctx);
1832template <
typename T>
1833inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Input &>
1835 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1840template <
typename T>
1841inline std::enable_if_t<has_DocumentListTraits<T>::value, Output &>
1844 yout.beginDocuments();
1845 const size_t count = DocumentListTraits<T>::size(yout, docList);
1846 for(
size_t i=0; i <
count; ++i) {
1847 if ( yout.preflightDocument(i) ) {
1848 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i),
true,
1850 yout.postflightDocument();
1853 yout.endDocuments();
1858template <
typename T>
1859inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
1862 yout.beginDocuments();
1863 if ( yout.preflightDocument(0) ) {
1864 yamlize(yout, map,
true, Ctx);
1865 yout.postflightDocument();
1867 yout.endDocuments();
1872template <
typename T>
1873inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
1876 yout.beginDocuments();
1877 if ( yout.preflightDocument(0) ) {
1878 yamlize(yout,
seq,
true, Ctx);
1879 yout.postflightDocument();
1881 yout.endDocuments();
1886template <
typename T>
1887inline std::enable_if_t<has_BlockScalarTraits<T>::value, Output &>
1890 Out.beginDocuments();
1891 if (Out.preflightDocument(0)) {
1892 yamlize(Out, Val,
true, Ctx);
1893 Out.postflightDocument();
1900template <
typename T>
1901inline std::enable_if_t<has_CustomMappingTraits<T>::value, Output &>
1904 Out.beginDocuments();
1905 if (Out.preflightDocument(0)) {
1906 yamlize(Out, Val,
true, Ctx);
1907 Out.postflightDocument();
1915template <
typename T>
1916inline std::enable_if_t<has_PolymorphicTraits<T>::value, Output &>
1919 Out.beginDocuments();
1920 if (Out.preflightDocument(0)) {
1923 assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar &&
"plain scalar documents are not supported");
1924 yamlize(Out, Val,
true, Ctx);
1925 Out.postflightDocument();
1932template <
typename T>
1933inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Output &>
1935 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1939template <
bool B>
struct IsFlowSequenceBase {};
1940template <>
struct IsFlowSequenceBase<
true> {
static const bool flow =
true; };
1942template <
typename T,
typename U =
void>
1943struct IsResizable : std::false_type {};
1945template <
typename T>
1946struct IsResizable<
T,
std::void_t<decltype(std::declval<T>().resize(0))>>
1947 :
public std::true_type {};
1949template <
typename T,
bool B>
struct IsResizableBase {
1950 using type =
typename T::value_type;
1952 static type &element(IO &io,
T &seq,
size_t index) {
1953 if (index >=
seq.size())
1954 seq.resize(index + 1);
1959template <
typename T>
struct IsResizableBase<
T,
false> {
1960 using type =
typename T::value_type;
1962 static type &element(IO &io,
T &seq,
size_t index) {
1963 if (index >=
seq.size()) {
1964 io.setError(Twine(
"value sequence extends beyond static size (") +
1965 Twine(
seq.size()) +
")");
1972template <
typename T,
bool Flow>
1973struct SequenceTraitsImpl
1974 : IsFlowSequenceBase<Flow>, IsResizableBase<T, IsResizable<T>::value> {
1975 static size_t size(IO &io,
T &seq) {
return seq.size(); }
1980template <
bool>
struct CheckIsBool {
static const bool value =
true; };
1984template <
typename T>
1985struct SequenceTraits<
1987 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1988 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
1989template <
typename T,
unsigned N>
1990struct SequenceTraits<
1992 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1993 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
1994template <
typename T>
1995struct SequenceTraits<
1997 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
1998 : SequenceTraitsImpl<SmallVectorImpl<T>, SequenceElementTraits<T>::flow> {};
1999template <
typename T>
2000struct SequenceTraits<
2002 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2003 : SequenceTraitsImpl<MutableArrayRef<T>, SequenceElementTraits<T>::flow> {};
2006template <
typename T>
2007struct SequenceElementTraits<
T,
std::enable_if_t<std::is_fundamental_v<T>>> {
2008 static const bool flow =
true;
2012template<>
struct SequenceElementTraits<
std::
string> {
2013 static const bool flow =
false;
2015template<>
struct SequenceElementTraits<StringRef> {
2016 static const bool flow =
false;
2018template<>
struct SequenceElementTraits<
std::pair<std::string, std::string>> {
2019 static const bool flow =
false;
2023template <
typename T>
struct StdMapStringCustomMappingTraitsImpl {
2024 using map_type = std::map<std::string, T>;
2026 static void inputOne(IO &io, StringRef key, map_type &v) {
2027 io.mapRequired(key.str().c_str(), v[std::string(key)]);
2030 static void output(IO &io, map_type &v) {
2032 io.mapRequired(
p.first.c_str(),
p.second);
2039#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW) \
2043 !std::is_fundamental_v<TYPE> && !std::is_same_v<TYPE, std::string> && \
2044 !std::is_same_v<TYPE, llvm::StringRef>, \
2045 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
2046 template <> struct SequenceElementTraits<TYPE> { \
2047 static const bool flow = FLOW; \
2054#define LLVM_YAML_IS_SEQUENCE_VECTOR(type) \
2055 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)
2059#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type) \
2060 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)
2062#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type) \
2065 template <> struct MappingTraits<Type> { \
2066 static void mapping(IO &IO, Type &Obj); \
2071#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type) \
2074 template <> struct ScalarEnumerationTraits<Type> { \
2075 static void enumeration(IO &io, Type &Value); \
2080#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type) \
2083 template <> struct ScalarBitSetTraits<Type> { \
2084 static void bitset(IO &IO, Type &Options); \
2089#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote) \
2092 template <> struct ScalarTraits<Type> { \
2093 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
2094 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
2095 static QuotingType mustQuote(StringRef) { return MustQuote; } \
2102#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
2105 template <unsigned N> \
2106 struct DocumentListTraits<SmallVector<_type, N>> \
2107 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
2109 struct DocumentListTraits<std::vector<_type>> \
2110 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
2116#define LLVM_YAML_IS_STRING_MAP(_type) \
2120 struct CustomMappingTraits<std::map<std::string, _type>> \
2121 : 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.
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.