q66 pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=60bf9fcaef4e1a01ae169f8112bfd080cdca15f0
commit 60bf9fcaef4e1a01ae169f8112bfd080cdca15f0 Author: Daniel Kolesa <[email protected]> Date: Wed Jul 9 13:26:00 2014 +0100 eolian: reduce code duplication --- src/lib/eolian/eo_parser.c | 81 +++-------------------- src/lib/eolian/eolian_database.c | 138 ++++++++++++++++++--------------------- src/lib/eolian/eolian_database.h | 3 + 3 files changed, 76 insertions(+), 146 deletions(-) diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index 6d6fb1f..fb65344 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -1053,69 +1053,6 @@ parse_chunk(Eo_Lexer *ls, Eina_Bool eot) static char *_accessor_type_str[ACCESSOR_TYPE_LAST] = { "setter", "getter" }; static char * _param_way_str[ PARAM_WAY_LAST] = { "IN", "OUT", "INOUT" }; -static void _print_type(FILE *f, Eo_Type_Def *tp); - -static Eina_Bool -_print_field(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, - void *fdata) -{ - FILE *f = (FILE*)fdata; - fprintf(f, "%s: ", (const char*)key); - _print_type(f, (Eo_Type_Def*)data); - fputs("; ", f); - return EINA_TRUE; -} - -static void -_print_type(FILE *f, Eo_Type_Def *tp) -{ - Eina_List *l; - Eo_Type_Def *stp; - if (tp->is_own) - fputs("own(", f); - if (tp->is_const) - fputs("const(", f); - if (tp->type == EOLIAN_TYPE_REGULAR) - fputs(tp->name, f); - else if (tp->type == EOLIAN_TYPE_REGULAR_STRUCT) - fprintf(f, "struct %s", tp->name); - else if (tp->type == EOLIAN_TYPE_POINTER) - { - _print_type(f, tp->base_type); - fputc('*', f); - } - else if (tp->type == EOLIAN_TYPE_FUNCTION) - { - Eina_Bool first = EINA_TRUE; - fputs("fn", f); - if (tp->ret_type) - { - fputs(" -> ", f); - _print_type(f, tp->ret_type); - } - fputs(" (", f); - EINA_LIST_FOREACH(tp->arguments, l, stp) - { - if (!first) fputs(", ", f); - first = EINA_FALSE; - _print_type(f, stp); - } - fputc(')', f); - } - else if (tp->type == EOLIAN_TYPE_STRUCT) - { - fputs("struct ", f); - if (tp->name) fprintf(f, "%s ", tp->name); - fputs("{ ", f); - eina_hash_foreach(tp->fields, _print_field, f); - fputs("}", f); - } - if (tp->is_own) - fputc(')', f); - if (tp->is_const) - fputc(')', f); -} - static void _dump_class(Eo_Class_Def *kls) { @@ -1148,14 +1085,14 @@ _dump_class(Eo_Class_Def *kls) if (meth->ret) { printf(" return: "); - _print_type(stdout, meth->ret->type); + database_type_print((Eolian_Type)meth->ret->type); printf(" (%s)\n", meth->ret->comment); } printf(" legacy : %s\n", meth->legacy); EINA_LIST_FOREACH(meth->params, m, param) { printf(" param: %s %s : ", _param_way_str[param->way], param->name); - _print_type(stdout, param->type); + database_type_print((Eolian_Type)param->type); printf(" (%s)\n", param->comment); } } @@ -1166,20 +1103,20 @@ _dump_class(Eo_Class_Def *kls) EINA_LIST_FOREACH(prop->keys, m, param) { printf(" key: %s : ", param->name); - _print_type(stdout, param->type); + database_type_print((Eolian_Type)param->type); printf(" (%s)\n", param->comment); } EINA_LIST_FOREACH(prop->values, m, param) { printf(" value: %s : ", param->name); - _print_type(stdout, param->type); + database_type_print((Eolian_Type)param->type); printf(" (%s)\n", param->comment); } EINA_LIST_FOREACH(prop->accessors, m, accessor) { printf(" accessor: "); if (accessor->ret) - _print_type(stdout, accessor->ret->type); + database_type_print((Eolian_Type)accessor->ret->type); printf(" : %s (%s)\n", _accessor_type_str[accessor->type], accessor->comment); printf(" legacy : %s\n", accessor->legacy); } @@ -1191,7 +1128,7 @@ _dump_class(Eo_Class_Def *kls) if (meth->ret) { printf(" return: "); - _print_type(stdout, meth->ret->type); + database_type_print((Eolian_Type)meth->ret->type); printf(" (%s)\n", meth->ret->comment); } printf(" legacy : %s\n", meth->legacy); @@ -1199,7 +1136,7 @@ _dump_class(Eo_Class_Def *kls) EINA_LIST_FOREACH(meth->params, m, param) { printf(" param: %s %s : ", _param_way_str[param->way], param->name); - _print_type(stdout, param->type); + database_type_print((Eolian_Type)param->type); printf(" (%s)\n", param->comment); } } @@ -1209,14 +1146,14 @@ static void _dump_type(Eo_Typedef_Def *type) { printf("Typedef: %s ", type->alias); - _print_type(stdout, type->type); + database_type_print((Eolian_Type)type->type); printf("\n"); } static void _dump_struct(Eo_Type_Def *type) { - _print_type(stdout, type); + database_type_print((Eolian_Type)type); } void diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c index 56bd848..a735fa7 100644 --- a/src/lib/eolian/eolian_database.c +++ b/src/lib/eolian/eolian_database.c @@ -1388,6 +1388,67 @@ eolian_type_name_get(Eolian_Type tp) return ((_Parameter_Type*)tp)->name; } +static Eina_Bool +_print_field(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, + void *fdata EINA_UNUSED) +{ + printf("%s: ", (const char*)key); + database_type_print((Eolian_Type)data); + puts("; "); + return EINA_TRUE; +} + +void +database_type_print(Eolian_Type type) +{ + Eina_List *l; + Eolian_Type stp; + _Parameter_Type *tp = (_Parameter_Type*)type; + if (tp->is_own) + puts("own("); + if (tp->is_const) + puts("const("); + if (tp->type == EOLIAN_TYPE_REGULAR) + puts(tp->name); + else if (tp->type == EOLIAN_TYPE_REGULAR_STRUCT) + printf("struct %s", tp->name); + else if (tp->type == EOLIAN_TYPE_POINTER) + { + database_type_print(tp->base_type); + putchar('*'); + } + else if (tp->type == EOLIAN_TYPE_FUNCTION) + { + Eina_Bool first = EINA_TRUE; + puts("fn"); + if (tp->ret_type) + { + puts(" -> "); + database_type_print(tp->ret_type); + } + puts(" ("); + EINA_LIST_FOREACH(tp->arguments, l, stp) + { + if (!first) puts(", "); + first = EINA_FALSE; + database_type_print(stp); + } + putchar(')'); + } + else if (tp->type == EOLIAN_TYPE_STRUCT) + { + puts("struct "); + if (tp->name) printf("%s ", tp->name); + puts("{ "); + eina_hash_foreach(tp->fields, _print_field, NULL); + puts("}"); + } + if (tp->is_own) + putchar(')'); + if (tp->is_const) + putchar(')'); +} + static void _implements_print(Eolian_Implement impl, int nb_spaces) { @@ -1422,73 +1483,6 @@ _event_print(Eolian_Event ev, int nb_spaces) printf("%*s <%s> <%s> <%s>\n", nb_spaces + 5, "", name, type, comment); } -static void _type_print(Eolian_Type tp, Eina_Strbuf *buf); - -static Eina_Bool -_field_print(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, - void *fdata) -{ - Eina_Strbuf *buf = (Eina_Strbuf*)fdata; - eina_strbuf_append_printf(buf, "%s: ", (const char*)key); - _type_print((Eolian_Type)data, buf); - eina_strbuf_append(buf, "; "); - return EINA_TRUE; -} - -static void -_type_print(Eolian_Type tp, Eina_Strbuf *buf) -{ - _Parameter_Type *tpp = (_Parameter_Type*)tp; - Eina_List *l; - Eolian_Type stp; - if (tpp->is_own) - eina_strbuf_append(buf, "own("); - if (tpp->is_const) - eina_strbuf_append(buf, "const("); - if (tpp->type == EOLIAN_TYPE_REGULAR) - eina_strbuf_append(buf, tpp->name); - else if (tpp->type == EOLIAN_TYPE_REGULAR_STRUCT) - { - eina_strbuf_append(buf, "struct "); - eina_strbuf_append(buf, tpp->name); - } - else if (tpp->type == EOLIAN_TYPE_POINTER) - { - _type_print(tpp->base_type, buf); - eina_strbuf_append_char(buf, '*'); - } - else if (tpp->type == EOLIAN_TYPE_FUNCTION) - { - Eina_Bool first = EINA_TRUE; - eina_strbuf_append(buf, "fn"); - if (tpp->ret_type) - { - eina_strbuf_append(buf, " -> "); - _type_print(tpp->ret_type, buf); - } - eina_strbuf_append(buf, " ("); - EINA_LIST_FOREACH(tpp->arguments, l, stp) - { - if (!first) eina_strbuf_append(buf, ", "); - first = EINA_FALSE; - _type_print(stp, buf); - } - eina_strbuf_append_char(buf, ')'); - } - else if (tpp->type == EOLIAN_TYPE_STRUCT) - { - eina_strbuf_append(buf, "struct "); - if (tpp->name) eina_strbuf_append_printf(buf, "%s ", tpp->name); - eina_strbuf_append(buf, "{ "); - eina_hash_foreach(tpp->fields, _field_print, buf); - eina_strbuf_append(buf, "}"); - } - if (tpp->is_own) - eina_strbuf_append_char(buf, ')'); - if (tpp->is_const) - eina_strbuf_append_char(buf, ')'); -} - static Eina_Bool _function_print(const _Function_Id *fid, int nb_spaces) { Eolian_Function foo_id = (Eolian_Function) fid; @@ -1578,13 +1572,9 @@ static Eina_Bool _function_print(const _Function_Id *fid, int nb_spaces) param_dir = "INOUT"; break; } - Eina_Strbuf *type_buf = eina_strbuf_new(); - _type_print(param->type, type_buf); - printf("%*s%s <%s> <%s> <%s>\n", nb_spaces + 5, "", - param_dir, param->name, - eina_strbuf_string_get(type_buf), - param->description?param->description:""); - eina_strbuf_free(type_buf); + printf("%*s%s <%s> <", nb_spaces + 5, "", param_dir, param->name); + database_type_print((Eolian_Type)param->type); + printf("> <%s>\n", param->description?param->description:""); } return EINA_TRUE; } diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h index 9fd3f7a..38f57e2 100644 --- a/src/lib/eolian/eolian_database.h +++ b/src/lib/eolian/eolian_database.h @@ -139,4 +139,7 @@ database_event_free(Eolian_Event event); Eina_Bool database_class_event_add(Eolian_Class class, Eolian_Event event_desc); +void +database_type_print(Eolian_Type type); + #endif --
