eolian: initial parsing for @owned

This is the new ownership system for Eolian, working on params,
returns, struct fields or events directly rather than specifying
ownership at type level. As the new system will evolve it will
gain missing features and necessary checks.
This commit is contained in:
Daniel Kolesa 2017-09-15 15:51:25 +02:00
parent 82fcf8aeca
commit 11ad2b94ff
3 changed files with 34 additions and 4 deletions

View File

@ -31,7 +31,7 @@ enum Tokens
KW(set), KW(type), KW(values), KW(var), KWAT(auto), KWAT(beta), \
KWAT(class), KWAT(const), KWAT(empty), KWAT(extern), \
KWAT(free), KWAT(hot), KWAT(in), KWAT(inout), KWAT(nonull), KWAT(nullable), \
KWAT(optional), KWAT(out), KWAT(private), KWAT(property), \
KWAT(optional), KWAT(out), KWAT(owned), KWAT(private), KWAT(property), \
KWAT(protected), KWAT(restart), KWAT(pure_virtual), KWAT(warn_unused), \
\
KW(byte), KW(ubyte), KW(char), KW(short), KW(ushort), KW(int), KW(uint), \

View File

@ -517,6 +517,9 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
fdef->type = tp;
fdef->name = eina_stringshare_ref(fname);
pop_type(ls);
fdef->owned = (ls->t.kw == KW_at_owned);
if (fdef->owned)
eo_lexer_get(ls);
check_next(ls, ';');
FILL_DOC(ls, fdef, doc);
}
@ -964,6 +967,7 @@ typedef struct _Eo_Ret_Def
Eolian_Documentation *doc;
Eolian_Expression *default_ret_val;
Eina_Bool warn_unused: 1;
Eina_Bool owned: 1;
} Eo_Ret_Def;
static void
@ -978,6 +982,7 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void, Eina_Bool allo
ret->doc = NULL;
ret->default_ret_val = NULL;
ret->warn_unused = EINA_FALSE;
ret->owned = EINA_FALSE;
if (allow_def && (ls->t.token == '('))
{
int line = ls->line_number, col = ls->column;
@ -987,7 +992,7 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void, Eina_Bool allo
ls->expr_mode = EINA_FALSE;
check_match(ls, ')', '(', line, col);
}
Eina_Bool has_warn_unused = EINA_FALSE;
Eina_Bool has_warn_unused = EINA_FALSE, has_owned = EINA_FALSE;
for (;;) switch (ls->t.kw)
{
case KW_at_warn_unused:
@ -995,6 +1000,11 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void, Eina_Bool allo
ret->warn_unused = EINA_TRUE;
eo_lexer_get(ls);
break;
case KW_at_owned:
CASE_LOCK(ls, owned, "owned qualifier");
ret->owned = EINA_TRUE;
eo_lexer_get(ls);
break;
default:
goto end;
}
@ -1008,7 +1018,7 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
Eina_Bool is_vals)
{
Eina_Bool has_nonull = EINA_FALSE, has_optional = EINA_FALSE,
has_nullable = EINA_FALSE;
has_nullable = EINA_FALSE, has_owned = EINA_FALSE;
Eolian_Function_Parameter *par = calloc(1, sizeof(Eolian_Function_Parameter));
par->param_dir = EOLIAN_IN_PARAM;
FILL_BASE(par->base, ls, ls->line_number, ls->column);
@ -1069,6 +1079,11 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
par->nullable = EINA_TRUE;
eo_lexer_get(ls);
break;
case KW_at_owned:
CASE_LOCK(ls, owned, "owned qualifier");
par->owned = EINA_TRUE;
eo_lexer_get(ls);
break;
default:
goto end;
}
@ -1182,6 +1197,7 @@ parse_accessor:
prop->get_return_doc = ret.doc;
prop->get_ret_val = ret.default_ret_val;
prop->get_return_warn_unused = ret.warn_unused;
prop->get_return_owned = ret.owned;
}
else
{
@ -1189,6 +1205,7 @@ parse_accessor:
prop->set_return_doc = ret.doc;
prop->set_ret_val = ret.default_ret_val;
prop->set_return_warn_unused = ret.warn_unused;
prop->set_return_owned = ret.owned;
}
break;
case KW_legacy:
@ -1392,6 +1409,7 @@ parse_function_pointer(Eo_Lexer *ls)
meth->get_return_doc = ret.doc;
meth->get_ret_val = NULL;
meth->get_return_warn_unused = EINA_FALSE;
meth->get_return_owned = EINA_FALSE;
break;
case KW_params:
CASE_LOCK(ls, params, "params definition");
@ -1486,6 +1504,7 @@ body:
meth->get_return_doc = ret.doc;
meth->get_ret_val = ret.default_ret_val;
meth->get_return_warn_unused = ret.warn_unused;
meth->get_return_owned = ret.owned;
break;
case KW_legacy:
CASE_LOCK(ls, legacy, "legacy name")
@ -1748,7 +1767,8 @@ parse_event(Eo_Lexer *ls)
ev->name = eina_stringshare_add(eina_strbuf_string_get(buf));
pop_strbuf(ls);
Eina_Bool has_scope = EINA_FALSE, has_beta = EINA_FALSE,
has_hot = EINA_FALSE, has_restart = EINA_FALSE;
has_hot = EINA_FALSE, has_restart = EINA_FALSE,
has_owned = EINA_FALSE;
for (;;) switch (ls->t.kw)
{
case KW_at_private:
@ -1774,6 +1794,11 @@ parse_event(Eo_Lexer *ls)
ev->is_restart = EINA_TRUE;
eo_lexer_get(ls);
break;
case KW_at_owned:
CASE_LOCK(ls, owned, "owned qualifier");
ev->owned = EINA_TRUE;
eo_lexer_get(ls);
break;
default:
goto end;
}

View File

@ -131,6 +131,8 @@ struct _Eolian_Function
Eina_Bool obj_is_const :1; /* True if the object has to be const. Useful for a few methods. */
Eina_Bool get_return_warn_unused :1; /* also used for methods */
Eina_Bool set_return_warn_unused :1;
Eina_Bool get_return_owned :1;
Eina_Bool set_return_owned :1;
Eina_Bool get_only_legacy: 1;
Eina_Bool set_only_legacy: 1;
Eina_Bool is_class :1;
@ -150,6 +152,7 @@ struct _Eolian_Function_Parameter
Eina_Bool nonull :1; /* True if this argument cannot be NULL - deprecated */
Eina_Bool nullable :1; /* True if this argument is nullable */
Eina_Bool optional :1; /* True if this argument is optional */
Eina_Bool owned :1;
};
struct _Eolian_Type
@ -223,6 +226,7 @@ struct _Eolian_Event
Eina_Bool is_beta :1;
Eina_Bool is_hot :1;
Eina_Bool is_restart :1;
Eina_Bool owned :1;
};
struct _Eolian_Struct_Type_Field
@ -231,6 +235,7 @@ struct _Eolian_Struct_Type_Field
Eolian_Object base;
Eolian_Type *type;
Eolian_Documentation *doc;
Eina_Bool owned :1;
};
struct _Eolian_Enum_Type_Field