1 //===- llvm/Support/YAMLTraits.h --------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_SUPPORT_YAMLTRAITS_H
11 #define LLVM_SUPPORT_YAMLTRAITS_H
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/Twine.h"
18 #include "llvm/Support/AlignOf.h"
19 #include "llvm/Support/Allocator.h"
20 #include "llvm/Support/Endian.h"
21 #include "llvm/Support/Regex.h"
22 #include "llvm/Support/SourceMgr.h"
23 #include "llvm/Support/YAMLParser.h"
24 #include "llvm/Support/raw_ostream.h"
32 #include <system_error>
33 #include <type_traits>
39 struct EmptyContext {};
41 /// This class should be specialized by any type that needs to be converted
42 /// to/from a YAML mapping. For example:
44 /// struct MappingTraits<MyStruct> {
45 /// static void mapping(IO &io, MyStruct &s) {
46 /// io.mapRequired("name", s.name);
47 /// io.mapRequired("size", s.size);
48 /// io.mapOptional("age", s.age);
52 struct MappingTraits {
54 // static void mapping(IO &io, T &fields);
55 // Optionally may provide:
56 // static StringRef validate(IO &io, T &fields);
58 // The optional flow flag will cause generated YAML to use a flow mapping
59 // (e.g. { a: 0, b: 1 }):
60 // static const bool flow = true;
63 /// This class is similar to MappingTraits<T> but allows you to pass in
64 /// additional context for each map operation. For example:
66 /// struct MappingContextTraits<MyStruct, MyContext> {
67 /// static void mapping(IO &io, MyStruct &s, MyContext &c) {
68 /// io.mapRequired("name", s.name);
69 /// io.mapRequired("size", s.size);
70 /// io.mapOptional("age", s.age);
74 template <class T, class Context> struct MappingContextTraits {
76 // static void mapping(IO &io, T &fields, Context &Ctx);
77 // Optionally may provide:
78 // static StringRef validate(IO &io, T &fields, Context &Ctx);
80 // The optional flow flag will cause generated YAML to use a flow mapping
81 // (e.g. { a: 0, b: 1 }):
82 // static const bool flow = true;
85 /// This class should be specialized by any integral type that converts
86 /// to/from a YAML scalar where there is a one-to-one mapping between
87 /// in-memory values and a string in YAML. For example:
89 /// struct ScalarEnumerationTraits<Colors> {
90 /// static void enumeration(IO &io, Colors &value) {
91 /// io.enumCase(value, "red", cRed);
92 /// io.enumCase(value, "blue", cBlue);
93 /// io.enumCase(value, "green", cGreen);
97 struct ScalarEnumerationTraits {
99 // static void enumeration(IO &io, T &value);
102 /// This class should be specialized by any integer type that is a union
103 /// of bit values and the YAML representation is a flow sequence of
104 /// strings. For example:
106 /// struct ScalarBitSetTraits<MyFlags> {
107 /// static void bitset(IO &io, MyFlags &value) {
108 /// io.bitSetCase(value, "big", flagBig);
109 /// io.bitSetCase(value, "flat", flagFlat);
110 /// io.bitSetCase(value, "round", flagRound);
114 struct ScalarBitSetTraits {
116 // static void bitset(IO &io, T &value);
119 /// This class should be specialized by type that requires custom conversion
120 /// to/from a yaml scalar. For example:
123 /// struct ScalarTraits<MyType> {
124 /// static void output(const MyType &val, void*, llvm::raw_ostream &out) {
125 /// // stream out custom formatting
126 /// out << llvm::format("%x", val);
128 /// static StringRef input(StringRef scalar, void*, MyType &value) {
129 /// // parse scalar and set `value`
130 /// // return empty string on success, or error string
131 /// return StringRef();
133 /// static bool mustQuote(StringRef) { return true; }
136 struct ScalarTraits {
139 // Function to write the value as a string:
140 //static void output(const T &value, void *ctxt, llvm::raw_ostream &out);
142 // Function to convert a string to a value. Returns the empty
143 // StringRef on success or an error string if string is malformed:
144 //static StringRef input(StringRef scalar, void *ctxt, T &value);
146 // Function to determine if the value should be quoted.
147 //static bool mustQuote(StringRef);
150 /// This class should be specialized by type that requires custom conversion
151 /// to/from a YAML literal block scalar. For example:
154 /// struct BlockScalarTraits<MyType> {
155 /// static void output(const MyType &Value, void*, llvm::raw_ostream &Out)
157 /// // stream out custom formatting
160 /// static StringRef input(StringRef Scalar, void*, MyType &Value) {
161 /// // parse scalar and set `value`
162 /// // return empty string on success, or error string
163 /// return StringRef();
166 template <typename T>
167 struct BlockScalarTraits {
170 // Function to write the value as a string:
171 // static void output(const T &Value, void *ctx, llvm::raw_ostream &Out);
173 // Function to convert a string to a value. Returns the empty
174 // StringRef on success or an error string if string is malformed:
175 // static StringRef input(StringRef Scalar, void *ctxt, T &Value);
178 /// This class should be specialized by any type that needs to be converted
179 /// to/from a YAML sequence. For example:
182 /// struct SequenceTraits< std::vector<MyType>> {
183 /// static size_t size(IO &io, std::vector<MyType> &seq) {
184 /// return seq.size();
186 /// static MyType& element(IO &, std::vector<MyType> &seq, size_t index) {
187 /// if ( index >= seq.size() )
188 /// seq.resize(index+1);
189 /// return seq[index];
193 struct SequenceTraits {
195 // static size_t size(IO &io, T &seq);
196 // static T::value_type& element(IO &io, T &seq, size_t index);
198 // The following is option and will cause generated YAML to use
199 // a flow sequence (e.g. [a,b,c]).
200 // static const bool flow = true;
203 /// This class should be specialized by any type that needs to be converted
204 /// to/from a list of YAML documents.
206 struct DocumentListTraits {
208 // static size_t size(IO &io, T &seq);
209 // static T::value_type& element(IO &io, T &seq, size_t index);
212 /// This class should be specialized by any type that needs to be converted
213 /// to/from a YAML mapping in the case where the names of the keys are not known
214 /// in advance, e.g. a string map.
215 template <typename T>
216 struct CustomMappingTraits {
217 // static void inputOne(IO &io, StringRef key, T &elem);
218 // static void output(IO &io, T &elem);
221 // Only used for better diagnostics of missing traits
222 template <typename T>
225 // Test if ScalarEnumerationTraits<T> is defined on type T.
227 struct has_ScalarEnumerationTraits
229 typedef void (*Signature_enumeration)(class IO&, T&);
231 template <typename U>
232 static char test(SameType<Signature_enumeration, &U::enumeration>*);
234 template <typename U>
235 static double test(...);
238 static bool const value =
239 (sizeof(test<ScalarEnumerationTraits<T>>(nullptr)) == 1);
242 // Test if ScalarBitSetTraits<T> is defined on type T.
244 struct has_ScalarBitSetTraits
246 typedef void (*Signature_bitset)(class IO&, T&);
248 template <typename U>
249 static char test(SameType<Signature_bitset, &U::bitset>*);
251 template <typename U>
252 static double test(...);
255 static bool const value = (sizeof(test<ScalarBitSetTraits<T>>(nullptr)) == 1);
258 // Test if ScalarTraits<T> is defined on type T.
260 struct has_ScalarTraits
262 typedef StringRef (*Signature_input)(StringRef, void*, T&);
263 typedef void (*Signature_output)(const T&, void*, llvm::raw_ostream&);
264 typedef bool (*Signature_mustQuote)(StringRef);
266 template <typename U>
267 static char test(SameType<Signature_input, &U::input> *,
268 SameType<Signature_output, &U::output> *,
269 SameType<Signature_mustQuote, &U::mustQuote> *);
271 template <typename U>
272 static double test(...);
275 static bool const value =
276 (sizeof(test<ScalarTraits<T>>(nullptr, nullptr, nullptr)) == 1);
279 // Test if BlockScalarTraits<T> is defined on type T.
281 struct has_BlockScalarTraits
283 typedef StringRef (*Signature_input)(StringRef, void *, T &);
284 typedef void (*Signature_output)(const T &, void *, llvm::raw_ostream &);
286 template <typename U>
287 static char test(SameType<Signature_input, &U::input> *,
288 SameType<Signature_output, &U::output> *);
290 template <typename U>
291 static double test(...);
294 static bool const value =
295 (sizeof(test<BlockScalarTraits<T>>(nullptr, nullptr)) == 1);
298 // Test if MappingContextTraits<T> is defined on type T.
299 template <class T, class Context> struct has_MappingTraits {
300 typedef void (*Signature_mapping)(class IO &, T &, Context &);
302 template <typename U>
303 static char test(SameType<Signature_mapping, &U::mapping>*);
305 template <typename U>
306 static double test(...);
309 static bool const value =
310 (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
313 // Test if MappingTraits<T> is defined on type T.
314 template <class T> struct has_MappingTraits<T, EmptyContext> {
315 typedef void (*Signature_mapping)(class IO &, T &);
317 template <typename U>
318 static char test(SameType<Signature_mapping, &U::mapping> *);
320 template <typename U> static double test(...);
323 static bool const value = (sizeof(test<MappingTraits<T>>(nullptr)) == 1);
326 // Test if MappingContextTraits<T>::validate() is defined on type T.
327 template <class T, class Context> struct has_MappingValidateTraits {
328 typedef StringRef (*Signature_validate)(class IO &, T &, Context &);
330 template <typename U>
331 static char test(SameType<Signature_validate, &U::validate>*);
333 template <typename U>
334 static double test(...);
337 static bool const value =
338 (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
341 // Test if MappingTraits<T>::validate() is defined on type T.
342 template <class T> struct has_MappingValidateTraits<T, EmptyContext> {
343 typedef StringRef (*Signature_validate)(class IO &, T &);
345 template <typename U>
346 static char test(SameType<Signature_validate, &U::validate> *);
348 template <typename U> static double test(...);
351 static bool const value = (sizeof(test<MappingTraits<T>>(nullptr)) == 1);
354 // Test if SequenceTraits<T> is defined on type T.
356 struct has_SequenceMethodTraits
358 typedef size_t (*Signature_size)(class IO&, T&);
360 template <typename U>
361 static char test(SameType<Signature_size, &U::size>*);
363 template <typename U>
364 static double test(...);
367 static bool const value = (sizeof(test<SequenceTraits<T>>(nullptr)) == 1);
370 // Test if CustomMappingTraits<T> is defined on type T.
372 struct has_CustomMappingTraits
374 typedef void (*Signature_input)(IO &io, StringRef key, T &v);
376 template <typename U>
377 static char test(SameType<Signature_input, &U::inputOne>*);
379 template <typename U>
380 static double test(...);
383 static bool const value =
384 (sizeof(test<CustomMappingTraits<T>>(nullptr)) == 1);
387 // has_FlowTraits<int> will cause an error with some compilers because
388 // it subclasses int. Using this wrapper only instantiates the
389 // real has_FlowTraits only if the template type is a class.
390 template <typename T, bool Enabled = std::is_class<T>::value>
394 static const bool value = false;
397 // Some older gcc compilers don't support straight forward tests
398 // for members, so test for ambiguity cause by the base and derived
399 // classes both defining the member.
401 struct has_FlowTraits<T, true>
403 struct Fallback { bool flow; };
404 struct Derived : T, Fallback { };
407 static char (&f(SameType<bool Fallback::*, &C::flow>*))[1];
410 static char (&f(...))[2];
413 static bool const value = sizeof(f<Derived>(nullptr)) == 2;
416 // Test if SequenceTraits<T> is defined on type T
418 struct has_SequenceTraits : public std::integral_constant<bool,
419 has_SequenceMethodTraits<T>::value > { };
421 // Test if DocumentListTraits<T> is defined on type T
423 struct has_DocumentListTraits
425 typedef size_t (*Signature_size)(class IO&, T&);
427 template <typename U>
428 static char test(SameType<Signature_size, &U::size>*);
430 template <typename U>
431 static double test(...);
434 static bool const value = (sizeof(test<DocumentListTraits<T>>(nullptr))==1);
437 inline bool isNumber(StringRef S) {
438 static const char OctalChars[] = "01234567";
439 if (S.startswith("0") &&
440 S.drop_front().find_first_not_of(OctalChars) == StringRef::npos)
443 if (S.startswith("0o") &&
444 S.drop_front(2).find_first_not_of(OctalChars) == StringRef::npos)
447 static const char HexChars[] = "0123456789abcdefABCDEF";
448 if (S.startswith("0x") &&
449 S.drop_front(2).find_first_not_of(HexChars) == StringRef::npos)
452 static const char DecChars[] = "0123456789";
453 if (S.find_first_not_of(DecChars) == StringRef::npos)
456 if (S.equals(".inf") || S.equals(".Inf") || S.equals(".INF"))
459 Regex FloatMatcher("^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
460 if (FloatMatcher.match(S))
466 inline bool isNumeric(StringRef S) {
467 if ((S.front() == '-' || S.front() == '+') && isNumber(S.drop_front()))
473 if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN"))
479 inline bool isNull(StringRef S) {
480 return S.equals("null") || S.equals("Null") || S.equals("NULL") ||
484 inline bool isBool(StringRef S) {
485 return S.equals("true") || S.equals("True") || S.equals("TRUE") ||
486 S.equals("false") || S.equals("False") || S.equals("FALSE");
489 inline bool needsQuotes(StringRef S) {
492 if (isspace(S.front()) || isspace(S.back()))
494 if (S.front() == ',')
497 static const char ScalarSafeChars[] =
498 "abcdefghijklmnopqrstuvwxyz"
499 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-/^., \t";
500 if (S.find_first_not_of(ScalarSafeChars) != StringRef::npos)
513 template <typename T, typename Context>
515 : public std::integral_constant<bool,
516 !has_ScalarEnumerationTraits<T>::value &&
517 !has_ScalarBitSetTraits<T>::value &&
518 !has_ScalarTraits<T>::value &&
519 !has_BlockScalarTraits<T>::value &&
520 !has_MappingTraits<T, Context>::value &&
521 !has_SequenceTraits<T>::value &&
522 !has_CustomMappingTraits<T>::value &&
523 !has_DocumentListTraits<T>::value> {};
525 template <typename T, typename Context>
526 struct validatedMappingTraits
527 : public std::integral_constant<
528 bool, has_MappingTraits<T, Context>::value &&
529 has_MappingValidateTraits<T, Context>::value> {};
531 template <typename T, typename Context>
532 struct unvalidatedMappingTraits
533 : public std::integral_constant<
534 bool, has_MappingTraits<T, Context>::value &&
535 !has_MappingValidateTraits<T, Context>::value> {};
537 // Base class for Input and Output.
540 IO(void *Ctxt=nullptr);
543 virtual bool outputting() = 0;
545 virtual unsigned beginSequence() = 0;
546 virtual bool preflightElement(unsigned, void *&) = 0;
547 virtual void postflightElement(void*) = 0;
548 virtual void endSequence() = 0;
549 virtual bool canElideEmptySequence() = 0;
551 virtual unsigned beginFlowSequence() = 0;
552 virtual bool preflightFlowElement(unsigned, void *&) = 0;
553 virtual void postflightFlowElement(void*) = 0;
554 virtual void endFlowSequence() = 0;
556 virtual bool mapTag(StringRef Tag, bool Default=false) = 0;
557 virtual void beginMapping() = 0;
558 virtual void endMapping() = 0;
559 virtual bool preflightKey(const char*, bool, bool, bool &, void *&) = 0;
560 virtual void postflightKey(void*) = 0;
561 virtual std::vector<StringRef> keys() = 0;
563 virtual void beginFlowMapping() = 0;
564 virtual void endFlowMapping() = 0;
566 virtual void beginEnumScalar() = 0;
567 virtual bool matchEnumScalar(const char*, bool) = 0;
568 virtual bool matchEnumFallback() = 0;
569 virtual void endEnumScalar() = 0;
571 virtual bool beginBitSetScalar(bool &) = 0;
572 virtual bool bitSetMatch(const char*, bool) = 0;
573 virtual void endBitSetScalar() = 0;
575 virtual void scalarString(StringRef &, bool) = 0;
576 virtual void blockScalarString(StringRef &) = 0;
578 virtual void setError(const Twine &) = 0;
580 template <typename T>
581 void enumCase(T &Val, const char* Str, const T ConstVal) {
582 if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
587 // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
588 template <typename T>
589 void enumCase(T &Val, const char* Str, const uint32_t ConstVal) {
590 if ( matchEnumScalar(Str, outputting() && Val == static_cast<T>(ConstVal)) ) {
595 template <typename FBT, typename T>
596 void enumFallback(T &Val) {
597 if (matchEnumFallback()) {
598 EmptyContext Context;
599 // FIXME: Force integral conversion to allow strong typedefs to convert.
600 FBT Res = static_cast<typename FBT::BaseType>(Val);
601 yamlize(*this, Res, true, Context);
602 Val = static_cast<T>(static_cast<typename FBT::BaseType>(Res));
606 template <typename T>
607 void bitSetCase(T &Val, const char* Str, const T ConstVal) {
608 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
609 Val = Val | ConstVal;
613 // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
614 template <typename T>
615 void bitSetCase(T &Val, const char* Str, const uint32_t ConstVal) {
616 if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
617 Val = Val | ConstVal;
621 template <typename T>
622 void maskedBitSetCase(T &Val, const char *Str, T ConstVal, T Mask) {
623 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
624 Val = Val | ConstVal;
627 template <typename T>
628 void maskedBitSetCase(T &Val, const char *Str, uint32_t ConstVal,
630 if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal))
631 Val = Val | ConstVal;
635 void setContext(void *);
637 template <typename T> void mapRequired(const char *Key, T &Val) {
639 this->processKey(Key, Val, true, Ctx);
641 template <typename T, typename Context>
642 void mapRequired(const char *Key, T &Val, Context &Ctx) {
643 this->processKey(Key, Val, true, Ctx);
646 template <typename T> void mapOptional(const char *Key, T &Val) {
648 mapOptionalWithContext(Key, Val, Ctx);
651 template <typename T>
652 void mapOptional(const char *Key, T &Val, const T &Default) {
654 mapOptionalWithContext(Key, Val, Default, Ctx);
657 template <typename T, typename Context>
658 typename std::enable_if<has_SequenceTraits<T>::value, void>::type
659 mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
660 // omit key/value instead of outputting empty sequence
661 if (this->canElideEmptySequence() && !(Val.begin() != Val.end()))
663 this->processKey(Key, Val, false, Ctx);
666 template <typename T, typename Context>
667 void mapOptionalWithContext(const char *Key, Optional<T> &Val, Context &Ctx) {
668 this->processKeyWithDefault(Key, Val, Optional<T>(), /*Required=*/false,
672 template <typename T, typename Context>
673 typename std::enable_if<!has_SequenceTraits<T>::value, void>::type
674 mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) {
675 this->processKey(Key, Val, false, Ctx);
678 template <typename T, typename Context>
679 void mapOptionalWithContext(const char *Key, T &Val, const T &Default,
681 this->processKeyWithDefault(Key, Val, Default, false, Ctx);
685 template <typename T, typename Context>
686 void processKeyWithDefault(const char *Key, Optional<T> &Val,
687 const Optional<T> &DefaultValue, bool Required,
689 assert(DefaultValue.hasValue() == false &&
690 "Optional<T> shouldn't have a value!");
693 const bool sameAsDefault = outputting() && !Val.hasValue();
694 if (!outputting() && !Val.hasValue())
696 if (this->preflightKey(Key, Required, sameAsDefault, UseDefault,
698 yamlize(*this, Val.getValue(), Required, Ctx);
699 this->postflightKey(SaveInfo);
706 template <typename T, typename Context>
707 void processKeyWithDefault(const char *Key, T &Val, const T &DefaultValue,
708 bool Required, Context &Ctx) {
711 const bool sameAsDefault = outputting() && Val == DefaultValue;
712 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
714 yamlize(*this, Val, Required, Ctx);
715 this->postflightKey(SaveInfo);
723 template <typename T, typename Context>
724 void processKey(const char *Key, T &Val, bool Required, Context &Ctx) {
727 if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) {
728 yamlize(*this, Val, Required, Ctx);
729 this->postflightKey(SaveInfo);
739 template <typename T, typename Context>
740 void doMapping(IO &io, T &Val, Context &Ctx) {
741 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
744 template <typename T> void doMapping(IO &io, T &Val, EmptyContext &Ctx) {
745 MappingTraits<T>::mapping(io, Val);
748 } // end namespace detail
750 template <typename T>
751 typename std::enable_if<has_ScalarEnumerationTraits<T>::value, void>::type
752 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
753 io.beginEnumScalar();
754 ScalarEnumerationTraits<T>::enumeration(io, Val);
758 template <typename T>
759 typename std::enable_if<has_ScalarBitSetTraits<T>::value, void>::type
760 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
762 if ( io.beginBitSetScalar(DoClear) ) {
764 Val = static_cast<T>(0);
765 ScalarBitSetTraits<T>::bitset(io, Val);
766 io.endBitSetScalar();
770 template <typename T>
771 typename std::enable_if<has_ScalarTraits<T>::value, void>::type
772 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
773 if ( io.outputting() ) {
775 llvm::raw_string_ostream Buffer(Storage);
776 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
777 StringRef Str = Buffer.str();
778 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
782 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
783 StringRef Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
784 if ( !Result.empty() ) {
785 io.setError(llvm::Twine(Result));
790 template <typename T>
791 typename std::enable_if<has_BlockScalarTraits<T>::value, void>::type
792 yamlize(IO &YamlIO, T &Val, bool, EmptyContext &Ctx) {
793 if (YamlIO.outputting()) {
795 llvm::raw_string_ostream Buffer(Storage);
796 BlockScalarTraits<T>::output(Val, YamlIO.getContext(), Buffer);
797 StringRef Str = Buffer.str();
798 YamlIO.blockScalarString(Str);
801 YamlIO.blockScalarString(Str);
803 BlockScalarTraits<T>::input(Str, YamlIO.getContext(), Val);
805 YamlIO.setError(llvm::Twine(Result));
809 template <typename T, typename Context>
810 typename std::enable_if<validatedMappingTraits<T, Context>::value, void>::type
811 yamlize(IO &io, T &Val, bool, Context &Ctx) {
812 if (has_FlowTraits<MappingTraits<T>>::value)
813 io.beginFlowMapping();
816 if (io.outputting()) {
817 StringRef Err = MappingTraits<T>::validate(io, Val);
819 llvm::errs() << Err << "\n";
820 assert(Err.empty() && "invalid struct trying to be written as yaml");
823 detail::doMapping(io, Val, Ctx);
824 if (!io.outputting()) {
825 StringRef Err = MappingTraits<T>::validate(io, Val);
829 if (has_FlowTraits<MappingTraits<T>>::value)
835 template <typename T, typename Context>
836 typename std::enable_if<unvalidatedMappingTraits<T, Context>::value, void>::type
837 yamlize(IO &io, T &Val, bool, Context &Ctx) {
838 if (has_FlowTraits<MappingTraits<T>>::value) {
839 io.beginFlowMapping();
840 detail::doMapping(io, Val, Ctx);
844 detail::doMapping(io, Val, Ctx);
849 template <typename T>
850 typename std::enable_if<has_CustomMappingTraits<T>::value, void>::type
851 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
852 if ( io.outputting() ) {
854 CustomMappingTraits<T>::output(io, Val);
858 for (StringRef key : io.keys())
859 CustomMappingTraits<T>::inputOne(io, key, Val);
864 template <typename T>
865 typename std::enable_if<missingTraits<T, EmptyContext>::value, void>::type
866 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
867 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
870 template <typename T, typename Context>
871 typename std::enable_if<has_SequenceTraits<T>::value, void>::type
872 yamlize(IO &io, T &Seq, bool, Context &Ctx) {
873 if ( has_FlowTraits< SequenceTraits<T> >::value ) {
874 unsigned incnt = io.beginFlowSequence();
875 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
876 for(unsigned i=0; i < count; ++i) {
878 if ( io.preflightFlowElement(i, SaveInfo) ) {
879 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
880 io.postflightFlowElement(SaveInfo);
883 io.endFlowSequence();
886 unsigned incnt = io.beginSequence();
887 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
888 for(unsigned i=0; i < count; ++i) {
890 if ( io.preflightElement(i, SaveInfo) ) {
891 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
892 io.postflightElement(SaveInfo);
900 struct ScalarTraits<bool> {
901 static void output(const bool &, void*, llvm::raw_ostream &);
902 static StringRef input(StringRef, void*, bool &);
903 static bool mustQuote(StringRef) { return false; }
907 struct ScalarTraits<StringRef> {
908 static void output(const StringRef &, void*, llvm::raw_ostream &);
909 static StringRef input(StringRef, void*, StringRef &);
910 static bool mustQuote(StringRef S) { return needsQuotes(S); }
914 struct ScalarTraits<std::string> {
915 static void output(const std::string &, void*, llvm::raw_ostream &);
916 static StringRef input(StringRef, void*, std::string &);
917 static bool mustQuote(StringRef S) { return needsQuotes(S); }
921 struct ScalarTraits<uint8_t> {
922 static void output(const uint8_t &, void*, llvm::raw_ostream &);
923 static StringRef input(StringRef, void*, uint8_t &);
924 static bool mustQuote(StringRef) { return false; }
928 struct ScalarTraits<uint16_t> {
929 static void output(const uint16_t &, void*, llvm::raw_ostream &);
930 static StringRef input(StringRef, void*, uint16_t &);
931 static bool mustQuote(StringRef) { return false; }
935 struct ScalarTraits<uint32_t> {
936 static void output(const uint32_t &, void*, llvm::raw_ostream &);
937 static StringRef input(StringRef, void*, uint32_t &);
938 static bool mustQuote(StringRef) { return false; }
942 struct ScalarTraits<uint64_t> {
943 static void output(const uint64_t &, void*, llvm::raw_ostream &);
944 static StringRef input(StringRef, void*, uint64_t &);
945 static bool mustQuote(StringRef) { return false; }
949 struct ScalarTraits<int8_t> {
950 static void output(const int8_t &, void*, llvm::raw_ostream &);
951 static StringRef input(StringRef, void*, int8_t &);
952 static bool mustQuote(StringRef) { return false; }
956 struct ScalarTraits<int16_t> {
957 static void output(const int16_t &, void*, llvm::raw_ostream &);
958 static StringRef input(StringRef, void*, int16_t &);
959 static bool mustQuote(StringRef) { return false; }
963 struct ScalarTraits<int32_t> {
964 static void output(const int32_t &, void*, llvm::raw_ostream &);
965 static StringRef input(StringRef, void*, int32_t &);
966 static bool mustQuote(StringRef) { return false; }
970 struct ScalarTraits<int64_t> {
971 static void output(const int64_t &, void*, llvm::raw_ostream &);
972 static StringRef input(StringRef, void*, int64_t &);
973 static bool mustQuote(StringRef) { return false; }
977 struct ScalarTraits<float> {
978 static void output(const float &, void*, llvm::raw_ostream &);
979 static StringRef input(StringRef, void*, float &);
980 static bool mustQuote(StringRef) { return false; }
984 struct ScalarTraits<double> {
985 static void output(const double &, void*, llvm::raw_ostream &);
986 static StringRef input(StringRef, void*, double &);
987 static bool mustQuote(StringRef) { return false; }
990 // For endian types, we just use the existing ScalarTraits for the underlying
991 // type. This way endian aware types are supported whenever a ScalarTraits
992 // is defined for the underlying type.
993 template <typename value_type, support::endianness endian, size_t alignment>
994 struct ScalarTraits<support::detail::packed_endian_specific_integral<
995 value_type, endian, alignment>> {
996 typedef support::detail::packed_endian_specific_integral<value_type, endian,
1000 static void output(const endian_type &E, void *Ctx,
1001 llvm::raw_ostream &Stream) {
1002 ScalarTraits<value_type>::output(static_cast<value_type>(E), Ctx, Stream);
1005 static StringRef input(StringRef Str, void *Ctx, endian_type &E) {
1007 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1008 E = static_cast<endian_type>(V);
1012 static bool mustQuote(StringRef Str) {
1013 return ScalarTraits<value_type>::mustQuote(Str);
1017 // Utility for use within MappingTraits<>::mapping() method
1018 // to [de]normalize an object for use with YAML conversion.
1019 template <typename TNorm, typename TFinal>
1020 struct MappingNormalization {
1021 MappingNormalization(IO &i_o, TFinal &Obj)
1022 : io(i_o), BufPtr(nullptr), Result(Obj) {
1023 if ( io.outputting() ) {
1024 BufPtr = new (&Buffer) TNorm(io, Obj);
1027 BufPtr = new (&Buffer) TNorm(io);
1031 ~MappingNormalization() {
1032 if ( ! io.outputting() ) {
1033 Result = BufPtr->denormalize(io);
1038 TNorm* operator->() { return BufPtr; }
1041 typedef llvm::AlignedCharArrayUnion<TNorm> Storage;
1049 // Utility for use within MappingTraits<>::mapping() method
1050 // to [de]normalize an object for use with YAML conversion.
1051 template <typename TNorm, typename TFinal>
1052 struct MappingNormalizationHeap {
1053 MappingNormalizationHeap(IO &i_o, TFinal &Obj,
1054 llvm::BumpPtrAllocator *allocator)
1055 : io(i_o), BufPtr(nullptr), Result(Obj) {
1056 if ( io.outputting() ) {
1057 BufPtr = new (&Buffer) TNorm(io, Obj);
1059 else if (allocator) {
1060 BufPtr = allocator->Allocate<TNorm>();
1061 new (BufPtr) TNorm(io);
1063 BufPtr = new TNorm(io);
1067 ~MappingNormalizationHeap() {
1068 if ( io.outputting() ) {
1072 Result = BufPtr->denormalize(io);
1076 TNorm* operator->() { return BufPtr; }
1079 typedef llvm::AlignedCharArrayUnion<TNorm> Storage;
1088 /// The Input class is used to parse a yaml document into in-memory structs
1091 /// It works by using YAMLParser to do a syntax parse of the entire yaml
1092 /// document, then the Input class builds a graph of HNodes which wraps
1093 /// each yaml Node. The extra layer is buffering. The low level yaml
1094 /// parser only lets you look at each node once. The buffering layer lets
1095 /// you search and interate multiple times. This is necessary because
1096 /// the mapRequired() method calls may not be in the same order
1097 /// as the keys in the document.
1099 class Input : public IO {
1101 // Construct a yaml Input object from a StringRef and optional
1102 // user-data. The DiagHandler can be specified to provide
1103 // alternative error reporting.
1104 Input(StringRef InputContent,
1105 void *Ctxt = nullptr,
1106 SourceMgr::DiagHandlerTy DiagHandler = nullptr,
1107 void *DiagHandlerCtxt = nullptr);
1110 // Check if there was an syntax or semantic error during parsing.
1111 std::error_code error();
1114 bool outputting() override;
1115 bool mapTag(StringRef, bool) override;
1116 void beginMapping() override;
1117 void endMapping() override;
1118 bool preflightKey(const char *, bool, bool, bool &, void *&) override;
1119 void postflightKey(void *) override;
1120 std::vector<StringRef> keys() override;
1121 void beginFlowMapping() override;
1122 void endFlowMapping() override;
1123 unsigned beginSequence() override;
1124 void endSequence() override;
1125 bool preflightElement(unsigned index, void *&) override;
1126 void postflightElement(void *) override;
1127 unsigned beginFlowSequence() override;
1128 bool preflightFlowElement(unsigned , void *&) override;
1129 void postflightFlowElement(void *) override;
1130 void endFlowSequence() override;
1131 void beginEnumScalar() override;
1132 bool matchEnumScalar(const char*, bool) override;
1133 bool matchEnumFallback() override;
1134 void endEnumScalar() override;
1135 bool beginBitSetScalar(bool &) override;
1136 bool bitSetMatch(const char *, bool ) override;
1137 void endBitSetScalar() override;
1138 void scalarString(StringRef &, bool) override;
1139 void blockScalarString(StringRef &) override;
1140 void setError(const Twine &message) override;
1141 bool canElideEmptySequence() override;
1144 virtual void anchor();
1147 HNode(Node *n) : _node(n) { }
1148 virtual ~HNode() = default;
1150 static inline bool classof(const HNode *) { return true; }
1155 class EmptyHNode : public HNode {
1156 void anchor() override;
1159 EmptyHNode(Node *n) : HNode(n) { }
1161 static inline bool classof(const HNode *n) {
1162 return NullNode::classof(n->_node);
1165 static inline bool classof(const EmptyHNode *) { return true; }
1168 class ScalarHNode : public HNode {
1169 void anchor() override;
1172 ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
1174 StringRef value() const { return _value; }
1176 static inline bool classof(const HNode *n) {
1177 return ScalarNode::classof(n->_node) ||
1178 BlockScalarNode::classof(n->_node);
1181 static inline bool classof(const ScalarHNode *) { return true; }
1187 class MapHNode : public HNode {
1188 void anchor() override;
1191 MapHNode(Node *n) : HNode(n) { }
1193 static inline bool classof(const HNode *n) {
1194 return MappingNode::classof(n->_node);
1197 static inline bool classof(const MapHNode *) { return true; }
1199 typedef llvm::StringMap<std::unique_ptr<HNode>> NameToNode;
1202 llvm::SmallVector<std::string, 6> ValidKeys;
1205 class SequenceHNode : public HNode {
1206 void anchor() override;
1209 SequenceHNode(Node *n) : HNode(n) { }
1211 static inline bool classof(const HNode *n) {
1212 return SequenceNode::classof(n->_node);
1215 static inline bool classof(const SequenceHNode *) { return true; }
1217 std::vector<std::unique_ptr<HNode>> Entries;
1220 std::unique_ptr<Input::HNode> createHNodes(Node *node);
1221 void setError(HNode *hnode, const Twine &message);
1222 void setError(Node *node, const Twine &message);
1225 // These are only used by operator>>. They could be private
1226 // if those templated things could be made friends.
1227 bool setCurrentDocument();
1228 bool nextDocument();
1230 /// Returns the current node that's being parsed by the YAML Parser.
1231 const Node *getCurrentNode() const;
1234 llvm::SourceMgr SrcMgr; // must be before Strm
1235 std::unique_ptr<llvm::yaml::Stream> Strm;
1236 std::unique_ptr<HNode> TopNode;
1238 llvm::BumpPtrAllocator StringAllocator;
1239 llvm::yaml::document_iterator DocIterator;
1240 std::vector<bool> BitValuesUsed;
1242 bool ScalarMatchFound;
1246 /// The Output class is used to generate a yaml document from in-memory structs
1249 class Output : public IO {
1251 Output(llvm::raw_ostream &, void *Ctxt = nullptr, int WrapColumn = 70);
1254 bool outputting() override;
1255 bool mapTag(StringRef, bool) override;
1256 void beginMapping() override;
1257 void endMapping() override;
1258 bool preflightKey(const char *key, bool, bool, bool &, void *&) override;
1259 void postflightKey(void *) override;
1260 std::vector<StringRef> keys() override;
1261 void beginFlowMapping() override;
1262 void endFlowMapping() override;
1263 unsigned beginSequence() override;
1264 void endSequence() override;
1265 bool preflightElement(unsigned, void *&) override;
1266 void postflightElement(void *) override;
1267 unsigned beginFlowSequence() override;
1268 bool preflightFlowElement(unsigned, void *&) override;
1269 void postflightFlowElement(void *) override;
1270 void endFlowSequence() override;
1271 void beginEnumScalar() override;
1272 bool matchEnumScalar(const char*, bool) override;
1273 bool matchEnumFallback() override;
1274 void endEnumScalar() override;
1275 bool beginBitSetScalar(bool &) override;
1276 bool bitSetMatch(const char *, bool ) override;
1277 void endBitSetScalar() override;
1278 void scalarString(StringRef &, bool) override;
1279 void blockScalarString(StringRef &) override;
1280 void setError(const Twine &message) override;
1281 bool canElideEmptySequence() override;
1283 // These are only used by operator<<. They could be private
1284 // if that templated operator could be made a friend.
1285 void beginDocuments();
1286 bool preflightDocument(unsigned);
1287 void postflightDocument();
1288 void endDocuments();
1291 void output(StringRef s);
1292 void outputUpToEndOfLine(StringRef s);
1293 void newLineCheck();
1294 void outputNewLine();
1295 void paddedKey(StringRef key);
1296 void flowKey(StringRef Key);
1307 llvm::raw_ostream &Out;
1309 SmallVector<InState, 8> StateStack;
1311 int ColumnAtFlowStart;
1312 int ColumnAtMapFlowStart;
1313 bool NeedBitValueComma;
1314 bool NeedFlowSequenceComma;
1315 bool EnumerationMatchFound;
1319 /// YAML I/O does conversion based on types. But often native data types
1320 /// are just a typedef of built in intergral types (e.g. int). But the C++
1321 /// type matching system sees through the typedef and all the typedefed types
1322 /// look like a built in type. This will cause the generic YAML I/O conversion
1323 /// to be used. To provide better control over the YAML conversion, you can
1324 /// use this macro instead of typedef. It will create a class with one field
1325 /// and automatic conversion operators to and from the base type.
1326 /// Based on BOOST_STRONG_TYPEDEF
1327 #define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1329 _type() = default; \
1330 _type(const _base v) : value(v) {} \
1331 _type(const _type &v) = default; \
1332 _type &operator=(const _type &rhs) = default; \
1333 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1334 operator const _base & () const { return value; } \
1335 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1336 bool operator==(const _base &rhs) const { return value == rhs; } \
1337 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1339 typedef _base BaseType; \
1343 /// Use these types instead of uintXX_t in any mapping to have
1344 /// its yaml output formatted as hexadecimal.
1346 LLVM_YAML_STRONG_TYPEDEF(uint8_t, Hex8)
1347 LLVM_YAML_STRONG_TYPEDEF(uint16_t, Hex16)
1348 LLVM_YAML_STRONG_TYPEDEF(uint32_t, Hex32)
1349 LLVM_YAML_STRONG_TYPEDEF(uint64_t, Hex64)
1352 struct ScalarTraits<Hex8> {
1353 static void output(const Hex8 &, void*, llvm::raw_ostream &);
1354 static StringRef input(StringRef, void*, Hex8 &);
1355 static bool mustQuote(StringRef) { return false; }
1359 struct ScalarTraits<Hex16> {
1360 static void output(const Hex16 &, void*, llvm::raw_ostream &);
1361 static StringRef input(StringRef, void*, Hex16 &);
1362 static bool mustQuote(StringRef) { return false; }
1366 struct ScalarTraits<Hex32> {
1367 static void output(const Hex32 &, void*, llvm::raw_ostream &);
1368 static StringRef input(StringRef, void*, Hex32 &);
1369 static bool mustQuote(StringRef) { return false; }
1373 struct ScalarTraits<Hex64> {
1374 static void output(const Hex64 &, void*, llvm::raw_ostream &);
1375 static StringRef input(StringRef, void*, Hex64 &);
1376 static bool mustQuote(StringRef) { return false; }
1379 // Define non-member operator>> so that Input can stream in a document list.
1380 template <typename T>
1382 typename std::enable_if<has_DocumentListTraits<T>::value, Input &>::type
1383 operator>>(Input &yin, T &docList) {
1386 while ( yin.setCurrentDocument() ) {
1387 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i), true, Ctx);
1396 // Define non-member operator>> so that Input can stream in a map as a document.
1397 template <typename T>
1398 inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
1400 operator>>(Input &yin, T &docMap) {
1402 yin.setCurrentDocument();
1403 yamlize(yin, docMap, true, Ctx);
1407 // Define non-member operator>> so that Input can stream in a sequence as
1409 template <typename T>
1411 typename std::enable_if<has_SequenceTraits<T>::value, Input &>::type
1412 operator>>(Input &yin, T &docSeq) {
1414 if (yin.setCurrentDocument())
1415 yamlize(yin, docSeq, true, Ctx);
1419 // Define non-member operator>> so that Input can stream in a block scalar.
1420 template <typename T>
1422 typename std::enable_if<has_BlockScalarTraits<T>::value, Input &>::type
1423 operator>>(Input &In, T &Val) {
1425 if (In.setCurrentDocument())
1426 yamlize(In, Val, true, Ctx);
1430 // Define non-member operator>> so that Input can stream in a string map.
1431 template <typename T>
1433 typename std::enable_if<has_CustomMappingTraits<T>::value, Input &>::type
1434 operator>>(Input &In, T &Val) {
1436 if (In.setCurrentDocument())
1437 yamlize(In, Val, true, Ctx);
1441 // Provide better error message about types missing a trait specialization
1442 template <typename T>
1443 inline typename std::enable_if<missingTraits<T, EmptyContext>::value,
1445 operator>>(Input &yin, T &docSeq) {
1446 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1450 // Define non-member operator<< so that Output can stream out document list.
1451 template <typename T>
1453 typename std::enable_if<has_DocumentListTraits<T>::value, Output &>::type
1454 operator<<(Output &yout, T &docList) {
1456 yout.beginDocuments();
1457 const size_t count = DocumentListTraits<T>::size(yout, docList);
1458 for(size_t i=0; i < count; ++i) {
1459 if ( yout.preflightDocument(i) ) {
1460 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i), true,
1462 yout.postflightDocument();
1465 yout.endDocuments();
1469 // Define non-member operator<< so that Output can stream out a map.
1470 template <typename T>
1471 inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
1473 operator<<(Output &yout, T &map) {
1475 yout.beginDocuments();
1476 if ( yout.preflightDocument(0) ) {
1477 yamlize(yout, map, true, Ctx);
1478 yout.postflightDocument();
1480 yout.endDocuments();
1484 // Define non-member operator<< so that Output can stream out a sequence.
1485 template <typename T>
1487 typename std::enable_if<has_SequenceTraits<T>::value, Output &>::type
1488 operator<<(Output &yout, T &seq) {
1490 yout.beginDocuments();
1491 if ( yout.preflightDocument(0) ) {
1492 yamlize(yout, seq, true, Ctx);
1493 yout.postflightDocument();
1495 yout.endDocuments();
1499 // Define non-member operator<< so that Output can stream out a block scalar.
1500 template <typename T>
1502 typename std::enable_if<has_BlockScalarTraits<T>::value, Output &>::type
1503 operator<<(Output &Out, T &Val) {
1505 Out.beginDocuments();
1506 if (Out.preflightDocument(0)) {
1507 yamlize(Out, Val, true, Ctx);
1508 Out.postflightDocument();
1514 // Define non-member operator<< so that Output can stream out a string map.
1515 template <typename T>
1517 typename std::enable_if<has_CustomMappingTraits<T>::value, Output &>::type
1518 operator<<(Output &Out, T &Val) {
1520 Out.beginDocuments();
1521 if (Out.preflightDocument(0)) {
1522 yamlize(Out, Val, true, Ctx);
1523 Out.postflightDocument();
1529 // Provide better error message about types missing a trait specialization
1530 template <typename T>
1531 inline typename std::enable_if<missingTraits<T, EmptyContext>::value,
1533 operator<<(Output &yout, T &seq) {
1534 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1538 template <typename T> struct SequenceTraitsImpl {
1539 typedef typename T::value_type _type;
1540 static size_t size(IO &io, T &seq) { return seq.size(); }
1541 static _type &element(IO &io, T &seq, size_t index) {
1542 if (index >= seq.size())
1543 seq.resize(index + 1);
1548 /// Implementation of CustomMappingTraits for std::map<std::string, T>.
1549 template <typename T> struct StdMapStringCustomMappingTraitsImpl {
1550 typedef std::map<std::string, T> map_type;
1551 static void inputOne(IO &io, StringRef key, map_type &v) {
1552 io.mapRequired(key.str().c_str(), v[key]);
1554 static void output(IO &io, map_type &v) {
1556 io.mapRequired(p.first.c_str(), p.second);
1560 } // end namespace yaml
1561 } // end namespace llvm
1563 /// Utility for declaring that a std::vector of a particular type
1564 /// should be considered a YAML sequence.
1565 #define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \
1569 struct SequenceTraits<std::vector<_type>> \
1570 : public SequenceTraitsImpl<std::vector<_type>> {}; \
1571 template <unsigned N> \
1572 struct SequenceTraits<SmallVector<_type, N>> \
1573 : public SequenceTraitsImpl<SmallVector<_type, N>> {}; \
1577 /// Utility for declaring that a std::vector of a particular type
1578 /// should be considered a YAML flow sequence.
1579 /// We need to do a partial specialization on the vector version, not a full.
1580 /// If this is a full specialization, the compiler is a bit too "smart" and
1581 /// decides to warn on -Wunused-const-variable. This workaround can be
1582 /// removed and we can do a full specialization on std::vector<T> once
1583 /// PR28878 is fixed.
1584 #define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \
1587 template <unsigned N> \
1588 struct SequenceTraits<SmallVector<_type, N>> \
1589 : public SequenceTraitsImpl<SmallVector<_type, N>> { \
1590 static const bool flow = true; \
1592 template <typename Allocator> \
1593 struct SequenceTraits<std::vector<_type, Allocator>> \
1594 : public SequenceTraitsImpl<std::vector<_type, Allocator>> { \
1595 static const bool flow = true; \
1600 /// Utility for declaring that a std::vector of a particular type
1601 /// should be considered a YAML document list.
1602 #define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
1605 template <unsigned N> \
1606 struct DocumentListTraits<SmallVector<_type, N>> \
1607 : public SequenceTraitsImpl<SmallVector<_type, N>> {}; \
1609 struct DocumentListTraits<std::vector<_type>> \
1610 : public SequenceTraitsImpl<std::vector<_type>> {}; \
1614 /// Utility for declaring that std::map<std::string, _type> should be considered
1616 #define LLVM_YAML_IS_STRING_MAP(_type) \
1620 struct CustomMappingTraits<std::map<std::string, _type>> \
1621 : public StdMapStringCustomMappingTraitsImpl<_type> {}; \
1625 #endif // LLVM_SUPPORT_YAMLTRAITS_H