eolian: add out-param variants of expr eval/value get funcs
authorDaniel Kolesa <d.kolesa@samsung.com>
Sun, 31 May 2020 00:11:15 +0000 (02:11 +0200)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 31 May 2020 21:37:04 +0000 (06:37 +0900)
This is for compatibility with bindings that can't express passing
unions by value (e.g. anything libffi based).

src/lib/eolian/Eolian.h
src/lib/eolian/database_expr_api.c
src/tests/eolian/eolian_parsing.c

index c052181fa92c46d826d033743c8bd92ea951c30a..3d3db0ee7b76b5a82d10eefcfff30adae53c2574 100644 (file)
@@ -2957,6 +2957,24 @@ eolian_type_namespaces_get(const Eolian_Type *tp)
  */
 EAPI Eolian_Value eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
 
+/*
+ * @brief Evaluate an Eolian expression into an out-param.
+ *
+ * @param[in] expr the expression.
+ * @param[in] mask the mask of allowed values (can combine with bitwise OR).
+ * @param[out] the value to fill
+ * @return EINA_TRUE on success, EINA_FALSE on failure
+ *
+ * This is like eolian_expression_eval, except it writes into an out-param
+ * and returns whether it succeeded or failed. On failure, no write is
+ * guaranteed.
+ *
+ * @since 1.25
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Bool eolian_expression_eval_fill(const Eolian_Expression *expr, Eolian_Expression_Mask m, Eolian_Value *val);
+
 /*
  * @brief Convert the result of expression evaluation to a literal as in how
  * it would appear in C (e.g. strings are quoted and escaped).
@@ -3079,6 +3097,22 @@ EAPI const Eolian_Expression *eolian_expression_unary_expression_get(const Eolia
  */
 EAPI Eolian_Value eolian_expression_value_get(const Eolian_Expression *expr);
 
+/*
+ * @brief Get the value of an expression into an out-param.
+ *
+ * @param[in] expr the expression.
+ * @param[out] val the value to fill.
+ * @return EINA_TRUE on success, EINA_FALSE on failure
+ *
+ * This is like eolian_expression_value_get, but it fills an out-param. On
+ * failure, nothing is guaranteed to be filled.
+ *
+ * @since 1.25
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Bool eolian_expression_value_get_fill(const Eolian_Expression *expr, Eolian_Value *val);
+
 /*
  * @brief Get the documentation of a constant.
  *
index 2d3f81c73d873b9e1a55b4cff6314c29e1af1638..83cfbc52acae3d29f70651a5f9c3a96db122cf4f 100644 (file)
@@ -15,6 +15,19 @@ eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m)
    return database_expr_eval(NULL, (Eolian_Expression *)expr, m, NULL, NULL);
 }
 
+EAPI Eina_Bool
+eolian_expression_eval_fill(const Eolian_Expression *expr,
+                            Eolian_Expression_Mask m, Eolian_Value *val)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(expr, EINA_FALSE);
+   Eolian_Value ret = database_expr_eval(NULL, (Eolian_Expression *)expr, m,
+                                         NULL, NULL);
+   if (ret.type == EOLIAN_EXPR_UNKNOWN)
+     return EINA_FALSE;
+   *val = ret;
+   return EINA_TRUE;
+}
+
 static void
 _append_char_escaped(Eina_Strbuf *buf, char c)
 {
@@ -269,3 +282,15 @@ eolian_expression_value_get(const Eolian_Expression *expr)
    v.value = expr->value;
    return v;
 }
+
+EAPI Eina_Bool
+eolian_expression_value_get_fill(const Eolian_Expression *expr, Eolian_Value *val)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(expr, EINA_FALSE);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(expr->type != EOLIAN_EXPR_UNKNOWN
+                                && expr->type != EOLIAN_EXPR_BINARY
+                                && expr->type != EOLIAN_EXPR_UNARY, EINA_FALSE);
+   val->type  = expr->type;
+   val->value = expr->value;
+   return EINA_TRUE;
+}
index 5e05da98c01e32cf02d4acd98ad5f2a9e58bb83d..c914e4ec4f261d3f5974f96577175aa77b887d34 100644 (file)
@@ -539,7 +539,7 @@ EFL_START_TEST(eolian_simple_parsing)
    const Eolian_Type *tp;
    const Eolian_Unit *unit;
    Eina_Iterator *iter;
-   Eolian_Value v;
+   Eolian_Value v, vv;
    void *dummy;
 
    Eolian_State *eos = eolian_state_new();
@@ -579,13 +579,14 @@ EFL_START_TEST(eolian_simple_parsing)
    /* Set return */
    tp = eolian_function_return_type_get(fid, EOLIAN_PROP_SET);
    fail_if(!tp);
-   printf("BUILT %d\n", (int)eolian_type_builtin_type_get(tp));
    fail_if(eolian_type_builtin_type_get(tp) != EOLIAN_TYPE_BUILTIN_BOOL);
    fail_if(strcmp(eolian_type_short_name_get(tp), "bool"));
    expr = eolian_function_return_default_value_get(fid, EOLIAN_PROP_SET);
    fail_if(!expr);
    v = eolian_expression_eval(expr, EOLIAN_MASK_BOOL);
+   fail_if(!eolian_expression_eval_fill(expr, EOLIAN_MASK_BOOL, &vv));
    fail_if(v.type != EOLIAN_EXPR_BOOL);
+   fail_if(vv.type != EOLIAN_EXPR_BOOL);
    /* Get return */
    tp = eolian_function_return_type_get(fid, EOLIAN_PROP_GET);
    fail_if(tp);