eolian: generalized node append

This commit is contained in:
Daniel Kolesa 2014-06-23 15:38:23 +01:00
parent 7c28de0616
commit 98d25243aa
2 changed files with 12 additions and 9 deletions

View File

@ -52,6 +52,7 @@ typedef struct _Eo_Node
{ {
unsigned char type; unsigned char type;
union { union {
void *def;
Eo_Class_Def *def_class; Eo_Class_Def *def_class;
Eo_Type_Def *def_type; Eo_Type_Def *def_type;
}; };

View File

@ -103,6 +103,15 @@ pop_strbuf(Eo_Lexer *ls)
ls->tmp.str_bufs = eina_list_remove_list(ls->tmp.str_bufs, ls->tmp.str_bufs); ls->tmp.str_bufs = eina_list_remove_list(ls->tmp.str_bufs, ls->tmp.str_bufs);
} }
static void
append_node(Eo_Lexer *ls, int type, void *def)
{
Eo_Node *nd = calloc(1, sizeof(Eo_Node));
nd->type = type;
nd->def = def;
ls->nodes = eina_list_append(ls->nodes, nd);
}
static Eina_Strbuf * static Eina_Strbuf *
parse_name(Eo_Lexer *ls, Eina_Strbuf *buf) parse_name(Eo_Lexer *ls, Eina_Strbuf *buf)
{ {
@ -852,7 +861,6 @@ parse_class(Eo_Lexer *ls, Eina_Bool allow_ctors, Eolian_Class_Type type)
static void static void
parse_unit(Eo_Lexer *ls) parse_unit(Eo_Lexer *ls)
{ {
Eo_Node *nd;
switch (ls->t.kw) switch (ls->t.kw)
{ {
case KW_abstract: case KW_abstract:
@ -870,10 +878,7 @@ parse_unit(Eo_Lexer *ls)
case KW_type: case KW_type:
{ {
parse_typedef(ls); parse_typedef(ls);
nd = calloc(1, sizeof(Eo_Node)); append_node(ls, NODE_TYPEDEF, ls->tmp.type_def);
nd->type = NODE_TYPEDEF;
nd->def_type = ls->tmp.type_def;
ls->nodes = eina_list_append(ls->nodes, nd);
ls->tmp.type_def = NULL; ls->tmp.type_def = NULL;
break; break;
} }
@ -883,10 +888,7 @@ parse_unit(Eo_Lexer *ls)
} }
return; return;
found_class: found_class:
nd = calloc(1, sizeof(Eo_Node)); append_node(ls, NODE_CLASS, ls->tmp.kls);
nd->type = NODE_CLASS;
nd->def_class = ls->tmp.kls;
ls->nodes = eina_list_append(ls->nodes, nd);
ls->tmp.kls = NULL; ls->tmp.kls = NULL;
} }