decoder_detail: static_assert member function is from visitor class

Improves readability of compiler errors.
This commit is contained in:
MerryMage 2016-12-23 11:10:02 +00:00
parent c7e5216473
commit b1bad4b5cc
2 changed files with 4 additions and 1 deletions

View file

@ -26,7 +26,8 @@ namespace detail {
template<class MatcherT> template<class MatcherT>
struct detail { struct detail {
private: private:
using opcode_type = typename MatcherT::opcode_type; using opcode_type = typename MatcherT::opcode_type;
using visitor_type = typename MatcherT::visitor_type;
static constexpr size_t opcode_bitsize = Common::BitSize<opcode_type>(); static constexpr size_t opcode_bitsize = Common::BitSize<opcode_type>();
@ -113,6 +114,7 @@ private:
CallRetT (Visitor::* const fn)(Args...), CallRetT (Visitor::* const fn)(Args...),
const std::array<opcode_type, sizeof...(iota)> arg_masks, const std::array<opcode_type, sizeof...(iota)> arg_masks,
const std::array<size_t, sizeof...(iota)> arg_shifts) { const std::array<size_t, sizeof...(iota)> arg_shifts) {
static_assert(std::is_same<visitor_type, Visitor>::value, "Member function is not from Matcher's Visitor");
return [fn, arg_masks, arg_shifts](Visitor& v, opcode_type instruction) { return [fn, arg_masks, arg_shifts](Visitor& v, opcode_type instruction) {
(void)instruction; (void)instruction;
return (v.*fn)(static_cast<Args>((instruction & arg_masks[iota]) >> arg_shifts[iota])...); return (v.*fn)(static_cast<Args>((instruction & arg_masks[iota]) >> arg_shifts[iota])...);

View file

@ -27,6 +27,7 @@ template <typename Visitor, typename OpcodeType>
class Matcher { class Matcher {
public: public:
using opcode_type = OpcodeType; using opcode_type = OpcodeType;
using visitor_type = Visitor;
using handler_return_type = typename Visitor::instruction_return_type; using handler_return_type = typename Visitor::instruction_return_type;
using handler_function = std::function<handler_return_type(Visitor&, opcode_type)>; using handler_function = std::function<handler_return_type(Visitor&, opcode_type)>;