summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-09-15 15:51:25 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-09-15 15:51:25 +0200
commit11ad2b94fff68c0ed1448598aa5371f6cdb008e9 (patch)
treef5902e018996f4ff1cd5747e6c43997a42d3667e /src
parent82fcf8aeca3fb662aa54fce7cc85fd709f5d057f (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/lib/eolian/eo_lexer.h2
-rw-r--r--src/lib/eolian/eo_parser.c31
-rw-r--r--src/lib/eolian/eolian_database.h5
3 files changed, 34 insertions, 4 deletions
diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h
index 9a82bca2ed..8d7cb214bd 100644
--- a/src/lib/eolian/eo_lexer.h
+++ b/src/lib/eolian/eo_lexer.h
@@ -31,7 +31,7 @@ enum Tokens
31 KW(set), KW(type), KW(values), KW(var), KWAT(auto), KWAT(beta), \ 31 KW(set), KW(type), KW(values), KW(var), KWAT(auto), KWAT(beta), \
32 KWAT(class), KWAT(const), KWAT(empty), KWAT(extern), \ 32 KWAT(class), KWAT(const), KWAT(empty), KWAT(extern), \
33 KWAT(free), KWAT(hot), KWAT(in), KWAT(inout), KWAT(nonull), KWAT(nullable), \ 33 KWAT(free), KWAT(hot), KWAT(in), KWAT(inout), KWAT(nonull), KWAT(nullable), \
34 KWAT(optional), KWAT(out), KWAT(private), KWAT(property), \ 34 KWAT(optional), KWAT(out), KWAT(owned), KWAT(private), KWAT(property), \
35 KWAT(protected), KWAT(restart), KWAT(pure_virtual), KWAT(warn_unused), \ 35 KWAT(protected), KWAT(restart), KWAT(pure_virtual), KWAT(warn_unused), \
36 \ 36 \
37 KW(byte), KW(ubyte), KW(char), KW(short), KW(ushort), KW(int), KW(uint), \ 37 KW(byte), KW(ubyte), KW(char), KW(short), KW(ushort), KW(int), KW(uint), \
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 5a3599f9c0..3600d3571b 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -517,6 +517,9 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
517 fdef->type = tp; 517 fdef->type = tp;
518 fdef->name = eina_stringshare_ref(fname); 518 fdef->name = eina_stringshare_ref(fname);
519 pop_type(ls); 519 pop_type(ls);
520 fdef->owned = (ls->t.kw == KW_at_owned);
521 if (fdef->owned)
522 eo_lexer_get(ls);
520 check_next(ls, ';'); 523 check_next(ls, ';');
521 FILL_DOC(ls, fdef, doc); 524 FILL_DOC(ls, fdef, doc);
522 } 525 }
@@ -964,6 +967,7 @@ typedef struct _Eo_Ret_Def
964 Eolian_Documentation *doc; 967 Eolian_Documentation *doc;
965 Eolian_Expression *default_ret_val; 968 Eolian_Expression *default_ret_val;
966 Eina_Bool warn_unused: 1; 969 Eina_Bool warn_unused: 1;
970 Eina_Bool owned: 1;
967} Eo_Ret_Def; 971} Eo_Ret_Def;
968 972
969static void 973static void
@@ -978,6 +982,7 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void, Eina_Bool allo
978 ret->doc = NULL; 982 ret->doc = NULL;
979 ret->default_ret_val = NULL; 983 ret->default_ret_val = NULL;
980 ret->warn_unused = EINA_FALSE; 984 ret->warn_unused = EINA_FALSE;
985 ret->owned = EINA_FALSE;
981 if (allow_def && (ls->t.token == '(')) 986 if (allow_def && (ls->t.token == '('))
982 { 987 {
983 int line = ls->line_number, col = ls->column; 988 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
987 ls->expr_mode = EINA_FALSE; 992 ls->expr_mode = EINA_FALSE;
988 check_match(ls, ')', '(', line, col); 993 check_match(ls, ')', '(', line, col);
989 } 994 }
990 Eina_Bool has_warn_unused = EINA_FALSE; 995 Eina_Bool has_warn_unused = EINA_FALSE, has_owned = EINA_FALSE;
991 for (;;) switch (ls->t.kw) 996 for (;;) switch (ls->t.kw)
992 { 997 {
993 case KW_at_warn_unused: 998 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
995 ret->warn_unused = EINA_TRUE; 1000 ret->warn_unused = EINA_TRUE;
996 eo_lexer_get(ls); 1001 eo_lexer_get(ls);
997 break; 1002 break;
1003 case KW_at_owned:
1004 CASE_LOCK(ls, owned, "owned qualifier");
1005 ret->owned = EINA_TRUE;
1006 eo_lexer_get(ls);
1007 break;
998 default: 1008 default:
999 goto end; 1009 goto end;
1000 } 1010 }
@@ -1008,7 +1018,7 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
1008 Eina_Bool is_vals) 1018 Eina_Bool is_vals)
1009{ 1019{
1010 Eina_Bool has_nonull = EINA_FALSE, has_optional = EINA_FALSE, 1020 Eina_Bool has_nonull = EINA_FALSE, has_optional = EINA_FALSE,
1011 has_nullable = EINA_FALSE; 1021 has_nullable = EINA_FALSE, has_owned = EINA_FALSE;
1012 Eolian_Function_Parameter *par = calloc(1, sizeof(Eolian_Function_Parameter)); 1022 Eolian_Function_Parameter *par = calloc(1, sizeof(Eolian_Function_Parameter));
1013 par->param_dir = EOLIAN_IN_PARAM; 1023 par->param_dir = EOLIAN_IN_PARAM;
1014 FILL_BASE(par->base, ls, ls->line_number, ls->column); 1024 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,
1069 par->nullable = EINA_TRUE; 1079 par->nullable = EINA_TRUE;
1070 eo_lexer_get(ls); 1080 eo_lexer_get(ls);
1071 break; 1081 break;
1082 case KW_at_owned:
1083 CASE_LOCK(ls, owned, "owned qualifier");
1084 par->owned = EINA_TRUE;
1085 eo_lexer_get(ls);
1086 break;
1072 default: 1087 default:
1073 goto end; 1088 goto end;
1074 } 1089 }
@@ -1182,6 +1197,7 @@ parse_accessor:
1182 prop->get_return_doc = ret.doc; 1197 prop->get_return_doc = ret.doc;
1183 prop->get_ret_val = ret.default_ret_val; 1198 prop->get_ret_val = ret.default_ret_val;
1184 prop->get_return_warn_unused = ret.warn_unused; 1199 prop->get_return_warn_unused = ret.warn_unused;
1200 prop->get_return_owned = ret.owned;
1185 } 1201 }
1186 else 1202 else
1187 { 1203 {
@@ -1189,6 +1205,7 @@ parse_accessor:
1189 prop->set_return_doc = ret.doc; 1205 prop->set_return_doc = ret.doc;
1190 prop->set_ret_val = ret.default_ret_val; 1206 prop->set_ret_val = ret.default_ret_val;
1191 prop->set_return_warn_unused = ret.warn_unused; 1207 prop->set_return_warn_unused = ret.warn_unused;
1208 prop->set_return_owned = ret.owned;
1192 } 1209 }
1193 break; 1210 break;
1194 case KW_legacy: 1211 case KW_legacy:
@@ -1392,6 +1409,7 @@ parse_function_pointer(Eo_Lexer *ls)
1392 meth->get_return_doc = ret.doc; 1409 meth->get_return_doc = ret.doc;
1393 meth->get_ret_val = NULL; 1410 meth->get_ret_val = NULL;
1394 meth->get_return_warn_unused = EINA_FALSE; 1411 meth->get_return_warn_unused = EINA_FALSE;
1412 meth->get_return_owned = EINA_FALSE;
1395 break; 1413 break;
1396 case KW_params: 1414 case KW_params:
1397 CASE_LOCK(ls, params, "params definition"); 1415 CASE_LOCK(ls, params, "params definition");
@@ -1486,6 +1504,7 @@ body:
1486 meth->get_return_doc = ret.doc; 1504 meth->get_return_doc = ret.doc;
1487 meth->get_ret_val = ret.default_ret_val; 1505 meth->get_ret_val = ret.default_ret_val;
1488 meth->get_return_warn_unused = ret.warn_unused; 1506 meth->get_return_warn_unused = ret.warn_unused;
1507 meth->get_return_owned = ret.owned;
1489 break; 1508 break;
1490 case KW_legacy: 1509 case KW_legacy:
1491 CASE_LOCK(ls, legacy, "legacy name") 1510 CASE_LOCK(ls, legacy, "legacy name")
@@ -1748,7 +1767,8 @@ parse_event(Eo_Lexer *ls)
1748 ev->name = eina_stringshare_add(eina_strbuf_string_get(buf)); 1767 ev->name = eina_stringshare_add(eina_strbuf_string_get(buf));
1749 pop_strbuf(ls); 1768 pop_strbuf(ls);
1750 Eina_Bool has_scope = EINA_FALSE, has_beta = EINA_FALSE, 1769 Eina_Bool has_scope = EINA_FALSE, has_beta = EINA_FALSE,
1751 has_hot = EINA_FALSE, has_restart = EINA_FALSE; 1770 has_hot = EINA_FALSE, has_restart = EINA_FALSE,
1771 has_owned = EINA_FALSE;
1752 for (;;) switch (ls->t.kw) 1772 for (;;) switch (ls->t.kw)
1753 { 1773 {
1754 case KW_at_private: 1774 case KW_at_private:
@@ -1774,6 +1794,11 @@ parse_event(Eo_Lexer *ls)
1774 ev->is_restart = EINA_TRUE; 1794 ev->is_restart = EINA_TRUE;
1775 eo_lexer_get(ls); 1795 eo_lexer_get(ls);
1776 break; 1796 break;
1797 case KW_at_owned:
1798 CASE_LOCK(ls, owned, "owned qualifier");
1799 ev->owned = EINA_TRUE;
1800 eo_lexer_get(ls);
1801 break;
1777 default: 1802 default:
1778 goto end; 1803 goto end;
1779 } 1804 }
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 261f09cad2..16a2a97981 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -131,6 +131,8 @@ struct _Eolian_Function
131 Eina_Bool obj_is_const :1; /* True if the object has to be const. Useful for a few methods. */ 131 Eina_Bool obj_is_const :1; /* True if the object has to be const. Useful for a few methods. */
132 Eina_Bool get_return_warn_unused :1; /* also used for methods */ 132 Eina_Bool get_return_warn_unused :1; /* also used for methods */
133 Eina_Bool set_return_warn_unused :1; 133 Eina_Bool set_return_warn_unused :1;
134 Eina_Bool get_return_owned :1;
135 Eina_Bool set_return_owned :1;
134 Eina_Bool get_only_legacy: 1; 136 Eina_Bool get_only_legacy: 1;
135 Eina_Bool set_only_legacy: 1; 137 Eina_Bool set_only_legacy: 1;
136 Eina_Bool is_class :1; 138 Eina_Bool is_class :1;
@@ -150,6 +152,7 @@ struct _Eolian_Function_Parameter
150 Eina_Bool nonull :1; /* True if this argument cannot be NULL - deprecated */ 152 Eina_Bool nonull :1; /* True if this argument cannot be NULL - deprecated */
151 Eina_Bool nullable :1; /* True if this argument is nullable */ 153 Eina_Bool nullable :1; /* True if this argument is nullable */
152 Eina_Bool optional :1; /* True if this argument is optional */ 154 Eina_Bool optional :1; /* True if this argument is optional */
155 Eina_Bool owned :1;
153}; 156};
154 157
155struct _Eolian_Type 158struct _Eolian_Type
@@ -223,6 +226,7 @@ struct _Eolian_Event
223 Eina_Bool is_beta :1; 226 Eina_Bool is_beta :1;
224 Eina_Bool is_hot :1; 227 Eina_Bool is_hot :1;
225 Eina_Bool is_restart :1; 228 Eina_Bool is_restart :1;
229 Eina_Bool owned :1;
226}; 230};
227 231
228struct _Eolian_Struct_Type_Field 232struct _Eolian_Struct_Type_Field
@@ -231,6 +235,7 @@ struct _Eolian_Struct_Type_Field
231 Eolian_Object base; 235 Eolian_Object base;
232 Eolian_Type *type; 236 Eolian_Type *type;
233 Eolian_Documentation *doc; 237 Eolian_Documentation *doc;
238 Eina_Bool owned :1;
234}; 239};
235 240
236struct _Eolian_Enum_Type_Field 241struct _Eolian_Enum_Type_Field