eolian-cxx: Various and various fixes with callbacks

Mimic the callback function generation for other functions that were
being generated incorrectly and inconsistently.
This commit is contained in:
Felipe Magno de Almeida 2014-07-17 21:49:12 -03:00
parent 15d85d7dc6
commit 907544be7b
6 changed files with 140 additions and 21 deletions

View File

@ -209,7 +209,8 @@ operator<<(std::ostream& out, eo_class_constructors const& x)
if (callback_iter != (*it).params.cend())
{
out << tab(2)
<< "F* _tmp_f = new F(std::move("
<< "typedef typename std::remove_reference<F>::type function_type;" << endl
<< "function_type* _tmp_f = new F(std::forward<F>("
<< (*callback_iter).name << "));"
<< endl;
}

View File

@ -10,12 +10,32 @@
namespace efl { namespace eolian { namespace grammar {
struct add_cast_to_t
{
add_cast_to_t(bool b)
: _b(b)
{
}
bool _b;
};
inline std::ostream&
operator<<(std::ostream& out, add_cast_to_t x)
{
if(x._b)
out << "static_cast<U*>(this)->";
return out;
}
struct event_callback_add
{
eo_event const& _event;
eo_class const& _cls;
event_callback_add(eo_event const& event, eo_class const& cls)
: _event(event), _cls(cls)
bool _add_cast_to_t;
event_callback_add(eo_event const& event, eo_class const& cls
, bool add_cast_to_t)
: _event(event), _cls(cls), _add_cast_to_t(add_cast_to_t)
{}
};
@ -28,13 +48,16 @@ operator<<(std::ostream& out, event_callback_add const& x)
<< tab(11) << "::efl::eo::callback_priority priority_ =" << endl
<< tab(11) << "::efl::eo::callback_priorities::default_)" << endl
<< tab(1) << "{" << endl
<< tab(2) << "::std::unique_ptr<F> f ( new F(std::move(callback_)) );" << endl
<< tab(2) << "eo_do(_eo_ptr()," << endl
<< tab(2) << "typedef typename std::remove_reference<F>::type function_type;" << endl
<< tab(2) << "::std::unique_ptr<function_type> f ( new function_type(std::move(callback_)) );" << endl
<< tab(2) << "eo_do(" << add_cast_to_t(x._add_cast_to_t) << "_eo_ptr()," << endl
<< tab(4) << "eo_event_callback_priority_add" << endl
<< tab(4) << "(" << x._event.eo_name << ", priority_," << endl
<< tab(4) << "&efl::eo::_detail::event_callback<" << x._cls.name << ", F>, f.get()));" << endl
<< tab(4) << "&efl::eo::_detail::event_callback<" << x._cls.name_space << "::" << x._cls.name << ", function_type>, f.get()));" << endl
<< tab(2) << "return ::efl::eo::make_signal_connection" << endl
<< tab(3) << "(f, this->_eo_ptr(), &efl::eo::_detail::event_callback<" << x._cls.name << ", F>," << endl
<< tab(3) << "(f, " << add_cast_to_t(x._add_cast_to_t)
<< "_eo_ptr(), &efl::eo::_detail::event_callback<"
<< x._cls.name_space << "::" << x._cls.name << ", function_type>," << endl
<< tab(3) << x._event.eo_name << " );" << endl
<< tab(1) << "}" << endl;
return out;
@ -43,8 +66,9 @@ operator<<(std::ostream& out, event_callback_add const& x)
struct event_callback_call
{
eo_event const& _event;
event_callback_call(eo_event const& event)
: _event(event)
bool _add_cast_to_t;
event_callback_call(eo_event const& event, bool add_cast_to_t)
: _event(event), _add_cast_to_t(add_cast_to_t)
{}
};
@ -55,7 +79,7 @@ operator<<(std::ostream& out, event_callback_call const& x)
<< tab(1) << "void" << endl
<< tab(1) << "event_" << x._event.name << "_callback_call(T* info)" << endl
<< tab(1) << "{" << endl
<< tab(2) << "eo_do(_eo_ptr(), eo_event_callback_call" << endl
<< tab(2) << "eo_do(" << add_cast_to_t(x._add_cast_to_t) << "_eo_ptr(), eo_event_callback_call" << endl
<< tab(4) << "(" << x._event.eo_name << ", info));" << endl
<< tab(1) << "}" << endl;
return out;
@ -64,7 +88,9 @@ operator<<(std::ostream& out, event_callback_call const& x)
struct events
{
eo_class const& _cls;
events(eo_class const& cls) : _cls(cls) {}
bool _add_cast_to_t;
events(eo_class const& cls, bool add_cast_to_t = false)
: _cls(cls), _add_cast_to_t(add_cast_to_t) {}
};
inline std::ostream&
@ -72,8 +98,8 @@ operator<<(std::ostream& out, events const& x)
{
for (eo_event const& e : x._cls.events)
{
out << event_callback_add(e, x._cls) << endl
<< event_callback_call(e);
out << event_callback_add(e, x._cls, x._add_cast_to_t) << endl
<< event_callback_call(e, x._add_cast_to_t);
}
return out;
}

View File

@ -55,6 +55,17 @@ operator<<(std::ostream& out, function const& x)
out << tab(2)
<< 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(2)
<< "typedef typename std::remove_reference<F>::type function_type;" << endl
<< tab(2) << "function_type* _tmp_f = new function_type(std::forward<F>("
<< (*callback_iter).name << "));"
<< endl;
}
out << tab(2)
<< "eo_do(_eo_ptr(), " << function_call(x._func) << ");" << endl;

View File

@ -102,13 +102,13 @@ operator<<(std::ostream& out, inheritance_wrapper const& x)
<< "_wrapper(Eo* objid EINA_UNUSED, "
<< "efl::eo::detail::Inherit_Private_Data* self"
<< (x._func.params.size() ? ", " : "")
<< parameters_declaration(x._func.params)
<< parameters_c_declaration(x._func.params)
<< ")" << endl
<< "{" << endl
<< tab(1)
<< (!function_is_void(x._func) ? "return ": "")
<< "static_cast<T*>(self->this_)->"
<< x._func.name << "(" << parameters_list(x._func.params) << ");" << endl
<< x._func.name << "(" << parameters_c_list(x._func.params) << ");" << endl
<< "}" << endl << endl;
return out;
@ -136,13 +136,13 @@ operator<<(std::ostream& out, inheritance_wrappers const& x)
<< "_wrapper(Eo* objid EINA_UNUSED, "
<< "efl::eo::detail::Inherit_Private_Data* self"
<< (func.params.size() ? ", " : "")
<< parameters_declaration(func.params)
<< parameters_c_declaration(func.params)
<< ")" << endl
<< "{" << endl
<< tab(1)
<< (!function_is_void(func) ? "return ": "")
<< "static_cast<T*>(self->this_)->"
<< func.name << "(" << parameters_list(func.params) << ");" << endl
<< func.name << "(" << parameters_c_list(func.params) << ");" << endl
<< "}" << endl << endl;
}
return out;
@ -299,6 +299,9 @@ struct inheritance_extension_function
inline std::ostream&
operator<<(std::ostream& out, inheritance_extension_function const& x)
{
if (parameters_count_callbacks(x._func.params) == 1)
out << tab(1) << "template <typename F>" << endl;
bool is_void = function_is_void(x._func);
out << tab(2)
<< reinterpret_type(x._func.ret) << " "
@ -312,7 +315,18 @@ operator<<(std::ostream& out, inheritance_extension_function const& x)
out << tab(3) << reinterpret_type(x._func.ret) << " _tmp_ret = {};" << endl;
}
out << tab(3) << "eo_do(static_cast<T*>(this)->_eo_ptr(), "
parameters_container_type::const_iterator callback_iter =
parameters_find_callback(x._func.params);
if (callback_iter != x._func.params.cend())
{
out << tab(2)
<< "typedef typename std::remove_reference<F>::type function_type;" << endl
<< "function_type* _tmp_f = new function_type(std::forward<F>("
<< (*callback_iter).name << "));"
<< endl;
}
out << tab(3) << "eo_do(static_cast<U*>(this)->_eo_ptr(), "
<< function_call(x._func) << ");" << endl;
if (!is_void)
@ -340,13 +354,13 @@ operator<<(std::ostream& out, inheritance_extension const& x)
<< "struct extension_inheritance< "
<< cls << ">" << endl
<< "{" << endl
<< tab(1) << "template <typename T>" << endl
<< tab(1) << "template <typename U>" << endl
<< tab(1) << "struct type" << endl
<< tab(1) << "{" << endl
<< tab(2) << "operator " << cls << "() const" << endl
<< tab(2) << "{" << endl
<< tab(3) << "return " << cls
<< "(eo_ref(static_cast<T const*>(this)->_eo_ptr()));" << endl
<< "(eo_ref(static_cast<U const*>(this)->_eo_ptr()));" << endl
<< tab(2) << "}" << endl
<< endl;
functions_container_type::const_iterator it,
@ -356,6 +370,7 @@ operator<<(std::ostream& out, inheritance_extension const& x)
{
out << inheritance_extension_function(*it);
}
out << events(x._cls, true);
out << tab(1) << "};" << endl
<< "};" << endl
<< endl;

View File

@ -40,6 +40,29 @@ operator<<(std::ostream& out, parameters_declaration const& x)
return out;
}
struct
parameters_c_declaration
{
parameters_container_type const& _params;
parameters_c_declaration(parameters_container_type const& params)
: _params(params)
{}
};
inline std::ostream&
operator<<(std::ostream& out, parameters_c_declaration const& x)
{
auto first = x._params.cbegin(),
last = x._params.cend();
for (auto it = first; it != last; ++it)
{
if (it != first)
out << ", ";
out << c_type(it->type) << " " << (*it).name;
}
return out;
}
struct
parameters_types
{
@ -97,6 +120,28 @@ operator<<(std::ostream& out, parameters_list const& x)
return out;
}
struct
parameters_c_list
{
parameters_container_type const& _params;
parameters_c_list(parameters_container_type const& params)
: _params(params)
{}
};
inline std::ostream&
operator<<(std::ostream& out, parameters_c_list const& x)
{
auto first = x._params.cbegin(), last = x._params.cend();
for (auto it = first; it != last; ++it)
{
if (it != first)
out << ", ";
out << it->name;
}
return out;
}
struct
parameters_cxx_list
{

View File

@ -11,6 +11,27 @@ namespace efl { namespace eolian { namespace grammar {
using std::endl;
struct c_type
{
eolian_type_instance const& _list;
c_type(eolian_type_instance const& list)
: _list(list)
{}
};
inline std::ostream&
operator<<(std::ostream& out, efl::eolian::grammar::c_type const& x)
{
assert(x._list.size() > 0);
std::string res;
for (auto rit = x._list.rbegin(), last = x._list.rend(); rit != last; ++rit)
{
res = /*type_is_binding(*rit) ? (*rit).binding :*/ (*rit).native;
}
assert(!res.empty());
return out << res;
}
struct reinterpret_type
{
eolian_type_instance const& _list;
@ -93,7 +114,7 @@ inline std::ostream&
operator<<(std::ostream& out, to_c const& x)
{
if (type_is_callback(x._type))
out << "efl::eolian::get_callback<" << type_to_native_str(x._type) << ", F>()";
out << "efl::eolian::get_callback<" << type_to_native_str(x._type) << ", function_type>()";
else if (type_is_binding(x._type))
out << "efl::eolian::to_c(" << x._varname << ")";
else