From a363ef5e0ebebcecb6ce05a049a694db94bd3d25 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Fri, 11 Mar 2016 14:45:40 -0700 Subject: [PATCH] C++11/14 updates --- .../chaiscript/dispatchkit/bad_boxed_cast.hpp | 2 +- include/chaiscript/dispatchkit/boxed_cast.hpp | 6 +-- .../chaiscript/dispatchkit/boxed_number.hpp | 2 +- .../chaiscript/dispatchkit/dispatchkit.hpp | 54 +++++++++---------- .../chaiscript/dispatchkit/dynamic_object.hpp | 2 +- .../dispatchkit/dynamic_object_detail.hpp | 25 ++++----- 6 files changed, 39 insertions(+), 52 deletions(-) diff --git a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp index 44cbf25..ee2be60 100644 --- a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp @@ -46,7 +46,7 @@ namespace chaiscript } bad_boxed_cast(const bad_boxed_cast &) = default; - virtual ~bad_boxed_cast() noexcept {} + virtual ~bad_boxed_cast() noexcept = default; /// \brief Description of what error occurred virtual const char * what() const noexcept override diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index 44450a0..5a11ee9 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -82,21 +82,19 @@ namespace chaiscript if (t_conversions && (*t_conversions)->convertable_type()) { try { - // std::cout << "trying an up conversion " << typeid(Type).name() << '\n'; // We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it // either way, we are not responsible if it doesn't work return detail::Cast_Helper::cast((*t_conversions)->boxed_type_conversion(t_conversions->saves(), bv), t_conversions); } catch (...) { try { - // std::cout << "trying a down conversion " << typeid(Type).name() << '\n'; - // try going the other way - down the inheritance graph + // try going the other way return detail::Cast_Helper::cast((*t_conversions)->boxed_type_down_conversion(t_conversions->saves(), bv), t_conversions); } catch (const chaiscript::detail::exception::bad_any_cast &) { throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); } } } else { - // If it's not polymorphic, just throw the error, don't waste the time on the + // If it's not convertable, just throw the error, don't waste the time on the // attempted dynamic_cast throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); } diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 011b6fa..7eefe99 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -30,7 +30,7 @@ namespace chaiscript { arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {} arithmetic_error(const arithmetic_error &) = default; - virtual ~arithmetic_error() noexcept {} + virtual ~arithmetic_error() noexcept = default; }; } } diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index d98400b..1345b13 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -56,14 +56,14 @@ namespace chaiscript class reserved_word_error : public std::runtime_error { public: - reserved_word_error(const std::string &t_word) noexcept + explicit reserved_word_error(const std::string &t_word) noexcept : std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word) { } reserved_word_error(const reserved_word_error &) = default; - virtual ~reserved_word_error() noexcept {} + virtual ~reserved_word_error() noexcept = default; std::string word() const { @@ -78,14 +78,14 @@ namespace chaiscript class illegal_name_error : public std::runtime_error { public: - illegal_name_error(const std::string &t_name) noexcept + explicit illegal_name_error(const std::string &t_name) noexcept : std::runtime_error("Reserved name not allowed in object name: " + t_name), m_name(t_name) { } illegal_name_error(const illegal_name_error &) = default; - virtual ~illegal_name_error() noexcept {} + virtual ~illegal_name_error() noexcept = default; std::string name() const { @@ -101,14 +101,14 @@ namespace chaiscript class name_conflict_error : public std::runtime_error { public: - name_conflict_error(const std::string &t_name) noexcept + explicit name_conflict_error(const std::string &t_name) noexcept : std::runtime_error("Name already exists in current context " + t_name), m_name(t_name) { } name_conflict_error(const name_conflict_error &) = default; - virtual ~name_conflict_error() noexcept {} + virtual ~name_conflict_error() noexcept = default; std::string name() const { @@ -131,7 +131,7 @@ namespace chaiscript } global_non_const(const global_non_const &) = default; - virtual ~global_non_const() noexcept {} + virtual ~global_non_const() noexcept = default; }; } @@ -194,30 +194,28 @@ namespace chaiscript apply_globals(m_globals.begin(), m_globals.end(), t_engine); } - ~Module() - { - } - bool has_function(const Proxy_Function &new_f, const std::string &name) { - return std::any_of(m_funcs.begin(), m_funcs.end(), [&](const std::pair &existing_f) { - return existing_f.second == name && *(existing_f.first) == *(new_f); - }); + return std::any_of(m_funcs.begin(), m_funcs.end(), + [&](const std::pair &existing_f) { + return existing_f.second == name && *(existing_f.first) == *(new_f); + } + ); } private: - std::vector > m_typeinfos; - std::vector > m_funcs; - std::vector > m_globals; + std::vector> m_typeinfos; + std::vector> m_funcs; + std::vector> m_globals; std::vector m_evals; std::vector m_conversions; template static void apply(InItr begin, const InItr end, T &t) { - for_each(begin, end, [&t](typename std::iterator_traits::reference obj) - { + for_each(begin, end, + [&t](const auto &obj) { try { t.add(obj.first, obj.second); } catch (const chaiscript::exception::name_conflict_error &) { @@ -600,12 +598,10 @@ namespace chaiscript { t_holder.call_params.pop_back(); StackData &stack = get_stack_data(t_holder); - if (stack.size() > 1) - { - stack.pop_back(); - } else { - throw std::range_error("Unable to pop global stack"); - } + + assert(!stack.empty()); + + stack.pop_back(); } @@ -916,10 +912,8 @@ namespace chaiscript } for (const auto &fun : t_funs) { - if (fun->is_attribute_function()) { - if (fun->compare_first_type(t_params[0], t_conversions)) { - return true; - } + if (fun->is_attribute_function() + && fun->compare_first_type(t_params[0], t_conversions)) { } } @@ -1107,7 +1101,7 @@ namespace chaiscript const Const_Proxy_Function &f = this->boxed_cast(params[0]); const Type_Conversions_State convs(m_conversions, m_conversions.conversion_saves()); - return Boxed_Value(f->call_match(std::vector(params.begin() + 1, params.end()), convs)); + return const_var(f->call_match(std::vector(params.begin() + 1, params.end()), convs)); } /// Dump all system info to stdout diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index d6052d9..b35ded6 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -33,7 +33,7 @@ namespace chaiscript option_explicit_set(const option_explicit_set &) = default; - virtual ~option_explicit_set() noexcept {} + virtual ~option_explicit_set() noexcept = default; }; class Dynamic_Object diff --git a/include/chaiscript/dispatchkit/dynamic_object_detail.hpp b/include/chaiscript/dispatchkit/dynamic_object_detail.hpp index 28df3e9..14f080d 100644 --- a/include/chaiscript/dispatchkit/dynamic_object_detail.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object_detail.hpp @@ -39,7 +39,7 @@ namespace chaiscript /// A Proxy_Function implementation designed for calling a function /// that is automatically guarded based on the first param based on the /// param's type name - class Dynamic_Object_Function : public Proxy_Function_Base + class Dynamic_Object_Function final : public Proxy_Function_Base { public: Dynamic_Object_Function( @@ -67,12 +67,11 @@ namespace chaiscript && "Programming error, Dynamic_Object_Function must have at least one parameter (this)"); } - virtual ~Dynamic_Object_Function() {} Dynamic_Object_Function &operator=(const Dynamic_Object_Function) = delete; Dynamic_Object_Function(Dynamic_Object_Function &) = delete; - virtual bool operator==(const Proxy_Function_Base &f) const override + bool operator==(const Proxy_Function_Base &f) const override { if (const auto *df = dynamic_cast(&f)) { @@ -82,9 +81,9 @@ namespace chaiscript } } - virtual bool is_attribute_function() const override { return m_is_attribute; } + bool is_attribute_function() const override { return m_is_attribute; } - virtual bool call_match(const std::vector &vals, const Type_Conversions_State &t_conversions) const override + bool call_match(const std::vector &vals, const Type_Conversions_State &t_conversions) const override { if (dynamic_object_typename_match(vals, m_type_name, m_ti, t_conversions)) { @@ -94,12 +93,12 @@ namespace chaiscript } } - virtual std::vector get_contained_functions() const override + std::vector get_contained_functions() const override { return {m_func}; } - virtual std::string annotation() const override + std::string annotation() const override { return m_func->annotation(); } @@ -170,9 +169,7 @@ namespace chaiscript Proxy_Function m_func; std::unique_ptr m_ti; const Type_Info m_doti; - bool m_is_attribute; - - + const bool m_is_attribute; }; @@ -182,7 +179,7 @@ namespace chaiscript * that is automatically guarded based on the first param based on the * param's type name */ - class Dynamic_Object_Constructor : public Proxy_Function_Base + class Dynamic_Object_Constructor final : public Proxy_Function_Base { public: Dynamic_Object_Constructor( @@ -208,9 +205,7 @@ namespace chaiscript return std::vector(begin, end); } - virtual ~Dynamic_Object_Constructor() {} - - virtual bool operator==(const Proxy_Function_Base &f) const override + bool operator==(const Proxy_Function_Base &f) const override { const Dynamic_Object_Constructor *dc = dynamic_cast(&f); return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func); @@ -230,7 +225,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions_State &t_conversions) const override + Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions_State &t_conversions) const override { auto bv = Boxed_Value(Dynamic_Object(m_type_name), true); std::vector new_params{bv};