2014-07-10 04:15:29 -07:00
|
|
|
#include <Eina.h>
|
2014-08-07 08:29:03 -07:00
|
|
|
#include "eo_lexer.h"
|
2014-07-10 04:15:29 -07:00
|
|
|
|
|
|
|
void
|
2014-07-10 06:44:17 -07:00
|
|
|
database_type_del(Eolian_Type *tp)
|
2014-07-10 04:15:29 -07:00
|
|
|
{
|
2014-07-10 06:44:17 -07:00
|
|
|
if (!tp) return;
|
2014-07-22 02:39:34 -07:00
|
|
|
const char *sp;
|
|
|
|
Eolian_Type *stp;
|
2014-08-07 07:15:07 -07:00
|
|
|
if (tp->base.file) eina_stringshare_del(tp->base.file);
|
2014-07-22 02:39:34 -07:00
|
|
|
if (tp->subtypes) EINA_LIST_FREE(tp->subtypes, stp)
|
|
|
|
database_type_del(stp);
|
|
|
|
if (tp->base_type)
|
|
|
|
database_type_del(tp->base_type);
|
|
|
|
if (tp->name) eina_stringshare_del(tp->name);
|
|
|
|
if (tp->full_name) eina_stringshare_del(tp->full_name);
|
|
|
|
if (tp->fields) eina_hash_free(tp->fields);
|
|
|
|
if (tp->namespaces) EINA_LIST_FREE(tp->namespaces, sp)
|
|
|
|
eina_stringshare_del(sp);
|
|
|
|
if (tp->comment) eina_stringshare_del(tp->comment);
|
2014-07-10 06:44:17 -07:00
|
|
|
free(tp);
|
2014-07-10 04:15:29 -07:00
|
|
|
}
|
|
|
|
|
2014-07-22 02:39:34 -07:00
|
|
|
void
|
|
|
|
database_typedef_del(Eolian_Type *tp)
|
|
|
|
{
|
|
|
|
if (!tp) return;
|
|
|
|
Eolian_Type *btp = tp->base_type;
|
|
|
|
/* prevent deletion of named structs as they're deleted later on */
|
|
|
|
if (btp && btp->type == EOLIAN_TYPE_STRUCT && btp->name)
|
|
|
|
tp->base_type = NULL;
|
|
|
|
database_type_del(tp);
|
|
|
|
}
|
|
|
|
|
2014-07-10 04:15:29 -07:00
|
|
|
Eina_Bool
|
2014-07-21 08:53:25 -07:00
|
|
|
database_type_add(Eolian_Type *def)
|
2014-07-10 04:15:29 -07:00
|
|
|
{
|
2014-07-21 08:57:45 -07:00
|
|
|
if (!_aliases) return EINA_FALSE;
|
|
|
|
eina_hash_set(_aliases, def->full_name, def);
|
2014-08-08 07:19:52 -07:00
|
|
|
eina_hash_set(_aliasesf, def->base.file, eina_list_append
|
|
|
|
((Eina_List*)eina_hash_find(_aliasesf, def->base.file), def));
|
2014-07-21 03:22:49 -07:00
|
|
|
return EINA_TRUE;
|
2014-07-10 04:15:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool database_struct_add(Eolian_Type *tp)
|
|
|
|
{
|
2014-07-21 03:22:49 -07:00
|
|
|
if (!_structs) return EINA_FALSE;
|
2014-07-21 08:57:45 -07:00
|
|
|
eina_hash_set(_structs, tp->full_name, tp);
|
2014-08-08 07:19:52 -07:00
|
|
|
eina_hash_set(_structsf, tp->base.file, eina_list_append
|
|
|
|
((Eina_List*)eina_hash_find(_structsf, tp->base.file), tp));
|
2014-07-21 03:22:49 -07:00
|
|
|
return EINA_TRUE;
|
2014-07-10 04:15:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ftype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Eolian_Type *stp;
|
|
|
|
Eina_Bool first = EINA_TRUE;
|
|
|
|
if (tp->ret_type)
|
2014-07-10 05:13:46 -07:00
|
|
|
database_type_to_str(tp->ret_type, buf, NULL);
|
2014-07-10 04:15:29 -07:00
|
|
|
else
|
|
|
|
eina_strbuf_append(buf, "void");
|
|
|
|
eina_strbuf_append(buf, " (*");
|
|
|
|
if (name) eina_strbuf_append(buf, name);
|
|
|
|
eina_strbuf_append(buf, ")(");
|
|
|
|
EINA_LIST_FOREACH(tp->arguments, l, stp)
|
|
|
|
{
|
|
|
|
if (!first) eina_strbuf_append(buf, ", ");
|
|
|
|
first = EINA_FALSE;
|
2014-07-10 05:13:46 -07:00
|
|
|
database_type_to_str(stp, buf, NULL);
|
2014-07-10 04:15:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_stype_field_cb(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data,
|
|
|
|
void *fdata)
|
|
|
|
{
|
2014-07-10 06:19:06 -07:00
|
|
|
database_type_to_str((Eolian_Type*)((Eolian_Struct_Field*)data)->type,
|
2014-07-10 05:13:46 -07:00
|
|
|
(Eina_Strbuf*)fdata, (const char*)key);
|
2014-07-10 04:15:29 -07:00
|
|
|
eina_strbuf_append((Eina_Strbuf*)fdata, "; ");
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_stype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
|
|
|
|
{
|
|
|
|
eina_strbuf_append(buf, "struct ");
|
|
|
|
if (tp->name)
|
|
|
|
{
|
2014-07-21 08:08:06 -07:00
|
|
|
Eina_List *l;
|
|
|
|
const char *sp;
|
|
|
|
EINA_LIST_FOREACH(tp->namespaces, l, sp)
|
|
|
|
{
|
|
|
|
eina_strbuf_append(buf, sp);
|
|
|
|
eina_strbuf_append_char(buf, '_');
|
|
|
|
}
|
2014-07-10 04:15:29 -07:00
|
|
|
eina_strbuf_append(buf, tp->name);
|
|
|
|
eina_strbuf_append_char(buf, ' ');
|
|
|
|
}
|
|
|
|
eina_strbuf_append(buf, "{ ");
|
|
|
|
eina_hash_foreach(tp->fields, _stype_field_cb, buf);
|
|
|
|
eina_strbuf_append(buf, "}");
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
eina_strbuf_append_char(buf, ' ');
|
|
|
|
eina_strbuf_append(buf, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:11:06 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-10 05:13:46 -07:00
|
|
|
void
|
|
|
|
database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
|
2014-07-10 04:15:29 -07:00
|
|
|
{
|
2014-07-22 04:11:06 -07:00
|
|
|
if (tp->type == EOLIAN_TYPE_ALIAS)
|
|
|
|
{
|
|
|
|
_atype_to_str(tp, buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (tp->type == EOLIAN_TYPE_FUNCTION)
|
2014-07-10 04:15:29 -07:00
|
|
|
{
|
|
|
|
_ftype_to_str(tp, buf, name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (tp->type == EOLIAN_TYPE_STRUCT)
|
|
|
|
{
|
|
|
|
_stype_to_str(tp, buf, name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((tp->type == EOLIAN_TYPE_REGULAR
|
|
|
|
|| tp->type == EOLIAN_TYPE_REGULAR_STRUCT
|
2014-07-30 03:57:11 -07:00
|
|
|
|| tp->type == EOLIAN_TYPE_VOID
|
|
|
|
|| tp->type == EOLIAN_TYPE_CLASS)
|
2014-07-10 04:15:29 -07:00
|
|
|
&& tp->is_const)
|
|
|
|
{
|
|
|
|
eina_strbuf_append(buf, "const ");
|
|
|
|
}
|
2014-08-01 07:11:28 -07:00
|
|
|
if (tp->type == EOLIAN_TYPE_REGULAR || tp->type == EOLIAN_TYPE_CLASS)
|
2014-07-21 08:08:06 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
const char *sp;
|
|
|
|
EINA_LIST_FOREACH(tp->namespaces, l, sp)
|
|
|
|
{
|
|
|
|
eina_strbuf_append(buf, sp);
|
|
|
|
eina_strbuf_append_char(buf, '_');
|
|
|
|
}
|
2014-08-07 08:29:03 -07:00
|
|
|
int kw = eo_lexer_keyword_str_to_id(tp->name);
|
|
|
|
if (kw) eina_strbuf_append(buf, eo_lexer_get_c_type(kw));
|
|
|
|
else eina_strbuf_append(buf, tp->name);
|
2014-07-21 08:08:06 -07:00
|
|
|
}
|
2014-07-10 04:15:29 -07:00
|
|
|
else if (tp->type == EOLIAN_TYPE_REGULAR_STRUCT)
|
|
|
|
{
|
|
|
|
eina_strbuf_append(buf, "struct ");
|
|
|
|
eina_strbuf_append(buf, tp->name);
|
|
|
|
}
|
|
|
|
else if (tp->type == EOLIAN_TYPE_VOID)
|
|
|
|
eina_strbuf_append(buf, "void");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Eolian_Type *btp = tp->base_type;
|
2014-07-10 05:13:46 -07:00
|
|
|
database_type_to_str(tp->base_type, buf, NULL);
|
2014-07-10 04:15:29 -07:00
|
|
|
if (btp->type != EOLIAN_TYPE_POINTER || btp->is_const)
|
|
|
|
eina_strbuf_append_char(buf, ' ');
|
|
|
|
eina_strbuf_append_char(buf, '*');
|
|
|
|
if (tp->is_const) eina_strbuf_append(buf, " const");
|
|
|
|
}
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
eina_strbuf_append_char(buf, ' ');
|
|
|
|
eina_strbuf_append(buf, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_print_field(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data,
|
|
|
|
void *fdata EINA_UNUSED)
|
|
|
|
{
|
|
|
|
printf("%s: ", (const char*)key);
|
|
|
|
database_type_print((Eolian_Type*)data);
|
2014-07-11 04:26:33 -07:00
|
|
|
printf("; ");
|
2014-07-10 04:15:29 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:11:06 -07:00
|
|
|
static void
|
|
|
|
_typedef_print(Eolian_Type *tp)
|
|
|
|
{
|
|
|
|
printf("type %s: ", tp->full_name);
|
|
|
|
database_type_print(tp->base_type);
|
|
|
|
}
|
|
|
|
|
2014-07-10 04:15:29 -07:00
|
|
|
void
|
|
|
|
database_type_print(Eolian_Type *tp)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Eolian_Type *stp;
|
2014-07-22 04:11:06 -07:00
|
|
|
if (tp->type == EOLIAN_TYPE_ALIAS)
|
|
|
|
{
|
|
|
|
_typedef_print(tp);
|
|
|
|
return;
|
|
|
|
}
|
2014-07-10 04:15:29 -07:00
|
|
|
if (tp->is_own)
|
2014-07-11 04:26:33 -07:00
|
|
|
printf("own(");
|
2014-07-10 04:15:29 -07:00
|
|
|
if (tp->is_const)
|
2014-07-11 04:26:33 -07:00
|
|
|
printf("const(");
|
2014-07-30 03:57:11 -07:00
|
|
|
if (tp->type == EOLIAN_TYPE_REGULAR || tp->type == EOLIAN_TYPE_CLASS)
|
2014-07-22 04:11:06 -07:00
|
|
|
printf("%s", tp->full_name);
|
2014-07-11 04:26:33 -07:00
|
|
|
else if (tp->type == EOLIAN_TYPE_VOID)
|
|
|
|
printf("void");
|
2014-07-10 04:15:29 -07:00
|
|
|
else if (tp->type == EOLIAN_TYPE_REGULAR_STRUCT)
|
2014-07-22 04:11:06 -07:00
|
|
|
printf("struct %s", tp->full_name);
|
2014-07-10 04:15:29 -07:00
|
|
|
else if (tp->type == EOLIAN_TYPE_POINTER)
|
|
|
|
{
|
|
|
|
database_type_print(tp->base_type);
|
|
|
|
putchar('*');
|
|
|
|
}
|
|
|
|
else if (tp->type == EOLIAN_TYPE_FUNCTION)
|
|
|
|
{
|
|
|
|
Eina_Bool first = EINA_TRUE;
|
2014-07-11 04:26:33 -07:00
|
|
|
printf("func");
|
2014-07-10 04:15:29 -07:00
|
|
|
if (tp->ret_type)
|
|
|
|
{
|
|
|
|
putchar(' ');
|
|
|
|
database_type_print(tp->ret_type);
|
|
|
|
}
|
|
|
|
else
|
2014-07-11 04:26:33 -07:00
|
|
|
printf(" void");
|
|
|
|
printf(" (");
|
2014-07-10 04:15:29 -07:00
|
|
|
EINA_LIST_FOREACH(tp->arguments, l, stp)
|
|
|
|
{
|
2014-07-11 04:26:33 -07:00
|
|
|
if (!first) printf(", ");
|
2014-07-10 04:15:29 -07:00
|
|
|
first = EINA_FALSE;
|
|
|
|
database_type_print(stp);
|
|
|
|
}
|
|
|
|
putchar(')');
|
|
|
|
}
|
|
|
|
else if (tp->type == EOLIAN_TYPE_STRUCT)
|
|
|
|
{
|
2014-07-11 04:26:33 -07:00
|
|
|
printf("struct ");
|
2014-07-10 04:15:29 -07:00
|
|
|
if (tp->name) printf("%s ", tp->name);
|
2014-07-11 04:26:33 -07:00
|
|
|
printf("{ ");
|
2014-07-10 04:15:29 -07:00
|
|
|
eina_hash_foreach(tp->fields, _print_field, NULL);
|
2014-07-11 04:26:33 -07:00
|
|
|
printf("}");
|
2014-07-10 04:15:29 -07:00
|
|
|
}
|
|
|
|
if (tp->is_own)
|
|
|
|
putchar(')');
|
|
|
|
if (tp->is_const)
|
|
|
|
putchar(')');
|
|
|
|
}
|