eolian: remove Eolian_Typedef, use Eolian_Type instead; allow eolian_type_base_type_get on aliases

This commit is contained in:
Daniel Kolesa 2014-07-21 16:53:25 +01:00
parent 3798eb2f99
commit e797e40478
9 changed files with 61 additions and 74 deletions

View File

@ -283,11 +283,11 @@ eolian_show_class(const Eolian_Class *class)
static Eina_Bool
_typedef_cb(Eina_Hash *hash EINA_UNUSED, const char *alias,
const Eolian_Typedef *tp, const void *fdata EINA_UNUSED)
const Eolian_Type *tp, const void *fdata EINA_UNUSED)
{
printf("Typedef: %s\n", alias);
printf(" type: <");
database_type_print(tp->type);
database_type_print(tp->base_type);
printf(">\n");
return EINA_TRUE;
}
@ -300,7 +300,7 @@ eolian_show_typedef(const char *alias)
else
{
Eina_Stringshare *shr = eina_stringshare_add(alias);
Eolian_Typedef *tp = eina_hash_find(_types, shr);
Eolian_Type *tp = eina_hash_find(_types, shr);
eina_stringshare_del(shr);
if (!tp) return EINA_FALSE;
_typedef_cb(NULL, alias, tp, NULL);

View File

@ -28,23 +28,11 @@ database_type_del(Eolian_Type *tp)
free(tp);
}
void
database_typedef_del(Eolian_Typedef *def)
{
if (!def) return;
eina_stringshare_del(def->alias);
eina_stringshare_del(def->file);
/* prevent deletion of named structs: stored in another hash */
if (def->type->type != EOLIAN_TYPE_STRUCT || !def->type->name)
database_type_del(def->type);
free(def);
}
Eina_Bool
database_type_add(Eolian_Typedef *def)
database_type_add(Eolian_Type *def)
{
if (!_types) return EINA_FALSE;
eina_hash_set(_types, def->alias, def);
eina_hash_set(_types, def->full_name, def);
return EINA_TRUE;
}

View File

@ -7,9 +7,9 @@ eolian_type_find_by_alias(const char *alias)
{
if (!_types) return NULL;
Eina_Stringshare *shr = eina_stringshare_add(alias);
Eolian_Typedef *def = eina_hash_find(_types, shr);
Eolian_Type *def = eina_hash_find(_types, shr);
eina_stringshare_del(shr);
return def ? def->type : NULL;
return def ? def->base_type : NULL;
}
EAPI Eina_Bool
@ -17,7 +17,7 @@ eolian_typedef_is_extern(const char *alias)
{
if (!_types) return EINA_FALSE;
Eina_Stringshare *shr = eina_stringshare_add(alias);
Eolian_Typedef *def = eina_hash_find(_types, shr);
Eolian_Type *def = eina_hash_find(_types, shr);
eina_stringshare_del(shr);
return def ? def->is_extern : EINA_FALSE;
}
@ -27,7 +27,7 @@ eolian_typedef_file_get(const char *alias)
{
if (!_types) return EINA_FALSE;
Eina_Stringshare *shr = eina_stringshare_add(alias);
Eolian_Typedef *def = eina_hash_find(_types, shr);
Eolian_Type *def = eina_hash_find(_types, shr);
eina_stringshare_del(shr);
return def ? eina_stringshare_ref(def->file) : NULL;
}
@ -141,7 +141,7 @@ eolian_type_base_type_get(const Eolian_Type *tp)
Eolian_Type_Type tpt;
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
tpt = eolian_type_type_get(tp);
EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt == EOLIAN_TYPE_POINTER, NULL);
EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt == EOLIAN_TYPE_POINTER || tpt == EOLIAN_TYPE_ALIAS, NULL);
return tp->base_type;
}

View File

@ -153,9 +153,6 @@ eo_definitions_temps_free(Eo_Lexer_Temps *tmp)
if (tmp->ret_def)
eo_definitions_ret_free(tmp->ret_def);
if (tmp->typedef_def)
database_typedef_del(tmp->typedef_def);
EINA_LIST_FREE(tmp->type_defs, tp)
database_type_del(tp);

View File

@ -101,7 +101,6 @@ typedef struct _Eo_Lexer_Temps
Eina_Stringshare *legacy_def;
Eo_Class_Def *kls;
Eo_Ret_Def *ret_def;
Eolian_Typedef *typedef_def;
Eina_List *type_defs;
Eo_Property_Def *prop;
Eo_Method_Def *meth;

View File

@ -105,10 +105,8 @@ typedef struct _Eo_Node
{
unsigned char type;
union {
void *def;
Eo_Class_Def *def_class;
Eolian_Typedef *def_typedef;
Eolian_Type *def_struct;
void *def;
Eo_Class_Def *def_class;
};
} Eo_Node;

View File

@ -375,10 +375,12 @@ parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon)
pop_strbuf(ls);
if (ls->t.token == '{')
{
ls->line_number = line;
ls->column = col;
if (eina_hash_find(_structs, ls->t.value))
eo_lexer_syntax_error(ls, "struct redefinition");
if (eina_hash_find(_structs, sname))
{
ls->line_number = line;
ls->column = col;
eo_lexer_syntax_error(ls, "struct redefinition");
}
return parse_struct(ls, sname, is_extern);
}
}
@ -456,28 +458,38 @@ parse_type_void(Eo_Lexer *ls)
return parse_type_struct(ls, EINA_FALSE, EINA_FALSE);
}
static void
static Eolian_Type *
parse_typedef(Eo_Lexer *ls)
{
ls->tmp.typedef_def = calloc(1, sizeof(Eolian_Typedef));
Eolian_Type *def = push_type(ls);
Eina_Bool is_extern = EINA_FALSE;
Eina_Strbuf *buf;
int line, col;
eo_lexer_get(ls);
if (ls->t.kw == KW_at_extern)
{
ls->tmp.typedef_def->is_extern = EINA_TRUE;
is_extern = EINA_TRUE;
eo_lexer_get(ls);
}
check(ls, TOK_VALUE);
def->is_extern = is_extern;
buf = push_strbuf(ls);
line = ls->line_number;
col = ls->column;
parse_name(ls, buf);
_fill_type_name(def, eina_stringshare_add(eina_strbuf_string_get(buf)));
/* todo: store info about the previous definition and mention it here */
if (eina_hash_find(_types, ls->t.value))
eo_lexer_syntax_error(ls, "typedef redefinition");
ls->tmp.typedef_def->alias = eina_stringshare_ref(ls->t.value);
ls->tmp.typedef_def->file = get_filename(ls);
eo_lexer_get(ls);
if (eina_hash_find(_types, eina_strbuf_string_get(buf)))
{
ls->line_number = line;
ls->column = col;
eo_lexer_syntax_error(ls, "type alias redefinition");
}
def->file = get_filename(ls);
(void)!!test_next(ls, ':');
ls->tmp.typedef_def->type = parse_type_struct_nonvoid(ls, EINA_TRUE,
EINA_TRUE);
def->base_type = parse_type_struct_nonvoid(ls, EINA_TRUE, EINA_TRUE);
pop_type(ls);
check_next(ls, ';');
return def;
}
static void
@ -1117,13 +1129,13 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
goto found_class;
case KW_type:
{
parse_typedef(ls);
database_type_add(ls->tmp.typedef_def);
ls->tmp.typedef_def = NULL;
database_type_add(parse_typedef(ls));
pop_type(ls);
break;
}
case KW_struct:
{
int line, col;
const char *name;
Eina_Bool is_extern = EINA_FALSE;
Eina_Strbuf *buf;
@ -1134,10 +1146,16 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
eo_lexer_get(ls);
}
buf = push_strbuf(ls);
line = ls->line_number;
col = ls->column;
parse_name(ls, buf);
/* todo: see typedef */
if (eina_hash_find(_structs, ls->t.value))
eo_lexer_syntax_error(ls, "struct redefinition");
if (eina_hash_find(_structs, eina_strbuf_string_get(buf)))
{
ls->line_number = line;
ls->column = col;
eo_lexer_syntax_error(ls, "struct redefinition");
}
name = eina_stringshare_add(eina_strbuf_string_get(buf));
pop_strbuf(ls);
parse_struct(ls, name, is_extern);

View File

@ -15,7 +15,7 @@ database_init()
{
if (_database_init_count > 0) return ++_database_init_count;
eina_init();
_types = eina_hash_stringshared_new(EINA_FREE_CB(database_typedef_del));
_types = eina_hash_stringshared_new(EINA_FREE_CB(database_type_del));
_structs = eina_hash_stringshared_new(EINA_FREE_CB(database_type_del));
_filenames = eina_hash_string_small_new(free);
_tfilenames = eina_hash_string_small_new(free);

View File

@ -100,25 +100,21 @@ struct _Eolian_Type
{
Eolian_Type_Type type;
union {
/* pointers and regular types */
struct {
Eina_List *subtypes;
Eolian_Type *base_type;
};
/* functions */
struct {
Eina_List *arguments;
Eolian_Type *ret_type;
};
/* structs, aliases, regular types */
/* everything else */
struct {
void *pad; /* make space for subtypes */
Eina_Stringshare *name; /* all */
Eina_Stringshare *full_name; /* all */
Eina_List *namespaces; /* all */
Eina_Hash *fields; /* structs */
Eina_Stringshare *comment; /* structs, aliases */
Eina_Stringshare *file; /* structs, aliases */
Eina_List *subtypes;
Eolian_Type *base_type;
Eina_Stringshare *name;
Eina_Stringshare *full_name;
Eina_List *namespaces;
Eina_Hash *fields;
Eina_Stringshare *comment;
Eina_Stringshare *file;
};
};
Eina_Bool is_const :1;
@ -138,14 +134,6 @@ struct _Eolian_Event
Eolian_Type *type;
};
typedef struct _Eolian_Typedef
{
Eina_Stringshare *alias;
Eina_Stringshare *file;
Eolian_Type *type;
Eina_Bool is_extern :1;
} Eolian_Typedef;
typedef struct _Eolian_Struct_Field
{
Eolian_Type *type;
@ -157,10 +145,9 @@ int database_shutdown();
/* types */
Eina_Bool database_type_add(Eolian_Typedef *def);
Eina_Bool database_type_add(Eolian_Type *def);
Eina_Bool database_struct_add(Eolian_Type *type);
void database_type_del(Eolian_Type *type);
void database_typedef_del(Eolian_Typedef *def);
void database_type_print(Eolian_Type *type);
void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name);