10 #ifndef LLVM_SUPPORT_YAMLTRAITS_H
11 #define LLVM_SUPPORT_YAMLTRAITS_H
152 template <
typename T, T>
156 template <
typename T>
167 template <
typename U>
170 template <
typename U>
171 static double test(...);
174 static bool const value = (
sizeof(test<ScalarEnumerationTraits<T> >(0)) == 1);
184 template <
typename U>
187 template <
typename U>
188 static double test(...);
191 static bool const value = (
sizeof(test<ScalarBitSetTraits<T> >(0)) == 1);
202 template <
typename U>
206 template <
typename U>
207 static double test(...);
210 static bool const value = (
sizeof(test<ScalarTraits<T> >(0,0)) == 1);
220 template <
typename U>
223 template <
typename U>
224 static double test(...);
227 static bool const value = (
sizeof(test<MappingTraits<T> >(0)) == 1);
237 template <
typename U>
240 template <
typename U>
241 static double test(...);
244 static bool const value = (
sizeof(test<SequenceTraits<T> >(0)) == 1);
251 template <typename T, bool Enabled = llvm::is_class<T>::value>
264 struct Fallback {
bool flow; };
265 struct Derived :
T, Fallback { };
271 static char (&f(...))[2];
274 static bool const value =
sizeof(f<Derived>(0)) == 2;
282 has_SequenceMethodTraits<T>::value > { };
291 template <
typename U>
294 template <
typename U>
295 static double test(...);
298 static bool const value = (
sizeof(test<DocumentListTraits<T> >(0)) == 1);
306 !has_ScalarEnumerationTraits<T>::value
307 && !has_ScalarBitSetTraits<T>::value
308 && !has_ScalarTraits<T>::value
309 && !has_MappingTraits<T>::value
310 && !has_SequenceTraits<T>::value
311 && !has_DocumentListTraits<T>::value > {};
337 virtual bool preflightKey(
const char*,
bool,
bool,
bool &,
void *&) = 0;
352 template <
typename T>
360 template <
typename T>
361 void enumCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
367 template <
typename T>
370 Val = Val | ConstVal;
375 template <
typename T>
376 void bitSetCase(
T &Val,
const char* Str,
const uint32_t ConstVal) {
378 Val = Val | ConstVal;
385 template <
typename T>
387 this->processKey(Key, Val,
true);
390 template <
typename T>
396 this->processKey(Key, Val,
false);
399 template <
typename T>
402 this->processKey(Key, Val,
false);
405 template <
typename T>
407 this->processKeyWithDefault(Key, Val, Default,
false);
411 template <
typename T>
412 void processKeyWithDefault(
const char *Key,
T &Val,
const T& DefaultValue,
416 const bool sameAsDefault =
outputting() && Val == DefaultValue;
417 if ( this->
preflightKey(Key, Required, sameAsDefault, UseDefault,
428 template <
typename T>
429 void processKey(
const char *Key,
T &Val,
bool Required) {
432 if ( this->
preflightKey(Key, Required,
false, UseDefault, SaveInfo) ) {
458 Val =
static_cast<T>(0);
479 if ( !Result.
empty() ) {
506 for(
unsigned i=0; i < count; ++i) {
518 for(
unsigned i=0; i < count; ++i) {
606 template <
typename TNorm,
typename TFinal>
609 : io(i_o), BufPtr(NULL), Result(Obj) {
611 BufPtr =
new (&Buffer) TNorm(io, Obj);
614 BufPtr =
new (&Buffer) TNorm(io);
620 Result = BufPtr->denormalize(io);
640 template <
typename TNorm,
typename TFinal>
643 : io(i_o), BufPtr(NULL), Result(Obj) {
645 BufPtr =
new (&Buffer) TNorm(io, Obj);
648 BufPtr =
new TNorm(io);
657 Result = BufPtr->denormalize(io);
694 void *DiagHandlerCtxt = NULL);
703 virtual bool outputting()
const;
705 virtual void beginMapping();
706 virtual void endMapping();
707 virtual bool preflightKey(
const char *,
bool,
bool,
bool &,
void *&);
708 virtual void postflightKey(
void *);
709 virtual unsigned beginSequence();
710 virtual void endSequence();
711 virtual bool preflightElement(
unsigned index,
void *&);
712 virtual void postflightElement(
void *);
713 virtual unsigned beginFlowSequence();
714 virtual bool preflightFlowElement(
unsigned ,
void *&);
715 virtual void postflightFlowElement(
void *);
716 virtual void endFlowSequence();
717 virtual void beginEnumScalar();
718 virtual bool matchEnumScalar(
const char*,
bool);
719 virtual void endEnumScalar();
720 virtual bool beginBitSetScalar(
bool &);
721 virtual bool bitSetMatch(
const char *,
bool );
722 virtual void endBitSetScalar();
724 virtual void setError(
const Twine &message);
725 virtual bool canElideEmptySequence();
728 virtual void anchor();
730 HNode(
Node *n) : _node(n) { }
732 static inline bool classof(
const HNode *) {
return true; }
737 class EmptyHNode :
public HNode {
738 virtual void anchor();
740 EmptyHNode(Node *n) : HNode(n) { }
741 static inline bool classof(
const HNode *n) {
744 static inline bool classof(
const EmptyHNode *) {
return true; }
747 class ScalarHNode :
public HNode {
748 virtual void anchor();
750 ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
752 StringRef value()
const {
return _value; }
754 static inline bool classof(
const HNode *n) {
757 static inline bool classof(
const ScalarHNode *) {
return true; }
762 class MapHNode :
public HNode {
764 MapHNode(Node *n) : HNode(n) { }
767 static inline bool classof(
const HNode *n) {
770 static inline bool classof(
const MapHNode *) {
return true; }
774 bool isValidKey(StringRef key);
780 class SequenceHNode :
public HNode {
782 SequenceHNode(Node *n) : HNode(n) { }
783 virtual ~SequenceHNode();
785 static inline bool classof(
const HNode *n) {
788 static inline bool classof(
const SequenceHNode *) {
return true; }
790 std::vector<HNode*> Entries;
793 Input::HNode *createHNodes(Node *node);
794 void setError(HNode *hnode,
const Twine &message);
795 void setError(Node *node,
const Twine &message);
806 OwningPtr<llvm::yaml::Stream> Strm;
807 OwningPtr<HNode> TopNode;
811 std::vector<bool> BitValuesUsed;
813 bool ScalarMatchFound;
834 virtual bool preflightKey(
const char *key,
bool,
bool,
bool &,
void *&);
865 void outputNewLine();
868 enum InState { inSeq, inFlowSeq, inMapFirstKey, inMapOtherKey };
873 int ColumnAtFlowStart;
874 bool NeedBitValueComma;
875 bool NeedFlowSequenceComma;
876 bool EnumerationMatchFound;
891 #define LLVM_YAML_STRONG_TYPEDEF(_base, _type) \
894 _type(const _base v) : value(v) { } \
895 _type(const _type &v) : value(v.value) {} \
896 _type &operator=(const _type &rhs) { value = rhs.value; return *this; }\
897 _type &operator=(const _base &rhs) { value = rhs; return *this; } \
898 operator const _base & () const { return value; } \
899 bool operator==(const _type &rhs) const { return value == rhs.value; } \
900 bool operator==(const _base &rhs) const { return value == rhs; } \
901 bool operator<(const _type &rhs) const { return value < rhs.value; } \
943 template <
typename T>
959 template <
typename T>
970 template <
typename T>
980 template <
typename T>
990 template <
typename T>
996 for(
size_t i=0; i < count; ++i) {
1007 template <
typename T>
1021 template <
typename T>
1035 template <
typename T>
1050 #define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \
1054 struct SequenceTraits< std::vector<_type> > { \
1055 static size_t size(IO &io, std::vector<_type> &seq) { \
1056 return seq.size(); \
1058 static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\
1059 if ( index >= seq.size() ) \
1060 seq.resize(index+1); \
1061 return seq[index]; \
1069 #define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \
1073 struct SequenceTraits< std::vector<_type> > { \
1074 static size_t size(IO &io, std::vector<_type> &seq) { \
1075 return seq.size(); \
1077 static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\
1078 if ( index >= seq.size() ) \
1079 seq.resize(index+1); \
1080 return seq[index]; \
1082 static const bool flow = true; \
1089 #define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \
1093 struct DocumentListTraits< std::vector<_type> > { \
1094 static size_t size(IO &io, std::vector<_type> &seq) { \
1095 return seq.size(); \
1097 static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\
1098 if ( index >= seq.size() ) \
1099 seq.resize(index+1); \
1100 return seq[index]; \
1108 #endif // LLVM_SUPPORT_YAMLTRAITS_H
static bool classof(const Node *N)
virtual unsigned beginSequence()
static char test(SameType< Signature_enumeration,&U::enumeration > *)
void bitSetCase(T &Val, const char *Str, const T ConstVal)
bool preflightDocument(unsigned)
virtual bool beginBitSetScalar(bool &)=0
virtual bool preflightFlowElement(unsigned, void *&)=0
void(* Signature_enumeration)(class IO &, T &)
llvm::enable_if_c< has_ScalarEnumerationTraits< T >::value, void >::type yamlize(IO &io, T &Val, bool)
static bool classof(const IO *io)
Output(llvm::raw_ostream &, void *Ctxt=NULL)
void enumCase(T &Val, const char *Str, const uint32_t ConstVal)
virtual void endEnumScalar()=0
static char test(SameType< Signature_size,&U::size > *)
virtual void endFlowSequence()
MappingNormalizationHeap(IO &i_o, TFinal &Obj)
static bool classof(const Node *N)
virtual void setError(const Twine &)=0
virtual void postflightElement(void *)=0
virtual unsigned beginSequence()=0
virtual void scalarString(StringRef &)=0
virtual bool mapTag(StringRef, bool)
virtual bool matchEnumScalar(const char *, bool)
virtual bool outputting() const
virtual bool preflightElement(unsigned, void *&)=0
virtual bool preflightFlowElement(unsigned, void *&)
StringRef(* Signature_input)(StringRef, void *, T &)
virtual bool canElideEmptySequence()
llvm::enable_if_c< has_SequenceTraits< T >::value, void >::type mapOptional(const char *Key, T &Val)
llvm::enable_if_c<!has_SequenceTraits< T >::value, void >::type mapOptional(const char *Key, T &Val)
void bitSetCase(T &Val, const char *Str, const uint32_t ConstVal)
virtual void beginEnumScalar()
virtual bool mapTag(StringRef Tag, bool Default=false)=0
static bool classof(const Node *N)
void enumCase(T &Val, const char *Str, const T ConstVal)
virtual void endMapping()
virtual void endFlowSequence()=0
void postflightDocument()
void(* Signature_mapping)(class IO &, T &)
llvm::enable_if_c< has_DocumentListTraits< T >::value, Output & >::type operator<<(Output &yout, T &docList)
size_t(* Signature_size)(class IO &, T &)
virtual bool beginBitSetScalar(bool &)
virtual void beginEnumScalar()=0
virtual void endBitSetScalar()
void(* DiagHandlerTy)(const SMDiagnostic &, void *Context)
virtual void postflightFlowElement(void *)
virtual bool preflightKey(const char *, bool, bool, bool &, void *&)=0
virtual bool canElideEmptySequence()=0
llvm::enable_if_c< has_DocumentListTraits< T >::value, Input & >::type operator>>(Input &yin, T &docList)
virtual void beginMapping()
virtual void endBitSetScalar()=0
virtual void endSequence()
virtual void scalarString(StringRef &)
virtual void beginMapping()=0
MappingNormalization(IO &i_o, TFinal &Obj)
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
static char test(SameType< Signature_input,&U::input > *, SameType< Signature_output,&U::output > *)
virtual bool bitSetMatch(const char *, bool)=0
virtual void postflightKey(void *)
virtual void postflightKey(void *)=0
static char test(SameType< Signature_mapping,&U::mapping > *)
virtual unsigned beginFlowSequence()
virtual unsigned beginFlowSequence()=0
virtual bool preflightElement(unsigned, void *&)
static char test(SameType< Signature_bitset,&U::bitset > *)
void(* Signature_bitset)(class IO &, T &)
static bool classof(const Node *N)
virtual void endEnumScalar()
virtual bool bitSetMatch(const char *, bool)
size_t(* Signature_size)(class IO &, T &)
virtual void endMapping()=0
virtual void postflightFlowElement(void *)=0
virtual bool matchEnumScalar(const char *, bool)=0
virtual bool outputting() const =0
virtual void postflightElement(void *)
~MappingNormalizationHeap()
virtual void setError(const Twine &message)
Iterator abstraction for Documents over a Stream.
void mapOptional(const char *Key, T &Val, const T &Default)
virtual void endSequence()=0
void mapRequired(const char *Key, T &Val)
virtual bool preflightKey(const char *key, bool, bool, bool &, void *&)
void(* Signature_output)(const T &, void *, llvm::raw_ostream &)
static char test(SameType< Signature_size,&U::size > *)
bool empty() const
empty - Check if the string is empty.
Abstract base class for all Nodes.