From e83e0897652bda4ecde28b7eeed7236c2b07ad39 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sun, 3 Dec 2017 21:18:20 +0100 Subject: [PATCH] eolian: contain master state in a larger structure --- src/lib/eolian/Eolian.h | 27 +++++++++++++++++---------- src/lib/eolian/eolian_database.c | 18 +++++++++++------- src/lib/eolian/eolian_database.h | 29 +++++++++++++++++------------ 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index d11d4f3..0e8b9d5 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -84,6 +84,12 @@ extern "C" { #ifdef EFL_BETA_API_SUPPORT +/* State information + * + * @ingroup Eolian + */ +typedef struct _Eolian Eolian; + /* Class type used to extract information on classes * * @ingroup Eolian @@ -523,30 +529,31 @@ EAPI int eolian_init(void); EAPI int eolian_shutdown(void); /* - * @brief Create a new primary unit for Eolian state. + * @brief Create a new Eolian state. + * + * This creates a new Eolian state that consists of a "master unit" with + * the same address (therefore, you can cast it to Eolian_Unit) plus extra + * state information. * - * This creates a nameless "master unit" which holds all Eolian state. * You need to free this with eolian_free once you're done. * - * @return A new master unit (or NULL on failure). + * @return A new state (or NULL on failure). * * @ingroup Eolian */ -EAPI Eolian_Unit *eolian_new(void); +EAPI Eolian *eolian_new(void); /* - * @brief Free a master unit. + * @brief Free an Eolian state. * - * You can use this to free an Eolian state. Do not EVER use this to free - * any unit other than master unit, as these are managed by the master unit - * and freeing them would result in incorrect behavior. + * You can use this to free an Eolian state. * * If the input is NULL, this function has no effect. * - * @param[in] unit the master unit to free + * @param[in] unit the state to free * */ -EAPI void eolian_free(Eolian_Unit *unit); +EAPI void eolian_free(Eolian *state); /* * @brief Scan the given directory (recursively) and search for .eo and diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c index 80af933..d2ae6a7 100644 --- a/src/lib/eolian/eolian_database.c +++ b/src/lib/eolian/eolian_database.c @@ -636,21 +636,25 @@ database_unit_del(Eolian_Unit *unit) eina_hash_free(unit->enums); } -EAPI Eolian_Unit * +EAPI Eolian * eolian_new(void) { - Eolian_Unit *nunit = calloc(1, sizeof(Eolian_Unit)); - if (!nunit) + Eolian *state = calloc(1, sizeof(Eolian)); + if (!state) return NULL; - database_unit_init(nunit, NULL); - return nunit; + database_unit_init(&state->unit, NULL); + return state; } EAPI void -eolian_free(Eolian_Unit *unit) +eolian_free(Eolian *state) { - database_unit_del(unit); + if (!state) + return; + + database_unit_del(&state->unit); + free(state); } #define EO_SUFFIX ".eo" diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h index 1ab61b0..e92cebd 100644 --- a/src/lib/eolian/eolian_database.h +++ b/src/lib/eolian/eolian_database.h @@ -59,6 +59,23 @@ extern Eina_Hash *_parsingeos; /* for deferred dependency parsing */ extern Eina_Hash *_defereos; +struct _Eolian_Unit +{ + Eolian_Unit *parent; + Eina_Hash *children; + Eina_Hash *classes; + Eina_Hash *globals; + Eina_Hash *constants; + Eina_Hash *aliases; + Eina_Hash *structs; + Eina_Hash *enums; +}; + +struct _Eolian +{ + Eolian_Unit unit; +}; + typedef struct _Eolian_Object { const char *file; @@ -294,18 +311,6 @@ struct _Eolian_Variable Eina_Bool is_extern :1; }; -struct _Eolian_Unit -{ - Eolian_Unit *parent; - Eina_Hash *children; - Eina_Hash *classes; - Eina_Hash *globals; - Eina_Hash *constants; - Eina_Hash *aliases; - Eina_Hash *structs; - Eina_Hash *enums; -}; - int database_init(void); int database_shutdown(void); -- 2.7.4