From fb82d67ab13b12534468a39ac29eb31d0d04cee5 Mon Sep 17 00:00:00 2001 From: Savio Sena Date: Thu, 24 Jul 2014 16:03:02 -0300 Subject: [PATCH] eolian-cxx: Fixed inheritance operations generation rules. The generated code was not converting the types from C to C++ correctly. --- .../grammar/inheritance_base_generator.hh | 40 +++++++++++-------- src/lib/eolian_cxx/grammar/type_generator.hh | 2 +- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh index 12f6550d97..3030b0b76b 100644 --- a/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh +++ b/src/lib/eolian_cxx/grammar/inheritance_base_generator.hh @@ -155,26 +155,35 @@ operator<<(std::ostream& out, inheritance_base_operations_function const& x) eo_function const& func = x._func; bool is_void = function_is_void(func); - out << tab(2) << "virtual " << reinterpret_type(func.ret) << " " + if (parameters_count_callbacks(func.params) == 1) + out << tab(2) << "template " << tab(2) << endl; + else + out << tab(2) << "virtual "; + + out << reinterpret_type(func.ret) << " " << func.name << "(" - << parameters_c_declaration(func.params) << ")" << endl + << parameters_declaration(func.params) << ")" << endl << tab(2) << "{" << endl; + if (!is_void) - { - out << tab(3) << func.ret.front().native << " _tmp_ret = {};" << endl; - } + out << tab(3) << func.ret.front().native << " _tmp_ret = {};" << endl; + + parameters_container_type::const_iterator + callback_iter = parameters_find_callback(func.params); + if (callback_iter != func.params.cend()) + out << tab(3) << "typedef typename std::remove_reference::type function_type;" << endl + << tab(3) << "function_type* _tmp_f = new function_type(std::forward(" + << (*callback_iter).name << "));" << endl; + out << tab(3) - << "eo_do_super(static_cast(this)->_eo_ptr()" << endl - << tab(4) << ", static_cast(this)->_eo_class()," << endl - << tab(4) << (!is_void ? "_tmp_ret = " : "") - << "::" << x._func.impl - << "("; - parameter_names_enumerate(out, func.params) - << "));" << endl; - if (!function_is_void(func)) + << "eo_do_super(static_cast(this)->_eo_ptr()," << endl + << tab(5) << "static_cast(this)->_eo_class()," << endl + << tab(5) << function_call(func) << ");" << endl; + + if (!is_void) out << tab(4) << "return " << to_cxx(func.ret, "_tmp_ret") << ";" << endl; - out << tab(2) << "}" << endl << endl; - return out; + + return out << tab(2) << "}" << endl << endl; } struct inheritance_base_operations @@ -301,7 +310,6 @@ operator<<(std::ostream& out, inheritance_extension_function const& x) if (!function_is_void(x._func)) out << tab(4) << "return " << to_cxx(x._func.ret, "_tmp_ret") << ";" << endl; - out << tab(2) << "}" << endl << endl; diff --git a/src/lib/eolian_cxx/grammar/type_generator.hh b/src/lib/eolian_cxx/grammar/type_generator.hh index feef8da393..8584a572db 100644 --- a/src/lib/eolian_cxx/grammar/type_generator.hh +++ b/src/lib/eolian_cxx/grammar/type_generator.hh @@ -94,7 +94,7 @@ operator<<(std::ostream& out, to_cxx const& x) out << "efl::eolian::to_cxx<" << reinterpret_type(x._type) << ">(" << x._varname - << ", " << type_ownership(x._type) << ");"; + << ", " << type_ownership(x._type) << ")"; } else out << x._varname;