aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2018-03-16 16:16:16 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2018-03-16 16:16:16 +0100
commit9610459502922a5a550a82e2430998b272f51d01 (patch)
treefca9ac984c48c479362f8d83713630730ab227cd
parenteolian: intial API for a new error mechanism (diff)
downloadefl-9610459502922a5a550a82e2430998b272f51d01.tar.gz
eolian: add APIs to get unit from object and state from unit
-rw-r--r--src/lib/eolian/Eolian.h34
-rw-r--r--src/lib/eolian/eo_parser.c1
-rw-r--r--src/lib/eolian/eolian_database.c14
-rw-r--r--src/lib/eolian/eolian_database.h1
4 files changed, 50 insertions, 0 deletions
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index 3e07f761dd..3f44929471 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -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
@@ -590,11 +591,27 @@ 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
@@ -841,6 +861,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.
*
* The iterator is obviously again to `const Eolian_Unit *`.
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 99ea9499e3..05200acd4a 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -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; \
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index 6db89eaa5b..86e66f116e 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -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)
{
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index eff2b966a5..8b58d65e54 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -75,6 +75,7 @@ struct _Eolian_State
struct _Eolian_Object
{
+ Eolian_Unit *unit;
Eina_Stringshare *file;
Eina_Stringshare *name;
int line;