summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2015-01-12 12:00:59 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-04-14 01:06:57 -0300
commitd53038989886a85b75c81a395269f6f349d7d78f (patch)
treed21410341bfd403ccc503a928687b304a734e9d5 /src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
parentbe58d02cb655c244a659abbcdb9ab44e8a5459ce (diff)
eolian_cxx: Add protected methods and events to C++ wrappers and fixes
Using eina::string_view in eolian generated interfaces (instead of std::string) to allow lightweight passing of both C strings and C++ std::string. Also, No longer using eina::optional in generated headers for types that already implements the concept of null state (like Eo wrappers and eina_accessor). Also fix allocating callback objects require by class methods (i.e. static) in static vectors so the memory will be freed when the programs exit. Added a new test case for testing callbacks on class methods. Moved method definitions and supplementary code from generated C++ wrappers to auxiliary header file (.eo.impl.hh) generated together with the main ".eo.hh" file. Updated Makefiles to list such files in the compilation and cleanup processes. Updated .gitignore to include these new generated files. Made general adjustments on the documentation of generated C++ wrappers Added "PREDEFINED" preprocessor macro definition in the Doxyfile.in in order to make some adjustments for better documentation in the C++ generated headers. Excluding generation of documentation for classes in the "eo_cxx" namespace (the namespace for "abstract" eolian C++ wrappers). Now generating the documentation for the events too. Hiding some auxiliary code from being documented. Some aesthetic adjustments for generated white space. Generate documentation for the main constructor of C++ wrappers and added auxiliary grammars to list parameters names.
Diffstat (limited to 'src/lib/eolian_cxx/grammar/inheritance_base_generator.hh')
-rw-r--r--src/lib/eolian_cxx/grammar/inheritance_base_generator.hh73
1 files changed, 58 insertions, 15 deletions
diff --git a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
index 38382d5092..11b8f2a29e 100644
--- a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
+++ b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh
@@ -30,9 +30,10 @@ _ns_as_prefix(eo_class const& cls)
30struct inheritance_operation 30struct inheritance_operation
31{ 31{
32 eo_class const& _cls; 32 eo_class const& _cls;
33 eo_function const& _func;
33 functions_container_type::size_type _idx; 34 functions_container_type::size_type _idx;
34 inheritance_operation(eo_class const& cls, functions_container_type::size_type idx) 35 inheritance_operation(eo_class const& cls, eo_function const& func, functions_container_type::size_type idx)
35 : _cls(cls), _idx(idx) 36 : _cls(cls), _func(func), _idx(idx)
36 {} 37 {}
37}; 38};
38 39
@@ -40,7 +41,7 @@ inline std::ostream&
40operator<<(std::ostream& out, inheritance_operation const& x) 41operator<<(std::ostream& out, inheritance_operation const& x)
41{ 42{
42 assert(x._idx < x._cls.functions.size()); 43 assert(x._idx < x._cls.functions.size());
43 eo_function const& func = x._cls.functions[x._idx]; 44 eo_function const& func = x._func;
44 out << tab(1) 45 out << tab(1)
45 << "ops[" << x._idx << "].func = reinterpret_cast<void*>(& ::" 46 << "ops[" << x._idx << "].func = reinterpret_cast<void*>(& ::"
46 << _ns_as_prefix(x._cls) << "_" 47 << _ns_as_prefix(x._cls) << "_"
@@ -74,17 +75,30 @@ operator<<(std::ostream& out, inheritance_operations_description const& x)
74 << ", Eo_Op_Description* ops)" << endl 75 << ", Eo_Op_Description* ops)" << endl
75 << "{" << endl 76 << "{" << endl
76 << tab(1) << "(void)ops;" << endl; 77 << tab(1) << "(void)ops;" << endl;
77 functions_container_type::size_type n_ops = x._cls.functions.size(); 78
78 for (functions_container_type::size_type i=0; i < n_ops; ++i) 79 auto funcs = x._cls.functions;
80 auto part = std::stable_partition(funcs.begin(), funcs.end(), [](eo_function const& f){ return f.scope == eolian_scope::public_; });
81
82 functions_container_type::size_type op_idx = 0;
83 for (auto it = funcs.begin(); it != part; ++it, ++op_idx)
79 { 84 {
80 out << inheritance_operation(x._cls, i); 85 out << inheritance_operation(x._cls, *it, op_idx);
86 }
87
88 if (part != funcs.end())
89 {
90 out << scope_guard_head(x._cls, *part);
91 for (auto it = part; it != funcs.end(); ++it, ++op_idx)
92 out << inheritance_operation(x._cls, *it, op_idx);
93 out << scope_guard_tail(x._cls, *part);
81 } 94 }
82 95
83 for (std::string const& parent : x._cls.parents) 96 for (std::string const& parent : x._cls.parents)
84 { 97 {
85 out << tab(1) 98 out << tab(1)
86 << "initialize_operation_description<T>(::efl::eo::detail::tag<::" 99 << "initialize_operation_description<T>(::efl::eo::detail::tag<::"
87 << parent << ">(), &ops[" << x._cls.functions.size() << s << "]);" << endl; 100 << parent << ">(), &ops[operation_description_class_size< "
101 << full_name(x._cls) << " >::value" << s << "]);" << endl;
88 102
89 s += " + operation_description_class_size<::" + parent + ">::value"; 103 s += " + operation_description_class_size<::" + parent + ">::value";
90 } 104 }
@@ -110,6 +124,9 @@ operator<<(std::ostream& out, inheritance_wrappers const& x)
110 for (it = first; it != last; ++it) 124 for (it = first; it != last; ++it)
111 { 125 {
112 eo_function const& func = *it; 126 eo_function const& func = *it;
127
128 out << scope_guard_head(x._cls, func);
129
113 out << "template <typename T>" << endl 130 out << "template <typename T>" << endl
114 << reinterpret_type(func.ret) << " " 131 << reinterpret_type(func.ret) << " "
115 << _ns_as_prefix(x._cls) << "_" 132 << _ns_as_prefix(x._cls) << "_"
@@ -140,7 +157,9 @@ operator<<(std::ostream& out, inheritance_wrappers const& x)
140 if (!function_is_void(func)) 157 if (!function_is_void(func))
141 out << tab(1) << "return _tmp_ret;" << endl; 158 out << tab(1) << "return _tmp_ret;" << endl;
142 159
143 out << "}" << endl << endl; 160 out << "}" << endl;
161
162 out << scope_guard_tail(x._cls, func) << endl;
144 } 163 }
145 return out; 164 return out;
146} 165}
@@ -148,8 +167,9 @@ operator<<(std::ostream& out, inheritance_wrappers const& x)
148struct inheritance_base_operations_size 167struct inheritance_base_operations_size
149{ 168{
150 eo_class const& _cls; 169 eo_class const& _cls;
151 inheritance_base_operations_size(eo_class const& cls) 170 functions_container_type const& _funcs;
152 : _cls(cls) 171 inheritance_base_operations_size(eo_class const& cls, functions_container_type const& funcs)
172 : _cls(cls), _funcs(funcs)
153 {} 173 {}
154}; 174};
155 175
@@ -160,8 +180,8 @@ operator<<(std::ostream& out, inheritance_base_operations_size const& x)
160 << endl << "struct operation_description_class_size< " 180 << endl << "struct operation_description_class_size< "
161 << full_name(x._cls) << " >" << endl 181 << full_name(x._cls) << " >" << endl
162 << "{" << endl 182 << "{" << endl
163 << tab(1) << "static const int value = " 183 << tab(1) << "static constexpr int value = "
164 << x._cls.functions.size(); 184 << x._funcs.size();
165 185
166 for (std::string const& parent : x._cls.parents) 186 for (std::string const& parent : x._cls.parents)
167 { 187 {
@@ -175,6 +195,27 @@ operator<<(std::ostream& out, inheritance_base_operations_size const& x)
175 return out; 195 return out;
176} 196}
177 197
198struct inheritance_base_operations_size_scopes
199{
200 eo_class const& _cls;
201 inheritance_base_operations_size_scopes(eo_class const& cls)
202 : _cls(cls)
203 {}
204};
205
206inline std::ostream&
207operator<<(std::ostream& out, inheritance_base_operations_size_scopes const& x)
208{
209 auto funcs = x._cls.functions;
210 auto part = std::stable_partition(funcs.begin(), funcs.end(), [](eo_function const& f){ return f.scope == eolian_scope::public_; });
211
212 out << "#ifdef " << name_upper(x._cls) << "_PROTECTED" << endl
213 << inheritance_base_operations_size(x._cls, funcs)
214 << "#else" << endl
215 << inheritance_base_operations_size(x._cls, {funcs.begin(), part})
216 << "#endif" << endl << endl;
217 return out;
218}
178 219
179struct inheritance_base_operations_extensions 220struct inheritance_base_operations_extensions
180{ 221{
@@ -230,7 +271,7 @@ operator<<(std::ostream& out, inheritance_base_operations_function const& x)
230 if (!is_void) 271 if (!is_void)
231 out << tab(3) << func.ret.front().native << " _tmp_ret = {};" << endl; 272 out << tab(3) << func.ret.front().native << " _tmp_ret = {};" << endl;
232 273
233 out << callbacks_heap_alloc("dynamic_cast<T*>(this)->_eo_ptr()", func.params, 3) 274 out << callbacks_heap_alloc("dynamic_cast<T*>(this)->_eo_ptr()", func.params, function_is_static(x._func), 3)
234 << endl; 275 << endl;
235 276
236 out << tab(3) 277 out << tab(3)
@@ -241,7 +282,7 @@ operator<<(std::ostream& out, inheritance_base_operations_function const& x)
241 if (!is_void) 282 if (!is_void)
242 out << tab(4) << "return " << to_cxx(func.ret, "_tmp_ret") << ";" << endl; 283 out << tab(4) << "return " << to_cxx(func.ret, "_tmp_ret") << ";" << endl;
243 284
244 return out << tab(2) << "}" << endl << endl; 285 return out << tab(2) << "}" << endl;
245} 286}
246 287
247struct inheritance_base_operations 288struct inheritance_base_operations
@@ -265,7 +306,9 @@ operator<<(std::ostream& out, inheritance_base_operations const& x)
265 last = x._cls.functions.end(); 306 last = x._cls.functions.end();
266 for (it = first; it != last; ++it) 307 for (it = first; it != last; ++it)
267 { 308 {
309 out << scope_guard_head(x._cls, *it);
268 out << inheritance_base_operations_function(x._cls, *it); 310 out << inheritance_base_operations_function(x._cls, *it);
311 out << scope_guard_tail(x._cls, *it) << endl;
269 } 312 }
270 out << tab(1) << "};" << endl 313 out << tab(1) << "};" << endl
271 << "};" << endl << endl; 314 << "};" << endl << endl;
@@ -365,7 +408,7 @@ eo_inheritance_detail_generator(std::ostream& out, eo_class const& cls)
365 out << inheritance_wrappers(cls) 408 out << inheritance_wrappers(cls)
366 << "namespace efl { namespace eo { namespace detail {" << endl << endl 409 << "namespace efl { namespace eo { namespace detail {" << endl << endl
367 << inheritance_base_operations(cls) << endl 410 << inheritance_base_operations(cls) << endl
368 << inheritance_base_operations_size(cls) 411 << inheritance_base_operations_size_scopes(cls)
369 << inheritance_operations_description(cls) 412 << inheritance_operations_description(cls)
370 << inheritance_call_constructors(cls) 413 << inheritance_call_constructors(cls)
371 << inheritance_eo_class_getter(cls) 414 << inheritance_eo_class_getter(cls)