[llvm] r277870 - Make YAML support SmallVector

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 15:41:22 PDT 2016


Zachary Turner via llvm-commits <llvm-commits at lists.llvm.org> writes:
> Author: zturner
> Date: Fri Aug  5 16:45:19 2016
> New Revision: 277870
>
> URL: http://llvm.org/viewvc/llvm-project?rev=277870&view=rev
> Log:
> Make YAML support SmallVector
>
> Currently YAML sequences require std::vectors. All of the methods that the
> YAML parser accesses though are present in SmallVector, so there's no
> reason we can't support SmallVector inherently. This patch does that.

I reverted this in r277881. It broke my local build and many bots,
because they started to fail to build dsymutil.

> Reviewed By: majnemer
> Differential Revision: https://reviews.llvm.org/D23213
>
> Modified:
>     llvm/trunk/include/llvm/Support/YAMLTraits.h
>
> Modified: llvm/trunk/include/llvm/Support/YAMLTraits.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=277870&r1=277869&r2=277870&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/YAMLTraits.h (original)
> +++ llvm/trunk/include/llvm/Support/YAMLTraits.h Fri Aug  5 16:45:19 2016
> @@ -1359,66 +1359,63 @@ operator<<(Output &yout, T &seq) {
>    return yout;
>  }
>  
> +template <typename T> 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<std::vector<_type>>                                    \
> +      : public SequenceTraitsImpl<std::vector<_type>> {};                      \
> +  template <unsigned N>                                                        \
> +  struct SequenceTraits<SmallVector<_type, N>>                                 \
> +      : public SequenceTraitsImpl<SmallVector<_type, N>> {};                   \
> +  }                                                                            \
>    }
>  
>  /// 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 <unsigned N>                                                        \
> +  struct SequenceTraits<SmallVector<_type, N>>                                 \
> +      : public SequenceTraitsImpl<SmallVector<_type, N>> {                     \
> +    static const bool flow = true;                                             \
> +  };                                                                           \
> +  template <>                                                                  \
> +  struct SequenceTraits<std::vector<_type>>                                    \
> +      : public SequenceTraitsImpl<std::vector<_type>> {                        \
> +    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 <unsigned N>                                                        \
> +  struct DocumentListTraits<SmallVector<_type, N>>                             \
> +      : public SequenceTraitsImpl<SmallVector<_type, N>> {};                   \
> +  template <>                                                                  \
> +  struct DocumentListTraits<std::vector<_type>>                                \
> +      : public SequenceTraitsImpl<std::vector<_type>> {};                      \
> +  }                                                                            \
>    }
>  
>  #endif // LLVM_SUPPORT_YAMLTRAITS_H
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list