eolian: add APIs to get unit from object and state from unit

This commit is contained in:
Daniel Kolesa 2018-03-16 16:16:16 +01:00
parent 60c733670d
commit 9610459502
4 changed files with 50 additions and 0 deletions

View File

@ -580,6 +580,7 @@ EAPI void *eolian_state_error_data_set(Eolian_State *state, void *data);
* them to Eolian_Object, store or manipulate them and then use this function
* to check their type in order to for example cast it back.
*
* @see eolian_object_unit_get
* @see eolian_object_file_get
* @see eolian_object_line_get
* @see eolian_object_column_get
@ -589,12 +590,28 @@ EAPI void *eolian_state_error_data_set(Eolian_State *state, void *data);
*/
EAPI Eolian_Object_Type eolian_object_type_get(const Eolian_Object *obj);
/*
* @brief Get the unit the object comes from.
*
* This returns the unit the object is located in.
*
* @see eolian_object_file_get
* @see eolian_object_type_get
* @see eolian_object_line_get
* @see eolian_object_column_get
* @see eolian_object_name_get
*
* @ingroup Eolian
*/
EAPI const Eolian_Unit *eolian_object_unit_get(const Eolian_Object *obj);
/*
* @brief Get the name of the file the object comes from.
*
* This returns the name of the file the object was declared in. It's not
* a full path, just the file name.
*
* @see eolian_object_unit_get
* @see eolian_object_type_get
* @see eolian_object_line_get
* @see eolian_object_column_get
@ -609,6 +626,7 @@ EAPI const char *eolian_object_file_get(const Eolian_Object *obj);
*
* This returns the line number in the file the object was declared at.
*
* @see eolian_object_unit_get
* @see eolian_object_type_get
* @see eolian_object_file_get
* @see eolian_object_column_get
@ -626,6 +644,7 @@ EAPI int eolian_object_line_get(const Eolian_Object *obj);
* assumes all input files are encoded in UTF-8, so this is really the
* code point number, not the byte number.
*
* @see eolian_object_unit_get
* @see eolian_object_type_get
* @see eolian_object_file_get
* @see eolian_object_line_get
@ -642,6 +661,7 @@ EAPI int eolian_object_column_get(const Eolian_Object *obj);
* For toplevel file declarations, this will be the fully namespaced
* name, for things like params this will be just the name itself.
*
* @see eolian_object_unit_get
* @see eolian_object_type_get
* @see eolian_object_file_get
* @see eolian_object_line_get
@ -840,6 +860,20 @@ 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 the state associated with the unit.
*
* Technically you can cast away the const to make the state mutable
* again, it's the same pointer after all. But this is considered a
* bad practice, because you're only supposed to use mutable objects
* at the very beginning and then just read.
*
* @param[in] unit The unit.
*
* @ingroup Eolian
*/
EAPI const Eolian_State *eolian_unit_state_get(const Eolian_Unit *unit);
/*
* @brief Get the children (dependencies) of a unit.
*

View File

@ -13,6 +13,7 @@
has_##var = EINA_TRUE;
#define FILL_BASE(exp, ls, l, c, tp) \
(exp).unit = ls->unit; \
(exp).file = eina_stringshare_ref(ls->filename); \
(exp).line = l; \
(exp).column = c; \

View File

@ -25,6 +25,13 @@ eolian_object_type_get(const Eolian_Object *obj)
return obj->type;
}
EAPI const Eolian_Unit *
eolian_object_unit_get(const Eolian_Object *obj)
{
if (!obj) return NULL;
return obj->unit;
}
EAPI const char *
eolian_object_file_get(const Eolian_Object *obj)
{
@ -1013,6 +1020,13 @@ eolian_state_enums_by_file_get(const Eolian_State *state, const char *file_name)
return eina_list_iterator_new(l);
}
EAPI const Eolian_State *
eolian_unit_state_get(const Eolian_Unit *unit)
{
if (!unit) return NULL;
return unit->state;
}
EAPI Eina_Iterator *
eolian_unit_children_get(const Eolian_Unit *unit)
{

View File

@ -75,6 +75,7 @@ struct _Eolian_State
struct _Eolian_Object
{
Eolian_Unit *unit;
Eina_Stringshare *file;
Eina_Stringshare *name;
int line;