q66 pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=295f1f48474d88fbb3bc797495282650f2289446
commit 295f1f48474d88fbb3bc797495282650f2289446 Author: Daniel Kolesa <[email protected]> Date: Wed Jul 9 12:05:56 2014 +0100 eolian: new API: eolian_type_struct_field_description_get --- src/lib/eolian/Eolian.h | 12 ++++++++++++ src/lib/eolian/eo_definitions.c | 7 +++++++ src/lib/eolian/eo_definitions.h | 11 ++++++++++- src/lib/eolian/eo_parser.c | 11 ++++++++--- src/lib/eolian/eolian_database.c | 30 ++++++++++++++++++++++++++++-- 5 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index 7c3f4df..6a32215 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -783,6 +783,18 @@ EAPI Eina_Iterator *eolian_type_struct_field_names_list_get(Eolian_Type tp); EAPI Eolian_Type eolian_type_struct_field_get(Eolian_Type tp, const char *field); /* + * @brief Get the description of a field of a struct type. + * + * @param[in] tp the type. + * @param[in] field the field name. + * @return the description when @c tp is EOLIAN_TYPE_STRUCT, @c field is not NULL + * and the field exists, NULL otherwise. + * + * @ingroup Eolian + */ +EAPI const char *eolian_type_struct_field_description_get(Eolian_Type tp, const char *field); + +/* * @brief Get the return type of a function type. * * @param[in] tp the type. diff --git a/src/lib/eolian/eo_definitions.c b/src/lib/eolian/eo_definitions.c index cb86ddd..5f29a74 100644 --- a/src/lib/eolian/eo_definitions.c +++ b/src/lib/eolian/eo_definitions.c @@ -4,6 +4,13 @@ #include "eo_definitions.h" void +eo_definitions_struct_field_free(Eo_Struct_Field_Def *def) +{ + eo_definitions_type_free(def->type); + if (def->comment) eina_stringshare_del(def->comment); +} + +void eo_definitions_type_free(Eo_Type_Def *tp) { Eo_Type_Def *stp; diff --git a/src/lib/eolian/eo_definitions.h b/src/lib/eolian/eo_definitions.h index ebb1d2f..60a7cd7 100644 --- a/src/lib/eolian/eo_definitions.h +++ b/src/lib/eolian/eo_definitions.h @@ -4,7 +4,7 @@ #include <Eina.h> #include <Eolian.h> -/* RET */ +/* TYPE */ typedef struct _eo_type_def Eo_Type_Def; struct _eo_type_def @@ -26,6 +26,14 @@ struct _eo_type_def Eina_Bool is_own :1; }; +typedef struct _eo_struct_field_def +{ + Eo_Type_Def *type; + const char *comment; +} Eo_Struct_Field_Def; + +/* RET */ + typedef struct _eo_ret_def { Eo_Type_Def *type; @@ -171,6 +179,7 @@ typedef struct _Eo_Lexer_Temps Eo_Implement_Def *impl; } Eo_Lexer_Temps; +void eo_definitions_struct_field_free(Eo_Struct_Field_Def *def); void eo_definitions_type_free(Eo_Type_Def *tp); void eo_definitions_class_def_free(Eo_Class_Def *kls); void eo_definitions_typedef_def_free(Eo_Typedef_Def *type); diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index fba9717..d204756 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -229,24 +229,29 @@ parse_struct(Eo_Lexer *ls, const char *name) Eo_Type_Def *def = push_type(ls); def->name = name; def->type = EOLIAN_TYPE_STRUCT; - def->fields = eina_hash_string_small_new(EINA_FREE_CB(eo_definitions_type_free)); + def->fields = eina_hash_string_small_new(EINA_FREE_CB(eo_definitions_struct_field_free)); check_next(ls, '{'); while (ls->t.token != '}') { const char *fname; + Eo_Struct_Field_Def *fdef; + Eo_Type_Def *tp; check(ls, TOK_VALUE); if (eina_hash_find(def->fields, ls->t.value)) eo_lexer_syntax_error(ls, "double field definition"); fname = eina_stringshare_add(ls->t.value); eo_lexer_get(ls); check_next(ls, ':'); - eina_hash_add(def->fields, fname, parse_type_struct_nonvoid(ls, - EINA_TRUE, EINA_FALSE)); + tp = parse_type_struct_nonvoid(ls, EINA_TRUE, EINA_FALSE); + fdef = calloc(1, sizeof(Eo_Struct_Field_Def)); + fdef->type = tp; + eina_hash_add(def->fields, fname, fdef); pop_type(ls); eina_stringshare_del(fname); check_next(ls, ';'); if (ls->t.token == TOK_COMMENT) { + fdef->comment = eina_stringshare_add(ls->t.value); eo_lexer_get(ls); } } diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c index 0d890b7..a5dc46c 100644 --- a/src/lib/eolian/eolian_database.c +++ b/src/lib/eolian/eolian_database.c @@ -77,6 +77,13 @@ typedef struct } _Parameter_Desc; /* maps directly to Eo_Type_Def */ + +typedef struct +{ + Eolian_Type type; + const char *comment; +} _Struct_Field_Type; + typedef struct { const char *name; @@ -1190,12 +1197,30 @@ EAPI Eolian_Type eolian_type_struct_field_get(Eolian_Type tp, const char *field) { _Parameter_Type *tpp = (_Parameter_Type*)tp; + _Struct_Field_Type *sf = NULL; + Eolian_Type_Type tpt; + EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL); + tpt = tpp->type; + EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt == EOLIAN_TYPE_STRUCT, NULL); + sf = eina_hash_find(tpp->fields, field); + if (!sf) return NULL; + return sf->type; +} + +EAPI const char * +eolian_type_struct_field_description_get(Eolian_Type tp, const char *field) +{ + _Parameter_Type *tpp = (_Parameter_Type*)tp; + _Struct_Field_Type *sf = NULL; Eolian_Type_Type tpt; EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL); tpt = tpp->type; EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt == EOLIAN_TYPE_STRUCT, NULL); - return eina_hash_find(tpp->fields, field); + sf = eina_hash_find(tpp->fields, field); + if (!sf) return NULL; + return sf->comment; } EAPI Eolian_Type @@ -1258,7 +1283,8 @@ static Eina_Bool _stype_field_cb(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, void *fdata) { - _type_to_str((Eolian_Type)data, (Eina_Strbuf*)fdata, (const char*)key); + _type_to_str((Eolian_Type)((_Struct_Field_Type*)data)->type, + (Eina_Strbuf*)fdata, (const char*)key); eina_strbuf_append((Eina_Strbuf*)fdata, "; "); return EINA_TRUE; } --
