From 53aa99550d5b3351d85f3031e6a5baa34be38756 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sun, 3 Dec 2017 21:10:44 +0100 Subject: [PATCH] eolian: add API for master unit creation --- src/lib/eolian/Eolian.h | 26 ++++++++++++++++++++++++++ src/lib/eolian/eolian_database.c | 32 +++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index 6774d6b6b4..d11d4f3904 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -522,6 +522,32 @@ EAPI int eolian_init(void); */ EAPI int eolian_shutdown(void); +/* + * @brief Create a new primary unit for Eolian state. + * + * 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). + * + * @ingroup Eolian + */ +EAPI Eolian_Unit *eolian_new(void); + +/* + * @brief Free a master unit. + * + * 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. + * + * If the input is NULL, this function has no effect. + * + * @param[in] unit the master unit to free + * + */ +EAPI void eolian_free(Eolian_Unit *unit); + /* * @brief Scan the given directory (recursively) and search for .eo and * .eot files. diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c index 59cebfa202..80af933947 100644 --- a/src/lib/eolian/eolian_database.c +++ b/src/lib/eolian/eolian_database.c @@ -602,10 +602,13 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, void database_unit_init(Eolian_Unit *unit, Eina_Stringshare *fname) { - Eolian_Unit *ocunit = _cunit; - unit->parent = ocunit; - if (ocunit) - eina_hash_add(ocunit->children, fname, unit); + if (fname) + { + Eolian_Unit *ocunit = _cunit; + unit->parent = ocunit; + if (ocunit) + eina_hash_add(ocunit->children, fname, unit); + } unit->children = eina_hash_stringshared_new(NULL); unit->classes = eina_hash_stringshared_new(NULL); @@ -614,7 +617,9 @@ database_unit_init(Eolian_Unit *unit, Eina_Stringshare *fname) unit->aliases = eina_hash_stringshared_new(NULL); unit->structs = eina_hash_stringshared_new(NULL); unit->enums = eina_hash_stringshared_new(NULL); - _cunit = unit; + + if (fname) + _cunit = unit; } void @@ -631,6 +636,23 @@ database_unit_del(Eolian_Unit *unit) eina_hash_free(unit->enums); } +EAPI Eolian_Unit * +eolian_new(void) +{ + Eolian_Unit *nunit = calloc(1, sizeof(Eolian_Unit)); + if (!nunit) + return NULL; + + database_unit_init(nunit, NULL); + return nunit; +} + +EAPI void +eolian_free(Eolian_Unit *unit) +{ + database_unit_del(unit); +} + #define EO_SUFFIX ".eo" #define EOT_SUFFIX ".eot"