eolian: allow multiple subtypes by reorganizing the type structure - preparation for new API
This commit is contained in:
parent
275103e1b0
commit
74d0cbf29b
|
@ -54,7 +54,7 @@ typedef struct _Function_Id* Eolian_Function;
|
|||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
typedef Eina_Inlist* Eolian_Type;
|
||||
typedef struct _Parameter_Type* Eolian_Type;
|
||||
|
||||
/* Class function parameter information
|
||||
*
|
||||
|
@ -492,22 +492,6 @@ EAPI const Eina_List *eolian_parameters_list_get(Eolian_Function function_id);
|
|||
*/
|
||||
EAPI void eolian_parameter_information_get(const Eolian_Function_Parameter param_desc, Eolian_Parameter_Dir *param_dir, const char **type, const char **name, const char **description);
|
||||
|
||||
/*
|
||||
* @brief Get information on given type.
|
||||
*
|
||||
* An Eolian type is an inlist of basic C types. For example:
|
||||
* Eina_List * <Eo *> contains two basic types.
|
||||
* The first Eolian type of the list stores Eina_List *, the next one Eo *.
|
||||
*
|
||||
* @param[in] etype Eolian type
|
||||
* @param[out] type C type
|
||||
* @param[out] own indicates if the ownership has to pass to the caller/callee.
|
||||
* @return the next type of the list.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eolian_Type eolian_type_information_get(Eolian_Type etype, const char **type, Eina_Bool *own);
|
||||
|
||||
/*
|
||||
* @brief Get type of a parameter
|
||||
*
|
||||
|
|
|
@ -193,8 +193,8 @@ parse_ptr:
|
|||
}
|
||||
}
|
||||
|
||||
static Eina_Inlist *
|
||||
parse_type(Eo_Lexer *ls, Eina_Inlist *types, Eina_Strbuf *sbuf)
|
||||
static Eolian_Type
|
||||
parse_type(Eo_Lexer *ls, Eolian_Type type, Eina_Strbuf *sbuf)
|
||||
{
|
||||
Eina_Bool is_own = EINA_FALSE;
|
||||
Eina_Strbuf *buf = sbuf ? sbuf : push_strbuf(ls);
|
||||
|
@ -210,8 +210,8 @@ parse_type(Eo_Lexer *ls, Eina_Inlist *types, Eina_Strbuf *sbuf)
|
|||
|
||||
if (!sbuf)
|
||||
{
|
||||
types = database_type_append(types, eina_strbuf_string_get(buf), is_own);
|
||||
ls->tmp.type = types;
|
||||
type = database_type_append(type, eina_strbuf_string_get(buf), is_own);
|
||||
ls->tmp.type = type;
|
||||
pop_strbuf(ls);
|
||||
}
|
||||
|
||||
|
@ -220,12 +220,15 @@ parse_type(Eo_Lexer *ls, Eina_Inlist *types, Eina_Strbuf *sbuf)
|
|||
int line = ls->line_number;
|
||||
if (sbuf) eina_strbuf_append(buf, " <");
|
||||
eo_lexer_get(ls);
|
||||
types = parse_type(ls, types, sbuf);
|
||||
parse_type(ls, type, sbuf);
|
||||
while (test_next(ls, ','))
|
||||
parse_type(ls, type, buf);
|
||||
parse_type(ls, type, sbuf);
|
||||
check_match(ls, '>', '<', line);
|
||||
if (sbuf) eina_strbuf_append_char(buf, '>');
|
||||
}
|
||||
|
||||
return types;
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -916,21 +919,22 @@ parse_chunk(Eo_Lexer *ls, Eina_Bool eot)
|
|||
static char *_accessor_type_str[ACCESSOR_TYPE_LAST] = { "setter", "getter" };
|
||||
static char * _param_way_str[ PARAM_WAY_LAST] = { "IN", "OUT", "INOUT" };
|
||||
|
||||
static void
|
||||
_print_type(FILE *f, Eolian_Type tp)
|
||||
typedef struct
|
||||
{
|
||||
const char *type;
|
||||
Eina_Bool own;
|
||||
Eolian_Type ntp = eolian_type_information_get(tp, &type, &own);
|
||||
if (own)
|
||||
fputs("@own ", f);
|
||||
fputs(type, f);
|
||||
if (ntp)
|
||||
{
|
||||
fputc('<', f);
|
||||
_print_type(f, ntp);
|
||||
fputc('>', f);
|
||||
}
|
||||
Eina_List *subtypes;
|
||||
Eina_Stringshare *name;
|
||||
Eina_Bool is_own :1;
|
||||
} _Parameter_Type;
|
||||
|
||||
static void
|
||||
_print_type(FILE *f, _Parameter_Type *tp)
|
||||
{
|
||||
Eina_List *l;
|
||||
Eolian_Type stp;
|
||||
fprintf(f, "%s%s<", tp->name, tp->is_own ? "@own " : "");
|
||||
EINA_LIST_FOREACH(tp->subtypes, l, stp)
|
||||
_type_print(f, stp);
|
||||
fputc('>', f);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -77,7 +77,7 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
EINA_INLIST;
|
||||
Eina_List *subtypes;
|
||||
Eina_Stringshare *name;
|
||||
Eina_Bool is_own :1; /* True if the ownership of this argument passes to the caller/callee */
|
||||
} _Parameter_Type;
|
||||
|
@ -107,13 +107,13 @@ _param_del(_Parameter_Desc *pdesc)
|
|||
void
|
||||
database_type_del(Eolian_Type type)
|
||||
{
|
||||
while (type)
|
||||
{
|
||||
_Parameter_Type *ptype = (_Parameter_Type *) type;
|
||||
eina_stringshare_del(ptype->name);
|
||||
type = eina_inlist_remove(type, EINA_INLIST_GET(ptype));
|
||||
free(ptype);
|
||||
}
|
||||
_Parameter_Type *typep = (_Parameter_Type*)type;
|
||||
Eolian_Type stype;
|
||||
if (!type) return;
|
||||
EINA_LIST_FREE(typep->subtypes, stype)
|
||||
database_type_del(stype);
|
||||
eina_stringshare_del(typep->name);
|
||||
free(typep);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -890,25 +890,19 @@ eolian_parameter_types_list_get(const Eolian_Function_Parameter param_desc)
|
|||
return param->type;
|
||||
}
|
||||
|
||||
EAPI Eolian_Type
|
||||
eolian_type_information_get(Eolian_Type list, const char **name, Eina_Bool *own)
|
||||
{
|
||||
_Parameter_Type *type = (_Parameter_Type *)list;
|
||||
if (name) *name = type->name;
|
||||
if (own) *own = type->is_own;
|
||||
return list->next;
|
||||
}
|
||||
|
||||
Eolian_Type
|
||||
database_type_append(Eolian_Type types, const char *name, Eina_Bool own)
|
||||
database_type_append(Eolian_Type type, const char *name, Eina_Bool own)
|
||||
{
|
||||
_Parameter_Type *type = calloc(1, sizeof(*type));
|
||||
type->name = eina_stringshare_add(name);
|
||||
type->is_own = own;
|
||||
if (types)
|
||||
return eina_inlist_append(types, EINA_INLIST_GET(type));
|
||||
else
|
||||
return EINA_INLIST_GET(type);
|
||||
_Parameter_Type *stypep = calloc(1, sizeof(*stypep));
|
||||
stypep->name = eina_stringshare_add(name);
|
||||
stypep->is_own = own;
|
||||
if (type)
|
||||
{
|
||||
_Parameter_Type *typep = (_Parameter_Type*)type;
|
||||
typep->subtypes = eina_list_append(typep->subtypes, stypep);
|
||||
return type;
|
||||
}
|
||||
return (Eolian_Type)stypep;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1192,6 +1186,18 @@ _event_print(Eolian_Event ev, int nb_spaces)
|
|||
printf("%*s <%s> <%s> <%s>\n", nb_spaces + 5, "", name, type, comment);
|
||||
}
|
||||
|
||||
static void
|
||||
_type_print(Eolian_Type tp, Eina_Strbuf *buf)
|
||||
{
|
||||
_Parameter_Type *tpp = (_Parameter_Type*)tp;
|
||||
Eina_List *l;
|
||||
Eolian_Type stp;
|
||||
eina_strbuf_append_printf(buf, "%s%s<", tpp->name, tpp->is_own ? "@own" : "");
|
||||
EINA_LIST_FOREACH(tpp->subtypes, l, stp)
|
||||
_type_print(stp, buf);
|
||||
eina_strbuf_append_char(buf, '>');
|
||||
}
|
||||
|
||||
static Eina_Bool _function_print(const _Function_Id *fid, int nb_spaces)
|
||||
{
|
||||
Eolian_Function foo_id = (Eolian_Function) fid;
|
||||
|
@ -1282,16 +1288,7 @@ static Eina_Bool _function_print(const _Function_Id *fid, int nb_spaces)
|
|||
break;
|
||||
}
|
||||
Eina_Strbuf *type_buf = eina_strbuf_new();
|
||||
Eolian_Type type = param->type;
|
||||
while (type)
|
||||
{
|
||||
const char *type_str = NULL;
|
||||
Eina_Bool is_own = EINA_FALSE;
|
||||
type = eolian_type_information_get(type, &type_str, &is_own);
|
||||
eina_strbuf_append_printf(type_buf, "%s%s%s",
|
||||
eina_strbuf_length_get(type_buf)?"/":"",
|
||||
type_str, is_own?"@own":"");
|
||||
}
|
||||
_type_print(param->type, type_buf);
|
||||
printf("%*s%s <%s> <%s> <%s>\n", nb_spaces + 5, "",
|
||||
param_dir, param->name,
|
||||
eina_strbuf_string_get(type_buf),
|
||||
|
|
|
@ -89,7 +89,7 @@ Eolian_Function_Parameter database_property_value_add(Eolian_Function foo_id, Eo
|
|||
/* Add a parameter to a method */
|
||||
Eolian_Function_Parameter database_method_parameter_add(Eolian_Function foo_id, Eolian_Parameter_Dir param_dir, Eolian_Type type, const char *name, const char *description);
|
||||
|
||||
Eolian_Type database_type_append(Eolian_Type types, const char *name, Eina_Bool own);
|
||||
Eolian_Type database_type_append(Eolian_Type type, const char *name, Eina_Bool own);
|
||||
|
||||
void database_type_del(Eolian_Type type);
|
||||
|
||||
|
|
Loading…
Reference in New Issue