summaryrefslogtreecommitdiff
path: root/src/bin/eolian_cxx
diff options
context:
space:
mode:
authorSavio Sena <savio@expertisesolutions.com.br>2014-07-16 21:29:47 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-07-18 18:57:13 -0300
commit78e396ac19b203b0dbfb1a2b8d298177fffde9e4 (patch)
tree8281622f4881cf40a65167e3fa3e99d22f4563b3 /src/bin/eolian_cxx
parent88f12935278c9d3547da96b74e525402e2efd3f0 (diff)
eolian-cxx: Initial version of complex types / callbacks / events implementation.
Diffstat (limited to 'src/bin/eolian_cxx')
-rw-r--r--src/bin/eolian_cxx/convert.cc2
-rw-r--r--src/bin/eolian_cxx/eolian_wrappers.hh19
-rw-r--r--src/bin/eolian_cxx/type_lookup.hh48
-rw-r--r--src/bin/eolian_cxx/type_lookup_table.cc31
4 files changed, 84 insertions, 16 deletions
diff --git a/src/bin/eolian_cxx/convert.cc b/src/bin/eolian_cxx/convert.cc
index 873068dac2..f52affa7db 100644
--- a/src/bin/eolian_cxx/convert.cc
+++ b/src/bin/eolian_cxx/convert.cc
@@ -116,7 +116,7 @@ convert_eolian_property_to_functions(Eolian_Class const& klass)
116 { 116 {
117 efl::eolian::eolian_type getter_param_type = 117 efl::eolian::eolian_type getter_param_type =
118 type_to_native(param.type); 118 type_to_native(param.type);
119 getter_param_type/*.native*/ += "*"; // XXX implement complex types 119 getter_param_type.native += "*";
120 return efl::eolian::eo_parameter 120 return efl::eolian::eo_parameter
121 { { getter_param_type }, param.name }; 121 { { getter_param_type }, param.name };
122 }); 122 });
diff --git a/src/bin/eolian_cxx/eolian_wrappers.hh b/src/bin/eolian_cxx/eolian_wrappers.hh
index e9a9ab99d6..79544286c6 100644
--- a/src/bin/eolian_cxx/eolian_wrappers.hh
+++ b/src/bin/eolian_cxx/eolian_wrappers.hh
@@ -180,8 +180,7 @@ function_type(Eolian_Function const& func)
180inline efl::eolian::eolian_type_instance 180inline efl::eolian::eolian_type_instance
181function_return_type(Eolian_Function const& func, Eolian_Function_Type func_type = method_t::value) 181function_return_type(Eolian_Function const& func, Eolian_Function_Type func_type = method_t::value)
182{ 182{
183 return type_lookup 183 return type_lookup(::eolian_function_return_type_get(&func, func_type));
184 (::eolian_function_return_type_get(&func, func_type));
185} 184}
186 185
187inline efl::eolian::eolian_type_instance 186inline efl::eolian::eolian_type_instance
@@ -286,11 +285,17 @@ parameter_type(Eolian_Function_Parameter const& parameter,
286 efl::eolian::eolian_type_instance type 285 efl::eolian::eolian_type_instance type
287 (type_lookup(::eolian_parameter_type_get(&parameter))); 286 (type_lookup(::eolian_parameter_type_get(&parameter)));
288 assert(!type.empty()); 287 assert(!type.empty());
289 // XXX implement complex types.
290 if (parameter_is_out(parameter)) 288 if (parameter_is_out(parameter))
291 type = { type_to_native(type) + "*" }; 289 {
290 type = { efl::eolian::type_to_native(type) };
291 type.front().native += "*";
292 }
292 if (parameter_is_const(parameter, func_type)) 293 if (parameter_is_const(parameter, func_type))
293 type.insert(0, "const "); 294 {
295 type[0].native.insert(0, "const ");
296 if (!type[0].binding.empty())
297 type[0].binding.insert(0, "const ");
298 }
294 return type; 299 return type;
295} 300}
296 301
@@ -311,7 +316,9 @@ event_create(Eolian_Class const& klass, const Eolian_Event *event_)
311{ 316{
312 efl::eolian::eo_event event; 317 efl::eolian::eo_event event;
313 const char *name, *comment; 318 const char *name, *comment;
314 if(::eolian_class_event_information_get(event_, &name, NULL, &comment)) 319 const Eolian_Type *type;
320 static_cast<void>(type); // XXX
321 if(::eolian_class_event_information_get(event_, &name, &type, &comment))
315 { 322 {
316 std::string name_ = safe_str(name); 323 std::string name_ = safe_str(name);
317 std::transform(name_.begin(), name_.end(), name_.begin(), 324 std::transform(name_.begin(), name_.end(), name_.begin(),
diff --git a/src/bin/eolian_cxx/type_lookup.hh b/src/bin/eolian_cxx/type_lookup.hh
index 4ac5057981..b5c7cfa144 100644
--- a/src/bin/eolian_cxx/type_lookup.hh
+++ b/src/bin/eolian_cxx/type_lookup.hh
@@ -12,6 +12,8 @@
12#include <cstddef> 12#include <cstddef>
13 13
14#include <Eolian.h> 14#include <Eolian.h>
15#include <eolian_database.h>
16
15#include <Eina.hh> 17#include <Eina.hh>
16 18
17#include "eo_types.hh" 19#include "eo_types.hh"
@@ -19,18 +21,46 @@
19 21
20namespace eolian_cxx { 22namespace eolian_cxx {
21 23
22inline std::string 24typedef std::vector<efl::eolian::eolian_type> lookup_table_type;
23type_lookup(const Eolian_Type *type) 25extern const lookup_table_type type_lookup_table;
26
27inline efl::eolian::eolian_type
28type_from_eolian(Eolian_Type const& type)
24{ 29{
25 if (type == NULL) 30 efl::eolian::eolian_type x;
26 return "void"; 31 x.native = normalize_spaces(safe_str(type.name));
27 // XXX add complex types implementation. 32 x.is_own = type.is_own;
28 const char *tps = eolian_type_c_type_get(type); 33 return x;
29 std::string ret = safe_str(tps);
30 ::eina_stringshare_del(tps);
31 return ret;
32} 34}
33 35
36template <typename Iterator>
37inline const efl::eolian::eolian_type&
38type_find(Iterator first, Iterator last, efl::eolian::eolian_type const& type)
39{
40 auto res = std::find_if
41 (first, last,
42 [&type] (efl::eolian::eolian_type const& x)
43 {
44 return (x.native == type.native && x.is_own == type.is_own);
45 });
46 return (res != last) ? *res : type;
47}
48
49inline efl::eolian::eolian_type_instance
50type_lookup(const Eolian_Type* type,
51 lookup_table_type const& lut = type_lookup_table)
52{
53 if (type == NULL) return { efl::eolian::void_type };
54 size_t n = ::eina_list_count(type->subtypes) + 1;
55 assert(n > 0);
56 efl::eolian::eolian_type_instance v(n);
57 for (size_t i=0; i<n; i++)
58 {
59 v[i] = type_find(lut.begin(), lut.end(), type_from_eolian(*type));
60 assert (i == n-1 || type_is_complex(v[i]));
61 }
62 return v;
63}
34 64
35} // namespace eolian_cxx { 65} // namespace eolian_cxx {
36 66
diff --git a/src/bin/eolian_cxx/type_lookup_table.cc b/src/bin/eolian_cxx/type_lookup_table.cc
new file mode 100644
index 0000000000..072ef22748
--- /dev/null
+++ b/src/bin/eolian_cxx/type_lookup_table.cc
@@ -0,0 +1,31 @@
1#include "type_lookup.hh"
2
3namespace eolian_cxx {
4
5using efl::eolian::eolian_type;
6
7// Keep the table sorted!
8// This can help: cat type_lookup_table | LC_ALL=C sort
9const lookup_table_type
10type_lookup_table
11{
12 {"Ecore_Cb", eolian_type::callback_, {"Ecore.h"}},
13 {"Ecore_Task_Cb", eolian_type::callback_, {"Ecore.h"}},
14 {"Ecore_Timeline_Cb", eolian_type::callback_, {"Ecore.h"}},
15 {"Eina_Accessor *", eolian_type::complex_, false, "efl::eina::accessor", {"eina-cxx/eina_accessor.hh"}},
16 {"Eina_Bool", eolian_type::simple_, false, "bool", {}},
17 {"Eina_Inlist *", eolian_type::complex_, false, "efl::eina::range_inlist", {"eina-cxx/eina_inlist.hh"}},
18 {"Eina_Inlist *", eolian_type::complex_, true, "efl::eina::inlist", {"eina-cxx/eina_inlist.hh"}},
19 {"Eina_Iterator *", eolian_type::complex_, false, "efl::eina::iterator", {"eina-cxx/eina_iterator.hh"}},
20 {"Eina_List *", eolian_type::complex_, false, "efl::eina::range_ptr_list", {"eina-cxx/eina_ptrlist.hh"}},
21 {"Eina_List *", eolian_type::complex_, true, "efl::eina::ptr_list", {"eina-cxx/eina_ptrlist.hh"}},
22 //{"Eina_List *", eolian_type::complex_, false, "efl::eina::ptr_list", {"eina-cxx/eina_ptrlist.hh"}},
23 {"Eo *", eolian_type::simple_, true, "efl::eo::base", {"eo_base.hh"}},
24 {"Evas_Object *", eolian_type::simple_, false, "evas_object", {"canvas/evas_object.eo.hh"}},
25 {"char *", eolian_type::simple_, true, "std::unique_ptr<char*>", {"memory"}},
26 {"const Eina_Inlist *", eolian_type::complex_, false, "efl::eina::range_inlist", {"eina-cxx/eina_inlist.hh"}},
27 {"const Eina_List *", eolian_type::complex_, false, "efl::eina::range_ptr_list", {"eina-cxx/eina_ptrlist.hh"}},
28 {"const char *", eolian_type::simple_, false, "std::string", {"string"}}
29};
30
31}