diff --git a/src/bin/eolian_cxx/convert.cc b/src/bin/eolian_cxx/convert.cc index 2fa45b569b..fab4c1608c 100644 --- a/src/bin/eolian_cxx/convert.cc +++ b/src/bin/eolian_cxx/convert.cc @@ -24,7 +24,7 @@ namespace eolian_cxx { extern efl::eina::log_domain domain; void -add_parent_recursive(const char* klass_name, std::set& parents) +add_ancestor_recursive(const char* klass_name, std::set& ancestor) { if (!klass_name) return; @@ -36,14 +36,14 @@ add_parent_recursive(const char* klass_name, std::set& parents) return; } - parents.insert(class_format_cxx(safe_lower(klass_name))); + ancestor.insert(class_format_cxx(safe_lower(klass_name))); Eina_Iterator* inheritances = ::eolian_class_inherits_get(klass); void* curr = 0; EINA_ITERATOR_FOREACH(inheritances, curr) { - add_parent_recursive(static_cast(curr), parents); + add_ancestor_recursive(static_cast(curr), ancestor); } eina_iterator_free(inheritances); } @@ -182,15 +182,17 @@ convert_eolian_inheritances(efl::eolian::eo_class& cls, Eolian_Class const& klas ::eolian_class_inherits_get(&klass); void *curr; - std::set parents; + std::set ancestors; EINA_ITERATOR_FOREACH(inheritances, curr) { - add_parent_recursive(static_cast(curr), parents); + const char* klass_name = static_cast(curr); + cls.parents.push_back(class_format_cxx(safe_lower(klass_name))); + add_ancestor_recursive(klass_name, ancestors); } eina_iterator_free(inheritances); - cls.parents.assign(parents.begin(), parents.end()); + cls.ancestors.assign(ancestors.begin(), ancestors.end()); } void diff --git a/src/bin/eolian_cxx/eolian_wrappers.hh b/src/bin/eolian_cxx/eolian_wrappers.hh index 6b0211e798..477173959b 100644 --- a/src/bin/eolian_cxx/eolian_wrappers.hh +++ b/src/bin/eolian_cxx/eolian_wrappers.hh @@ -348,7 +348,7 @@ parameter_type(Eolian_Function_Parameter const& parameter, assert(!type.empty()); if (parameter_is_out(parameter)) { - if (type.front().native == "char *") + if (type.front().native.find("char") != std::string::npos) type = { efl::eolian::type_to_native(type) }; type.is_out = true; type.front().native += "*"; diff --git a/src/bindings/eo_cxx/eo_concrete.hh b/src/bindings/eo_cxx/eo_concrete.hh index d92fe7b851..cd72dd7e1a 100644 --- a/src/bindings/eo_cxx/eo_concrete.hh +++ b/src/bindings/eo_cxx/eo_concrete.hh @@ -47,6 +47,15 @@ struct concrete { } + + /// @brief Default constructor. + /// + /// Constructs a NULL initialized efl::eo::concrete object. + /// + concrete() : _eo_raw(nullptr) + { + } + /// @brief Class destructor. /// ~concrete() diff --git a/src/bindings/eo_cxx/eo_cxx_interop.hh b/src/bindings/eo_cxx/eo_cxx_interop.hh index b0ca1ed445..ddf4375cd1 100644 --- a/src/bindings/eo_cxx/eo_cxx_interop.hh +++ b/src/bindings/eo_cxx/eo_cxx_interop.hh @@ -108,6 +108,14 @@ to_cxx(Eo* x, std::tuple, tag) return T(::eo_ref(x)); } +template +inline T +to_cxx(Eo** x, std::tuple, tag) +{ + static_assert(sizeof(Eo*) == sizeof(typename std::remove_pointer::type), ""); + return static_cast((static_cast(x))); +} + #ifdef _EVAS_H template Evas_Object_Textblock_Node_Format * diff --git a/src/bindings/eo_cxx/eo_inherit.hh b/src/bindings/eo_cxx/eo_inherit.hh index c04e3ceb88..d4512a9b0a 100644 --- a/src/bindings/eo_cxx/eo_inherit.hh +++ b/src/bindings/eo_cxx/eo_inherit.hh @@ -105,12 +105,6 @@ struct inherit /// Eo_Class const* _eo_class() const { return _eo_cls; } - template - void parent_set(T& p_) - { - detail::parent_set(_eo_raw, p_._eo_ptr()); - } - Eo* _release() { Eo* tmp = _eo_raw; diff --git a/src/bindings/eo_cxx/eo_private.hh b/src/bindings/eo_cxx/eo_private.hh index 7640890835..344b1c5cc6 100644 --- a/src/bindings/eo_cxx/eo_private.hh +++ b/src/bindings/eo_cxx/eo_private.hh @@ -7,6 +7,7 @@ #define EFL_CXX_EO_PRIVATE_HH #include "eo_ops.hh" +#include "eo_concrete.hh" namespace efl { namespace eo { namespace detail { @@ -87,7 +88,7 @@ Eo_Class const* do_eo_class_new(Eo_Class_Description& class_desc) template struct operation_description_class_size; template<> -struct operation_description_class_size { static const int value = 0; }; +struct operation_description_class_size { static const int value = 0; }; /// @internal /// @@ -134,7 +135,7 @@ namespace detail { template struct operations; template <> -struct operations { template struct type {}; }; +struct operations { template struct type {}; }; /// @internal /// @@ -163,7 +164,7 @@ struct Inherit_Private_Data namespace efl { namespace eo { namespace detail { template -int initialize_operation_description(efl::eo::detail::tag +int initialize_operation_description(efl::eo::detail::tag , Eo_Op_Description* ops) { (void)ops; diff --git a/src/lib/eolian_cxx/eo_types.hh b/src/lib/eolian_cxx/eo_types.hh index 42abe397cd..4fa79a4f86 100644 --- a/src/lib/eolian_cxx/eo_types.hh +++ b/src/lib/eolian_cxx/eo_types.hh @@ -14,7 +14,7 @@ struct eo_parameter; struct eo_function; struct eo_event; -typedef std::vector parents_container_type; +typedef std::vector ancestors_container_type; typedef std::vector includes_container_type; typedef std::vector constructors_container_type; typedef std::vector functions_container_type; @@ -215,7 +215,8 @@ struct eo_class eo_class_type type; std::string name; std::string eo_name; - parents_container_type parents; + ancestors_container_type parents; + ancestors_container_type ancestors; constructors_container_type constructors; functions_container_type functions; events_container_type events; diff --git a/src/lib/eolian_cxx/grammar/eo_class_constructors_generator.hh b/src/lib/eolian_cxx/grammar/eo_class_constructors_generator.hh index 9ffed7543e..42d577614d 100644 --- a/src/lib/eolian_cxx/grammar/eo_class_constructors_generator.hh +++ b/src/lib/eolian_cxx/grammar/eo_class_constructors_generator.hh @@ -41,9 +41,9 @@ operator<<(std::ostream& out, class_inheritance const& x) { eo_class const& cls = x._cls; - parents_container_type::const_iterator it, - first = cls.parents.cbegin(), - last = cls.parents.cend(); + ancestors_container_type::const_iterator it, + first = cls.ancestors.cbegin(), + last = cls.ancestors.cend(); for (it = first; it != last; ++it) { out << tab(2) << ", ::" << abstract_namespace << "::" << *it << endl; diff --git a/src/lib/eolian_cxx/grammar/eo_class_generator.hh b/src/lib/eolian_cxx/grammar/eo_class_generator.hh index 57dc7390ba..1abf1ba675 100644 --- a/src/lib/eolian_cxx/grammar/eo_class_generator.hh +++ b/src/lib/eolian_cxx/grammar/eo_class_generator.hh @@ -151,7 +151,7 @@ struct address_of_inheritance inline std::ostream& operator<<(std::ostream& out, address_of_inheritance const& x) { - for (std::string const& parent : x._cls.parents) + for (std::string const& parent : x._cls.ancestors) { out << tab(2) << ", ::" << abstract_namespace << "::" << parent << "::" << x._struct_name << "<" << x._struct_name << ">" << endl; diff --git a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh index 9e10e5067d..30ee36d1bb 100644 --- a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh +++ b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh @@ -65,12 +65,8 @@ struct inheritance_operations_description inline std::ostream& operator<<(std::ostream& out, inheritance_operations_description const& x) { - extensions_container_type::const_iterator it, first, last; std::string s; - first = x._cls.extensions.begin(); - last = x._cls.extensions.end(); - out << "template " << endl << "int initialize_operation_description(::efl::eo::detail::tag<" << full_name(x._cls) << ">" << endl @@ -84,21 +80,13 @@ operator<<(std::ostream& out, inheritance_operations_description const& x) out << inheritance_operation(x._cls, i); } - out << tab(1) - << "initialize_operation_description(efl::eo::detail::tag<" - << x._cls.parent - << ">(), &ops[" - << x._cls.functions.size() << "]);" << endl; - - s += " + operation_description_class_size<" + x._cls.parent + ">::value"; - - for (it = first; it != last; ++it) + for (std::string const& parent : x._cls.parents) { out << tab(1) - << "initialize_operation_description(efl::eo::detail::tag<" - << *it << ">(), &ops[" << x._cls.functions.size() << s << "]);" << endl; + << "initialize_operation_description(::efl::eo::detail::tag<::" + << parent << ">(), &ops[" << x._cls.functions.size() << s << "]);" << endl; - s += " + operation_description_class_size< " + *it + ">::value"; + s += " + operation_description_class_size<::" + parent + ">::value"; } out << tab(1) << "return 0;" << endl @@ -168,21 +156,16 @@ struct inheritance_base_operations_size inline std::ostream& operator<<(std::ostream& out, inheritance_base_operations_size const& x) { - extensions_container_type::const_iterator it, first = x._cls.extensions.begin(); - extensions_container_type::const_iterator last = x._cls.extensions.end(); - first = x._cls.extensions.begin(); - out << "template<>" << endl << "struct operation_description_class_size< " << full_name(x._cls) << " >" << endl << "{" << endl << tab(1) << "static const int value = " - << x._cls.functions.size() - << " + operation_description_class_size<" << class_name(x._cls.parent) << ">::value"; + << x._cls.functions.size(); - for (it = first; it != last; ++it) + for (std::string const& parent : x._cls.parents) { - out << " + operation_description_class_size< " << *it << " >::value"; + out << " + operation_description_class_size<::" << parent << " >::value"; } out << ";" << endl @@ -205,14 +188,14 @@ inline std::ostream& operator<<(std::ostream& out, inheritance_base_operations_extensions const& x) { eo_class const& cls = x._cls; - extensions_container_type::const_iterator it, first = cls.extensions.begin(); - extensions_container_type::const_iterator last = cls.extensions.end(); + ancestors_container_type::const_iterator it, first = cls.parents.begin(); + ancestors_container_type::const_iterator last = cls.parents.end(); - out << endl << tab(3) << ": operations< " << class_name(cls.parent) << " >::template type"; for (it = first; it != last; ++it) { - out << "," << endl << tab(3) - << "operations< " << *it + out << endl + << tab(3) << (it == first ? ": " : ", ") + << "virtual operations< ::" << *it << " >::template type"; } @@ -247,12 +230,12 @@ operator<<(std::ostream& out, inheritance_base_operations_function const& x) if (!is_void) out << tab(3) << func.ret.front().native << " _tmp_ret = {};" << endl; - out << callbacks_heap_alloc("static_cast(this)->_eo_ptr()", func.params, 3) + out << callbacks_heap_alloc("dynamic_cast(this)->_eo_ptr()", func.params, 3) << endl; out << tab(3) - << "eo_do_super(static_cast(this)->_eo_ptr()," << endl - << tab(5) << "static_cast(this)->_eo_class()," << endl + << "eo_do_super(dynamic_cast(this)->_eo_ptr()," << endl + << tab(5) << "dynamic_cast(this)->_eo_class()," << endl << tab(5) << function_call(func) << ");" << endl; if (!is_void) @@ -325,10 +308,10 @@ operator<<(std::ostream& out, inheritance_call_constructors const& x) { eo_constructor const& ctor = *it; out << "inline void" << endl - << "call_constructor(tag< " + << "call_constructor(::efl::eo::detail::tag< " << full_name(x._cls) << " >" << endl << tab(5) << ", Eo* eo, Eo_Class const* cls EINA_UNUSED," << endl - << tab(5) << "args_class<" + << tab(5) << "::efl::eo::detail::args_class<" << full_name(x._cls) << ", ::std::tuple<" << parameters_types(ctor.params) @@ -343,10 +326,10 @@ operator<<(std::ostream& out, inheritance_call_constructors const& x) } out << "inline void" << endl - << "call_constructor(tag< " + << "call_constructor(::efl::eo::detail::tag< " << full_name(x._cls) << " >" << endl << tab(5) << ", Eo* eo, Eo_Class const* cls EINA_UNUSED," << endl - << tab(5) << "args_class<" + << tab(5) << "::efl::eo::detail::args_class<" << full_name(x._cls) << ", ::std::tuple<::efl::eo::parent_type> > const& args)" << endl << "{" << endl @@ -357,81 +340,6 @@ operator<<(std::ostream& out, inheritance_call_constructors const& x) return out; } -struct inheritance_extension_function -{ - eo_function const& _func; - inheritance_extension_function(eo_function const& func) : _func(func) {} -}; - -inline std::ostream& -operator<<(std::ostream& out, inheritance_extension_function const& x) -{ - out << template_parameters_declaration(x._func.params, 1); - - bool is_void = function_is_void(x._func); - out << tab(2) - << reinterpret_type(x._func.ret) << " " - << x._func.name << "(" - << parameters_declaration(x._func.params) - << ")" << endl - << tab(2) << "{" << endl; - - if (!is_void) - { - out << tab(3) << x._func.ret.front().native << " _tmp_ret = {};" << endl; - } - - out << callbacks_heap_alloc("static_cast(this)->_eo_ptr()", x._func.params, 2) - << endl; - - out << tab(3) << "eo_do(static_cast(this)->_eo_ptr(), " - << function_call(x._func) << ");" << endl; - - if (!function_is_void(x._func)) - out << tab(4) << "return " << to_cxx(x._func.ret, "_tmp_ret") << ";" << endl; - out << tab(2) << "}" << endl - << endl; - - return out; -} - -struct inheritance_extension -{ - eo_class const& _cls; - inheritance_extension(eo_class const& cls) : _cls(cls) {} -}; - -inline std::ostream& -operator<<(std::ostream& out, inheritance_extension const& x) -{ - full_name const cls(x._cls); - out << "template<>" << endl - << "struct extension_inheritance< " - << cls << ">" << endl - << "{" << endl - << tab(1) << "template " << endl - << tab(1) << "struct type" << endl - << tab(1) << "{" << endl - << tab(2) << "operator " << cls << "() const" << endl - << tab(2) << "{" << endl - << tab(3) << "return " << cls - << "(eo_ref(static_cast(this)->_eo_ptr()));" << endl - << tab(2) << "}" << endl - << endl; - functions_container_type::const_iterator it, - first = x._cls.functions.begin(), - last = x._cls.functions.end(); - for (it = first; it != last; ++it) - { - out << inheritance_extension_function(*it); - } - out << events(x._cls, true); - out << tab(1) << "};" << endl - << "};" << endl - << endl; - return out; -} - struct inheritance_eo_class_getter { eo_class const& _cls; @@ -460,7 +368,6 @@ eo_inheritance_detail_generator(std::ostream& out, eo_class const& cls) << inheritance_base_operations_size(cls) << inheritance_operations_description(cls) << inheritance_call_constructors(cls) - << inheritance_extension(cls) << inheritance_eo_class_getter(cls) << "} } }" << endl; } diff --git a/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc b/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc index 1930717252..1337135528 100644 --- a/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc +++ b/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc @@ -14,7 +14,7 @@ struct bar : efl::eo::inherit { bar() - : inherit_base() + : inherit_base(efl::eo::parent = nullptr) {} bool simple_get() diff --git a/src/tests/eolian_cxx/simple.eo b/src/tests/eolian_cxx/simple.eo index 764adb7856..a35ec3aae3 100644 --- a/src/tests/eolian_cxx/simple.eo +++ b/src/tests/eolian_cxx/simple.eo @@ -4,13 +4,13 @@ class Simple (Eo.Base) data: null; methods { simple_get { - return bool; + return: bool; } name_get { params { @out const(char)* name; } - return bool; + return: bool; } } implements {