diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 9b4548d..d8a4eed 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -257,7 +257,7 @@ namespace chaiscript { public: Dispatch_Function(std::vector t_funcs) - : Proxy_Function_Base(build_type_infos(t_funcs)), + : Proxy_Function_Base(build_type_infos(t_funcs), calculate_arity(t_funcs)), m_funcs(std::move(t_funcs)) { } @@ -280,15 +280,15 @@ namespace chaiscript } - virtual int get_arity() const CHAISCRIPT_OVERRIDE + static int calculate_arity(const std::vector &t_funcs) { - if (m_funcs.empty()) { + if (t_funcs.empty()) { return -1; } - const auto arity = m_funcs.front()->get_arity(); + const auto arity = t_funcs.front()->get_arity(); - for (const auto &func : m_funcs) + for (const auto &func : t_funcs) { if (arity != func->get_arity()) { diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index 93ffd26..69c24d5 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -73,7 +73,7 @@ namespace chaiscript Dynamic_Object_Function( std::string t_type_name, const Proxy_Function &t_func) - : Proxy_Function_Base(t_func->get_param_types()), + : Proxy_Function_Base(t_func->get_param_types(), t_func->get_arity()), m_type_name(std::move(t_type_name)), m_func(t_func), m_doti(user_type()) { assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) @@ -84,7 +84,7 @@ namespace chaiscript std::string t_type_name, const Proxy_Function &t_func, const Type_Info &t_ti) - : Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)), + : Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti), t_func->get_arity()), m_type_name(std::move(t_type_name)), m_func(t_func), m_ti(new Type_Info(t_ti)), m_doti(user_type()) { assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) @@ -121,12 +121,6 @@ namespace chaiscript return {m_func}; } - - virtual int get_arity() const CHAISCRIPT_OVERRIDE - { - return m_func->get_arity(); - } - virtual std::string annotation() const CHAISCRIPT_OVERRIDE { return m_func->annotation(); @@ -215,7 +209,7 @@ namespace chaiscript Dynamic_Object_Constructor( std::string t_type_name, const Proxy_Function &t_func) - : Proxy_Function_Base(build_type_list(t_func->get_param_types())), + : Proxy_Function_Base(build_type_list(t_func->get_param_types()), t_func->get_arity() - 1), m_type_name(std::move(t_type_name)), m_func(t_func) { assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) @@ -256,13 +250,6 @@ namespace chaiscript return m_func->call_match(new_vals, t_conversions); } - - virtual int get_arity() const CHAISCRIPT_OVERRIDE - { - // "this" is not considered part of the arity - return m_func->get_arity() - 1; - } - virtual std::string annotation() const CHAISCRIPT_OVERRIDE { return m_func->annotation(); diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index df446ad..0da241e 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -84,13 +84,11 @@ namespace chaiscript //! to the passed in values bool filter(const std::vector &vals, const Type_Conversions &t_conversions) const { - int arity = get_arity(); - - if (arity < 0) + if (m_arity < 0) { return true; - } else if (size_t(arity) == vals.size()) { - if (arity == 0) + } else if (size_t(m_arity) == vals.size()) { + if (m_arity == 0) { return true; } else { @@ -102,7 +100,10 @@ namespace chaiscript } /// \returns the number of arguments the function takes or -1 if it is variadic - virtual int get_arity() const = 0; + int get_arity() const + { + return m_arity; + } virtual std::string annotation() const = 0; @@ -127,8 +128,8 @@ namespace chaiscript protected: virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const = 0; - Proxy_Function_Base(std::vector t_types) - : m_types(std::move(t_types)), m_has_arithmetic_param(false) + Proxy_Function_Base(std::vector t_types, int t_arity) + : m_types(std::move(t_types)), m_has_arithmetic_param(false), m_arity(t_arity) { for (size_t i = 1; i < m_types.size(); ++i) { @@ -175,7 +176,7 @@ namespace chaiscript std::vector m_types; bool m_has_arithmetic_param; - + int m_arity; }; } @@ -216,7 +217,7 @@ namespace chaiscript AST_NodePtr t_parsenode = AST_NodePtr(), std::string t_description = "", Proxy_Function t_guard = Proxy_Function()) - : Proxy_Function_Base(build_param_type_list(t_arity)), + : Proxy_Function_Base(build_param_type_list(t_arity), t_arity), m_f(std::move(t_f)), m_arity(t_arity), m_description(std::move(t_description)), m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode)) { } @@ -239,10 +240,6 @@ namespace chaiscript && test_guard(vals, t_conversions); } - virtual int get_arity() const CHAISCRIPT_OVERRIDE - { - return m_arity; - } Proxy_Function get_guard() const { @@ -338,8 +335,8 @@ namespace chaiscript public: Bound_Function(const Const_Proxy_Function &t_f, const std::vector &t_args) - : Proxy_Function_Base(build_param_type_info(t_f, t_args)), - m_f(t_f), m_args(t_args), m_arity(t_f->get_arity()<0?-1:static_cast(get_param_types().size())-1) + : Proxy_Function_Base(build_param_type_info(t_f, t_args), (t_f->get_arity()<0?-1:static_cast(build_param_type_info(t_f, t_args).size())-1)), + m_f(t_f), m_args(t_args) { assert(m_f->get_arity() < 0 || m_f->get_arity() == static_cast(m_args.size())); } @@ -395,11 +392,6 @@ namespace chaiscript return args; } - virtual int get_arity() const CHAISCRIPT_OVERRIDE - { - return m_arity; - } - virtual std::string annotation() const CHAISCRIPT_OVERRIDE { return "Bound: " + m_f->annotation(); @@ -444,17 +436,12 @@ namespace chaiscript { public: Proxy_Function_Impl_Base(std::vector t_types) - : Proxy_Function_Base(std::move(t_types)) + : Proxy_Function_Base(std::move(t_types), t_types.size() - 1) { } virtual ~Proxy_Function_Impl_Base() {} - virtual int get_arity() const CHAISCRIPT_OVERRIDE - { - return static_cast(m_types.size()) - 1; - } - virtual std::string annotation() const CHAISCRIPT_OVERRIDE { return ""; @@ -524,8 +511,8 @@ namespace chaiscript { public: Attribute_Access(T Class::* t_attr) - : Proxy_Function_Base(param_types()), - m_attr(t_attr) + : Proxy_Function_Base(param_types(), 1), + m_attr(t_attr) { } @@ -543,12 +530,6 @@ namespace chaiscript } } - - virtual int get_arity() const CHAISCRIPT_OVERRIDE - { - return 1; - } - virtual bool call_match(const std::vector &vals, const Type_Conversions &) const CHAISCRIPT_OVERRIDE { if (vals.size() != 1)