summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-02-17 02:11:02 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2019-02-17 02:26:22 +0100
commit9674dadbdad9f03afe802733e119444e38af3096 (patch)
tree7c2aaf72803451276d150b69f6dbf690440c8bee
parentb59d2e049c05073e3ab0087e3cce0b1ae6f92d12 (diff)
eolian: restrict usage of ptr() to directly used types
That means, it can only now be used on parameters and struct fields, never aliased within typedefs. This simplifies the logic so that we don't have ptr metadata buried several layers deep.
-rw-r--r--src/lib/eolian/eo_parser.c40
-rw-r--r--src/tests/eolian/data/free_func.eo8
-rw-r--r--src/tests/eolian/eolian_parsing.c15
3 files changed, 21 insertions, 42 deletions
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 4346b3432d..d7e5abb636 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -404,14 +404,14 @@ parse_expr(Eo_Lexer *ls)
404 return parse_expr_bin(ls, 1); 404 return parse_expr_bin(ls, 1);
405} 405}
406 406
407static Eolian_Type *parse_type_void(Eo_Lexer *ls); 407static Eolian_Type *parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ptr);
408 408
409static Eolian_Type * 409static Eolian_Type *
410parse_type(Eo_Lexer *ls) 410parse_type(Eo_Lexer *ls, Eina_Bool allow_ptr)
411{ 411{
412 Eolian_Type *ret; 412 Eolian_Type *ret;
413 eo_lexer_context_push(ls); 413 eo_lexer_context_push(ls);
414 ret = parse_type_void(ls); 414 ret = parse_type_void(ls, allow_ptr);
415 if (ret->type == EOLIAN_TYPE_VOID) 415 if (ret->type == EOLIAN_TYPE_VOID)
416 { 416 {
417 eo_lexer_context_restore(ls); 417 eo_lexer_context_restore(ls);
@@ -464,7 +464,7 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
464 eolian_object_ref(&fdef->base); 464 eolian_object_ref(&fdef->base);
465 eo_lexer_get(ls); 465 eo_lexer_get(ls);
466 check_next(ls, ':'); 466 check_next(ls, ':');
467 tp = parse_type(ls); 467 tp = parse_type(ls, EINA_TRUE);
468 FILL_BASE(fdef->base, ls, fline, fcol, STRUCT_FIELD); 468 FILL_BASE(fdef->base, ls, fline, fcol, STRUCT_FIELD);
469 fdef->type = eo_lexer_type_release(ls, tp); 469 fdef->type = eo_lexer_type_release(ls, tp);
470 fdef->base.name = eina_stringshare_ref(fname); 470 fdef->base.name = eina_stringshare_ref(fname);
@@ -628,7 +628,7 @@ parse_struct_attrs(Eo_Lexer *ls, Eina_Bool is_enum, Eina_Bool *is_extern,
628} 628}
629 629
630static Eolian_Type * 630static Eolian_Type *
631parse_type_void(Eo_Lexer *ls) 631parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ptr)
632{ 632{
633 Eolian_Type *def; 633 Eolian_Type *def;
634 Eina_Strbuf *buf; 634 Eina_Strbuf *buf;
@@ -642,7 +642,7 @@ parse_type_void(Eo_Lexer *ls)
642 pline = ls->line_number; 642 pline = ls->line_number;
643 pcol = ls->column; 643 pcol = ls->column;
644 check_next(ls, '('); 644 check_next(ls, '(');
645 def = parse_type_void(ls); 645 def = parse_type_void(ls, allow_ptr);
646 FILL_BASE(def->base, ls, line, col, TYPE); 646 FILL_BASE(def->base, ls, line, col, TYPE);
647 def->is_const = EINA_TRUE; 647 def->is_const = EINA_TRUE;
648 check_match(ls, ')', '(', pline, pcol); 648 check_match(ls, ')', '(', pline, pcol);
@@ -650,12 +650,14 @@ parse_type_void(Eo_Lexer *ls)
650 } 650 }
651 case KW_ptr: 651 case KW_ptr:
652 { 652 {
653 if (!allow_ptr)
654 break;
653 int pline, pcol; 655 int pline, pcol;
654 eo_lexer_get(ls); 656 eo_lexer_get(ls);
655 pline = ls->line_number; 657 pline = ls->line_number;
656 pcol = ls->column; 658 pcol = ls->column;
657 check_next(ls, '('); 659 check_next(ls, '(');
658 def = parse_type_void(ls); 660 def = parse_type_void(ls, EINA_FALSE);
659 FILL_BASE(def->base, ls, line, col, TYPE); 661 FILL_BASE(def->base, ls, line, col, TYPE);
660 def->is_ptr = EINA_TRUE; 662 def->is_ptr = EINA_TRUE;
661 check_match(ls, ')', '(', pline, pcol); 663 check_match(ls, ')', '(', pline, pcol);
@@ -668,7 +670,7 @@ parse_type_void(Eo_Lexer *ls)
668 pline = ls->line_number; 670 pline = ls->line_number;
669 pcol = ls->column; 671 pcol = ls->column;
670 check_next(ls, '('); 672 check_next(ls, '(');
671 def = parse_type_void(ls); 673 def = parse_type_void(ls, allow_ptr);
672 FILL_BASE(def->base, ls, line, col, TYPE); 674 FILL_BASE(def->base, ls, line, col, TYPE);
673 def->legacy = EINA_TRUE; 675 def->legacy = EINA_TRUE;
674 check_match(ls, ')', '(', pline, pcol); 676 check_match(ls, ')', '(', pline, pcol);
@@ -681,7 +683,7 @@ parse_type_void(Eo_Lexer *ls)
681 pline = ls->line_number; 683 pline = ls->line_number;
682 pcolumn = ls->column; 684 pcolumn = ls->column;
683 check_next(ls, '('); 685 check_next(ls, '(');
684 def = parse_type_void(ls); 686 def = parse_type_void(ls, allow_ptr);
685 check_next(ls, ','); 687 check_next(ls, ',');
686 check(ls, TOK_VALUE); 688 check(ls, TOK_VALUE);
687 def->freefunc = eina_stringshare_ref(ls->t.value.s); 689 def->freefunc = eina_stringshare_ref(ls->t.value.s);
@@ -721,16 +723,16 @@ parse_type_void(Eo_Lexer *ls)
721 int bline = ls->line_number, bcol = ls->column; 723 int bline = ls->line_number, bcol = ls->column;
722 check_next(ls, '<'); 724 check_next(ls, '<');
723 if (tpid == KW_future) 725 if (tpid == KW_future)
724 def->base_type = eo_lexer_type_release(ls, parse_type_void(ls)); 726 def->base_type = eo_lexer_type_release(ls, parse_type_void(ls, EINA_TRUE));
725 else 727 else
726 def->base_type = eo_lexer_type_release(ls, parse_type(ls)); 728 def->base_type = eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE));
727 if ((def->base_type->owned = (ls->t.kw == KW_at_owned))) 729 if ((def->base_type->owned = (ls->t.kw == KW_at_owned)))
728 eo_lexer_get(ls); 730 eo_lexer_get(ls);
729 if (tpid == KW_hash) 731 if (tpid == KW_hash)
730 { 732 {
731 check_next(ls, ','); 733 check_next(ls, ',');
732 def->base_type->next_type = 734 def->base_type->next_type =
733 eo_lexer_type_release(ls, parse_type(ls)); 735 eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE));
734 if ((def->base_type->next_type->owned = (ls->t.kw == KW_at_owned))) 736 if ((def->base_type->next_type->owned = (ls->t.kw == KW_at_owned)))
735 eo_lexer_get(ls); 737 eo_lexer_get(ls);
736 } 738 }
@@ -802,7 +804,7 @@ parse_typedef(Eo_Lexer *ls)
802 } 804 }
803 eo_lexer_context_pop(ls); 805 eo_lexer_context_pop(ls);
804 check_next(ls, ':'); 806 check_next(ls, ':');
805 def->base_type = eo_lexer_type_release(ls, parse_type(ls)); 807 def->base_type = eo_lexer_type_release(ls, parse_type(ls, EINA_FALSE));
806 check_next(ls, ';'); 808 check_next(ls, ';');
807 FILL_DOC(ls, def, doc); 809 FILL_DOC(ls, def, doc);
808 eo_lexer_dtor_pop(ls); 810 eo_lexer_dtor_pop(ls);
@@ -835,7 +837,7 @@ parse_variable(Eo_Lexer *ls, Eina_Bool global)
835 } 837 }
836 eo_lexer_context_pop(ls); 838 eo_lexer_context_pop(ls);
837 check_next(ls, ':'); 839 check_next(ls, ':');
838 def->base_type = eo_lexer_type_release(ls, parse_type(ls)); 840 def->base_type = eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE));
839 /* constants are required to have a value */ 841 /* constants are required to have a value */
840 if (!global) 842 if (!global)
841 check(ls, '='); 843 check(ls, '=');
@@ -870,9 +872,9 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void,
870 eo_lexer_get(ls); 872 eo_lexer_get(ls);
871 check_next(ls, ':'); 873 check_next(ls, ':');
872 if (allow_void) 874 if (allow_void)
873 ret->type = parse_type_void(ls); 875 ret->type = parse_type_void(ls, EINA_TRUE);
874 else 876 else
875 ret->type = parse_type(ls); 877 ret->type = parse_type(ls, EINA_TRUE);
876 ret->doc = NULL; 878 ret->doc = NULL;
877 ret->default_ret_val = NULL; 879 ret->default_ret_val = NULL;
878 ret->warn_unused = EINA_FALSE; 880 ret->warn_unused = EINA_FALSE;
@@ -940,9 +942,9 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
940 eo_lexer_get(ls); 942 eo_lexer_get(ls);
941 check_next(ls, ':'); 943 check_next(ls, ':');
942 if (par->param_dir == EOLIAN_OUT_PARAM || par->param_dir == EOLIAN_INOUT_PARAM) 944 if (par->param_dir == EOLIAN_OUT_PARAM || par->param_dir == EOLIAN_INOUT_PARAM)
943 par->type = eo_lexer_type_release(ls, parse_type_void(ls)); 945 par->type = eo_lexer_type_release(ls, parse_type_void(ls, EINA_TRUE));
944 else 946 else
945 par->type = eo_lexer_type_release(ls, parse_type(ls)); 947 par->type = eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE));
946 if ((is_vals || (par->param_dir == EOLIAN_OUT_PARAM)) && (ls->t.token == '(')) 948 if ((is_vals || (par->param_dir == EOLIAN_OUT_PARAM)) && (ls->t.token == '('))
947 { 949 {
948 int line = ls->line_number, col = ls->column; 950 int line = ls->line_number, col = ls->column;
@@ -1775,7 +1777,7 @@ parse_event(Eo_Lexer *ls)
1775 } 1777 }
1776end: 1778end:
1777 check_next(ls, ':'); 1779 check_next(ls, ':');
1778 ev->type = eo_lexer_type_release(ls, parse_type_void(ls)); 1780 ev->type = eo_lexer_type_release(ls, parse_type_void(ls, EINA_TRUE));
1779 ev->type->owned = has_owned; 1781 ev->type->owned = has_owned;
1780 check(ls, ';'); 1782 check(ls, ';');
1781 eo_lexer_get(ls); 1783 eo_lexer_get(ls);
diff --git a/src/tests/eolian/data/free_func.eo b/src/tests/eolian/data/free_func.eo
index 6a3228ba81..55cc05e2b6 100644
--- a/src/tests/eolian/data/free_func.eo
+++ b/src/tests/eolian/data/free_func.eo
@@ -6,18 +6,10 @@ struct @free(test_free) Named2 {
6 field: int; 6 field: int;
7} 7}
8 8
9/* typedef */
10type Typedef1: int;
11type @free(def_free) Typedef2: int;
12
13/* opaque */ 9/* opaque */
14struct Opaque1; 10struct Opaque1;
15struct @free(opaque_free) Opaque2; 11struct @free(opaque_free) Opaque2;
16 12
17/* pointers */
18type Pointer1: ptr(char);
19type Pointer2: free(ptr(char), ptr_free);
20
21class Free_Func { 13class Free_Func {
22 methods { 14 methods {
23 foo { 15 foo {
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index b029a4ddad..616c920440 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -981,7 +981,6 @@ EFL_START_TEST(eolian_free_func)
981{ 981{
982 const Eolian_Class *class; 982 const Eolian_Class *class;
983 const Eolian_Typedecl *tdl; 983 const Eolian_Typedecl *tdl;
984 const Eolian_Type *type;
985 const Eolian_Unit *unit; 984 const Eolian_Unit *unit;
986 985
987 Eolian_State *eos = eolian_state_new(); 986 Eolian_State *eos = eolian_state_new();
@@ -1000,26 +999,12 @@ EFL_START_TEST(eolian_free_func)
1000 fail_if(!(tdl = eolian_unit_struct_by_name_get(unit, "Named2"))); 999 fail_if(!(tdl = eolian_unit_struct_by_name_get(unit, "Named2")));
1001 fail_if(strcmp(eolian_typedecl_free_func_get(tdl), "test_free")); 1000 fail_if(strcmp(eolian_typedecl_free_func_get(tdl), "test_free"));
1002 1001
1003 /* typedef */
1004 fail_if(!(tdl = eolian_unit_alias_by_name_get(unit, "Typedef1")));
1005 fail_if(eolian_typedecl_free_func_get(tdl));
1006 fail_if(!(tdl = eolian_unit_alias_by_name_get(unit, "Typedef2")));
1007 fail_if(strcmp(eolian_typedecl_free_func_get(tdl), "def_free"));
1008
1009 /* opaque struct */ 1002 /* opaque struct */
1010 fail_if(!(tdl = eolian_unit_struct_by_name_get(unit, "Opaque1"))); 1003 fail_if(!(tdl = eolian_unit_struct_by_name_get(unit, "Opaque1")));
1011 fail_if(eolian_typedecl_free_func_get(tdl)); 1004 fail_if(eolian_typedecl_free_func_get(tdl));
1012 fail_if(!(tdl = eolian_unit_struct_by_name_get(unit, "Opaque2"))); 1005 fail_if(!(tdl = eolian_unit_struct_by_name_get(unit, "Opaque2")));
1013 fail_if(strcmp(eolian_typedecl_free_func_get(tdl), "opaque_free")); 1006 fail_if(strcmp(eolian_typedecl_free_func_get(tdl), "opaque_free"));
1014 1007
1015 /* pointer */
1016 fail_if(!(tdl = eolian_unit_alias_by_name_get(unit, "Pointer1")));
1017 fail_if(!(type = eolian_typedecl_base_type_get(tdl)));
1018 fail_if(eolian_type_free_func_get(type));
1019 fail_if(!(tdl = eolian_unit_alias_by_name_get(unit, "Pointer2")));
1020 fail_if(!(type = eolian_typedecl_base_type_get(tdl)));
1021 fail_if(strcmp(eolian_type_free_func_get(type), "ptr_free"));
1022
1023 eolian_state_free(eos); 1008 eolian_state_free(eos);
1024} 1009}
1025EFL_END_TEST 1010EFL_END_TEST