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 = static_cast<T>(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 = static_cast<T>(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!");
692 bool UseDefault = true;
693 const bool sameAsDefault = outputting() && !Val.hasValue();
694 if (!outputting() && !Val.hasValue())
696 if (Val.hasValue() &&
697 this->preflightKey(Key, Required, sameAsDefault, UseDefault,
699 yamlize(*this, Val.getValue(), Required, Ctx);
700 this->postflightKey(SaveInfo);
707 template <typename T, typename Context>
708 void processKeyWithDefault(const char *Key, T &Val, const T &DefaultValue,
709 bool Required, Context &Ctx) {
712 const bool sameAsDefault = outputting() && Val == DefaultValue;
713 if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
715 yamlize(*this, Val, Required, Ctx);
716 this->postflightKey(SaveInfo);
724 template <typename T, typename Context>
725 void processKey(const char *Key, T &Val, bool Required, Context &Ctx) {
728 if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) {
729 yamlize(*this, Val, Required, Ctx);
730 this->postflightKey(SaveInfo);
740 template <typename T, typename Context>
741 void doMapping(IO &io, T &Val, Context &Ctx) {
742 MappingContextTraits<T, Context>::mapping(io, Val, Ctx);
745 template <typename T> void doMapping(IO &io, T &Val, EmptyContext &Ctx) {
746 MappingTraits<T>::mapping(io, Val);
749 } // end namespace detail
751 template <typename T>
752 typename std::enable_if<has_ScalarEnumerationTraits<T>::value, void>::type
753 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
754 io.beginEnumScalar();
755 ScalarEnumerationTraits<T>::enumeration(io, Val);
759 template <typename T>
760 typename std::enable_if<has_ScalarBitSetTraits<T>::value, void>::type
761 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
763 if ( io.beginBitSetScalar(DoClear) ) {
765 Val = static_cast<T>(0);
766 ScalarBitSetTraits<T>::bitset(io, Val);
767 io.endBitSetScalar();
771 template <typename T>
772 typename std::enable_if<has_ScalarTraits<T>::value, void>::type
773 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
774 if ( io.outputting() ) {
776 llvm::raw_string_ostream Buffer(Storage);
777 ScalarTraits<T>::output(Val, io.getContext(), Buffer);
778 StringRef Str = Buffer.str();
779 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
783 io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
784 StringRef Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
785 if ( !Result.empty() ) {
786 io.setError(llvm::Twine(Result));
791 template <typename T>
792 typename std::enable_if<has_BlockScalarTraits<T>::value, void>::type
793 yamlize(IO &YamlIO, T &Val, bool, EmptyContext &Ctx) {
794 if (YamlIO.outputting()) {
796 llvm::raw_string_ostream Buffer(Storage);
797 BlockScalarTraits<T>::output(Val, YamlIO.getContext(), Buffer);
798 StringRef Str = Buffer.str();
799 YamlIO.blockScalarString(Str);
802 YamlIO.blockScalarString(Str);
804 BlockScalarTraits<T>::input(Str, YamlIO.getContext(), Val);
806 YamlIO.setError(llvm::Twine(Result));
810 template <typename T, typename Context>
811 typename std::enable_if<validatedMappingTraits<T, Context>::value, void>::type
812 yamlize(IO &io, T &Val, bool, Context &Ctx) {
813 if (has_FlowTraits<MappingTraits<T>>::value)
814 io.beginFlowMapping();
817 if (io.outputting()) {
818 StringRef Err = MappingTraits<T>::validate(io, Val);
820 llvm::errs() << Err << "\n";
821 assert(Err.empty() && "invalid struct trying to be written as yaml");
824 detail::doMapping(io, Val, Ctx);
825 if (!io.outputting()) {
826 StringRef Err = MappingTraits<T>::validate(io, Val);
830 if (has_FlowTraits<MappingTraits<T>>::value)
836 template <typename T, typename Context>
837 typename std::enable_if<unvalidatedMappingTraits<T, Context>::value, void>::type
838 yamlize(IO &io, T &Val, bool, Context &Ctx) {
839 if (has_FlowTraits<MappingTraits<T>>::value) {
840 io.beginFlowMapping();
841 detail::doMapping(io, Val, Ctx);
845 detail::doMapping(io, Val, Ctx);
850 template <typename T>
851 typename std::enable_if<has_CustomMappingTraits<T>::value, void>::type
852 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
853 if ( io.outputting() ) {
855 CustomMappingTraits<T>::output(io, Val);
859 for (StringRef key : io.keys())
860 CustomMappingTraits<T>::inputOne(io, key, Val);
865 template <typename T>
866 typename std::enable_if<missingTraits<T, EmptyContext>::value, void>::type
867 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
868 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
871 template <typename T, typename Context>
872 typename std::enable_if<has_SequenceTraits<T>::value, void>::type
873 yamlize(IO &io, T &Seq, bool, Context &Ctx) {
874 if ( has_FlowTraits< SequenceTraits<T> >::value ) {
875 unsigned incnt = io.beginFlowSequence();
876 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
877 for(unsigned i=0; i < count; ++i) {
879 if ( io.preflightFlowElement(i, SaveInfo) ) {
880 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
881 io.postflightFlowElement(SaveInfo);
884 io.endFlowSequence();
887 unsigned incnt = io.beginSequence();
888 unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
889 for(unsigned i=0; i < count; ++i) {
891 if ( io.preflightElement(i, SaveInfo) ) {
892 yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
893 io.postflightElement(SaveInfo);
901 struct ScalarTraits<bool> {
902 static void output(const bool &, void*, llvm::raw_ostream &);
903 static StringRef input(StringRef, void*, bool &);
904 static bool mustQuote(StringRef) { return false; }
908 struct ScalarTraits<StringRef> {
909 static void output(const StringRef &, void*, llvm::raw_ostream &);
910 static StringRef input(StringRef, void*, StringRef &);
911 static bool mustQuote(StringRef S) { return needsQuotes(S); }
915 struct ScalarTraits<std::string> {
916 static void output(const std::string &, void*, llvm::raw_ostream &);
917 static StringRef input(StringRef, void*, std::string &);
918 static bool mustQuote(StringRef S) { return needsQuotes(S); }
922 struct ScalarTraits<uint8_t> {
923 static void output(const uint8_t &, void*, llvm::raw_ostream &);
924 static StringRef input(StringRef, void*, uint8_t &);
925 static bool mustQuote(StringRef) { return false; }
929 struct ScalarTraits<uint16_t> {
930 static void output(const uint16_t &, void*, llvm::raw_ostream &);
931 static StringRef input(StringRef, void*, uint16_t &);
932 static bool mustQuote(StringRef) { return false; }
936 struct ScalarTraits<uint32_t> {
937 static void output(const uint32_t &, void*, llvm::raw_ostream &);
938 static StringRef input(StringRef, void*, uint32_t &);
939 static bool mustQuote(StringRef) { return false; }
943 struct ScalarTraits<uint64_t> {
944 static void output(const uint64_t &, void*, llvm::raw_ostream &);
945 static StringRef input(StringRef, void*, uint64_t &);
946 static bool mustQuote(StringRef) { return false; }
950 struct ScalarTraits<int8_t> {
951 static void output(const int8_t &, void*, llvm::raw_ostream &);
952 static StringRef input(StringRef, void*, int8_t &);
953 static bool mustQuote(StringRef) { return false; }
957 struct ScalarTraits<int16_t> {
958 static void output(const int16_t &, void*, llvm::raw_ostream &);
959 static StringRef input(StringRef, void*, int16_t &);
960 static bool mustQuote(StringRef) { return false; }
964 struct ScalarTraits<int32_t> {
965 static void output(const int32_t &, void*, llvm::raw_ostream &);
966 static StringRef input(StringRef, void*, int32_t &);
967 static bool mustQuote(StringRef) { return false; }
971 struct ScalarTraits<int64_t> {
972 static void output(const int64_t &, void*, llvm::raw_ostream &);
973 static StringRef input(StringRef, void*, int64_t &);
974 static bool mustQuote(StringRef) { return false; }
978 struct ScalarTraits<float> {
979 static void output(const float &, void*, llvm::raw_ostream &);
980 static StringRef input(StringRef, void*, float &);
981 static bool mustQuote(StringRef) { return false; }
985 struct ScalarTraits<double> {
986 static void output(const double &, void*, llvm::raw_ostream &);
987 static StringRef input(StringRef, void*, double &);
988 static bool mustQuote(StringRef) { return false; }
991 // For endian types, we just use the existing ScalarTraits for the underlying
992 // type. This way endian aware types are supported whenever a ScalarTraits
993 // is defined for the underlying type.
994 template <typename value_type, support::endianness endian, size_t alignment>
995 struct ScalarTraits<support::detail::packed_endian_specific_integral<
996 value_type, endian, alignment>> {
997 typedef support::detail::packed_endian_specific_integral<value_type, endian,
1001 static void output(const endian_type &E, void *Ctx,
1002 llvm::raw_ostream &Stream) {
1003 ScalarTraits<value_type>::output(static_cast<value_type>(E), Ctx, Stream);
1006 static StringRef input(StringRef Str, void *Ctx, endian_type &E) {
1008 auto R = ScalarTraits<value_type>::input(Str, Ctx, V);
1009 E = static_cast<endian_type>(V);
1013 static bool mustQuote(StringRef Str) {
1014 return ScalarTraits<value_type>::mustQuote(Str);
1018 // Utility for use within MappingTraits<>::mapping() method
1019 // to [de]normalize an object for use with YAML conversion.
1020 template <typename TNorm, typename TFinal>
1021 struct MappingNormalization {
1022 MappingNormalization(IO &i_o, TFinal &Obj)
1023 : io(i_o), BufPtr(nullptr), Result(Obj) {
1024 if ( io.outputting() ) {
1025 BufPtr = new (&Buffer) TNorm(io, Obj);
1028 BufPtr = new (&Buffer) TNorm(io);
1032 ~MappingNormalization() {
1033 if ( ! io.outputting() ) {
1034 Result = BufPtr->denormalize(io);
1039 TNorm* operator->() { return BufPtr; }
1042 typedef llvm::AlignedCharArrayUnion<TNorm> Storage;
1050 // Utility for use within MappingTraits<>::mapping() method
1051 // to [de]normalize an object for use with YAML conversion.
1052 template <typename TNorm, typename TFinal>
1053 struct MappingNormalizationHeap {
1054 MappingNormalizationHeap(IO &i_o, TFinal &Obj,
1055 llvm::BumpPtrAllocator *allocator)
1056 : io(i_o), BufPtr(nullptr), Result(Obj) {
1057 if ( io.outputting() ) {
1058 BufPtr = new (&Buffer) TNorm(io, Obj);
1060 else if (allocator) {
1061 BufPtr = allocator->Allocate<TNorm>();
1062 new (BufPtr) TNorm(io);
1064 BufPtr = new TNorm(io);
1068 ~MappingNormalizationHeap() {
1069 if ( io.outputting() ) {
1073 Result = BufPtr->denormalize(io);
1077 TNorm* operator->() { return BufPtr; }
1080 typedef llvm::AlignedCharArrayUnion<TNorm> Storage;
1089 /// The Input class is used to parse a yaml document into in-memory structs
1092 /// It works by using YAMLParser to do a syntax parse of the entire yaml
1093 /// document, then the Input class builds a graph of HNodes which wraps
1094 /// each yaml Node. The extra layer is buffering. The low level yaml
1095 /// parser only lets you look at each node once. The buffering layer lets
1096 /// you search and interate multiple times. This is necessary because
1097 /// the mapRequired() method calls may not be in the same order
1098 /// as the keys in the document.
1100 class Input : public IO {
1102 // Construct a yaml Input object from a StringRef and optional
1103 // user-data. The DiagHandler can be specified to provide
1104 // alternative error reporting.
1105 Input(StringRef InputContent,
1106 void *Ctxt = nullptr,
1107 SourceMgr::DiagHandlerTy DiagHandler = nullptr,
1108 void *DiagHandlerCtxt = nullptr);
1111 // Check if there was an syntax or semantic error during parsing.
1112 std::error_code error();
1115 bool outputting() override;
1116 bool mapTag(StringRef, bool) override;
1117 void beginMapping() override;
1118 void endMapping() override;
1119 bool preflightKey(const char *, bool, bool, bool &, void *&) override;
1120 void postflightKey(void *) override;
1121 std::vector<StringRef> keys() override;
1122 void beginFlowMapping() override;
1123 void endFlowMapping() override;
1124 unsigned beginSequence() override;
1125 void endSequence() override;
1126 bool preflightElement(unsigned index, void *&) override;
1127 void postflightElement(void *) override;
1128 unsigned beginFlowSequence() override;
1129 bool preflightFlowElement(unsigned , void *&) override;
1130 void postflightFlowElement(void *) override;
1131 void endFlowSequence() override;
1132 void beginEnumScalar() override;
1133 bool matchEnumScalar(const char*, bool) override;
1134 bool matchEnumFallback() override;
1135 void endEnumScalar() override;
1136 bool beginBitSetScalar(bool &) override;
1137 bool bitSetMatch(const char *, bool ) override;
1138 void endBitSetScalar() override;
1139 void scalarString(StringRef &, bool) override;
1140 void blockScalarString(StringRef &) override;
1141 void setError(const Twine &message) override;
1142 bool canElideEmptySequence() override;
1145 virtual void anchor();
1148 HNode(Node *n) : _node(n) { }
1149 virtual ~HNode() = default;
1151 static inline bool classof(const HNode *) { return true; }
1156 class EmptyHNode : public HNode {
1157 void anchor() override;
1160 EmptyHNode(Node *n) : HNode(n) { }
1162 static inline bool classof(const HNode *n) {
1163 return NullNode::classof(n->_node);
1166 static inline bool classof(const EmptyHNode *) { return true; }
1169 class ScalarHNode : public HNode {
1170 void anchor() override;
1173 ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
1175 StringRef value() const { return _value; }
1177 static inline bool classof(const HNode *n) {
1178 return ScalarNode::classof(n->_node) ||
1179 BlockScalarNode::classof(n->_node);
1182 static inline bool classof(const ScalarHNode *) { return true; }
1188 class MapHNode : public HNode {
1189 void anchor() override;
1192 MapHNode(Node *n) : HNode(n) { }
1194 static inline bool classof(const HNode *n) {
1195 return MappingNode::classof(n->_node);
1198 static inline bool classof(const MapHNode *) { return true; }
1200 typedef llvm::StringMap<std::unique_ptr<HNode>> NameToNode;
1203 llvm::SmallVector<std::string, 6> ValidKeys;
1206 class SequenceHNode : public HNode {
1207 void anchor() override;
1210 SequenceHNode(Node *n) : HNode(n) { }
1212 static inline bool classof(const HNode *n) {
1213 return SequenceNode::classof(n->_node);
1216 static inline bool classof(const SequenceHNode *) { return true; }
1218 std::vector<std::unique_ptr<HNode>> Entries;
1221 std::unique_ptr<Input::HNode> createHNodes(Node *node);
1222 void setError(HNode *hnode, const Twine &message);
1223 void setError(Node *node, const Twine &message);
1226 // These are only used by operator>>. They could be private
1227 // if those templated things could be made friends.
1228 bool setCurrentDocument();
1229 bool nextDocument();
1231 /// Returns the current node that's being parsed by the YAML Parser.
1232 const Node *getCurrentNode() const;
1235 llvm::SourceMgr SrcMgr; // must be before Strm
1236 std::unique_ptr<llvm::yaml::Stream> Strm;
1237 std::unique_ptr<HNode> TopNode;
1239 llvm::BumpPtrAllocator StringAllocator;
1240 llvm::yaml::document_iterator DocIterator;
1241 std::vector<bool> BitValuesUsed;
1243 bool ScalarMatchFound;
1247 /// The Output class is used to generate a yaml document from in-memory structs
1250 class Output : public IO {
1252 Output(llvm::raw_ostream &, void *Ctxt = nullptr, int WrapColumn = 70);
1255 /// \brief Set whether or not to output optional values which are equal
1256 /// to the default value. By default, when outputting if you attempt
1257 /// to write a value that is equal to the default, the value gets ignored.
1258 /// Sometimes, it is useful to be able to see these in the resulting YAML
1260 void setWriteDefaultValues(bool Write) { WriteDefaultValues = Write; }
1262 bool outputting() override;
1263 bool mapTag(StringRef, bool) override;
1264 void beginMapping() override;
1265 void endMapping() override;
1266 bool preflightKey(const char *key, bool, bool, bool &, void *&) override;
1267 void postflightKey(void *) override;
1268 std::vector<StringRef> keys() override;
1269 void beginFlowMapping() override;
1270 void endFlowMapping() override;
1271 unsigned beginSequence() override;
1272 void endSequence() override;
1273 bool preflightElement(unsigned, void *&) override;
1274 void postflightElement(void *) override;
1275 unsigned beginFlowSequence() override;
1276 bool preflightFlowElement(unsigned, void *&) override;
1277 void postflightFlowElement(void *) override;
1278 void endFlowSequence() override;
1279 void beginEnumScalar() override;
1280 bool matchEnumScalar(const char*, bool) override;
1281 bool matchEnumFallback() override;
1282 void endEnumScalar() override;
1283 bool beginBitSetScalar(bool &) override;
1284 bool bitSetMatch(const char *, bool ) override;
1285 void endBitSetScalar() override;
1286 void scalarString(StringRef &, bool) override;
1287 void blockScalarString(StringRef &) override;
1288 void setError(const Twine &message) override;
1289 bool canElideEmptySequence() override;
1291 // These are only used by operator<<. They could be private
1292 // if that templated operator could be made a friend.
1293 void beginDocuments();
1294 bool preflightDocument(unsigned);
1295 void postflightDocument();
1296 void endDocuments();
1299 void output(StringRef s);
1300 void outputUpToEndOfLine(StringRef s);
1301 void newLineCheck();
1302 void outputNewLine();
1303 void paddedKey(StringRef key);
1304 void flowKey(StringRef Key);
1315 llvm::raw_ostream &Out;
1317 SmallVector<InState, 8> StateStack;
1319 int ColumnAtFlowStart;
1320 int ColumnAtMapFlowStart;
1321 bool NeedBitValueComma;
1322 bool NeedFlowSequenceComma;
1323 bool EnumerationMatchFound;
1325 bool WriteDefaultValues;
1328 /// YAML I/O does conversion based on types. But often native data types
1329 /// are just a typedef of built in intergral types (e.g. int). But the C++
1330 /// type matching system sees through the typedef and all the typedefed types
1331 /// look like a built in type. This will cause the generic YAML I/O conversion
1332 /// to be used. To provide better control over the YAML conversion, you can
1333 /// use this macro instead of typedef. It will create a class with one field
1334 /// and automatic conversion operators to and from the base type.
1335 /// Based on BOOST_STRONG_TYPEDEF
1336 #define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
1338 _type() = default; \
1339 _type(const _base v) : value(v) {} \
1340 _type(const _type &v) = default; \
1341 _type &operator=(const _type &rhs) = default; \
1342 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
1343 operator const _base & () const { return value; } \
1344 bool operator==(const _type &rhs) const { return value == rhs.value; } \
1345 bool operator==(const _base &rhs) const { return value == rhs; } \
1346 bool operator<(const _type &rhs) const { return value < rhs.value; } \
1348 typedef _base BaseType; \
1352 /// Use these types instead of uintXX_t in any mapping to have
1353 /// its yaml output formatted as hexadecimal.
1355 LLVM_YAML_STRONG_TYPEDEF(uint8_t, Hex8)
1356 LLVM_YAML_STRONG_TYPEDEF(uint16_t, Hex16)
1357 LLVM_YAML_STRONG_TYPEDEF(uint32_t, Hex32)
1358 LLVM_YAML_STRONG_TYPEDEF(uint64_t, Hex64)
1361 struct ScalarTraits<Hex8> {
1362 static void output(const Hex8 &, void*, llvm::raw_ostream &);
1363 static StringRef input(StringRef, void*, Hex8 &);
1364 static bool mustQuote(StringRef) { return false; }
1368 struct ScalarTraits<Hex16> {
1369 static void output(const Hex16 &, void*, llvm::raw_ostream &);
1370 static StringRef input(StringRef, void*, Hex16 &);
1371 static bool mustQuote(StringRef) { return false; }
1375 struct ScalarTraits<Hex32> {
1376 static void output(const Hex32 &, void*, llvm::raw_ostream &);
1377 static StringRef input(StringRef, void*, Hex32 &);
1378 static bool mustQuote(StringRef) { return false; }
1382 struct ScalarTraits<Hex64> {
1383 static void output(const Hex64 &, void*, llvm::raw_ostream &);
1384 static StringRef input(StringRef, void*, Hex64 &);
1385 static bool mustQuote(StringRef) { return false; }
1388 // Define non-member operator>> so that Input can stream in a document list.
1389 template <typename T>
1391 typename std::enable_if<has_DocumentListTraits<T>::value, Input &>::type
1392 operator>>(Input &yin, T &docList) {
1395 while ( yin.setCurrentDocument() ) {
1396 yamlize(yin, DocumentListTraits<T>::element(yin, docList, i), true, Ctx);
1405 // Define non-member operator>> so that Input can stream in a map as a document.
1406 template <typename T>
1407 inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
1409 operator>>(Input &yin, T &docMap) {
1411 yin.setCurrentDocument();
1412 yamlize(yin, docMap, true, Ctx);
1416 // Define non-member operator>> so that Input can stream in a sequence as
1418 template <typename T>
1420 typename std::enable_if<has_SequenceTraits<T>::value, Input &>::type
1421 operator>>(Input &yin, T &docSeq) {
1423 if (yin.setCurrentDocument())
1424 yamlize(yin, docSeq, true, Ctx);
1428 // Define non-member operator>> so that Input can stream in a block scalar.
1429 template <typename T>
1431 typename std::enable_if<has_BlockScalarTraits<T>::value, Input &>::type
1432 operator>>(Input &In, T &Val) {
1434 if (In.setCurrentDocument())
1435 yamlize(In, Val, true, Ctx);
1439 // Define non-member operator>> so that Input can stream in a string map.
1440 template <typename T>
1442 typename std::enable_if<has_CustomMappingTraits<T>::value, Input &>::type
1443 operator>>(Input &In, T &Val) {
1445 if (In.setCurrentDocument())
1446 yamlize(In, Val, true, Ctx);
1450 // Provide better error message about types missing a trait specialization
1451 template <typename T>
1452 inline typename std::enable_if<missingTraits<T, EmptyContext>::value,
1454 operator>>(Input &yin, T &docSeq) {
1455 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1459 // Define non-member operator<< so that Output can stream out document list.
1460 template <typename T>
1462 typename std::enable_if<has_DocumentListTraits<T>::value, Output &>::type
1463 operator<<(Output &yout, T &docList) {
1465 yout.beginDocuments();
1466 const size_t count = DocumentListTraits<T>::size(yout, docList);
1467 for(size_t i=0; i < count; ++i) {
1468 if ( yout.preflightDocument(i) ) {
1469 yamlize(yout, DocumentListTraits<T>::element(yout, docList, i), true,
1471 yout.postflightDocument();
1474 yout.endDocuments();
1478 // Define non-member operator<< so that Output can stream out a map.
1479 template <typename T>
1480 inline typename std::enable_if<has_MappingTraits<T, EmptyContext>::value,
1482 operator<<(Output &yout, T &map) {
1484 yout.beginDocuments();
1485 if ( yout.preflightDocument(0) ) {
1486 yamlize(yout, map, true, Ctx);
1487 yout.postflightDocument();
1489 yout.endDocuments();
1493 // Define non-member operator<< so that Output can stream out a sequence.
1494 template <typename T>
1496 typename std::enable_if<has_SequenceTraits<T>::value, Output &>::type
1497 operator<<(Output &yout, T &seq) {
1499 yout.beginDocuments();
1500 if ( yout.preflightDocument(0) ) {
1501 yamlize(yout, seq, true, Ctx);
1502 yout.postflightDocument();
1504 yout.endDocuments();
1508 // Define non-member operator<< so that Output can stream out a block scalar.
1509 template <typename T>
1511 typename std::enable_if<has_BlockScalarTraits<T>::value, Output &>::type
1512 operator<<(Output &Out, T &Val) {
1514 Out.beginDocuments();
1515 if (Out.preflightDocument(0)) {
1516 yamlize(Out, Val, true, Ctx);
1517 Out.postflightDocument();
1523 // Define non-member operator<< so that Output can stream out a string map.
1524 template <typename T>
1526 typename std::enable_if<has_CustomMappingTraits<T>::value, Output &>::type
1527 operator<<(Output &Out, T &Val) {
1529 Out.beginDocuments();
1530 if (Out.preflightDocument(0)) {
1531 yamlize(Out, Val, true, Ctx);
1532 Out.postflightDocument();
1538 // Provide better error message about types missing a trait specialization
1539 template <typename T>
1540 inline typename std::enable_if<missingTraits<T, EmptyContext>::value,
1542 operator<<(Output &yout, T &seq) {
1543 char missing_yaml_trait_for_type[sizeof(MissingTrait<T>)];
1547 template <typename T> struct SequenceTraitsImpl {
1548 typedef typename T::value_type _type;
1549 static size_t size(IO &io, T &seq) { return seq.size(); }
1550 static _type &element(IO &io, T &seq, size_t index) {
1551 if (index >= seq.size())
1552 seq.resize(index + 1);
1557 /// Implementation of CustomMappingTraits for std::map<std::string, T>.
1558 template <typename T> struct StdMapStringCustomMappingTraitsImpl {
1559 typedef std::map<std::string, T> map_type;
1560 static void inputOne(IO &io, StringRef key, map_type &v) {
1561 io.mapRequired(key.str().c_str(), v[key]);
1563 static void output(IO &io, map_type &v) {
1565 io.mapRequired(p.first.c_str(), p.second);
1569 } // end namespace yaml
1570 } // end namespace llvm
1572 /// Utility for declaring that a std::vector of a particular type
1573 /// should be considered a YAML sequence.
1574 #define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \
1578 struct SequenceTraits<std::vector<_type>> \
1579 : public SequenceTraitsImpl<std::vector<_type>> {}; \
1580 template <unsigned N> \
1581 struct SequenceTraits<SmallVector<_type, N>> \
1582 : public SequenceTraitsImpl<SmallVector<_type, N>> {}; \
1586 /// Utility for declaring that a std::vector of a particular type
1587 /// should be considered a YAML flow sequence.
1588 /// We need to do a partial specialization on the vector version, not a full.
1589 /// If this is a full specialization, the compiler is a bit too "smart" and
1590 /// decides to warn on -Wunused-const-variable. This workaround can be
1591 /// removed and we can do a full specialization on std::vector<T> once
1592 /// PR28878 is fixed.
1593 #define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \
1596 template <unsigned N> \
1597 struct SequenceTraits<SmallVector<_type, N>> \
1598 : public SequenceTraitsImpl<SmallVector<_type, N>> { \
1599 static const bool flow = true; \
1601 template <typename Allocator> \
1602 struct SequenceTraits<std::vector<_type, Allocator>> \
1603 : public SequenceTraitsImpl<std::vector<_type, Allocator>> { \
1604 static const bool flow = true; \
1609 /// Utility for declaring that a std::vector of a particular type
1610 /// should be considered a YAML document list.
1611 #define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
1614 template <unsigned N> \
1615 struct DocumentListTraits<SmallVector<_type, N>> \
1616 : public SequenceTraitsImpl<SmallVector<_type, N>> {}; \
1618 struct DocumentListTraits<std::vector<_type>> \
1619 : public SequenceTraitsImpl<std::vector<_type>> {}; \
1623 /// Utility for declaring that std::map<std::string, _type> should be considered
1625 #define LLVM_YAML_IS_STRING_MAP(_type) \
1629 struct CustomMappingTraits<std::map<std::string, _type>> \
1630 : public StdMapStringCustomMappingTraitsImpl<_type> {}; \
1634 #endif // LLVM_SUPPORT_YAMLTRAITS_H