forked from enlightenment/efl
eolian: remove Eolian_Typedef, use Eolian_Type instead; allow eolian_type_base_type_get on aliases
This commit is contained in:
parent
3798eb2f99
commit
e797e40478
|
@ -283,11 +283,11 @@ eolian_show_class(const Eolian_Class *class)
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_typedef_cb(Eina_Hash *hash EINA_UNUSED, const char *alias,
|
_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("Typedef: %s\n", alias);
|
||||||
printf(" type: <");
|
printf(" type: <");
|
||||||
database_type_print(tp->type);
|
database_type_print(tp->base_type);
|
||||||
printf(">\n");
|
printf(">\n");
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ eolian_show_typedef(const char *alias)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Eina_Stringshare *shr = eina_stringshare_add(alias);
|
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);
|
eina_stringshare_del(shr);
|
||||||
if (!tp) return EINA_FALSE;
|
if (!tp) return EINA_FALSE;
|
||||||
_typedef_cb(NULL, alias, tp, NULL);
|
_typedef_cb(NULL, alias, tp, NULL);
|
||||||
|
|
|
@ -28,23 +28,11 @@ database_type_del(Eolian_Type *tp)
|
||||||
free(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
|
Eina_Bool
|
||||||
database_type_add(Eolian_Typedef *def)
|
database_type_add(Eolian_Type *def)
|
||||||
{
|
{
|
||||||
if (!_types) return EINA_FALSE;
|
if (!_types) return EINA_FALSE;
|
||||||
eina_hash_set(_types, def->alias, def);
|
eina_hash_set(_types, def->full_name, def);
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ eolian_type_find_by_alias(const char *alias)
|
||||||
{
|
{
|
||||||
if (!_types) return NULL;
|
if (!_types) return NULL;
|
||||||
Eina_Stringshare *shr = eina_stringshare_add(alias);
|
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);
|
eina_stringshare_del(shr);
|
||||||
return def ? def->type : NULL;
|
return def ? def->base_type : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
|
@ -17,7 +17,7 @@ eolian_typedef_is_extern(const char *alias)
|
||||||
{
|
{
|
||||||
if (!_types) return EINA_FALSE;
|
if (!_types) return EINA_FALSE;
|
||||||
Eina_Stringshare *shr = eina_stringshare_add(alias);
|
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);
|
eina_stringshare_del(shr);
|
||||||
return def ? def->is_extern : EINA_FALSE;
|
return def ? def->is_extern : EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ eolian_typedef_file_get(const char *alias)
|
||||||
{
|
{
|
||||||
if (!_types) return EINA_FALSE;
|
if (!_types) return EINA_FALSE;
|
||||||
Eina_Stringshare *shr = eina_stringshare_add(alias);
|
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);
|
eina_stringshare_del(shr);
|
||||||
return def ? eina_stringshare_ref(def->file) : NULL;
|
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;
|
Eolian_Type_Type tpt;
|
||||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||||
tpt = eolian_type_type_get(tp);
|
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;
|
return tp->base_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,9 +153,6 @@ eo_definitions_temps_free(Eo_Lexer_Temps *tmp)
|
||||||
if (tmp->ret_def)
|
if (tmp->ret_def)
|
||||||
eo_definitions_ret_free(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)
|
EINA_LIST_FREE(tmp->type_defs, tp)
|
||||||
database_type_del(tp);
|
database_type_del(tp);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,6 @@ typedef struct _Eo_Lexer_Temps
|
||||||
Eina_Stringshare *legacy_def;
|
Eina_Stringshare *legacy_def;
|
||||||
Eo_Class_Def *kls;
|
Eo_Class_Def *kls;
|
||||||
Eo_Ret_Def *ret_def;
|
Eo_Ret_Def *ret_def;
|
||||||
Eolian_Typedef *typedef_def;
|
|
||||||
Eina_List *type_defs;
|
Eina_List *type_defs;
|
||||||
Eo_Property_Def *prop;
|
Eo_Property_Def *prop;
|
||||||
Eo_Method_Def *meth;
|
Eo_Method_Def *meth;
|
||||||
|
|
|
@ -105,10 +105,8 @@ typedef struct _Eo_Node
|
||||||
{
|
{
|
||||||
unsigned char type;
|
unsigned char type;
|
||||||
union {
|
union {
|
||||||
void *def;
|
void *def;
|
||||||
Eo_Class_Def *def_class;
|
Eo_Class_Def *def_class;
|
||||||
Eolian_Typedef *def_typedef;
|
|
||||||
Eolian_Type *def_struct;
|
|
||||||
};
|
};
|
||||||
} Eo_Node;
|
} Eo_Node;
|
||||||
|
|
||||||
|
|
|
@ -375,10 +375,12 @@ parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon)
|
||||||
pop_strbuf(ls);
|
pop_strbuf(ls);
|
||||||
if (ls->t.token == '{')
|
if (ls->t.token == '{')
|
||||||
{
|
{
|
||||||
ls->line_number = line;
|
if (eina_hash_find(_structs, sname))
|
||||||
ls->column = col;
|
{
|
||||||
if (eina_hash_find(_structs, ls->t.value))
|
ls->line_number = line;
|
||||||
eo_lexer_syntax_error(ls, "struct redefinition");
|
ls->column = col;
|
||||||
|
eo_lexer_syntax_error(ls, "struct redefinition");
|
||||||
|
}
|
||||||
return parse_struct(ls, sname, is_extern);
|
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);
|
return parse_type_struct(ls, EINA_FALSE, EINA_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static Eolian_Type *
|
||||||
parse_typedef(Eo_Lexer *ls)
|
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);
|
eo_lexer_get(ls);
|
||||||
if (ls->t.kw == KW_at_extern)
|
if (ls->t.kw == KW_at_extern)
|
||||||
{
|
{
|
||||||
ls->tmp.typedef_def->is_extern = EINA_TRUE;
|
is_extern = EINA_TRUE;
|
||||||
eo_lexer_get(ls);
|
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 */
|
/* todo: store info about the previous definition and mention it here */
|
||||||
if (eina_hash_find(_types, ls->t.value))
|
if (eina_hash_find(_types, eina_strbuf_string_get(buf)))
|
||||||
eo_lexer_syntax_error(ls, "typedef redefinition");
|
{
|
||||||
ls->tmp.typedef_def->alias = eina_stringshare_ref(ls->t.value);
|
ls->line_number = line;
|
||||||
ls->tmp.typedef_def->file = get_filename(ls);
|
ls->column = col;
|
||||||
eo_lexer_get(ls);
|
eo_lexer_syntax_error(ls, "type alias redefinition");
|
||||||
|
}
|
||||||
|
def->file = get_filename(ls);
|
||||||
(void)!!test_next(ls, ':');
|
(void)!!test_next(ls, ':');
|
||||||
ls->tmp.typedef_def->type = parse_type_struct_nonvoid(ls, EINA_TRUE,
|
def->base_type = parse_type_struct_nonvoid(ls, EINA_TRUE, EINA_TRUE);
|
||||||
EINA_TRUE);
|
|
||||||
pop_type(ls);
|
pop_type(ls);
|
||||||
check_next(ls, ';');
|
check_next(ls, ';');
|
||||||
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1117,13 +1129,13 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
|
||||||
goto found_class;
|
goto found_class;
|
||||||
case KW_type:
|
case KW_type:
|
||||||
{
|
{
|
||||||
parse_typedef(ls);
|
database_type_add(parse_typedef(ls));
|
||||||
database_type_add(ls->tmp.typedef_def);
|
pop_type(ls);
|
||||||
ls->tmp.typedef_def = NULL;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KW_struct:
|
case KW_struct:
|
||||||
{
|
{
|
||||||
|
int line, col;
|
||||||
const char *name;
|
const char *name;
|
||||||
Eina_Bool is_extern = EINA_FALSE;
|
Eina_Bool is_extern = EINA_FALSE;
|
||||||
Eina_Strbuf *buf;
|
Eina_Strbuf *buf;
|
||||||
|
@ -1134,10 +1146,16 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
|
||||||
eo_lexer_get(ls);
|
eo_lexer_get(ls);
|
||||||
}
|
}
|
||||||
buf = push_strbuf(ls);
|
buf = push_strbuf(ls);
|
||||||
|
line = ls->line_number;
|
||||||
|
col = ls->column;
|
||||||
parse_name(ls, buf);
|
parse_name(ls, buf);
|
||||||
/* todo: see typedef */
|
/* todo: see typedef */
|
||||||
if (eina_hash_find(_structs, ls->t.value))
|
if (eina_hash_find(_structs, eina_strbuf_string_get(buf)))
|
||||||
eo_lexer_syntax_error(ls, "struct redefinition");
|
{
|
||||||
|
ls->line_number = line;
|
||||||
|
ls->column = col;
|
||||||
|
eo_lexer_syntax_error(ls, "struct redefinition");
|
||||||
|
}
|
||||||
name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
||||||
pop_strbuf(ls);
|
pop_strbuf(ls);
|
||||||
parse_struct(ls, name, is_extern);
|
parse_struct(ls, name, is_extern);
|
||||||
|
|
|
@ -15,7 +15,7 @@ database_init()
|
||||||
{
|
{
|
||||||
if (_database_init_count > 0) return ++_database_init_count;
|
if (_database_init_count > 0) return ++_database_init_count;
|
||||||
eina_init();
|
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));
|
_structs = eina_hash_stringshared_new(EINA_FREE_CB(database_type_del));
|
||||||
_filenames = eina_hash_string_small_new(free);
|
_filenames = eina_hash_string_small_new(free);
|
||||||
_tfilenames = eina_hash_string_small_new(free);
|
_tfilenames = eina_hash_string_small_new(free);
|
||||||
|
|
|
@ -100,25 +100,21 @@ struct _Eolian_Type
|
||||||
{
|
{
|
||||||
Eolian_Type_Type type;
|
Eolian_Type_Type type;
|
||||||
union {
|
union {
|
||||||
/* pointers and regular types */
|
|
||||||
struct {
|
|
||||||
Eina_List *subtypes;
|
|
||||||
Eolian_Type *base_type;
|
|
||||||
};
|
|
||||||
/* functions */
|
/* functions */
|
||||||
struct {
|
struct {
|
||||||
Eina_List *arguments;
|
Eina_List *arguments;
|
||||||
Eolian_Type *ret_type;
|
Eolian_Type *ret_type;
|
||||||
};
|
};
|
||||||
/* structs, aliases, regular types */
|
/* everything else */
|
||||||
struct {
|
struct {
|
||||||
void *pad; /* make space for subtypes */
|
Eina_List *subtypes;
|
||||||
Eina_Stringshare *name; /* all */
|
Eolian_Type *base_type;
|
||||||
Eina_Stringshare *full_name; /* all */
|
Eina_Stringshare *name;
|
||||||
Eina_List *namespaces; /* all */
|
Eina_Stringshare *full_name;
|
||||||
Eina_Hash *fields; /* structs */
|
Eina_List *namespaces;
|
||||||
Eina_Stringshare *comment; /* structs, aliases */
|
Eina_Hash *fields;
|
||||||
Eina_Stringshare *file; /* structs, aliases */
|
Eina_Stringshare *comment;
|
||||||
|
Eina_Stringshare *file;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Eina_Bool is_const :1;
|
Eina_Bool is_const :1;
|
||||||
|
@ -138,14 +134,6 @@ struct _Eolian_Event
|
||||||
Eolian_Type *type;
|
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
|
typedef struct _Eolian_Struct_Field
|
||||||
{
|
{
|
||||||
Eolian_Type *type;
|
Eolian_Type *type;
|
||||||
|
@ -157,10 +145,9 @@ int database_shutdown();
|
||||||
|
|
||||||
/* types */
|
/* 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);
|
Eina_Bool database_struct_add(Eolian_Type *type);
|
||||||
void database_type_del(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_print(Eolian_Type *type);
|
||||||
void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name);
|
void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name);
|
||||||
|
|
Loading…
Reference in New Issue