q66 pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=917a5216f87667374cb8bba1c60a92390fe5050f

commit 917a5216f87667374cb8bba1c60a92390fe5050f
Author: Daniel Kolesa <[email protected]>
Date:   Thu Mar 8 18:59:37 2018 +0100

    eolian: add APIs to retrieve declarations as objects
    
    This will replace the old declarations API.
---
 src/lib/eolian/Eolian.h          | 66 ++++++++++++++++++++++++++++++++++++++++
 src/lib/eolian/eolian_database.c | 49 ++++++++++++++++++++++++++++-
 src/lib/eolian/eolian_database.h |  2 ++
 3 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index e74832f70c..f8bea89811 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -745,6 +745,46 @@ EAPI const Eolian_Unit 
*eolian_state_unit_by_file_get(const Eolian_State *state,
 EAPI Eina_Iterator *eolian_state_units_get(const Eolian_State *state);
 
 /*
+ * @brief Get an object in a state by name.
+ *
+ * Only objects declared directly within the file can be retrieved, i.e.
+ * classes, typedecls and variables.
+ *
+ * @param[in] state The state.
+ * @param[in] name The fully namespaced object name.
+ *
+ * @ingroup Eolian
+ */
+EAPI const Eolian_Object *eolian_state_object_by_name_get(const Eolian_State 
*state, const char *name);
+
+/*
+ * @brief Get a list of objects from a file.
+ *
+ * The list follows declaration order in the file. Only objects declared
+ * directly within the file can be retrieved, i.e. classes, typedecls and
+ * variables.
+ *
+ * @param[in] state The state.
+ * @param[in] file_name The file name.
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Iterator *eolian_state_objects_by_file_get(const Eolian_State 
*state, const char *file_name);
+
+/*
+ * @brief Get all objects in the state.
+ *
+ * The order is not necessarily the declaration order. Only objects declared
+ * directly within the file can be retrieved, i.e. classes, typedecls and
+ * variables.
+ *
+ * @param[in] state The state.
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Iterator *eolian_state_objects_get(const Eolian_State *state);
+
+/*
  * @brief Get a class within a state by name.
  *
  * @param[in] state The state.
@@ -963,6 +1003,32 @@ EAPI Eina_Iterator *eolian_unit_children_get(const 
Eolian_Unit *unit);
 EAPI const char *eolian_unit_file_get(const Eolian_Unit *unit);
 
 /*
+ * @brief Get an object in a unit by name.
+ *
+ * Only objects declared directly within the file can be retrieved, i.e.
+ * classes, typedecls and variables.
+ *
+ * @param[in] unit The unit.
+ * @param[in] name The fully namespaced object name.
+ *
+ * @ingroup Eolian
+ */
+EAPI const Eolian_Object *eolian_unit_object_by_name_get(const Eolian_Unit 
*unit, const char *name);
+
+/*
+ * @brief Get all objects in the unit.
+ *
+ * The order is not necessarily the declaration order. Only objects declared
+ * directly within the file can be retrieved, i.e. classes, typedecls and
+ * variables.
+ *
+ * @param[in] unit The unit.
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Iterator *eolian_unit_objects_get(const Eolian_Unit *unit);
+
+/*
  * @brief Get a class within a unit by name.
  *
  * @param[in] unit The unit.
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index 8e3d77fbaa..e9bfd98066 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -22,7 +22,12 @@ database_decl_add(Eolian_Unit *unit, Eina_Stringshare *name,
    decl->data = ptr;
    EOLIAN_OBJECT_ADD(unit, name, decl, decls);
    eina_hash_set(unit->state->decls_f, file, eina_list_append
-                 ((Eina_List*)eina_hash_find(unit->state->decls_f, file), 
decl));
+                 ((Eina_List *)eina_hash_find(unit->state->decls_f, file), 
decl));
+   /* object storage */
+   eina_hash_add(unit->objects, name, ptr);
+   eina_hash_add(unit->state->unit.objects, name, ptr);
+   eina_hash_set(unit->state->objects_f, file, eina_list_append
+                 ((Eina_List *)eina_hash_find(unit->state->objects_f, file), 
ptr));
 }
 
 static void
@@ -526,6 +531,7 @@ database_unit_init(Eolian_State *state, Eolian_Unit *unit, 
const char *file)
    unit->aliases    = 
eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
    unit->structs    = 
eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
    unit->enums      = 
eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
+   unit->objects    = eina_hash_stringshared_new(NULL);
    unit->decls      = 
eina_hash_stringshared_new(EINA_FREE_CB(database_decl_del));
 }
 
@@ -542,6 +548,7 @@ database_unit_del(Eolian_Unit *unit)
    eina_hash_free(unit->aliases);
    eina_hash_free(unit->structs);
    eina_hash_free(unit->enums);
+   eina_hash_free(unit->objects);
    eina_hash_free(unit->decls);
 }
 
@@ -572,6 +579,7 @@ eolian_state_new(void)
    state->enums_f     = eina_hash_stringshared_new(_hashlist_free);
    state->globals_f   = eina_hash_stringshared_new(_hashlist_free);
    state->constants_f = eina_hash_stringshared_new(_hashlist_free);
+   state->objects_f   = eina_hash_stringshared_new(_hashlist_free);
    state->decls_f     = eina_hash_stringshared_new(_hashlist_free);
 
    return state;
@@ -597,6 +605,7 @@ eolian_state_free(Eolian_State *state)
    eina_hash_free(state->enums_f);
    eina_hash_free(state->globals_f);
    eina_hash_free(state->constants_f);
+   eina_hash_free(state->objects_f);
    eina_hash_free(state->decls_f);
 
    free(state);
@@ -908,6 +917,29 @@ eolian_state_units_get(const Eolian_State *state)
    return eina_hash_iterator_data_new(state->units);
 }
 
+EAPI const Eolian_Object *
+eolian_state_object_by_name_get(const Eolian_State *state, const char *name)
+{
+   return eolian_unit_object_by_name_get((Eolian_Unit *)state, name);
+}
+
+EAPI Eina_Iterator *
+eolian_state_objects_by_file_get(const Eolian_State *state, const char 
*file_name)
+{
+   if (!state) return NULL;
+   Eina_Stringshare *shr = eina_stringshare_add(file_name);
+   Eina_List *l = eina_hash_find(state->objects_f, shr);
+   eina_stringshare_del(shr);
+   if (!l) return NULL;
+   return eina_list_iterator_new(l);
+}
+
+EAPI Eina_Iterator *
+eolian_state_objects_get(const Eolian_State *state)
+{
+   return eolian_unit_objects_get((Eolian_Unit *)state);
+}
+
 EAPI const Eolian_Class *
 eolian_state_class_by_name_get(const Eolian_State *state, const char 
*class_name)
 {
@@ -1059,6 +1091,21 @@ eolian_unit_file_get(const Eolian_Unit *unit)
    return unit->file;
 }
 
+EAPI const Eolian_Object *
+eolian_unit_object_by_name_get(const Eolian_Unit *unit, const char *name)
+{
+   if (!unit) return NULL;
+   Eina_Stringshare *shr = eina_stringshare_add(name);
+   Eolian_Object *o = eina_hash_find(unit->objects, shr);
+   eina_stringshare_del(shr);
+   return o;
+}
+
+EAPI Eina_Iterator *eolian_unit_objects_get(const Eolian_Unit *unit)
+{
+   return (unit ? eina_hash_iterator_data_new(unit->objects) : NULL);
+}
+
 EAPI const Eolian_Class *
 eolian_unit_class_by_name_get(const Eolian_Unit *unit, const char *class_name)
 {
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 556cfce1ba..aac5cde699 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -42,6 +42,7 @@ struct _Eolian_Unit
    Eina_Hash     *aliases;
    Eina_Hash     *structs;
    Eina_Hash     *enums;
+   Eina_Hash     *objects;
    Eina_Hash     *decls;
 };
 
@@ -61,6 +62,7 @@ struct _Eolian_State
    Eina_Hash *enums_f;
    Eina_Hash *globals_f;
    Eina_Hash *constants_f;
+   Eina_Hash *objects_f;
    Eina_Hash *decls_f;
 };
 

-- 


Reply via email to