2014-06-18 03:25:07 -07:00
|
|
|
#include "eo_parser.h"
|
|
|
|
|
2014-06-20 07:07:25 -07:00
|
|
|
#define CASE_LOCK(ls, var, msg) \
|
|
|
|
if (has_##var) \
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_syntax_error(ls, "double " msg); \
|
2014-06-20 07:07:25 -07:00
|
|
|
has_##var = EINA_TRUE;
|
|
|
|
|
2014-06-20 07:46:00 -07:00
|
|
|
#define PARSE_SECTION \
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col; \
|
2014-06-20 07:46:00 -07:00
|
|
|
eo_lexer_get(ls); \
|
|
|
|
line = ls->line_number; \
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column; \
|
2014-06-20 07:46:00 -07:00
|
|
|
check_next(ls, '{'); \
|
|
|
|
while (ls->t.token != '}')
|
|
|
|
|
2014-06-18 03:25:07 -07:00
|
|
|
static void
|
|
|
|
error_expected(Eo_Lexer *ls, int token)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
char tbuf[256];
|
|
|
|
eo_lexer_token_to_str(token, tbuf);
|
|
|
|
snprintf(buf, sizeof(buf), "'%s' expected", tbuf);
|
|
|
|
eo_lexer_syntax_error(ls, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
test_next(Eo_Lexer *ls, int token)
|
|
|
|
{
|
|
|
|
if (ls->t.token == token)
|
|
|
|
{
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check(Eo_Lexer *ls, int token)
|
|
|
|
{
|
|
|
|
if (ls->t.token != token)
|
2014-07-01 10:25:17 -07:00
|
|
|
error_expected(ls, token);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_kw(Eo_Lexer *ls, int kw)
|
|
|
|
{
|
|
|
|
if (ls->t.kw != kw)
|
2014-07-01 10:25:17 -07:00
|
|
|
error_expected(ls, TOK_VALUE + kw);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_next(Eo_Lexer *ls, int token)
|
|
|
|
{
|
|
|
|
check(ls, token);
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_kw_next(Eo_Lexer *ls, int kw)
|
|
|
|
{
|
|
|
|
check_kw(ls, kw);
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(Eo_Lexer *ls, int what, int who, int where, int col)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
if (!test_next(ls, what))
|
|
|
|
{
|
|
|
|
if (where == ls->line_number)
|
2014-07-01 10:25:17 -07:00
|
|
|
error_expected(ls, what);
|
2014-06-18 03:25:07 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
char tbuf[256];
|
|
|
|
char vbuf[256];
|
|
|
|
eo_lexer_token_to_str(what, tbuf);
|
|
|
|
eo_lexer_token_to_str(who , vbuf);
|
|
|
|
snprintf(buf, sizeof(buf),
|
2014-07-22 07:01:09 -07:00
|
|
|
"'%s' expected (to close '%s' at line %d, column %d)",
|
2014-07-02 16:00:02 -07:00
|
|
|
tbuf, vbuf, where, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_syntax_error(ls, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Strbuf *
|
|
|
|
push_strbuf(Eo_Lexer *ls)
|
|
|
|
{
|
|
|
|
Eina_Strbuf *buf = eina_strbuf_new();
|
|
|
|
ls->tmp.str_bufs = eina_list_prepend(ls->tmp.str_bufs, buf);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pop_strbuf(Eo_Lexer *ls)
|
|
|
|
{
|
|
|
|
Eina_Strbuf *buf = eina_list_data_get(ls->tmp.str_bufs);
|
|
|
|
eina_strbuf_free(buf);
|
|
|
|
ls->tmp.str_bufs = eina_list_remove_list(ls->tmp.str_bufs, ls->tmp.str_bufs);
|
|
|
|
}
|
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static Eolian_Type *
|
2014-07-09 03:18:21 -07:00
|
|
|
push_type(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-10 06:44:17 -07:00
|
|
|
Eolian_Type *def = calloc(1, sizeof(Eolian_Type));
|
2014-07-09 03:18:21 -07:00
|
|
|
ls->tmp.type_defs = eina_list_prepend(ls->tmp.type_defs, def);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pop_type(Eo_Lexer *ls)
|
|
|
|
{
|
|
|
|
ls->tmp.type_defs = eina_list_remove_list(ls->tmp.type_defs, ls->tmp.type_defs);
|
|
|
|
}
|
|
|
|
|
2014-06-23 11:04:20 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-21 04:03:51 -07:00
|
|
|
static const char *
|
|
|
|
get_filename(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-22 02:15:56 -07:00
|
|
|
char *s = strdup(ls->source);
|
|
|
|
Eina_Array *arr = eina_file_split(s);
|
2014-07-21 04:03:51 -07:00
|
|
|
const char *file = eina_stringshare_add(eina_array_data_get(arr,
|
|
|
|
eina_array_count_get(arr) - 1));
|
2014-07-22 02:15:56 -07:00
|
|
|
free(s);
|
2014-07-21 04:03:51 -07:00
|
|
|
eina_array_free(arr);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2014-07-22 07:01:09 -07:00
|
|
|
static void
|
|
|
|
redef_error(Eo_Lexer *ls, Eolian_Type_Type type, Eolian_Type *old)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
char fbuf[256] = { '\0' };
|
|
|
|
const char *file = get_filename(ls);
|
|
|
|
if (file != old->file)
|
|
|
|
snprintf(fbuf, sizeof(fbuf), " in file '%s'", old->file);
|
|
|
|
eina_stringshare_del(file);
|
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"%s '%s' redefined (originally at line %d, column %d%s)",
|
|
|
|
(type == EOLIAN_TYPE_STRUCT) ? "struct" : "type alias",
|
|
|
|
old->full_name, old->line, old->column, fbuf);
|
|
|
|
eo_lexer_syntax_error(ls, buf);
|
|
|
|
}
|
|
|
|
|
2014-06-18 03:25:07 -07:00
|
|
|
static Eina_Strbuf *
|
|
|
|
parse_name(Eo_Lexer *ls, Eina_Strbuf *buf)
|
|
|
|
{
|
|
|
|
check(ls, TOK_VALUE);
|
2014-07-21 07:11:19 -07:00
|
|
|
if (eo_lexer_get_c_type(ls->t.kw))
|
|
|
|
eo_lexer_syntax_error(ls, "invalid name");
|
2014-06-18 03:25:07 -07:00
|
|
|
eina_strbuf_reset(buf);
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
eina_strbuf_append(buf, ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
2014-06-20 02:45:55 -07:00
|
|
|
if (ls->t.token != '.') break;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-20 02:45:55 -07:00
|
|
|
eina_strbuf_append(buf, ".");
|
2014-06-18 03:25:07 -07:00
|
|
|
check(ls, TOK_VALUE);
|
2014-07-21 07:11:19 -07:00
|
|
|
if (eo_lexer_get_c_type(ls->t.kw))
|
|
|
|
eo_lexer_syntax_error(ls, "invalid name");
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_List *
|
|
|
|
parse_name_list(Eo_Lexer *ls)
|
|
|
|
{
|
|
|
|
Eina_Strbuf *buf = push_strbuf(ls);
|
|
|
|
ls->tmp.str_items = NULL;
|
|
|
|
parse_name(ls, buf);
|
|
|
|
ls->tmp.str_items = eina_list_append(ls->tmp.str_items,
|
|
|
|
eina_stringshare_add(eina_strbuf_string_get(buf)));
|
|
|
|
while (test_next(ls, ','))
|
|
|
|
{
|
|
|
|
parse_name(ls, buf);
|
|
|
|
ls->tmp.str_items = eina_list_append(ls->tmp.str_items,
|
|
|
|
eina_stringshare_add(eina_strbuf_string_get(buf)));
|
|
|
|
}
|
|
|
|
pop_strbuf(ls);
|
|
|
|
return ls->tmp.str_items;
|
|
|
|
}
|
|
|
|
|
2014-07-21 07:11:19 -07:00
|
|
|
static void
|
|
|
|
_fill_type_name(Eolian_Type *tp, const char *type_name)
|
|
|
|
{
|
|
|
|
char *full_name = strdup(type_name);
|
|
|
|
char *name = full_name, *dot = full_name;
|
|
|
|
tp->full_name = type_name;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
dot = strchr(dot, '.');
|
|
|
|
if (dot)
|
|
|
|
{
|
|
|
|
*dot = '\0';
|
|
|
|
tp->namespaces = eina_list_append(tp->namespaces,
|
|
|
|
eina_stringshare_add(name));
|
|
|
|
++dot;
|
|
|
|
name = dot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (dot);
|
|
|
|
tp->name = eina_stringshare_add(name);
|
|
|
|
free(full_name);
|
|
|
|
}
|
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static Eolian_Type *parse_type_void(Eo_Lexer *ls);
|
|
|
|
static Eolian_Type *parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct,
|
2014-07-08 07:44:42 -07:00
|
|
|
Eina_Bool allow_anon);
|
2014-06-30 15:07:32 -07:00
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static Eolian_Type *
|
2014-06-30 15:07:32 -07:00
|
|
|
parse_type(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-22 07:27:11 -07:00
|
|
|
Eolian_Type *ret;
|
|
|
|
eo_lexer_context_push(ls);
|
|
|
|
ret = parse_type_void(ls);
|
2014-06-30 15:07:32 -07:00
|
|
|
if (ret->type == EOLIAN_TYPE_VOID)
|
|
|
|
{
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_restore(ls);
|
2014-06-30 15:07:32 -07:00
|
|
|
eo_lexer_syntax_error(ls, "non-void type expected");
|
|
|
|
}
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_pop(ls);
|
2014-06-30 15:07:32 -07:00
|
|
|
return ret;
|
|
|
|
}
|
2014-06-30 13:52:57 -07:00
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static Eolian_Type *
|
2014-07-08 07:44:42 -07:00
|
|
|
parse_type_struct_nonvoid(Eo_Lexer *ls, Eina_Bool allow_struct,
|
|
|
|
Eina_Bool allow_anon)
|
|
|
|
{
|
2014-07-22 07:27:11 -07:00
|
|
|
Eolian_Type *ret;
|
|
|
|
eo_lexer_context_push(ls);
|
|
|
|
ret = parse_type_struct(ls, allow_struct, allow_anon);
|
2014-07-08 07:44:42 -07:00
|
|
|
if (ret->type == EOLIAN_TYPE_VOID)
|
|
|
|
{
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_restore(ls);
|
2014-07-08 07:44:42 -07:00
|
|
|
eo_lexer_syntax_error(ls, "non-void type expected");
|
|
|
|
}
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_pop(ls);
|
2014-07-08 07:44:42 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static Eolian_Type *
|
2014-06-30 13:52:57 -07:00
|
|
|
parse_function_type(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col;
|
2014-07-10 06:44:17 -07:00
|
|
|
Eolian_Type *def = push_type(ls);
|
2014-06-30 13:52:57 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-30 14:07:13 -07:00
|
|
|
if (ls->t.kw == KW_void)
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-30 14:07:13 -07:00
|
|
|
else
|
2014-07-09 03:18:21 -07:00
|
|
|
{
|
|
|
|
def->ret_type = parse_type_void(ls);
|
|
|
|
pop_type(ls);
|
|
|
|
}
|
2014-06-30 13:52:57 -07:00
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-06-30 13:52:57 -07:00
|
|
|
check_next(ls, '(');
|
|
|
|
if (ls->t.token != ')')
|
|
|
|
{
|
|
|
|
def->arguments = eina_list_append(def->arguments, parse_type(ls));
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
2014-06-30 13:52:57 -07:00
|
|
|
while (test_next(ls, ','))
|
2014-07-09 03:18:21 -07:00
|
|
|
{
|
|
|
|
def->arguments = eina_list_append(def->arguments, parse_type(ls));
|
|
|
|
pop_type(ls);
|
|
|
|
}
|
2014-06-30 13:52:57 -07:00
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, ')', '(', line, col);
|
2014-06-30 13:52:57 -07:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static void
|
|
|
|
_struct_field_free(Eolian_Struct_Field *def)
|
|
|
|
{
|
|
|
|
database_type_del(def->type);
|
|
|
|
if (def->comment) eina_stringshare_del(def->comment);
|
2014-07-22 02:22:21 -07:00
|
|
|
free(def);
|
2014-07-10 06:44:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eolian_Type *
|
2014-07-22 06:48:08 -07:00
|
|
|
parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
|
|
|
|
int line, int column)
|
2014-07-08 07:02:36 -07:00
|
|
|
{
|
2014-07-22 06:48:08 -07:00
|
|
|
int bline = ls->line_number, bcolumn = ls->column;
|
2014-07-10 06:44:17 -07:00
|
|
|
Eolian_Type *def = push_type(ls);
|
2014-07-15 07:33:22 -07:00
|
|
|
def->is_extern = is_extern;
|
2014-07-21 04:03:51 -07:00
|
|
|
def->file = get_filename(ls);
|
2014-07-21 07:11:19 -07:00
|
|
|
if (name) _fill_type_name(def, name);
|
2014-07-08 08:17:44 -07:00
|
|
|
def->type = EOLIAN_TYPE_STRUCT;
|
2014-07-10 06:44:17 -07:00
|
|
|
def->fields = eina_hash_string_small_new(EINA_FREE_CB(_struct_field_free));
|
2014-07-08 07:44:42 -07:00
|
|
|
check_next(ls, '{');
|
2014-07-09 04:48:16 -07:00
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
def->comment = eina_stringshare_ref(ls->t.value);
|
2014-07-09 04:48:16 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-08 07:44:42 -07:00
|
|
|
while (ls->t.token != '}')
|
|
|
|
{
|
2014-07-08 08:42:33 -07:00
|
|
|
const char *fname;
|
2014-07-10 06:44:17 -07:00
|
|
|
Eolian_Struct_Field *fdef;
|
|
|
|
Eolian_Type *tp;
|
2014-07-08 07:44:42 -07:00
|
|
|
check(ls, TOK_VALUE);
|
2014-07-08 08:17:44 -07:00
|
|
|
if (eina_hash_find(def->fields, ls->t.value))
|
|
|
|
eo_lexer_syntax_error(ls, "double field definition");
|
2014-07-17 06:17:19 -07:00
|
|
|
fname = eina_stringshare_ref(ls->t.value);
|
2014-07-08 07:44:42 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ':');
|
2014-07-09 04:05:56 -07:00
|
|
|
tp = parse_type_struct_nonvoid(ls, EINA_TRUE, EINA_FALSE);
|
2014-07-10 06:44:17 -07:00
|
|
|
fdef = calloc(1, sizeof(Eolian_Struct_Field));
|
2014-07-09 04:05:56 -07:00
|
|
|
fdef->type = tp;
|
|
|
|
eina_hash_add(def->fields, fname, fdef);
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
2014-07-08 08:42:33 -07:00
|
|
|
eina_stringshare_del(fname);
|
2014-07-08 07:44:42 -07:00
|
|
|
check_next(ls, ';');
|
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
fdef->comment = eina_stringshare_ref(ls->t.value);
|
2014-07-08 07:44:42 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 06:48:08 -07:00
|
|
|
check_match(ls, '}', '{', bline, bcolumn);
|
|
|
|
def->line = line;
|
|
|
|
def->column = column;
|
2014-07-21 03:42:05 -07:00
|
|
|
if (name) database_struct_add(def);
|
2014-07-08 07:44:42 -07:00
|
|
|
return def;
|
2014-07-08 07:02:36 -07:00
|
|
|
}
|
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static Eolian_Type *
|
2014-07-08 07:02:36 -07:00
|
|
|
parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon)
|
2014-06-26 03:51:08 -07:00
|
|
|
{
|
2014-07-10 06:44:17 -07:00
|
|
|
Eolian_Type *def;
|
2014-07-14 04:11:48 -07:00
|
|
|
const char *ctype;
|
|
|
|
const char *sname = NULL;
|
2014-07-21 07:11:19 -07:00
|
|
|
Eina_Strbuf *buf;
|
2014-06-26 03:51:08 -07:00
|
|
|
switch (ls->t.kw)
|
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_const:
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col;
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-07-01 10:25:17 -07:00
|
|
|
check_next(ls, '(');
|
|
|
|
def = parse_type_void(ls);
|
|
|
|
def->is_const = EINA_TRUE;
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, ')', '(', line, col);
|
2014-07-01 10:25:17 -07:00
|
|
|
goto parse_ptr;
|
|
|
|
}
|
|
|
|
case KW_own:
|
|
|
|
{
|
2014-07-22 07:27:11 -07:00
|
|
|
int line, column;
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
column = ls->column;
|
2014-07-01 10:25:17 -07:00
|
|
|
check_next(ls, '(');
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_push(ls);
|
2014-07-01 10:25:17 -07:00
|
|
|
def = parse_type_void(ls);
|
|
|
|
if (def->type != EOLIAN_TYPE_POINTER)
|
|
|
|
{
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_restore(ls);
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_syntax_error(ls, "pointer type expected");
|
|
|
|
}
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_pop(ls);
|
2014-07-01 10:25:17 -07:00
|
|
|
def->is_own = EINA_TRUE;
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, ')', '(', line, column);
|
2014-07-01 10:25:17 -07:00
|
|
|
goto parse_ptr;
|
|
|
|
}
|
|
|
|
case KW_struct:
|
|
|
|
eo_lexer_get(ls);
|
2014-07-08 07:02:36 -07:00
|
|
|
if (allow_struct)
|
|
|
|
{
|
2014-07-15 07:33:22 -07:00
|
|
|
Eina_Bool is_extern = EINA_FALSE;
|
2014-07-21 03:47:35 -07:00
|
|
|
int line, col;
|
2014-07-15 07:33:22 -07:00
|
|
|
if (ls->t.kw == KW_at_extern)
|
|
|
|
{
|
|
|
|
is_extern = EINA_TRUE;
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-08 07:02:36 -07:00
|
|
|
if (allow_anon && ls->t.token == '{')
|
2014-07-15 07:33:22 -07:00
|
|
|
{
|
|
|
|
if (is_extern)
|
|
|
|
eo_lexer_syntax_error(ls, "extern anonymous struct");
|
2014-07-22 06:48:08 -07:00
|
|
|
return parse_struct(ls, NULL, EINA_FALSE, 0, 0);
|
2014-07-15 07:33:22 -07:00
|
|
|
}
|
2014-07-21 03:34:14 -07:00
|
|
|
/* todo: see typedef */
|
2014-07-21 07:11:19 -07:00
|
|
|
buf = push_strbuf(ls);
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_push(ls);
|
2014-07-21 03:47:35 -07:00
|
|
|
line = ls->line_number;
|
|
|
|
col = ls->column;
|
2014-07-21 07:11:19 -07:00
|
|
|
parse_name(ls, buf);
|
|
|
|
sname = eina_stringshare_add(eina_strbuf_string_get(buf));
|
|
|
|
pop_strbuf(ls);
|
2014-07-15 09:06:18 -07:00
|
|
|
if (ls->t.token == '{')
|
2014-07-21 03:47:35 -07:00
|
|
|
{
|
2014-07-22 06:48:08 -07:00
|
|
|
Eolian_Type *tp = (Eolian_Type*)eina_hash_find(_structs,
|
|
|
|
sname);
|
|
|
|
if (tp)
|
2014-07-21 08:53:25 -07:00
|
|
|
{
|
2014-07-22 06:48:08 -07:00
|
|
|
eina_stringshare_del(sname);
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_restore(ls);
|
2014-07-22 07:01:09 -07:00
|
|
|
redef_error(ls, EOLIAN_TYPE_STRUCT, tp);
|
2014-07-21 08:53:25 -07:00
|
|
|
}
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_pop(ls);
|
2014-07-22 06:48:08 -07:00
|
|
|
return parse_struct(ls, sname, is_extern, line, col);
|
2014-07-21 03:47:35 -07:00
|
|
|
}
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_pop(ls);
|
2014-07-08 07:02:36 -07:00
|
|
|
}
|
2014-07-14 04:11:48 -07:00
|
|
|
else
|
|
|
|
{
|
2014-07-21 07:11:19 -07:00
|
|
|
buf = push_strbuf(ls);
|
|
|
|
parse_name(ls, buf);
|
|
|
|
sname = eina_stringshare_add(eina_strbuf_string_get(buf));
|
|
|
|
pop_strbuf(ls);
|
2014-07-14 04:11:48 -07:00
|
|
|
}
|
2014-07-15 09:06:18 -07:00
|
|
|
def = push_type(ls);
|
|
|
|
def->type = EOLIAN_TYPE_REGULAR_STRUCT;
|
2014-07-21 07:11:19 -07:00
|
|
|
_fill_type_name(def, sname);
|
2014-07-15 09:06:18 -07:00
|
|
|
goto parse_ptr;
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_func:
|
|
|
|
return parse_function_type(ls);
|
|
|
|
default:
|
|
|
|
break;
|
2014-06-26 03:51:08 -07:00
|
|
|
}
|
2014-07-09 03:18:21 -07:00
|
|
|
def = push_type(ls);
|
2014-07-15 09:06:18 -07:00
|
|
|
if (ls->t.kw == KW_void)
|
2014-07-21 07:11:19 -07:00
|
|
|
{
|
|
|
|
def->type = EOLIAN_TYPE_VOID;
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-06-30 15:07:32 -07:00
|
|
|
else
|
|
|
|
{
|
2014-07-15 09:06:18 -07:00
|
|
|
def->type = EOLIAN_TYPE_REGULAR;
|
2014-06-30 15:07:32 -07:00
|
|
|
check(ls, TOK_VALUE);
|
|
|
|
ctype = eo_lexer_get_c_type(ls->t.kw);
|
2014-07-21 07:11:19 -07:00
|
|
|
if (ctype)
|
|
|
|
{
|
|
|
|
_fill_type_name(def, eina_stringshare_add(ctype));
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf = push_strbuf(ls);
|
|
|
|
parse_name(ls, buf);
|
|
|
|
_fill_type_name(def, eina_stringshare_add(eina_strbuf_string_get
|
|
|
|
(buf)));
|
|
|
|
pop_strbuf(ls);
|
|
|
|
}
|
2014-06-30 15:07:32 -07:00
|
|
|
}
|
2014-06-26 03:51:08 -07:00
|
|
|
parse_ptr:
|
|
|
|
while (ls->t.token == '*')
|
|
|
|
{
|
2014-07-10 06:44:17 -07:00
|
|
|
Eolian_Type *pdef;
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
|
|
|
pdef = push_type(ls);
|
2014-06-27 06:47:40 -07:00
|
|
|
pdef->base_type = def;
|
|
|
|
pdef->type = EOLIAN_TYPE_POINTER;
|
|
|
|
def = pdef;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-06-18 05:57:47 -07:00
|
|
|
if (ls->t.token == '<')
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line = ls->line_number, col = ls->column;
|
2014-06-18 05:57:47 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-27 06:47:40 -07:00
|
|
|
def->subtypes = eina_list_append(def->subtypes, parse_type(ls));
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
2014-06-26 07:55:18 -07:00
|
|
|
while (test_next(ls, ','))
|
2014-07-09 03:18:21 -07:00
|
|
|
{
|
|
|
|
def->subtypes = eina_list_append(def->subtypes, parse_type(ls));
|
|
|
|
pop_type(ls);
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '>', '<', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
2014-06-27 06:47:40 -07:00
|
|
|
return def;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
2014-07-10 06:44:17 -07:00
|
|
|
static Eolian_Type *
|
2014-07-08 07:02:36 -07:00
|
|
|
parse_type_void(Eo_Lexer *ls)
|
|
|
|
{
|
|
|
|
return parse_type_struct(ls, EINA_FALSE, EINA_FALSE);
|
|
|
|
}
|
|
|
|
|
2014-07-21 08:53:25 -07:00
|
|
|
static Eolian_Type *
|
2014-06-18 03:25:07 -07:00
|
|
|
parse_typedef(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-21 08:53:25 -07:00
|
|
|
Eolian_Type *def = push_type(ls);
|
|
|
|
Eina_Bool is_extern = EINA_FALSE;
|
|
|
|
Eina_Strbuf *buf;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-07-15 07:33:22 -07:00
|
|
|
if (ls->t.kw == KW_at_extern)
|
|
|
|
{
|
2014-07-21 08:53:25 -07:00
|
|
|
is_extern = EINA_TRUE;
|
2014-07-15 07:33:22 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-21 09:12:35 -07:00
|
|
|
def->type = EOLIAN_TYPE_ALIAS;
|
2014-07-21 08:53:25 -07:00
|
|
|
def->is_extern = is_extern;
|
|
|
|
buf = push_strbuf(ls);
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_push(ls);
|
2014-07-22 06:48:08 -07:00
|
|
|
def->line = ls->line_number;
|
|
|
|
def->column = ls->column;
|
2014-07-21 08:53:25 -07:00
|
|
|
parse_name(ls, buf);
|
|
|
|
_fill_type_name(def, eina_stringshare_add(eina_strbuf_string_get(buf)));
|
2014-07-21 03:34:14 -07:00
|
|
|
/* todo: store info about the previous definition and mention it here */
|
2014-07-22 06:48:08 -07:00
|
|
|
Eolian_Type *tp = (Eolian_Type*)eina_hash_find(_aliases, def->full_name);
|
|
|
|
if (tp)
|
2014-07-21 08:53:25 -07:00
|
|
|
{
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_restore(ls);
|
2014-07-22 07:01:09 -07:00
|
|
|
redef_error(ls, EOLIAN_TYPE_ALIAS, tp);
|
2014-07-21 08:53:25 -07:00
|
|
|
}
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_pop(ls);
|
2014-07-21 08:53:25 -07:00
|
|
|
def->file = get_filename(ls);
|
2014-07-09 02:19:36 -07:00
|
|
|
(void)!!test_next(ls, ':');
|
2014-07-21 08:53:25 -07:00
|
|
|
def->base_type = parse_type_struct_nonvoid(ls, EINA_TRUE, EINA_TRUE);
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
check_next(ls, ';');
|
2014-07-23 02:57:23 -07:00
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
|
|
|
def->comment = eina_stringshare_ref(ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-21 08:53:25 -07:00
|
|
|
return def;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-30 15:13:04 -07:00
|
|
|
parse_return(Eo_Lexer *ls, Eina_Bool allow_void)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
Eo_Ret_Def *ret = calloc(1, sizeof(Eo_Ret_Def));
|
|
|
|
ls->tmp.ret_def = ret;
|
|
|
|
eo_lexer_get(ls);
|
2014-06-30 15:13:04 -07:00
|
|
|
if (allow_void)
|
2014-07-01 10:25:17 -07:00
|
|
|
ret->type = parse_type_void(ls);
|
2014-06-30 15:13:04 -07:00
|
|
|
else
|
2014-07-01 10:25:17 -07:00
|
|
|
ret->type = parse_type(ls);
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
if (ls->t.token == '(')
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line = ls->line_number, col = ls->column;
|
2014-06-19 07:05:24 -07:00
|
|
|
eo_lexer_get_balanced(ls, '(', ')');
|
2014-07-17 06:17:19 -07:00
|
|
|
ret->default_ret_val = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, ')', '(', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
if (ls->t.kw == KW_at_warn_unused)
|
|
|
|
{
|
|
|
|
ret->warn_unused = EINA_TRUE;
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
check_next(ls, ';');
|
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
ret->comment = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_param(Eo_Lexer *ls, Eina_Bool allow_inout)
|
|
|
|
{
|
|
|
|
Eo_Param_Def *par = calloc(1, sizeof(Eo_Param_Def));
|
|
|
|
ls->tmp.param = par;
|
|
|
|
if (allow_inout)
|
|
|
|
{
|
|
|
|
if (ls->t.kw == KW_at_in)
|
|
|
|
{
|
2014-07-10 07:40:58 -07:00
|
|
|
par->way = EOLIAN_IN_PARAM;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
else if (ls->t.kw == KW_at_out)
|
|
|
|
{
|
2014-07-10 07:40:58 -07:00
|
|
|
par->way = EOLIAN_OUT_PARAM;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
else if (ls->t.kw == KW_at_inout)
|
|
|
|
{
|
2014-07-10 07:40:58 -07:00
|
|
|
par->way = EOLIAN_INOUT_PARAM;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
else
|
2014-07-10 07:40:58 -07:00
|
|
|
par->way = EOLIAN_IN_PARAM;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
2014-07-10 07:40:58 -07:00
|
|
|
if (par->way == EOLIAN_OUT_PARAM)
|
2014-06-30 15:21:36 -07:00
|
|
|
par->type = parse_type_void(ls);
|
|
|
|
else
|
|
|
|
par->type = parse_type(ls);
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
check(ls, TOK_VALUE);
|
2014-07-17 06:17:19 -07:00
|
|
|
par->name = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
if (ls->t.kw == KW_at_nonull)
|
|
|
|
{
|
|
|
|
par->nonull = EINA_TRUE;
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
check_next(ls, ';');
|
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
par->comment = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_legacy(Eo_Lexer *ls)
|
|
|
|
{
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
check(ls, TOK_VALUE);
|
2014-07-17 06:17:19 -07:00
|
|
|
ls->tmp.legacy_def = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ';');
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_attrs(Eo_Lexer *ls)
|
|
|
|
{
|
|
|
|
Eo_Accessor_Param *acc = NULL;
|
2014-07-07 07:14:00 -07:00
|
|
|
Eina_Bool has_const = EINA_FALSE;
|
2014-06-18 03:25:07 -07:00
|
|
|
acc = calloc(1, sizeof(Eo_Accessor_Param));
|
|
|
|
ls->tmp.accessor_param = acc;
|
2014-07-17 06:17:19 -07:00
|
|
|
acc->name = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ':');
|
|
|
|
check(ls, TOK_VALUE);
|
2014-07-01 10:25:17 -07:00
|
|
|
for (;;) switch (ls->t.kw)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_const:
|
|
|
|
CASE_LOCK(ls, const, "const qualifier")
|
2014-07-07 07:14:00 -07:00
|
|
|
acc->is_const = EINA_TRUE;
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
break;
|
|
|
|
default:
|
2014-07-07 07:14:00 -07:00
|
|
|
if (ls->t.token != ';')
|
|
|
|
eo_lexer_syntax_error(ls, "attribute expected");
|
2014-07-01 10:25:17 -07:00
|
|
|
goto end;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
end:
|
|
|
|
check_next(ls, ';');
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_accessor(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col;
|
2014-06-18 03:25:07 -07:00
|
|
|
Eo_Accessor_Def *acc = NULL;
|
|
|
|
Eina_Bool has_return = EINA_FALSE, has_legacy = EINA_FALSE;
|
|
|
|
acc = calloc(1, sizeof(Eo_Accessor_Def));
|
|
|
|
ls->tmp.accessor = acc;
|
|
|
|
acc->type = (ls->t.kw == KW_get) ? GETTER : SETTER;
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-06-18 03:25:07 -07:00
|
|
|
check_next(ls, '{');
|
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
acc->comment = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-01 10:25:17 -07:00
|
|
|
for (;;) switch (ls->t.kw)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_return:
|
|
|
|
CASE_LOCK(ls, return, "return")
|
|
|
|
parse_return(ls, acc->type == GETTER);
|
|
|
|
acc->ret = ls->tmp.ret_def;
|
|
|
|
ls->tmp.ret_def = NULL;
|
|
|
|
break;
|
|
|
|
case KW_legacy:
|
|
|
|
CASE_LOCK(ls, legacy, "legacy name")
|
|
|
|
parse_legacy(ls);
|
|
|
|
acc->legacy = ls->tmp.legacy_def;
|
|
|
|
ls->tmp.legacy_def = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (ls->t.token != '}')
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
check(ls, TOK_VALUE);
|
|
|
|
parse_attrs(ls);
|
|
|
|
acc->params = eina_list_append(acc->params,
|
|
|
|
ls->tmp.accessor_param);
|
|
|
|
ls->tmp.accessor_param = NULL;
|
|
|
|
/* this code path is disabled for the time being,
|
|
|
|
* it's not used in regular eolian yet either...
|
|
|
|
eo_lexer_lookahead(ls);
|
|
|
|
if (ls->lookahead.token == ':')
|
|
|
|
parse_attrs(ls);
|
|
|
|
else
|
|
|
|
parse_param(ls, EINA_TRUE);*/
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
2014-07-01 10:25:17 -07:00
|
|
|
else
|
|
|
|
goto end;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
end:
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-20 03:33:25 -07:00
|
|
|
parse_params(Eo_Lexer *ls, Eina_Bool allow_inout)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-20 07:46:00 -07:00
|
|
|
PARSE_SECTION
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-20 03:33:25 -07:00
|
|
|
parse_param(ls, allow_inout);
|
2014-06-18 03:25:07 -07:00
|
|
|
ls->tmp.params = eina_list_append(ls->tmp.params, ls->tmp.param);
|
|
|
|
ls->tmp.param = NULL;
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_property(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col;
|
2014-06-18 03:25:07 -07:00
|
|
|
Eo_Property_Def *prop = NULL;
|
|
|
|
Eina_Bool has_get = EINA_FALSE, has_set = EINA_FALSE,
|
|
|
|
has_keys = EINA_FALSE, has_values = EINA_FALSE;
|
|
|
|
prop = calloc(1, sizeof(Eo_Property_Def));
|
|
|
|
ls->tmp.prop = prop;
|
2014-07-22 08:35:54 -07:00
|
|
|
check(ls, TOK_VALUE);
|
|
|
|
prop->name = eina_stringshare_ref(ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
if (ls->t.kw == KW_at_protected)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-30 15:17:05 -07:00
|
|
|
prop->scope = EOLIAN_SCOPE_PROTECTED;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-06-18 03:25:07 -07:00
|
|
|
check_next(ls, '{');
|
2014-07-01 10:25:17 -07:00
|
|
|
for (;;) switch (ls->t.kw)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_get:
|
|
|
|
CASE_LOCK(ls, get, "get definition")
|
|
|
|
parse_accessor(ls);
|
|
|
|
prop->accessors = eina_list_append(prop->accessors,
|
|
|
|
ls->tmp.accessor);
|
|
|
|
ls->tmp.accessor = NULL;
|
|
|
|
break;
|
|
|
|
case KW_set:
|
|
|
|
CASE_LOCK(ls, set, "set definition")
|
|
|
|
parse_accessor(ls);
|
|
|
|
prop->accessors = eina_list_append(prop->accessors,
|
|
|
|
ls->tmp.accessor);
|
|
|
|
ls->tmp.accessor = NULL;
|
|
|
|
break;
|
|
|
|
case KW_keys:
|
|
|
|
CASE_LOCK(ls, keys, "keys definition")
|
|
|
|
parse_params(ls, EINA_FALSE);
|
|
|
|
prop->keys = ls->tmp.params;
|
|
|
|
ls->tmp.params = NULL;
|
|
|
|
break;
|
|
|
|
case KW_values:
|
|
|
|
CASE_LOCK(ls, values, "values definition")
|
|
|
|
parse_params(ls, EINA_FALSE);
|
|
|
|
prop->values = ls->tmp.params;
|
|
|
|
ls->tmp.params = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto end;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
end:
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_method(Eo_Lexer *ls, Eina_Bool ctor)
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col;
|
2014-06-18 03:25:07 -07:00
|
|
|
Eo_Method_Def *meth = NULL;
|
|
|
|
Eina_Bool has_const = EINA_FALSE, has_params = EINA_FALSE,
|
2014-07-22 09:13:24 -07:00
|
|
|
has_return = EINA_FALSE, has_legacy = EINA_FALSE,
|
|
|
|
has_protected = EINA_FALSE;
|
2014-06-18 03:25:07 -07:00
|
|
|
meth = calloc(1, sizeof(Eo_Method_Def));
|
|
|
|
ls->tmp.meth = meth;
|
|
|
|
if (ctor)
|
|
|
|
{
|
|
|
|
if (ls->t.token != TOK_VALUE)
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_syntax_error(ls, "expected method name");
|
2014-07-17 06:17:19 -07:00
|
|
|
meth->name = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-22 08:35:54 -07:00
|
|
|
check(ls, TOK_VALUE);
|
|
|
|
meth->name = eina_stringshare_ref(ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
2014-07-22 09:13:24 -07:00
|
|
|
for (;;) switch (ls->t.kw)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-22 09:13:24 -07:00
|
|
|
case KW_at_protected:
|
|
|
|
CASE_LOCK(ls, protected, "protected qualifier")
|
2014-06-30 15:17:05 -07:00
|
|
|
meth->scope = EOLIAN_SCOPE_PROTECTED;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-07-22 09:13:24 -07:00
|
|
|
break;
|
|
|
|
case KW_at_const:
|
|
|
|
CASE_LOCK(ls, const, "const qualifier")
|
|
|
|
meth->obj_const = EINA_TRUE;
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto body;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
}
|
2014-07-22 09:13:24 -07:00
|
|
|
body:
|
2014-06-18 03:25:07 -07:00
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-06-18 03:25:07 -07:00
|
|
|
check_next(ls, '{');
|
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
meth->comment = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-01 10:25:17 -07:00
|
|
|
for (;;) switch (ls->t.kw)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_return:
|
|
|
|
CASE_LOCK(ls, return, "return")
|
|
|
|
parse_return(ls, EINA_FALSE);
|
|
|
|
meth->ret = ls->tmp.ret_def;
|
|
|
|
ls->tmp.ret_def = NULL;
|
|
|
|
break;
|
|
|
|
case KW_legacy:
|
|
|
|
CASE_LOCK(ls, legacy, "legacy name")
|
|
|
|
parse_legacy(ls);
|
|
|
|
meth->legacy = ls->tmp.legacy_def;
|
|
|
|
ls->tmp.legacy_def = NULL;
|
|
|
|
break;
|
|
|
|
case KW_params:
|
|
|
|
CASE_LOCK(ls, params, "params definition")
|
|
|
|
parse_params(ls, EINA_TRUE);
|
|
|
|
meth->params = ls->tmp.params;
|
|
|
|
ls->tmp.params = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto end;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
end:
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-20 04:24:10 -07:00
|
|
|
parse_implement(Eo_Lexer *ls, Eina_Bool iface)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
Eina_Strbuf *buf = NULL;
|
2014-07-10 07:23:06 -07:00
|
|
|
Eolian_Implement *impl = NULL;
|
2014-06-18 03:25:07 -07:00
|
|
|
buf = push_strbuf(ls);
|
2014-07-10 07:23:06 -07:00
|
|
|
impl = calloc(1, sizeof(Eolian_Implement));
|
2014-06-18 03:25:07 -07:00
|
|
|
ls->tmp.impl = impl;
|
2014-06-20 04:24:10 -07:00
|
|
|
if (iface)
|
2014-07-01 10:25:17 -07:00
|
|
|
check_kw(ls, KW_class);
|
2014-06-18 03:25:07 -07:00
|
|
|
if (ls->t.kw == KW_class)
|
|
|
|
{
|
2014-06-20 02:45:55 -07:00
|
|
|
eina_strbuf_append(buf, "class.");
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-20 02:45:55 -07:00
|
|
|
check_next(ls, '.');
|
2014-06-18 03:25:07 -07:00
|
|
|
if (ls->t.kw == KW_destructor)
|
|
|
|
{
|
|
|
|
eina_strbuf_append(buf, "destructor");
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_kw_next(ls, KW_constructor);
|
|
|
|
eina_strbuf_append(buf, "constructor");
|
|
|
|
}
|
|
|
|
check_next(ls, ';');
|
2014-07-10 07:23:06 -07:00
|
|
|
impl->full_name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
2014-06-18 03:25:07 -07:00
|
|
|
pop_strbuf(ls);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (ls->t.kw == KW_virtual)
|
|
|
|
{
|
2014-06-20 02:45:55 -07:00
|
|
|
eina_strbuf_append(buf, "virtual.");
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-20 02:45:55 -07:00
|
|
|
check_next(ls, '.');
|
2014-06-18 03:25:07 -07:00
|
|
|
if ((ls->t.token != TOK_VALUE) || (ls->t.kw == KW_get || ls->t.kw == KW_set))
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_syntax_error(ls, "name expected");
|
2014-06-18 03:25:07 -07:00
|
|
|
eina_strbuf_append(buf, ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
2014-06-20 02:45:55 -07:00
|
|
|
if (ls->t.token == '.')
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
if (ls->t.kw == KW_set)
|
|
|
|
{
|
2014-06-20 02:45:55 -07:00
|
|
|
eina_strbuf_append(buf, ".set");
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
check_kw_next(ls, KW_get);
|
2014-06-20 02:45:55 -07:00
|
|
|
eina_strbuf_append(buf, ".get");
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
check_next(ls, ';');
|
2014-07-10 07:23:06 -07:00
|
|
|
impl->full_name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
2014-06-18 03:25:07 -07:00
|
|
|
pop_strbuf(ls);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((ls->t.token != TOK_VALUE) || (ls->t.kw == KW_get || ls->t.kw == KW_set))
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_syntax_error(ls, "class name expected");
|
2014-06-18 03:25:07 -07:00
|
|
|
eina_strbuf_append(buf, ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
2014-06-20 02:45:55 -07:00
|
|
|
check_next(ls, '.');
|
|
|
|
eina_strbuf_append(buf, ".");
|
2014-06-18 03:25:07 -07:00
|
|
|
if ((ls->t.token != TOK_VALUE) || (ls->t.kw == KW_get || ls->t.kw == KW_set))
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_syntax_error(ls, "name or constructor/destructor expected");
|
2014-06-18 03:25:07 -07:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
switch (ls->t.kw)
|
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_constructor:
|
|
|
|
case KW_destructor:
|
|
|
|
case KW_get:
|
|
|
|
case KW_set:
|
|
|
|
eina_strbuf_append(buf, eo_lexer_keyword_str_get(ls->t.kw));
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
goto end;
|
|
|
|
default:
|
|
|
|
break;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
check(ls, TOK_VALUE);
|
|
|
|
eina_strbuf_append(buf, ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
2014-06-20 02:45:55 -07:00
|
|
|
if (ls->t.token != '.') break;
|
|
|
|
eina_strbuf_append(buf, ".");
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
check_next(ls, ';');
|
2014-07-10 07:23:06 -07:00
|
|
|
impl->full_name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
2014-06-18 03:25:07 -07:00
|
|
|
pop_strbuf(ls);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_event(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-10 07:31:01 -07:00
|
|
|
Eolian_Event *ev = calloc(1, sizeof(Eolian_Event));
|
2014-07-16 06:43:40 -07:00
|
|
|
Eina_Strbuf *buf = push_strbuf(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
ls->tmp.event = ev;
|
|
|
|
/* code path not in use yet
|
|
|
|
if (ls->t.kw == KW_private)
|
|
|
|
{
|
2014-07-16 06:43:40 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
}*/
|
|
|
|
check(ls, TOK_VALUE);
|
2014-07-16 06:43:40 -07:00
|
|
|
eina_strbuf_append(buf, ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-07-16 06:43:40 -07:00
|
|
|
while (ls->t.token == ',')
|
|
|
|
{
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
check(ls, TOK_VALUE);
|
|
|
|
eina_strbuf_append_char(buf, ',');
|
|
|
|
eina_strbuf_append(buf, ls->t.value);
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
|
|
|
ev->name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
|
|
|
pop_strbuf(ls);
|
2014-07-15 15:50:34 -07:00
|
|
|
if (ls->t.token == ':')
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
eo_lexer_get(ls);
|
2014-07-11 03:47:37 -07:00
|
|
|
ev->type = parse_type(ls);
|
|
|
|
pop_type(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
check(ls, ';');
|
2014-07-16 06:43:40 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
ev->comment = eina_stringshare_ref(ls->t.value);
|
2014-07-16 06:43:40 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_constructors(Eo_Lexer *ls)
|
|
|
|
{
|
2014-06-20 07:46:00 -07:00
|
|
|
PARSE_SECTION
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
parse_method(ls, EINA_TRUE);
|
|
|
|
ls->tmp.kls->constructors = eina_list_append(ls->tmp.kls->constructors,
|
|
|
|
ls->tmp.meth);
|
|
|
|
ls->tmp.meth = NULL;
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_methods(Eo_Lexer *ls)
|
|
|
|
{
|
2014-06-20 07:46:00 -07:00
|
|
|
PARSE_SECTION
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
parse_method(ls, EINA_FALSE);
|
|
|
|
ls->tmp.kls->methods = eina_list_append(ls->tmp.kls->methods,
|
|
|
|
ls->tmp.meth);
|
|
|
|
ls->tmp.meth = NULL;
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_properties(Eo_Lexer *ls)
|
|
|
|
{
|
2014-06-20 07:46:00 -07:00
|
|
|
PARSE_SECTION
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
parse_property(ls);
|
|
|
|
ls->tmp.kls->properties = eina_list_append(ls->tmp.kls->properties,
|
|
|
|
ls->tmp.prop);
|
|
|
|
ls->tmp.prop = NULL;
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-20 04:24:10 -07:00
|
|
|
parse_implements(Eo_Lexer *ls, Eina_Bool iface)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-20 07:46:00 -07:00
|
|
|
PARSE_SECTION
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-20 04:24:10 -07:00
|
|
|
parse_implement(ls, iface);
|
2014-06-18 03:25:07 -07:00
|
|
|
ls->tmp.kls->implements = eina_list_append(ls->tmp.kls->implements,
|
|
|
|
ls->tmp.impl);
|
|
|
|
ls->tmp.impl = NULL;
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_events(Eo_Lexer *ls)
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col;
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-06-18 03:25:07 -07:00
|
|
|
check(ls, '{');
|
2014-07-16 06:43:40 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-06-18 03:25:07 -07:00
|
|
|
while (ls->t.token != '}')
|
|
|
|
{
|
|
|
|
parse_event(ls);
|
|
|
|
ls->tmp.kls->events = eina_list_append(ls->tmp.kls->events,
|
|
|
|
ls->tmp.event);
|
|
|
|
ls->tmp.event = NULL;
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-20 04:24:10 -07:00
|
|
|
parse_class_body(Eo_Lexer *ls, Eina_Bool allow_ctors, Eolian_Class_Type type)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
Eina_Bool has_legacy_prefix = EINA_FALSE,
|
|
|
|
has_eo_prefix = EINA_FALSE,
|
|
|
|
has_data = EINA_FALSE,
|
|
|
|
has_constructors = EINA_FALSE,
|
|
|
|
has_properties = EINA_FALSE,
|
|
|
|
has_methods = EINA_FALSE,
|
|
|
|
has_implements = EINA_FALSE,
|
|
|
|
has_events = EINA_FALSE;
|
|
|
|
if (ls->t.token == TOK_COMMENT)
|
|
|
|
{
|
2014-07-17 06:17:19 -07:00
|
|
|
ls->tmp.kls->comment = eina_stringshare_ref(ls->t.value);
|
2014-06-18 03:25:07 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-18 09:29:25 -07:00
|
|
|
if (type == EOLIAN_CLASS_INTERFACE)
|
|
|
|
{
|
|
|
|
ls->tmp.kls->data_type = eina_stringshare_add("null");
|
|
|
|
}
|
2014-07-01 10:25:17 -07:00
|
|
|
for (;;) switch (ls->t.kw)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_legacy_prefix:
|
|
|
|
CASE_LOCK(ls, legacy_prefix, "legacy prefix definition")
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ':');
|
|
|
|
check(ls, TOK_VALUE);
|
2014-07-17 06:17:19 -07:00
|
|
|
ls->tmp.kls->legacy_prefix = eina_stringshare_ref(ls->t.value);
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ';');
|
|
|
|
break;
|
|
|
|
case KW_eo_prefix:
|
|
|
|
CASE_LOCK(ls, eo_prefix, "eo prefix definition")
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ':');
|
|
|
|
check(ls, TOK_VALUE);
|
2014-07-17 06:17:19 -07:00
|
|
|
ls->tmp.kls->eo_prefix = eina_stringshare_ref(ls->t.value);
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ';');
|
|
|
|
break;
|
|
|
|
case KW_data:
|
2014-07-18 09:29:25 -07:00
|
|
|
if (type == EOLIAN_CLASS_INTERFACE) return;
|
2014-07-01 10:25:17 -07:00
|
|
|
CASE_LOCK(ls, data, "data definition")
|
|
|
|
eo_lexer_get(ls);
|
2014-07-16 07:33:11 -07:00
|
|
|
check_next(ls, ':');
|
|
|
|
check(ls, TOK_VALUE);
|
2014-07-17 06:17:19 -07:00
|
|
|
ls->tmp.kls->data_type = eina_stringshare_ref(ls->t.value);
|
2014-07-01 10:25:17 -07:00
|
|
|
eo_lexer_get(ls);
|
|
|
|
check_next(ls, ';');
|
|
|
|
break;
|
|
|
|
case KW_constructors:
|
|
|
|
if (!allow_ctors)
|
|
|
|
return;
|
|
|
|
CASE_LOCK(ls, constructors, "constructors definition")
|
|
|
|
parse_constructors(ls);
|
|
|
|
break;
|
|
|
|
case KW_properties:
|
|
|
|
CASE_LOCK(ls, properties, "properties definition")
|
|
|
|
parse_properties(ls);
|
|
|
|
break;
|
|
|
|
case KW_methods:
|
|
|
|
CASE_LOCK(ls, methods, "methods definition")
|
|
|
|
parse_methods(ls);
|
|
|
|
break;
|
|
|
|
case KW_implements:
|
|
|
|
CASE_LOCK(ls, implements, "implements definition")
|
|
|
|
parse_implements(ls, type == EOLIAN_CLASS_INTERFACE);
|
|
|
|
break;
|
|
|
|
case KW_events:
|
|
|
|
CASE_LOCK(ls, events, "events definition")
|
|
|
|
parse_events(ls);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_class(Eo_Lexer *ls, Eina_Bool allow_ctors, Eolian_Class_Type type)
|
|
|
|
{
|
2014-07-02 16:00:02 -07:00
|
|
|
int line, col;
|
2014-06-18 03:25:07 -07:00
|
|
|
Eina_Strbuf *buf = push_strbuf(ls);
|
|
|
|
ls->tmp.kls = calloc(1, sizeof(Eo_Class_Def));
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
ls->tmp.kls->type = type;
|
|
|
|
parse_name(ls, buf);
|
|
|
|
ls->tmp.kls->name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
|
|
|
pop_strbuf(ls);
|
2014-06-19 08:30:18 -07:00
|
|
|
if (ls->t.token != '{')
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-19 08:30:18 -07:00
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-06-19 08:30:18 -07:00
|
|
|
check_next(ls, '(');
|
|
|
|
if (ls->t.token != ')')
|
|
|
|
{
|
|
|
|
ls->tmp.kls->inherits = parse_name_list(ls);
|
|
|
|
ls->tmp.str_items = NULL;
|
|
|
|
}
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, ')', '(', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
line = ls->line_number;
|
2014-07-02 16:00:02 -07:00
|
|
|
col = ls->column;
|
2014-06-18 03:25:07 -07:00
|
|
|
check_next(ls, '{');
|
2014-06-20 04:24:10 -07:00
|
|
|
parse_class_body(ls, allow_ctors, type);
|
2014-07-02 16:00:02 -07:00
|
|
|
check_match(ls, '}', '{', line, col);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-24 05:45:51 -07:00
|
|
|
parse_unit(Eo_Lexer *ls, Eina_Bool eot)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
|
|
|
switch (ls->t.kw)
|
|
|
|
{
|
2014-07-01 10:25:17 -07:00
|
|
|
case KW_abstract:
|
|
|
|
if (eot) goto def;
|
|
|
|
parse_class(ls, EINA_TRUE, EOLIAN_CLASS_ABSTRACT);
|
|
|
|
goto found_class;
|
|
|
|
case KW_class:
|
|
|
|
if (eot) goto def;
|
|
|
|
parse_class(ls, EINA_TRUE, EOLIAN_CLASS_REGULAR);
|
|
|
|
goto found_class;
|
|
|
|
case KW_mixin:
|
|
|
|
if (eot) goto def;
|
|
|
|
parse_class(ls, EINA_FALSE, EOLIAN_CLASS_MIXIN);
|
|
|
|
goto found_class;
|
|
|
|
case KW_interface:
|
|
|
|
if (eot) goto def;
|
|
|
|
parse_class(ls, EINA_FALSE, EOLIAN_CLASS_INTERFACE);
|
|
|
|
goto found_class;
|
|
|
|
case KW_type:
|
|
|
|
{
|
2014-07-21 08:53:25 -07:00
|
|
|
database_type_add(parse_typedef(ls));
|
|
|
|
pop_type(ls);
|
2014-06-20 06:38:57 -07:00
|
|
|
break;
|
2014-07-01 10:25:17 -07:00
|
|
|
}
|
2014-07-08 07:02:36 -07:00
|
|
|
case KW_struct:
|
|
|
|
{
|
2014-07-08 07:44:42 -07:00
|
|
|
const char *name;
|
2014-07-22 07:27:11 -07:00
|
|
|
int line, col;
|
2014-07-22 06:48:08 -07:00
|
|
|
Eolian_Type *tp;
|
2014-07-15 07:33:22 -07:00
|
|
|
Eina_Bool is_extern = EINA_FALSE;
|
2014-07-21 07:11:19 -07:00
|
|
|
Eina_Strbuf *buf;
|
2014-07-08 07:02:36 -07:00
|
|
|
eo_lexer_get(ls);
|
2014-07-15 07:33:22 -07:00
|
|
|
if (ls->t.kw == KW_at_extern)
|
|
|
|
{
|
|
|
|
is_extern = EINA_TRUE;
|
|
|
|
eo_lexer_get(ls);
|
|
|
|
}
|
2014-07-21 07:11:19 -07:00
|
|
|
buf = push_strbuf(ls);
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_push(ls);
|
2014-07-21 08:53:25 -07:00
|
|
|
line = ls->line_number;
|
|
|
|
col = ls->column;
|
2014-07-21 07:11:19 -07:00
|
|
|
parse_name(ls, buf);
|
2014-07-22 06:48:08 -07:00
|
|
|
name = eina_stringshare_add(eina_strbuf_string_get(buf));
|
2014-07-21 03:34:14 -07:00
|
|
|
/* todo: see typedef */
|
2014-07-22 06:48:08 -07:00
|
|
|
tp = (Eolian_Type*)eina_hash_find(_structs, name);
|
|
|
|
if (tp)
|
2014-07-21 08:53:25 -07:00
|
|
|
{
|
2014-07-22 06:48:08 -07:00
|
|
|
eina_stringshare_del(name);
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_restore(ls);
|
2014-07-22 07:01:09 -07:00
|
|
|
redef_error(ls, EOLIAN_TYPE_STRUCT, tp);
|
2014-07-21 08:53:25 -07:00
|
|
|
}
|
2014-07-22 07:27:11 -07:00
|
|
|
eo_lexer_context_pop(ls);
|
2014-07-21 07:11:19 -07:00
|
|
|
pop_strbuf(ls);
|
2014-07-22 06:48:08 -07:00
|
|
|
parse_struct(ls, name, is_extern, line, col);
|
2014-07-09 03:18:21 -07:00
|
|
|
pop_type(ls);
|
2014-07-08 17:31:49 -07:00
|
|
|
break;
|
2014-07-08 07:02:36 -07:00
|
|
|
}
|
2014-07-01 10:25:17 -07:00
|
|
|
def:
|
|
|
|
default:
|
|
|
|
eo_lexer_syntax_error(ls, "invalid token");
|
|
|
|
break;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
2014-06-20 06:38:57 -07:00
|
|
|
return;
|
|
|
|
found_class:
|
2014-06-23 11:04:20 -07:00
|
|
|
append_node(ls, NODE_CLASS, ls->tmp.kls);
|
2014-06-20 06:38:57 -07:00
|
|
|
ls->tmp.kls = NULL;
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-24 05:45:51 -07:00
|
|
|
parse_chunk(Eo_Lexer *ls, Eina_Bool eot)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-07-16 08:06:04 -07:00
|
|
|
while (ls->t.token >= 0)
|
2014-07-01 10:25:17 -07:00
|
|
|
parse_unit(ls, eot);
|
2014-06-18 03:25:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
2014-06-24 05:45:51 -07:00
|
|
|
eo_parser_walk(Eo_Lexer *ls, Eina_Bool eot)
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-19 04:02:46 -07:00
|
|
|
if (!setjmp(ls->err_jmp))
|
2014-06-18 03:25:07 -07:00
|
|
|
{
|
2014-06-24 05:45:51 -07:00
|
|
|
parse_chunk(ls, eot);
|
2014-06-18 03:25:07 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|