summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-09-04 18:00:58 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2019-09-04 18:02:47 +0200
commit6751f011c1c621c67b671baa4d63e887af374bd4 (patch)
tree38f2c7d73e4171799e502cf61db346a1aa3c28a2
parent0021d1386d5828e1bd2b857a2f073327902df817 (diff)
eolian: remove the expression eval_type API
This is unnecessary because for all contexts where type is relevant the validator already makes sure the type and expression match correctly, so you don't ever need to re-validate it. If you are doing a generic case and are not sure, just use MASK_ALL.
-rw-r--r--src/bin/eolian/sources.c2
-rw-r--r--src/bin/eolian/types.c4
-rw-r--r--src/bindings/luajit/eolian.lua7
-rw-r--r--src/lib/eolian/Eolian.h14
-rw-r--r--src/lib/eolian/database_expr_api.c10
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp2
-rw-r--r--src/tests/eolian/eolian_parsing.c4
7 files changed, 6 insertions, 37 deletions
diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index 94078fd5ed..2d2db389f4 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -107,7 +107,7 @@ _append_defval(Eina_Strbuf *buf, const Eolian_Expression *exp, const Eolian_Type
107{ 107{
108 if (exp) 108 if (exp)
109 { 109 {
110 Eolian_Value val = eolian_expression_eval_type(exp, tp); 110 Eolian_Value val = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
111 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val); 111 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
112 if (lit) 112 if (lit)
113 { 113 {
diff --git a/src/bin/eolian/types.c b/src/bin/eolian/types.c
index b55a89bdfd..d45d1ba81b 100644
--- a/src/bin/eolian/types.c
+++ b/src/bin/eolian/types.c
@@ -191,7 +191,7 @@ _var_generate(const Eolian_State *state, const Eolian_Variable *vr)
191 eina_strbuf_prepend_printf(buf, "#ifndef %s\n", fn); 191 eina_strbuf_prepend_printf(buf, "#ifndef %s\n", fn);
192 eina_strbuf_append_printf(buf, "#define %s ", fn); 192 eina_strbuf_append_printf(buf, "#define %s ", fn);
193 const Eolian_Expression *vv = eolian_variable_value_get(vr); 193 const Eolian_Expression *vv = eolian_variable_value_get(vr);
194 Eolian_Value val = eolian_expression_eval_type(vv, vt); 194 Eolian_Value val = eolian_expression_eval(vv, EOLIAN_MASK_ALL);
195 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val); 195 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
196 eina_strbuf_append(buf, lit); 196 eina_strbuf_append(buf, lit);
197 Eina_Stringshare *exp = eolian_expression_serialize(vv); 197 Eina_Stringshare *exp = eolian_expression_serialize(vv);
@@ -397,7 +397,7 @@ _source_gen_var(Eina_Strbuf *buf, const Eolian_Variable *vr)
397 eina_stringshare_del(ct); 397 eina_stringshare_del(ct);
398 free(fn); 398 free(fn);
399 399
400 Eolian_Value val = eolian_expression_eval_type(vv, vt); 400 Eolian_Value val = eolian_expression_eval(vv, EOLIAN_MASK_ALL);
401 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val); 401 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
402 eina_strbuf_append(buf, lit); 402 eina_strbuf_append(buf, lit);
403 eina_strbuf_append_char(buf, ';'); 403 eina_strbuf_append_char(buf, ';');
diff --git a/src/bindings/luajit/eolian.lua b/src/bindings/luajit/eolian.lua
index 88b6f96eb3..a848d029c1 100644
--- a/src/bindings/luajit/eolian.lua
+++ b/src/bindings/luajit/eolian.lua
@@ -460,7 +460,6 @@ ffi.cdef [[
460 const Eolian_Function *eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp); 460 const Eolian_Function *eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp);
461 461
462 Eolian_Value_t eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m); 462 Eolian_Value_t eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
463 Eolian_Value_t eolian_expression_eval_type(const Eolian_Expression *expr, const Eolian_Type *type);
464 const char *eolian_expression_value_to_literal(const Eolian_Value *v); 463 const char *eolian_expression_value_to_literal(const Eolian_Value *v);
465 const char *eolian_expression_serialize(const Eolian_Expression *expr); 464 const char *eolian_expression_serialize(const Eolian_Expression *expr);
466 Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr); 465 Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr);
@@ -1711,12 +1710,6 @@ M.Expression = ffi.metatype("Eolian_Expression", {
1711 return ffi.cast("Eolian_Value*", v) 1710 return ffi.cast("Eolian_Value*", v)
1712 end, 1711 end,
1713 1712
1714 eval_type = function(self, tp)
1715 local v = eolian.eolian_expression_eval_type(self, tp)
1716 if v == nil then return nil end
1717 return ffi.cast("Eolian_Value*", v)
1718 end,
1719
1720 serialize = function(self) 1713 serialize = function(self)
1721 local v = eolian.eolian_expression_serialize(self) 1714 local v = eolian.eolian_expression_serialize(self)
1722 if v == nil then return nil end 1715 if v == nil then return nil end
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index cee793f0d9..78be1ac97f 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -3078,20 +3078,6 @@ eolian_type_namespaces_get(const Eolian_Type *tp)
3078EAPI Eolian_Value eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m); 3078EAPI Eolian_Value eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m);
3079 3079
3080/* 3080/*
3081 * @brief Evaluate an Eolian expression given a type instead of a mask.
3082 *
3083 * @param[in] expr the expression.
3084 * @param[in] type the type the expression is assigned to.
3085 * @return the value, its type is set to EOLIAN_EXPR_UNKNOWN on error.
3086 *
3087 * The mask is automatically decided from the given type, allowing only values
3088 * that can be assigned to that type.
3089 *
3090 * @ingroup Eolian
3091 */
3092EAPI Eolian_Value eolian_expression_eval_type(const Eolian_Expression *expr, const Eolian_Type *type);
3093
3094/*
3095 * @brief Convert the result of expression evaluation to a literal as in how 3081 * @brief Convert the result of expression evaluation to a literal as in how
3096 * it would appear in C (e.g. strings are quoted and escaped). 3082 * it would appear in C (e.g. strings are quoted and escaped).
3097 * 3083 *
diff --git a/src/lib/eolian/database_expr_api.c b/src/lib/eolian/database_expr_api.c
index 92f5b915aa..6aaa1bb9be 100644
--- a/src/lib/eolian/database_expr_api.c
+++ b/src/lib/eolian/database_expr_api.c
@@ -15,16 +15,6 @@ 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 Eolian_Value
19eolian_expression_eval_type(const Eolian_Expression *expr,
20 const Eolian_Type *type)
21{
22 Eolian_Value err;
23 err.type = EOLIAN_EXPR_UNKNOWN;
24 EINA_SAFETY_ON_NULL_RETURN_VAL(expr, err);
25 return database_expr_eval_type(NULL, (Eolian_Expression *)expr, type, NULL, NULL);
26}
27
28static void 18static void
29_append_char_escaped(Eina_Strbuf *buf, char c) 19_append_char_escaped(Eina_Strbuf *buf, char c)
30{ 20{
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index 74375159a0..b451ed2d6b 100644
--- a/src/lib/eolian_cxx/grammar/klass_def.hpp
+++ b/src/lib/eolian_cxx/grammar/klass_def.hpp
@@ -1015,7 +1015,7 @@ struct variable_def
1015 if (!expr) 1015 if (!expr)
1016 throw std::runtime_error("Could not get constant variable value expression"); 1016 throw std::runtime_error("Could not get constant variable value expression");
1017 1017
1018 this->expression_value = ::eolian_expression_eval_type(expr, ::eolian_variable_base_type_get(variable)); 1018 this->expression_value = ::eolian_expression_eval(expr, ::EOLIAN_MASK_ALL);
1019 } 1019 }
1020 } 1020 }
1021}; 1021};
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index c35d10b1a7..60d35150dc 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -800,7 +800,7 @@ EFL_START_TEST(eolian_var)
800 fail_if(!(name = eolian_type_short_name_get(type))); 800 fail_if(!(name = eolian_type_short_name_get(type)));
801 fail_if(strcmp(name, "int")); 801 fail_if(strcmp(name, "int"));
802 fail_if(!(exp = eolian_variable_value_get(var))); 802 fail_if(!(exp = eolian_variable_value_get(var)));
803 v = eolian_expression_eval_type(exp, type); 803 v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
804 fail_if(v.type != EOLIAN_EXPR_INT); 804 fail_if(v.type != EOLIAN_EXPR_INT);
805 fail_if(v.value.i != 5); 805 fail_if(v.value.i != 5);
806 806
@@ -812,7 +812,7 @@ EFL_START_TEST(eolian_var)
812 fail_if(!(name = eolian_type_short_name_get(type))); 812 fail_if(!(name = eolian_type_short_name_get(type)));
813 fail_if(strcmp(name, "float")); 813 fail_if(strcmp(name, "float"));
814 fail_if(!(exp = eolian_variable_value_get(var))); 814 fail_if(!(exp = eolian_variable_value_get(var)));
815 v = eolian_expression_eval_type(exp, type); 815 v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
816 fail_if(v.type != EOLIAN_EXPR_FLOAT); 816 fail_if(v.type != EOLIAN_EXPR_FLOAT);
817 fail_if(((int)v.value.f) != 10); 817 fail_if(((int)v.value.f) != 10);
818 818