summaryrefslogtreecommitdiff
path: root/src/bin/eolian_cxx
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2014-12-17 11:47:19 -0200
committerVitor Sousa <vitorsousasilva@gmail.com>2015-01-05 15:52:27 -0200
commited75aa32d6ccdea66a952ed5c82203b0cd1961b2 (patch)
tree3fb61da2424b4443c525adb2ee4e483df8617146 /src/bin/eolian_cxx
parentebebcf64389d4e362ee9efaaf8aad4a1e76149e4 (diff)
cxx: General C++ Eo wrapper generation improvement
Using a new architecture in the generated files that simplify multiple inheritance and allows the use of interface types as parameters. No longer using a hand-crafted C++ header for eo_base.eo. This file was added to the generation process. Updated all files that are dependent in the hand-crafted eo_base C++ header. Now there is a class that contains the essentials functions of the former eo::base wrapper and that is used to create (through inheritance) the "concrete" classes for all Eo generated wrappers. No longer binding any function or property that are protected, private or legacy for now. eolian_type_instance is now a struct with general information for the whole type. Added the new header file namespace_generator.hh to hold namespace generation grammars. Separated declaration and definition of Eo wrappers methods. Referring for most objects by its full name (starting at the global namespace ::) in the generated files. Created additional helper grammars to avoid code replication. Removed a TODO comment referring to a doubt about inheritance of constructor methods. Added a TODO comment regarding memory allocation for callbacks in static member functions.
Diffstat (limited to 'src/bin/eolian_cxx')
-rw-r--r--src/bin/eolian_cxx/convert.cc69
-rw-r--r--src/bin/eolian_cxx/eolian_cxx.cc9
-rw-r--r--src/bin/eolian_cxx/eolian_wrappers.hh8
-rw-r--r--src/bin/eolian_cxx/type_lookup.hh6
-rw-r--r--src/bin/eolian_cxx/type_lookup_table.cc34
5 files changed, 72 insertions, 54 deletions
diff --git a/src/bin/eolian_cxx/convert.cc b/src/bin/eolian_cxx/convert.cc
index acb2c78a1e..8f5cec8927 100644
--- a/src/bin/eolian_cxx/convert.cc
+++ b/src/bin/eolian_cxx/convert.cc
@@ -22,6 +22,34 @@ namespace eolian_cxx {
22 22
23extern efl::eina::log_domain domain; 23extern efl::eina::log_domain domain;
24 24
25void
26remove_repeated_base(const char* klass_name, efl::eolian::parents_container_type& cont)
27{
28 Eolian_Class const* klass = ::eolian_class_get_by_name(klass_name);
29 if (!klass)
30 {
31 std::cerr << "Error: could not get eolian class name `" << klass_name << "'" << std::endl;
32 return;
33 }
34
35 Eina_Iterator* inheritances = ::eolian_class_inherits_get(klass);
36 void* curr = 0;
37
38 EINA_ITERATOR_FOREACH(inheritances, curr)
39 {
40 if (!curr)
41 continue;
42
43 const char* parent = static_cast<const char*>(curr);
44 cont.erase(
45 std::remove(cont.begin(), cont.end(), safe_lower(class_format_cxx(parent)))
46 , cont.end());
47
48 remove_repeated_base(parent, cont);
49 }
50 eina_iterator_free(inheritances);
51}
52
25static efl::eolian::parameters_container_type 53static efl::eolian::parameters_container_type
26_convert_eolian_parameters(Eina_Iterator *parameters, 54_convert_eolian_parameters(Eina_Iterator *parameters,
27 Eolian_Function_Type func_type) 55 Eolian_Function_Type func_type)
@@ -148,13 +176,6 @@ _convert_property_get_to_function(Eolian_Class const& klass,
148 return get_; 176 return get_;
149} 177}
150 178
151static std::string
152_convert_class_name(std::string const& name)
153{
154 return (name == "eo_base" || name == "eo::base" || name == "")
155 ? "efl::eo::base"
156 : name;
157}
158 179
159void 180void
160convert_eolian_inheritances(efl::eolian::eo_class& cls, Eolian_Class const& klass) 181convert_eolian_inheritances(efl::eolian::eo_class& cls, Eolian_Class const& klass)
@@ -163,23 +184,21 @@ convert_eolian_inheritances(efl::eolian::eo_class& cls, Eolian_Class const& klas
163 ::eolian_class_inherits_get(&klass); 184 ::eolian_class_inherits_get(&klass);
164 void *curr; 185 void *curr;
165 186
166 if (!eina_iterator_next(inheritances, &curr) || !curr) 187 EINA_ITERATOR_FOREACH(inheritances, curr)
167 { 188 {
168 cls.parent = "efl::eo::base"; 189 std::string parent = safe_lower(static_cast<const char*>(curr));
169 eina_iterator_free(inheritances); 190 cls.parents.push_back(class_format_cxx(parent));
170 return;
171 } 191 }
172 else 192 eina_iterator_free(inheritances);
193
194 if (cls.parents.empty())
195 return;
196
197 inheritances = ::eolian_class_inherits_get(&klass);
198 EINA_ITERATOR_FOREACH(inheritances, curr)
173 { 199 {
174 // First element is the parent 200 if (curr)
175 const char *ptr = static_cast<const char*>(curr); 201 remove_repeated_base(static_cast<const char*>(curr), cls.parents);
176 cls.parent = _convert_class_name(class_format_cxx(safe_lower(ptr)));
177
178 EINA_ITERATOR_FOREACH(inheritances, curr)
179 {
180 std::string extension = safe_lower(static_cast<const char*>(curr));
181 cls.extensions.push_back(_convert_class_name(class_format_cxx(extension)));
182 }
183 } 202 }
184 eina_iterator_free(inheritances); 203 eina_iterator_free(inheritances);
185} 204}
@@ -213,6 +232,9 @@ convert_eolian_functions(efl::eolian::eo_class& cls, Eolian_Class const& klass)
213 Eolian_Function const& func = *first; 232 Eolian_Function const& func = *first;
214 Eolian_Function_Type const func_type = function_op_type(func); 233 Eolian_Function_Type const func_type = function_op_type(func);
215 234
235 if (!function_is_visible(func, func_type))
236 continue;
237
216 if (function_is_constructor(klass, func)) 238 if (function_is_constructor(klass, func))
217 { 239 {
218 cls.constructors.push_back({ 240 cls.constructors.push_back({
@@ -221,7 +243,7 @@ convert_eolian_functions(efl::eolian::eo_class& cls, Eolian_Class const& klass)
221 convert_comments_function(klass, func) 243 convert_comments_function(klass, func)
222 }); 244 });
223 } 245 }
224 else if (function_is_visible(func, func_type)) 246 else
225 { 247 {
226 cls.functions.push_back({ 248 cls.functions.push_back({
227 function_type(func), 249 function_type(func),
@@ -239,6 +261,9 @@ convert_eolian_functions(efl::eolian::eo_class& cls, Eolian_Class const& klass)
239 Eolian_Function const& func = *first; 261 Eolian_Function const& func = *first;
240 Eolian_Function_Type t = ::eolian_function_type_get(&func); 262 Eolian_Function_Type t = ::eolian_function_type_get(&func);
241 263
264 if (!function_is_visible(func, t))
265 continue;
266
242 if(t == EOLIAN_PROP_GET) 267 if(t == EOLIAN_PROP_GET)
243 { 268 {
244 cls.functions.push_back 269 cls.functions.push_back
diff --git a/src/bin/eolian_cxx/eolian_cxx.cc b/src/bin/eolian_cxx/eolian_cxx.cc
index 5aa477edf0..93e9e442ab 100644
--- a/src/bin/eolian_cxx/eolian_cxx.cc
+++ b/src/bin/eolian_cxx/eolian_cxx.cc
@@ -101,14 +101,7 @@ generator_options(const Eolian_Class& klass)
101 std::string eo_parent_file = class_base_file(*ext); 101 std::string eo_parent_file = class_base_file(*ext);
102 if (!eo_parent_file.empty()) 102 if (!eo_parent_file.empty())
103 { 103 {
104 // we have our own eo_base.hh 104 gen_opts.cxx_headers.push_back(eo_parent_file + ".hh");
105 std::string eo_base_eo = "eo_base.eo";
106 if (eo_parent_file.length() < eo_base_eo.length() ||
107 !std::equal(eo_base_eo.begin(), eo_base_eo.end(),
108 eo_parent_file.end() - eo_base_eo.length()))
109 {
110 gen_opts.cxx_headers.push_back(eo_parent_file + ".hh");
111 }
112 } 105 }
113 else 106 else
114 { 107 {
diff --git a/src/bin/eolian_cxx/eolian_wrappers.hh b/src/bin/eolian_cxx/eolian_wrappers.hh
index d56379393f..6b0211e798 100644
--- a/src/bin/eolian_cxx/eolian_wrappers.hh
+++ b/src/bin/eolian_cxx/eolian_wrappers.hh
@@ -350,14 +350,14 @@ parameter_type(Eolian_Function_Parameter const& parameter,
350 { 350 {
351 if (type.front().native == "char *") 351 if (type.front().native == "char *")
352 type = { efl::eolian::type_to_native(type) }; 352 type = { efl::eolian::type_to_native(type) };
353 type.front().is_out = true; 353 type.is_out = true;
354 type.front().native += "*"; 354 type.front().native += "*";
355 } 355 }
356 if (parameter_is_const(parameter, func_type)) 356 if (parameter_is_const(parameter, func_type))
357 { 357 {
358 type[0].native.insert(0, "const "); 358 type.front().native.insert(0, "const ");
359 if (!type[0].binding.empty()) 359 if (!type.front().binding.empty())
360 type[0].binding.insert(0, "const "); 360 type.front().binding.insert(0, "const ");
361 } 361 }
362 return type; 362 return type;
363} 363}
diff --git a/src/bin/eolian_cxx/type_lookup.hh b/src/bin/eolian_cxx/type_lookup.hh
index 1b64bbb20b..f7be16e857 100644
--- a/src/bin/eolian_cxx/type_lookup.hh
+++ b/src/bin/eolian_cxx/type_lookup.hh
@@ -77,14 +77,14 @@ type_lookup(const Eolian_Type* type,
77 efl::eolian::eolian_type_instance v(types.size()); 77 efl::eolian::eolian_type_instance v(types.size());
78 for (std::size_t i = 0; i != types.size(); ++i) 78 for (std::size_t i = 0; i != types.size(); ++i)
79 { 79 {
80 v[i] = type_find(lut.begin(), lut.end(), type_from_eolian(*types[i])); 80 v.parts[i] = type_find(lut.begin(), lut.end(), type_from_eolian(*types[i]));
81 } 81 }
82 82
83 // Let's degrade to opaque classes when not enough information 83 // Let's degrade to opaque classes when not enough information
84 // is available for complex types 84 // is available for complex types
85 if(v.size() == 1 && type_is_complex(v[0])) 85 if(v.parts.size() == 1 && type_is_complex(v.front()))
86 { 86 {
87 efl::eolian::eolian_type tmp = v[0]; 87 efl::eolian::eolian_type tmp = v.front();
88 return {efl::eolian::type_to_native(tmp)}; 88 return {efl::eolian::type_to_native(tmp)};
89 } 89 }
90 90
diff --git a/src/bin/eolian_cxx/type_lookup_table.cc b/src/bin/eolian_cxx/type_lookup_table.cc
index d4e7c1e9d6..7fa085e9ba 100644
--- a/src/bin/eolian_cxx/type_lookup_table.cc
+++ b/src/bin/eolian_cxx/type_lookup_table.cc
@@ -13,25 +13,25 @@ type_lookup_table
13 {"Ecore_Task_Cb", eolian_type::callback_, {"Ecore.h"}}, 13 {"Ecore_Task_Cb", eolian_type::callback_, {"Ecore.h"}},
14 {"Ecore_Timeline_Cb", eolian_type::callback_, {"Ecore.h"}}, 14 {"Ecore_Timeline_Cb", eolian_type::callback_, {"Ecore.h"}},
15 {"Edje_Signal_Cb", eolian_type::callback_, {"Edje.h"}}, 15 {"Edje_Signal_Cb", eolian_type::callback_, {"Edje.h"}},
16 {"Eina_Accessor *", eolian_type::complex_, false, false, "efl::eina::accessor", {"eina-cxx/eina_accessor.hh"}}, 16 {"Eina_Accessor *", eolian_type::complex_, false, false, true, "::efl::eina::accessor", {"eina-cxx/eina_accessor.hh"}},
17 {"Eina_Bool", eolian_type::simple_, false, false, "bool", {}}, 17 {"Eina_Bool", eolian_type::simple_, false, false, false, "bool", {}},
18 {"Eina_Bool *", eolian_type::simple_, false, false, "bool*", {}}, 18 {"Eina_Bool *", eolian_type::simple_, false, false, false, "bool*", {}},
19 {"Eina_Inlist *", eolian_type::complex_, false, false, "efl::eina::range_inlist", {"eina-cxx/eina_inlist.hh"}}, 19 {"Eina_Inlist *", eolian_type::complex_, false, false, true, "::efl::eina::range_inlist", {"eina-cxx/eina_inlist.hh"}},
20 {"Eina_Inlist *", eolian_type::complex_, false, true, "efl::eina::inlist", {"eina-cxx/eina_inlist.hh"}}, 20 {"Eina_Inlist *", eolian_type::complex_, false, true, true, "::efl::eina::inlist", {"eina-cxx/eina_inlist.hh"}},
21 {"Eina_Iterator *", eolian_type::complex_, false, false, "efl::eina::iterator", {"eina-cxx/eina_iterator.hh"}}, 21 {"Eina_Iterator *", eolian_type::complex_, false, false, true, "::efl::eina::iterator", {"eina-cxx/eina_iterator.hh"}},
22 {"Eina_List *", eolian_type::complex_, false, false, "efl::eina::range_list", {"eina-cxx/eina_list.hh"}}, 22 {"Eina_List *", eolian_type::complex_, false, false, true, "::efl::eina::range_list", {"eina-cxx/eina_list.hh"}},
23 {"Eina_List *", eolian_type::complex_, false, true, "efl::eina::list", {"eina-cxx/eina_list.hh"}}, 23 {"Eina_List *", eolian_type::complex_, false, true, true, "::efl::eina::list", {"eina-cxx/eina_list.hh"}},
24 {"const Eina_List *", eolian_type::complex_, true, false, "efl::eina::crange_list", {"eina-cxx/eina_list.hh"}}, 24 {"const Eina_List *", eolian_type::complex_, true, false, true, "::efl::eina::crange_list", {"eina-cxx/eina_list.hh"}},
25 {"Eio_Filter_Direct_Cb", eolian_type::callback_, {"Eio.h"}}, 25 {"Eio_Filter_Direct_Cb", eolian_type::callback_, {"Eio.h"}},
26 {"Emodel *", eolian_type::simple_, false, false, "emodel", {"Emodel.hh"}}, 26 {"Emodel *", eolian_type::simple_, false, false, true, "::emodel", {"Emodel.hh"}},
27 {"Eo *", eolian_type::simple_, false, true, "efl::eo::base", {"eo_base.hh"}}, 27 {"Eo *", eolian_type::simple_, false, true, true, "::efl::eo::concrete", {"eo_concrete.hh"}},
28 {"Eo *", eolian_type::simple_, false, false, "efl::eo::base", {"eo_base.hh"}}, 28 {"Eo *", eolian_type::simple_, false, false, true, "::efl::eo::concrete", {"eo_concrete.hh"}},
29 //{"Evas_Object_Box_Layout", eolian_type::callback_, {"Evas.h"}}, 29 //{"Evas_Object_Box_Layout", eolian_type::callback_, {"Evas.h"}},
30 {"Evas_Object *", eolian_type::simple_, false, false, "evas::object", {"canvas/evas_object.eo.hh"}}, 30 {"Evas_Object *", eolian_type::simple_, false, false, true, "::evas::object", {"canvas/evas_object.eo.hh"}},
31 {"char *", eolian_type::simple_, false, true, "std::unique_ptr<char*>", {"memory"}}, 31 {"char *", eolian_type::simple_, false, true, true, "std::unique_ptr<char*>", {"memory"}},
32 {"const Eina_Inlist *", eolian_type::complex_, false, false, "efl::eina::range_inlist", {"eina-cxx/eina_inlist.hh"}}, 32 {"const Eina_Inlist *", eolian_type::complex_, false, false, true, "::efl::eina::range_inlist", {"eina-cxx/eina_inlist.hh"}},
33 {"const Eina_List *", eolian_type::complex_, false, false, "efl::eina::range_list", {"eina-cxx/eina_ptrlist.hh"}}, 33 {"const Eina_List *", eolian_type::complex_, false, false, true, "::efl::eina::range_list", {"eina-cxx/eina_ptrlist.hh"}},
34 {"const char *", eolian_type::simple_, false, false, "std::string", {"string"}}, 34 {"const char *", eolian_type::simple_, false, false, true, "std::string", {"string"}},
35}; 35};
36 36
37} 37}