eolian_cxx: Fix compilation of inheritance from Eolian generated classes

Updated the code for the "inheritance helper" functions and classes
to be in conformance with the new wrapper architecture.

Member variable "parents" of efl::eo::eo_class struct was split in two
member variables, "ancestors" and "parents", the former containing all
Eo class ancestors and the later only the direct bases.
Changed all required files accordingly.

Check to avoid using biding string when the parameter is @out now matches
any variation of "char".

Add default constructor to efl::eo::concrete in order to allow it to be
NULL initialized in the "inheritance helper" classes.

Removed conflicting parent_set member function in the efl::eo::inherit
class.

Removed the "inheritance_extension_function" generator since it is no
longer used.
This commit is contained in:
Vitor Sousa 2014-12-30 21:18:40 -02:00
parent 2b12114777
commit 4222cd3f50
12 changed files with 59 additions and 137 deletions

View File

@ -24,7 +24,7 @@ namespace eolian_cxx {
extern efl::eina::log_domain domain;
void
add_parent_recursive(const char* klass_name, std::set<std::string>& parents)
add_ancestor_recursive(const char* klass_name, std::set<std::string>& ancestor)
{
if (!klass_name)
return;
@ -36,14 +36,14 @@ add_parent_recursive(const char* klass_name, std::set<std::string>& parents)
return;
}
parents.insert(class_format_cxx(safe_lower(klass_name)));
ancestor.insert(class_format_cxx(safe_lower(klass_name)));
Eina_Iterator* inheritances = ::eolian_class_inherits_get(klass);
void* curr = 0;
EINA_ITERATOR_FOREACH(inheritances, curr)
{
add_parent_recursive(static_cast<const char*>(curr), parents);
add_ancestor_recursive(static_cast<const char*>(curr), ancestor);
}
eina_iterator_free(inheritances);
}
@ -182,15 +182,17 @@ convert_eolian_inheritances(efl::eolian::eo_class& cls, Eolian_Class const& klas
::eolian_class_inherits_get(&klass);
void *curr;
std::set<std::string> parents;
std::set<std::string> ancestors;
EINA_ITERATOR_FOREACH(inheritances, curr)
{
add_parent_recursive(static_cast<const char*>(curr), parents);
const char* klass_name = static_cast<const char*>(curr);
cls.parents.push_back(class_format_cxx(safe_lower(klass_name)));
add_ancestor_recursive(klass_name, ancestors);
}
eina_iterator_free(inheritances);
cls.parents.assign(parents.begin(), parents.end());
cls.ancestors.assign(ancestors.begin(), ancestors.end());
}
void

View File

@ -348,7 +348,7 @@ parameter_type(Eolian_Function_Parameter const& parameter,
assert(!type.empty());
if (parameter_is_out(parameter))
{
if (type.front().native == "char *")
if (type.front().native.find("char") != std::string::npos)
type = { efl::eolian::type_to_native(type) };
type.is_out = true;
type.front().native += "*";

View File

@ -47,6 +47,15 @@ struct concrete
{
}
/// @brief Default constructor.
///
/// Constructs a NULL initialized efl::eo::concrete object.
///
concrete() : _eo_raw(nullptr)
{
}
/// @brief Class destructor.
///
~concrete()

View File

@ -108,6 +108,14 @@ to_cxx(Eo* x, std::tuple<std::false_type>, tag<T>)
return T(::eo_ref(x));
}
template <typename T>
inline T
to_cxx(Eo** x, std::tuple<std::false_type>, tag<T>)
{
static_assert(sizeof(Eo*) == sizeof(typename std::remove_pointer<T>::type), "");
return static_cast<T>((static_cast<void*>(x)));
}
#ifdef _EVAS_H
template <typename T>
Evas_Object_Textblock_Node_Format *

View File

@ -105,12 +105,6 @@ struct inherit
///
Eo_Class const* _eo_class() const { return _eo_cls; }
template <typename T>
void parent_set(T& p_)
{
detail::parent_set(_eo_raw, p_._eo_ptr());
}
Eo* _release()
{
Eo* tmp = _eo_raw;

View File

@ -7,6 +7,7 @@
#define EFL_CXX_EO_PRIVATE_HH
#include "eo_ops.hh"
#include "eo_concrete.hh"
namespace efl { namespace eo { namespace detail {
@ -87,7 +88,7 @@ Eo_Class const* do_eo_class_new(Eo_Class_Description& class_desc)
template <typename T> struct operation_description_class_size;
template<>
struct operation_description_class_size<efl::eo::base> { static const int value = 0; };
struct operation_description_class_size<efl::eo::concrete> { static const int value = 0; };
/// @internal
///
@ -134,7 +135,7 @@ namespace detail {
template <typename T> struct operations;
template <>
struct operations<efl::eo::base> { template <typename T> struct type {}; };
struct operations<efl::eo::concrete> { template <typename T> struct type {}; };
/// @internal
///
@ -163,7 +164,7 @@ struct Inherit_Private_Data
namespace efl { namespace eo { namespace detail {
template <typename T>
int initialize_operation_description(efl::eo::detail::tag<efl::eo::base>
int initialize_operation_description(efl::eo::detail::tag<efl::eo::concrete>
, Eo_Op_Description* ops)
{
(void)ops;

View File

@ -14,7 +14,7 @@ struct eo_parameter;
struct eo_function;
struct eo_event;
typedef std::vector<std::string> parents_container_type;
typedef std::vector<std::string> ancestors_container_type;
typedef std::vector<std::string> includes_container_type;
typedef std::vector<eo_constructor> constructors_container_type;
typedef std::vector<eo_function> functions_container_type;
@ -215,7 +215,8 @@ struct eo_class
eo_class_type type;
std::string name;
std::string eo_name;
parents_container_type parents;
ancestors_container_type parents;
ancestors_container_type ancestors;
constructors_container_type constructors;
functions_container_type functions;
events_container_type events;

View File

@ -41,9 +41,9 @@ operator<<(std::ostream& out, class_inheritance const& x)
{
eo_class const& cls = x._cls;
parents_container_type::const_iterator it,
first = cls.parents.cbegin(),
last = cls.parents.cend();
ancestors_container_type::const_iterator it,
first = cls.ancestors.cbegin(),
last = cls.ancestors.cend();
for (it = first; it != last; ++it)
{
out << tab(2) << ", ::" << abstract_namespace << "::" << *it << endl;

View File

@ -151,7 +151,7 @@ struct address_of_inheritance
inline std::ostream&
operator<<(std::ostream& out, address_of_inheritance const& x)
{
for (std::string const& parent : x._cls.parents)
for (std::string const& parent : x._cls.ancestors)
{
out << tab(2) << ", ::" << abstract_namespace << "::" << parent << "::"
<< x._struct_name << "<" << x._struct_name << ">" << endl;

View File

@ -65,12 +65,8 @@ struct inheritance_operations_description
inline std::ostream&
operator<<(std::ostream& out, inheritance_operations_description const& x)
{
extensions_container_type::const_iterator it, first, last;
std::string s;
first = x._cls.extensions.begin();
last = x._cls.extensions.end();
out << "template <typename T>"
<< endl << "int initialize_operation_description(::efl::eo::detail::tag<"
<< full_name(x._cls) << ">" << endl
@ -84,21 +80,13 @@ operator<<(std::ostream& out, inheritance_operations_description const& x)
out << inheritance_operation(x._cls, i);
}
out << tab(1)
<< "initialize_operation_description<T>(efl::eo::detail::tag<"
<< x._cls.parent
<< ">(), &ops["
<< x._cls.functions.size() << "]);" << endl;
s += " + operation_description_class_size<" + x._cls.parent + ">::value";
for (it = first; it != last; ++it)
for (std::string const& parent : x._cls.parents)
{
out << tab(1)
<< "initialize_operation_description<T>(efl::eo::detail::tag<"
<< *it << ">(), &ops[" << x._cls.functions.size() << s << "]);" << endl;
<< "initialize_operation_description<T>(::efl::eo::detail::tag<::"
<< parent << ">(), &ops[" << x._cls.functions.size() << s << "]);" << endl;
s += " + operation_description_class_size< " + *it + ">::value";
s += " + operation_description_class_size<::" + parent + ">::value";
}
out << tab(1) << "return 0;" << endl
@ -168,21 +156,16 @@ struct inheritance_base_operations_size
inline std::ostream&
operator<<(std::ostream& out, inheritance_base_operations_size const& x)
{
extensions_container_type::const_iterator it, first = x._cls.extensions.begin();
extensions_container_type::const_iterator last = x._cls.extensions.end();
first = x._cls.extensions.begin();
out << "template<>"
<< endl << "struct operation_description_class_size< "
<< full_name(x._cls) << " >" << endl
<< "{" << endl
<< tab(1) << "static const int value = "
<< x._cls.functions.size()
<< " + operation_description_class_size<" << class_name(x._cls.parent) << ">::value";
<< x._cls.functions.size();
for (it = first; it != last; ++it)
for (std::string const& parent : x._cls.parents)
{
out << " + operation_description_class_size< " << *it << " >::value";
out << " + operation_description_class_size<::" << parent << " >::value";
}
out << ";" << endl
@ -205,14 +188,14 @@ inline std::ostream&
operator<<(std::ostream& out, inheritance_base_operations_extensions const& x)
{
eo_class const& cls = x._cls;
extensions_container_type::const_iterator it, first = cls.extensions.begin();
extensions_container_type::const_iterator last = cls.extensions.end();
ancestors_container_type::const_iterator it, first = cls.parents.begin();
ancestors_container_type::const_iterator last = cls.parents.end();
out << endl << tab(3) << ": operations< " << class_name(cls.parent) << " >::template type<T>";
for (it = first; it != last; ++it)
{
out << "," << endl << tab(3)
<< "operations< " << *it
out << endl
<< tab(3) << (it == first ? ": " : ", ")
<< "virtual operations< ::" << *it
<< " >::template type<T>";
}
@ -247,12 +230,12 @@ operator<<(std::ostream& out, inheritance_base_operations_function const& x)
if (!is_void)
out << tab(3) << func.ret.front().native << " _tmp_ret = {};" << endl;
out << callbacks_heap_alloc("static_cast<T*>(this)->_eo_ptr()", func.params, 3)
out << callbacks_heap_alloc("dynamic_cast<T*>(this)->_eo_ptr()", func.params, 3)
<< endl;
out << tab(3)
<< "eo_do_super(static_cast<T*>(this)->_eo_ptr()," << endl
<< tab(5) << "static_cast<T*>(this)->_eo_class()," << endl
<< "eo_do_super(dynamic_cast<T*>(this)->_eo_ptr()," << endl
<< tab(5) << "dynamic_cast<T*>(this)->_eo_class()," << endl
<< tab(5) << function_call(func) << ");" << endl;
if (!is_void)
@ -325,10 +308,10 @@ operator<<(std::ostream& out, inheritance_call_constructors const& x)
{
eo_constructor const& ctor = *it;
out << "inline void" << endl
<< "call_constructor(tag< "
<< "call_constructor(::efl::eo::detail::tag< "
<< full_name(x._cls) << " >" << endl
<< tab(5) << ", Eo* eo, Eo_Class const* cls EINA_UNUSED," << endl
<< tab(5) << "args_class<"
<< tab(5) << "::efl::eo::detail::args_class<"
<< full_name(x._cls)
<< ", ::std::tuple<"
<< parameters_types(ctor.params)
@ -343,10 +326,10 @@ operator<<(std::ostream& out, inheritance_call_constructors const& x)
}
out << "inline void" << endl
<< "call_constructor(tag< "
<< "call_constructor(::efl::eo::detail::tag< "
<< full_name(x._cls) << " >" << endl
<< tab(5) << ", Eo* eo, Eo_Class const* cls EINA_UNUSED," << endl
<< tab(5) << "args_class<"
<< tab(5) << "::efl::eo::detail::args_class<"
<< full_name(x._cls)
<< ", ::std::tuple<::efl::eo::parent_type> > const& args)" << endl
<< "{" << endl
@ -357,81 +340,6 @@ operator<<(std::ostream& out, inheritance_call_constructors const& x)
return out;
}
struct inheritance_extension_function
{
eo_function const& _func;
inheritance_extension_function(eo_function const& func) : _func(func) {}
};
inline std::ostream&
operator<<(std::ostream& out, inheritance_extension_function const& x)
{
out << template_parameters_declaration(x._func.params, 1);
bool is_void = function_is_void(x._func);
out << tab(2)
<< reinterpret_type(x._func.ret) << " "
<< x._func.name << "("
<< parameters_declaration(x._func.params)
<< ")" << endl
<< tab(2) << "{" << endl;
if (!is_void)
{
out << tab(3) << x._func.ret.front().native << " _tmp_ret = {};" << endl;
}
out << callbacks_heap_alloc("static_cast<U*>(this)->_eo_ptr()", x._func.params, 2)
<< endl;
out << tab(3) << "eo_do(static_cast<U*>(this)->_eo_ptr(), "
<< function_call(x._func) << ");" << endl;
if (!function_is_void(x._func))
out << tab(4) << "return " << to_cxx(x._func.ret, "_tmp_ret") << ";" << endl;
out << tab(2) << "}" << endl
<< endl;
return out;
}
struct inheritance_extension
{
eo_class const& _cls;
inheritance_extension(eo_class const& cls) : _cls(cls) {}
};
inline std::ostream&
operator<<(std::ostream& out, inheritance_extension const& x)
{
full_name const cls(x._cls);
out << "template<>" << endl
<< "struct extension_inheritance< "
<< cls << ">" << endl
<< "{" << 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<U const*>(this)->_eo_ptr()));" << endl
<< tab(2) << "}" << endl
<< endl;
functions_container_type::const_iterator it,
first = x._cls.functions.begin(),
last = x._cls.functions.end();
for (it = first; it != last; ++it)
{
out << inheritance_extension_function(*it);
}
out << events(x._cls, true);
out << tab(1) << "};" << endl
<< "};" << endl
<< endl;
return out;
}
struct inheritance_eo_class_getter
{
eo_class const& _cls;
@ -460,7 +368,6 @@ eo_inheritance_detail_generator(std::ostream& out, eo_class const& cls)
<< inheritance_base_operations_size(cls)
<< inheritance_operations_description(cls)
<< inheritance_call_constructors(cls)
<< inheritance_extension(cls)
<< inheritance_eo_class_getter(cls)
<< "} } }" << endl;
}

View File

@ -14,7 +14,7 @@ struct bar
: efl::eo::inherit<bar, simple>
{
bar()
: inherit_base()
: inherit_base(efl::eo::parent = nullptr)
{}
bool simple_get()

View File

@ -4,13 +4,13 @@ class Simple (Eo.Base)
data: null;
methods {
simple_get {
return bool;
return: bool;
}
name_get {
params {
@out const(char)* name;
}
return bool;
return: bool;
}
}
implements {