eolian: do not require unit for expr eval APIs

The necessary information is now stored directly in the expr
during database validation.

Also enable expr validation for params.
This commit is contained in:
Daniel Kolesa 2018-01-16 16:10:43 +01:00
parent b70604d018
commit dd2e579fec
13 changed files with 46 additions and 49 deletions

View File

@ -108,7 +108,7 @@ _append_defval(const Eolian_Unit *src, Eina_Strbuf *buf,
{
if (exp)
{
Eolian_Value val = eolian_expression_eval_type(src, exp, tp);
Eolian_Value val = eolian_expression_eval_type(exp, tp);
Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
if (lit)
{
@ -474,7 +474,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Class *cl,
}
else if ((ftype != EOLIAN_PROP_SET) && dfv)
{
Eolian_Value val = eolian_expression_eval(src, dfv, EOLIAN_MASK_ALL);
Eolian_Value val = eolian_expression_eval(dfv, EOLIAN_MASK_ALL);
if (val.type)
{
Eina_Stringshare *vals = eolian_expression_value_to_literal(&val);

View File

@ -87,7 +87,7 @@ _type_generate(const Eolian_Unit *src, const Eolian_Typedecl *tp,
else
{
Eolian_Value val =
eolian_expression_eval(src, vale, EOLIAN_MASK_INT);
eolian_expression_eval(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);
@ -183,7 +183,7 @@ _var_generate(const Eolian_Unit *src, const Eolian_Variable *vr, Eina_Bool legac
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(src, vv, vt);
Eolian_Value val = eolian_expression_eval_type(vv, vt);
Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
eina_strbuf_append(buf, lit);
Eina_Stringshare *exp = eolian_expression_serialize(vv);
@ -290,7 +290,7 @@ void eo_gen_types_source_gen(const Eolian_Unit *src,
eina_stringshare_del(ct);
free(fn);
Eolian_Value val = eolian_expression_eval_type(src, vv, vt);
Eolian_Value val = eolian_expression_eval_type(vv, vt);
Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
eina_strbuf_append(buf, lit);
eina_strbuf_append_char(buf, ';');

View File

@ -428,8 +428,8 @@ ffi.cdef [[
const Eolian_Function *eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp);
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);
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);
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);
@ -1476,15 +1476,15 @@ M.unary_operator = {
M.Expression = ffi.metatype("Eolian_Expression", {
__index = {
eval = function(self, unit, mask)
eval = function(self, mask)
mask = mask or emask.ALL
local v = eolian.eolian_expression_eval(unit, self, mask)
local v = eolian.eolian_expression_eval(self, mask)
if v == nil then return nil end
return ffi.cast("Eolian_Value*", v)
end,
eval_type = function(self, unit, tp)
local v = eolian.eolian_expression_eval_type(unit, self, tp)
eval_type = function(self, tp)
local v = eolian.eolian_expression_eval_type(self, tp)
if v == nil then return nil end
return ffi.cast("Eolian_Value*", v)
end,

View File

@ -110,10 +110,10 @@ interface Efl.Gfx.Buffer ()
]]
get {}
values {
l: uint(0); [[Left border pixels, usually 0 or 1]]
r: uint(0); [[Right border pixels, usually 0 or 1]]
t: uint(0); [[Top border pixels, usually 0 or 1]]
b: uint(0); [[Bottom border pixels, usually 0 or 1]]
l: uint(0U); [[Left border pixels, usually 0 or 1]]
r: uint(0U); [[Right border pixels, usually 0 or 1]]
t: uint(0U); [[Top border pixels, usually 0 or 1]]
b: uint(0U); [[Bottom border pixels, usually 0 or 1]]
}
}

View File

@ -2086,7 +2086,6 @@ EAPI Eina_Stringshare *eolian_type_free_func_get(const Eolian_Type *tp);
/*
* @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.
@ -2096,12 +2095,11 @@ EAPI Eina_Stringshare *eolian_type_free_func_get(const Eolian_Type *tp);
*
* @ingroup Eolian
*/
EAPI Eolian_Value eolian_expression_eval(const Eolian_Unit *unit, const Eolian_Expression *expr, Eolian_Expression_Mask m);
EAPI Eolian_Value eolian_expression_eval(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.
@ -2111,7 +2109,7 @@ EAPI Eolian_Value eolian_expression_eval(const Eolian_Unit *unit, const Eolian_E
*
* @ingroup Eolian
*/
EAPI Eolian_Value eolian_expression_eval_type(const Eolian_Unit *unit, const Eolian_Expression *expr, const Eolian_Type *type);
EAPI Eolian_Value eolian_expression_eval_type(const Eolian_Expression *expr, const Eolian_Type *type);
/*
* @brief Convert the result of expression evaluation to a literal as in how

View File

@ -470,7 +470,7 @@ eval_exp(const Eolian_Unit *unit, Eolian_Expression *expr,
}
case EOLIAN_EXPR_STRING:
{
if (!(mask & EOLIAN_MASK_STRING))
if (!(mask & EOLIAN_MASK_STRING) && !(mask & EOLIAN_MASK_NULL))
return expr_type_error(expr, EOLIAN_MASK_STRING, mask);
*out = *expr;
return EINA_TRUE;

View File

@ -7,24 +7,22 @@
#include "eolian_database.h"
EAPI Eolian_Value
eolian_expression_eval(const Eolian_Unit *unit, const Eolian_Expression *expr,
Eolian_Expression_Mask m)
eolian_expression_eval(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(unit, (Eolian_Expression *)expr, m);
return database_expr_eval(NULL, (Eolian_Expression *)expr, m);
}
EAPI Eolian_Value
eolian_expression_eval_type(const Eolian_Unit *unit,
const Eolian_Expression *expr,
eolian_expression_eval_type(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 database_expr_eval_type(unit, (Eolian_Expression *)expr, type);
return database_expr_eval_type(NULL, (Eolian_Expression *)expr, type);
}
static void

View File

@ -197,8 +197,8 @@ _etype_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp,
eina_strbuf_append(buf, ef->name);
if (ef->value)
{
Eolian_Value val = eolian_expression_eval(src, ef->value,
EOLIAN_MASK_INT);
Eolian_Value val = eolian_expression_eval(ef->value,
EOLIAN_MASK_INT);
const char *ret;
eina_strbuf_append(buf, " = ");
ret = eolian_expression_value_to_literal(&val);

View File

@ -308,6 +308,9 @@ _validate_param(const Eolian_Unit *src, Eolian_Function_Parameter *param)
if (!_validate_type(src, param->type))
return EINA_FALSE;
if (param->value && !_validate_expr(src, param->value, param->type, 0))
return EINA_FALSE;
if (!_validate_doc(src, param->doc))
return EINA_FALSE;

View File

@ -1077,7 +1077,7 @@ struct enum_value_def
name = eolian_typedecl_enum_field_name_get(enum_field);
c_name = eolian_typedecl_enum_field_c_name_get(enum_field);
auto exp = eolian_typedecl_enum_field_value_get(enum_field, EINA_TRUE);
value = eolian_expression_eval(unit, exp, EOLIAN_MASK_INT); // FIXME hardcoded int
value = eolian_expression_eval(exp, EOLIAN_MASK_INT); // FIXME hardcoded int
documentation = eolian_typedecl_enum_field_documentation_get(enum_field);
}
};

View File

@ -47,8 +47,8 @@ class Efl.Canvas.Vg (Efl.Canvas.Object, Efl.File)
@property viewbox_align {
[[Control how the viewbox is positioned inside the viewport.]]
values {
align_x: double(0); [[Alignment in the horizontal axis (0 <= align_x <= 1).]]
align_y: double(0); [[Alignment in the vertical axis (0 <= align_y <= 1).]]
align_x: double(0.0); [[Alignment in the horizontal axis (0 <= align_x <= 1).]]
align_y: double(0.0); [[Alignment in the vertical axis (0 <= align_y <= 1).]]
}
}
@property root_node {

View File

@ -1366,13 +1366,11 @@ M.Expression = Node:clone {
end,
eval_enum = function(self)
-- FIXME: unit
return self.expr:eval(eos:unit_get(), eolian.expression_mask.INT)
return self.expr:eval(eolian.expression_mask.INT)
end,
eval_type = function(self, tp)
-- FIXME: unit
return self.expr:eval_type(eos:unit_get(), tp.type)
return self.expr:eval_type(tp.type)
end,
serialize = function(self)

View File

@ -587,7 +587,7 @@ START_TEST(eolian_simple_parsing)
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(unit, expr, EOLIAN_MASK_BOOL);
v = eolian_expression_eval(expr, EOLIAN_MASK_BOOL);
fail_if(v.type != EOLIAN_EXPR_BOOL);
/* Get return */
tp = eolian_function_return_type_get(fid, EOLIAN_PROP_GET);
@ -603,7 +603,7 @@ START_TEST(eolian_simple_parsing)
fail_if(strcmp(eolian_parameter_name_get(param), "value"));
expr = eolian_parameter_default_value_get(param);
fail_if(!expr);
v = eolian_expression_eval(unit, expr, EOLIAN_MASK_INT);
v = eolian_expression_eval(expr, EOLIAN_MASK_INT);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 100);
@ -627,7 +627,7 @@ START_TEST(eolian_simple_parsing)
eina_stringshare_del(string);
expr = eolian_function_return_default_value_get(fid, EOLIAN_METHOD);
fail_if(!expr);
v = eolian_expression_eval(unit, expr, EOLIAN_MASK_NULL);
v = eolian_expression_eval(expr, EOLIAN_MASK_NULL);
fail_if(v.type != EOLIAN_EXPR_NULL);
fail_if(eolian_function_is_legacy_only(fid, EOLIAN_METHOD));
@ -649,7 +649,7 @@ START_TEST(eolian_simple_parsing)
fail_if(strcmp(eolian_parameter_name_get(param), "c"));
expr = eolian_parameter_default_value_get(param);
fail_if(!expr);
v = eolian_expression_eval(unit, expr, EOLIAN_MASK_FLOAT);
v = eolian_expression_eval(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**)&param)));
@ -811,7 +811,7 @@ START_TEST(eolian_var)
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(unit, exp, type);
v = eolian_expression_eval_type(exp, type);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 5);
@ -823,7 +823,7 @@ START_TEST(eolian_var)
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(unit, exp, type);
v = eolian_expression_eval_type(exp, type);
fail_if(v.type != EOLIAN_EXPR_FLOAT);
fail_if(((int)v.value.f) != 10);
@ -878,7 +878,7 @@ START_TEST(eolian_enum)
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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 0);
@ -887,7 +887,7 @@ START_TEST(eolian_enum)
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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 15);
@ -896,7 +896,7 @@ START_TEST(eolian_enum)
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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 15);
@ -908,19 +908,19 @@ START_TEST(eolian_enum)
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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != (1 << 2));
@ -938,14 +938,14 @@ START_TEST(eolian_enum)
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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(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(unit, exp, EOLIAN_MASK_ALL);
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
fail_if(v.type != EOLIAN_EXPR_INT);
fail_if(v.value.i != 5);