summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 02:11:15 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2020-05-31 02:14:46 +0200
commit1ba91f37fb155763423d3e2e9f3d1892c4c185f6 (patch)
treeda9ecb2bf5d9b014280bcb8ca518565da2cdf073
parentaa3f1b67e79ccf0add44f627e5ae5801b635d85b (diff)
eolian: add out-param variants of expr eval/value get funcs
This is for compatibility with bindings that can't express passing unions by value (e.g. anything libffi based).
-rw-r--r--src/lib/eolian/Eolian.h34
-rw-r--r--src/lib/eolian/database_expr_api.c25
-rw-r--r--src/tests/eolian/eolian_parsing.c5
3 files changed, 62 insertions, 2 deletions
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index c052181fa9..3d3db0ee7b 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -2958,6 +2958,24 @@ eolian_type_namespaces_get(const Eolian_Type *tp)
2958EAPI Eolian_Value eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m); 2958EAPI Eolian_Value eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
2959 2959
2960/* 2960/*
2961 * @brief Evaluate an Eolian expression into an out-param.
2962 *
2963 * @param[in] expr the expression.
2964 * @param[in] mask the mask of allowed values (can combine with bitwise OR).
2965 * @param[out] the value to fill
2966 * @return EINA_TRUE on success, EINA_FALSE on failure
2967 *
2968 * This is like eolian_expression_eval, except it writes into an out-param
2969 * and returns whether it succeeded or failed. On failure, no write is
2970 * guaranteed.
2971 *
2972 * @since 1.25
2973 *
2974 * @ingroup Eolian
2975 */
2976EAPI Eina_Bool eolian_expression_eval_fill(const Eolian_Expression *expr, Eolian_Expression_Mask m, Eolian_Value *val);
2977
2978/*
2961 * @brief Convert the result of expression evaluation to a literal as in how 2979 * @brief Convert the result of expression evaluation to a literal as in how
2962 * it would appear in C (e.g. strings are quoted and escaped). 2980 * it would appear in C (e.g. strings are quoted and escaped).
2963 * 2981 *
@@ -3080,6 +3098,22 @@ EAPI const Eolian_Expression *eolian_expression_unary_expression_get(const Eolia
3080EAPI Eolian_Value eolian_expression_value_get(const Eolian_Expression *expr); 3098EAPI Eolian_Value eolian_expression_value_get(const Eolian_Expression *expr);
3081 3099
3082/* 3100/*
3101 * @brief Get the value of an expression into an out-param.
3102 *
3103 * @param[in] expr the expression.
3104 * @param[out] val the value to fill.
3105 * @return EINA_TRUE on success, EINA_FALSE on failure
3106 *
3107 * This is like eolian_expression_value_get, but it fills an out-param. On
3108 * failure, nothing is guaranteed to be filled.
3109 *
3110 * @since 1.25
3111 *
3112 * @ingroup Eolian
3113 */
3114EAPI Eina_Bool eolian_expression_value_get_fill(const Eolian_Expression *expr, Eolian_Value *val);
3115
3116/*
3083 * @brief Get the documentation of a constant. 3117 * @brief Get the documentation of a constant.
3084 * 3118 *
3085 * @param[in] var the constant. 3119 * @param[in] var the constant.
diff --git a/src/lib/eolian/database_expr_api.c b/src/lib/eolian/database_expr_api.c
index 2d3f81c73d..83cfbc52ac 100644
--- a/src/lib/eolian/database_expr_api.c
+++ b/src/lib/eolian/database_expr_api.c
@@ -15,6 +15,19 @@ eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m)
15 return database_expr_eval(NULL, (Eolian_Expression *)expr, m, NULL, NULL); 15 return database_expr_eval(NULL, (Eolian_Expression *)expr, m, NULL, NULL);
16} 16}
17 17
18EAPI Eina_Bool
19eolian_expression_eval_fill(const Eolian_Expression *expr,
20 Eolian_Expression_Mask m, Eolian_Value *val)
21{
22 EINA_SAFETY_ON_NULL_RETURN_VAL(expr, EINA_FALSE);
23 Eolian_Value ret = database_expr_eval(NULL, (Eolian_Expression *)expr, m,
24 NULL, NULL);
25 if (ret.type == EOLIAN_EXPR_UNKNOWN)
26 return EINA_FALSE;
27 *val = ret;
28 return EINA_TRUE;
29}
30
18static void 31static void
19_append_char_escaped(Eina_Strbuf *buf, char c) 32_append_char_escaped(Eina_Strbuf *buf, char c)
20{ 33{
@@ -269,3 +282,15 @@ eolian_expression_value_get(const Eolian_Expression *expr)
269 v.value = expr->value; 282 v.value = expr->value;
270 return v; 283 return v;
271} 284}
285
286EAPI Eina_Bool
287eolian_expression_value_get_fill(const Eolian_Expression *expr, Eolian_Value *val)
288{
289 EINA_SAFETY_ON_NULL_RETURN_VAL(expr, EINA_FALSE);
290 EINA_SAFETY_ON_FALSE_RETURN_VAL(expr->type != EOLIAN_EXPR_UNKNOWN
291 && expr->type != EOLIAN_EXPR_BINARY
292 && expr->type != EOLIAN_EXPR_UNARY, EINA_FALSE);
293 val->type = expr->type;
294 val->value = expr->value;
295 return EINA_TRUE;
296}
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index 5e05da98c0..c914e4ec4f 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -539,7 +539,7 @@ EFL_START_TEST(eolian_simple_parsing)
539 const Eolian_Type *tp; 539 const Eolian_Type *tp;
540 const Eolian_Unit *unit; 540 const Eolian_Unit *unit;
541 Eina_Iterator *iter; 541 Eina_Iterator *iter;
542 Eolian_Value v; 542 Eolian_Value v, vv;
543 void *dummy; 543 void *dummy;
544 544
545 Eolian_State *eos = eolian_state_new(); 545 Eolian_State *eos = eolian_state_new();
@@ -579,13 +579,14 @@ EFL_START_TEST(eolian_simple_parsing)
579 /* Set return */ 579 /* Set return */
580 tp = eolian_function_return_type_get(fid, EOLIAN_PROP_SET); 580 tp = eolian_function_return_type_get(fid, EOLIAN_PROP_SET);
581 fail_if(!tp); 581 fail_if(!tp);
582 printf("BUILT %d\n", (int)eolian_type_builtin_type_get(tp));
583 fail_if(eolian_type_builtin_type_get(tp) != EOLIAN_TYPE_BUILTIN_BOOL); 582 fail_if(eolian_type_builtin_type_get(tp) != EOLIAN_TYPE_BUILTIN_BOOL);
584 fail_if(strcmp(eolian_type_short_name_get(tp), "bool")); 583 fail_if(strcmp(eolian_type_short_name_get(tp), "bool"));
585 expr = eolian_function_return_default_value_get(fid, EOLIAN_PROP_SET); 584 expr = eolian_function_return_default_value_get(fid, EOLIAN_PROP_SET);
586 fail_if(!expr); 585 fail_if(!expr);
587 v = eolian_expression_eval(expr, EOLIAN_MASK_BOOL); 586 v = eolian_expression_eval(expr, EOLIAN_MASK_BOOL);
587 fail_if(!eolian_expression_eval_fill(expr, EOLIAN_MASK_BOOL, &vv));
588 fail_if(v.type != EOLIAN_EXPR_BOOL); 588 fail_if(v.type != EOLIAN_EXPR_BOOL);
589 fail_if(vv.type != EOLIAN_EXPR_BOOL);
589 /* Get return */ 590 /* Get return */
590 tp = eolian_function_return_type_get(fid, EOLIAN_PROP_GET); 591 tp = eolian_function_return_type_get(fid, EOLIAN_PROP_GET);
591 fail_if(tp); 592 fail_if(tp);