eolian: add EOLIAN_TYPE_REGULAR_STRUCT rather than including the struct keyword in name field

This commit is contained in:
Daniel Kolesa 2014-07-09 10:49:52 +01:00
parent 892c5cba5f
commit cc387bd621
3 changed files with 24 additions and 14 deletions

View File

@ -118,6 +118,7 @@ typedef enum
EOLIAN_TYPE_UNKNOWN_TYPE,
EOLIAN_TYPE_VOID,
EOLIAN_TYPE_REGULAR,
EOLIAN_TYPE_REGULAR_STRUCT,
EOLIAN_TYPE_POINTER,
EOLIAN_TYPE_FUNCTION,
EOLIAN_TYPE_STRUCT

View File

@ -303,22 +303,13 @@ parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon)
def->type = EOLIAN_TYPE_VOID;
else
{
def->type = EOLIAN_TYPE_REGULAR;
def->type = has_struct ? EOLIAN_TYPE_REGULAR_STRUCT : EOLIAN_TYPE_REGULAR;
def->is_const = EINA_FALSE;
check(ls, TOK_VALUE);
ctype = eo_lexer_get_c_type(ls->t.kw);
if (ctype && has_struct)
eo_lexer_syntax_error(ls, "invalid struct name");
if (has_struct)
{
Eina_Strbuf *buf = eina_strbuf_new();
eina_strbuf_append(buf, "struct ");
eina_strbuf_append(buf, ls->t.value);
def->name = eina_stringshare_add(eina_strbuf_string_get(buf));
eina_strbuf_free(buf);
}
else
def->name = eina_stringshare_add(ctype ? ctype : ls->t.value);
def->name = eina_stringshare_add(ctype ? ctype : ls->t.value);
}
eo_lexer_get(ls);
parse_ptr:
@ -1046,6 +1037,8 @@ _print_type(FILE *f, Eo_Type_Def *tp)
fputs("const(", f);
if (tp->type == EOLIAN_TYPE_REGULAR)
fputs(tp->name, f);
else if (tp->type == EOLIAN_TYPE_REGULAR_STRUCT)
fprintf(f, "struct %s", tp->name);
else if (tp->type == EOLIAN_TYPE_POINTER)
{
_print_type(f, tp->base_type);

View File

@ -1168,7 +1168,9 @@ eolian_type_subtypes_list_get(Eolian_Type tp)
Eolian_Type_Type tpt;
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
tpt = tpp->type;
EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt == EOLIAN_TYPE_REGULAR || tpt == EOLIAN_TYPE_POINTER, NULL);
EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt == EOLIAN_TYPE_REGULAR
|| tpt == EOLIAN_TYPE_POINTER
|| tpt == EOLIAN_TYPE_REGULAR_STRUCT, NULL);
if (!tpp->subtypes) return NULL;
return eina_list_iterator_new(tpp->subtypes);
}
@ -1295,11 +1297,20 @@ _type_to_str(Eolian_Type tp, Eina_Strbuf *buf, const char *name)
_stype_to_str(tp, buf, name);
return;
}
if ((tpp->type == EOLIAN_TYPE_REGULAR || tpp->type == EOLIAN_TYPE_VOID)
if ((tpp->type == EOLIAN_TYPE_REGULAR
|| tpp->type == EOLIAN_TYPE_REGULAR_STRUCT
|| tpp->type == EOLIAN_TYPE_VOID)
&& tpp->is_const)
eina_strbuf_append(buf, "const ");
{
eina_strbuf_append(buf, "const ");
}
if (tpp->type == EOLIAN_TYPE_REGULAR)
eina_strbuf_append(buf, tpp->name);
else if (tpp->type == EOLIAN_TYPE_REGULAR_STRUCT)
{
eina_strbuf_append(buf, "struct ");
eina_strbuf_append(buf, tpp->name);
}
else if (tpp->type == EOLIAN_TYPE_VOID)
eina_strbuf_append(buf, "void");
else
@ -1391,6 +1402,11 @@ _type_print(Eolian_Type tp, Eina_Strbuf *buf)
eina_strbuf_append(buf, "const(");
if (tpp->type == EOLIAN_TYPE_REGULAR)
eina_strbuf_append(buf, tpp->name);
else if (tpp->type == EOLIAN_TYPE_REGULAR_STRUCT)
{
eina_strbuf_append(buf, "struct ");
eina_strbuf_append(buf, tpp->name);
}
else if (tpp->type == EOLIAN_TYPE_POINTER)
{
_type_print(tpp->base_type, buf);