summaryrefslogtreecommitdiff
path: root/src/bin/eolian/eo_generator.c
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-09-02 17:00:14 +0300
committerDaniel Zaoui <daniel.zaoui@samsung.com>2014-09-03 08:36:20 +0300
commitffa9ad7daf0bdc6c8de9cb8e3994cc5b6e53858a (patch)
tree1df8cb19e3f205bb718763e01f9b96b8412cff9a /src/bin/eolian/eo_generator.c
parent3f468537fd38a3d8f6e59521a485fde38ebc1b6e (diff)
Eolian/Generator: support params initialization.
This is needed when get properties or methods have to return a value in case of failure or to initialize parameters. The way used is to generate an intermediate function that will initialize the parameters and then invoke the "user" function.
Diffstat (limited to 'src/bin/eolian/eo_generator.c')
-rw-r--r--src/bin/eolian/eo_generator.c76
1 files changed, 70 insertions, 6 deletions
diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c
index c4cc89c54c..ce1d0ad52c 100644
--- a/src/bin/eolian/eo_generator.c
+++ b/src/bin/eolian/eo_generator.c
@@ -6,6 +6,10 @@
6#include "common_funcs.h" 6#include "common_funcs.h"
7 7
8static _eolian_class_vars class_env; 8static _eolian_class_vars class_env;
9/* Used to store the function names that will have to be appended
10 * with __eolian during C generation. Needed when params have to
11 * be initialized and for future features. */
12static Eina_Hash *_funcs_params_init = NULL;
9 13
10static const char 14static const char
11tmpl_dtor[] = "\ 15tmpl_dtor[] = "\
@@ -348,6 +352,7 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
348 Eina_Bool add_star = EINA_FALSE; 352 Eina_Bool add_star = EINA_FALSE;
349 Eina_Iterator *itr; 353 Eina_Iterator *itr;
350 void *data, *data2; 354 void *data, *data2;
355 const Eolian_Expression *default_ret_val = NULL;
351 356
352 Eina_Bool need_implementation = EINA_TRUE; 357 Eina_Bool need_implementation = EINA_TRUE;
353 if (!impl_env && eolian_function_is_virtual_pure(funcid, ftype)) need_implementation = EINA_FALSE; 358 if (!impl_env && eolian_function_is_virtual_pure(funcid, ftype)) need_implementation = EINA_FALSE;
@@ -356,8 +361,11 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
356 Eina_Strbuf *va_args = eina_strbuf_new(); 361 Eina_Strbuf *va_args = eina_strbuf_new();
357 Eina_Strbuf *params = eina_strbuf_new(); /* only variables names */ 362 Eina_Strbuf *params = eina_strbuf_new(); /* only variables names */
358 Eina_Strbuf *full_params = eina_strbuf_new(); /* variables types + names */ 363 Eina_Strbuf *full_params = eina_strbuf_new(); /* variables types + names */
364 Eina_Strbuf *params_init = eina_strbuf_new(); /* init of variables to default */
359 365
360 rettypet = eolian_function_return_type_get(funcid, ftype); 366 rettypet = eolian_function_return_type_get(funcid, ftype);
367 if (rettypet)
368 default_ret_val = eolian_function_return_default_value_get(funcid, ftype);
361 if (ftype == EOLIAN_PROP_GET) 369 if (ftype == EOLIAN_PROP_GET)
362 { 370 {
363 suffix = "_get"; 371 suffix = "_get";
@@ -372,6 +380,7 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
372 rettypet = eolian_parameter_type_get(param); 380 rettypet = eolian_parameter_type_get(param);
373 var_as_ret = EINA_TRUE; 381 var_as_ret = EINA_TRUE;
374 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE); 382 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
383 default_ret_val = eolian_parameter_default_value_get(param);
375 } 384 }
376 eina_iterator_free(itr); 385 eina_iterator_free(itr);
377 } 386 }
@@ -415,6 +424,30 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
415 eina_strbuf_append_printf(full_params, ", %s%s%s%s%s", 424 eina_strbuf_append_printf(full_params, ", %s%s%s%s%s",
416 is_const?"const ":"", 425 is_const?"const ":"",
417 ptype, had_star?"":" ", add_star?"*":"", pname); 426 ptype, had_star?"":" ", add_star?"*":"", pname);
427 if (ftype != EOLIAN_PROP_SET)
428 {
429 const Eolian_Expression *dflt_value = eolian_parameter_default_value_get(param);
430 if (dflt_value)
431 {
432 const char *val_str = NULL;
433 Eolian_Value val = eolian_expression_eval
434 (dflt_value, EOLIAN_MASK_ALL);
435 if (val.type)
436 {
437 val_str = eolian_expression_value_to_literal(&val);
438 eina_strbuf_append_printf(params_init,
439 " if (%s) *%s = %s;",
440 pname, pname, val_str);
441 if (eolian_expression_type_get(dflt_value) == EOLIAN_EXPR_ENUM)
442 {
443 Eina_Stringshare *string = eolian_expression_serialize(dflt_value);
444 eina_strbuf_append_printf(params_init, " /* %s */", string);
445 eina_stringshare_del(string);
446 }
447 eina_strbuf_append_printf(params_init, "\n");
448 }
449 }
450 }
418 eina_stringshare_del(ptype); 451 eina_stringshare_del(ptype);
419 } 452 }
420 eina_iterator_free(itr); 453 eina_iterator_free(itr);
@@ -433,6 +466,25 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
433 impl_env?impl_env->lower_classname:"", 466 impl_env?impl_env->lower_classname:"",
434 eolian_function_name_get(funcid), suffix); 467 eolian_function_name_get(funcid), suffix);
435 468
469 if (eina_strbuf_length_get(params_init))
470 {
471 eina_hash_add(_funcs_params_init,
472 eina_stringshare_add(eolian_function_name_get(funcid)), funcid);
473 eina_strbuf_append_printf(fbody, "static %s%s __eolian_%s%s%s_%s%s(Eo *obj, @#Datatype_Data *pd@#full_params)\n{\n%s\n",
474 ret_const?"const ":"", rettype?rettype:"void",
475 class_env.lower_classname,
476 impl_env?"_":"",
477 impl_env?impl_env->lower_classname:"",
478 eolian_function_name_get(funcid), suffix,
479 eina_strbuf_string_get(params_init));
480 eina_strbuf_append_printf(fbody, " %s_%s%s%s_%s%s(obj, pd, %s);\n}\n\n",
481 rettype?"return ":"",
482 class_env.lower_classname,
483 impl_env?"_":"",
484 impl_env?impl_env->lower_classname:"",
485 eolian_function_name_get(funcid), suffix,
486 eina_strbuf_string_get(params));
487 }
436 eina_strbuf_free(ret_param); 488 eina_strbuf_free(ret_param);
437 } 489 }
438 if (!impl_env) 490 if (!impl_env)
@@ -458,20 +510,23 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
458 func_env.lower_eo_func); 510 func_env.lower_eo_func);
459 if (!ret_is_void) 511 if (!ret_is_void)
460 { 512 {
461 const Eolian_Expression *default_ret_val =
462 eolian_function_return_default_value_get(funcid, ftype);
463 const char *val_str = NULL; 513 const char *val_str = NULL;
464 if (default_ret_val) 514 if (default_ret_val)
465 { 515 {
466 Eolian_Value val = eolian_expression_eval_type 516 Eolian_Value val = eolian_expression_eval
467 (default_ret_val, rettypet); 517 (default_ret_val, EOLIAN_MASK_ALL);
468 if (val.type) 518 if (val.type)
469 val_str = eolian_expression_value_to_literal(&val); 519 val_str = eolian_expression_value_to_literal(&val);
470 } 520 }
471 eina_strbuf_append_printf(eo_func_decl, ", %s%s, %s", 521 eina_strbuf_append_printf(eo_func_decl, ", %s%s, %s",
472 ret_const ? "const " : "", rettype, 522 ret_const ? "const " : "", rettype,
473 val_str?val_str:"0"); 523 val_str?val_str:"0");
474 524 if (val_str && eolian_expression_type_get(default_ret_val) == EOLIAN_EXPR_ENUM)
525 {
526 Eina_Stringshare *string = eolian_expression_serialize(default_ret_val);
527 eina_strbuf_append_printf(eo_func_decl, " /* %s */", string);
528 eina_stringshare_del(string);
529 }
475 } 530 }
476 if (has_params) 531 if (has_params)
477 { 532 {
@@ -508,6 +563,7 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
508 563
509 eina_strbuf_free(va_args); 564 eina_strbuf_free(va_args);
510 eina_strbuf_free(full_params); 565 eina_strbuf_free(full_params);
566 eina_strbuf_free(params_init);
511 eina_strbuf_free(params); 567 eina_strbuf_free(params);
512 eina_strbuf_free(fbody); 568 eina_strbuf_free(fbody);
513 return EINA_TRUE; 569 return EINA_TRUE;
@@ -530,7 +586,12 @@ eo_op_desc_generate(const Eolian_Class *class, Eolian_Function *fid, Eolian_Func
530 if (eolian_function_is_class(fid)) class_str = "CLASS_"; 586 if (eolian_function_is_class(fid)) class_str = "CLASS_";
531 eina_strbuf_append_printf(buf, "\n EO_OP_%sFUNC(%s, ", class_str, func_env.lower_eo_func); 587 eina_strbuf_append_printf(buf, "\n EO_OP_%sFUNC(%s, ", class_str, func_env.lower_eo_func);
532 if (!is_virtual_pure) 588 if (!is_virtual_pure)
533 eina_strbuf_append_printf(buf, "_%s_%s%s, \"%s\"),", class_env.lower_classname, funcname, suffix, desc); 589 {
590 eina_strbuf_append_printf(buf, "%s_%s_%s%s, \"%s\"),",
591 eina_hash_find(_funcs_params_init, funcname)
592 && ftype != EOLIAN_PROP_SET?"__eolian":"",
593 class_env.lower_classname, funcname, suffix, desc);
594 }
534 else 595 else
535 eina_strbuf_append_printf(buf, "NULL, \"%s\"),", desc); 596 eina_strbuf_append_printf(buf, "NULL, \"%s\"),", desc);
536 597
@@ -863,6 +924,7 @@ eo_source_generate(const Eolian_Class *class, Eina_Strbuf *buf)
863 Eina_Strbuf *str_bodyf = eina_strbuf_new(); 924 Eina_Strbuf *str_bodyf = eina_strbuf_new();
864 925
865 _class_env_create(class, NULL, &class_env); 926 _class_env_create(class, NULL, &class_env);
927 _funcs_params_init = eina_hash_stringshared_new(NULL);
866 928
867 if (!eo_source_beginning_generate(class, buf)) goto end; 929 if (!eo_source_beginning_generate(class, buf)) goto end;
868 930
@@ -901,6 +963,8 @@ eo_source_generate(const Eolian_Class *class, Eina_Strbuf *buf)
901 963
902 ret = EINA_TRUE; 964 ret = EINA_TRUE;
903end: 965end:
966 eina_hash_free(_funcs_params_init);
967 _funcs_params_init = NULL;
904 eina_strbuf_free(str_bodyf); 968 eina_strbuf_free(str_bodyf);
905 return ret; 969 return ret;
906} 970}