}
static void
-_append_defval(Eina_Strbuf *buf, const Eolian_Expression *exp,
- const Eolian_Type *tp)
+_append_defval(const Eolian_Unit *src, Eina_Strbuf *buf,
+ const Eolian_Expression *exp, const Eolian_Type *tp)
{
if (exp)
{
- Eolian_Value val = eolian_expression_eval_type(exp, tp);
+ Eolian_Value val = eolian_expression_eval_type(src, exp, tp);
Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
if (lit)
{
}
static void
-_gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
- Eolian_Function_Type ftype, Eina_Strbuf *buf,
- const Eolian_Implement *impl, Eina_Strbuf *lbuf)
+_gen_func(const Eolian_Unit *src, const Eolian_Class *cl,
+ const Eolian_Function *fid, Eolian_Function_Type ftype,
+ Eina_Strbuf *buf, const Eolian_Implement *impl, Eina_Strbuf *lbuf)
{
Eina_Bool is_empty = eolian_implement_is_empty(impl, ftype);
Eina_Bool is_auto = eolian_implement_is_auto(impl, ftype);
}
else if ((ftype != EOLIAN_PROP_SET) && dfv)
{
- Eolian_Value val = eolian_expression_eval(dfv, EOLIAN_MASK_ALL);
+ Eolian_Value val = eolian_expression_eval(src, dfv, EOLIAN_MASK_ALL);
if (val.type)
{
Eina_Stringshare *vals = eolian_expression_value_to_literal(&val);
if (rtp)
{
eina_strbuf_append(buf, " return ");
- _append_defval(buf, def_ret, rtp);
+ _append_defval(src, buf, def_ret, rtp);
eina_strbuf_append(buf, ";\n");
}
eina_strbuf_append(buf, "}\n\n");
if (strcmp(rtpn, "void"))
{
eina_strbuf_append_printf(buf, ", %s, ", rtpn);
- _append_defval(buf, def_ret, rtp);
+ _append_defval(src, buf, def_ret, rtp);
}
if (has_params)
{
{
case EOLIAN_PROP_GET:
case EOLIAN_PROP_SET:
- _gen_func(cl, fid, ftype, buf, imp, lbuf);
+ _gen_func(src, cl, fid, ftype, buf, imp, lbuf);
break;
case EOLIAN_PROPERTY:
- _gen_func(cl, fid, EOLIAN_PROP_SET, buf, imp, lbuf);
- _gen_func(cl, fid, EOLIAN_PROP_GET, buf, imp, lbuf);
+ _gen_func(src, cl, fid, EOLIAN_PROP_SET, buf, imp, lbuf);
+ _gen_func(src, cl, fid, EOLIAN_PROP_GET, buf, imp, lbuf);
break;
default:
- _gen_func(cl, fid, EOLIAN_METHOD, buf, imp, lbuf);
+ _gen_func(src, cl, fid, EOLIAN_METHOD, buf, imp, lbuf);
}
}
eina_iterator_free(itr);
else
{
Eolian_Value val =
- eolian_expression_eval(vale, EOLIAN_MASK_INT);
+ eolian_expression_eval(src, vale, EOLIAN_MASK_INT);
const char *lit = eolian_expression_value_to_literal(&val);
eina_strbuf_append_printf(buf, " %s = %s", membn, lit);
const char *exp = eolian_expression_serialize(vale);
eina_strbuf_prepend_printf(buf, "#ifndef %s\n", fn);
eina_strbuf_append_printf(buf, "#define %s ", fn);
const Eolian_Expression *vv = eolian_variable_value_get(vr);
- Eolian_Value val = eolian_expression_eval_type(vv, vt);
+ Eolian_Value val = eolian_expression_eval_type(src, vv, vt);
Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
eina_strbuf_append(buf, lit);
Eina_Stringshare *exp = eolian_expression_serialize(vv);
}
}
-void eo_gen_types_source_gen(const Eolian_Unit *src EINA_UNUSED,
+void eo_gen_types_source_gen(const Eolian_Unit *src,
const char *eof, Eina_Strbuf *buf)
{
const Eolian_Declaration *decl;
eina_stringshare_del(ct);
free(fn);
- Eolian_Value val = eolian_expression_eval_type(vv, vt);
+ Eolian_Value val = eolian_expression_eval_type(src, vv, vt);
Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
eina_strbuf_append(buf, lit);
eina_strbuf_append_char(buf, ';');
const char *eolian_type_free_func_get(const Eolian_Type *tp);
const char *eolian_typedecl_free_func_get(const Eolian_Typedecl *tp);
- Eolian_Value_t eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
- Eolian_Value_t eolian_expression_eval_type(const Eolian_Expression *expr, const Eolian_Type *type);
+ Eolian_Value_t eolian_expression_eval(const Eolian_Unit *unit, const Eolian_Expression *expr, Eolian_Expression_Mask m);
+ Eolian_Value_t eolian_expression_eval_type(const Eolian_Unit *unit, const Eolian_Expression *expr, const Eolian_Type *type);
const char *eolian_expression_value_to_literal(const Eolian_Value *v);
const char *eolian_expression_serialize(const Eolian_Expression *expr);
Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr);
M.Expression = ffi.metatype("Eolian_Expression", {
__index = {
- eval = function(self, mask)
+ eval = function(self, unit, mask)
mask = mask or emask.ALL
- local v = eolian.eolian_expression_eval(self, mask)
+ local v = eolian.eolian_expression_eval(unit, self, mask)
if v == nil then return nil end
return ffi.cast("Eolian_Value*", v)
end,
- eval_type = function(self, tp)
- local v = eolian.eolian_expression_eval_type(self, tp)
+ eval_type = function(self, unit, tp)
+ local v = eolian.eolian_expression_eval_type(unit, self, tp)
if v == nil then return nil end
return ffi.cast("Eolian_Value*", v)
end,
/*
* @brief Evaluate an Eolian expression.
*
+ * @param[in] unit the unit to look in
* @param[in] expr the expression.
* @param[in] mask the mask of allowed values (can combine with bitwise OR).
* @return the value, its type is set to EOLIAN_EXPR_UNKNOWN on error.
*
* @ingroup Eolian
*/
-EAPI Eolian_Value eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
+EAPI Eolian_Value eolian_expression_eval(const Eolian_Unit *unit, const Eolian_Expression *expr, Eolian_Expression_Mask m);
/*
* @brief Evaluate an Eolian expression given a type instead of a mask.
*
+ * @param[in] unit the unit to look in
* @param[in] expr the expression.
* @param[in] type the type the expression is assigned to.
* @return the value, its type is set to EOLIAN_EXPR_UNKNOWN on error.
*
* @ingroup Eolian
*/
-EAPI Eolian_Value eolian_expression_eval_type(const Eolian_Expression *expr, const Eolian_Type *type);
+EAPI Eolian_Value eolian_expression_eval_type(const Eolian_Unit *unit, const Eolian_Expression *expr, const Eolian_Type *type);
/*
* @brief Convert the result of expression evaluation to a literal as in how
#include "eo_lexer.h"
EAPI Eolian_Value
-eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m)
+eolian_expression_eval(const Eolian_Unit *unit, const Eolian_Expression *expr,
+ Eolian_Expression_Mask m)
{
Eolian_Value err;
err.type = EOLIAN_EXPR_UNKNOWN;
EINA_SAFETY_ON_NULL_RETURN_VAL(expr, err);
- return database_expr_eval(NULL, expr, m);
+ return database_expr_eval(unit, expr, m);
}
static Eolian_Value
}
EAPI Eolian_Value
-eolian_expression_eval_type(const Eolian_Expression *expr,
+eolian_expression_eval_type(const Eolian_Unit *unit,
+ const Eolian_Expression *expr,
const Eolian_Type *type)
{
Eolian_Value err;
err.type = EOLIAN_EXPR_UNKNOWN;
EINA_SAFETY_ON_NULL_RETURN_VAL(expr, err);
- return _eval_type(NULL, expr, type);
+ return _eval_type(unit, expr, type);
}
static void
eina_strbuf_append(buf, ef->name);
if (ef->value)
{
- Eolian_Value val = eolian_expression_eval(ef->value,
+ /* FIXME: pass unit properly */
+ Eolian_Value val = eolian_expression_eval(NULL, ef->value,
EOLIAN_MASK_INT);
const char *ret;
eina_strbuf_append(buf, " = ");
const Eolian_Type *tp, Eolian_Expression_Mask msk)
{
Eolian_Value val;
+ /* FIXME: pass unit properly */
if (tp)
- val = eolian_expression_eval_type(expr, tp);
+ val = eolian_expression_eval_type(NULL, expr, tp);
else
- val = eolian_expression_eval(expr, msk);
+ val = eolian_expression_eval(NULL, expr, msk);
return (val.type != EOLIAN_EXPR_UNKNOWN);
}
fail_if(strcmp(eolian_type_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);
+ v = eolian_expression_eval(unit, expr, EOLIAN_MASK_BOOL);
fail_if(v.type != EOLIAN_EXPR_BOOL);
/* Get return */
tp = eolian_function_return_type_get(fid, EOLIAN_PROP_GET);
fail_if(strcmp(eolian_parameter_name_get(param), "value"));
expr = eolian_parameter_default_value_get(param);
fail_if(!expr);
- v = eolian_expression_eval(expr, EOLIAN_MASK_INT);
+ v = eolian_expression_eval(unit, expr, EOLIAN_MASK_INT);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 100);
eina_stringshare_del(string);
expr = eolian_function_return_default_value_get(fid, EOLIAN_METHOD);
fail_if(!expr);
- v = eolian_expression_eval(expr, EOLIAN_MASK_NULL);
+ v = eolian_expression_eval(unit, expr, EOLIAN_MASK_NULL);
fail_if(v.type != EOLIAN_EXPR_NULL);
fail_if(eolian_function_is_legacy_only(fid, EOLIAN_METHOD));
fail_if(strcmp(eolian_parameter_name_get(param), "c"));
expr = eolian_parameter_default_value_get(param);
fail_if(!expr);
- v = eolian_expression_eval(expr, EOLIAN_MASK_FLOAT);
+ v = eolian_expression_eval(unit, expr, EOLIAN_MASK_FLOAT);
fail_if(v.type != EOLIAN_EXPR_DOUBLE);
fail_if(v.value.d != 1337.6);
fail_if(!(eina_iterator_next(iter, (void**)¶m)));
fail_if(!(name = eolian_type_name_get(type)));
fail_if(strcmp(name, "int"));
fail_if(!(exp = eolian_variable_value_get(var)));
- v = eolian_expression_eval_type(exp, type);
+ v = eolian_expression_eval_type(unit, exp, type);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 5);
fail_if(!(name = eolian_type_name_get(type)));
fail_if(strcmp(name, "float"));
fail_if(!(exp = eolian_variable_value_get(var)));
- v = eolian_expression_eval_type(exp, type);
+ v = eolian_expression_eval_type(unit, exp, type);
fail_if(v.type != EOLIAN_EXPR_FLOAT);
fail_if(((int)v.value.f) != 10);
fail_if(!(field = eolian_typedecl_enum_field_get(tdl, "first")));
fail_if(!(exp = eolian_typedecl_enum_field_value_get(field, EINA_FALSE)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 0);
fail_if(!(field = eolian_typedecl_enum_field_get(tdl, "baz")));
fail_if(!(exp = eolian_typedecl_enum_field_value_get(field, EINA_FALSE)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 15);
fail_if(!(field = eolian_typedecl_enum_field_get(tdl, "foo")));
fail_if(!(exp = eolian_typedecl_enum_field_value_get(field, EINA_FALSE)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 15);
fail_if(!(field = eolian_typedecl_enum_field_get(tdl, "flag1")));
fail_if(!(exp = eolian_typedecl_enum_field_value_get(field, EINA_FALSE)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != (1 << 0));
fail_if(!(field = eolian_typedecl_enum_field_get(tdl, "flag2")));
fail_if(!(exp = eolian_typedecl_enum_field_value_get(field, EINA_FALSE)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != (1 << 1));
fail_if(!(field = eolian_typedecl_enum_field_get(tdl, "flag3")));
fail_if(!(exp = eolian_typedecl_enum_field_value_get(field, EINA_FALSE)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != (1 << 2));
fail_if(!(name = eolian_type_name_get(type)));
fail_if(strcmp(name, "Baz"));
fail_if(!(exp = eolian_variable_value_get(var)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != (1 << 0));
fail_if(!(var = eolian_variable_constant_get_by_name(unit, "Pants")));
fail_if(eolian_variable_type_get(var) != EOLIAN_VAR_CONSTANT);
fail_if(!(exp = eolian_variable_value_get(var)));
- v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
+ v = eolian_expression_eval(unit, exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 5);