summaryrefslogtreecommitdiff
path: root/src/bin/eolian
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-09-24 17:06:24 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2019-09-24 18:27:37 +0200
commit92da64a532f8c1746d7bd06b66b7ff4409c2ff8c (patch)
tree02e05754553c64c119f2e78194f5527d5cf0ff1e /src/bin/eolian
parent553ce69bade88ac675aa56fcb184240403a12bfc (diff)
eolian: remove support for globals
This was meant to happen but did not previously happen. It is not ideal to do it now but better do it while we still can. In short, this removes one half of the variables API (keeps constants as they are) and repurposes the API to be only for constants. This is also better for consistency to match errors.
Diffstat (limited to 'src/bin/eolian')
-rw-r--r--src/bin/eolian/docs.c9
-rw-r--r--src/bin/eolian/types.c93
2 files changed, 25 insertions, 77 deletions
diff --git a/src/bin/eolian/docs.c b/src/bin/eolian/docs.c
index e9af2e8..6b016eb 100644
--- a/src/bin/eolian/docs.c
+++ b/src/bin/eolian/docs.c
@@ -27,13 +27,8 @@ _generate_ref(const Eolian_State *state, const char *refn, Eina_Strbuf *wbuf)
27 char *n = strdup(eolian_object_name_get(decl)); 27 char *n = strdup(eolian_object_name_get(decl));
28 char *p = n; 28 char *p = n;
29 while ((p = strchr(p, '.'))) *p = '_'; 29 while ((p = strchr(p, '.'))) *p = '_';
30 if (eolian_object_type_get(decl) == EOLIAN_OBJECT_VARIABLE) 30 if (eolian_object_type_get(decl) == EOLIAN_OBJECT_CONSTANT)
31 { 31 eina_str_toupper(&n);
32 const Eolian_Variable *v = (const Eolian_Variable *)decl;
33 /* constants are emitted as macros */
34 if (eolian_variable_type_get(v) == EOLIAN_VAR_CONSTANT)
35 eina_str_toupper(&n);
36 }
37 eina_strbuf_append(wbuf, n); 32 eina_strbuf_append(wbuf, n);
38 free(n); 33 free(n);
39 return; 34 return;
diff --git a/src/bin/eolian/types.c b/src/bin/eolian/types.c
index 75426f1..9623283 100644
--- a/src/bin/eolian/types.c
+++ b/src/bin/eolian/types.c
@@ -168,12 +168,12 @@ _type_generate(const Eolian_State *state, const Eolian_Typedecl *tp,
168} 168}
169 169
170static Eina_Strbuf * 170static Eina_Strbuf *
171_var_generate(const Eolian_State *state, const Eolian_Variable *vr) 171_const_generate(const Eolian_State *state, const Eolian_Constant *vr)
172{ 172{
173 char *fn = strdup(eolian_variable_name_get(vr)); 173 char *fn = strdup(eolian_constant_name_get(vr));
174 char *p = strrchr(fn, '.'); 174 char *p = strrchr(fn, '.');
175 if (p) *p = '\0'; 175 if (p) *p = '\0';
176 Eina_Strbuf *buf = eo_gen_docs_full_gen(state, eolian_variable_documentation_get(vr), 176 Eina_Strbuf *buf = eo_gen_docs_full_gen(state, eolian_constant_documentation_get(vr),
177 fn, 0); 177 fn, 0);
178 if (p) 178 if (p)
179 { 179 {
@@ -184,31 +184,23 @@ _var_generate(const Eolian_State *state, const Eolian_Variable *vr)
184 eina_str_toupper(&fn); 184 eina_str_toupper(&fn);
185 if (!buf) buf = eina_strbuf_new(); 185 if (!buf) buf = eina_strbuf_new();
186 else eina_strbuf_append_char(buf, '\n'); 186 else eina_strbuf_append_char(buf, '\n');
187 const Eolian_Type *vt = eolian_variable_base_type_get(vr); 187
188 if (eolian_variable_type_get(vr) == EOLIAN_VAR_CONSTANT) 188 /* we generate a define macro here, as it's a constant */
189 { 189 eina_strbuf_prepend_printf(buf, "#ifndef %s\n", fn);
190 /* we generate a define macro here, as it's a constant */ 190 eina_strbuf_append_printf(buf, "#define %s ", fn);
191 eina_strbuf_prepend_printf(buf, "#ifndef %s\n", fn); 191 const Eolian_Expression *vv = eolian_constant_value_get(vr);
192 eina_strbuf_append_printf(buf, "#define %s ", fn); 192 Eolian_Value val = eolian_expression_eval(vv, EOLIAN_MASK_ALL);
193 const Eolian_Expression *vv = eolian_variable_value_get(vr); 193 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
194 Eolian_Value val = eolian_expression_eval(vv, EOLIAN_MASK_ALL); 194 eina_strbuf_append(buf, lit);
195 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val); 195 Eina_Stringshare *exp = eolian_expression_serialize(vv);
196 eina_strbuf_append(buf, lit); 196 if (exp && strcmp(lit, exp))
197 Eina_Stringshare *exp = eolian_expression_serialize(vv); 197 eina_strbuf_append_printf(buf, " /* %s */", exp);
198 if (exp && strcmp(lit, exp)) 198 eina_stringshare_del(lit);
199 eina_strbuf_append_printf(buf, " /* %s */", exp); 199 eina_stringshare_del(exp);
200 eina_stringshare_del(lit); 200 eina_strbuf_append(buf, "\n#endif");
201 eina_stringshare_del(exp); 201
202 eina_strbuf_append(buf, "\n#endif");
203 }
204 else
205 {
206 Eina_Stringshare *ct = eolian_type_c_type_get(vt);
207 eina_strbuf_append_printf(buf, "EWAPI extern %s %s;", ct, fn);
208 eina_stringshare_del(ct);
209 }
210 free(fn); 202 free(fn);
211 if (eolian_variable_is_beta(vr)) 203 if (eolian_constant_is_beta(vr))
212 { 204 {
213 eina_strbuf_prepend(buf, "#ifdef EFL_BETA_API_SUPPORT\n"); 205 eina_strbuf_prepend(buf, "#ifdef EFL_BETA_API_SUPPORT\n");
214 eina_strbuf_append(buf, "\n#endif /* EFL_BETA_API_SUPPORT */"); 206 eina_strbuf_append(buf, "\n#endif /* EFL_BETA_API_SUPPORT */");
@@ -259,13 +251,13 @@ void eo_gen_types_header_gen(const Eolian_State *state,
259 { 251 {
260 Eolian_Object_Type dt = eolian_object_type_get(decl); 252 Eolian_Object_Type dt = eolian_object_type_get(decl);
261 253
262 if (dt == EOLIAN_OBJECT_VARIABLE) 254 if (dt == EOLIAN_OBJECT_CONSTANT)
263 { 255 {
264 const Eolian_Variable *vr = (const Eolian_Variable *)decl; 256 const Eolian_Constant *vr = (const Eolian_Constant *)decl;
265 if (!vr || eolian_variable_is_extern(vr)) 257 if (!vr || eolian_constant_is_extern(vr))
266 continue; 258 continue;
267 259
268 Eina_Strbuf *vbuf = _var_generate(state, vr); 260 Eina_Strbuf *vbuf = _const_generate(state, vr);
269 if (vbuf) 261 if (vbuf)
270 { 262 {
271 eina_strbuf_append(buf, eina_strbuf_string_get(vbuf)); 263 eina_strbuf_append(buf, eina_strbuf_string_get(vbuf));
@@ -375,43 +367,6 @@ _source_gen_error(Eina_Strbuf *buf, const Eolian_Error *err)
375 eina_strbuf_append(buf, " return err;\n}\n\n"); 367 eina_strbuf_append(buf, " return err;\n}\n\n");
376} 368}
377 369
378static void
379_source_gen_var(Eina_Strbuf *buf, const Eolian_Variable *vr)
380{
381 if (eolian_variable_is_extern(vr))
382 return;
383
384 if (eolian_variable_type_get(vr) == EOLIAN_VAR_CONSTANT)
385 return;
386
387 const Eolian_Expression *vv = eolian_variable_value_get(vr);
388 if (!vv)
389 return;
390
391 char *fn = strdup(eolian_variable_name_get(vr));
392 for (char *p = strchr(fn, '.'); p; p = strchr(p, '.'))
393 *p = '_';
394 eina_str_toupper(&fn);
395
396 const Eolian_Type *vt = eolian_variable_base_type_get(vr);
397 Eina_Stringshare *ct = eolian_type_c_type_get(vt);
398 eina_strbuf_append_printf(buf, "EWAPI %s %s = ", ct, fn);
399 eina_stringshare_del(ct);
400 free(fn);
401
402 Eolian_Value val = eolian_expression_eval(vv, EOLIAN_MASK_ALL);
403 Eina_Stringshare *lit = eolian_expression_value_to_literal(&val);
404 eina_strbuf_append(buf, lit);
405 eina_strbuf_append_char(buf, ';');
406 Eina_Stringshare *exp = eolian_expression_serialize(vv);
407 if (exp && strcmp(lit, exp))
408 eina_strbuf_append_printf(buf, " /* %s */", exp);
409 eina_stringshare_del(lit);
410 eina_stringshare_del(exp);
411
412 eina_strbuf_append(buf, "\n");
413}
414
415void eo_gen_types_source_gen(Eina_Iterator *itr, Eina_Strbuf *buf) 370void eo_gen_types_source_gen(Eina_Iterator *itr, Eina_Strbuf *buf)
416{ 371{
417 const Eolian_Object *decl; 372 const Eolian_Object *decl;
@@ -421,8 +376,6 @@ void eo_gen_types_source_gen(Eina_Iterator *itr, Eina_Strbuf *buf)
421 376
422 if (dt == EOLIAN_OBJECT_ERROR) 377 if (dt == EOLIAN_OBJECT_ERROR)
423 _source_gen_error(buf, (const Eolian_Error *)decl); 378 _source_gen_error(buf, (const Eolian_Error *)decl);
424 else if (dt == EOLIAN_OBJECT_VARIABLE)
425 _source_gen_var(buf, (const Eolian_Variable *)decl);
426 } 379 }
427 eina_iterator_free(itr); 380 eina_iterator_free(itr);
428} 381}