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));
1063template <
typename T,
typename Context>
1064std::string doValidate(IO &io,
T &Val, Context &Ctx) {
1065 return MappingContextTraits<T, Context>::validate(io, Val, Ctx);
1068template <
typename T> std::string doValidate(IO &io,
T &Val, EmptyContext &) {
1069 return MappingTraits<T>::validate(io, Val);
1074template <
typename T,
typename Context>
1075std::enable_if_t<validatedMappingTraits<T, Context>::value,
void>
1076yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1077 if (has_FlowTraits<MappingTraits<T>>
::value)
1078 io.beginFlowMapping();
1081 if (io.outputting()) {
1082 std::string Err = detail::doValidate(io, Val, Ctx);
1084 errs() << Err <<
"\n";
1085 assert(Err.empty() &&
"invalid struct trying to be written as yaml");
1088 detail::doMapping(io, Val, Ctx);
1089 if (!io.outputting()) {
1090 std::string Err = detail::doValidate(io, Val, Ctx);
1094 if (has_FlowTraits<MappingTraits<T>>
::value)
1095 io.endFlowMapping();
1100template <
typename T,
typename Context>
1101std::enable_if_t<!has_MappingEnumInputTraits<T, Context>::value,
bool>
1102yamlizeMappingEnumInput(IO &io,
T &Val) {
1106template <
typename T,
typename Context>
1107std::enable_if_t<has_MappingEnumInputTraits<T, Context>::value,
bool>
1108yamlizeMappingEnumInput(IO &io,
T &Val) {
1109 if (io.outputting())
1112 io.beginEnumScalar();
1113 MappingTraits<T>::enumInput(io, Val);
1114 bool Matched = !io.matchEnumFallback();
1119template <
typename T,
typename Context>
1120std::enable_if_t<unvalidatedMappingTraits<T, Context>::value,
void>
1121yamlize(IO &io,
T &Val,
bool, Context &Ctx) {
1122 if (yamlizeMappingEnumInput<T, Context>(io, Val))
1124 if (has_FlowTraits<MappingTraits<T>>
::value) {
1125 io.beginFlowMapping();
1126 detail::doMapping(io, Val, Ctx);
1127 io.endFlowMapping();
1130 detail::doMapping(io, Val, Ctx);
1135template <
typename T>
1136std::enable_if_t<has_CustomMappingTraits<T>::value,
void>
1137yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1138 if ( io.outputting() ) {
1140 CustomMappingTraits<T>::output(io, Val);
1144 for (StringRef key : io.keys())
1145 CustomMappingTraits<T>::inputOne(io, key, Val);
1150template <
typename T>
1151std::enable_if_t<has_PolymorphicTraits<T>::value,
void>
1152yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1153 switch (io.outputting() ? PolymorphicTraits<T>::getKind(Val)
1154 : io.getNodeKind()) {
1155 case NodeKind::Scalar:
1156 return yamlize(io, PolymorphicTraits<T>::getAsScalar(Val),
true, Ctx);
1158 return yamlize(io, PolymorphicTraits<T>::getAsMap(Val),
true, Ctx);
1159 case NodeKind::Sequence:
1160 return yamlize(io, PolymorphicTraits<T>::getAsSequence(Val),
true, Ctx);
1164template <
typename T>
1165std::enable_if_t<missingTraits<T, EmptyContext>::value,
void>
1166yamlize(IO &io,
T &Val,
bool, EmptyContext &Ctx) {
1167 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1170template <
typename T,
typename Context>
1171std::enable_if_t<has_SequenceTraits<T>::value,
void>
1172yamlize(IO &io,
T &Seq,
bool, Context &Ctx) {
1173 if ( has_FlowTraits< SequenceTraits<T>>
::value ) {
1174 unsigned incnt = io.beginFlowSequence();
1175 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1176 for(
unsigned i=0; i <
count; ++i) {
1178 if ( io.preflightFlowElement(i, SaveInfo) ) {
1179 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1180 io.postflightFlowElement(SaveInfo);
1183 io.endFlowSequence();
1186 unsigned incnt = io.beginSequence();
1187 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
1188 for(
unsigned i=0; i <
count; ++i) {
1190 if ( io.preflightElement(i, SaveInfo) ) {
1191 yamlize(io, SequenceTraits<T>::element(io, Seq, i),
true, Ctx);
1192 io.postflightElement(SaveInfo);
1200struct ScalarTraits<
bool> {
1201 static void output(
const bool &,
void* , raw_ostream &);
1202 static StringRef input(StringRef,
void *,
bool &);
1203 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1207struct ScalarTraits<StringRef> {
1208 static void output(
const StringRef &,
void *, raw_ostream &);
1209 static StringRef input(StringRef,
void *, StringRef &);
1210 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1215 static void output(
const std::string &,
void *, raw_ostream &);
1216 static StringRef input(StringRef,
void *, std::string &);
1217 static QuotingType mustQuote(StringRef S) {
return needsQuotes(S); }
1221struct ScalarTraits<uint8_t> {
1222 static void output(
const uint8_t &,
void *, raw_ostream &);
1223 static StringRef input(StringRef,
void *, uint8_t &);
1224 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1229 static void output(
const uint16_t &,
void *, raw_ostream &);
1230 static StringRef input(StringRef,
void *,
uint16_t &);
1231 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1236 static void output(
const uint32_t &,
void *, raw_ostream &);
1237 static StringRef input(StringRef,
void *,
uint32_t &);
1238 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1243 static void output(
const uint64_t &,
void *, raw_ostream &);
1244 static StringRef input(StringRef,
void *,
uint64_t &);
1245 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1249struct ScalarTraits<int8_t> {
1250 static void output(
const int8_t &,
void *, raw_ostream &);
1251 static StringRef input(StringRef,
void *, int8_t &);
1252 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1256struct ScalarTraits<int16_t> {
1257 static void output(
const int16_t &,
void *, raw_ostream &);
1258 static StringRef input(StringRef,
void *, int16_t &);
1259 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1263struct ScalarTraits<int32_t> {
1264 static void output(
const int32_t &,
void *, raw_ostream &);
1265 static StringRef input(StringRef,
void *, int32_t &);
1266 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1270struct ScalarTraits<int64_t> {
1271 static void output(
const int64_t &,
void *, raw_ostream &);
1272 static StringRef input(StringRef,
void *, int64_t &);
1273 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1277struct ScalarTraits<float> {
1278 static void output(
const float &,
void *, raw_ostream &);
1279 static StringRef input(StringRef,
void *,
float &);
1280 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1284struct ScalarTraits<double> {
1285 static void output(
const double &,
void *, raw_ostream &);
1286 static StringRef input(StringRef,
void *,
double &);
1287 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1293template <
typename value_type, llvm::endianness endian,
size_t alignment>
1294struct ScalarTraits<support::detail::packed_endian_specific_integral<
1295 value_type, endian, alignment>,
1296 std::enable_if_t<has_ScalarTraits<value_type>::value>> {
1298 support::detail::packed_endian_specific_integral<value_type,
endian,
1301 static void output(
const endian_type &
E,
void *Ctx, raw_ostream &Stream) {
1302 ScalarTraits<value_type>::output(
static_cast<value_type
>(
E), Ctx, Stream);
1305 static StringRef input(StringRef Str,
void *Ctx, endian_type &
E) {
1307 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1308 E =
static_cast<endian_type
>(
V);
1312 static QuotingType mustQuote(StringRef Str) {
1313 return ScalarTraits<value_type>::mustQuote(Str);
1317template <
typename value_type, llvm::endianness endian,
size_t alignment>
1318struct ScalarEnumerationTraits<
1319 support::detail::packed_endian_specific_integral<value_type, endian,
1321 std::enable_if_t<has_ScalarEnumerationTraits<value_type>::value>> {
1323 support::detail::packed_endian_specific_integral<value_type,
endian,
1326 static void enumeration(IO &io, endian_type &
E) {
1328 ScalarEnumerationTraits<value_type>::enumeration(io, V);
1333template <
typename value_type, llvm::endianness endian,
size_t alignment>
1334struct ScalarBitSetTraits<
1335 support::detail::packed_endian_specific_integral<value_type, endian,
1337 std::enable_if_t<has_ScalarBitSetTraits<value_type>::value>> {
1339 support::detail::packed_endian_specific_integral<value_type,
endian,
1341 static void bitset(IO &io, endian_type &
E) {
1343 ScalarBitSetTraits<value_type>::bitset(io, V);
1350template <
typename TNorm,
typename TFinal>
1351struct MappingNormalization {
1352 MappingNormalization(IO &i_o, TFinal &Obj)
1353 : io(i_o), BufPtr(nullptr),
Result(Obj) {
1354 if ( io.outputting() ) {
1355 BufPtr =
new (&Buffer) TNorm(io, Obj);
1358 BufPtr =
new (&Buffer) TNorm(io);
1362 ~MappingNormalization() {
1363 if ( ! io.outputting() ) {
1364 Result = BufPtr->denormalize(io);
1369 TNorm* operator->() {
return BufPtr; }
1372 using Storage = AlignedCharArrayUnion<TNorm>;
1382template <
typename TNorm,
typename TFinal>
1383struct MappingNormalizationHeap {
1384 MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *
allocator)
1386 if ( io.outputting() ) {
1387 BufPtr =
new (&Buffer) TNorm(io, Obj);
1391 new (BufPtr) TNorm(io);
1393 BufPtr =
new TNorm(io);
1397 ~MappingNormalizationHeap() {
1398 if ( io.outputting() ) {
1402 Result = BufPtr->denormalize(io);
1406 TNorm* operator->() {
return BufPtr; }
1409 using Storage = AlignedCharArrayUnion<TNorm>;
1413 TNorm *BufPtr =
nullptr;
1429class Input :
public IO {
1434 Input(StringRef InputContent,
1435 void *Ctxt =
nullptr,
1437 void *DiagHandlerCtxt =
nullptr);
1438 Input(MemoryBufferRef Input,
1439 void *Ctxt =
nullptr,
1441 void *DiagHandlerCtxt =
nullptr);
1445 std::error_code
error();
1448 bool outputting()
const override;
1449 bool mapTag(StringRef,
bool)
override;
1450 void beginMapping()
override;
1451 void endMapping()
override;
1452 bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&)
override;
1453 void postflightKey(
void *)
override;
1454 std::vector<StringRef> keys()
override;
1455 void beginFlowMapping()
override;
1456 void endFlowMapping()
override;
1457 unsigned beginSequence()
override;
1458 void endSequence()
override;
1459 bool preflightElement(
unsigned index,
void *&)
override;
1460 void postflightElement(
void *)
override;
1461 unsigned beginFlowSequence()
override;
1462 bool preflightFlowElement(
unsigned ,
void *&)
override;
1463 void postflightFlowElement(
void *)
override;
1464 void endFlowSequence()
override;
1465 void beginEnumScalar()
override;
1466 bool matchEnumScalar(
const char*,
bool)
override;
1467 bool matchEnumFallback()
override;
1468 void endEnumScalar()
override;
1469 bool beginBitSetScalar(
bool &)
override;
1470 bool bitSetMatch(
const char *,
bool )
override;
1471 void endBitSetScalar()
override;
1472 void scalarString(StringRef &, QuotingType)
override;
1473 void blockScalarString(StringRef &)
override;
1474 void scalarTag(std::string &)
override;
1476 void setError(
const Twine &message)
override;
1477 bool canElideEmptySequence()
override;
1481 HNode(
Node *n) : _node(n) {}
1483 static bool classof(
const HNode *) {
return true; }
1488 class EmptyHNode :
public HNode {
1490 EmptyHNode(
Node *n) : HNode(n) { }
1492 static bool classof(
const HNode *n) {
return NullNode::classof(n->_node); }
1494 static bool classof(
const EmptyHNode *) {
return true; }
1497 class ScalarHNode :
public HNode {
1499 ScalarHNode(
Node *n, StringRef s) : HNode(n), _value(s) { }
1501 StringRef
value()
const {
return _value; }
1503 static bool classof(
const HNode *n) {
1504 return ScalarNode::classof(n->_node) ||
1505 BlockScalarNode::classof(n->_node);
1508 static bool classof(
const ScalarHNode *) {
return true; }
1514 class MapHNode :
public HNode {
1516 MapHNode(
Node *n) : HNode(n) { }
1518 static bool classof(
const HNode *n) {
1519 return MappingNode::classof(n->_node);
1522 static bool classof(
const MapHNode *) {
return true; }
1524 using NameToNodeAndLoc = StringMap<std::pair<HNode *, SMRange>>;
1526 NameToNodeAndLoc Mapping;
1527 SmallVector<std::string, 6> ValidKeys;
1530 class SequenceHNode :
public HNode {
1532 SequenceHNode(
Node *n) : HNode(n) { }
1534 static bool classof(
const HNode *n) {
1535 return SequenceNode::classof(n->_node);
1538 static bool classof(
const SequenceHNode *) {
return true; }
1540 std::vector<HNode *> Entries;
1543 Input::HNode *createHNodes(
Node *node);
1544 void setError(HNode *hnode,
const Twine &message);
1545 void setError(
Node *node,
const Twine &message);
1546 void setError(
const SMRange &Range,
const Twine &message);
1548 void reportWarning(HNode *hnode,
const Twine &message);
1549 void reportWarning(
Node *hnode,
const Twine &message);
1550 void reportWarning(
const SMRange &Range,
const Twine &message);
1553 void releaseHNodeBuffers();
1558 bool setCurrentDocument();
1559 bool nextDocument();
1562 const Node *getCurrentNode()
const;
1564 void setAllowUnknownKeys(
bool Allow)
override;
1568 std::unique_ptr<llvm::yaml::Stream> Strm;
1569 HNode *TopNode =
nullptr;
1572 SpecificBumpPtrAllocator<EmptyHNode> EmptyHNodeAllocator;
1573 SpecificBumpPtrAllocator<ScalarHNode> ScalarHNodeAllocator;
1574 SpecificBumpPtrAllocator<MapHNode> MapHNodeAllocator;
1575 SpecificBumpPtrAllocator<SequenceHNode> SequenceHNodeAllocator;
1576 document_iterator DocIterator;
1578 HNode *CurrentNode =
nullptr;
1579 bool ScalarMatchFound =
false;
1580 bool AllowUnknownKeys =
false;
1587class Output :
public IO {
1589 Output(raw_ostream &,
void *Ctxt =
nullptr,
int WrapColumn = 70);
1597 void setWriteDefaultValues(
bool Write) { WriteDefaultValues =
Write; }
1599 bool outputting()
const override;
1600 bool mapTag(StringRef,
bool)
override;
1601 void beginMapping()
override;
1602 void endMapping()
override;
1603 bool preflightKey(
const char *key,
bool,
bool,
bool &,
void *&)
override;
1604 void postflightKey(
void *)
override;
1605 std::vector<StringRef> keys()
override;
1606 void beginFlowMapping()
override;
1607 void endFlowMapping()
override;
1608 unsigned beginSequence()
override;
1609 void endSequence()
override;
1610 bool preflightElement(
unsigned,
void *&)
override;
1611 void postflightElement(
void *)
override;
1612 unsigned beginFlowSequence()
override;
1613 bool preflightFlowElement(
unsigned,
void *&)
override;
1614 void postflightFlowElement(
void *)
override;
1615 void endFlowSequence()
override;
1616 void beginEnumScalar()
override;
1617 bool matchEnumScalar(
const char*,
bool)
override;
1618 bool matchEnumFallback()
override;
1619 void endEnumScalar()
override;
1620 bool beginBitSetScalar(
bool &)
override;
1621 bool bitSetMatch(
const char *,
bool )
override;
1622 void endBitSetScalar()
override;
1623 void scalarString(StringRef &, QuotingType)
override;
1624 void blockScalarString(StringRef &)
override;
1625 void scalarTag(std::string &)
override;
1627 void setError(
const Twine &message)
override;
1628 bool canElideEmptySequence()
override;
1632 void beginDocuments();
1633 bool preflightDocument(
unsigned);
1634 void postflightDocument();
1635 void endDocuments();
1638 void output(StringRef s);
1639 void outputUpToEndOfLine(StringRef s);
1640 void newLineCheck(
bool EmptySequence =
false);
1641 void outputNewLine();
1642 void paddedKey(StringRef key);
1643 void flowKey(StringRef Key);
1648 inFlowSeqFirstElement,
1649 inFlowSeqOtherElement,
1656 static bool inSeqAnyElement(InState State);
1657 static bool inFlowSeqAnyElement(InState State);
1658 static bool inMapAnyKey(InState State);
1659 static bool inFlowMapAnyKey(InState State);
1663 SmallVector<InState, 8> StateStack;
1665 int ColumnAtFlowStart = 0;
1666 int ColumnAtMapFlowStart = 0;
1667 bool NeedBitValueComma =
false;
1668 bool NeedFlowSequenceComma =
false;
1669 bool EnumerationMatchFound =
false;
1670 bool WriteDefaultValues =
false;
1672 StringRef PaddingBeforeContainer;
1675template <
typename T,
typename Context>
1676void IO::processKeyWithDefault(
const char *Key, std::optional<T> &Val,
1677 const std::optional<T> &DefaultValue,
1678 bool Required, Context &Ctx) {
1679 assert(!DefaultValue &&
"std::optional<T> shouldn't have a value!");
1681 bool UseDefault =
true;
1682 const bool sameAsDefault = outputting() && !Val;
1683 if (!outputting() && !Val)
1686 this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) {
1692 bool IsNone =
false;
1694 if (
const auto *
Node =
1695 dyn_cast<ScalarNode>(((Input *)
this)->getCurrentNode()))
1698 IsNone =
Node->getRawValue().rtrim(
' ') ==
"<none>";
1703 yamlize(*
this, *Val, Required, Ctx);
1704 this->postflightKey(SaveInfo);
1719#define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1721 _type() = default; \
1722 _type(const _base v) : value(v) {} \
1723 _type(const _type &v) = default; \
1724 _type &operator=(const _type &rhs) = default; \
1725 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1726 operator const _base & () const { return value; } \
1727 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1728 bool operator==(const _base &rhs) const { return value == rhs; } \
1729 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1731 using BaseType = _base; \
1744struct ScalarTraits<Hex8> {
1745 static void output(
const Hex8 &,
void *, raw_ostream &);
1746 static StringRef input(StringRef,
void *, Hex8 &);
1747 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1751struct ScalarTraits<Hex16> {
1752 static void output(
const Hex16 &,
void *, raw_ostream &);
1753 static StringRef input(StringRef,
void *, Hex16 &);
1754 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1758struct ScalarTraits<Hex32> {
1759 static void output(
const Hex32 &,
void *, raw_ostream &);
1760 static StringRef input(StringRef,
void *, Hex32 &);
1761 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1765struct ScalarTraits<Hex64> {
1766 static void output(
const Hex64 &,
void *, raw_ostream &);
1767 static StringRef input(StringRef,
void *, Hex64 &);
1768 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1771template <>
struct ScalarTraits<VersionTuple> {
1773 static StringRef input(StringRef,
void *, VersionTuple &);
1774 static QuotingType mustQuote(StringRef) {
return QuotingType::None; }
1778template <
typename T>
1779inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
1783 while ( yin.setCurrentDocument() ) {
1784 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i),
true, Ctx);
1794template <
typename T>
1795inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Input &>
1798 yin.setCurrentDocument();
1799 yamlize(yin, docMap,
true, Ctx);
1805template <
typename T>
1806inline std::enable_if_t<has_SequenceTraits<T>::value, Input &>
1809 if (yin.setCurrentDocument())
1810 yamlize(yin, docSeq,
true, Ctx);
1815template <
typename T>
1816inline std::enable_if_t<has_BlockScalarTraits<T>::value, Input &>
1819 if (
In.setCurrentDocument())
1820 yamlize(In, Val,
true, Ctx);
1825template <
typename T>
1826inline std::enable_if_t<has_CustomMappingTraits<T>::value, Input &>
1829 if (
In.setCurrentDocument())
1830 yamlize(In, Val,
true, Ctx);
1835template <
typename T>
1836inline std::enable_if_t<has_PolymorphicTraits<T>::value, Input &>
1839 if (
In.setCurrentDocument())
1840 yamlize(In, Val,
true, Ctx);
1845template <
typename T>
1846inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Input &>
1848 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1853template <
typename T>
1854inline std::enable_if_t<has_DocumentListTraits<T>::value, Output &>
1857 yout.beginDocuments();
1858 const size_t count = DocumentListTraits<T>::size(yout, docList);
1859 for(
size_t i=0; i <
count; ++i) {
1860 if ( yout.preflightDocument(i) ) {
1861 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i),
true,
1863 yout.postflightDocument();
1866 yout.endDocuments();
1871template <
typename T>
1872inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
1875 yout.beginDocuments();
1876 if ( yout.preflightDocument(0) ) {
1877 yamlize(yout, map,
true, Ctx);
1878 yout.postflightDocument();
1880 yout.endDocuments();
1885template <
typename T>
1886inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
1889 yout.beginDocuments();
1890 if ( yout.preflightDocument(0) ) {
1891 yamlize(yout,
seq,
true, Ctx);
1892 yout.postflightDocument();
1894 yout.endDocuments();
1899template <
typename T>
1900inline std::enable_if_t<has_BlockScalarTraits<T>::value, Output &>
1903 Out.beginDocuments();
1904 if (Out.preflightDocument(0)) {
1905 yamlize(Out, Val,
true, Ctx);
1906 Out.postflightDocument();
1913template <
typename T>
1914inline std::enable_if_t<has_CustomMappingTraits<T>::value, Output &>
1917 Out.beginDocuments();
1918 if (Out.preflightDocument(0)) {
1919 yamlize(Out, Val,
true, Ctx);
1920 Out.postflightDocument();
1928template <
typename T>
1929inline std::enable_if_t<has_PolymorphicTraits<T>::value, Output &>
1932 Out.beginDocuments();
1933 if (Out.preflightDocument(0)) {
1936 assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar &&
"plain scalar documents are not supported");
1937 yamlize(Out, Val,
true, Ctx);
1938 Out.postflightDocument();
1945template <
typename T>
1946inline std::enable_if_t<missingTraits<T, EmptyContext>::value, Output &>
1948 char missing_yaml_trait_for_type[
sizeof(MissingTrait<T>)];
1952template <
bool B>
struct IsFlowSequenceBase {};
1953template <>
struct IsFlowSequenceBase<
true> {
static const bool flow =
true; };
1955template <
typename T,
typename U =
void>
1956struct IsResizable : std::false_type {};
1958template <
typename T>
1959struct IsResizable<
T,
std::void_t<decltype(std::declval<T>().resize(0))>>
1960 :
public std::true_type {};
1962template <
typename T,
bool B>
struct IsResizableBase {
1963 using type =
typename T::value_type;
1965 static type &element(IO &io,
T &seq,
size_t index) {
1966 if (index >=
seq.size())
1967 seq.resize(index + 1);
1972template <
typename T>
struct IsResizableBase<
T,
false> {
1973 using type =
typename T::value_type;
1975 static type &element(IO &io,
T &seq,
size_t index) {
1976 if (index >=
seq.size()) {
1977 io.setError(Twine(
"value sequence extends beyond static size (") +
1978 Twine(
seq.size()) +
")");
1985template <
typename T,
bool Flow>
1986struct SequenceTraitsImpl
1987 : IsFlowSequenceBase<Flow>, IsResizableBase<T, IsResizable<T>::value> {
1988 static size_t size(IO &io,
T &seq) {
return seq.size(); }
1993template <
bool>
struct CheckIsBool {
static const bool value =
true; };
1997template <
typename T>
1998struct SequenceTraits<
2000 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2001 : SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
2002template <
typename T,
unsigned N>
2003struct SequenceTraits<
2005 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2006 : SequenceTraitsImpl<SmallVector<T, N>, SequenceElementTraits<T>::flow> {};
2007template <
typename T>
2008struct SequenceTraits<
2010 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2011 : SequenceTraitsImpl<SmallVectorImpl<T>, SequenceElementTraits<T>::flow> {};
2012template <
typename T>
2013struct SequenceTraits<
2015 std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
2016 : SequenceTraitsImpl<MutableArrayRef<T>, SequenceElementTraits<T>::flow> {};
2019template <
typename T>
2020struct SequenceElementTraits<
T,
std::enable_if_t<std::is_fundamental_v<T>>> {
2021 static const bool flow =
true;
2025template<>
struct SequenceElementTraits<
std::
string> {
2026 static const bool flow =
false;
2028template<>
struct SequenceElementTraits<StringRef> {
2029 static const bool flow =
false;
2031template<>
struct SequenceElementTraits<
std::pair<std::string, std::string>> {
2032 static const bool flow =
false;
2036template <
typename T>
struct StdMapStringCustomMappingTraitsImpl {
2037 using map_type = std::map<std::string, T>;
2039 static void inputOne(IO &io, StringRef key, map_type &v) {
2040 io.mapRequired(key.str().c_str(), v[std::string(key)]);
2043 static void output(IO &io, map_type &v) {
2045 io.mapRequired(
p.first.c_str(),
p.second);
2052#define LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(TYPE, FLOW) \
2056 !std::is_fundamental_v<TYPE> && !std::is_same_v<TYPE, std::string> && \
2057 !std::is_same_v<TYPE, llvm::StringRef>, \
2058 "only use LLVM_YAML_IS_SEQUENCE_VECTOR for types you control"); \
2059 template <> struct SequenceElementTraits<TYPE> { \
2060 static const bool flow = FLOW; \
2067#define LLVM_YAML_IS_SEQUENCE_VECTOR(type) \
2068 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, false)
2072#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type) \
2073 LLVM_YAML_IS_SEQUENCE_VECTOR_IMPL(type, true)
2075#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type) \
2078 template <> struct MappingTraits<Type> { \
2079 static void mapping(IO &IO, Type &Obj); \
2084#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type) \
2087 template <> struct ScalarEnumerationTraits<Type> { \
2088 static void enumeration(IO &io, Type &Value); \
2093#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type) \
2096 template <> struct ScalarBitSetTraits<Type> { \
2097 static void bitset(IO &IO, Type &Options); \
2102#define LLVM_YAML_DECLARE_SCALAR_TRAITS(Type, MustQuote) \
2105 template <> struct ScalarTraits<Type> { \
2106 static void output(const Type &Value, void *ctx, raw_ostream &Out); \
2107 static StringRef input(StringRef Scalar, void *ctxt, Type &Value); \
2108 static QuotingType mustQuote(StringRef) { return MustQuote; } \
2115#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
2118 template <unsigned N> \
2119 struct DocumentListTraits<SmallVector<_type, N>> \
2120 : public SequenceTraitsImpl<SmallVector<_type, N>, false> {}; \
2122 struct DocumentListTraits<std::vector<_type>> \
2123 : public SequenceTraitsImpl<std::vector<_type>, false> {}; \
2129#define LLVM_YAML_IS_STRING_MAP(_type) \
2133 struct CustomMappingTraits<std::map<std::string, _type>> \
2134 : 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.