From dff8d564758daa2804472cf1c72ac0811998d6bb Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 5 Sep 2014 10:43:50 +0100 Subject: [PATCH] eolian: use implements only to retrieve functions list This also changes the implements list so that it also includes virtual functions. --- src/bin/eolian/eo_generator.c | 161 +++++++++----------- src/bin/eolian/impl_generator.c | 35 +---- src/bin/eolian/legacy_generator.c | 85 +++++------ src/lib/eolian/database_fill.c | 2 +- src/tests/eolian/data/object_impl_add_ref.c | 26 ++-- src/tests/eolian/data/object_impl_ref.c | 26 ++-- 6 files changed, 151 insertions(+), 184 deletions(-) diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c index 20f69a0b19..0a292f08aa 100644 --- a/src/bin/eolian/eo_generator.c +++ b/src/bin/eolian/eo_generator.c @@ -83,7 +83,7 @@ tmpl_eo_retdesc[] =" * @return %s\n"; #endif static Eina_Bool -eo_fundef_generate(const Eolian_Class *class, Eolian_Function *func, Eolian_Function_Type ftype, Eina_Strbuf *functext) +eo_fundef_generate(const Eolian_Class *class, const Eolian_Function *func, Eolian_Function_Type ftype, Eina_Strbuf *functext) { _eolian_class_func_vars func_env; const char *str_dir[] = {"in", "out", "inout"}; @@ -229,10 +229,8 @@ eo_fundef_generate(const Eolian_Class *class, Eolian_Function *func, Eolian_Func Eina_Bool eo_header_generate(const Eolian_Class *class, Eina_Strbuf *buf) { - const Eolian_Function_Type ftype_order[] = {EOLIAN_PROPERTY, EOLIAN_METHOD}; Eina_Iterator *itr; Eolian_Event *event; - Eolian_Function *fid; char *tmpstr = malloc(0x1FF); Eina_Strbuf * str_hdr = eina_strbuf_new(); @@ -300,27 +298,27 @@ eo_header_generate(const Eolian_Class *class, Eina_Strbuf *buf) } } - int i; - for (i = 0; i < (int)EINA_C_ARRAY_LENGTH(ftype_order); i++) + if ((itr = eolian_class_implements_get(class))) { - itr = eolian_class_functions_get(class, ftype_order[i]); - EINA_ITERATOR_FOREACH(itr, fid) + const Eolian_Implement *impl; + EINA_ITERATOR_FOREACH(itr, impl) { - const Eolian_Function_Type ftype = eolian_function_type_get(fid); - Eina_Bool prop_read = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_GET ) ? EINA_TRUE : EINA_FALSE ; - Eina_Bool prop_write = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_SET ) ? EINA_TRUE : EINA_FALSE ; - - if (!prop_read && !prop_write) - { - eo_fundef_generate(class, fid, EOLIAN_UNRESOLVED, str_hdr); - } - if (prop_write) + if (eolian_implement_class_get(impl) != class) + continue; + Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; + const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); + switch (ftype) { + case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: + eo_fundef_generate(class, fid, ftype, str_hdr); + break; + case EOLIAN_PROPERTY: eo_fundef_generate(class, fid, EOLIAN_PROP_SET, str_hdr); - } - if (prop_read) - { eo_fundef_generate(class, fid, EOLIAN_PROP_GET, str_hdr); + break; + default: + eo_fundef_generate(class, fid, EOLIAN_UNRESOLVED, str_hdr); + break; } } eina_iterator_free(itr); @@ -570,7 +568,7 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid, } static Eina_Bool -eo_op_desc_generate(const Eolian_Class *class, Eolian_Function *fid, Eolian_Function_Type ftype, +eo_op_desc_generate(const Eolian_Class *class, const Eolian_Function *fid, Eolian_Function_Type ftype, const char *desc, Eina_Strbuf *buf) { _eolian_class_func_vars func_env; @@ -636,12 +634,25 @@ eo_source_beginning_generate(const Eolian_Class *class, Eina_Strbuf *buf) return EINA_TRUE; } +static void +_desc_generate(const Eolian_Class *class, const Eolian_Function *fid, Eolian_Function_Type ftype, Eina_Strbuf *tmpbuf, Eina_Strbuf *str_op) +{ + const char *funcname = eolian_function_name_get(fid); + char tmpstr[256]; + snprintf(tmpstr, sizeof(tmpstr), "%s%s", funcname, (ftype == EOLIAN_PROP_SET) + ? "_set" : ((ftype == EOLIAN_PROP_GET) ? "_get" : "")); + + char *desc = _source_desc_get(eolian_function_description_get(fid, ftype)); + eo_op_desc_generate(class, fid, ftype, desc, tmpbuf); + eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); + free(desc); +} + static Eina_Bool eo_source_end_generate(const Eolian_Class *class, Eina_Strbuf *buf) { Eina_Bool ret = EINA_FALSE; Eina_Iterator *itr; - Eolian_Function *fn; Eolian_Implement *impl_desc; Eolian_Event *event; const char *inherit_name; @@ -777,51 +788,28 @@ eo_source_end_generate(const Eolian_Class *class, Eina_Strbuf *buf) } eina_iterator_free(itr); - //Properties - itr = eolian_class_functions_get(class, EOLIAN_PROPERTY); - EINA_ITERATOR_FOREACH(itr, fn) + if ((itr = eolian_class_implements_get(class))) { - const char *funcname = eolian_function_name_get(fn); - const Eolian_Function_Type ftype = eolian_function_type_get(fn); - char tmpstr[0xFF]; - - Eina_Bool prop_read = ( ftype == EOLIAN_PROP_SET ) ? EINA_FALSE : EINA_TRUE; - Eina_Bool prop_write = ( ftype == EOLIAN_PROP_GET ) ? EINA_FALSE : EINA_TRUE; - - if (prop_write && !eolian_function_is_legacy_only(fn, EOLIAN_PROP_SET)) + const Eolian_Implement *impl; + EINA_ITERATOR_FOREACH(itr, impl) { - char *desc = _source_desc_get(eolian_function_description_get(fn, EOLIAN_PROP_SET)); + if (eolian_implement_class_get(impl) != class) + continue; + Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; + const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); - sprintf(tmpstr, "%s_set", funcname); - eo_op_desc_generate(class, fn, EOLIAN_PROP_SET, desc, tmpbuf); - eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); - free(desc); - } - if (prop_read && !eolian_function_is_legacy_only(fn, EOLIAN_PROP_GET)) - { - char *desc = _source_desc_get(eolian_function_description_get(fn, EOLIAN_PROP_GET)); - - sprintf(tmpstr, "%s_get", funcname); - eo_op_desc_generate(class, fn, EOLIAN_PROP_GET, desc, tmpbuf); - eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); - free(desc); + Eina_Bool prop_read = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_GET); + Eina_Bool prop_write = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_SET); + + if (!prop_read && !prop_write && !eolian_function_is_legacy_only(fid, EOLIAN_METHOD)) + _desc_generate(class, fid, EOLIAN_METHOD, tmpbuf, str_op); + if (prop_write && !eolian_function_is_legacy_only(fid, EOLIAN_PROP_SET)) + _desc_generate(class, fid, EOLIAN_PROP_SET, tmpbuf, str_op); + if (prop_read && !eolian_function_is_legacy_only(fid, EOLIAN_PROP_GET)) + _desc_generate(class, fid, EOLIAN_PROP_GET, tmpbuf, str_op); } + eina_iterator_free(itr); } - eina_iterator_free(itr); - - //Methods - itr = eolian_class_functions_get(class, EOLIAN_METHOD); - EINA_ITERATOR_FOREACH(itr, fn) - { - if (eolian_function_is_legacy_only(fn, EOLIAN_METHOD)) - continue; - - char *desc = _source_desc_get(eolian_function_description_get(fn, EOLIAN_METHOD)); - eo_op_desc_generate(class, fn, EOLIAN_METHOD, desc, tmpbuf); - eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); - free(desc); - } - eina_iterator_free(itr); itr = eolian_class_events_get(class); EINA_ITERATOR_FOREACH(itr, event) @@ -921,7 +909,6 @@ eo_source_generate(const Eolian_Class *class, Eina_Strbuf *buf) { Eina_Bool ret = EINA_FALSE; Eina_Iterator *itr; - Eolian_Function *fn; Eina_Strbuf *str_bodyf = eina_strbuf_new(); @@ -930,33 +917,36 @@ eo_source_generate(const Eolian_Class *class, Eina_Strbuf *buf) if (!eo_source_beginning_generate(class, buf)) goto end; - //Properties - itr = eolian_class_functions_get(class, EOLIAN_PROPERTY); - EINA_ITERATOR_FOREACH(itr, fn) + if ((itr = eolian_class_implements_get(class))) { - const Eolian_Function_Type ftype = eolian_function_type_get(fn); - - Eina_Bool prop_read = ( ftype == EOLIAN_PROP_SET ) ? EINA_FALSE : EINA_TRUE; - Eina_Bool prop_write = ( ftype == EOLIAN_PROP_GET ) ? EINA_FALSE : EINA_TRUE; - - if (prop_write) + const Eolian_Implement *impl; + EINA_ITERATOR_FOREACH(itr, impl) { - if (!eo_bind_func_generate(class, fn, EOLIAN_PROP_SET, str_bodyf, NULL)) goto end; - } - if (prop_read) - { - if (!eo_bind_func_generate(class, fn, EOLIAN_PROP_GET, str_bodyf, NULL)) goto end; + if (eolian_implement_class_get(impl) != class) + continue; + Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; + const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); + switch (ftype) + { + case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: + if (!eo_bind_func_generate(class, fid, ftype, str_bodyf, NULL)) + goto end; + break; + case EOLIAN_PROPERTY: + if (!eo_bind_func_generate(class, fid, EOLIAN_PROP_SET, str_bodyf, NULL)) + goto end; + if (!eo_bind_func_generate(class, fid, EOLIAN_PROP_GET, str_bodyf, NULL)) + goto end; + break; + default: + if (!eo_bind_func_generate(class, fid, EOLIAN_UNRESOLVED, str_bodyf, NULL)) + goto end; + break; + } } + eina_iterator_free(itr); + itr = NULL; } - eina_iterator_free(itr); - - //Methods - itr = eolian_class_functions_get(class, EOLIAN_METHOD); - EINA_ITERATOR_FOREACH(itr, fn) - { - if (!eo_bind_func_generate(class, fn, EOLIAN_UNRESOLVED, str_bodyf, NULL)) goto end; - } - eina_iterator_free(itr); eina_strbuf_append(buf, eina_strbuf_string_get(str_bodyf)); eina_strbuf_reset(str_bodyf); @@ -965,6 +955,7 @@ eo_source_generate(const Eolian_Class *class, Eina_Strbuf *buf) ret = EINA_TRUE; end: + if (itr) eina_iterator_free(itr); eina_hash_free(_funcs_params_init); _funcs_params_init = NULL; eina_strbuf_free(str_bodyf); diff --git a/src/bin/eolian/impl_generator.c b/src/bin/eolian/impl_generator.c index 645982d3c4..5394b63bbb 100644 --- a/src/bin/eolian/impl_generator.c +++ b/src/bin/eolian/impl_generator.c @@ -251,27 +251,6 @@ impl_source_generate(const Eolian_Class *class, Eina_Strbuf *buffer) eina_strbuf_prepend_printf(buffer, "%s", eina_strbuf_string_get(begin)); eina_strbuf_free(begin); - /* Properties */ - itr = eolian_class_functions_get(class, EOLIAN_PROPERTY); - EINA_ITERATOR_FOREACH(itr, foo) - { - const Eolian_Function_Type ftype = eolian_function_type_get(foo); - if (ftype == EOLIAN_PROP_SET || ftype == EOLIAN_PROPERTY) - _prototype_generate(foo, EOLIAN_PROP_SET, data_type_buf, NULL, buffer); - - if (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROPERTY) - _prototype_generate(foo, EOLIAN_PROP_GET, data_type_buf, NULL, buffer); - } - eina_iterator_free(itr); - - /* Methods */ - itr = eolian_class_functions_get(class, EOLIAN_METHOD); - EINA_ITERATOR_FOREACH(itr, foo) - { - _prototype_generate(foo, EOLIAN_METHOD, data_type_buf, NULL, buffer); - } - eina_iterator_free(itr); - itr = eolian_class_implements_get(class); if (itr) { @@ -280,24 +259,26 @@ impl_source_generate(const Eolian_Class *class, Eina_Strbuf *buffer) EINA_ITERATOR_FOREACH(itr, impl_desc) { Eolian_Function_Type ftype; - const Eolian_Class *cl = eolian_implement_class_get(impl_desc); - if (cl == class) - continue; + Eolian_Implement *idesc = (eolian_implement_class_get(impl_desc) == class) ? NULL : impl_desc; if (!(foo = eolian_implement_function_get(impl_desc, &ftype))) { const char *name = names[eolian_implement_is_prop_get(impl_desc) | (eolian_implement_is_prop_set(impl_desc) << 1)]; - ERR ("Failed to generate implementation of %s%s - missing form super class", + ERR ("Failed to generate implementation of %s%s - missing from class", name, eolian_implement_full_name_get(impl_desc)); goto end; } switch (ftype) { case EOLIAN_PROP_SET: case EOLIAN_PROP_GET: - _prototype_generate(foo, ftype, data_type_buf, impl_desc, buffer); + _prototype_generate(foo, ftype, data_type_buf, idesc, buffer); + break; + case EOLIAN_PROPERTY: + _prototype_generate(foo, EOLIAN_PROP_SET, data_type_buf, idesc, buffer); + _prototype_generate(foo, EOLIAN_PROP_GET, data_type_buf, idesc, buffer); break; default: - _prototype_generate(foo, eolian_function_type_get(foo), data_type_buf, impl_desc, buffer); + _prototype_generate(foo, eolian_function_type_get(foo), data_type_buf, idesc, buffer); break; } } diff --git a/src/bin/eolian/legacy_generator.c b/src/bin/eolian/legacy_generator.c index a21041e46f..d52b52900d 100644 --- a/src/bin/eolian/legacy_generator.c +++ b/src/bin/eolian/legacy_generator.c @@ -355,8 +355,6 @@ end: Eina_Bool legacy_header_generate(const Eolian_Class *class, Eina_Strbuf *buf) { - const Eolian_Function_Type ftype_order[] = {EOLIAN_PROPERTY, EOLIAN_METHOD}; - _class_env_create(class, NULL, &class_env); const char *desc = eolian_class_description_get(class); @@ -372,28 +370,28 @@ legacy_header_generate(const Eolian_Class *class, Eina_Strbuf *buf) eina_strbuf_free(linedesc); } - int i; - for (i = 0; i < 2; i++) + Eina_Iterator *itr = eolian_class_implements_get(class); + if (itr) { - void *data; - Eina_Iterator *itr = eolian_class_functions_get(class, ftype_order[i]); - EINA_ITERATOR_FOREACH(itr, data) + const Eolian_Implement *impl; + EINA_ITERATOR_FOREACH(itr, impl) { - const Eolian_Function_Type ftype = eolian_function_type_get((Eolian_Function*)data); - Eina_Bool prop_read = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_GET ) ? EINA_TRUE : EINA_FALSE ; - Eina_Bool prop_write = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_SET ) ? EINA_TRUE : EINA_FALSE ; - - if (!prop_read && !prop_write) + if (eolian_implement_class_get(impl) != class) + continue; + Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; + const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); + switch (ftype) { - _eapi_decl_func_generate(class, (Eolian_Function*)data, EOLIAN_METHOD, buf); - } - if (prop_write) - { - _eapi_decl_func_generate(class, (Eolian_Function*)data, EOLIAN_PROP_SET, buf); - } - if (prop_read) - { - _eapi_decl_func_generate(class, (Eolian_Function*)data, EOLIAN_PROP_GET, buf); + case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: + _eapi_decl_func_generate(class, fid, ftype, buf); + break; + case EOLIAN_PROPERTY: + _eapi_decl_func_generate(class, fid, EOLIAN_PROP_SET, buf); + _eapi_decl_func_generate(class, fid, EOLIAN_PROP_GET, buf); + break; + default: + _eapi_decl_func_generate(class, fid, EOLIAN_METHOD, buf); + break; } } eina_iterator_free(itr); @@ -406,40 +404,37 @@ legacy_source_generate(const Eolian_Class *class, Eina_Strbuf *buf) { Eina_Bool ret = EINA_FALSE; Eina_Iterator *itr; - Eolian_Function *fn; _class_env_create(class, NULL, &class_env); Eina_Strbuf *tmpbuf = eina_strbuf_new(); Eina_Strbuf *str_bodyf = eina_strbuf_new(); - //Properties - itr = eolian_class_functions_get(class, EOLIAN_PROPERTY); - EINA_ITERATOR_FOREACH(itr, fn) + if ((itr = eolian_class_implements_get(class))) { - const Eolian_Function_Type ftype = eolian_function_type_get(fn); - - Eina_Bool prop_read = ( ftype == EOLIAN_PROP_SET ) ? EINA_FALSE : EINA_TRUE; - Eina_Bool prop_write = ( ftype == EOLIAN_PROP_GET ) ? EINA_FALSE : EINA_TRUE; - - if (prop_write) + const Eolian_Implement *impl; + EINA_ITERATOR_FOREACH(itr, impl) { - _eapi_func_generate(class, fn, EOLIAN_PROP_SET, str_bodyf); - } - if (prop_read) - { - _eapi_func_generate(class, fn, EOLIAN_PROP_GET, str_bodyf); + if (eolian_implement_class_get(impl) != class) + continue; + Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; + const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); + switch (ftype) + { + case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: + _eapi_func_generate(class, fid, ftype, str_bodyf); + break; + case EOLIAN_PROPERTY: + _eapi_func_generate(class, fid, EOLIAN_PROP_SET, str_bodyf); + _eapi_func_generate(class, fid, EOLIAN_PROP_GET, str_bodyf); + break; + default: + _eapi_func_generate(class, fid, EOLIAN_METHOD, str_bodyf); + break; + } } + eina_iterator_free(itr); } - eina_iterator_free(itr); - - //Methods - itr = eolian_class_functions_get(class, EOLIAN_METHOD); - EINA_ITERATOR_FOREACH(itr, fn) - { - _eapi_func_generate(class, fn, EOLIAN_UNRESOLVED, str_bodyf); - } - eina_iterator_free(itr); eina_strbuf_append(buf, eina_strbuf_string_get(str_bodyf)); diff --git a/src/lib/eolian/database_fill.c b/src/lib/eolian/database_fill.c index d96cb7a8e7..ca915ccf07 100644 --- a/src/lib/eolian/database_fill.c +++ b/src/lib/eolian/database_fill.c @@ -342,7 +342,7 @@ pasttags: static Eina_Bool _db_build_implement(Eolian_Class *cl, Eolian_Function *foo_id) { - if (foo_id->impl || foo_id->get_virtual_pure || foo_id->set_virtual_pure) + if (foo_id->impl) return EINA_TRUE; Eolian_Implement *impl = calloc(1, sizeof(Eolian_Implement)); diff --git a/src/tests/eolian/data/object_impl_add_ref.c b/src/tests/eolian/data/object_impl_add_ref.c index 77cabe3f27..cd1fe29e86 100644 --- a/src/tests/eolian/data/object_impl_add_ref.c +++ b/src/tests/eolian/data/object_impl_add_ref.c @@ -7,6 +7,19 @@ typedef struct } Object_Impl_Data; +EOLIAN static void +_object_impl_base_constructor(Eo *obj, Object_Impl_Data *pd) +{ + +} + +EOLIAN static void +_object_impl_base_destructor(Eo *obj, Object_Impl_Data *pd) +{ + eo_do_super(obj, OBJECT_IMPL_CLASS, base_destructor()); + +} + EOLIAN static Eina_Bool _object_impl_a_set(Eo *obj, Object_Impl_Data *pd, const char *part, const Eina_List *value) { @@ -49,19 +62,6 @@ _object_impl_foo2(const Eo *obj, Object_Impl_Data *pd, int a, const char *b) } -EOLIAN static void -_object_impl_base_constructor(Eo *obj, Object_Impl_Data *pd) -{ - -} - -EOLIAN static void -_object_impl_base_destructor(Eo *obj, Object_Impl_Data *pd) -{ - eo_do_super(obj, OBJECT_IMPL_CLASS, base_destructor()); - -} - EOLIAN static void _object_impl_class_constructor(Eo_Class *klass) { diff --git a/src/tests/eolian/data/object_impl_ref.c b/src/tests/eolian/data/object_impl_ref.c index a3f1bcb145..7297c70f5a 100644 --- a/src/tests/eolian/data/object_impl_ref.c +++ b/src/tests/eolian/data/object_impl_ref.c @@ -7,6 +7,19 @@ typedef struct } Object_Impl_Data; +EOLIAN static void +_object_impl_base_constructor(Eo *obj, Object_Impl_Data *pd) +{ + +} + +EOLIAN static void +_object_impl_base_destructor(Eo *obj, Object_Impl_Data *pd) +{ + eo_do_super(obj, OBJECT_IMPL_CLASS, base_destructor()); + +} + EOLIAN static Eina_Bool _object_impl_a_set(Eo *obj, Object_Impl_Data *pd, const char *part, const Eina_List *value) { @@ -49,19 +62,6 @@ _object_impl_foo2(const Eo *obj, Object_Impl_Data *pd, int a, const char *b) } -EOLIAN static void -_object_impl_base_constructor(Eo *obj, Object_Impl_Data *pd) -{ - -} - -EOLIAN static void -_object_impl_base_destructor(Eo *obj, Object_Impl_Data *pd) -{ - eo_do_super(obj, OBJECT_IMPL_CLASS, base_destructor()); - -} - EOLIAN static void _object_impl_class_constructor(Eo_Class *klass) {