eolian: support for typedefs in c_type_get

This commit is contained in:
Daniel Kolesa 2014-07-22 12:11:06 +01:00
parent 2942d4bdfa
commit b0788a546b
3 changed files with 45 additions and 4 deletions

View File

@ -928,7 +928,8 @@ EAPI Eina_Bool eolian_type_is_extern(const Eolian_Type *tp);
* Providing the name is useful for function types, as in C a function
* pointer type alone is not valid syntax. For non-function types, the
* name is simply appended to the type (with a space). C type names do
* not include subtypes as C doesn't support them.
* not include subtypes as C doesn't support them. Name is ignored for
* alias types. Alias types are turned into C typedefs.
*
* Keep in mind that if @c name is NULL, the name won't be included.
*

View File

@ -105,10 +105,35 @@ _stype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
}
}
static void
_atype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf)
{
Eina_Strbuf *fulln = eina_strbuf_new();
Eina_List *l;
const char *sp;
eina_strbuf_append(buf, "typedef ");
EINA_LIST_FOREACH(tp->namespaces, l, sp)
{
eina_strbuf_append(fulln, sp);
eina_strbuf_append_char(fulln, '_');
}
eina_strbuf_append(fulln, tp->name);
database_type_to_str(tp->base_type, buf, eina_strbuf_string_get(fulln));
eina_strbuf_free(fulln);
}
void
database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
{
if (tp->type == EOLIAN_TYPE_FUNCTION)
if (tp->type == EOLIAN_TYPE_ALIAS)
{
_atype_to_str(tp, buf);
return;
}
else if (tp->type == EOLIAN_TYPE_FUNCTION)
{
_ftype_to_str(tp, buf, name);
return;
@ -169,21 +194,33 @@ _print_field(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data,
return EINA_TRUE;
}
static void
_typedef_print(Eolian_Type *tp)
{
printf("type %s: ", tp->full_name);
database_type_print(tp->base_type);
}
void
database_type_print(Eolian_Type *tp)
{
Eina_List *l;
Eolian_Type *stp;
if (tp->type == EOLIAN_TYPE_ALIAS)
{
_typedef_print(tp);
return;
}
if (tp->is_own)
printf("own(");
if (tp->is_const)
printf("const(");
if (tp->type == EOLIAN_TYPE_REGULAR)
printf("%s", tp->name);
printf("%s", tp->full_name);
else if (tp->type == EOLIAN_TYPE_VOID)
printf("void");
else if (tp->type == EOLIAN_TYPE_REGULAR_STRUCT)
printf("struct %s", tp->name);
printf("struct %s", tp->full_name);
else if (tp->type == EOLIAN_TYPE_POINTER)
{
database_type_print(tp->base_type);

View File

@ -241,6 +241,9 @@ START_TEST(eolian_typedef)
fail_if(!(type_name = eolian_type_name_get(atype)));
fail_if(strcmp(type_name, "Coord"));
eina_stringshare_del(type_name);
fail_if(!(type_name = eolian_type_c_type_get(atype)));
fail_if(strcmp(type_name, "typedef int Evas_Coord"));
eina_stringshare_del(type_name);
fail_if(!(type = eolian_type_base_type_get(atype)));
fail_if(!(type_name = eolian_type_name_get(type)));
fail_if(eolian_type_is_own(type));