From e58da1faa0f8fb5321eddfbcc623f43732ea0006 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Mon, 1 Jun 2015 14:48:50 +0100 Subject: [PATCH] eolian: add actual useful declaration APIs --- src/lib/eolian/Eolian.h | 53 ++++++++++++++++++++++++++++++++++++++++ src/lib/eolian/eolian_database.c | 42 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index 8d2b7de..b9ca6db 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -310,6 +310,7 @@ typedef enum typedef enum { + EOLIAN_DECL_UNKNOWN = -1, EOLIAN_DECL_CLASS, EOLIAN_DECL_ALIAS, EOLIAN_DECL_STRUCT, @@ -2070,6 +2071,58 @@ EAPI Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var); */ EAPI Eina_Iterator *eolian_declarations_get_by_file(const char *fname); +/* + * @brief Get the type of a declaration + * + * @param[in] decl the declaration + * @return the declaration type + * + * @ingroup Eolian + */ +EAPI Eolian_Declaration_Type eolian_declaration_type_get(const Eolian_Declaration *decl); + +/* + * @brief Get the name of a declaration + * + * This matches the full namespaced name of the data it's holding. + * + * @param[in] decl the declaration + * @return the declaration name + * + * @ingroup Eolian + */ +EAPI Eina_Stringshare *eolian_declaration_name_get(const Eolian_Declaration *decl); + +/* + * @brief Get the class of a class declaration. + * + * @param[in] decl the declaration + * @return the class + * + * @ingroup Eolian + */ +EAPI const Eolian_Class *eolian_declaration_class_get(const Eolian_Declaration *decl); + +/* + * @brief Get the type of a type (alias, struct, enum) declaration. + * + * @param[in] decl the declaration + * @return the type + * + * @ingroup Eolian + */ +EAPI const Eolian_Type *eolian_declaration_data_type_get(const Eolian_Declaration *decl); + +/* + * @brief Get the variable of a variable (constant, global) declaration. + * + * @param[in] decl the declaration + * @return the class + * + * @ingroup Eolian + */ +EAPI const Eolian_Variable *eolian_declaration_variable_get(const Eolian_Declaration *decl); + #endif /** diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c index 2deecca..ceca0e3 100644 --- a/src/lib/eolian/eolian_database.c +++ b/src/lib/eolian/eolian_database.c @@ -120,6 +120,48 @@ eolian_declarations_get_by_file(const char *fname) return eina_list_iterator_new(l); } +EAPI Eolian_Declaration_Type +eolian_declaration_type_get(const Eolian_Declaration *decl) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(decl, EOLIAN_DECL_UNKNOWN); + return decl->type; +} + +EAPI Eina_Stringshare * +eolian_declaration_name_get(const Eolian_Declaration *decl) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL); + return decl->name; +} + +EAPI const Eolian_Class * +eolian_declaration_class_get(const Eolian_Declaration *decl) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL); + EINA_SAFETY_ON_FALSE_RETURN_VAL(decl->type == EOLIAN_DECL_CLASS, NULL); + return (const Eolian_Class *)decl->data; +} + +EAPI const Eolian_Type * +eolian_declaration_data_type_get(const Eolian_Declaration *decl) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL); + EINA_SAFETY_ON_FALSE_RETURN_VAL(decl->type == EOLIAN_DECL_ALIAS || + decl->type == EOLIAN_DECL_STRUCT || + decl->type == EOLIAN_DECL_ENUM, NULL); + return (const Eolian_Type *)decl->data; +} + + +EAPI const Eolian_Variable * +eolian_declaration_variable_get(const Eolian_Declaration *decl) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL); + EINA_SAFETY_ON_FALSE_RETURN_VAL(decl->type == EOLIAN_DECL_VAR, NULL); + return (const Eolian_Variable *)decl->data; +} + + #define EO_SUFFIX ".eo" #define EOT_SUFFIX ".eot" -- 2.7.4