From e5d016bb63a55b38e6a8d7f4fa953b35861174e1 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 12 Oct 2016 14:56:22 +0200 Subject: [PATCH] eolian: add an API to get the C name used to access the class --- src/lib/eolian/Eolian.h | 18 ++++++++++++++++++ src/lib/eolian/database_class_api.c | 29 +++++++++++++++++++++++++++++ src/tests/eolian/eolian_parsing.c | 5 +++++ 3 files changed, 52 insertions(+) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index 06822d4..31c5050 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -1286,11 +1286,29 @@ EAPI Eina_Bool eolian_class_dtor_enable_get(const Eolian_Class *klass); * * You have to delete the stringshare manually. * + * @see eolian_class_c_name_get + * * @ingroup Eolian */ EAPI Eina_Stringshare *eolian_class_c_get_function_name_get(const Eolian_Class *klass); /* + * @brief Get the C name of the class. + * + * @param[in] klass the class + * @return the C name + * + * The C name is the name of the macro the class is accessed through, in format + * CLASS_NAME_SUFFIX where SUFFIX is CLASS, MIXIN or INTERFACE. You're responsible + * for the stringshare afterwards. + * + * @see eolian_class_c_get_function_name_get + * + * @ingroup Eolian + */ +EAPI Eina_Stringshare *eolian_class_c_name_get(const Eolian_Class *klass); + +/* * @brief Get an alias type declaration by name. Supports namespaces. * * @param[in] name the name of the alias diff --git a/src/lib/eolian/database_class_api.c b/src/lib/eolian/database_class_api.c index 30ebc6a..244d33d 100644 --- a/src/lib/eolian/database_class_api.c +++ b/src/lib/eolian/database_class_api.c @@ -210,3 +210,32 @@ eolian_class_c_get_function_name_get(const Eolian_Class *cl) eina_strbuf_free(buf); return ret; } + +EAPI Eina_Stringshare * +eolian_class_c_name_get(const Eolian_Class *cl) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(cl, NULL); + Eina_Stringshare *ret; + Eina_Strbuf *buf = eina_strbuf_new(); + char *bufp; + eina_strbuf_append(buf, cl->full_name); + switch (cl->type) + { + case EOLIAN_CLASS_INTERFACE: + eina_strbuf_append(buf, "_INTERFACE"); + break; + case EOLIAN_CLASS_MIXIN: + eina_strbuf_append(buf, "_MIXIN"); + break; + default: + eina_strbuf_append(buf, "_CLASS"); + break; + } + eina_strbuf_replace_all(buf, ".", "_"); + bufp = eina_strbuf_string_steal(buf); + eina_str_toupper(&bufp); + ret = eina_stringshare_add(bufp); + free(bufp); + eina_strbuf_free(buf); + return ret; +} diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c index d10dcdd..fa2abee 100644 --- a/src/tests/eolian/eolian_parsing.c +++ b/src/tests/eolian/eolian_parsing.c @@ -562,6 +562,11 @@ START_TEST(eolian_simple_parsing) fail_if(strcmp(string, "class_simple_class_get")); eina_stringshare_del(string); + /* c name */ + fail_if(!(string = eolian_class_c_name_get(class))); + fail_if(strcmp(string, "CLASS_SIMPLE_CLASS")); + eina_stringshare_del(string); + /* Property */ fail_if(!(fid = eolian_class_function_get_by_name(class, "a", EOLIAN_PROPERTY))); fail_if(strcmp(eolian_function_name_get(fid), "a")); -- 2.7.4