eolian: introduce typed slice types
Summary: This adds two new complex types, slice<T> and rw_slice<T>. This is necessary to make the type useful to bindings, as Eina_Slice on its own says nothing about what it's carrying and that prevents useful code from being generated outside of C. @feature Reviewers: bu5hm4n, segfaultxavi, lauromoura, cedric Reviewed By: cedric Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D7980
This commit is contained in:
parent
45b46781a2
commit
dc492b1586
|
@ -142,15 +142,19 @@ ffi.cdef [[
|
|||
|
||||
EOLIAN_TYPE_BUILTIN_BOOL,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_SLICE,
|
||||
EOLIAN_TYPE_BUILTIN_RW_SLICE,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_VOID,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_ACCESSOR,
|
||||
EOLIAN_TYPE_BUILTIN_ARRAY,
|
||||
EOLIAN_TYPE_BUILTIN_FUTURE,
|
||||
EOLIAN_TYPE_BUILTIN_ITERATOR,
|
||||
EOLIAN_TYPE_BUILTIN_HASH,
|
||||
EOLIAN_TYPE_BUILTIN_LIST,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_FUTURE,
|
||||
EOLIAN_TYPE_BUILTIN_INARRAY,
|
||||
EOLIAN_TYPE_BUILTIN_INLIST,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_ANY_VALUE,
|
||||
EOLIAN_TYPE_BUILTIN_ANY_VALUE_PTR,
|
||||
|
@ -158,6 +162,7 @@ ffi.cdef [[
|
|||
EOLIAN_TYPE_BUILTIN_MSTRING,
|
||||
EOLIAN_TYPE_BUILTIN_STRING,
|
||||
EOLIAN_TYPE_BUILTIN_STRINGSHARE,
|
||||
EOLIAN_TYPE_BUILTIN_STRBUF,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_VOID_PTR,
|
||||
EOLIAN_TYPE_BUILTIN_FREE_CB
|
||||
|
@ -822,25 +827,30 @@ M.type_builtin_type = {
|
|||
|
||||
BOOL = 30,
|
||||
|
||||
VOID = 31,
|
||||
SLICE = 31,
|
||||
RW_SLICE = 32,
|
||||
|
||||
ACCESSOR = 32,
|
||||
ARRAY = 33,
|
||||
ITERATOR = 34,
|
||||
HASH = 35,
|
||||
LIST = 36,
|
||||
VOID = 33,
|
||||
|
||||
FUTURE = 37,
|
||||
ACCESSOR = 34,
|
||||
ARRAY = 35,
|
||||
FUTURE = 36,
|
||||
ITERATOR = 37,
|
||||
HASH = 38,
|
||||
LIST = 39,
|
||||
INARRAY = 40,
|
||||
INLIST = 41,
|
||||
|
||||
ANY_VALUE = 38,
|
||||
ANY_VALUE_PTR = 39,
|
||||
ANY_VALUE = 42,
|
||||
ANY_VALUE_PTR = 43,
|
||||
|
||||
MSTRING = 40,
|
||||
STRING = 41,
|
||||
STRINGSHARE = 42,
|
||||
MSTRING = 44,
|
||||
STRING = 45,
|
||||
STRINGSHARE = 46,
|
||||
STRBUF = 47.
|
||||
|
||||
VOID_PTR = 43,
|
||||
FREE_CB = 44
|
||||
VOID_PTR = 48,
|
||||
FREE_CB = 49
|
||||
}
|
||||
|
||||
M.typedecl_type = {
|
||||
|
|
|
@ -316,6 +316,9 @@ typedef enum
|
|||
|
||||
EOLIAN_TYPE_BUILTIN_BOOL,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_SLICE,
|
||||
EOLIAN_TYPE_BUILTIN_RW_SLICE,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_VOID,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_ACCESSOR,
|
||||
|
@ -333,6 +336,7 @@ typedef enum
|
|||
EOLIAN_TYPE_BUILTIN_MSTRING,
|
||||
EOLIAN_TYPE_BUILTIN_STRING,
|
||||
EOLIAN_TYPE_BUILTIN_STRINGSHARE,
|
||||
EOLIAN_TYPE_BUILTIN_STRBUF,
|
||||
|
||||
EOLIAN_TYPE_BUILTIN_VOID_PTR,
|
||||
EOLIAN_TYPE_BUILTIN_FREE_CB
|
||||
|
|
|
@ -237,7 +237,7 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
|
|||
if (tp->base_type)
|
||||
{
|
||||
int kwid = eo_lexer_keyword_str_to_id(tp->base.name);
|
||||
if (!tp->freefunc)
|
||||
if (!tp->freefunc && kwid > KW_void)
|
||||
{
|
||||
tp->freefunc = eina_stringshare_add(eo_complex_frees[
|
||||
kwid - KW_accessor]);
|
||||
|
|
|
@ -70,6 +70,8 @@ static const char * const ctypes[] =
|
|||
|
||||
"Eina_Bool",
|
||||
|
||||
"Eina_Slice", "Eina_Rw_Slice",
|
||||
|
||||
"void",
|
||||
|
||||
"Eina_Accessor *", "Eina_Array *", "Eina_Future *", "Eina_Iterator *",
|
||||
|
|
|
@ -50,6 +50,8 @@ enum Tokens
|
|||
\
|
||||
KW(bool), \
|
||||
\
|
||||
KW(slice), KW(rw_slice), \
|
||||
\
|
||||
KW(void), \
|
||||
\
|
||||
KW(accessor), KW(array), KW(future), KW(iterator), KW(hash), KW(list), \
|
||||
|
|
|
@ -684,7 +684,8 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ptr)
|
|||
def->btype = ls->t.kw - KW_byte + 1;
|
||||
def->base.name = eina_stringshare_ref(ls->t.value.s);
|
||||
eo_lexer_get(ls);
|
||||
if (tpid >= KW_accessor && tpid <= KW_inlist)
|
||||
if ((tpid >= KW_accessor && tpid <= KW_inlist) ||
|
||||
(tpid >= KW_slice && tpid <= KW_rw_slice))
|
||||
{
|
||||
int bline = ls->line_number, bcol = ls->column;
|
||||
check_next(ls, '<');
|
||||
|
|
|
@ -15,6 +15,7 @@ class Complex_Type {
|
|||
foo {
|
||||
params {
|
||||
buf: mstring @owned;
|
||||
sl: slice<ubyte>;
|
||||
}
|
||||
return: list<stringshare> @owned; [[comment for method return]]
|
||||
}
|
||||
|
|
|
@ -476,11 +476,10 @@ EFL_START_TEST(eolian_complex_type)
|
|||
fail_if(eolian_type_builtin_type_get(type) != EOLIAN_TYPE_BUILTIN_STRINGSHARE);
|
||||
fail_if(strcmp(type_name, "Eina_Stringshare *"));
|
||||
eina_stringshare_del(type_name);
|
||||
/* Methods parameter type */
|
||||
/* Methods parameter types */
|
||||
fail_if(!(iter = eolian_function_parameters_get(fid)));
|
||||
|
||||
fail_if(!(eina_iterator_next(iter, (void**)¶m)));
|
||||
fail_if(eina_iterator_next(iter, &dummy));
|
||||
eina_iterator_free(iter);
|
||||
fail_if(strcmp(eolian_parameter_name_get(param), "buf"));
|
||||
fail_if(!(type = eolian_parameter_type_get(param)));
|
||||
fail_if(!(type_name = eolian_type_c_type_get(type, EOLIAN_C_TYPE_PARAM)));
|
||||
|
@ -489,6 +488,18 @@ EFL_START_TEST(eolian_complex_type)
|
|||
fail_if(strcmp(type_name, "char *"));
|
||||
eina_stringshare_del(type_name);
|
||||
|
||||
fail_if(!(eina_iterator_next(iter, (void**)¶m)));
|
||||
fail_if(strcmp(eolian_parameter_name_get(param), "sl"));
|
||||
fail_if(!(type = eolian_parameter_type_get(param)));
|
||||
fail_if(!(type_name = eolian_type_c_type_get(type, EOLIAN_C_TYPE_PARAM)));
|
||||
fail_if(eolian_type_is_owned(type));
|
||||
fail_if(eolian_type_builtin_type_get(type) != EOLIAN_TYPE_BUILTIN_SLICE);
|
||||
fail_if(strcmp(type_name, "Eina_Slice"));
|
||||
eina_stringshare_del(type_name);
|
||||
|
||||
fail_if(eina_iterator_next(iter, &dummy));
|
||||
eina_iterator_free(iter);
|
||||
|
||||
eolian_state_free(eos);
|
||||
}
|
||||
EFL_END_TEST
|
||||
|
|
Loading…
Reference in New Issue