summaryrefslogtreecommitdiff
path: root/src/lib/eolian
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-08-31 01:49:18 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2019-08-31 01:58:19 +0200
commit5e5bfc70e5d52a2779473127a0f1ccdc92588de9 (patch)
treec6993b1c8e94c2d1f4737e5f2739fb01d79a21eb /src/lib/eolian
parentb1d147abf4ff235e6acb32c53bd695cb533a4a97 (diff)
eolian: refactor ownability validation to accommodate new syntax
This refactors ownability checks so that they're only performed in contexts where @move can be specified, which both helps with performance and enables later removal of ownability info from types themselves.
Diffstat (limited to 'src/lib/eolian')
-rw-r--r--src/lib/eolian/database_validate.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index 0d118ceb4a..6a9a17d3ef 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -106,7 +106,7 @@ _validate_doc(Eolian_Documentation *doc)
106 106
107static Eina_Bool _validate_type(Validate_State *vals, Eolian_Type *tp); 107static Eina_Bool _validate_type(Validate_State *vals, Eolian_Type *tp);
108static Eina_Bool _validate_type_by_ref(Validate_State *vals, Eolian_Type *tp, 108static Eina_Bool _validate_type_by_ref(Validate_State *vals, Eolian_Type *tp,
109 Eina_Bool by_ref); 109 Eina_Bool by_ref, Eina_Bool move);
110static Eina_Bool _validate_expr(Eolian_Expression *expr, 110static Eina_Bool _validate_expr(Eolian_Expression *expr,
111 const Eolian_Type *tp, 111 const Eolian_Type *tp,
112 Eolian_Expression_Mask msk); 112 Eolian_Expression_Mask msk);
@@ -124,7 +124,7 @@ static Eina_Bool
124_sf_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, 124_sf_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
125 const Eolian_Struct_Type_Field *sf, Cb_Ret *sc) 125 const Eolian_Struct_Type_Field *sf, Cb_Ret *sc)
126{ 126{
127 sc->succ = _validate_type_by_ref(sc->vals, sf->type, sf->by_ref); 127 sc->succ = _validate_type_by_ref(sc->vals, sf->type, sf->by_ref, sf->move);
128 128
129 if (!sc->succ) 129 if (!sc->succ)
130 return EINA_FALSE; 130 return EINA_FALSE;
@@ -212,35 +212,41 @@ _validate_typedecl(Validate_State *vals, Eolian_Typedecl *tp)
212} 212}
213 213
214static Eina_Bool 214static Eina_Bool
215_validate_ownable(Eolian_Type *tp) 215_validate_by_ref(Eolian_Type *tp, Eina_Bool by_ref, Eina_Bool move)
216{ 216{
217 Eina_Bool maybe_ownable =
218 database_type_is_ownable(tp->base.unit, tp, EINA_FALSE);
219
220 /* only allow value types when @by_ref */
221 if (by_ref && !maybe_ownable)
222 return EINA_FALSE;
223
224 /* futures can be whatever... */
217 if (tp->btype == EOLIAN_TYPE_BUILTIN_FUTURE) 225 if (tp->btype == EOLIAN_TYPE_BUILTIN_FUTURE)
218 return EINA_TRUE; 226 return EINA_TRUE;
219 if (tp->owned && !tp->ownable) 227
228 /* not marked @move; just validate */
229 if (!move)
230 return EINA_TRUE;
231
232 /* marked @move, now pointer-like or otherwise ownable, error */
233 if (!maybe_ownable || !tp->ownable)
220 { 234 {
221 _eo_parser_log(&tp->base, "type '%s' is not ownable", tp->base.name); 235 _eo_parser_log(&tp->base, "type '%s' is not ownable", tp->base.name);
222 return EINA_FALSE; 236 return EINA_FALSE;
223 } 237 }
224 return _validate(&tp->base);
225}
226 238
227static Eina_Bool 239 return EINA_TRUE;
228_validate_by_ref(Eolian_Type *tp, Eina_Bool by_ref)
229{
230 /* when not @by_ref, allow any type */
231 if (!by_ref)
232 return EINA_TRUE;
233 /* else only allow value types */
234 return !database_type_is_ownable(tp->base.unit, tp, EINA_FALSE);
235} 240}
236 241
237static Eina_Bool 242static Eina_Bool
238_validate_type_by_ref(Validate_State *vals, Eolian_Type *tp, Eina_Bool by_ref) 243_validate_type_by_ref(Validate_State *vals, Eolian_Type *tp,
244 Eina_Bool by_ref, Eina_Bool move)
239{ 245{
240 if (!_validate_type(vals, tp)) 246 if (!_validate_type(vals, tp))
241 return EINA_FALSE; 247 return EINA_FALSE;
242 248
243 return _validate_by_ref(tp, by_ref); 249 return _validate_by_ref(tp, by_ref, move);
244} 250}
245 251
246static Eina_Bool 252static Eina_Bool
@@ -248,12 +254,6 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
248{ 254{
249 const Eolian_Unit *src = tp->base.unit; 255 const Eolian_Unit *src = tp->base.unit;
250 256
251 if (tp->owned && !database_type_is_ownable(src, tp, EINA_FALSE))
252 {
253 _eo_parser_log(&tp->base, "type '%s' is not ownable", tp->base.name);
254 return EINA_FALSE;
255 }
256
257 if (tp->is_ptr) 257 if (tp->is_ptr)
258 { 258 {
259 tp->is_ptr = EINA_FALSE; 259 tp->is_ptr = EINA_FALSE;
@@ -270,7 +270,7 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
270 { 270 {
271 case EOLIAN_TYPE_VOID: 271 case EOLIAN_TYPE_VOID:
272 case EOLIAN_TYPE_UNDEFINED: 272 case EOLIAN_TYPE_UNDEFINED:
273 return _validate_ownable(tp); 273 return _validate(&tp->base);
274 case EOLIAN_TYPE_REGULAR: 274 case EOLIAN_TYPE_REGULAR:
275 { 275 {
276 if (tp->base_type) 276 if (tp->base_type)
@@ -293,7 +293,7 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
293 return EINA_FALSE; 293 return EINA_FALSE;
294 itp = itp->next_type; 294 itp = itp->next_type;
295 } 295 }
296 return _validate_ownable(tp); 296 return _validate(&tp->base);
297 } 297 }
298 /* builtins */ 298 /* builtins */
299 int id = eo_lexer_keyword_str_to_id(tp->base.name); 299 int id = eo_lexer_keyword_str_to_id(tp->base.name);
@@ -326,7 +326,7 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
326 return EINA_FALSE; 326 return EINA_FALSE;
327 } 327 }
328 } 328 }
329 return _validate_ownable(tp); 329 return _validate(&tp->base);
330 } 330 }
331 /* user defined */ 331 /* user defined */
332 tp->tdecl = database_type_decl_find(src, tp); 332 tp->tdecl = database_type_decl_find(src, tp);
@@ -347,7 +347,7 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
347 if (tp->tdecl->ownable) 347 if (tp->tdecl->ownable)
348 tp->ownable = EINA_TRUE; 348 tp->ownable = EINA_TRUE;
349 tp->base.c_name = eina_stringshare_ref(tp->tdecl->base.c_name); 349 tp->base.c_name = eina_stringshare_ref(tp->tdecl->base.c_name);
350 return _validate_ownable(tp); 350 return _validate(&tp->base);
351 } 351 }
352 case EOLIAN_TYPE_CLASS: 352 case EOLIAN_TYPE_CLASS:
353 { 353 {
@@ -366,7 +366,7 @@ _validate_type(Validate_State *vals, Eolian_Type *tp)
366 } 366 }
367 tp->ownable = EINA_TRUE; 367 tp->ownable = EINA_TRUE;
368 tp->base.c_name = eina_stringshare_ref(tp->klass->base.c_name); 368 tp->base.c_name = eina_stringshare_ref(tp->klass->base.c_name);
369 return _validate_ownable(tp); 369 return _validate(&tp->base);
370 } 370 }
371 case EOLIAN_TYPE_ERROR: 371 case EOLIAN_TYPE_ERROR:
372 { 372 {
@@ -413,7 +413,7 @@ _validate_expr(Eolian_Expression *expr, const Eolian_Type *tp,
413static Eina_Bool 413static Eina_Bool
414_validate_param(Validate_State *vals, Eolian_Function_Parameter *param) 414_validate_param(Validate_State *vals, Eolian_Function_Parameter *param)
415{ 415{
416 if (!_validate_type_by_ref(vals, param->type, param->by_ref)) 416 if (!_validate_type_by_ref(vals, param->type, param->by_ref, param->move))
417 return EINA_FALSE; 417 return EINA_FALSE;
418 418
419 if (param->value && !_validate_expr(param->value, param->type, 0)) 419 if (param->value && !_validate_expr(param->value, param->type, 0))
@@ -456,11 +456,11 @@ _validate_function(Validate_State *vals, Eolian_Function *func, Eina_Hash *nhash
456 Eina_Bool was_stable = _set_stable(vals, !func->base.is_beta && vals->stable); 456 Eina_Bool was_stable = _set_stable(vals, !func->base.is_beta && vals->stable);
457 457
458 if (func->get_ret_type && !_validate_type_by_ref(vals, func->get_ret_type, 458 if (func->get_ret_type && !_validate_type_by_ref(vals, func->get_ret_type,
459 func->get_return_by_ref)) 459 func->get_return_by_ref, func->get_return_move))
460 return _reset_stable(vals, was_stable, EINA_FALSE); 460 return _reset_stable(vals, was_stable, EINA_FALSE);
461 461
462 if (func->set_ret_type && !_validate_type_by_ref(vals, func->set_ret_type, 462 if (func->set_ret_type && !_validate_type_by_ref(vals, func->set_ret_type,
463 func->set_return_by_ref)) 463 func->set_return_by_ref, func->set_return_move))
464 return _reset_stable(vals, was_stable, EINA_FALSE); 464 return _reset_stable(vals, was_stable, EINA_FALSE);
465 465
466 if (func->get_ret_val && !_validate_expr(func->get_ret_val, 466 if (func->get_ret_val && !_validate_expr(func->get_ret_val,