summaryrefslogtreecommitdiff
path: root/src/bin/eolian/eo_generator.c
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-06-08 11:57:31 +0300
committerDaniel Zaoui <daniel.zaoui@samsung.com>2014-06-08 12:41:18 +0300
commit233650ed9d4d17a3f2b9bda4eccfa0982c821029 (patch)
tree2d5c118e5436ae68c5377084a0704f8ad8358cba /src/bin/eolian/eo_generator.c
parentb9b90ac204acc3db23023e1c04cdcbac3dd1ba96 (diff)
Eolian/Generator: concentrate the function name calculation to one
place. Instead of having the calculation (class name + function name + set/get) in many places in the code, it is now in one place and accessible via a function environment structure.
Diffstat (limited to '')
-rw-r--r--src/bin/eolian/eo_generator.c76
1 files changed, 43 insertions, 33 deletions
diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c
index da4cb356d0..1eab486b6d 100644
--- a/src/bin/eolian/eo_generator.c
+++ b/src/bin/eolian/eo_generator.c
@@ -62,7 +62,7 @@ const Eo_Class *@#class_class_get(void) EINA_CONST;\n\
62static const char 62static const char
63tmpl_eo_funcdef_doxygen[] = "\ 63tmpl_eo_funcdef_doxygen[] = "\
64/**\n\ 64/**\n\
65 * @def @#eoprefix_@#func\n\ 65 * @def %s\n\
66 *\n\ 66 *\n\
67@#desc\n\ 67@#desc\n\
68 *\n\ 68 *\n\
@@ -72,9 +72,6 @@ tmpl_eo_funcdef_doxygen[] = "\
72 */\n"; 72 */\n";
73 73
74static const char 74static const char
75tmpl_eo_funcdef[] = "EAPI @#rettype @#eoprefix_@#func(@#full_params);\n";
76
77static const char
78tmpl_eo_pardesc[] =" * @param[%s] %s %s\n"; 75tmpl_eo_pardesc[] =" * @param[%s] %s %s\n";
79 76
80#if 0 77#if 0
@@ -85,6 +82,7 @@ tmpl_eo_retdesc[] =" * @return %s\n";
85static Eina_Bool 82static Eina_Bool
86eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Function_Type ftype, Eina_Strbuf *functext) 83eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Function_Type ftype, Eina_Strbuf *functext)
87{ 84{
85 _eolian_class_func_vars func_env;
88 const char *str_dir[] = {"in", "out", "inout"}; 86 const char *str_dir[] = {"in", "out", "inout"};
89 const Eina_List *l; 87 const Eina_List *l;
90 void *data; 88 void *data;
@@ -96,6 +94,7 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
96 Eina_Bool ret_const = EINA_FALSE; 94 Eina_Bool ret_const = EINA_FALSE;
97 Eolian_Function_Scope scope = eolian_function_scope_get(func); 95 Eolian_Function_Scope scope = eolian_function_scope_get(func);
98 96
97 _class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env);
99 char *fsuffix = ""; 98 char *fsuffix = "";
100 rettype = eolian_function_return_type_get(func, ftype); 99 rettype = eolian_function_return_type_get(func, ftype);
101 if (ftype == EOLIAN_PROP_GET) 100 if (ftype == EOLIAN_PROP_GET)
@@ -122,15 +121,14 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
122 Eina_Strbuf *str_func = eina_strbuf_new(); 121 Eina_Strbuf *str_func = eina_strbuf_new();
123 if (scope == EOLIAN_SCOPE_PROTECTED) 122 if (scope == EOLIAN_SCOPE_PROTECTED)
124 eina_strbuf_append_printf(str_func, "#ifdef %s_PROTECTED\n", class_env.upper_classname); 123 eina_strbuf_append_printf(str_func, "#ifdef %s_PROTECTED\n", class_env.upper_classname);
125 _template_fill(str_func, tmpl_eo_funcdef_doxygen, class, NULL, funcname, EINA_FALSE); 124
126 _template_fill(str_func, tmpl_eo_funcdef, class, NULL, funcname, EINA_FALSE); 125 eina_strbuf_append_printf(str_func, tmpl_eo_funcdef_doxygen, func_env.lower_eo_func);
126 eina_strbuf_append_printf(str_func, "EAPI @#rettype %s(@#full_params);\n", func_env.lower_eo_func);
127
127 if (scope == EOLIAN_SCOPE_PROTECTED) 128 if (scope == EOLIAN_SCOPE_PROTECTED)
128 eina_strbuf_append_printf(str_func, "#endif\n"); 129 eina_strbuf_append_printf(str_func, "#endif\n");
129 eina_strbuf_append_printf(str_func, "\n"); 130 eina_strbuf_append_printf(str_func, "\n");
130 131
131 eina_strbuf_replace_all(str_func, "@#EOPREFIX", class_env.upper_eo_prefix);
132 eina_strbuf_replace_all(str_func, "@#eoprefix", class_env.lower_eo_prefix);
133
134 Eina_Strbuf *linedesc = eina_strbuf_new(); 132 Eina_Strbuf *linedesc = eina_strbuf_new();
135 eina_strbuf_append(linedesc, funcdesc ? funcdesc : "No description supplied."); 133 eina_strbuf_append(linedesc, funcdesc ? funcdesc : "No description supplied.");
136 if (eina_strbuf_length_get(linedesc)) 134 if (eina_strbuf_length_get(linedesc))
@@ -226,8 +224,8 @@ Eina_Bool
226eo_header_generate(const Eolian_Class class, Eina_Strbuf *buf) 224eo_header_generate(const Eolian_Class class, Eina_Strbuf *buf)
227{ 225{
228 const Eolian_Function_Type ftype_order[] = {EOLIAN_CTOR, EOLIAN_PROPERTY, EOLIAN_METHOD}; 226 const Eolian_Function_Type ftype_order[] = {EOLIAN_CTOR, EOLIAN_PROPERTY, EOLIAN_METHOD};
229 const Eina_List *l; 227 const Eina_List *itr;
230 void *data; 228 Eolian_Function fid;
231 char *tmpstr = malloc(0x1FF); 229 char *tmpstr = malloc(0x1FF);
232 Eina_Strbuf * str_hdr = eina_strbuf_new(); 230 Eina_Strbuf * str_hdr = eina_strbuf_new();
233 231
@@ -247,7 +245,7 @@ eo_header_generate(const Eolian_Class class, Eina_Strbuf *buf)
247 eina_strbuf_append(buf, eina_strbuf_string_get(linedesc)); 245 eina_strbuf_append(buf, eina_strbuf_string_get(linedesc));
248 eina_strbuf_free(linedesc); 246 eina_strbuf_free(linedesc);
249 247
250 _template_fill(str_hdr, tmpl_eo_obj_header, class, NULL, "", EINA_TRUE); 248 _template_fill(str_hdr, tmpl_eo_obj_header, class, NULL, NULL, EINA_TRUE);
251 249
252 eina_strbuf_replace_all(str_hdr, "@#EOPREFIX", class_env.upper_eo_prefix); 250 eina_strbuf_replace_all(str_hdr, "@#EOPREFIX", class_env.upper_eo_prefix);
253 eina_strbuf_replace_all(str_hdr, "@#eoprefix", class_env.lower_eo_prefix); 251 eina_strbuf_replace_all(str_hdr, "@#eoprefix", class_env.lower_eo_prefix);
@@ -257,7 +255,7 @@ eo_header_generate(const Eolian_Class class, Eina_Strbuf *buf)
257 Eina_Strbuf *tmpbuf = eina_strbuf_new(); 255 Eina_Strbuf *tmpbuf = eina_strbuf_new();
258 256
259 Eolian_Event event; 257 Eolian_Event event;
260 EINA_LIST_FOREACH(eolian_class_events_list_get(class), l, event) 258 EINA_LIST_FOREACH(eolian_class_events_list_get(class), itr, event)
261 { 259 {
262 const char *evname = NULL; 260 const char *evname = NULL;
263 const char *evdesc = NULL; 261 const char *evdesc = NULL;
@@ -270,32 +268,34 @@ eo_header_generate(const Eolian_Class class, Eina_Strbuf *buf)
270 eina_strbuf_prepend(tmpbuf," * "); 268 eina_strbuf_prepend(tmpbuf," * ");
271 eina_strbuf_append_printf(str_ev, "\n/**\n%s\n */\n", eina_strbuf_string_get(tmpbuf)); 269 eina_strbuf_append_printf(str_ev, "\n/**\n%s\n */\n", eina_strbuf_string_get(tmpbuf));
272 270
273 _template_fill(tmpbuf, "@#CLASS_EVENT_@#FUNC", class, NULL, evname, EINA_TRUE); 271 eina_strbuf_reset(tmpbuf);
272 eina_strbuf_append_printf(tmpbuf, "%s_EVENT_%s", class_env.upper_classname, evname);
274 eina_strbuf_replace_all(tmpbuf, ",", "_"); 273 eina_strbuf_replace_all(tmpbuf, ",", "_");
275 const char* s = eina_strbuf_string_get(tmpbuf); 274 char* s = (char *)eina_strbuf_string_get(tmpbuf);
275 eina_str_toupper(&s);
276 eina_strbuf_append_printf(str_ev, "#define %s (&(_%s))\n", s, s); 276 eina_strbuf_append_printf(str_ev, "#define %s (&(_%s))\n", s, s);
277 eina_strbuf_append_printf(str_extrn_ev, "EAPI extern const Eo_Event_Description _%s;\n", s); 277 eina_strbuf_append_printf(str_extrn_ev, "EAPI extern const Eo_Event_Description _%s;\n", s);
278 } 278 }
279 279
280 int i; 280 int i;
281 for (i = 0; i < 3; i++) 281 for (i = 0; i < 3; i++)
282 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, ftype_order[i]), l, data) 282 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, ftype_order[i]), itr, fid)
283 { 283 {
284 const Eolian_Function_Type ftype = eolian_function_type_get((Eolian_Function)data); 284 const Eolian_Function_Type ftype = eolian_function_type_get(fid);
285 Eina_Bool prop_read = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_GET ) ? EINA_TRUE : EINA_FALSE ; 285 Eina_Bool prop_read = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_GET ) ? EINA_TRUE : EINA_FALSE ;
286 Eina_Bool prop_write = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_SET ) ? EINA_TRUE : EINA_FALSE ; 286 Eina_Bool prop_write = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_SET ) ? EINA_TRUE : EINA_FALSE ;
287 287
288 if (!prop_read && !prop_write) 288 if (!prop_read && !prop_write)
289 { 289 {
290 eo_fundef_generate(class, (Eolian_Function)data, EOLIAN_UNRESOLVED, str_hdr); 290 eo_fundef_generate(class, fid, EOLIAN_UNRESOLVED, str_hdr);
291 } 291 }
292 if (prop_write) 292 if (prop_write)
293 { 293 {
294 eo_fundef_generate(class, (Eolian_Function)data, EOLIAN_PROP_SET, str_hdr); 294 eo_fundef_generate(class, fid, EOLIAN_PROP_SET, str_hdr);
295 } 295 }
296 if (prop_read) 296 if (prop_read)
297 { 297 {
298 eo_fundef_generate(class, (Eolian_Function)data, EOLIAN_PROP_GET, str_hdr); 298 eo_fundef_generate(class, fid, EOLIAN_PROP_GET, str_hdr);
299 } 299 }
300 } 300 }
301 301
@@ -316,6 +316,7 @@ eo_header_generate(const Eolian_Class class, Eina_Strbuf *buf)
316static Eina_Bool 316static Eina_Bool
317eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf, _eolian_class_vars *impl_env) 317eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf, _eolian_class_vars *impl_env)
318{ 318{
319 _eolian_class_func_vars func_env;
319 const char *suffix = ""; 320 const char *suffix = "";
320 Eina_Bool var_as_ret = EINA_FALSE; 321 Eina_Bool var_as_ret = EINA_FALSE;
321 const char *rettype = NULL; 322 const char *rettype = NULL;
@@ -408,11 +409,11 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
408 eina_list_count(eolian_property_keys_list_get(funcid)) || 409 eina_list_count(eolian_property_keys_list_get(funcid)) ||
409 (!var_as_ret && eina_list_count(eolian_parameters_list_get(funcid)) != 0); 410 (!var_as_ret && eina_list_count(eolian_parameters_list_get(funcid)) != 0);
410 Eina_Bool ret_is_void = (!rettype || !strcmp(rettype, "void")); 411 Eina_Bool ret_is_void = (!rettype || !strcmp(rettype, "void"));
412 _class_func_env_create(class, eolian_function_name_get(funcid), ftype, &func_env);
411 eina_strbuf_append_printf(eo_func_decl, 413 eina_strbuf_append_printf(eo_func_decl,
412 "EAPI EO_%sFUNC_BODY%s(%s_%s%s", 414 "EAPI EO_%sFUNC_BODY%s(%s",
413 ret_is_void?"VOID_":"", has_params?"V":"", 415 ret_is_void?"VOID_":"", has_params?"V":"",
414 class_env.lower_eo_prefix, eolian_function_name_get(funcid), 416 func_env.lower_eo_func);
415 suffix);
416 if (!ret_is_void) 417 if (!ret_is_void)
417 { 418 {
418 const char *dflt_ret_val = 419 const char *dflt_ret_val =
@@ -463,15 +464,16 @@ static Eina_Bool
463eo_op_desc_generate(const Eolian_Class class, Eolian_Function fid, Eolian_Function_Type ftype, 464eo_op_desc_generate(const Eolian_Class class, Eolian_Function fid, Eolian_Function_Type ftype,
464 const char *desc, Eina_Strbuf *buf) 465 const char *desc, Eina_Strbuf *buf)
465{ 466{
467 _eolian_class_func_vars func_env;
466 const char *funcname = eolian_function_name_get(fid); 468 const char *funcname = eolian_function_name_get(fid);
467 const char *suffix = ""; 469 const char *suffix = "";
468 470
469 eina_strbuf_reset(buf); 471 eina_strbuf_reset(buf);
470 _class_func_names_fill(class, NULL, funcname); 472 _class_func_env_create(class, funcname, ftype, &func_env);
471 if (ftype == EOLIAN_PROP_GET) suffix = "_get"; 473 if (ftype == EOLIAN_PROP_GET) suffix = "_get";
472 if (ftype == EOLIAN_PROP_SET) suffix = "_set"; 474 if (ftype == EOLIAN_PROP_SET) suffix = "_set";
473 Eina_Bool is_virtual_pure = eolian_function_is_virtual_pure(fid, ftype); 475 Eina_Bool is_virtual_pure = eolian_function_is_virtual_pure(fid, ftype);
474 eina_strbuf_append_printf(buf, "\n EO_OP_FUNC(%s_%s%s, ", class_env.lower_eo_prefix, funcname, suffix); 476 eina_strbuf_append_printf(buf, "\n EO_OP_FUNC(%s, ", func_env.lower_eo_func);
475 if (!is_virtual_pure) 477 if (!is_virtual_pure)
476 eina_strbuf_append_printf(buf, "_%s_%s%s, \"%s\"),", class_env.lower_classname, funcname, suffix, desc); 478 eina_strbuf_append_printf(buf, "_%s_%s%s, \"%s\"),", class_env.lower_classname, funcname, suffix, desc);
477 else 479 else
@@ -494,10 +496,14 @@ eo_source_beginning_generate(const Eolian_Class class, Eina_Strbuf *buf)
494 const char *evname; 496 const char *evname;
495 const char *evdesc; 497 const char *evdesc;
496 char *evdesc_line1; 498 char *evdesc_line1;
499 char *p;
497 500
501 eina_strbuf_reset(str_ev);
498 eolian_class_event_information_get(event, &evname, NULL, &evdesc); 502 eolian_class_event_information_get(event, &evname, NULL, &evdesc);
499 evdesc_line1 = _source_desc_get(evdesc); 503 evdesc_line1 = _source_desc_get(evdesc);
500 _template_fill(str_ev, "@#CLASS_EVENT_@#FUNC", class, NULL, evname, EINA_TRUE); 504 eina_strbuf_append_printf(str_ev, "%s_EVENT_%s", class_env.upper_classname, evname);
505 p = (char *)eina_strbuf_string_get(str_ev);
506 eina_str_toupper(&p);
501 eina_strbuf_replace_all(str_ev, ",", "_"); 507 eina_strbuf_replace_all(str_ev, ",", "_");
502 508
503 eina_strbuf_append_printf(tmpbuf, 509 eina_strbuf_append_printf(tmpbuf,
@@ -562,7 +568,7 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf)
562 568
563 eina_strbuf_reset(tmpbuf); 569 eina_strbuf_reset(tmpbuf);
564 if (eolian_class_ctor_enable_get(class)) 570 if (eolian_class_ctor_enable_get(class))
565 _template_fill(tmpbuf, "_@#class_class_constructor", class, NULL, "", EINA_TRUE); 571 _template_fill(tmpbuf, "_@#class_class_constructor", class, NULL, NULL, EINA_TRUE);
566 else 572 else
567 eina_strbuf_append_printf(tmpbuf, "NULL"); 573 eina_strbuf_append_printf(tmpbuf, "NULL");
568 eina_strbuf_replace_all(str_end, "@#ctor_name", eina_strbuf_string_get(tmpbuf)); 574 eina_strbuf_replace_all(str_end, "@#ctor_name", eina_strbuf_string_get(tmpbuf));
@@ -572,7 +578,7 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf)
572 { 578 {
573 eina_strbuf_replace_all(str_end, "@#dtor_func", eina_strbuf_string_get(tmpbuf)); 579 eina_strbuf_replace_all(str_end, "@#dtor_func", eina_strbuf_string_get(tmpbuf));
574 eina_strbuf_reset(tmpbuf); 580 eina_strbuf_reset(tmpbuf);
575 _template_fill(tmpbuf, "_@#class_class_destructor", class, NULL, "", EINA_TRUE); 581 _template_fill(tmpbuf, "_@#class_class_destructor", class, NULL, NULL, EINA_TRUE);
576 eina_strbuf_replace_all(str_end, "@#dtor_name", eina_strbuf_string_get(tmpbuf)); 582 eina_strbuf_replace_all(str_end, "@#dtor_name", eina_strbuf_string_get(tmpbuf));
577 } 583 }
578 else 584 else
@@ -690,9 +696,13 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf)
690 EINA_LIST_FOREACH(eolian_class_events_list_get(class), itr, event) 696 EINA_LIST_FOREACH(eolian_class_events_list_get(class), itr, event)
691 { 697 {
692 const char *evname; 698 const char *evname;
699 char *p;
693 700
701 eina_strbuf_reset(tmpbuf);
694 eolian_class_event_information_get(event, &evname, NULL, NULL); 702 eolian_class_event_information_get(event, &evname, NULL, NULL);
695 _template_fill(tmpbuf, "@#CLASS_EVENT_@#FUNC", class, NULL, evname, EINA_TRUE); 703 eina_strbuf_append_printf(tmpbuf, "%s_EVENT_%s", class_env.upper_classname, evname);
704 p = (char *)eina_strbuf_string_get(tmpbuf);
705 eina_str_toupper(&p);
696 eina_strbuf_replace_all(tmpbuf, ",", "_"); 706 eina_strbuf_replace_all(tmpbuf, ",", "_");
697 eina_strbuf_append_printf(str_ev, "\n %s,", eina_strbuf_string_get(tmpbuf)); 707 eina_strbuf_append_printf(str_ev, "\n %s,", eina_strbuf_string_get(tmpbuf));
698 } 708 }
@@ -701,7 +711,7 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf)
701 if (eina_strbuf_length_get(str_ev)) 711 if (eina_strbuf_length_get(str_ev))
702 { 712 {
703 Eina_Strbuf *events_desc = eina_strbuf_new(); 713 Eina_Strbuf *events_desc = eina_strbuf_new();
704 _template_fill(events_desc, tmpl_events_desc, class, NULL, "", EINA_TRUE); 714 _template_fill(events_desc, tmpl_events_desc, class, NULL, NULL, EINA_TRUE);
705 eina_strbuf_replace_all(events_desc, "@#list_evdesc", eina_strbuf_string_get(str_ev)); 715 eina_strbuf_replace_all(events_desc, "@#list_evdesc", eina_strbuf_string_get(str_ev));
706 eina_strbuf_replace_all(str_end, "@#events_desc", eina_strbuf_string_get(events_desc)); 716 eina_strbuf_replace_all(str_end, "@#events_desc", eina_strbuf_string_get(events_desc));
707 eina_strbuf_free(events_desc); 717 eina_strbuf_free(events_desc);
@@ -731,7 +741,7 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf)
731 if (eina_strbuf_length_get(str_op)) 741 if (eina_strbuf_length_get(str_op))
732 { 742 {
733 Eina_Strbuf *ops_desc = eina_strbuf_new(); 743 Eina_Strbuf *ops_desc = eina_strbuf_new();
734 _template_fill(ops_desc, tmpl_eo_ops_desc, class, NULL, "", EINA_TRUE); 744 _template_fill(ops_desc, tmpl_eo_ops_desc, class, NULL, NULL, EINA_TRUE);
735 eina_strbuf_replace_all(ops_desc, "@#list_op", eina_strbuf_string_get(str_op)); 745 eina_strbuf_replace_all(ops_desc, "@#list_op", eina_strbuf_string_get(str_op));
736 eina_strbuf_replace_all(str_end, "@#ops_desc", eina_strbuf_string_get(ops_desc)); 746 eina_strbuf_replace_all(str_end, "@#ops_desc", eina_strbuf_string_get(ops_desc));
737 eina_strbuf_free(ops_desc); 747 eina_strbuf_free(ops_desc);
@@ -782,10 +792,10 @@ eo_source_generate(const Eolian_Class class, Eina_Strbuf *buf)
782 792
783 Eina_Strbuf *str_bodyf = eina_strbuf_new(); 793 Eina_Strbuf *str_bodyf = eina_strbuf_new();
784 794
785 if (!eo_source_beginning_generate(class, buf)) goto end;
786
787 _class_env_create(class, NULL, &class_env); 795 _class_env_create(class, NULL, &class_env);
788 796
797 if (!eo_source_beginning_generate(class, buf)) goto end;
798
789 //Properties 799 //Properties
790 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, EOLIAN_PROPERTY), itr, fn) 800 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, EOLIAN_PROPERTY), itr, fn)
791 { 801 {