summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-02-17 02:20:35 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2019-02-17 02:26:22 +0100
commitdc563769900310241962c3e920559a1074ea5d2f (patch)
tree587eea63298240558b60c3935986918a4dbdb812
parent9674dadbdad9f03afe802733e119444e38af3096 (diff)
eolian: disallow freefuncs on typedefs
Now the only kind of typedecl that is allowed a freefunc is a struct. This simplifies the overall logic and makes freefuncs a bit more predictable.
-rw-r--r--src/lib/eolian/eo_parser.c76
1 files changed, 32 insertions, 44 deletions
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index d7e5abb636..f28d8ae86c 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -593,40 +593,6 @@ parse_enum(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
593 return def; 593 return def;
594} 594}
595 595
596static void
597parse_struct_attrs(Eo_Lexer *ls, Eina_Bool is_enum, Eina_Bool *is_extern,
598 const char **freefunc)
599{
600 Eina_Bool has_extern = EINA_FALSE, has_free = EINA_FALSE;
601 *freefunc = NULL;
602 *is_extern = EINA_FALSE;
603 for (;;) switch (ls->t.kw)
604 {
605 case KW_at_extern:
606 CASE_LOCK(ls, extern, "@extern qualifier")
607 eo_lexer_get(ls);
608 *is_extern = EINA_TRUE;
609 break;
610 case KW_at_free:
611 {
612 CASE_LOCK(ls, free, "@free qualifier")
613 if (is_enum)
614 eo_lexer_syntax_error(ls, "enums cannot have @free");
615 eo_lexer_get(ls);
616 int pline = ls->line_number, pcol = ls->column;
617 check_next(ls, '(');
618 check(ls, TOK_VALUE);
619 *freefunc = eina_stringshare_add(ls->t.value.s);
620 eo_lexer_dtor_push(ls, EINA_FREE_CB(eina_stringshare_del), (void *)*freefunc);
621 eo_lexer_get(ls);
622 check_match(ls, ')', '(', pline, pcol);
623 break;
624 }
625 default:
626 return;
627 }
628}
629
630static Eolian_Type * 596static Eolian_Type *
631parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ptr) 597parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ptr)
632{ 598{
@@ -778,18 +744,14 @@ static Eolian_Typedecl *
778parse_typedef(Eo_Lexer *ls) 744parse_typedef(Eo_Lexer *ls)
779{ 745{
780 Eolian_Typedecl *def = eo_lexer_typedecl_new(ls); 746 Eolian_Typedecl *def = eo_lexer_typedecl_new(ls);
781 Eina_Bool has_extern;
782 const char *freefunc;
783 Eina_Strbuf *buf; 747 Eina_Strbuf *buf;
784 eo_lexer_get(ls); 748 eo_lexer_get(ls);
785 parse_struct_attrs(ls, EINA_FALSE, &has_extern, &freefunc); 749 if (ls->t.kw == KW_at_extern)
786 if (freefunc)
787 { 750 {
788 def->freefunc = eina_stringshare_ref(freefunc); 751 def->is_extern = EINA_TRUE;
789 eo_lexer_dtor_pop(ls); 752 eo_lexer_get(ls);
790 } 753 }
791 def->type = EOLIAN_TYPEDECL_ALIAS; 754 def->type = EOLIAN_TYPEDECL_ALIAS;
792 def->is_extern = has_extern;
793 buf = eina_strbuf_new(); 755 buf = eina_strbuf_new();
794 eo_lexer_dtor_push(ls, EINA_FREE_CB(eina_strbuf_free), buf); 756 eo_lexer_dtor_push(ls, EINA_FREE_CB(eina_strbuf_free), buf);
795 eo_lexer_context_push(ls); 757 eo_lexer_context_push(ls);
@@ -2246,11 +2208,37 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2246 Eina_Bool is_enum = (ls->t.kw == KW_enum); 2208 Eina_Bool is_enum = (ls->t.kw == KW_enum);
2247 const char *name; 2209 const char *name;
2248 int line, col; 2210 int line, col;
2249 Eina_Bool has_extern; 2211 const char *freefunc = NULL;
2250 const char *freefunc;
2251 Eina_Strbuf *buf; 2212 Eina_Strbuf *buf;
2252 eo_lexer_get(ls); 2213 eo_lexer_get(ls);
2253 parse_struct_attrs(ls, is_enum, &has_extern, &freefunc); 2214 Eina_Bool has_extern = EINA_FALSE, has_free = EINA_FALSE;
2215 for (;;) switch (ls->t.kw)
2216 {
2217 case KW_at_extern:
2218 CASE_LOCK(ls, extern, "@extern qualifier")
2219 eo_lexer_get(ls);
2220 break;
2221 case KW_at_free:
2222 {
2223 if (is_enum)
2224 goto postparams;
2225 CASE_LOCK(ls, free, "@free qualifier")
2226 if (is_enum)
2227 eo_lexer_syntax_error(ls, "enums cannot have @free");
2228 eo_lexer_get(ls);
2229 int pline = ls->line_number, pcol = ls->column;
2230 check_next(ls, '(');
2231 check(ls, TOK_VALUE);
2232 freefunc = eina_stringshare_add(ls->t.value.s);
2233 eo_lexer_dtor_push(ls, EINA_FREE_CB(eina_stringshare_del), (void *)freefunc);
2234 eo_lexer_get(ls);
2235 check_match(ls, ')', '(', pline, pcol);
2236 break;
2237 }
2238 default:
2239 goto postparams;
2240 }
2241postparams:
2254 buf = eina_strbuf_new(); 2242 buf = eina_strbuf_new();
2255 eo_lexer_dtor_push(ls, EINA_FREE_CB(eina_strbuf_free), buf); 2243 eo_lexer_dtor_push(ls, EINA_FREE_CB(eina_strbuf_free), buf);
2256 eo_lexer_context_push(ls); 2244 eo_lexer_context_push(ls);