eolian: add an API to get the C name used to access the class

This commit is contained in:
Daniel Kolesa 2016-10-12 14:56:22 +02:00
parent e6fa6ba945
commit e5d016bb63
3 changed files with 52 additions and 0 deletions

View File

@ -1286,10 +1286,28 @@ 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.
*

View File

@ -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;
}

View File

@ -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"));