From 888dc3b6fe31c2a4787a5e5a8fc643b63500c48c Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 11 Jul 2014 13:10:04 +0100 Subject: [PATCH] eolian: remove eolian_show and replace it with variants for class/struct/typedef/all. --- src/bin/eolian/main.c | 2 +- src/lib/eolian/Eolian.h | 61 ++++++++++++++++++++++++- src/lib/eolian/database_print.c | 79 +++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 2 deletions(-) diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c index 8d1b6e52f1..469c738b0f 100644 --- a/src/bin/eolian/main.c +++ b/src/bin/eolian/main.c @@ -341,7 +341,7 @@ int main(int argc, char **argv) EINA_LIST_FOREACH(files4gen, itr, filename) { class = eolian_class_find_by_file(filename); - if (class) eolian_show(class); + if (class) eolian_show_class(class); } } diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index 764a16e391..6307d6fa71 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -222,9 +222,68 @@ EAPI Eina_Bool eolian_all_eot_files_parse(); * * @param[in] klass the class to show * + * @return EINA_TRUE on success, EINA_FALSE otherwise (currently always + * succeeds). + * + * @see eolian_show_typedef + * @see eolian_show_struct + * @see eolian_show_all + * * @ingroup Eolian */ -EAPI Eina_Bool eolian_show(const Eolian_Class *klass); +EAPI Eina_Bool eolian_show_class(const Eolian_Class *klass); + +/* + * @brief Show information about a given typedef. + * + * If @c alias is NULL, this function will print information of + * all the typedefs. + * + * @param[in] alias the typedef to show. + * + * @return EINA_TRUE on success, EINA_FALSE otherwise (when typedef is not + * found). + * + * @see eolian_show_class + * @see eolian_show_struct + * @see eolian_show_all + * + * @ingroup Eolian + */ +EAPI Eina_Bool eolian_show_typedef(const char *alias); + +/* + * @brief Show information about a given struct. + * + * If @c name is NULL, this function will print information of + * all the named global structs. + * + * @param[in] name the struct to show. + * + * @return EINA_TRUE on success, EINA_FALSE otherwise (when struct is not + * found). + * + * @see eolian_show_class + * @see eolian_show_typedef + * @see eolian_show_all + * + * @ingroup Eolian + */ +EAPI Eina_Bool eolian_show_struct(const char *name); + +/* + * @brief Show information about everything. + * + * This will print a complete dump of all information stored in the Eolian + * database. + * + * @see eolian_show_class + * @see eolian_show_typedef + * @see eolian_show_struct + * + * @ingroup Eolian + */ +EAPI void eolian_show_all(); /* * @brief Finds a class by its name diff --git a/src/lib/eolian/database_print.c b/src/lib/eolian/database_print.c index 274ff3c7fa..d10647c0d3 100644 --- a/src/lib/eolian/database_print.c +++ b/src/lib/eolian/database_print.c @@ -263,3 +263,82 @@ eolian_show(const Eolian_Class *class) } return EINA_TRUE; } + +EAPI Eina_Bool +eolian_show_class(const Eolian_Class *class) +{ + if (!class) + { + Eina_List *itr; + Eolian_Class *cl; + EINA_LIST_FOREACH(_classes, itr, cl) + _class_print(cl); + } + else + { + _class_print(class); + } + return EINA_TRUE; +} + +static Eina_Bool +_typedef_cb(Eina_Hash *hash EINA_UNUSED, const char *alias, + const Eolian_Typedef *tp, const void *fdata EINA_UNUSED) +{ + printf("Typedef: %s\n", alias); + printf(" type: <"); + database_type_print(tp->type); + printf(">\n"); + return EINA_TRUE; +} + +EAPI Eina_Bool +eolian_show_typedef(const char *alias) +{ + if (!alias) + eina_hash_foreach(_types, (Eina_Hash_Foreach)_typedef_cb, NULL); + else + { + Eina_Stringshare *shr = eina_stringshare_add(alias); + Eolian_Typedef *tp = eina_hash_find(_types, shr); + eina_stringshare_del(shr); + if (!tp) return EINA_FALSE; + _typedef_cb(NULL, alias, tp, NULL); + } + return EINA_TRUE; +} + +static Eina_Bool +_struct_cb(Eina_Hash *hash EINA_UNUSED, const char *name, + const Eolian_Type *tp, const void *fdata EINA_UNUSED) +{ + printf("Struct: %s\n", name); + printf(" type: <"); + database_type_print((Eolian_Type*)tp); + printf(">\n"); + return EINA_TRUE; +} + +EAPI Eina_Bool +eolian_show_struct(const char *name) +{ + if (!name) + eina_hash_foreach(_structs, (Eina_Hash_Foreach)_struct_cb, NULL); + else + { + Eina_Stringshare *shr = eina_stringshare_add(name); + Eolian_Type *tp = eina_hash_find(_structs, shr); + eina_stringshare_del(shr); + if (!tp) return EINA_FALSE; + _struct_cb(NULL, name, tp, NULL); + } + return EINA_TRUE; +} + +EAPI void +eolian_show_all() +{ + eolian_show_class(NULL); + eolian_show_typedef(NULL); + eolian_show_struct(NULL); +}