From 61d5e2ad85c2d81a74bc2dc94d0a52e917eb5477 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 30 May 2015 15:47:22 -0600 Subject: [PATCH] Revert "Work around coverity crash" This reverts commit bb0d1005138e53cb2d414401f0338f22fbbc636b. Conflicts: include/chaiscript/dispatchkit/dispatchkit.hpp include/chaiscript/dispatchkit/type_info.hpp --- .../dispatchkit/type_conversions.hpp | 13 ++- include/chaiscript/dispatchkit/type_info.hpp | 81 +++++++++---------- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/include/chaiscript/dispatchkit/type_conversions.hpp b/include/chaiscript/dispatchkit/type_conversions.hpp index a08addd..a5abed4 100644 --- a/include/chaiscript/dispatchkit/type_conversions.hpp +++ b/include/chaiscript/dispatchkit/type_conversions.hpp @@ -300,6 +300,13 @@ namespace chaiscript class Type_Conversions { public: + struct Less_Than + { + bool operator()(const std::type_info *t_lhs, const std::type_info *t_rhs) const + { + return *t_lhs != *t_rhs && t_lhs->before(*t_rhs); + } + }; Type_Conversions() : m_mutex(), @@ -322,7 +329,7 @@ namespace chaiscript { } - const std::set &thread_cache() const + const std::set &thread_cache() const { auto &cache = *m_thread_cache; if (cache.size() != m_num_types) @@ -459,9 +466,9 @@ namespace chaiscript mutable chaiscript::detail::threading::shared_mutex m_mutex; std::set> m_conversions; - std::set m_convertableTypes; + std::set m_convertableTypes; std::atomic_size_t m_num_types; - mutable chaiscript::detail::threading::Thread_Storage> m_thread_cache; + mutable chaiscript::detail::threading::Thread_Storage> m_thread_cache; mutable chaiscript::detail::threading::Thread_Storage m_conversion_saves; }; diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index a15c245..de61ab6 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include namespace chaiscript @@ -29,12 +28,9 @@ namespace chaiscript /// \brief Compile time deduced information about a type class Type_Info { - private: - class Undef {}; - public: - Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, - bool t_is_arithmetic, const std::type_index &t_ti, const std::type_index &t_bare_ti) + CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, + bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti) : m_type_info(t_ti), m_bare_type_info(t_bare_ti), m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer), m_is_void(t_is_void), m_is_arithmetic(t_is_arithmetic), @@ -42,8 +38,8 @@ namespace chaiscript { } - Type_Info() - : m_type_info(typeid(Type_Info::Undef)), m_bare_type_info(typeid(Type_Info::Undef)), + CHAISCRIPT_CONSTEXPR Type_Info() + : m_type_info(nullptr), m_bare_type_info(nullptr), m_is_const(false), m_is_reference(false), m_is_pointer(false), m_is_void(false), m_is_arithmetic(false), m_is_undef(true) @@ -59,45 +55,46 @@ namespace chaiscript Type_Info& operator=(const Type_Info&) = default; - bool operator<(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool operator<(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { return m_type_info < ti.m_type_info; } - bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool operator==(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { - return ti.m_type_info == m_type_info; + return ti.m_type_info == m_type_info + || (ti.m_type_info && m_type_info && *ti.m_type_info == *m_type_info); } - bool operator==(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool operator==(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT { - return !m_is_undef - && m_type_info == ti; + return m_type_info != nullptr && (*m_type_info) == ti; } - bool bare_equal(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool bare_equal(const Type_Info &ti) const CHAISCRIPT_NOEXCEPT { - return ti.m_bare_type_info == m_bare_type_info; + return ti.m_bare_type_info == m_bare_type_info + || (ti.m_bare_type_info && m_bare_type_info && *ti.m_bare_type_info == *m_bare_type_info); } - bool bare_equal_type_info(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT + CHAISCRIPT_CONSTEXPR bool bare_equal_type_info(const std::type_info &ti) const CHAISCRIPT_NOEXCEPT { - return !m_is_undef - && m_bare_type_info == ti; + return m_bare_type_info != nullptr + && (*m_bare_type_info) == ti; } - bool is_const() const CHAISCRIPT_NOEXCEPT { return m_is_const; } - bool is_reference() const CHAISCRIPT_NOEXCEPT { return m_is_reference; } - bool is_void() const CHAISCRIPT_NOEXCEPT { return m_is_void; } - bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return m_is_arithmetic; } - bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef; } - bool is_pointer() const CHAISCRIPT_NOEXCEPT { return m_is_pointer; } + CHAISCRIPT_CONSTEXPR bool is_const() const CHAISCRIPT_NOEXCEPT { return m_is_const; } + CHAISCRIPT_CONSTEXPR bool is_reference() const CHAISCRIPT_NOEXCEPT { return m_is_reference; } + CHAISCRIPT_CONSTEXPR bool is_void() const CHAISCRIPT_NOEXCEPT { return m_is_void; } + CHAISCRIPT_CONSTEXPR bool is_arithmetic() const CHAISCRIPT_NOEXCEPT { return m_is_arithmetic; } + CHAISCRIPT_CONSTEXPR bool is_undef() const CHAISCRIPT_NOEXCEPT { return m_is_undef || m_bare_type_info == nullptr; } + CHAISCRIPT_CONSTEXPR bool is_pointer() const CHAISCRIPT_NOEXCEPT { return m_is_pointer; } std::string name() const { - if (!m_is_undef) + if (m_type_info) { - return m_type_info.name(); + return m_type_info->name(); } else { return ""; } @@ -105,22 +102,22 @@ namespace chaiscript std::string bare_name() const { - if (!m_is_undef) + if (m_bare_type_info) { - return m_bare_type_info.name(); + return m_bare_type_info->name(); } else { return ""; } } - const std::type_index &bare_type_info() const + CHAISCRIPT_CONSTEXPR const std::type_info *bare_type_info() const { return m_bare_type_info; } private: - std::type_index m_type_info; - std::type_index m_bare_type_info; + const std::type_info *m_type_info; + const std::type_info *m_bare_type_info; bool m_is_const; bool m_is_reference; bool m_is_pointer; @@ -142,8 +139,8 @@ namespace chaiscript return Type_Info(std::is_const::type>::type>::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, std::is_arithmetic::value && !std::is_same::type, bool>::value, - typeid(T), - typeid(typename Bare_Type::type)); + &typeid(T), + &typeid(typename Bare_Type::type)); } }; @@ -157,8 +154,8 @@ namespace chaiscript return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, std::is_arithmetic::value && !std::is_same::type, bool>::value, - typeid(std::shared_ptr ), - typeid(typename Bare_Type::type)); + &typeid(std::shared_ptr ), + &typeid(typename Bare_Type::type)); } }; @@ -172,8 +169,8 @@ namespace chaiscript return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, std::is_arithmetic::value && !std::is_same::type, bool>::value, - typeid(const std::shared_ptr &), - typeid(typename Bare_Type::type)); + &typeid(const std::shared_ptr &), + &typeid(typename Bare_Type::type)); } }; @@ -187,8 +184,8 @@ namespace chaiscript return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, std::is_arithmetic::value && !std::is_same::type, bool>::value, - typeid(std::reference_wrapper ), - typeid(typename Bare_Type::type)); + &typeid(std::reference_wrapper ), + &typeid(typename Bare_Type::type)); } }; @@ -202,8 +199,8 @@ namespace chaiscript return Type_Info(std::is_const::value, std::is_reference::value, std::is_pointer::value, std::is_void::value, std::is_arithmetic::value && !std::is_same::type, bool>::value, - typeid(const std::reference_wrapper &), - typeid(typename Bare_Type::type)); + &typeid(const std::reference_wrapper &), + &typeid(typename Bare_Type::type)); } };