diff --git a/src/bin/eolian/common_funcs.c b/src/bin/eolian/common_funcs.c index b3e9703bd8..311228a871 100644 --- a/src/bin/eolian/common_funcs.c +++ b/src/bin/eolian/common_funcs.c @@ -5,94 +5,55 @@ int _eolian_gen_log_dom = -1; const char *current_classname = NULL; -static void -_class_names_fill(const char *classname) +void +_class_func_names_fill(const char *classname, const char *funcname) { char *p; const char *eo_prefix = NULL; - if (classname == current_classname) return; - current_classname = classname; - if (eolian_class_exists(classname)) - eo_prefix = eolian_class_eo_prefix_get(classname); - if (!eo_prefix) eo_prefix = classname; - strncpy(current_eo_prefix_lower, eo_prefix, sizeof(current_eo_prefix_lower) - 1); - p = current_eo_prefix_lower; - eina_str_tolower(&p); - strncpy(current_eo_prefix_upper, eo_prefix, sizeof(current_eo_prefix_lower) - 1); - p = current_eo_prefix_upper; - eina_str_toupper(&p); + if (classname != current_classname) + { + current_classname = classname; + + /* class/CLASS*/ + strncpy(capclass, classname, sizeof(capclass) - 1); + p = capclass; + eina_str_toupper(&p); + strncpy(lowclass, classname, sizeof(lowclass) - 1); + p = lowclass; + eina_str_tolower(&p); + + /* eo_prefix */ + if (eolian_class_exists(classname)) + eo_prefix = eolian_class_eo_prefix_get(classname); + if (!eo_prefix) eo_prefix = classname; + strncpy(current_eo_prefix_lower, eo_prefix, sizeof(current_eo_prefix_lower) - 1); + p = current_eo_prefix_lower; + eina_str_tolower(&p); + strncpy(current_eo_prefix_upper, eo_prefix, sizeof(current_eo_prefix_lower) - 1); + p = current_eo_prefix_upper; + eina_str_toupper(&p); + } + if (funcname) + { + strncpy(capfunc, funcname, sizeof(capfunc) - 1); + p = capfunc; + eina_str_toupper(&p); + } } void _template_fill(Eina_Strbuf *buf, const char* templ, const char* classname, const char *funcname, Eina_Bool reset) { - static char capobjclass[0xFF]; - static char lowobjclass[0xFF]; - static char capclass[0xFF]; - static char lowclass[0xFF]; - static char normclass[0xFF]; - static char capfunc[0xFF]; - - char *p; - - _class_names_fill(classname); + _class_func_names_fill(classname, funcname); if (buf) { if (reset) eina_strbuf_reset(buf); if (templ) eina_strbuf_append(buf, templ); - } - - if (strcmp(classname, normclass)) - { - //Fill cache - strncpy(normclass, classname, sizeof(normclass) - 1); - - strncpy(capclass, classname, sizeof(capclass) - 1); - p = capclass; - eina_str_toupper(&p); - - strncpy(lowclass, classname, sizeof(lowclass) - 1); - p = lowclass; - eina_str_tolower(&p); - - Eina_Strbuf *classobj = eina_strbuf_new(); - eina_strbuf_append(classobj, classname); - - // More to exclusion list - if (strcmp(classname, "Eo_Base") && strcmp(classname, "Elm_Widget")) - eina_strbuf_replace(classobj, "_", "_obj_", 1); - - if (!strcmp(classname, "Evas_Object")) - { - eina_strbuf_reset(classobj); - eina_strbuf_append(classobj, "Evas_Obj"); - } - - strncpy(capobjclass, eina_strbuf_string_get(classobj), - sizeof(capobjclass) - 1); - p = capobjclass; - eina_str_toupper(&p); - - strncpy(lowobjclass, eina_strbuf_string_get(classobj), - sizeof(lowobjclass) - 1); - p = lowobjclass; - eina_str_tolower(&p); - - eina_strbuf_free(classobj); - } - - if (funcname) strncpy(capfunc, funcname, sizeof(capfunc) - 1); - p = capfunc; eina_str_toupper(&p); - - if (buf) - { if (funcname) eina_strbuf_replace_all(buf, "@#func", funcname); eina_strbuf_replace_all(buf, "@#FUNC", capfunc); eina_strbuf_replace_all(buf, "@#Class", classname); eina_strbuf_replace_all(buf, "@#class", lowclass); eina_strbuf_replace_all(buf, "@#CLASS", capclass); - eina_strbuf_replace_all(buf, "@#OBJCLASS", capobjclass); - eina_strbuf_replace_all(buf, "@#objclass", lowobjclass); } } diff --git a/src/bin/eolian/common_funcs.h b/src/bin/eolian/common_funcs.h index 922cb2ab0b..bbe88c3c37 100644 --- a/src/bin/eolian/common_funcs.h +++ b/src/bin/eolian/common_funcs.h @@ -38,7 +38,16 @@ char *_startline(char *str, char *pos); char *_source_desc_get(const char *str); +void _class_func_names_fill(const char *classname, const char *funcname); + char current_eo_prefix_lower[256]; char current_eo_prefix_upper[256]; + +char capobjclass[0xFF]; +char lowobjclass[0xFF]; +char capclass[0xFF]; +char lowclass[0xFF]; +char normclass[0xFF]; +char capfunc[0xFF]; #endif diff --git a/src/bin/eolian/eo1_generator.c b/src/bin/eolian/eo1_generator.c index b6f61ef63f..d294504038 100644 --- a/src/bin/eolian/eo1_generator.c +++ b/src/bin/eolian/eo1_generator.c @@ -16,9 +16,7 @@ _gen_@#class_class_destructor(Eo_Class *klass)\n\ "; static const char -tmpl_eo_src_end[] = "\ -@#list_ctors_body\ -\n\ +tmpl_eo1_class_ctor[] = "\ static void\n\ _gen_@#class_class_constructor(Eo_Class *klass)\n\ {\n\ @@ -26,24 +24,35 @@ _gen_@#class_class_constructor(Eo_Class *klass)\n\ EO_OP_FUNC_SENTINEL\n\ };\n\ eo_class_funcs_set(klass, func_desc);\n\ -@#ctor_func\ -}\n\ -\n\ -@#dtor_func\ +@#user_ctor_func\ +}\n\n"; + +static const char +tmpl_eo1_ops_desc[] = "\ static const Eo_Op_Description _@#class_op_desc[] = {@#list_op\n\ EO_OP_DESCRIPTION_SENTINEL\n\ -};\n\ -\n\ +};\n\n"; + +static const char +tmpl_events_desc[] = "\ static const Eo_Event_Description *_@#class_event_desc[] = {@#list_evdesc\n\ NULL\n\ -};\n\ +};\n\n"; + +static const char +tmpl_eo_src[] = "\ +@#functions_body\ \n\ +@#ctor_func\ +@#dtor_func\ +@#ops_desc\ +@#events_desc\ static const Eo_Class_Description _@#class_class_desc = {\n\ EO_VERSION,\n\ \"@#Class\",\n\ @#type_class,\n\ - EO_CLASS_DESCRIPTION_OPS(&@#EOPREFIX_BASE_ID, _@#class_op_desc, @#EOPREFIX_SUB_ID_LAST),\n\ - _@#class_event_desc,\n\ + @#eo_class_desc_ops,\n\ + @#Events_Desc,\n\ @#SizeOfData,\n\ _gen_@#class_class_constructor,\n\ @#dtor_name\n\ @@ -120,14 +129,7 @@ _eo_obj_@#class_@#func(Eo *obj, void *_pd, va_list *list@#list_unused)\n\ }\n\ "; -Eina_Bool -eo1_enum_append(const char *classname, const char *funcname, Eina_Strbuf *str) -{ - _template_fill(str, tmpl_eo_subid_apnd, classname, funcname, EINA_FALSE); - return EINA_TRUE; -} - -Eina_Bool +static Eina_Bool eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function_Type ftype, Eina_Strbuf *functext) { const char *str_dir[] = {"in", "out", "inout"}; @@ -357,7 +359,7 @@ _varg_upgr(const char *stype) return stype; } -Eina_Bool +static Eina_Bool eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf, const char *impl_name) { const char *suffix = ""; @@ -499,24 +501,34 @@ eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Fun return EINA_TRUE; } -Eina_Bool -eo1_eo_func_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf) +static Eina_Bool +eo1_eo_func_desc_generate(const char *class_name, const char *impl_name, const char *func_name, Eina_Strbuf *buf) { - _template_fill(buf, tmpl_eo_func_desc, classname, funcname, EINA_TRUE); - eina_strbuf_replace_all(buf, "@#EOPREFIX", current_eo_prefix_upper); + if (impl_name) + _class_func_names_fill(impl_name, func_name); + else + _class_func_names_fill(class_name, func_name); + eina_strbuf_reset(buf); + eina_strbuf_append_printf(buf, + "\n EO_OP_FUNC(%s_ID(%s_SUB_ID_%s), _eo_obj_%s%s%s_%s),", + current_eo_prefix_upper, current_eo_prefix_upper, capfunc, + lowclass, impl_name?"_":"", impl_name?impl_name:"", + func_name); return EINA_TRUE; } -Eina_Bool -eo1_eo_op_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf) +static Eina_Bool +eo1_eo_op_desc_generate(const char *classname, const char *funcname, + const char *desc, Eina_Strbuf *buf) { _template_fill(buf, tmpl_eo_op_desc, classname, funcname, EINA_TRUE); eina_strbuf_replace_all(buf, "@#EOPREFIX", current_eo_prefix_upper); + eina_strbuf_replace_all(buf, "@#desc", desc); return EINA_TRUE; } -Eina_Bool +static Eina_Bool eo1_source_beginning_generate(const char *classname, Eina_Strbuf *buf) { const Eina_List *itr; @@ -559,7 +571,7 @@ eo1_source_beginning_generate(const char *classname, Eina_Strbuf *buf) return EINA_TRUE; } -Eina_Bool +static Eina_Bool eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) { Eina_Bool ret = EINA_FALSE; @@ -599,20 +611,19 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) Eina_Strbuf *str_ev = eina_strbuf_new(); Eina_Strbuf *tmpl_impl = eina_strbuf_new(); - _template_fill(str_end, tmpl_eo_src_end, classname, "", EINA_TRUE); + _template_fill(str_end, tmpl_eo_src, classname, NULL, EINA_TRUE); - if (!eolian_class_functions_list_get(classname, CONSTRUCTOR) && - !eolian_class_functions_list_get(classname, DESTRUCTOR) && - !eolian_class_functions_list_get(classname, PROPERTY_FUNC) && - !eolian_class_functions_list_get(classname, METHOD_FUNC)) - { - eina_strbuf_replace_all(str_end, "&@#EOPREFIX_BASE_ID", "NULL"); - eina_strbuf_replace_all(str_end, "@#EOPREFIX_SUB_ID_LAST", "0"); - } eina_strbuf_replace_all(str_end, "@#type_class", str_classtype); eina_strbuf_replace_all(str_end, "@#EOPREFIX", current_eo_prefix_upper); eina_strbuf_replace_all(str_end, "@#eoprefix", current_eo_prefix_lower); + _template_fill(tmpbuf, tmpl_eo1_class_ctor, classname, "", EINA_TRUE); + eina_strbuf_replace_all(str_end, "@#ctor_func", eina_strbuf_string_get(tmpbuf)); + eina_strbuf_reset(tmpbuf); + if (eolian_class_ctor_enable_get(classname)) + _template_fill(tmpbuf, " _@#class_class_constructor(klass);\n", classname, "", EINA_TRUE); + eina_strbuf_replace_all(str_end, "@#user_ctor_func", eina_strbuf_string_get(tmpbuf)); + if (eolian_class_dtor_enable_get(classname)) { _template_fill(tmpbuf, tmpl_dtor, classname, "", EINA_TRUE); @@ -627,9 +638,6 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) } eina_strbuf_reset(tmpbuf); - if (eolian_class_ctor_enable_get(classname)) - _template_fill(tmpbuf, " _@#class_class_constructor(klass);\n", classname, "", EINA_TRUE); - eina_strbuf_replace_all(str_end, "@#ctor_func", eina_strbuf_string_get(tmpbuf)); // default constructor Eolian_Function ctor_fn = eolian_class_default_constructor_get(classname); @@ -722,17 +730,13 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) { const char *funcname = eolian_function_name_get(fn); char *desc = _source_desc_get(eolian_function_description_get(fn, "comment")); - - _template_fill(tmpbuf, tmpl_eo_op_desc, classname, funcname, EINA_TRUE); - eina_strbuf_replace_all(tmpbuf, "@#EOPREFIX", current_eo_prefix_upper); - - eina_strbuf_replace_all(tmpbuf, "@#desc", desc); + eo1_eo_op_desc_generate(classname, funcname, desc, tmpbuf); + eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); free(desc); - eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); + eo1_eo_func_desc_generate(classname, NULL, funcname, tmpbuf); + eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf)); - _template_fill(str_func, tmpl_eo_func_desc, classname, funcname, EINA_FALSE); - eina_strbuf_replace_all(str_func, "@#EOPREFIX", current_eo_prefix_upper); eo1_bind_func_generate(classname, fn, UNRESOLVED, str_bodyf, NULL); } @@ -751,13 +755,12 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) char *desc = _source_desc_get(eolian_function_description_get(fn, "comment_set")); sprintf(tmpstr, "%s_set", funcname); - eo1_eo_op_desc_generate(classname, tmpstr, tmpbuf); - eina_strbuf_replace_all(tmpbuf, "@#desc", desc); + eo1_eo_op_desc_generate(classname, tmpstr, desc, tmpbuf); eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); free(desc); if (!eolian_function_is_virtual_pure(fn)) - eo1_eo_func_desc_generate(classname, tmpstr, tmpbuf); + eo1_eo_func_desc_generate(classname, NULL, tmpstr, tmpbuf); else eina_strbuf_reset(tmpbuf); eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf)); @@ -767,13 +770,12 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) char *desc = _source_desc_get(eolian_function_description_get(fn, "comment_get")); sprintf(tmpstr, "%s_get", funcname); - eo1_eo_op_desc_generate(classname, tmpstr, tmpbuf); - eina_strbuf_replace_all(tmpbuf, "@#desc", desc); + eo1_eo_op_desc_generate(classname, tmpstr, desc, tmpbuf); free(desc); eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); if (!eolian_function_is_virtual_pure(fn)) - eo1_eo_func_desc_generate(classname, tmpstr, tmpbuf); + eo1_eo_func_desc_generate(classname, NULL, tmpstr, tmpbuf); else eina_strbuf_reset(tmpbuf); eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf)); @@ -784,15 +786,14 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) EINA_LIST_FOREACH(eolian_class_functions_list_get(classname, METHOD_FUNC), itr, fn) { const char *funcname = eolian_function_name_get(fn); - char *desc = _source_desc_get(eolian_function_description_get(fn, "comment")); - eo1_eo_op_desc_generate(classname, funcname, tmpbuf); - eina_strbuf_replace_all(tmpbuf, "@#desc", desc); + char *desc = _source_desc_get(eolian_function_description_get(fn, "comment")); + eo1_eo_op_desc_generate(classname, funcname, desc, tmpbuf); free(desc); eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); if (!eolian_function_is_virtual_pure(fn)) - eo1_eo_func_desc_generate(classname, funcname, tmpbuf); + eo1_eo_func_desc_generate(classname, NULL, funcname, tmpbuf); else eina_strbuf_reset(tmpbuf); eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf)); @@ -808,7 +809,23 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) eina_strbuf_replace_all(tmpbuf, ",", "_"); eina_strbuf_append_printf(str_ev, "\n %s,", eina_strbuf_string_get(tmpbuf)); } - eina_strbuf_replace_all(str_end, "@#list_evdesc", eina_strbuf_string_get(str_ev)); + + eina_strbuf_reset(tmpbuf); + if (eina_strbuf_length_get(str_ev)) + { + Eina_Strbuf *events_desc = eina_strbuf_new(); + _template_fill(events_desc, tmpl_events_desc, classname, "", EINA_TRUE); + eina_strbuf_replace_all(events_desc, "@#list_evdesc", eina_strbuf_string_get(str_ev)); + eina_strbuf_replace_all(str_end, "@#events_desc", eina_strbuf_string_get(events_desc)); + eina_strbuf_free(events_desc); + eina_strbuf_append_printf(tmpbuf, "_%s_event_desc", lowclass); + } + else + { + eina_strbuf_append_printf(tmpbuf, "NULL"); + eina_strbuf_replace_all(str_end, "@#events_desc", ""); + } + eina_strbuf_replace_all(str_end, "@#Events_Desc", eina_strbuf_string_get(tmpbuf)); const char *inherit_name; eina_strbuf_reset(tmpbuf); @@ -824,8 +841,28 @@ eo1_source_end_generate(const char *classname, Eina_Strbuf *buf) eina_strbuf_replace_all(str_end, "@#list_inherit", eina_strbuf_string_get(tmpbuf)); eina_strbuf_replace_all(str_end, "@#list_func", eina_strbuf_string_get(str_func)); - eina_strbuf_replace_all(str_end, "@#list_op", eina_strbuf_string_get(str_op)); - eina_strbuf_replace_all(str_end, "@#list_ctors_body", eina_strbuf_string_get(str_bodyf)); + + eina_strbuf_reset(tmpbuf); + if (eina_strbuf_length_get(str_op)) + { + Eina_Strbuf *ops_desc = eina_strbuf_new(); + _template_fill(ops_desc, tmpl_eo1_ops_desc, classname, "", EINA_TRUE); + eina_strbuf_replace_all(ops_desc, "@#list_op", eina_strbuf_string_get(str_op)); + eina_strbuf_replace_all(str_end, "@#ops_desc", eina_strbuf_string_get(ops_desc)); + eina_strbuf_free(ops_desc); + _template_fill(tmpbuf, + "EO_CLASS_DESCRIPTION_OPS(&@#EOPREFIX_BASE_ID, _@#class_op_desc, @#EOPREFIX_SUB_ID_LAST)", + classname, NULL, EINA_TRUE); + eina_strbuf_replace_all(tmpbuf, "@#EOPREFIX", current_eo_prefix_upper); + } + else + { + eina_strbuf_replace_all(str_end, "@#ops_desc", ""); + eina_strbuf_append_printf(tmpbuf, "EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0)"); + } + + eina_strbuf_replace_all(str_end, "@#functions_body", eina_strbuf_string_get(str_bodyf)); + eina_strbuf_replace_all(str_end, "@#eo_class_desc_ops", eina_strbuf_string_get(tmpbuf)); const char *data_type = eolian_class_data_type_get(classname); if (data_type && !strcmp(data_type, "null")) diff --git a/src/bin/eolian/eo1_generator.h b/src/bin/eolian/eo1_generator.h index 8fba677c25..a3965aaa3c 100644 --- a/src/bin/eolian/eo1_generator.h +++ b/src/bin/eolian/eo1_generator.h @@ -18,53 +18,6 @@ Eina_Bool eo_source_generate(const char *classname, int eo_version, Eina_Strbuf *buf); -/* - * @brief Generate beginning of Eo1 source code for Eo class - * - * This function generates the base id definition and the list of events. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -eo1_source_beginning_generate(const char *classname, Eina_Strbuf *buf); - -/* - * @brief Generate end of Eo1 source code for Eo class - * - * This function generates the constructors, the class constructor, the function - * descriptions and the class description. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -eo1_source_end_generate(const char *classname, Eina_Strbuf *buf); - -/* - * @brief Generate the source code for a specific Eo function. - * - * This function generates for a given function id the corresponding - * Eo function. - * - * @param[in] classname class name - * @param[in] funcid Function Id - * @param[in] ftype type of the function (SET/GET/METHOD...) - * @param[in] impl_name name to append in case of implement. - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf, const char *impl_name); - /* * @brief Generate the header code for a specific Eo class. * @@ -78,79 +31,5 @@ eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Fun */ Eina_Bool eo1_header_generate(const char *classname, Eina_Strbuf *buf); -/* - * @brief Append the header code for a specific Eo class. - * - * This function generates header code by appending it into an existing class. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool eo1_header_append(const char *classname, Eina_Strbuf *buf); - -/* - * @brief Fill the given buffer with the Eo enum of a given function. - * - * @param[in] classname class name - * @param[in] funcname function name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool eo1_enum_append(const char *classname, const char *funcname, Eina_Strbuf *buf); - -/* - * @brief Generate the function definition (header) for a specific Eo function. - * - * This function generates for a given function the corresponding - * Eo function definition. - * - * @param[in] classname class name - * @param[in] funcid Function Id - * @param[in] ftype type of the function (SET/GET/METHOD...) - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function_Type ftype, Eina_Strbuf *buf); - -/* - * @brief Generate the function description for a specific Eo function. - * - * This function generates for a given function the corresponding - * Eo function description. - * - * @param[in] classname class name - * @param[in] funcname function name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -eo1_eo_func_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf); - -/* - * @brief Generate the Eo op description for a specific Eo function. - * - * This function generates for a given function the corresponding - * Eo function definition. - * - * @param[in] classname class name - * @param[in] funcname function name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -eo1_eo_op_desc_generate(const char *classname, const char *funcname, Eina_Strbuf *buf); - #endif diff --git a/src/bin/eolian/legacy_generator.c b/src/bin/eolian/legacy_generator.c index f1d209cb90..00464ed5bd 100644 --- a/src/bin/eolian/legacy_generator.c +++ b/src/bin/eolian/legacy_generator.c @@ -4,7 +4,6 @@ #include "Eolian.h" #include "legacy_generator.h" -#include "eo1_generator.h" #include "common_funcs.h" static const char