summaryrefslogtreecommitdiff
path: root/src/bin/eolian/eo1_generator.c
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-03-10 11:52:46 +0200
committerDaniel Zaoui <daniel.zaoui@samsung.com>2014-03-10 15:07:05 +0200
commit4e33fd16e2e819eb8d0db828b66cf5a0889b2581 (patch)
tree4e08fd122b28af6d6f5f9ad9ac5a98be6002ea75 /src/bin/eolian/eo1_generator.c
parent456e6f20e0feb41c8c72b8bdeea505ab8d75e4c8 (diff)
Eolian: add support of eo_prefix and data.
You can add in the .eo file the eo_prefix:... and data:... in case you want to override respectively the Eo prefix and the data type. If "data: null" is used, no data type will be added.
Diffstat (limited to '')
-rw-r--r--src/bin/eolian/eo1_generator.c93
1 files changed, 67 insertions, 26 deletions
diff --git a/src/bin/eolian/eo1_generator.c b/src/bin/eolian/eo1_generator.c
index 6938ee294d..f0075b615d 100644
--- a/src/bin/eolian/eo1_generator.c
+++ b/src/bin/eolian/eo1_generator.c
@@ -8,7 +8,7 @@
8static const char 8static const char
9tmpl_eo_src_begin[] = "\ 9tmpl_eo_src_begin[] = "\
10\n\ 10\n\
11EAPI Eo_Op @#OBJCLASS_BASE_ID = EO_NOOP;\n\ 11EAPI Eo_Op @#EOPREFIX_BASE_ID = EO_NOOP;\n\
12\n\ 12\n\
13@#list_events\n\ 13@#list_events\n\
14\n\ 14\n\
@@ -51,58 +51,58 @@ static const Eo_Class_Description _@#class_class_desc = {\n\
51 EO_VERSION,\n\ 51 EO_VERSION,\n\
52 \"@#Class\",\n\ 52 \"@#Class\",\n\
53 @#type_class,\n\ 53 @#type_class,\n\
54 EO_CLASS_DESCRIPTION_OPS(&@#OBJCLASS_BASE_ID, _@#class_op_desc, @#OBJCLASS_SUB_ID_LAST),\n\ 54 EO_CLASS_DESCRIPTION_OPS(&@#EOPREFIX_BASE_ID, _@#class_op_desc, @#EOPREFIX_SUB_ID_LAST),\n\
55 _@#class_event_desc,\n\ 55 _@#class_event_desc,\n\
56 sizeof(@#Class_Data),\n\ 56 @#SizeOfData,\n\
57 _gen_@#class_class_constructor,\n\ 57 _gen_@#class_class_constructor,\n\
58 @#dtor_name\n\ 58 @#dtor_name\n\
59};\n\ 59};\n\
60\n\ 60\n\
61EO_DEFINE_CLASS(@#objclass_class_get, &_@#class_class_desc, @#list_inheritNULL);\ 61EO_DEFINE_CLASS(@#eoprefix_class_get, &_@#class_class_desc, @#list_inheritNULL);\
62"; 62";
63 63
64static const char 64static const char
65tmpl_eo_op_desc[] = "\n EO_OP_DESCRIPTION(@#OBJCLASS_SUB_ID_@#FUNC, \"@#desc\"),"; 65tmpl_eo_op_desc[] = "\n EO_OP_DESCRIPTION(@#EOPREFIX_SUB_ID_@#FUNC, \"@#desc\"),";
66 66
67static const char 67static const char
68tmpl_eo_func_desc[] = "\n EO_OP_FUNC(@#OBJCLASS_ID(@#OBJCLASS_SUB_ID_@#FUNC), _eo_obj_@#class_@#func),"; 68tmpl_eo_func_desc[] = "\n EO_OP_FUNC(@#EOPREFIX_ID(@#EOPREFIX_SUB_ID_@#FUNC), _eo_obj_@#class_@#func),";
69 69
70static const char 70static const char
71tmpl_eobase_func_desc[] = "\n EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_@#FUNC), _eo_obj_@#class_@#func),"; 71tmpl_eobase_func_desc[] = "\n EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_@#FUNC), _eo_obj_@#class_@#func),";
72 72
73static const char 73static const char
74tmpl_eo_header[] = "\ 74tmpl_eo_obj_header[] = "\
75#define @#OBJCLASS_CLASS @#objclass_class_get()\n\ 75#define @#EOPREFIX_CLASS @#eoprefix_class_get()\n\
76\n\ 76\n\
77const Eo_Class *@#objclass_class_get(void) EINA_CONST;\n\ 77const Eo_Class *@#eoprefix_class_get(void) EINA_CONST;\n\
78\n\ 78\n\
79extern EAPI Eo_Op @#OBJCLASS_BASE_ID;\n\ 79extern EAPI Eo_Op @#EOPREFIX_BASE_ID;\n\
80\n\ 80\n\
81enum\n\ 81enum\n\
82{@#list_subid\n\ 82{@#list_subid\n\
83 @#OBJCLASS_SUB_ID_LAST\n\ 83 @#EOPREFIX_SUB_ID_LAST\n\
84};\n\ 84};\n\
85\n\ 85\n\
86#define @#OBJCLASS_ID(sub_id) (@#OBJCLASS_BASE_ID + sub_id)\n\ 86#define @#EOPREFIX_ID(sub_id) (@#EOPREFIX_BASE_ID + sub_id)\n\
87"; 87";
88 88
89static const char 89static const char
90tmpl_eo_subid[] = "\n @#OBJCLASS_SUB_ID_@#FUNC,"; 90tmpl_eo_subid[] = "\n @#EOPREFIX_SUB_ID_@#FUNC,";
91 91
92static const char 92static const char
93tmpl_eo_subid_apnd[] = " @#OBJCLASS_SUB_ID_@#FUNC,\n"; 93tmpl_eo_subid_apnd[] = " @#EOPREFIX_SUB_ID_@#FUNC,\n";
94 94
95static const char 95static const char
96tmpl_eo_funcdef[] = "\n\ 96tmpl_eo_funcdef[] = "\n\
97/**\n\ 97/**\n\
98 * @def @#objclass_@#func\n\ 98 * @def @#eoprefix_@#func\n\
99 *\n\ 99 *\n\
100@#desc\n\ 100@#desc\n\
101 *\n\ 101 *\n\
102@#list_desc_param\ 102@#list_desc_param\
103 *\n\ 103 *\n\
104 */\n\ 104 */\n\
105#define @#eoprefix_@#func(@#list_param) @#OBJCLASS_ID(@#OBJCLASS_SUB_ID_@#FUNC)@#list_typecheck\n\ 105#define @#eoprefix_@#func(@#list_param) @#EOPREFIX_ID(@#EOPREFIX_SUB_ID_@#FUNC)@#list_typecheck\n\
106"; 106";
107 107
108static const char 108static const char
@@ -135,6 +135,7 @@ eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function
135 void *data; 135 void *data;
136 char funcname[0xFF]; 136 char funcname[0xFF];
137 char descname[0xFF]; 137 char descname[0xFF];
138 char *tmpstr = malloc(0x1FF);
138 139
139 char *fsuffix = ""; 140 char *fsuffix = "";
140 if (ftype == GET) fsuffix = "_get"; 141 if (ftype == GET) fsuffix = "_get";
@@ -147,6 +148,9 @@ eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function
147 Eina_Strbuf *str_func = eina_strbuf_new(); 148 Eina_Strbuf *str_func = eina_strbuf_new();
148 _template_fill(str_func, tmpl_eo_funcdef, classname, funcname, EINA_TRUE); 149 _template_fill(str_func, tmpl_eo_funcdef, classname, funcname, EINA_TRUE);
149 150
151 eina_strbuf_replace_all(str_func, "@#EOPREFIX", current_eo_prefix_upper);
152 eina_strbuf_replace_all(str_func, "@#eoprefix", current_eo_prefix_lower);
153
150 Eina_Strbuf *linedesc = eina_strbuf_new(); 154 Eina_Strbuf *linedesc = eina_strbuf_new();
151 eina_strbuf_append(linedesc, funcdesc ? funcdesc : "No description supplied."); 155 eina_strbuf_append(linedesc, funcdesc ? funcdesc : "No description supplied.");
152 if (eina_strbuf_length_get(linedesc)) 156 if (eina_strbuf_length_get(linedesc))
@@ -223,6 +227,7 @@ eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function
223 eina_strbuf_replace_all(str_func, "@#list_desc_param", eina_strbuf_string_get(str_pardesc)); 227 eina_strbuf_replace_all(str_func, "@#list_desc_param", eina_strbuf_string_get(str_pardesc));
224 eina_strbuf_replace_all(str_func, "@#list_typecheck", eina_strbuf_string_get(str_typecheck)); 228 eina_strbuf_replace_all(str_func, "@#list_typecheck", eina_strbuf_string_get(str_typecheck));
225 229
230 free(tmpstr);
226 eina_strbuf_free(str_par); 231 eina_strbuf_free(str_par);
227 eina_strbuf_free(str_pardesc); 232 eina_strbuf_free(str_pardesc);
228 eina_strbuf_free(str_typecheck); 233 eina_strbuf_free(str_typecheck);
@@ -239,7 +244,7 @@ eo1_header_generate(const char *classname, Eina_Strbuf *buf)
239 const Eolian_Function_Type ftype_order[] = {CONSTRUCTOR, PROPERTY_FUNC, METHOD_FUNC}; 244 const Eolian_Function_Type ftype_order[] = {CONSTRUCTOR, PROPERTY_FUNC, METHOD_FUNC};
240 const Eina_List *l; 245 const Eina_List *l;
241 void *data; 246 void *data;
242 char tmpstr[0x1FF]; 247 char *tmpstr = malloc(0x1FF);
243 248
244 if (!eolian_class_exists(classname)) 249 if (!eolian_class_exists(classname))
245 { 250 {
@@ -248,7 +253,10 @@ eo1_header_generate(const char *classname, Eina_Strbuf *buf)
248 } 253 }
249 254
250 Eina_Strbuf * str_hdr = eina_strbuf_new(); 255 Eina_Strbuf * str_hdr = eina_strbuf_new();
251 _template_fill(str_hdr, tmpl_eo_header, classname, "", EINA_TRUE); 256 _template_fill(str_hdr, tmpl_eo_obj_header, classname, "", EINA_TRUE);
257
258 eina_strbuf_replace_all(str_hdr, "@#EOPREFIX", current_eo_prefix_upper);
259 eina_strbuf_replace_all(str_hdr, "@#eoprefix", current_eo_prefix_lower);
252 260
253 Eina_Strbuf *str_subid = eina_strbuf_new(); 261 Eina_Strbuf *str_subid = eina_strbuf_new();
254 Eina_Strbuf *str_ev = eina_strbuf_new(); 262 Eina_Strbuf *str_ev = eina_strbuf_new();
@@ -300,6 +308,7 @@ eo1_header_generate(const char *classname, Eina_Strbuf *buf)
300 _template_fill(str_subid, tmpl_eo_subid, classname, tmpstr, EINA_FALSE); 308 _template_fill(str_subid, tmpl_eo_subid, classname, tmpstr, EINA_FALSE);
301 eo1_fundef_generate(classname, (Eolian_Function)data, GET, str_hdr); 309 eo1_fundef_generate(classname, (Eolian_Function)data, GET, str_hdr);
302 } 310 }
311 eina_strbuf_replace_all(str_subid, "@#EOPREFIX", current_eo_prefix_upper);
303 } 312 }
304 313
305 eina_strbuf_replace_all(str_hdr, "@#list_subid", eina_strbuf_string_get(str_subid)); 314 eina_strbuf_replace_all(str_hdr, "@#list_subid", eina_strbuf_string_get(str_subid));
@@ -307,6 +316,7 @@ eo1_header_generate(const char *classname, Eina_Strbuf *buf)
307 316
308 eina_strbuf_append(buf, eina_strbuf_string_get(str_hdr)); 317 eina_strbuf_append(buf, eina_strbuf_string_get(str_hdr));
309 318
319 free(tmpstr);
310 eina_strbuf_free(str_subid); 320 eina_strbuf_free(str_subid);
311 eina_strbuf_free(str_ev); 321 eina_strbuf_free(str_ev);
312 eina_strbuf_free(tmpbuf); 322 eina_strbuf_free(tmpbuf);
@@ -442,7 +452,19 @@ eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Fun
442 eina_strbuf_replace_all(fbody, "@#list_vars", eina_strbuf_string_get(va_args)); 452 eina_strbuf_replace_all(fbody, "@#list_vars", eina_strbuf_string_get(va_args));
443 eina_strbuf_replace_all(fbody, "@#full_params", eina_strbuf_string_get(full_params)); 453 eina_strbuf_replace_all(fbody, "@#full_params", eina_strbuf_string_get(full_params));
444 eina_strbuf_replace_all(fbody, "@#list_params", eina_strbuf_string_get(params)); 454 eina_strbuf_replace_all(fbody, "@#list_params", eina_strbuf_string_get(params));
445 eina_strbuf_replace_all(fbody, "@#Datatype", classname); 455 const char *data_type = eolian_class_data_type_get(classname);
456 if (data_type && !strcmp(data_type, "null"))
457 eina_strbuf_replace_all(fbody, "@#Datatype_Data", "void *");
458 else
459 {
460 if (data_type) eina_strbuf_replace_all(fbody, "@#Datatype_Data", data_type);
461 else eina_strbuf_replace_all(fbody, "@#Datatype", classname);
462 }
463
464 if (!data_type || !strcmp(data_type, "null"))
465 eina_strbuf_replace_all(fbody, "@#Datatype", classname);
466 else
467 eina_strbuf_replace_all(fbody, "@#Datatype_Data", data_type);
446 eina_strbuf_append(buf, eina_strbuf_string_get(fbody)); 468 eina_strbuf_append(buf, eina_strbuf_string_get(fbody));
447 469
448 eina_strbuf_free(va_args); 470 eina_strbuf_free(va_args);
@@ -456,6 +478,7 @@ Eina_Bool
456eo1_eo_func_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf) 478eo1_eo_func_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf)
457{ 479{
458 _template_fill(buf, tmpl_eo_func_desc, classname, funcname, EINA_TRUE); 480 _template_fill(buf, tmpl_eo_func_desc, classname, funcname, EINA_TRUE);
481 eina_strbuf_replace_all(buf, "@#EOPREFIX", current_eo_prefix_upper);
459 return EINA_TRUE; 482 return EINA_TRUE;
460} 483}
461 484
@@ -463,6 +486,8 @@ Eina_Bool
463eo1_eo_op_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf) 486eo1_eo_op_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf)
464{ 487{
465 _template_fill(buf, tmpl_eo_op_desc, classname, funcname, EINA_TRUE); 488 _template_fill(buf, tmpl_eo_op_desc, classname, funcname, EINA_TRUE);
489 eina_strbuf_replace_all(buf, "@#EOPREFIX", current_eo_prefix_upper);
490
466 return EINA_TRUE; 491 return EINA_TRUE;
467} 492}
468 493
@@ -476,6 +501,7 @@ eo1_source_beginning_generate(const char *classname, Eina_Strbuf *buf)
476 Eina_Strbuf *str_ev = eina_strbuf_new(); 501 Eina_Strbuf *str_ev = eina_strbuf_new();
477 502
478 _template_fill(str_begin, tmpl_eo_src_begin, classname, "", EINA_TRUE); 503 _template_fill(str_begin, tmpl_eo_src_begin, classname, "", EINA_TRUE);
504 eina_strbuf_replace_all(str_begin, "@#EOPREFIX", current_eo_prefix_upper);
479 505
480 Eolian_Event event; 506 Eolian_Event event;
481 EINA_LIST_FOREACH(eolian_class_events_list_get(classname), itr, event) 507 EINA_LIST_FOREACH(eolian_class_events_list_get(classname), itr, event)
@@ -547,6 +573,8 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf)
547 _template_fill(str_end, tmpl_eo_src_end, classname, "", EINA_TRUE); 573 _template_fill(str_end, tmpl_eo_src_end, classname, "", EINA_TRUE);
548 574
549 eina_strbuf_replace_all(str_end, "@#type_class", str_classtype); 575 eina_strbuf_replace_all(str_end, "@#type_class", str_classtype);
576 eina_strbuf_replace_all(str_end, "@#EOPREFIX", current_eo_prefix_upper);
577 eina_strbuf_replace_all(str_end, "@#eoprefix", current_eo_prefix_lower);
550 578
551 if (eolian_class_dtor_enable_get(classname)) 579 if (eolian_class_dtor_enable_get(classname))
552 { 580 {
@@ -592,7 +620,9 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf)
592 eolian_implement_information_get(impl_desc, &impl_class, &funcname, &ftype); 620 eolian_implement_information_get(impl_desc, &impl_class, &funcname, &ftype);
593 621
594 eina_strbuf_reset(tmpl_impl); 622 eina_strbuf_reset(tmpl_impl);
623 _template_fill(str_func, NULL, impl_class, NULL, EINA_FALSE); /* Invoked to set the variables */
595 eina_strbuf_append(tmpl_impl, tmpl_eo_func_desc); 624 eina_strbuf_append(tmpl_impl, tmpl_eo_func_desc);
625 eina_strbuf_replace_all(tmpl_impl, "@#EOPREFIX", current_eo_prefix_upper);
596 626
597 char implname[0xFF]; 627 char implname[0xFF];
598 char *tp = implname; 628 char *tp = implname;
@@ -657,12 +687,15 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf)
657 char *desc = _source_desc_get(eolian_function_description_get(fn, "comment")); 687 char *desc = _source_desc_get(eolian_function_description_get(fn, "comment"));
658 688
659 _template_fill(tmpbuf, tmpl_eo_op_desc, classname, funcname, EINA_TRUE); 689 _template_fill(tmpbuf, tmpl_eo_op_desc, classname, funcname, EINA_TRUE);
690 eina_strbuf_replace_all(tmpbuf, "@#EOPREFIX", current_eo_prefix_upper);
691
660 eina_strbuf_replace_all(tmpbuf, "@#desc", desc); 692 eina_strbuf_replace_all(tmpbuf, "@#desc", desc);
661 free(desc); 693 free(desc);
662 694
663 eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); 695 eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf));
664 696
665 _template_fill(str_func, tmpl_eo_func_desc, classname, funcname, EINA_FALSE); 697 _template_fill(str_func, tmpl_eo_func_desc, classname, funcname, EINA_FALSE);
698 eina_strbuf_replace_all(str_func, "@#EOPREFIX", current_eo_prefix_upper);
666 eo1_bind_func_generate(classname, fn, UNRESOLVED, str_bodyf, NULL); 699 eo1_bind_func_generate(classname, fn, UNRESOLVED, str_bodyf, NULL);
667 } 700 }
668 701
@@ -744,21 +777,29 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf)
744 eina_strbuf_reset(tmpbuf); 777 eina_strbuf_reset(tmpbuf);
745 EINA_LIST_FOREACH(eolian_class_inherits_list_get(classname), itr, inherit_name) 778 EINA_LIST_FOREACH(eolian_class_inherits_list_get(classname), itr, inherit_name)
746 { 779 {
747 if (!strcmp(inherit_name, "Elm_Widget")) 780 _template_fill(tmpbuf, "@#EOPREFIX_CLASS, ", inherit_name, "", EINA_FALSE);
748 eina_strbuf_append(tmpbuf, "ELM_OBJ_WIDGET_CLASS, "); 781 eina_strbuf_replace_all(tmpbuf, "@#EOPREFIX", current_eo_prefix_upper);
749 else if (!strcmp(inherit_name, "Elm_Interface_Scrollable"))
750 eina_strbuf_append(tmpbuf, "ELM_SCROLLABLE_INTERFACE, ");
751 else
752 _template_fill(tmpbuf, "@#OBJCLASS_CLASS, ", inherit_name, "", EINA_FALSE);
753 } 782 }
754 783
755 if (eina_strbuf_length_get(tmpbuf) == 0) eina_strbuf_append(tmpbuf,"EO_BASE_CLASS, "); 784 if (eina_strbuf_length_get(tmpbuf) == 0) eina_strbuf_append(tmpbuf, "NULL, ");
756 eina_strbuf_replace_all(str_end, "@#list_inherit", eina_strbuf_string_get(tmpbuf)); 785 eina_strbuf_replace_all(str_end, "@#list_inherit", eina_strbuf_string_get(tmpbuf));
757 786
758 eina_strbuf_replace_all(str_end, "@#list_func", eina_strbuf_string_get(str_func)); 787 eina_strbuf_replace_all(str_end, "@#list_func", eina_strbuf_string_get(str_func));
759 eina_strbuf_replace_all(str_end, "@#list_op", eina_strbuf_string_get(str_op)); 788 eina_strbuf_replace_all(str_end, "@#list_op", eina_strbuf_string_get(str_op));
760 eina_strbuf_replace_all(str_end, "@#list_ctors_body", eina_strbuf_string_get(str_bodyf)); 789 eina_strbuf_replace_all(str_end, "@#list_ctors_body", eina_strbuf_string_get(str_bodyf));
761 790
791 const char *data_type = eolian_class_data_type_get(classname);
792 if (data_type && !strcmp(data_type, "null"))
793 eina_strbuf_replace_all(str_end, "@#SizeOfData", "0");
794 else
795 {
796 Eina_Strbuf *sizeofbuf = eina_strbuf_new();
797 eina_strbuf_append_printf(sizeofbuf, "sizeof(%s%s)",
798 data_type?data_type:classname,
799 data_type?"":"_Data");
800 eina_strbuf_replace_all(str_end, "@#SizeOfData", eina_strbuf_string_get(sizeofbuf));
801 eina_strbuf_free(sizeofbuf);
802 }
762 eina_strbuf_append(buf, eina_strbuf_string_get(str_end)); 803 eina_strbuf_append(buf, eina_strbuf_string_get(str_end));
763 804
764 ret = EINA_TRUE; 805 ret = EINA_TRUE;