From 9e91c28b7121f726b3ee62bd5d17abb9bfe6841a Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 5 Aug 2016 23:12:31 +0000 Subject: [PATCH] Resubmit "Make YAML support SmallVector" This resubmits a3770391c5fb64108d565e12f61dd77ce71b5b4f, which was reverted due to breakages on non-Windows machines. Due to differences in template instantiation rules on Microsoft and non-Microsoft platforms, a member access restriction was triggering on non-Microsoft compilers. Previously, a friend declaration for std::vector<> had been introduced into the DebugMap class to make the member access restriction pass, but the introduction of support for SmallVector<> meant that an additional friend declaration would need to be added. This didn't really make a lot of sense since the user of the macro is probably only using one type (SmallVector<>, vector<>, etc) and we could in theory add support for even more types to this macro in the future (e.g. std::deque), so rather than add another friend declaration, I just made the type being referenced a public nested typedef instead of a private nested typedef. llvm-svn: 277888 --- llvm/include/llvm/Support/YAMLTraits.h | 91 ++++++++++++++++------------------ llvm/tools/dsymutil/DebugMap.h | 3 +- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h index bc3fa8a..7389dc2 100644 --- a/llvm/include/llvm/Support/YAMLTraits.h +++ b/llvm/include/llvm/Support/YAMLTraits.h @@ -1359,66 +1359,63 @@ operator<<(Output &yout, T &seq) { return yout; } +template struct SequenceTraitsImpl { + typedef typename T::value_type _type; + static size_t size(IO &io, T &seq) { return seq.size(); } + static _type &element(IO &io, T &seq, size_t index) { + if (index >= seq.size()) + seq.resize(index + 1); + return seq[index]; + } +}; + } // namespace yaml } // namespace llvm /// Utility for declaring that a std::vector of a particular type /// should be considered a YAML sequence. -#define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \ - namespace llvm { \ - namespace yaml { \ - template<> \ - struct SequenceTraits< std::vector<_type> > { \ - static size_t size(IO &io, std::vector<_type> &seq) { \ - return seq.size(); \ - } \ - static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\ - if ( index >= seq.size() ) \ - seq.resize(index+1); \ - return seq[index]; \ - } \ - }; \ - } \ +#define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \ + namespace llvm { \ + namespace yaml { \ + template <> \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> {}; \ + template \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> {}; \ + } \ } /// Utility for declaring that a std::vector of a particular type /// should be considered a YAML flow sequence. -#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \ - namespace llvm { \ - namespace yaml { \ - template<> \ - struct SequenceTraits< std::vector<_type> > { \ - static size_t size(IO &io, std::vector<_type> &seq) { \ - return seq.size(); \ - } \ - static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\ - (void)flow; /* Remove this workaround after PR17897 is fixed */ \ - if ( index >= seq.size() ) \ - seq.resize(index+1); \ - return seq[index]; \ - } \ - static const bool flow = true; \ - }; \ - } \ +#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \ + namespace llvm { \ + namespace yaml { \ + template \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> { \ + static const bool flow = true; \ + }; \ + template <> \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> { \ + static const bool flow = true; \ + }; \ + } \ } /// Utility for declaring that a std::vector of a particular type /// should be considered a YAML document list. -#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \ - namespace llvm { \ - namespace yaml { \ - template<> \ - struct DocumentListTraits< std::vector<_type> > { \ - static size_t size(IO &io, std::vector<_type> &seq) { \ - return seq.size(); \ - } \ - static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\ - if ( index >= seq.size() ) \ - seq.resize(index+1); \ - return seq[index]; \ - } \ - }; \ - } \ +#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \ + namespace llvm { \ + namespace yaml { \ + template \ + struct DocumentListTraits> \ + : public SequenceTraitsImpl> {}; \ + template <> \ + struct DocumentListTraits> \ + : public SequenceTraitsImpl> {}; \ + } \ } #endif // LLVM_SUPPORT_YAMLTRAITS_H diff --git a/llvm/tools/dsymutil/DebugMap.h b/llvm/tools/dsymutil/DebugMap.h index 1a3d62b..639f503 100644 --- a/llvm/tools/dsymutil/DebugMap.h +++ b/llvm/tools/dsymutil/DebugMap.h @@ -130,6 +130,7 @@ public: SymbolMapping() = default; }; + typedef std::pair YAMLSymbolMapping; typedef StringMapEntry DebugMapEntry; /// \brief Adds a symbol mapping to this DebugMapObject. @@ -170,10 +171,8 @@ private: /// For YAMLIO support. ///@{ - typedef std::pair YAMLSymbolMapping; friend yaml::MappingTraits; friend yaml::SequenceTraits>>; - friend yaml::SequenceTraits>; DebugMapObject() = default; public: -- 2.7.4