From 43e23492033614096dda88aedc482d0d7c2d0546 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 20 Jun 2014 16:53:51 +0100 Subject: eolian/generator: public api func name deduplication, spank tasn if it breaks --- src/bin/eolian/common_funcs.c | 42 +++++++++++++++++++++++++++++++++++++++--- src/bin/eolian/common_funcs.h | 2 ++ src/bin/eolian/eo_generator.c | 15 +++++++++------ 3 files changed, 50 insertions(+), 9 deletions(-) (limited to 'src/bin/eolian') diff --git a/src/bin/eolian/common_funcs.c b/src/bin/eolian/common_funcs.c index de58280928..5dd20f2805 100644 --- a/src/bin/eolian/common_funcs.c +++ b/src/bin/eolian/common_funcs.c @@ -50,7 +50,7 @@ _class_env_create(const Eolian_Class class, const char *over_classname, _eolian_ void _class_func_env_create(const Eolian_Class class, const char *funcname, Eolian_Function_Type ftype, _eolian_class_func_vars *env) { - char *p; + char *p, *ret; const char *suffix = ""; const char *legacy = NULL; Eolian_Function funcid = eolian_class_function_find_by_name(class, funcname, ftype); @@ -72,11 +72,15 @@ _class_func_env_create(const Eolian_Class class, const char *funcname, Eolian_Fu p = strncpy(env->upper_func, funcname, PATH_MAX - 1); eina_str_toupper(&p); - sprintf(p = env->upper_eo_func, "%s_%s%s", tmp_env.upper_eo_prefix, funcname, suffix); + ret = _func_name_dedup(tmp_env.upper_eo_prefix, funcname); + sprintf(p = env->upper_eo_func, "%s%s", ret, suffix); eina_str_toupper(&p); + free(ret); - sprintf(p = env->lower_eo_func, "%s_%s%s", tmp_env.lower_eo_prefix, funcname, suffix); + ret = _func_name_dedup(tmp_env.lower_eo_prefix, funcname); + sprintf(p = env->lower_eo_func, "%s%s", ret, suffix); eina_str_tolower(&p); + free(ret); env->legacy_func[0] = '\0'; if (legacy && !strcmp(legacy, "null")) goto end; @@ -161,3 +165,35 @@ _source_desc_get(const char *str) return ret; } +char * +_func_name_dedup(const char *classn, const char *funcn) +{ + const char *last_p = strrchr(classn, '_'); + const char *func_p = strchr(funcn, '_'); + Eina_Strbuf *buf = eina_strbuf_new(); + int len; + char *ret; + + if (!last_p) last_p = classn; + else last_p++; + if (!func_p) len = strlen(funcn); + else len = func_p - funcn; + + if ((int)strlen(last_p) != len || strncmp(last_p, funcn, len)) + { + eina_strbuf_append(buf, classn); + eina_strbuf_append_char(buf, '_'); + eina_strbuf_append(buf, funcn); + ret = eina_strbuf_string_steal(buf); + eina_strbuf_free(buf); + return ret; + } + + if (last_p != classn) + eina_strbuf_append_n(buf, classn, last_p - classn); /* includes _ */ + + eina_strbuf_append(buf, funcn); + ret = eina_strbuf_string_steal(buf); + eina_strbuf_free(buf); + return ret; +} diff --git a/src/bin/eolian/common_funcs.h b/src/bin/eolian/common_funcs.h index ff98d7d508..ca510efb1f 100644 --- a/src/bin/eolian/common_funcs.h +++ b/src/bin/eolian/common_funcs.h @@ -66,4 +66,6 @@ void _class_env_create(const Eolian_Class class, const char *over_classname, _eo void _class_func_env_create(const Eolian_Class class, const char *funcname, Eolian_Function_Type ftype EINA_UNUSED, _eolian_class_func_vars *env); +char *_func_name_dedup(const char *classn, const char *funcn); + #endif diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c index 30e11bc3c1..1eb4fbd50f 100644 --- a/src/bin/eolian/eo_generator.c +++ b/src/bin/eolian/eo_generator.c @@ -598,6 +598,7 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf) Eolian_Function fnid = NULL; const char *funcname = NULL; char *tp = implname; + char *ret; if (eolian_implement_information_get(impl_desc, &impl_class, &fnid, &ftype)) { @@ -615,29 +616,31 @@ eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf) goto end; } + ret = _func_name_dedup(impl_env.lower_eo_prefix, funcname); switch (ftype) { case EOLIAN_PROP_SET: case EOLIAN_PROP_GET: case EOLIAN_PROPERTY: if (ftype != EOLIAN_PROP_GET) { - eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_%s_set, _%s_%s_set),", - impl_env.lower_eo_prefix, funcname, implname, funcname); + eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_set, _%s_%s_set),", + ret, implname, funcname); eo_bind_func_generate(class, fnid, EOLIAN_PROP_SET, str_bodyf, &impl_env); } if (ftype != EOLIAN_PROP_SET) { - eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_%s_get, _%s_%s_get),", - impl_env.lower_eo_prefix, funcname, implname, funcname); + eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_get, _%s_%s_get),", + ret, implname, funcname); eo_bind_func_generate(class, fnid, EOLIAN_PROP_GET, str_bodyf, &impl_env); } break; default: - eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_%s, _%s_%s),", - impl_env.lower_eo_prefix, funcname, implname, funcname); + eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s, _%s_%s),", + ret, implname, funcname); eo_bind_func_generate(class, fnid, ftype, str_bodyf, &impl_env); break; } + free(ret); } //Constructors -- cgit v1.2.1