HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Android 10
|
10.0.0_r6
下载
查看原文件
收藏
根目录
prebuilts
clang
host
darwin-x86
clang-r349610b
include
llvm
Support
YAMLTraits.h
//===- llvm/Support/YAMLTraits.h --------------------------------*- C++ -*-===// // // The LLVM Linker // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_YAMLTRAITS_H #define LLVM_SUPPORT_YAMLTRAITS_H #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/AlignOf.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Regex.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" #include "llvm/Support/raw_ostream.h" #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace llvm { namespace yaml { enum class NodeKind : uint8_t { Scalar, Map, Sequence, }; struct EmptyContext {}; /// This class should be specialized by any type that needs to be converted /// to/from a YAML mapping. For example: /// /// struct MappingTraits
{ /// static void mapping(IO &io, MyStruct &s) { /// io.mapRequired("name", s.name); /// io.mapRequired("size", s.size); /// io.mapOptional("age", s.age); /// } /// }; template
struct MappingTraits { // Must provide: // static void mapping(IO &io, T &fields); // Optionally may provide: // static StringRef validate(IO &io, T &fields); // // The optional flow flag will cause generated YAML to use a flow mapping // (e.g. { a: 0, b: 1 }): // static const bool flow = true; }; /// This class is similar to MappingTraits
but allows you to pass in /// additional context for each map operation. For example: /// /// struct MappingContextTraits
{ /// static void mapping(IO &io, MyStruct &s, MyContext &c) { /// io.mapRequired("name", s.name); /// io.mapRequired("size", s.size); /// io.mapOptional("age", s.age); /// ++c.TimesMapped; /// } /// }; template
struct MappingContextTraits { // Must provide: // static void mapping(IO &io, T &fields, Context &Ctx); // Optionally may provide: // static StringRef validate(IO &io, T &fields, Context &Ctx); // // The optional flow flag will cause generated YAML to use a flow mapping // (e.g. { a: 0, b: 1 }): // static const bool flow = true; }; /// This class should be specialized by any integral type that converts /// to/from a YAML scalar where there is a one-to-one mapping between /// in-memory values and a string in YAML. For example: /// /// struct ScalarEnumerationTraits
{ /// static void enumeration(IO &io, Colors &value) { /// io.enumCase(value, "red", cRed); /// io.enumCase(value, "blue", cBlue); /// io.enumCase(value, "green", cGreen); /// } /// }; template
struct ScalarEnumerationTraits { // Must provide: // static void enumeration(IO &io, T &value); }; /// This class should be specialized by any integer type that is a union /// of bit values and the YAML representation is a flow sequence of /// strings. For example: /// /// struct ScalarBitSetTraits
{ /// static void bitset(IO &io, MyFlags &value) { /// io.bitSetCase(value, "big", flagBig); /// io.bitSetCase(value, "flat", flagFlat); /// io.bitSetCase(value, "round", flagRound); /// } /// }; template
struct ScalarBitSetTraits { // Must provide: // static void bitset(IO &io, T &value); }; /// Describe which type of quotes should be used when quoting is necessary. /// Some non-printable characters need to be double-quoted, while some others /// are fine with simple-quoting, and some don't need any quoting. enum class QuotingType { None, Single, Double }; /// This class should be specialized by type that requires custom conversion /// to/from a yaml scalar. For example: /// /// template<> /// struct ScalarTraits
{ /// static void output(const MyType &val, void*, llvm::raw_ostream &out) { /// // stream out custom formatting /// out << llvm::format("%x", val); /// } /// static StringRef input(StringRef scalar, void*, MyType &value) { /// // parse scalar and set `value` /// // return empty string on success, or error string /// return StringRef(); /// } /// static QuotingType mustQuote(StringRef) { return QuotingType::Single; } /// }; template
struct ScalarTraits { // Must provide: // // Function to write the value as a string: // static void output(const T &value, void *ctxt, llvm::raw_ostream &out); // // Function to convert a string to a value. Returns the empty // StringRef on success or an error string if string is malformed: // static StringRef input(StringRef scalar, void *ctxt, T &value); // // Function to determine if the value should be quoted. // static QuotingType mustQuote(StringRef); }; /// This class should be specialized by type that requires custom conversion /// to/from a YAML literal block scalar. For example: /// /// template <> /// struct BlockScalarTraits
{ /// static void output(const MyType &Value, void*, llvm::raw_ostream &Out) /// { /// // stream out custom formatting /// Out << Value; /// } /// static StringRef input(StringRef Scalar, void*, MyType &Value) { /// // parse scalar and set `value` /// // return empty string on success, or error string /// return StringRef(); /// } /// }; template
struct BlockScalarTraits { // Must provide: // // Function to write the value as a string: // static void output(const T &Value, void *ctx, llvm::raw_ostream &Out); // // Function to convert a string to a value. Returns the empty // StringRef on success or an error string if string is malformed: // static StringRef input(StringRef Scalar, void *ctxt, T &Value); // // Optional: // static StringRef inputTag(T &Val, std::string Tag) // static void outputTag(const T &Val, raw_ostream &Out) }; /// This class should be specialized by type that requires custom conversion /// to/from a YAML scalar with optional tags. For example: /// /// template <> /// struct TaggedScalarTraits
{ /// static void output(const MyType &Value, void*, llvm::raw_ostream /// &ScalarOut, llvm::raw_ostream &TagOut) /// { /// // stream out custom formatting including optional Tag /// Out << Value; /// } /// static StringRef input(StringRef Scalar, StringRef Tag, void*, MyType /// &Value) { /// // parse scalar and set `value` /// // return empty string on success, or error string /// return StringRef(); /// } /// static QuotingType mustQuote(const MyType &Value, StringRef) { /// return QuotingType::Single; /// } /// }; template
struct TaggedScalarTraits { // Must provide: // // Function to write the value and tag as strings: // static void output(const T &Value, void *ctx, llvm::raw_ostream &ScalarOut, // llvm::raw_ostream &TagOut); // // Function to convert a string to a value. Returns the empty // StringRef on success or an error string if string is malformed: // static StringRef input(StringRef Scalar, StringRef Tag, void *ctxt, T // &Value); // // Function to determine if the value should be quoted. // static QuotingType mustQuote(const T &Value, StringRef Scalar); }; /// This class should be specialized by any type that needs to be converted /// to/from a YAML sequence. For example: /// /// template<> /// struct SequenceTraits
{ /// static size_t size(IO &io, MyContainer &seq) { /// return seq.size(); /// } /// static MyType& element(IO &, MyContainer &seq, size_t index) { /// if ( index >= seq.size() ) /// seq.resize(index+1); /// return seq[index]; /// } /// }; template
struct SequenceTraits { // Must provide: // static size_t size(IO &io, T &seq); // static T::value_type& element(IO &io, T &seq, size_t index); // // The following is option and will cause generated YAML to use // a flow sequence (e.g. [a,b,c]). // static const bool flow = true; }; /// This class should be specialized by any type for which vectors of that /// type need to be converted to/from a YAML sequence. template
struct SequenceElementTraits { // Must provide: // static const bool flow; }; /// This class should be specialized by any type that needs to be converted /// to/from a list of YAML documents. template
struct DocumentListTraits { // Must provide: // static size_t size(IO &io, T &seq); // static T::value_type& element(IO &io, T &seq, size_t index); }; /// This class should be specialized by any type that needs to be converted /// to/from a YAML mapping in the case where the names of the keys are not known /// in advance, e.g. a string map. template
struct CustomMappingTraits { // static void inputOne(IO &io, StringRef key, T &elem); // static void output(IO &io, T &elem); }; /// This class should be specialized by any type that can be represented as /// a scalar, map, or sequence, decided dynamically. For example: /// /// typedef std::unique_ptr
MyPoly; /// /// template<> /// struct PolymorphicTraits
{ /// static NodeKind getKind(const MyPoly &poly) { /// return poly->getKind(); /// } /// static MyScalar& getAsScalar(MyPoly &poly) { /// if (!poly || !isa
(poly)) /// poly.reset(new MyScalar()); /// return *cast
(poly.get()); /// } /// // ... /// }; template
struct PolymorphicTraits { // Must provide: // static NodeKind getKind(const T &poly); // static scalar_type &getAsScalar(T &poly); // static map_type &getAsMap(T &poly); // static sequence_type &getAsSequence(T &poly); }; // Only used for better diagnostics of missing traits template
struct MissingTrait; // Test if ScalarEnumerationTraits
is defined on type T. template
struct has_ScalarEnumerationTraits { using Signature_enumeration = void (*)(class IO&, T&); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // Test if ScalarBitSetTraits
is defined on type T. template
struct has_ScalarBitSetTraits { using Signature_bitset = void (*)(class IO&, T&); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // Test if ScalarTraits
is defined on type T. template
struct has_ScalarTraits { using Signature_input = StringRef (*)(StringRef, void*, T&); using Signature_output = void (*)(const T&, void*, raw_ostream&); using Signature_mustQuote = QuotingType (*)(StringRef); template
static char test(SameType
*, SameType
*, SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr, nullptr, nullptr)) == 1); }; // Test if BlockScalarTraits
is defined on type T. template
struct has_BlockScalarTraits { using Signature_input = StringRef (*)(StringRef, void *, T &); using Signature_output = void (*)(const T &, void *, raw_ostream &); template
static char test(SameType
*, SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr, nullptr)) == 1); }; // Test if TaggedScalarTraits
is defined on type T. template
struct has_TaggedScalarTraits { using Signature_input = StringRef (*)(StringRef, StringRef, void *, T &); using Signature_output = void (*)(const T &, void *, raw_ostream &, raw_ostream &); using Signature_mustQuote = QuotingType (*)(const T &, StringRef); template
static char test(SameType
*, SameType
*, SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr, nullptr, nullptr)) == 1); }; // Test if MappingContextTraits
is defined on type T. template
struct has_MappingTraits { using Signature_mapping = void (*)(class IO &, T &, Context &); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // Test if MappingTraits
is defined on type T. template
struct has_MappingTraits
{ using Signature_mapping = void (*)(class IO &, T &); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // Test if MappingContextTraits
::validate() is defined on type T. template
struct has_MappingValidateTraits { using Signature_validate = StringRef (*)(class IO &, T &, Context &); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // Test if MappingTraits
::validate() is defined on type T. template
struct has_MappingValidateTraits
{ using Signature_validate = StringRef (*)(class IO &, T &); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // Test if SequenceTraits
is defined on type T. template
struct has_SequenceMethodTraits { using Signature_size = size_t (*)(class IO&, T&); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // Test if CustomMappingTraits
is defined on type T. template
struct has_CustomMappingTraits { using Signature_input = void (*)(IO &io, StringRef key, T &v); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; // has_FlowTraits
will cause an error with some compilers because // it subclasses int. Using this wrapper only instantiates the // real has_FlowTraits only if the template type is a class. template
::value> class has_FlowTraits { public: static const bool value = false; }; // Some older gcc compilers don't support straight forward tests // for members, so test for ambiguity cause by the base and derived // classes both defining the member. template
struct has_FlowTraits
{ struct Fallback { bool flow; }; struct Derived : T, Fallback { }; template
static char (&f(SameType
*))[1]; template
static char (&f(...))[2]; static bool const value = sizeof(f
(nullptr)) == 2; }; // Test if SequenceTraits
is defined on type T template
struct has_SequenceTraits : public std::integral_constant
::value > { }; // Test if DocumentListTraits
is defined on type T template
struct has_DocumentListTraits { using Signature_size = size_t (*)(class IO &, T &); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr))==1); }; template
struct has_PolymorphicTraits { using Signature_getKind = NodeKind (*)(const T &); template
static char test(SameType
*); template
static double test(...); static bool const value = (sizeof(test
>(nullptr)) == 1); }; inline bool isNumeric(StringRef S) { const static auto skipDigits = [](StringRef Input) { return Input.drop_front( std::min(Input.find_first_not_of("0123456789"), Input.size())); }; // Make S.front() and S.drop_front().front() (if S.front() is [+-]) calls // safe. if (S.empty() || S.equals("+") || S.equals("-")) return false; if (S.equals(".nan") || S.equals(".NaN") || S.equals(".NAN")) return true; // Infinity and decimal numbers can be prefixed with sign. StringRef Tail = (S.front() == '-' || S.front() == '+') ? S.drop_front() : S; // Check for infinity first, because checking for hex and oct numbers is more // expensive. if (Tail.equals(".inf") || Tail.equals(".Inf") || Tail.equals(".INF")) return true; // Section 10.3.2 Tag Resolution // YAML 1.2 Specification prohibits Base 8 and Base 16 numbers prefixed with // [-+], so S should be used instead of Tail. if (S.startswith("0o")) return S.size() > 2 && S.drop_front(2).find_first_not_of("01234567") == StringRef::npos; if (S.startswith("0x")) return S.size() > 2 && S.drop_front(2).find_first_not_of( "0123456789abcdefABCDEF") == StringRef::npos; // Parse float: [-+]? (\. [0-9]+ | [0-9]+ (\. [0-9]* )?) ([eE] [-+]? [0-9]+)? S = Tail; // Handle cases when the number starts with '.' and hence needs at least one // digit after dot (as opposed by number which has digits before the dot), but // doesn't have one. if (S.startswith(".") && (S.equals(".") || (S.size() > 1 && std::strchr("0123456789", S[1]) == nullptr))) return false; if (S.startswith("E") || S.startswith("e")) return false; enum ParseState { Default, FoundDot, FoundExponent, }; ParseState State = Default; S = skipDigits(S); // Accept decimal integer. if (S.empty()) return true; if (S.front() == '.') { State = FoundDot; S = S.drop_front(); } else if (S.front() == 'e' || S.front() == 'E') { State = FoundExponent; S = S.drop_front(); } else { return false; } if (State == FoundDot) { S = skipDigits(S); if (S.empty()) return true; if (S.front() == 'e' || S.front() == 'E') { State = FoundExponent; S = S.drop_front(); } else { return false; } } assert(State == FoundExponent && "Should have found exponent at this point."); if (S.empty()) return false; if (S.front() == '+' || S.front() == '-') { S = S.drop_front(); if (S.empty()) return false; } return skipDigits(S).empty(); } inline bool isNull(StringRef S) { return S.equals("null") || S.equals("Null") || S.equals("NULL") || S.equals("~"); } inline bool isBool(StringRef S) { return S.equals("true") || S.equals("True") || S.equals("TRUE") || S.equals("false") || S.equals("False") || S.equals("FALSE"); } // 5.1. Character Set // The allowed character range explicitly excludes the C0 control block #x0-#x1F // (except for TAB #x9, LF #xA, and CR #xD which are allowed), DEL #x7F, the C1 // control block #x80-#x9F (except for NEL #x85 which is allowed), the surrogate // block #xD800-#xDFFF, #xFFFE, and #xFFFF. inline QuotingType needsQuotes(StringRef S) { if (S.empty()) return QuotingType::Single; if (isspace(S.front()) || isspace(S.back())) return QuotingType::Single; if (isNull(S)) return QuotingType::Single; if (isBool(S)) return QuotingType::Single; if (isNumeric(S)) return QuotingType::Single; // 7.3.3 Plain Style // Plain scalars must not begin with most indicators, as this would cause // ambiguity with other YAML constructs. static constexpr char Indicators[] = R"(-?:\,[]{}#&*!|>'"%@`)"; if (S.find_first_of(Indicators) == 0) return QuotingType::Single; QuotingType MaxQuotingNeeded = QuotingType::None; for (unsigned char C : S) { // Alphanum is safe. if (isAlnum(C)) continue; switch (C) { // Safe scalar characters. case '_': case '-': case '^': case '.': case ',': case ' ': // TAB (0x9) is allowed in unquoted strings. case 0x9: continue; // LF(0xA) and CR(0xD) may delimit values and so require at least single // quotes. case 0xA: case 0xD: MaxQuotingNeeded = QuotingType::Single; continue; // DEL (0x7F) are excluded from the allowed character range. case 0x7F: return QuotingType::Double; // Forward slash is allowed to be unquoted, but we quote it anyway. We have // many tests that use FileCheck against YAML output, and this output often // contains paths. If we quote backslashes but not forward slashes then // paths will come out either quoted or unquoted depending on which platform // the test is run on, making FileCheck comparisons difficult. case '/': default: { // C0 control block (0x0 - 0x1F) is excluded from the allowed character // range. if (C <= 0x1F) return QuotingType::Double; // Always double quote UTF-8. if ((C & 0x80) != 0) return QuotingType::Double; // The character is not safe, at least simple quoting needed. MaxQuotingNeeded = QuotingType::Single; } } } return MaxQuotingNeeded; } template
struct missingTraits : public std::integral_constant
::value && !has_ScalarBitSetTraits
::value && !has_ScalarTraits
::value && !has_BlockScalarTraits
::value && !has_TaggedScalarTraits
::value && !has_MappingTraits
::value && !has_SequenceTraits
::value && !has_CustomMappingTraits
::value && !has_DocumentListTraits
::value && !has_PolymorphicTraits
::value> {}; template
struct validatedMappingTraits : public std::integral_constant< bool, has_MappingTraits
::value && has_MappingValidateTraits
::value> {}; template
struct unvalidatedMappingTraits : public std::integral_constant< bool, has_MappingTraits
::value && !has_MappingValidateTraits
::value> {}; // Base class for Input and Output. class IO { public: IO(void *Ctxt = nullptr); virtual ~IO(); virtual bool outputting() = 0; virtual unsigned beginSequence() = 0; virtual bool preflightElement(unsigned, void *&) = 0; virtual void postflightElement(void*) = 0; virtual void endSequence() = 0; virtual bool canElideEmptySequence() = 0; virtual unsigned beginFlowSequence() = 0; virtual bool preflightFlowElement(unsigned, void *&) = 0; virtual void postflightFlowElement(void*) = 0; virtual void endFlowSequence() = 0; virtual bool mapTag(StringRef Tag, bool Default=false) = 0; virtual void beginMapping() = 0; virtual void endMapping() = 0; virtual bool preflightKey(const char*, bool, bool, bool &, void *&) = 0; virtual void postflightKey(void*) = 0; virtual std::vector
keys() = 0; virtual void beginFlowMapping() = 0; virtual void endFlowMapping() = 0; virtual void beginEnumScalar() = 0; virtual bool matchEnumScalar(const char*, bool) = 0; virtual bool matchEnumFallback() = 0; virtual void endEnumScalar() = 0; virtual bool beginBitSetScalar(bool &) = 0; virtual bool bitSetMatch(const char*, bool) = 0; virtual void endBitSetScalar() = 0; virtual void scalarString(StringRef &, QuotingType) = 0; virtual void blockScalarString(StringRef &) = 0; virtual void scalarTag(std::string &) = 0; virtual NodeKind getNodeKind() = 0; virtual void setError(const Twine &) = 0; template
void enumCase(T &Val, const char* Str, const T ConstVal) { if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) { Val = ConstVal; } } // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF template
void enumCase(T &Val, const char* Str, const uint32_t ConstVal) { if ( matchEnumScalar(Str, outputting() && Val == static_cast
(ConstVal)) ) { Val = ConstVal; } } template
void enumFallback(T &Val) { if (matchEnumFallback()) { EmptyContext Context; // FIXME: Force integral conversion to allow strong typedefs to convert. FBT Res = static_cast
(Val); yamlize(*this, Res, true, Context); Val = static_cast
(static_cast
(Res)); } } template
void bitSetCase(T &Val, const char* Str, const T ConstVal) { if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) { Val = static_cast
(Val | ConstVal); } } // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF template
void bitSetCase(T &Val, const char* Str, const uint32_t ConstVal) { if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) { Val = static_cast
(Val | ConstVal); } } template
void maskedBitSetCase(T &Val, const char *Str, T ConstVal, T Mask) { if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal)) Val = Val | ConstVal; } template
void maskedBitSetCase(T &Val, const char *Str, uint32_t ConstVal, uint32_t Mask) { if (bitSetMatch(Str, outputting() && (Val & Mask) == ConstVal)) Val = Val | ConstVal; } void *getContext(); void setContext(void *); template
void mapRequired(const char *Key, T &Val) { EmptyContext Ctx; this->processKey(Key, Val, true, Ctx); } template
void mapRequired(const char *Key, T &Val, Context &Ctx) { this->processKey(Key, Val, true, Ctx); } template
void mapOptional(const char *Key, T &Val) { EmptyContext Ctx; mapOptionalWithContext(Key, Val, Ctx); } template
void mapOptional(const char *Key, T &Val, const T &Default) { EmptyContext Ctx; mapOptionalWithContext(Key, Val, Default, Ctx); } template
typename std::enable_if
::value, void>::type mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) { // omit key/value instead of outputting empty sequence if (this->canElideEmptySequence() && !(Val.begin() != Val.end())) return; this->processKey(Key, Val, false, Ctx); } template
void mapOptionalWithContext(const char *Key, Optional
&Val, Context &Ctx) { this->processKeyWithDefault(Key, Val, Optional
(), /*Required=*/false, Ctx); } template
typename std::enable_if::value, void>::type mapOptionalWithContext(const char *Key, T &Val, Context &Ctx) { this->processKey(Key, Val, false, Ctx); } template
void mapOptionalWithContext(const char *Key, T &Val, const T &Default, Context &Ctx) { this->processKeyWithDefault(Key, Val, Default, false, Ctx); } private: template
void processKeyWithDefault(const char *Key, Optional
&Val, const Optional
&DefaultValue, bool Required, Context &Ctx) { assert(DefaultValue.hasValue() == false && "Optional
shouldn't have a value!"); void *SaveInfo; bool UseDefault = true; const bool sameAsDefault = outputting() && !Val.hasValue(); if (!outputting() && !Val.hasValue()) Val = T(); if (Val.hasValue() && this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo)) { yamlize(*this, Val.getValue(), Required, Ctx); this->postflightKey(SaveInfo); } else { if (UseDefault) Val = DefaultValue; } } template
void processKeyWithDefault(const char *Key, T &Val, const T &DefaultValue, bool Required, Context &Ctx) { void *SaveInfo; bool UseDefault; const bool sameAsDefault = outputting() && Val == DefaultValue; if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault, SaveInfo) ) { yamlize(*this, Val, Required, Ctx); this->postflightKey(SaveInfo); } else { if ( UseDefault ) Val = DefaultValue; } } template
void processKey(const char *Key, T &Val, bool Required, Context &Ctx) { void *SaveInfo; bool UseDefault; if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) { yamlize(*this, Val, Required, Ctx); this->postflightKey(SaveInfo); } } private: void *Ctxt; }; namespace detail { template
void doMapping(IO &io, T &Val, Context &Ctx) { MappingContextTraits
::mapping(io, Val, Ctx); } template
void doMapping(IO &io, T &Val, EmptyContext &Ctx) { MappingTraits
::mapping(io, Val); } } // end namespace detail template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { io.beginEnumScalar(); ScalarEnumerationTraits
::enumeration(io, Val); io.endEnumScalar(); } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { bool DoClear; if ( io.beginBitSetScalar(DoClear) ) { if ( DoClear ) Val = static_cast
(0); ScalarBitSetTraits
::bitset(io, Val); io.endBitSetScalar(); } } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { if ( io.outputting() ) { std::string Storage; raw_string_ostream Buffer(Storage); ScalarTraits
::output(Val, io.getContext(), Buffer); StringRef Str = Buffer.str(); io.scalarString(Str, ScalarTraits
::mustQuote(Str)); } else { StringRef Str; io.scalarString(Str, ScalarTraits
::mustQuote(Str)); StringRef Result = ScalarTraits
::input(Str, io.getContext(), Val); if ( !Result.empty() ) { io.setError(Twine(Result)); } } } template
typename std::enable_if
::value, void>::type yamlize(IO &YamlIO, T &Val, bool, EmptyContext &Ctx) { if (YamlIO.outputting()) { std::string Storage; raw_string_ostream Buffer(Storage); BlockScalarTraits
::output(Val, YamlIO.getContext(), Buffer); StringRef Str = Buffer.str(); YamlIO.blockScalarString(Str); } else { StringRef Str; YamlIO.blockScalarString(Str); StringRef Result = BlockScalarTraits
::input(Str, YamlIO.getContext(), Val); if (!Result.empty()) YamlIO.setError(Twine(Result)); } } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { if (io.outputting()) { std::string ScalarStorage, TagStorage; raw_string_ostream ScalarBuffer(ScalarStorage), TagBuffer(TagStorage); TaggedScalarTraits
::output(Val, io.getContext(), ScalarBuffer, TagBuffer); io.scalarTag(TagBuffer.str()); StringRef ScalarStr = ScalarBuffer.str(); io.scalarString(ScalarStr, TaggedScalarTraits
::mustQuote(Val, ScalarStr)); } else { std::string Tag; io.scalarTag(Tag); StringRef Str; io.scalarString(Str, QuotingType::None); StringRef Result = TaggedScalarTraits
::input(Str, Tag, io.getContext(), Val); if (!Result.empty()) { io.setError(Twine(Result)); } } } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, Context &Ctx) { if (has_FlowTraits
>::value) io.beginFlowMapping(); else io.beginMapping(); if (io.outputting()) { StringRef Err = MappingTraits
::validate(io, Val); if (!Err.empty()) { errs() << Err << "\n"; assert(Err.empty() && "invalid struct trying to be written as yaml"); } } detail::doMapping(io, Val, Ctx); if (!io.outputting()) { StringRef Err = MappingTraits
::validate(io, Val); if (!Err.empty()) io.setError(Err); } if (has_FlowTraits
>::value) io.endFlowMapping(); else io.endMapping(); } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, Context &Ctx) { if (has_FlowTraits
>::value) { io.beginFlowMapping(); detail::doMapping(io, Val, Ctx); io.endFlowMapping(); } else { io.beginMapping(); detail::doMapping(io, Val, Ctx); io.endMapping(); } } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { if ( io.outputting() ) { io.beginMapping(); CustomMappingTraits
::output(io, Val); io.endMapping(); } else { io.beginMapping(); for (StringRef key : io.keys()) CustomMappingTraits
::inputOne(io, key, Val); io.endMapping(); } } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { switch (io.outputting() ? PolymorphicTraits
::getKind(Val) : io.getNodeKind()) { case NodeKind::Scalar: return yamlize(io, PolymorphicTraits
::getAsScalar(Val), true, Ctx); case NodeKind::Map: return yamlize(io, PolymorphicTraits
::getAsMap(Val), true, Ctx); case NodeKind::Sequence: return yamlize(io, PolymorphicTraits
::getAsSequence(Val), true, Ctx); } } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { char missing_yaml_trait_for_type[sizeof(MissingTrait
)]; } template
typename std::enable_if
::value, void>::type yamlize(IO &io, T &Seq, bool, Context &Ctx) { if ( has_FlowTraits< SequenceTraits
>::value ) { unsigned incnt = io.beginFlowSequence(); unsigned count = io.outputting() ? SequenceTraits
::size(io, Seq) : incnt; for(unsigned i=0; i < count; ++i) { void *SaveInfo; if ( io.preflightFlowElement(i, SaveInfo) ) { yamlize(io, SequenceTraits
::element(io, Seq, i), true, Ctx); io.postflightFlowElement(SaveInfo); } } io.endFlowSequence(); } else { unsigned incnt = io.beginSequence(); unsigned count = io.outputting() ? SequenceTraits
::size(io, Seq) : incnt; for(unsigned i=0; i < count; ++i) { void *SaveInfo; if ( io.preflightElement(i, SaveInfo) ) { yamlize(io, SequenceTraits
::element(io, Seq, i), true, Ctx); io.postflightElement(SaveInfo); } } io.endSequence(); } } template<> struct ScalarTraits
{ static void output(const bool &, void* , raw_ostream &); static StringRef input(StringRef, void *, bool &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const StringRef &, void *, raw_ostream &); static StringRef input(StringRef, void *, StringRef &); static QuotingType mustQuote(StringRef S) { return needsQuotes(S); } }; template<> struct ScalarTraits
{ static void output(const std::string &, void *, raw_ostream &); static StringRef input(StringRef, void *, std::string &); static QuotingType mustQuote(StringRef S) { return needsQuotes(S); } }; template<> struct ScalarTraits
{ static void output(const uint8_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, uint8_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const uint16_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, uint16_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const uint32_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, uint32_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const uint64_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, uint64_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const int8_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, int8_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const int16_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, int16_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const int32_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, int32_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const int64_t &, void *, raw_ostream &); static StringRef input(StringRef, void *, int64_t &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const float &, void *, raw_ostream &); static StringRef input(StringRef, void *, float &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; template<> struct ScalarTraits
{ static void output(const double &, void *, raw_ostream &); static StringRef input(StringRef, void *, double &); static QuotingType mustQuote(StringRef) { return QuotingType::None; } }; // For endian types, we just use the existing ScalarTraits for the underlying // type. This way endian aware types are supported whenever a ScalarTraits // is defined for the underlying type. template
struct ScalarTraits
> { using endian_type = support::detail::packed_endian_specific_integral
; static void output(const endian_type &E, void *Ctx, raw_ostream &Stream) { ScalarTraits
::output(static_cast