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 ==
"+" || S ==
"-")
573 if (S ==
".nan" || S ==
".NaN" || S ==
".NAN")
577 StringRef
Tail = (S.front() ==
'-' || S.front() ==
'+') ? S.drop_front() : S;
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 ==
"null" || S ==
"Null" || S ==
"NULL" || S ==
"~";
662inline bool isBool(StringRef S) {
664 return S ==
"true" || S ==
"True" || S ==
"TRUE" || S ==
"false" ||
665 S ==
"False" || S ==
"FALSE";
677inline QuotingType needsQuotes(StringRef S,
bool ForcePreserveAsString =
true) {
679 return QuotingType::Single;
681 QuotingType MaxQuotingNeeded = QuotingType::None;
682 if (isSpace(
static_cast<unsigned char>(S.front())) ||
683 isSpace(
static_cast<unsigned char>(S.back())))
684 MaxQuotingNeeded = QuotingType::Single;
685 if (ForcePreserveAsString) {
687 MaxQuotingNeeded = QuotingType::Single;
689 MaxQuotingNeeded = QuotingType::Single;
691 MaxQuotingNeeded = QuotingType::Single;
697 if (std::strchr(R
"(-?:\,[]{}#&*!|>'"%@`)", S[0]) != nullptr)
698 MaxQuotingNeeded = QuotingType::Single;
700 for (
unsigned char C : S) {
721 return QuotingType::Double;
724 return QuotingType::Double;
735 return QuotingType::Double;
739 return QuotingType::Double;
742 MaxQuotingNeeded = QuotingType::Single;
747 return MaxQuotingNeeded;
750template <
typename T,
typename Context>
752 :
public std::integral_constant<bool,
753 !has_ScalarEnumerationTraits<T>::value &&
754 !has_ScalarBitSetTraits<T>::value &&
755 !has_ScalarTraits<T>::value &&
756 !has_BlockScalarTraits<T>::value &&
757 !has_TaggedScalarTraits<T>::value &&
758 !has_MappingTraits<T, Context>::value &&
759 !has_SequenceTraits<T>::value &&
760 !has_CustomMappingTraits<T>::value &&
761 !has_DocumentListTraits<T>::value &&
762 !has_PolymorphicTraits<T>::value> {};
764template <
typename T,
typename Context>
765struct validatedMappingTraits
766 :
public std::integral_constant<
767 bool, has_MappingTraits<T, Context>::value &&
768 has_MappingValidateTraits<T, Context>::value> {};
770template <
typename T,
typename Context>
771struct unvalidatedMappingTraits
772 :
public std::integral_constant<
773 bool, has_MappingTraits<T, Context>::value &&
774 !has_MappingValidateTraits<T, Context>::value> {};
779 IO(
void *Ctxt =
nullptr);
782 virtual bool outputting()
const = 0;
784 virtual unsigned beginSequence() = 0;
785 virtual bool preflightElement(
unsigned,
void *&) = 0;
786 virtual void postflightElement(
void*) = 0;
787 virtual void endSequence() = 0;
788 virtual bool canElideEmptySequence() = 0;
790 virtual unsigned beginFlowSequence() = 0;
791 virtual bool preflightFlowElement(
unsigned,
void *&) = 0;
792 virtual void postflightFlowElement(
void*) = 0;
793 virtual void endFlowSequence() = 0;
795 virtual bool mapTag(StringRef Tag,
bool Default=
false) = 0;
796 virtual void beginMapping() = 0;
797 virtual void endMapping() = 0;
798 virtual bool preflightKey(
const char*,
bool,
bool,
bool &,
void *&) = 0;
799 virtual void postflightKey(
void*) = 0;
800 virtual std::vector<StringRef> keys() = 0;
802 virtual void beginFlowMapping() = 0;
803 virtual void endFlowMapping() = 0;
805 virtual void beginEnumScalar() = 0;
806 virtual bool matchEnumScalar(
const char*,
bool) = 0;
807 virtual bool matchEnumFallback() = 0;
808 virtual void endEnumScalar() = 0;
810 virtual bool beginBitSetScalar(
bool &) = 0;
811 virtual bool bitSetMatch(
const char*,
bool) = 0;
812 virtual void endBitSetScalar() = 0;
814 virtual void scalarString(StringRef &, QuotingType) = 0;
815 virtual void blockScalarString(StringRef &) = 0;
816 virtual void scalarTag(std::string &) = 0;
820 virtual void setError(
const Twine &) = 0;
821 virtual void setAllowUnknownKeys(
bool Allow);
823 template <
typename T>
824 void enumCase(
T &Val,
const char* Str,
const T ConstVal) {
825 if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
831 template <
typename T>
832 void enumCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
833 if ( matchEnumScalar(Str, outputting() && Val ==
static_cast<T>(ConstVal)) ) {
838 template <
typename FBT,
typename T>
839 void enumFallback(
T &Val) {
840 if (matchEnumFallback()) {
841 EmptyContext Context;
843 FBT Res =
static_cast<typename FBT::BaseType
>(Val);
844 yamlize(*
this, Res,
true, Context);
845 Val =
static_cast<T>(
static_cast<typename FBT::BaseType
>(Res));
849 template <
typename T>
850 void bitSetCase(
T &Val,
const char* Str,
const T ConstVal) {
851 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
852 Val =
static_cast<T>(Val | ConstVal);
857 template <
typename T>
858 void bitSetCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
859 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
860 Val =
static_cast<T>(Val | ConstVal);
864 template <
typename T>
865 void maskedBitSetCase(
T &Val,
const char *Str,
T ConstVal,
T Mask) {
866 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
867 Val = Val | ConstVal;
870 template <
typename T>
871 void maskedBitSetCase(
T &Val,
const char *Str,
uint32_t ConstVal,
873 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
874 Val = Val | ConstVal;
877 void *getContext()
const;
878 void setContext(
void *);
880 template <
typename T>
void mapRequired(
const char *Key,
T &Val) {
882 this->processKey(Key, Val,
true, Ctx);
885 template <
typename T,
typename Context>
886 void mapRequired(
const char *Key,
T &Val, Context &Ctx) {
887 this->processKey(Key, Val,
true, Ctx);
890 template <
typename T>
void mapOptional(
const char *Key,
T &Val) {
892 mapOptionalWithContext(Key, Val, Ctx);
895 template <
typename T,
typename DefaultT>
898 mapOptionalWithContext(Key, Val,
Default, Ctx);
901 template <
typename T,
typename Context>
902 std::enable_if_t<has_SequenceTraits<T>::value,
void>
903 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
905 if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
907 this->processKey(Key, Val,
false, Ctx);
910 template <
typename T,
typename Context>
911 void mapOptionalWithContext(
const char *Key, std::optional<T> &Val,
913 this->processKeyWithDefault(Key, Val, std::optional<T>(),
917 template <
typename T,
typename Context>
918 std::enable_if_t<!has_SequenceTraits<T>::value,
void>
919 mapOptionalWithContext(
const char *Key,
T &Val, Context &Ctx) {
920 this->processKey(Key, Val,
false, Ctx);
923 template <
typename T,
typename Context,
typename DefaultT>
924 void mapOptionalWithContext(
const char *Key,
T &Val,
const DefaultT &
Default,
926 static_assert(std::is_convertible<DefaultT, T>::value,
927 "Default type must be implicitly convertible to value type!");
928 this->processKeyWithDefault(Key, Val,
static_cast<const T &
>(
Default),
933 template <
typename T,
typename Context>
934 void processKeyWithDefault(
const char *Key, std::optional<T> &Val,
935 const std::optional<T> &DefaultValue,
936 bool Required, Context &Ctx);
938 template <
typename T,
typename Context>
939 void processKeyWithDefault(
const char *Key,
T &Val,
const T &DefaultValue,
940 bool Required, Context &Ctx) {
943 const bool sameAsDefault = outputting() && Val == DefaultValue;
944 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
946 yamlize(*
this, Val, Required, Ctx);
947 this->postflightKey(SaveInfo);
955 template <
typename T,
typename Context>
956 void processKey(
const char *Key,
T &Val,
bool Required, Context &Ctx) {
959 if ( this->preflightKey(Key, Required,
false, UseDefault, SaveInfo) ) {
960 yamlize(*
this, Val, Required, Ctx);
961 this->postflightKey(SaveInfo);
971template <
typename T,
typename Context>
972void doMapping(IO &io,
T &Val, Context &Ctx) {
973 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
976template <
typename T>
void doMapping(IO &io,
T &Val, EmptyContext &Ctx) {
977 MappingTraits<T>::mapping(io, Val);
983std::enable_if_t<has_ScalarEnumerationTraits<T>::value,
void>
984yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
985 io.beginEnumScalar();
986 ScalarEnumerationTraits<T>::enumeration(io, Val);
991std::enable_if_t<has_ScalarBitSetTraits<T>::value,
void>
992yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
994 if ( io.beginBitSetScalar(DoClear) ) {
997 ScalarBitSetTraits<T>::bitset(io, Val);
998 io.endBitSetScalar();
1002template <
typename T>
1003std::enable_if_t<has_ScalarTraits<T>::value,
void> yamlize(IO &io,
T &Val,
bool,
1004 EmptyContext &Ctx) {
1005 if ( io.outputting() ) {
1006 SmallString<128> Storage;
1007 raw_svector_ostream Buffer(Storage);
1008 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
1009 StringRef Str = Buffer.str();
1010 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1014 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
1015 StringRef
Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
1017 io.setError(Twine(Result));
1022template <
typename T>
1023std::enable_if_t<has_BlockScalarTraits<T>::value,
void>
1024yamlize(IO &
YamlIO,
T &Val,
bool, EmptyContext &Ctx) {
1025 if (
YamlIO.outputting()) {
1026 std::string Storage;
1027 raw_string_ostream Buffer(Storage);
1028 BlockScalarTraits<T>::output(Val,
YamlIO.getContext(), Buffer);
1029 StringRef Str(Storage);
1030 YamlIO.blockScalarString(Str);
1033 YamlIO.blockScalarString(Str);
1035 BlockScalarTraits<T>::input(Str,
YamlIO.getContext(), Val);
1037 YamlIO.setError(Twine(Result));
1041template <
typename T>
1042std::enable_if_t<has_TaggedScalarTraits<T>::value,
void>
1043yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1044 if (io.outputting()) {
1045 std::string ScalarStorage, TagStorage;
1046 raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage);
1047 TaggedScalarTraits<T>::output(Val, io.getContext(), ScalarBuffer,
1049 io.scalarTag(TagStorage);
1050 StringRef ScalarStr(ScalarStorage);
1051 io.scalarString(ScalarStr,
1052 TaggedScalarTraits<T>::mustQuote(Val, ScalarStr));
1057 io.scalarString(Str, QuotingType::None);
1059 TaggedScalarTraits<T>::input(Str,
Tag, io.getContext(), Val);
1061 io.setError(Twine(Result));
1068template <
typename T,
typename Context>
1069std::string doValidate(IO &io,
T &Val, Context &Ctx) {
1070 return MappingContextTraits<T, Context>::validate(io, Val, Ctx);
1073template <
typename T> std::string doValidate(IO &io,
T &Val, EmptyContext &) {
1074 return MappingTraits<T>::validate(io, Val);
1079template <
typename T,
typename Context>
1080std::enable_if_t<validatedMappingTraits<T, Context>::value,
void>
1081yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1082 if (has_FlowTraits<MappingTraits<T>>
::value)
1083 io.beginFlowMapping();
1086 if (io.outputting()) {
1087 std::string Err = detail::doValidate(io, Val, Ctx);
1089 errs() << Err <<
"\n";
1090 assert(Err.empty() &&
"invalid struct trying to be written as yaml");
1093 detail::doMapping(io, Val, Ctx);
1094 if (!io.outputting()) {
1095 std::string Err = detail::doValidate(io, Val, Ctx);
1099 if (has_FlowTraits<MappingTraits<T>>
::value)
1100 io.endFlowMapping();
1105template <
typename T,
typename Context>
1106std::enable_if_t<!has_MappingEnumInputTraits<T, Context>::value,
bool>
1107yamlizeMappingEnumInput(IO &io,
T &Val) {
1111template <
typename T,
typename Context>
1112std::enable_if_t<has_MappingEnumInputTraits<T, Context>::value,
bool>
1113yamlizeMappingEnumInput(IO &io,
T &Val) {
1114 if (io.outputting())
1117 io.beginEnumScalar();
1118 MappingTraits<T>::enumInput(io, Val);
1119 bool Matched = !io.matchEnumFallback();
1124template <
typename T,
typename Context>
1125std::enable_if_t<unvalidatedMappingTraits<T, Context>::value,
void>
1126yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1127 if (yamlizeMappingEnumInput<T, Context>(io, Val))
1129 if (has_FlowTraits<MappingTraits<T>>
::value) {
1130 io.beginFlowMapping();
1131 detail::doMapping(io, Val, Ctx);
1132 io.endFlowMapping();
1135 detail::doMapping(io, Val, Ctx);
1140template <
typename T>
1141std::enable_if_t<has_CustomMappingTraits<T>::value,
void>
1142yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1143 if ( io.outputting() ) {
1145 CustomMappingTraits<T>::output(io, Val);
1149 for (StringRef key : io.keys())
1150 CustomMappingTraits<T>::inputOne(io, key, Val);
1155template <
typename T>
1156std::enable_if_t<has_PolymorphicTraits<T>::value,
void>
1157yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1158 switch (io.outputting() ? PolymorphicTraits<T>::getKind(Val)
1159 : io.getNodeKind()) {
1160 case NodeKind::Scalar:
1161 return yamlize(io, PolymorphicTraits<T>::getAsScalar(Val),
true, Ctx);
1163 return yamlize(io, PolymorphicTraits<T>::getAsMap(Val),
true, Ctx);
1164 case NodeKind::Sequence:
1165 return yamlize(io, PolymorphicTraits<T>::getAsSequence(Val),
true, Ctx);
1169template <
typename T>
1170std::enable_if_t<missingTraits<T, EmptyContext>::value,
void>
1171yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1172 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1175template <
typename T,
typename Context>
1176std::enable_if_t<has_SequenceTraits<T>::value,
void>
1177yamlize(IO &io,
T &Seq,
bool, Context &Ctx) {
1178 if ( has_FlowTraits< SequenceTraits<T>>
::value ) {
1179 unsigned incnt = io.beginFlowSequence();
1180 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1181 for(
unsigned i=0; i <
count; ++i) {
1183 if ( io.preflightFlowElement(i, SaveInfo) ) {
1184 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1185 io.postflightFlowElement(SaveInfo);
1188 io.endFlowSequence();
1191 unsigned incnt = io.beginSequence();
1192 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1193 for(
unsigned i=0; i <
count; ++i) {
1195 if ( io.preflightElement(i, SaveInfo) ) {
1196 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1197 io.postflightElement(SaveInfo);
1205struct ScalarTraits<
bool> {
1206 static void output(
const bool &,
void* , raw_ostream &);
1207 static StringRef input(StringRef,
void *,
bool &);
1208 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1212struct ScalarTraits<StringRef> {
1213 static void output(
const StringRef &,
void *, raw_ostream &);
1214 static StringRef input(StringRef,
void *, StringRef &);
1215 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1220 static void output(
const std::string &,
void *, raw_ostream &);
1221 static StringRef input(StringRef,
void *, std::string &);
1222 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1226struct ScalarTraits<uint8_t> {
1227 static void output(
const uint8_t &,
void *, raw_ostream &);
1228 static StringRef input(StringRef,
void *, uint8_t &);
1229 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1234 static void output(
const uint16_t &,
void *, raw_ostream &);
1235 static StringRef input(StringRef,
void *,
uint16_t &);
1236 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1241 static void output(
const uint32_t &,
void *, raw_ostream &);
1242 static StringRef input(StringRef,
void *,
uint32_t &);
1243 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1248 static void output(
const uint64_t &,
void *, raw_ostream &);
1249 static StringRef input(StringRef,
void *,
uint64_t &);
1250 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1254struct ScalarTraits<int8_t> {
1255 static void output(
const int8_t &,
void *, raw_ostream &);
1256 static StringRef input(StringRef,
void *, int8_t &);
1257 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1261struct ScalarTraits<int16_t> {
1262 static void output(
const int16_t &,
void *, raw_ostream &);
1263 static StringRef input(StringRef,
void *, int16_t &);
1264 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1268struct ScalarTraits<int32_t> {
1269 static void output(
const int32_t &,
void *, raw_ostream &);
1270 static StringRef input(StringRef,
void *, int32_t &);
1271 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1275struct ScalarTraits<int64_t> {
1276 static void output(
const int64_t &,
void *, raw_ostream &);
1277 static StringRef input(StringRef,
void *, int64_t &);
1278 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1282struct ScalarTraits<float> {
1283 static void output(
const float &,
void *, raw_ostream &);
1284 static StringRef input(StringRef,
void *,
float &);
1285 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1289struct ScalarTraits<double> {
1290 static void output(
const double &,
void *, raw_ostream &);
1291 static StringRef input(StringRef,
void *,
double &);
1292 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1298template <
typename value_type, llvm::endianness endian,
size_t alignment>
1299struct ScalarTraits<support::detail::packed_endian_specific_integral<
1300 value_type, endian, alignment>,
1301 std::enable_if_t<has_ScalarTraits<value_type>::value>> {
1303 support::detail::packed_endian_specific_integral<value_type,
endian,
1306 static void output(
const endian_type &
E,
void *Ctx, raw_ostream &Stream) {
1307 ScalarTraits<value_type>::output(
static_cast<value_type
>(
E), Ctx, Stream);
1310 static StringRef input(StringRef Str,
void *Ctx, endian_type &
E) {
1312 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1313 E =
static_cast<endian_type
>(
V);
1317 static QuotingType mustQuote(StringRef Str) {
1318 return ScalarTraits<value_type>::mustQuote(Str);
1322template <
typename value_type, llvm::endianness endian,
size_t alignment>
1323struct ScalarEnumerationTraits<
1324 support::detail::packed_endian_specific_integral<value_type, endian,
1326 std::enable_if_t<has_ScalarEnumerationTraits<value_type>::value>> {
1328 support::detail::packed_endian_specific_integral<value_type,
endian,
1331 static void enumeration(IO &io, endian_type &
E) {
1333 ScalarEnumerationTraits<value_type>::enumeration(io, V);
1338template <
typename value_type, llvm::endianness endian,
size_t alignment>
1339struct ScalarBitSetTraits<
1340 support::detail::packed_endian_specific_integral<value_type, endian,
1342 std::enable_if_t<has_ScalarBitSetTraits<value_type>::value>> {
1344 support::detail::packed_endian_specific_integral<value_type,
endian,
1346 static void bitset(IO &io, endian_type &
E) {
1348 ScalarBitSetTraits<value_type>::bitset(io, V);
1355template <
typename TNorm,
typename TFinal>
1356struct MappingNormalization {
1357 MappingNormalization(IO &i_o, TFinal &Obj)
1358 : io(i_o), BufPtr(nullptr),
Result(Obj) {
1359 if ( io.outputting() ) {
1360 BufPtr =
new (&Buffer) TNorm(io, Obj);
1363 BufPtr =
new (&Buffer) TNorm(io);
1367 ~MappingNormalization() {
1368 if ( ! io.outputting() ) {
1369 Result = BufPtr->denormalize(io);
1374 TNorm* operator->() {
return BufPtr; }
1377 using Storage = AlignedCharArrayUnion<TNorm>;
1387template <
typename TNorm,
typename TFinal>
1388struct MappingNormalizationHeap {
1389 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *
allocator)
1391 if ( io.outputting() ) {
1392 BufPtr =
new (&Buffer) TNorm(io, Obj);
1396 new (BufPtr) TNorm(io);
1398 BufPtr =
new TNorm(io);
1402 ~MappingNormalizationHeap() {
1403 if ( io.outputting() ) {
1407 Result = BufPtr->denormalize(io);
1411 TNorm* operator->() {
return BufPtr; }
1414 using Storage = AlignedCharArrayUnion<TNorm>;
1418 TNorm *BufPtr =
nullptr;
1434class Input :
public IO {
1439 Input(StringRef InputContent,
1440 void *Ctxt =
nullptr,
1442 void *DiagHandlerCtxt =
nullptr);
1443 Input(MemoryBufferRef Input,
1444 void *Ctxt =
nullptr,
1446 void *DiagHandlerCtxt =
nullptr);
1450 std::error_code
error();
1453 bool outputting()
const override;
1454 bool mapTag(StringRef,
bool)
override;
1455 void beginMapping()
override;
1456 void endMapping()
override;
1457 bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&)
override;
1458 void postflightKey(
void *)
override;
1459 std::vector<StringRef> keys()
override;
1460 void beginFlowMapping()
override;
1461 void endFlowMapping()
override;
1462 unsigned beginSequence()
override;
1463 void endSequence()
override;
1464 bool preflightElement(
unsigned index,
void *&)
override;
1465 void postflightElement(
void *)
override;
1466 unsigned beginFlowSequence()
override;
1467 bool preflightFlowElement(
unsigned ,
void *&)
override;
1468 void postflightFlowElement(
void *)
override;
1469 void endFlowSequence()
override;
1470 void beginEnumScalar()
override;
1471 bool matchEnumScalar(
const char*,
bool)
override;
1472 bool matchEnumFallback()
override;
1473 void endEnumScalar()
override;
1474 bool beginBitSetScalar(
bool &)
override;
1475 bool bitSetMatch(
const char *,
bool )
override;
1476 void endBitSetScalar()
override;
1477 void scalarString(StringRef &, QuotingType)
override;
1478 void blockScalarString(StringRef &)
override;
1479 void scalarTag(std::string &)
override;
1481 void setError(
const Twine &message)
override;
1482 bool canElideEmptySequence()
override;
1486 HNode(
Node *n) : _node(n) {}
1488 static bool classof(
const HNode *) {
return true; }
1493 class EmptyHNode :
public HNode {
1495 EmptyHNode(
Node *n) : HNode(n) { }
1497 static bool classof(
const HNode *n) {
return NullNode::classof(n->_node); }
1499 static bool classof(
const EmptyHNode *) {
return true; }
1502 class ScalarHNode :
public HNode {
1504 ScalarHNode(
Node *n, StringRef s) : HNode(n), _value(s) { }
1506 StringRef
value()
const {
return _value; }
1508 static bool classof(
const HNode *n) {
1509 return ScalarNode::classof(n->_node) ||
1510 BlockScalarNode::classof(n->_node);
1513 static bool classof(
const ScalarHNode *) {
return true; }
1519 class MapHNode :
public HNode {
1521 MapHNode(
Node *n) : HNode(n) { }
1523 static bool classof(
const HNode *n) {
1524 return MappingNode::classof(n->_node);
1527 static bool classof(
const MapHNode *) {
return true; }
1529 using NameToNodeAndLoc = StringMap<std::pair<HNode *, SMRange>>;
1531 NameToNodeAndLoc Mapping;
1532 SmallVector<std::string, 6> ValidKeys;
1535 class SequenceHNode :
public HNode {
1537 SequenceHNode(
Node *n) : HNode(n) { }
1539 static bool classof(
const HNode *n) {
1540 return SequenceNode::classof(n->_node);
1543 static bool classof(
const SequenceHNode *) {
return true; }
1545 std::vector<HNode *> Entries;
1548 Input::HNode *createHNodes(
Node *node);
1549 void setError(HNode *hnode,
const Twine &message);
1550 void setError(
Node *node,
const Twine &message);
1551 void setError(
const SMRange &
Range,
const Twine &message);
1553 void reportWarning(HNode *hnode,
const Twine &message);
1554 void reportWarning(
Node *hnode,
const Twine &message);
1555 void reportWarning(
const SMRange &
Range,
const Twine &message);
1558 void releaseHNodeBuffers();
1563 bool setCurrentDocument();
1564 bool nextDocument();
1567 const Node *getCurrentNode()
const;
1569 void setAllowUnknownKeys(
bool Allow)
override;
1573 std::unique_ptr<llvm::yaml::Stream> Strm;
1574 HNode *TopNode =
nullptr;
1577 SpecificBumpPtrAllocator<EmptyHNode> EmptyHNodeAllocator;
1578 SpecificBumpPtrAllocator<ScalarHNode> ScalarHNodeAllocator;
1579 SpecificBumpPtrAllocator<MapHNode> MapHNodeAllocator;
1580 SpecificBumpPtrAllocator<SequenceHNode> SequenceHNodeAllocator;
1581 document_iterator DocIterator;
1583 HNode *CurrentNode =
nullptr;
1584 bool ScalarMatchFound =
false;
1585 bool AllowUnknownKeys =
false;
1592class Output :
public IO {
1594 Output(raw_ostream &,
void *Ctxt =
nullptr,
int WrapColumn = 70);
1602 void setWriteDefaultValues(
bool Write) { WriteDefaultValues =
Write; }
1604 bool outputting()
const override;
1605 bool mapTag(StringRef,
bool)
override;
1606 void beginMapping()
override;
1607 void endMapping()
override;
1608 bool preflightKey(
const char *key,
bool,
bool,
bool &,
void *&)
override;
1609 void postflightKey(
void *)
override;
1610 std::vector<StringRef> keys()
override;
1611 void beginFlowMapping()
override;
1612 void endFlowMapping()
override;
1613 unsigned beginSequence()
override;
1614 void endSequence()
override;
1615 bool preflightElement(
unsigned,
void *&)
override;
1616 void postflightElement(
void *)
override;
1617 unsigned beginFlowSequence()
override;
1618 bool preflightFlowElement(
unsigned,
void *&)
override;
1619 void postflightFlowElement(
void *)
override;
1620 void endFlowSequence()
override;
1621 void beginEnumScalar()
override;
1622 bool matchEnumScalar(
const char*,
bool)
override;
1623 bool matchEnumFallback()
override;
1624 void endEnumScalar()
override;
1625 bool beginBitSetScalar(
bool &)
override;
1626 bool bitSetMatch(
const char *,
bool )
override;
1627 void endBitSetScalar()
override;
1628 void scalarString(StringRef &, QuotingType)
override;
1629 void blockScalarString(StringRef &)
override;
1630 void scalarTag(std::string &)
override;
1632 void setError(
const Twine &message)
override;
1633 bool canElideEmptySequence()
override;
1637 void beginDocuments();
1638 bool preflightDocument(
unsigned);
1639 void postflightDocument();
1640 void endDocuments();
1643 void output(StringRef s);
1644 void output(StringRef, QuotingType);
1645 void outputUpToEndOfLine(StringRef s);
1646 void newLineCheck(
bool EmptySequence =
false);
1647 void outputNewLine();
1648 void paddedKey(StringRef key);
1649 void flowKey(StringRef Key);
1654 inFlowSeqFirstElement,
1655 inFlowSeqOtherElement,
1662 static bool inSeqAnyElement(InState State);
1663 static bool inFlowSeqAnyElement(InState State);
1664 static bool inMapAnyKey(InState State);
1665 static bool inFlowMapAnyKey(InState State);
1669 SmallVector<InState, 8> StateStack;
1671 int ColumnAtFlowStart = 0;
1672 int ColumnAtMapFlowStart = 0;
1673 bool NeedBitValueComma =
false;
1674 bool NeedFlowSequenceComma =
false;
1675 bool EnumerationMatchFound =
false;
1676 bool WriteDefaultValues =
false;
1678 StringRef PaddingBeforeContainer;
1681template <
typename T,
typename Context>
1682void IO::processKeyWithDefault(
const char *Key, std::optional<T> &Val,
1683 const std::optional<T> &DefaultValue,
1684 bool Required, Context &Ctx) {
1685 assert(!DefaultValue &&
"std::optional<T> shouldn't have a value!");
1687 bool UseDefault =
true;
1688 const bool sameAsDefault = outputting() && !Val;
1689 if (!outputting() && !Val)
1692 this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) {
1698 bool IsNone =
false;
1700 if (
const auto *
Node =
1701 dyn_cast<ScalarNode>(((Input *)
this)->getCurrentNode()))
1704 IsNone =
Node->getRawValue().rtrim(
' ') ==
"<none>";
1709 yamlize(*
this, *Val, Required, Ctx);
1710 this->postflightKey(SaveInfo);
1725#define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1727 _type() = default; \
1728 _type(const _base v) : value(v) {} \
1729 _type(const _type &v) = default; \
1730 _type &operator=(const _type &rhs) = default; \
1731 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1732 operator const _base & () const { return value; } \
1733 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1734 bool operator==(const _base &rhs) const { return value == rhs; } \
1735 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1737 using BaseType = _base; \
1750struct ScalarTraits<Hex8> {
1751 static void output(
const Hex8 &,
void *, raw_ostream &);
1752 static StringRef input(StringRef,
void *, Hex8 &);
1753 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1757struct ScalarTraits<Hex16> {
1758 static void output(
const Hex16 &,
void *, raw_ostream &);
1759 static StringRef input(StringRef,
void *, Hex16 &);
1760 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1764struct ScalarTraits<Hex32> {
1765 static void output(
const Hex32 &,
void *, raw_ostream &);
1766 static StringRef input(StringRef,
void *, Hex32 &);
1767 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1771struct ScalarTraits<Hex64> {
1772 static void output(
const Hex64 &,
void *, raw_ostream &);
1773 static StringRef input(StringRef,
void *, Hex64 &);
1774 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1777template <>
struct ScalarTraits<VersionTuple> {
1779 static StringRef input(StringRef,
void *, VersionTuple &);
1780 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1784template <
typename T>
1785inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
1789 while ( yin.setCurrentDocument() ) {
1790 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i),
true, Ctx);
1800template <
typename T>
1801inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Input &>
1804 yin.setCurrentDocument();
1805 yamlize(yin, docMap,
true, Ctx);
1811template <
typename T>
1812inline std::enable_if_t<has_SequenceTraits<T>::value, Input &>
1815 if (yin.setCurrentDocument())
1816 yamlize(yin, docSeq,
true, Ctx);
1821template <
typename T>
1822inline std::enable_if_t<has_BlockScalarTraits<T>::value, Input &>
1825 if (
In.setCurrentDocument())
1826 yamlize(In, Val,
true, Ctx);
1831template <
typename T>
1832inline std::enable_if_t<has_CustomMappingTraits<T>::value, Input &>
1835 if (
In.setCurrentDocument())
1836 yamlize(In, Val,
true, Ctx);
1841template <
typename T>
1842inline std::enable_if_t<has_PolymorphicTraits<T>::value, Input &>
1845 if (
In.setCurrentDocument())
1846 yamlize(In, Val,
true, Ctx);
1851template <
typename T>
1852inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Input &>
1854 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1859template <
typename T>
1860inline std::enable_if_t<has_DocumentListTraits<T>::value, Output &>
1863 yout.beginDocuments();
1864 const size_t count = DocumentListTraits<T>::size(yout, docList);
1865 for(
size_t i=0; i <
count; ++i) {
1866 if ( yout.preflightDocument(i) ) {
1867 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i),
true,
1869 yout.postflightDocument();
1872 yout.endDocuments();
1877template <
typename T>
1878inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
1881 yout.beginDocuments();
1882 if ( yout.preflightDocument(0) ) {
1883 yamlize(yout, map,
true, Ctx);
1884 yout.postflightDocument();
1886 yout.endDocuments();
1891template <
typename T>
1892inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
1895 yout.beginDocuments();
1896 if ( yout.preflightDocument(0) ) {
1897 yamlize(yout,
seq,
true, Ctx);
1898 yout.postflightDocument();
1900 yout.endDocuments();
1905template <
typename T>
1906inline std::enable_if_t<has_BlockScalarTraits<T>::value, Output &>
1909 Out.beginDocuments();
1910 if (Out.preflightDocument(0)) {
1911 yamlize(Out, Val,
true, Ctx);
1912 Out.postflightDocument();
1919template <
typename T>
1920inline std::enable_if_t<has_CustomMappingTraits<T>::value, Output &>
1923 Out.beginDocuments();
1924 if (Out.preflightDocument(0)) {
1925 yamlize(Out, Val,
true, Ctx);
1926 Out.postflightDocument();
1934template <
typename T>
1935inline std::enable_if_t<has_PolymorphicTraits<T>::value, Output &>
1938 Out.beginDocuments();
1939 if (Out.preflightDocument(0)) {
1942 assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar &&
"plain scalar documents are not supported");
1943 yamlize(Out, Val,
true, Ctx);
1944 Out.postflightDocument();
1951template <
typename T>
1952inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Output &>
1954 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1958template <
bool B>
struct IsFlowSequenceBase {};
1959template <>
struct IsFlowSequenceBase<
true> {
static const bool flow =
true; };
1961template <
typename T,
typename U =
void>
1962struct IsResizable : std::false_type {};
1964template <
typename T>
1965struct IsResizable<
T,
std::void_t<decltype(std::declval<T>().resize(0))>>
1966 :
public std::true_type {};
1968template <
typename T,
bool B>
struct IsResizableBase {
1969 using type =
typename T::value_type;
1971 static type &element(IO &io,
T &seq,
size_t index) {
1972 if (index >=
seq.size())
1973 seq.resize(index + 1);
1978template <
typename T>
struct IsResizableBase<
T,
false> {
1979 using type =
typename T::value_type;
1981 static type &element(IO &io,
T &seq,
size_t index) {
1982 if (index >=
seq.size()) {
1983 io.setError(Twine(
"value sequence extends beyond static size (") +
1984 Twine(
seq.size()) +
")");
1991template <
typename T,
bool Flow>
1992struct SequenceTraitsImpl
1993 : IsFlowSequenceBase<Flow>, IsResizableBase<T, IsResizable<T>::value> {
1994 static size_t size(IO &io,
T &seq) {
return seq.size(); }
1999template <
bool>
struct CheckIsBool {
static const bool value =
true; };
2003template <
typename T>
2004struct SequenceTraits<
2006 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2007 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
2008template <
typename T,
unsigned N>
2009struct SequenceTraits<
2011 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2012 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
2013template <
typename T>
2014struct SequenceTraits<
2016 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2017 : SequenceTraitsImpl<SmallVectorImpl<T>, SequenceElementTraits<T>::flow> {};
2018template <
typename T>
2019struct SequenceTraits<
2021 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2022 : SequenceTraitsImpl<MutableArrayRef<T>, SequenceElementTraits<T>::flow> {};
2025template <
typename T>
2026struct SequenceElementTraits<
T,
std::enable_if_t<std::is_fundamental_v<T>>> {
2027 static const bool flow =
true;
2031template<>
struct SequenceElementTraits<
std::
string> {
2032 static const bool flow =
false;
2034template<>
struct SequenceElementTraits<StringRef> {
2035 static const bool flow =
false;
2037template<>
struct SequenceElementTraits<
std::pair<std::string, std::string>> {
2038 static const bool flow =
false;
2042template <
typename T>
struct StdMapStringCustomMappingTraitsImpl {
2043 using map_type = std::map<std::string, T>;
2045 static void inputOne(IO &io, StringRef key, map_type &v) {
2046 io.mapRequired(key.str().c_str(), v[std::string(key)]);
2049 static void output(IO &io, map_type &v) {
2051 io.mapRequired(
p.first.c_str(),
p.second);
2058#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW) \
2062 !std::is_fundamental_v<TYPE> && !std::is_same_v<TYPE, std::string> && \
2063 !std::is_same_v<TYPE, llvm::StringRef>, \
2064 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
2065 template <> struct SequenceElementTraits<TYPE> { \
2066 static const bool flow = FLOW; \
2073#define LLVM_YAML_IS_SEQUENCE_VECTOR(type) \
2074 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)
2078#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type) \
2079 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)
2081#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type) \
2084 template <> struct MappingTraits<Type> { \
2085 static void mapping(IO &IO, Type &Obj); \
2090#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type) \
2093 template <> struct ScalarEnumerationTraits<Type> { \
2094 static void enumeration(IO &io, Type &Value); \
2099#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type) \
2102 template <> struct ScalarBitSetTraits<Type> { \
2103 static void bitset(IO &IO, Type &Options); \
2108#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote) \
2111 template <> struct ScalarTraits<Type> { \
2112 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
2113 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
2114 static QuotingType mustQuote(StringRef) { return MustQuote; } \
2121#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
2124 template <unsigned N> \
2125 struct DocumentListTraits<SmallVector<_type, N>> \
2126 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
2128 struct DocumentListTraits<std::vector<_type>> \
2129 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
2135#define LLVM_YAML_IS_STRING_MAP(_type) \
2139 struct CustomMappingTraits<std::map<std::string, _type>> \
2140 : 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.