summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-02-21 15:24:35 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2019-02-22 16:18:49 +0100
commitdc492b15864b1a358e188b8d83dd2d35c1ec7600 (patch)
tree859d581d3ba47d2b4e352a66da300a2c3a8cbf36 /src
parent45b46781a260d1d2f56a39abccc4d41d5cf26336 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/bindings/luajit/eolian.lua42
-rw-r--r--src/lib/eolian/Eolian.h4
-rw-r--r--src/lib/eolian/database_validate.c2
-rw-r--r--src/lib/eolian/eo_lexer.c2
-rw-r--r--src/lib/eolian/eo_lexer.h2
-rw-r--r--src/lib/eolian/eo_parser.c3
-rw-r--r--src/tests/eolian/data/complex_type.eo1
-rw-r--r--src/tests/eolian/eolian_parsing.c17
8 files changed, 52 insertions, 21 deletions
diff --git a/src/bindings/luajit/eolian.lua b/src/bindings/luajit/eolian.lua
index 99d596106c..098e8a5a99 100644
--- a/src/bindings/luajit/eolian.lua
+++ b/src/bindings/luajit/eolian.lua
@@ -142,15 +142,19 @@ ffi.cdef [[
142 142
143 EOLIAN_TYPE_BUILTIN_BOOL, 143 EOLIAN_TYPE_BUILTIN_BOOL,
144 144
145 EOLIAN_TYPE_BUILTIN_SLICE,
146 EOLIAN_TYPE_BUILTIN_RW_SLICE,
147
145 EOLIAN_TYPE_BUILTIN_VOID, 148 EOLIAN_TYPE_BUILTIN_VOID,
146 149
147 EOLIAN_TYPE_BUILTIN_ACCESSOR, 150 EOLIAN_TYPE_BUILTIN_ACCESSOR,
148 EOLIAN_TYPE_BUILTIN_ARRAY, 151 EOLIAN_TYPE_BUILTIN_ARRAY,
152 EOLIAN_TYPE_BUILTIN_FUTURE,
149 EOLIAN_TYPE_BUILTIN_ITERATOR, 153 EOLIAN_TYPE_BUILTIN_ITERATOR,
150 EOLIAN_TYPE_BUILTIN_HASH, 154 EOLIAN_TYPE_BUILTIN_HASH,
151 EOLIAN_TYPE_BUILTIN_LIST, 155 EOLIAN_TYPE_BUILTIN_LIST,
152 156 EOLIAN_TYPE_BUILTIN_INARRAY,
153 EOLIAN_TYPE_BUILTIN_FUTURE, 157 EOLIAN_TYPE_BUILTIN_INLIST,
154 158
155 EOLIAN_TYPE_BUILTIN_ANY_VALUE, 159 EOLIAN_TYPE_BUILTIN_ANY_VALUE,
156 EOLIAN_TYPE_BUILTIN_ANY_VALUE_PTR, 160 EOLIAN_TYPE_BUILTIN_ANY_VALUE_PTR,
@@ -158,6 +162,7 @@ ffi.cdef [[
158 EOLIAN_TYPE_BUILTIN_MSTRING, 162 EOLIAN_TYPE_BUILTIN_MSTRING,
159 EOLIAN_TYPE_BUILTIN_STRING, 163 EOLIAN_TYPE_BUILTIN_STRING,
160 EOLIAN_TYPE_BUILTIN_STRINGSHARE, 164 EOLIAN_TYPE_BUILTIN_STRINGSHARE,
165 EOLIAN_TYPE_BUILTIN_STRBUF,
161 166
162 EOLIAN_TYPE_BUILTIN_VOID_PTR, 167 EOLIAN_TYPE_BUILTIN_VOID_PTR,
163 EOLIAN_TYPE_BUILTIN_FREE_CB 168 EOLIAN_TYPE_BUILTIN_FREE_CB
@@ -822,25 +827,30 @@ M.type_builtin_type = {
822 827
823 BOOL = 30, 828 BOOL = 30,
824 829
825 VOID = 31, 830 SLICE = 31,
831 RW_SLICE = 32,
826 832
827 ACCESSOR = 32, 833 VOID = 33,
828 ARRAY = 33,
829 ITERATOR = 34,
830 HASH = 35,
831 LIST = 36,
832 834
833 FUTURE = 37, 835 ACCESSOR = 34,
836 ARRAY = 35,
837 FUTURE = 36,
838 ITERATOR = 37,
839 HASH = 38,
840 LIST = 39,
841 INARRAY = 40,
842 INLIST = 41,
834 843
835 ANY_VALUE = 38, 844 ANY_VALUE = 42,
836 ANY_VALUE_PTR = 39, 845 ANY_VALUE_PTR = 43,
837 846
838 MSTRING = 40, 847 MSTRING = 44,
839 STRING = 41, 848 STRING = 45,
840 STRINGSHARE = 42, 849 STRINGSHARE = 46,
850 STRBUF = 47.
841 851
842 VOID_PTR = 43, 852 VOID_PTR = 48,
843 FREE_CB = 44 853 FREE_CB = 49
844} 854}
845 855
846M.typedecl_type = { 856M.typedecl_type = {
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index 0320da2010..a61f1086b9 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -316,6 +316,9 @@ typedef enum
316 316
317 EOLIAN_TYPE_BUILTIN_BOOL, 317 EOLIAN_TYPE_BUILTIN_BOOL,
318 318
319 EOLIAN_TYPE_BUILTIN_SLICE,
320 EOLIAN_TYPE_BUILTIN_RW_SLICE,
321
319 EOLIAN_TYPE_BUILTIN_VOID, 322 EOLIAN_TYPE_BUILTIN_VOID,
320 323
321 EOLIAN_TYPE_BUILTIN_ACCESSOR, 324 EOLIAN_TYPE_BUILTIN_ACCESSOR,
@@ -333,6 +336,7 @@ typedef enum
333 EOLIAN_TYPE_BUILTIN_MSTRING, 336 EOLIAN_TYPE_BUILTIN_MSTRING,
334 EOLIAN_TYPE_BUILTIN_STRING, 337 EOLIAN_TYPE_BUILTIN_STRING,
335 EOLIAN_TYPE_BUILTIN_STRINGSHARE, 338 EOLIAN_TYPE_BUILTIN_STRINGSHARE,
339 EOLIAN_TYPE_BUILTIN_STRBUF,
336 340
337 EOLIAN_TYPE_BUILTIN_VOID_PTR, 341 EOLIAN_TYPE_BUILTIN_VOID_PTR,
338 EOLIAN_TYPE_BUILTIN_FREE_CB 342 EOLIAN_TYPE_BUILTIN_FREE_CB
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index 9b7c2af899..7805a407ab 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -237,7 +237,7 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
237 if (tp->base_type) 237 if (tp->base_type)
238 { 238 {
239 int kwid = eo_lexer_keyword_str_to_id(tp->base.name); 239 int kwid = eo_lexer_keyword_str_to_id(tp->base.name);
240 if (!tp->freefunc) 240 if (!tp->freefunc && kwid > KW_void)
241 { 241 {
242 tp->freefunc = eina_stringshare_add(eo_complex_frees[ 242 tp->freefunc = eina_stringshare_add(eo_complex_frees[
243 kwid - KW_accessor]); 243 kwid - KW_accessor]);
diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c
index 8e358164fd..d548cbe157 100644
--- a/src/lib/eolian/eo_lexer.c
+++ b/src/lib/eolian/eo_lexer.c
@@ -70,6 +70,8 @@ static const char * const ctypes[] =
70 70
71 "Eina_Bool", 71 "Eina_Bool",
72 72
73 "Eina_Slice", "Eina_Rw_Slice",
74
73 "void", 75 "void",
74 76
75 "Eina_Accessor *", "Eina_Array *", "Eina_Future *", "Eina_Iterator *", 77 "Eina_Accessor *", "Eina_Array *", "Eina_Future *", "Eina_Iterator *",
diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h
index 67724ec9d0..5fca6d8644 100644
--- a/src/lib/eolian/eo_lexer.h
+++ b/src/lib/eolian/eo_lexer.h
@@ -50,6 +50,8 @@ enum Tokens
50 \ 50 \
51 KW(bool), \ 51 KW(bool), \
52 \ 52 \
53 KW(slice), KW(rw_slice), \
54 \
53 KW(void), \ 55 KW(void), \
54 \ 56 \
55 KW(accessor), KW(array), KW(future), KW(iterator), KW(hash), KW(list), \ 57 KW(accessor), KW(array), KW(future), KW(iterator), KW(hash), KW(list), \
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index f28d8ae86c..cc3ea7aabb 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -684,7 +684,8 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ptr)
684 def->btype = ls->t.kw - KW_byte + 1; 684 def->btype = ls->t.kw - KW_byte + 1;
685 def->base.name = eina_stringshare_ref(ls->t.value.s); 685 def->base.name = eina_stringshare_ref(ls->t.value.s);
686 eo_lexer_get(ls); 686 eo_lexer_get(ls);
687 if (tpid >= KW_accessor && tpid <= KW_inlist) 687 if ((tpid >= KW_accessor && tpid <= KW_inlist) ||
688 (tpid >= KW_slice && tpid <= KW_rw_slice))
688 { 689 {
689 int bline = ls->line_number, bcol = ls->column; 690 int bline = ls->line_number, bcol = ls->column;
690 check_next(ls, '<'); 691 check_next(ls, '<');
diff --git a/src/tests/eolian/data/complex_type.eo b/src/tests/eolian/data/complex_type.eo
index 511a8eee76..f2c03676e0 100644
--- a/src/tests/eolian/data/complex_type.eo
+++ b/src/tests/eolian/data/complex_type.eo
@@ -15,6 +15,7 @@ class Complex_Type {
15 foo { 15 foo {
16 params { 16 params {
17 buf: mstring @owned; 17 buf: mstring @owned;
18 sl: slice<ubyte>;
18 } 19 }
19 return: list<stringshare> @owned; [[comment for method return]] 20 return: list<stringshare> @owned; [[comment for method return]]
20 } 21 }
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index 616c920440..53ffbe67fe 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -476,11 +476,10 @@ EFL_START_TEST(eolian_complex_type)
476 fail_if(eolian_type_builtin_type_get(type) != EOLIAN_TYPE_BUILTIN_STRINGSHARE); 476 fail_if(eolian_type_builtin_type_get(type) != EOLIAN_TYPE_BUILTIN_STRINGSHARE);
477 fail_if(strcmp(type_name, "Eina_Stringshare *")); 477 fail_if(strcmp(type_name, "Eina_Stringshare *"));
478 eina_stringshare_del(type_name); 478 eina_stringshare_del(type_name);
479 /* Methods parameter type */ 479 /* Methods parameter types */
480 fail_if(!(iter = eolian_function_parameters_get(fid))); 480 fail_if(!(iter = eolian_function_parameters_get(fid)));
481
481 fail_if(!(eina_iterator_next(iter, (void**)&param))); 482 fail_if(!(eina_iterator_next(iter, (void**)&param)));
482 fail_if(eina_iterator_next(iter, &dummy));
483 eina_iterator_free(iter);
484 fail_if(strcmp(eolian_parameter_name_get(param), "buf")); 483 fail_if(strcmp(eolian_parameter_name_get(param), "buf"));
485 fail_if(!(type = eolian_parameter_type_get(param))); 484 fail_if(!(type = eolian_parameter_type_get(param)));
486 fail_if(!(type_name = eolian_type_c_type_get(type, EOLIAN_C_TYPE_PARAM))); 485 fail_if(!(type_name = eolian_type_c_type_get(type, EOLIAN_C_TYPE_PARAM)));
@@ -489,6 +488,18 @@ EFL_START_TEST(eolian_complex_type)
489 fail_if(strcmp(type_name, "char *")); 488 fail_if(strcmp(type_name, "char *"));
490 eina_stringshare_del(type_name); 489 eina_stringshare_del(type_name);
491 490
491 fail_if(!(eina_iterator_next(iter, (void**)&param)));
492 fail_if(strcmp(eolian_parameter_name_get(param), "sl"));
493 fail_if(!(type = eolian_parameter_type_get(param)));
494 fail_if(!(type_name = eolian_type_c_type_get(type, EOLIAN_C_TYPE_PARAM)));
495 fail_if(eolian_type_is_owned(type));
496 fail_if(eolian_type_builtin_type_get(type) != EOLIAN_TYPE_BUILTIN_SLICE);
497 fail_if(strcmp(type_name, "Eina_Slice"));
498 eina_stringshare_del(type_name);
499
500 fail_if(eina_iterator_next(iter, &dummy));
501 eina_iterator_free(iter);
502
492 eolian_state_free(eos); 503 eolian_state_free(eos);
493} 504}
494EFL_END_TEST 505EFL_END_TEST