summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2014-08-26 15:54:28 -0300
committerVitor Sousa <vitorsousasilva@gmail.com>2015-01-05 15:52:27 -0200
commit2b12114777cc9e0b7db3894f37dd71f6b5b073b4 (patch)
tree36f246a048f624419cad6609f4cfd9c0c697a82b
parent0685885c2a488c41f118118de8506f8d286e3eea (diff)
allow C++ user create new classes inheriting from Eolian generated Classes
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile_Eolian_Cxx.am13
-rw-r--r--src/bindings/eo_cxx/eo_private.hh17
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_inherit_01.cc24
-rw-r--r--src/lib/eolian_cxx/grammar/inheritance_base_generator.hh67
-rw-r--r--src/tests/eolian_cxx/eolian_cxx_suite.cc2
-rw-r--r--src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc44
-rw-r--r--src/tests/eolian_cxx/simple.c38
-rw-r--r--src/tests/eolian_cxx/simple.eo19
9 files changed, 221 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 57b56b7a88..b0b48848fb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,7 +2,7 @@ MAINTAINERCLEANFILES = Makefile.in
2CLEANFILES = 2CLEANFILES =
3BUILT_SOURCES = 3BUILT_SOURCES =
4 4
5EOLIAN_FLAGS = \ 5EOLIAN_FLAGS = -I$(srcdir)\
6 -I$(srcdir)/lib/eo \ 6 -I$(srcdir)/lib/eo \
7 -I$(srcdir)/lib/evas/canvas \ 7 -I$(srcdir)/lib/evas/canvas \
8 -I$(srcdir)/lib/edje \ 8 -I$(srcdir)/lib/edje \
diff --git a/src/Makefile_Eolian_Cxx.am b/src/Makefile_Eolian_Cxx.am
index 88f1186eaa..d0b84509a1 100644
--- a/src/Makefile_Eolian_Cxx.am
+++ b/src/Makefile_Eolian_Cxx.am
@@ -72,6 +72,8 @@ tests/eolian_cxx/d.c \
72tests/eolian_cxx/eolian_cxx_test_callback.cc \ 72tests/eolian_cxx/eolian_cxx_test_callback.cc \
73tests/eolian_cxx/eolian_cxx_test_address_of.cc \ 73tests/eolian_cxx/eolian_cxx_test_address_of.cc \
74tests/eolian_cxx/eolian_cxx_test_wrapper.cc \ 74tests/eolian_cxx/eolian_cxx_test_wrapper.cc \
75tests/eolian_cxx/simple.c \
76tests/eolian_cxx/eolian_cxx_test_inheritance.cc \
75tests/eolian_cxx/eolian_cxx_test_generate.cc 77tests/eolian_cxx/eolian_cxx_test_generate.cc
76 78
77tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh 79tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_callback.$(OBJEXT): tests/eolian_cxx/callback.eo.hh
@@ -83,7 +85,15 @@ tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-b.$(OBJEXT): tests/eolian_cxx
83tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-c.$(OBJEXT): tests/eolian_cxx/c.eo.c tests/eolian_cxx/c.eo.h 85tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-c.$(OBJEXT): tests/eolian_cxx/c.eo.c tests/eolian_cxx/c.eo.h
84tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-d.$(OBJEXT): tests/eolian_cxx/d.eo.c tests/eolian_cxx/d.eo.h 86tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-d.$(OBJEXT): tests/eolian_cxx/d.eo.c tests/eolian_cxx/d.eo.h
85 87
86CLEANFILES += tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.c tests/eolian_cxx/callback.eo.h \ 88tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-eolian_cxx_test_inheritance.$(OBJEXT): tests/eolian_cxx/simple.eo.hh
89
90tests/eolian_cxx/tests_eolian_cxx_eolian_cxx_suite-simple.$(OBJEXT): tests/eolian_cxx/simple.eo.c tests/eolian_cxx/simple.eo.h
91
92CLEANFILES += tests/eolian_cxx/callback.eo.hh tests/eolian_cxx/callback.eo.c \
93tests/eolian_cxx/callback.eo.h \
94tests/eolian_cxx/simple.eo.c \
95tests/eolian_cxx/simple.eo.h \
96tests/eolian_cxx/simple.eo.hh \
87tests/eolian_cxx/a.eo.hh tests/eolian_cxx/a.eo.c tests/eolian_cxx/a.eo.h \ 97tests/eolian_cxx/a.eo.hh tests/eolian_cxx/a.eo.c tests/eolian_cxx/a.eo.h \
88tests/eolian_cxx/b.eo.hh tests/eolian_cxx/b.eo.c tests/eolian_cxx/b.eo.h \ 98tests/eolian_cxx/b.eo.hh tests/eolian_cxx/b.eo.c tests/eolian_cxx/b.eo.h \
89tests/eolian_cxx/c.eo.hh tests/eolian_cxx/c.eo.c tests/eolian_cxx/c.eo.h \ 99tests/eolian_cxx/c.eo.hh tests/eolian_cxx/c.eo.c tests/eolian_cxx/c.eo.h \
@@ -111,6 +121,7 @@ tests_eolian_cxx_eolian_cxx_suite_DEPENDENCIES = @USE_EOLIAN_INTERNAL_LIBS@
111endif 121endif
112 122
113EXTRA_DIST += tests/eolian_cxx/callback.eo \ 123EXTRA_DIST += tests/eolian_cxx/callback.eo \
124tests/eolian_cxx/simple.eo \
114tests/eolian_cxx/a.eo \ 125tests/eolian_cxx/a.eo \
115tests/eolian_cxx/b.eo \ 126tests/eolian_cxx/b.eo \
116tests/eolian_cxx/c.eo \ 127tests/eolian_cxx/c.eo \
diff --git a/src/bindings/eo_cxx/eo_private.hh b/src/bindings/eo_cxx/eo_private.hh
index a2271733b3..7640890835 100644
--- a/src/bindings/eo_cxx/eo_private.hh
+++ b/src/bindings/eo_cxx/eo_private.hh
@@ -86,6 +86,9 @@ Eo_Class const* do_eo_class_new(Eo_Class_Description& class_desc)
86 86
87template <typename T> struct operation_description_class_size; 87template <typename T> struct operation_description_class_size;
88 88
89template<>
90struct operation_description_class_size<efl::eo::base> { static const int value = 0; };
91
89/// @internal 92/// @internal
90/// 93///
91/// @brief Provides the operator to convert @p T to @p D. 94/// @brief Provides the operator to convert @p T to @p D.
@@ -130,6 +133,9 @@ namespace detail {
130/// 133///
131template <typename T> struct operations; 134template <typename T> struct operations;
132 135
136template <>
137struct operations<efl::eo::base> { template <typename T> struct type {}; };
138
133/// @internal 139/// @internal
134/// 140///
135/// @brief Provides the operations of an extension as well as its 141/// @brief Provides the operations of an extension as well as its
@@ -153,6 +159,17 @@ struct Inherit_Private_Data
153 void* this_; 159 void* this_;
154}; 160};
155 161
162} } } // namespace efl { namespace eo { namespace detail {
163
164namespace efl { namespace eo { namespace detail {
165template <typename T>
166int initialize_operation_description(efl::eo::detail::tag<efl::eo::base>
167 , Eo_Op_Description* ops)
168{
169 (void)ops;
170 return 0;
171}
172
156/// @} 173/// @}
157 174
158} } } // namespace efl { namespace eo { namespace detail { 175} } } // namespace efl { namespace eo { namespace detail {
diff --git a/src/examples/eolian_cxx/eolian_cxx_inherit_01.cc b/src/examples/eolian_cxx/eolian_cxx_inherit_01.cc
index b258f05d1c..0e6fce92f0 100644
--- a/src/examples/eolian_cxx/eolian_cxx_inherit_01.cc
+++ b/src/examples/eolian_cxx/eolian_cxx_inherit_01.cc
@@ -30,7 +30,7 @@ struct ColourableCircle
30 } 30 }
31}; 31};
32 32
33 33/*
34struct ColourableFoo 34struct ColourableFoo
35 : efl::eo::inherit<ColourableFoo, 35 : efl::eo::inherit<ColourableFoo,
36 ::colourable, 36 ::colourable,
@@ -40,6 +40,24 @@ struct ColourableFoo
40 : inherit_base(efl::eo::args<::colourable>(size) 40 : inherit_base(efl::eo::args<::colourable>(size)
41 , efl::eo::args<::colourablesquare>(rgb)) 41 , efl::eo::args<::colourablesquare>(rgb))
42 {} 42 {}
43};*/
44
45struct ColourableBar
46 : efl::eo::inherit<ColourableBar, ::colourablesquare>
47{
48 ColourableBar()
49 : inherit_base(efl::eo::args<::colourablesquare>(0))
50 {}
51
52 int colour_get()
53 {
54 int rgb = 0;
55 eo_do_super(_eo_ptr(), _eo_class(), rgb = ::colourable_colour_get());
56 std::cout << "ColourableBar::colour_get(" << this << ") ==> "
57 << std::hex << rgb << std::endl;
58 return rgb;
59 }
60
43}; 61};
44 62
45int 63int
@@ -55,6 +73,10 @@ main()
55 int r, g, b; 73 int r, g, b;
56 obj2.composite_colour_get(&r, &g, &b); 74 obj2.composite_colour_get(&r, &g, &b);
57 75
76
77 ColourableBar obj3;
78 obj3.composite_colour_get(&r, &g, &b);
79
58 assert(r == 0xc0); 80 assert(r == 0xc0);
59 assert(g == 0xff); 81 assert(g == 0xff);
60 assert(b == 0xee); 82 assert(b == 0xee);
diff --git a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
index 9ed55d4302..9e10e5067d 100644
--- a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
+++ b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
@@ -65,6 +65,12 @@ struct inheritance_operations_description
65inline std::ostream& 65inline std::ostream&
66operator<<(std::ostream& out, inheritance_operations_description const& x) 66operator<<(std::ostream& out, inheritance_operations_description const& x)
67{ 67{
68 extensions_container_type::const_iterator it, first, last;
69 std::string s;
70
71 first = x._cls.extensions.begin();
72 last = x._cls.extensions.end();
73
68 out << "template <typename T>" 74 out << "template <typename T>"
69 << endl << "int initialize_operation_description(::efl::eo::detail::tag<" 75 << endl << "int initialize_operation_description(::efl::eo::detail::tag<"
70 << full_name(x._cls) << ">" << endl 76 << full_name(x._cls) << ">" << endl
@@ -77,6 +83,24 @@ operator<<(std::ostream& out, inheritance_operations_description const& x)
77 { 83 {
78 out << inheritance_operation(x._cls, i); 84 out << inheritance_operation(x._cls, i);
79 } 85 }
86
87 out << tab(1)
88 << "initialize_operation_description<T>(efl::eo::detail::tag<"
89 << x._cls.parent
90 << ">(), &ops["
91 << x._cls.functions.size() << "]);" << endl;
92
93 s += " + operation_description_class_size<" + x._cls.parent + ">::value";
94
95 for (it = first; it != last; ++it)
96 {
97 out << tab(1)
98 << "initialize_operation_description<T>(efl::eo::detail::tag<"
99 << *it << ">(), &ops[" << x._cls.functions.size() << s << "]);" << endl;
100
101 s += " + operation_description_class_size< " + *it + ">::value";
102 }
103
80 out << tab(1) << "return 0;" << endl 104 out << tab(1) << "return 0;" << endl
81 << "}" << endl; 105 << "}" << endl;
82 106
@@ -144,18 +168,57 @@ struct inheritance_base_operations_size
144inline std::ostream& 168inline std::ostream&
145operator<<(std::ostream& out, inheritance_base_operations_size const& x) 169operator<<(std::ostream& out, inheritance_base_operations_size const& x)
146{ 170{
171 extensions_container_type::const_iterator it, first = x._cls.extensions.begin();
172 extensions_container_type::const_iterator last = x._cls.extensions.end();
173 first = x._cls.extensions.begin();
174
147 out << "template<>" 175 out << "template<>"
148 << endl << "struct operation_description_class_size< " 176 << endl << "struct operation_description_class_size< "
149 << full_name(x._cls) << " >" << endl 177 << full_name(x._cls) << " >" << endl
150 << "{" << endl 178 << "{" << endl
151 << tab(1) << "static const int value = " 179 << tab(1) << "static const int value = "
152 << x._cls.functions.size() 180 << x._cls.functions.size()
153 << ";" << endl 181 << " + operation_description_class_size<" << class_name(x._cls.parent) << ">::value";
182
183 for (it = first; it != last; ++it)
184 {
185 out << " + operation_description_class_size< " << *it << " >::value";
186 }
187
188 out << ";" << endl
154 << "};" << endl 189 << "};" << endl
155 << endl; 190 << endl;
191
156 return out; 192 return out;
157} 193}
158 194
195
196struct inheritance_base_operations_extensions
197{
198 eo_class const& _cls;
199 inheritance_base_operations_extensions(eo_class const& cls)
200 : _cls(cls)
201 {}
202};
203
204inline std::ostream&
205operator<<(std::ostream& out, inheritance_base_operations_extensions const& x)
206{
207 eo_class const& cls = x._cls;
208 extensions_container_type::const_iterator it, first = cls.extensions.begin();
209 extensions_container_type::const_iterator last = cls.extensions.end();
210
211 out << endl << tab(3) << ": operations< " << class_name(cls.parent) << " >::template type<T>";
212 for (it = first; it != last; ++it)
213 {
214 out << "," << endl << tab(3)
215 << "operations< " << *it
216 << " >::template type<T>";
217 }
218
219 return out << endl;
220}
221
159struct inheritance_base_operations_function 222struct inheritance_base_operations_function
160{ 223{
161 eo_class const& _cls; 224 eo_class const& _cls;
@@ -212,7 +275,7 @@ operator<<(std::ostream& out, inheritance_base_operations const& x)
212 << full_name(x._cls) << " >" << endl 275 << full_name(x._cls) << " >" << endl
213 << "{" << endl 276 << "{" << endl
214 << tab(1) << "template <typename T>" << endl 277 << tab(1) << "template <typename T>" << endl
215 << tab(1) << "struct type" << endl 278 << tab(1) << "struct type" << inheritance_base_operations_extensions(x._cls)
216 << tab(1) << "{" << endl; 279 << tab(1) << "{" << endl;
217 functions_container_type::const_iterator it, 280 functions_container_type::const_iterator it,
218 first = x._cls.functions.begin(), 281 first = x._cls.functions.begin(),
diff --git a/src/tests/eolian_cxx/eolian_cxx_suite.cc b/src/tests/eolian_cxx/eolian_cxx_suite.cc
index 56bc99a752..7af2de8908 100644
--- a/src/tests/eolian_cxx/eolian_cxx_suite.cc
+++ b/src/tests/eolian_cxx/eolian_cxx_suite.cc
@@ -8,6 +8,7 @@ void eolian_cxx_test_wrapper(TCase* tc);
8void eolian_cxx_test_generate(TCase* tc); 8void eolian_cxx_test_generate(TCase* tc);
9void eolian_cxx_test_callback(TCase* tc); 9void eolian_cxx_test_callback(TCase* tc);
10void eolian_cxx_test_address_of(TCase* tc); 10void eolian_cxx_test_address_of(TCase* tc);
11void eolian_cxx_test_inheritance(TCase* tc);
11 12
12typedef struct _Eolian_Cxx_Test_Case Eolian_Cxx_Test_Case; 13typedef struct _Eolian_Cxx_Test_Case Eolian_Cxx_Test_Case;
13struct _Eolian_Cxx_Test_Case 14struct _Eolian_Cxx_Test_Case
@@ -22,6 +23,7 @@ static const Eolian_Cxx_Test_Case etc[] = {
22 { "Eolian-Cxx Generation", eolian_cxx_test_generate }, 23 { "Eolian-Cxx Generation", eolian_cxx_test_generate },
23 { "Eolian-Cxx Callback", eolian_cxx_test_callback }, 24 { "Eolian-Cxx Callback", eolian_cxx_test_callback },
24 { "Eolian-Cxx Address_of", eolian_cxx_test_address_of }, 25 { "Eolian-Cxx Address_of", eolian_cxx_test_address_of },
26 { "Eolian-Cxx Inheritance", eolian_cxx_test_inheritance },
25 { NULL, NULL } 27 { NULL, NULL }
26}; 28};
27 29
diff --git a/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc b/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc
new file mode 100644
index 0000000000..1930717252
--- /dev/null
+++ b/src/tests/eolian_cxx/eolian_cxx_test_inheritance.cc
@@ -0,0 +1,44 @@
1
2#ifdef HAVE_CONFIG_H
3# include <config.h>
4#endif
5
6#include <Eo.h>
7#include <Ecore.h>
8
9#include <simple.eo.hh>
10
11#include <check.h>
12
13struct bar
14: efl::eo::inherit<bar, simple>
15{
16 bar()
17 : inherit_base()
18 {}
19
20 bool simple_get()
21 {
22 printf("calling bar::%s\n", __FUNCTION__);
23 return false;
24 }
25};
26
27void foo(simple is)
28{
29 fail_if(is.simple_get());
30}
31
32START_TEST(eolian_cxx_test_inheritance_simple)
33{
34 efl::eo::eo_init i;
35 bar b;
36 foo(b);
37}
38END_TEST
39
40void
41eolian_cxx_test_inheritance(TCase* tc)
42{
43 tcase_add_test(tc, eolian_cxx_test_inheritance_simple);
44}
diff --git a/src/tests/eolian_cxx/simple.c b/src/tests/eolian_cxx/simple.c
new file mode 100644
index 0000000000..c78073ce2d
--- /dev/null
+++ b/src/tests/eolian_cxx/simple.c
@@ -0,0 +1,38 @@
1
2#ifdef HAVE_CONFIG_H
3# include <config.h>
4#endif
5
6#include <Eo.h>
7#include <Ecore.h>
8
9#include <stdlib.h>
10
11#include "simple.eo.h"
12
13#define MY_CLASS SIMPLE_CLASS
14
15static void _simple_eo_base_constructor(Eo *obj, void *pd EINA_UNUSED)
16{
17 eo_do_super(obj, MY_CLASS, eo_constructor());
18}
19
20static Eina_Bool _simple_simple_get(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
21{
22 printf("calling %s\n", __FUNCTION__);
23
24 return EINA_TRUE;
25}
26
27static Eina_Bool _simple_name_get(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED, const char** name)
28{
29 static const char* _name= "simple_class";
30
31 printf("calling %s= simples class\n", __FUNCTION__);
32 *name = _name;
33
34 return EINA_TRUE;
35}
36
37#include "simple.eo.c"
38
diff --git a/src/tests/eolian_cxx/simple.eo b/src/tests/eolian_cxx/simple.eo
new file mode 100644
index 0000000000..764adb7856
--- /dev/null
+++ b/src/tests/eolian_cxx/simple.eo
@@ -0,0 +1,19 @@
1class Simple (Eo.Base)
2{
3 legacy_prefix: null;
4 data: null;
5 methods {
6 simple_get {
7 return bool;
8 }
9 name_get {
10 params {
11 @out const(char)* name;
12 }
13 return bool;
14 }
15 }
16 implements {
17 Eo.Base.constructor;
18 }
19}