From 6e23780bb13fdc16a2034d01bf3fc06a2355fbee Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Mon, 23 May 2016 17:34:50 -0300 Subject: [PATCH] eolian-cxx: Fix generation of complex types in C++ binding Fixed generation of complex types in C++ binding, with tests. This problem came after the removal of the pointer types for top-level complex types. --- src/bin/eolian_cxx/type_lookup.hh | 12 +++- src/bin/eolian_cxx/type_lookup_table.cc | 5 +- src/bindings/cxx/eina_cxx/Eina.hh | 1 + src/bindings/cxx/eina_cxx/eina_array.hh | 2 - .../cxx/eina_cxx/eina_clone_allocators.hh | 14 ++++ src/bindings/cxx/eina_cxx/eina_workarounds.hh | 71 +++++++++++++++++++ src/bindings/cxx/eo_cxx/eo_cxx_interop.hh | 49 +++++++++++++ src/tests/eolian_cxx/complex_cxx.cc | 23 ++++++ 8 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 src/bindings/cxx/eina_cxx/eina_workarounds.hh diff --git a/src/bin/eolian_cxx/type_lookup.hh b/src/bin/eolian_cxx/type_lookup.hh index 57d7c940b6..37e4ff7b33 100644 --- a/src/bin/eolian_cxx/type_lookup.hh +++ b/src/bin/eolian_cxx/type_lookup.hh @@ -124,15 +124,21 @@ type_lookup(const Eolian_Type* type, std::vector types; types.push_back(type); - if (::eolian_type_type_get(type) == EOLIAN_TYPE_POINTER && type_is_complex(*eolian_type_base_type_get(type))) + if (::eolian_type_type_get(type) == EOLIAN_TYPE_COMPLEX/* && type_is_complex(*eolian_type_base_type_get(type))*/) { efl::eina::iterator end; efl::eina::iterator it - (::eolian_type_subtypes_get(eolian_type_base_type_get(type))); + (::eolian_type_subtypes_get(type)); while(it != end) { if(Eolian_Type const* t = &*it) - types.push_back(t), ++it; + { + types.push_back + ( ::eolian_type_type_get(t) == EOLIAN_TYPE_POINTER ? ::eolian_type_base_type_get(t) /* remove this base type get when pointers are removed */ + : t + ); + ++it; + } } } diff --git a/src/bin/eolian_cxx/type_lookup_table.cc b/src/bin/eolian_cxx/type_lookup_table.cc index 55a8e6968a..046b8b8744 100644 --- a/src/bin/eolian_cxx/type_lookup_table.cc +++ b/src/bin/eolian_cxx/type_lookup_table.cc @@ -4,8 +4,6 @@ namespace eolian_cxx { using efl::eolian::eolian_type; -// Keep the table sorted! -// This can help: cat type_lookup_table | LC_ALL=C sort const lookup_table_type type_lookup_table { @@ -22,6 +20,9 @@ type_lookup_table {"Eina_List *", eolian_type::complex_, false, false, true, true, "::efl::eina::range_list", {"eina_list.hh"}}, {"Eina_List *", eolian_type::complex_, false, true, true, true, "::efl::eina::list", {"eina_list.hh"}}, {"const Eina_List *", eolian_type::complex_, true, false, true, true, "::efl::eina::crange_list", {"eina_list.hh"}}, + {"Eina_Array *", eolian_type::complex_, false, false, true, true, "::efl::eina::range_array", {"eina_array.hh"}}, + {"Eina_Array *", eolian_type::complex_, false, true, true, true, "::efl::eina::array", {"eina_array.hh"}}, + {"const Eina_Array *", eolian_type::complex_, true, false, true, true, "::efl::eina::crange_array", {"eina_array.hh"}}, {"Eio_Filter_Direct_Cb", eolian_type::callback_, {"Eio.h"}}, {"Eo *", eolian_type::simple_, false, true, true, false, "::efl::eo::concrete", {"eo_concrete.hh"}}, {"Eo *", eolian_type::simple_, false, false, true, false, "::efl::eo::concrete", {"eo_concrete.hh"}}, diff --git a/src/bindings/cxx/eina_cxx/Eina.hh b/src/bindings/cxx/eina_cxx/Eina.hh index 8f5462892e..cb413f49c8 100644 --- a/src/bindings/cxx/eina_cxx/Eina.hh +++ b/src/bindings/cxx/eina_cxx/Eina.hh @@ -23,6 +23,7 @@ #include #include #include +#include /** * @page eina_cxx_main Eina C++ (BETA) diff --git a/src/bindings/cxx/eina_cxx/eina_array.hh b/src/bindings/cxx/eina_cxx/eina_array.hh index 7c8e7985d0..2c5cdb103e 100644 --- a/src/bindings/cxx/eina_cxx/eina_array.hh +++ b/src/bindings/cxx/eina_cxx/eina_array.hh @@ -479,8 +479,6 @@ public: typedef typename _base_type::native_handle_type native_handle_type; - range_array& operator=(range_array&& other) = default; - using _base_type::_base_type; using _base_type::size; using _base_type::empty; diff --git a/src/bindings/cxx/eina_cxx/eina_clone_allocators.hh b/src/bindings/cxx/eina_cxx/eina_clone_allocators.hh index 76ff620f98..3af9336fc5 100644 --- a/src/bindings/cxx/eina_cxx/eina_clone_allocators.hh +++ b/src/bindings/cxx/eina_cxx/eina_clone_allocators.hh @@ -1,6 +1,8 @@ #ifndef EINA_CLONE_ALLOCATORS_HH_ #define EINA_CLONE_ALLOCATORS_HH_ +#include + #include #include @@ -122,6 +124,18 @@ struct view_clone_allocator */ struct heap_no_copy_allocator { + static void deallocate_clone(_Elm_Calendar_Mark const volatile*) {} + static void deallocate_clone(_Elm_Calendar_Mark volatile*) {} + static void deallocate_clone(_Elm_Calendar_Mark const*) {} + static void deallocate_clone(_Elm_Calendar_Mark*) {} + static void deallocate_clone(Elm_Gen_Item const volatile*) {} + static void deallocate_clone(Elm_Gen_Item volatile*) {} + static void deallocate_clone(Elm_Gen_Item const*) {} + static void deallocate_clone(Elm_Gen_Item*) {} + static void deallocate_clone(_Elm_Map_Overlay const volatile*) {} + static void deallocate_clone(_Elm_Map_Overlay volatile*) {} + static void deallocate_clone(_Elm_Map_Overlay const*) {} + static void deallocate_clone(_Elm_Map_Overlay*) {} template static void deallocate_clone(T* p) { diff --git a/src/bindings/cxx/eina_cxx/eina_workarounds.hh b/src/bindings/cxx/eina_cxx/eina_workarounds.hh new file mode 100644 index 0000000000..635bf235ff --- /dev/null +++ b/src/bindings/cxx/eina_cxx/eina_workarounds.hh @@ -0,0 +1,71 @@ +#ifndef EINA_WORKAROUNDS_HH_ +#define EINA_WORKAROUNDS_HH_ + +#include + +#include +#include + +struct _Elm_Calendar_Mark; +struct Elm_Gen_Item; +struct _Elm_Map_Overlay; + +namespace std { + +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Calendar_Mark > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Calendar_Mark const > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Calendar_Mark volatile > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Calendar_Mark const volatile > : std::false_type {}; + +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Calendar_Mark > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Calendar_Mark const > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Calendar_Mark volatile > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Calendar_Mark const volatile > : std::false_type {}; + +template <> +struct is_base_of< ::efl::eo::concrete, Elm_Gen_Item > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, Elm_Gen_Item const > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, Elm_Gen_Item volatile > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, Elm_Gen_Item const volatile > : std::false_type {}; + +template <> +struct is_base_of< const ::efl::eo::concrete, Elm_Gen_Item > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, Elm_Gen_Item const > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, Elm_Gen_Item volatile > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, Elm_Gen_Item const volatile > : std::false_type {}; + +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Map_Overlay > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Map_Overlay const > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Map_Overlay volatile > : std::false_type {}; +template <> +struct is_base_of< ::efl::eo::concrete, _Elm_Map_Overlay const volatile > : std::false_type {}; + +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Map_Overlay > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Map_Overlay const > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Map_Overlay volatile > : std::false_type {}; +template <> +struct is_base_of< const ::efl::eo::concrete, _Elm_Map_Overlay const volatile > : std::false_type {}; + +} + +#endif diff --git a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh index 1e35d0c942..a588b5b8e1 100644 --- a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh +++ b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh @@ -303,6 +303,55 @@ to_cxx(Eina_List* x, std::tuple, tag< eina::optional {x}; } +template +inline efl::eina::range_array +to_cxx(const Eina_Array* x, std::tuple, tag< efl::eina::range_array >) +{ + return efl::eina::range_array {x}; +} + +template +inline eina::optional > +to_cxx(const Eina_Array* x, std::tuple, tag< eina::optional > >) +{ + if (!x) + return nullptr; + return efl::eina::range_array {x}; +} + +template +inline efl::eina::range_array +to_cxx(Eina_Array* x, std::tuple, tag< efl::eina::range_array >) +{ + return efl::eina::range_array{x}; +} + +template +inline eina::optional > +to_cxx(Eina_Array* x, std::tuple, tag< eina::optional > >) +{ + if (!x) + return nullptr; + return efl::eina::range_array{x}; +} + +template +inline efl::eina::array +to_cxx(Eina_Array* x, std::tuple, tag< efl::eina::array >) +{ + return efl::eina::array {x}; +} + +template +inline eina::optional > +to_cxx(Eina_Array* x, std::tuple, tag< eina::optional > >) +{ + if (!x) + return nullptr; + return efl::eina::array {x}; +} + + inline eina::stringshare to_cxx(Eina_Stringshare const* x, const std::false_type, tag) { diff --git a/src/tests/eolian_cxx/complex_cxx.cc b/src/tests/eolian_cxx/complex_cxx.cc index 60b76c4337..8b8d5e6286 100644 --- a/src/tests/eolian_cxx/complex_cxx.cc +++ b/src/tests/eolian_cxx/complex_cxx.cc @@ -3,3 +3,26 @@ #include "complex.eo.h" #include "complex.eo.hh" + +template +struct test1; + +template +struct test1 +{ + static_assert(std::is_same, U>::value, "Wrong type"); +}; + +template +struct test2; + +template +struct test2 +{ + static_assert(std::is_same, U>::value, "Wrong type"); +}; + +test1 foo; +test2 bar; + +