summaryrefslogtreecommitdiff
path: root/src/lib/eolian
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-08-30 16:08:31 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2019-08-30 16:22:20 +0200
commitfbcad90fece71a55391056fdc41d59edd32a1dfd (patch)
treee486bf313a2b5bd74b07cdaad6218c3631d5a18e /src/lib/eolian
parentbbd213bcfb4e8dc3a809b8346cdfba2144f963ed (diff)
eolian: add parsing for @move and @by_ref
The @by_ref qualifier is now allowed on parameters, returns and struct fields in the usual qualifier section. It will mean that this type is passed around by reference, and will only be allowed on types that are not already pointer-like. The @move qualifier will replace @owned as one with a clearer meaning. It means "transfer of ownership". It has the same semantics as the current @owned, i.e. on return values it transfers ownership of the value to the caller, on parameters it transfers ownership to the callee (the inverse is the default when not specified). On struct fields, it means the field will transfer together with the struct that contains it.
Diffstat (limited to 'src/lib/eolian')
-rw-r--r--src/lib/eolian/eo_lexer.h6
-rw-r--r--src/lib/eolian/eo_parser.c54
-rw-r--r--src/lib/eolian/eolian_database.h12
3 files changed, 57 insertions, 15 deletions
diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h
index 836f06152b..96e385952f 100644
--- a/src/lib/eolian/eo_lexer.h
+++ b/src/lib/eolian/eo_lexer.h
@@ -35,9 +35,9 @@ enum Tokens
35 \ 35 \
36 KWAT(auto), KWAT(beta), KWAT(by_ref), KWAT(c_name), KWAT(const), \ 36 KWAT(auto), KWAT(beta), KWAT(by_ref), KWAT(c_name), KWAT(const), \
37 KWAT(empty), KWAT(extern), KWAT(free), KWAT(hot), KWAT(in), KWAT(inout), \ 37 KWAT(empty), KWAT(extern), KWAT(free), KWAT(hot), KWAT(in), KWAT(inout), \
38 KWAT(no_unused), KWAT(nullable), KWAT(optional), KWAT(out), KWAT(owned), \ 38 KWAT(move), KWAT(no_unused), KWAT(nullable), KWAT(optional), KWAT(out), \
39 KWAT(private), KWAT(property), KWAT(protected), KWAT(restart), \ 39 KWAT(owned), KWAT(private), KWAT(property), KWAT(protected), KWAT(restart), \
40 KWAT(pure_virtual), KWAT(static), KWAT(transfer), \ 40 KWAT(pure_virtual), KWAT(static), \
41 \ 41 \
42 KWH(version), \ 42 KWH(version), \
43 \ 43 \
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index b24a35152a..e69989aa8c 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -517,8 +517,24 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
517 FILL_BASE(fdef->base, ls, fline, fcol, STRUCT_FIELD); 517 FILL_BASE(fdef->base, ls, fline, fcol, STRUCT_FIELD);
518 fdef->type = eo_lexer_type_release(ls, tp); 518 fdef->type = eo_lexer_type_release(ls, tp);
519 fdef->base.name = eina_stringshare_ref(fname); 519 fdef->base.name = eina_stringshare_ref(fname);
520 if ((fdef->type->owned = (ls->t.kw == KW_at_owned))) 520 Eina_Bool has_owned = EINA_FALSE, has_by_ref = EINA_FALSE;
521 eo_lexer_get(ls); 521 for (;;) switch (ls->t.kw)
522 {
523 case KW_at_by_ref:
524 CASE_LOCK(ls, by_ref, "by_ref qualifier");
525 fdef->by_ref = EINA_TRUE;
526 eo_lexer_get(ls);
527 break;
528 case KW_at_owned:
529 case KW_at_move:
530 CASE_LOCK(ls, owned, "owned qualifier");
531 fdef->type->owned = fdef->move = EINA_TRUE;
532 eo_lexer_get(ls);
533 break;
534 default:
535 goto qual_end;
536 }
537qual_end:
522 check_next(ls, ';'); 538 check_next(ls, ';');
523 FILL_DOC(ls, fdef, doc); 539 FILL_DOC(ls, fdef, doc);
524 } 540 }
@@ -758,14 +774,14 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ptr)
758 def->base_type = eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE)); 774 def->base_type = eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE));
759 /* view-only types are not allowed to own the contents */ 775 /* view-only types are not allowed to own the contents */
760 if (tpid == KW_array || tpid == KW_hash || tpid == KW_list || tpid == KW_future) 776 if (tpid == KW_array || tpid == KW_hash || tpid == KW_list || tpid == KW_future)
761 if ((def->base_type->owned = (ls->t.kw == KW_at_owned))) 777 if ((def->base_type->owned = (ls->t.kw == KW_at_owned || ls->t.kw == KW_at_move)))
762 eo_lexer_get(ls); 778 eo_lexer_get(ls);
763 if (tpid == KW_hash) 779 if (tpid == KW_hash)
764 { 780 {
765 check_next(ls, ','); 781 check_next(ls, ',');
766 def->base_type->next_type = 782 def->base_type->next_type =
767 eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE)); 783 eo_lexer_type_release(ls, parse_type(ls, EINA_TRUE));
768 if ((def->base_type->next_type->owned = (ls->t.kw == KW_at_owned))) 784 if ((def->base_type->next_type->owned = (ls->t.kw == KW_at_owned || ls->t.kw == KW_at_move)))
769 eo_lexer_get(ls); 785 eo_lexer_get(ls);
770 } 786 }
771 check_match(ls, '>', '<', bline, bcol); 787 check_match(ls, '>', '<', bline, bcol);
@@ -1006,6 +1022,7 @@ typedef struct _Eo_Ret_Def
1006 Eolian_Expression *default_ret_val; 1022 Eolian_Expression *default_ret_val;
1007 Eina_Bool no_unused: 1; 1023 Eina_Bool no_unused: 1;
1008 Eina_Bool owned: 1; 1024 Eina_Bool owned: 1;
1025 Eina_Bool by_ref: 1;
1009} Eo_Ret_Def; 1026} Eo_Ret_Def;
1010 1027
1011static void 1028static void
@@ -1022,6 +1039,7 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void,
1022 ret->default_ret_val = NULL; 1039 ret->default_ret_val = NULL;
1023 ret->no_unused = EINA_FALSE; 1040 ret->no_unused = EINA_FALSE;
1024 ret->owned = EINA_FALSE; 1041 ret->owned = EINA_FALSE;
1042 ret->by_ref = EINA_FALSE;
1025 if (allow_def && (ls->t.token == '(')) 1043 if (allow_def && (ls->t.token == '('))
1026 { 1044 {
1027 int line = ls->line_number, col = ls->column; 1045 int line = ls->line_number, col = ls->column;
@@ -1031,7 +1049,8 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void,
1031 ls->expr_mode = EINA_FALSE; 1049 ls->expr_mode = EINA_FALSE;
1032 check_match(ls, ')', '(', line, col); 1050 check_match(ls, ')', '(', line, col);
1033 } 1051 }
1034 Eina_Bool has_no_unused = EINA_FALSE, has_owned = EINA_FALSE; 1052 Eina_Bool has_no_unused = EINA_FALSE, has_owned = EINA_FALSE,
1053 has_by_ref = EINA_FALSE;
1035 if (!is_funcptr) for (;;) switch (ls->t.kw) 1054 if (!is_funcptr) for (;;) switch (ls->t.kw)
1036 { 1055 {
1037 case KW_at_no_unused: 1056 case KW_at_no_unused:
@@ -1040,10 +1059,16 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void,
1040 eo_lexer_get(ls); 1059 eo_lexer_get(ls);
1041 break; 1060 break;
1042 case KW_at_owned: 1061 case KW_at_owned:
1062 case KW_at_move:
1043 CASE_LOCK(ls, owned, "owned qualifier"); 1063 CASE_LOCK(ls, owned, "owned qualifier");
1044 ret->owned = EINA_TRUE; 1064 ret->owned = EINA_TRUE;
1045 eo_lexer_get(ls); 1065 eo_lexer_get(ls);
1046 break; 1066 break;
1067 case KW_at_by_ref:
1068 CASE_LOCK(ls, by_ref, "by_ref qualifier");
1069 ret->by_ref = EINA_TRUE;
1070 eo_lexer_get(ls);
1071 break;
1047 default: 1072 default:
1048 goto end; 1073 goto end;
1049 } 1074 }
@@ -1057,7 +1082,8 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
1057 Eina_Bool is_vals) 1082 Eina_Bool is_vals)
1058{ 1083{
1059 Eina_Bool has_optional = EINA_FALSE, 1084 Eina_Bool has_optional = EINA_FALSE,
1060 has_owned = EINA_FALSE; 1085 has_owned = EINA_FALSE,
1086 has_by_ref = EINA_FALSE;
1061 Eolian_Function_Parameter *par = calloc(1, sizeof(Eolian_Function_Parameter)); 1087 Eolian_Function_Parameter *par = calloc(1, sizeof(Eolian_Function_Parameter));
1062 par->param_dir = EOLIAN_IN_PARAM; 1088 par->param_dir = EOLIAN_IN_PARAM;
1063 FILL_BASE(par->base, ls, ls->line_number, ls->column, FUNCTION_PARAMETER); 1089 FILL_BASE(par->base, ls, ls->line_number, ls->column, FUNCTION_PARAMETER);
@@ -1106,7 +1132,12 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
1106 break; 1132 break;
1107 case KW_at_owned: 1133 case KW_at_owned:
1108 CASE_LOCK(ls, owned, "owned qualifier"); 1134 CASE_LOCK(ls, owned, "owned qualifier");
1109 par->type->owned = EINA_TRUE; 1135 par->type->owned = par->move = EINA_TRUE;
1136 eo_lexer_get(ls);
1137 break;
1138 case KW_at_by_ref:
1139 CASE_LOCK(ls, by_ref, "by_ref qualifier");
1140 par->by_ref = EINA_TRUE;
1110 eo_lexer_get(ls); 1141 eo_lexer_get(ls);
1111 break; 1142 break;
1112 default: 1143 default:
@@ -1224,7 +1255,8 @@ parse_accessor:
1224 prop->get_return_doc = ret.doc; 1255 prop->get_return_doc = ret.doc;
1225 prop->get_ret_val = ret.default_ret_val; 1256 prop->get_ret_val = ret.default_ret_val;
1226 prop->get_return_no_unused = ret.no_unused; 1257 prop->get_return_no_unused = ret.no_unused;
1227 prop->get_ret_type->owned = ret.owned; 1258 prop->get_return_by_ref = ret.by_ref;
1259 prop->get_return_move = prop->get_ret_type->owned = ret.owned;
1228 } 1260 }
1229 else 1261 else
1230 { 1262 {
@@ -1232,7 +1264,8 @@ parse_accessor:
1232 prop->set_return_doc = ret.doc; 1264 prop->set_return_doc = ret.doc;
1233 prop->set_ret_val = ret.default_ret_val; 1265 prop->set_ret_val = ret.default_ret_val;
1234 prop->set_return_no_unused = ret.no_unused; 1266 prop->set_return_no_unused = ret.no_unused;
1235 prop->set_ret_type->owned = ret.owned; 1267 prop->set_return_by_ref = ret.by_ref;
1268 prop->set_return_move = prop->set_ret_type->owned = ret.owned;
1236 } 1269 }
1237 break; 1270 break;
1238 case KW_keys: 1271 case KW_keys:
@@ -1543,7 +1576,8 @@ body:
1543 meth->get_return_doc = ret.doc; 1576 meth->get_return_doc = ret.doc;
1544 meth->get_ret_val = ret.default_ret_val; 1577 meth->get_ret_val = ret.default_ret_val;
1545 meth->get_return_no_unused = ret.no_unused; 1578 meth->get_return_no_unused = ret.no_unused;
1546 meth->get_ret_type->owned = ret.owned; 1579 meth->get_return_by_ref = ret.by_ref;
1580 meth->get_return_move = meth->get_ret_type->owned = ret.owned;
1547 break; 1581 break;
1548 case KW_params: 1582 case KW_params:
1549 CASE_LOCK(ls, params, "params definition") 1583 CASE_LOCK(ls, params, "params definition")
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 1e26e24a38..e66543f6bd 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -227,12 +227,16 @@ struct _Eolian_Function
227 Eolian_Implement *impl; 227 Eolian_Implement *impl;
228 Eolian_Documentation *get_return_doc; 228 Eolian_Documentation *get_return_doc;
229 Eolian_Documentation *set_return_doc; 229 Eolian_Documentation *set_return_doc;
230 Eina_List *ctor_of;
231 Eolian_Class *klass;
230 Eina_Bool obj_is_const :1; /* True if the object has to be const. Useful for a few methods. */ 232 Eina_Bool obj_is_const :1; /* True if the object has to be const. Useful for a few methods. */
231 Eina_Bool get_return_no_unused :1; /* also used for methods */ 233 Eina_Bool get_return_no_unused :1; /* also used for methods */
232 Eina_Bool set_return_no_unused :1; 234 Eina_Bool set_return_no_unused :1;
235 Eina_Bool get_return_move :1;
236 Eina_Bool set_return_move :1;
237 Eina_Bool get_return_by_ref :1;
238 Eina_Bool set_return_by_ref :1;
233 Eina_Bool is_static :1; 239 Eina_Bool is_static :1;
234 Eina_List *ctor_of;
235 Eolian_Class *klass;
236}; 240};
237 241
238struct _Eolian_Part 242struct _Eolian_Part
@@ -255,6 +259,8 @@ struct _Eolian_Function_Parameter
255 Eolian_Documentation *doc; 259 Eolian_Documentation *doc;
256 Eolian_Parameter_Dir param_dir; 260 Eolian_Parameter_Dir param_dir;
257 Eina_Bool optional :1; /* True if this argument is optional */ 261 Eina_Bool optional :1; /* True if this argument is optional */
262 Eina_Bool by_ref :1;
263 Eina_Bool move :1;
258}; 264};
259 265
260struct _Eolian_Type 266struct _Eolian_Type
@@ -342,6 +348,8 @@ struct _Eolian_Struct_Type_Field
342 Eolian_Object base; 348 Eolian_Object base;
343 Eolian_Type *type; 349 Eolian_Type *type;
344 Eolian_Documentation *doc; 350 Eolian_Documentation *doc;
351 Eina_Bool move :1;
352 Eina_Bool by_ref :1;
345}; 353};
346 354
347struct _Eolian_Enum_Type_Field 355struct _Eolian_Enum_Type_Field