eolian: add API to get the C class datatype

This commit is contained in:
Daniel Kolesa 2016-10-13 14:54:12 +02:00
parent e0390009bc
commit b6113a6bd9
3 changed files with 37 additions and 0 deletions

View File

@ -1308,6 +1308,24 @@ EAPI Eina_Stringshare *eolian_class_c_get_function_name_get(const Eolian_Class *
*/
EAPI Eina_Stringshare *eolian_class_c_name_get(const Eolian_Class *klass);
/*
* @brief Get the C data type of the class.
*
* @param[in] klass the class
* @return the C data type
*
* This will sanitize the data type of the class for C usage; if it's "null",
* this returns "void"; if it's actually explicitly set, it returns the sanitized
* version of the string, otherwise it returns Class_Name_Data. Keep in mind that
* this does not add an asterisk (it doesn't return a pointer type name). You're
* responsible for the stringshare afterwards.
*
* @see eolian_class_c_get_function_name_get
*
* @ingroup Eolian
*/
EAPI Eina_Stringshare *eolian_class_c_data_type_get(const Eolian_Class *klass);
/*
* @brief Get an alias type declaration by name. Supports namespaces.
*

View File

@ -239,3 +239,19 @@ eolian_class_c_name_get(const Eolian_Class *cl)
eina_strbuf_free(buf);
return ret;
}
EAPI Eina_Stringshare *
eolian_class_c_data_type_get(const Eolian_Class *cl)
{
char buf[512];
EINA_SAFETY_ON_NULL_RETURN_VAL(cl, NULL);
if (!cl->data_type)
snprintf(buf, sizeof(buf), "%s_Data", cl->full_name);
else if (!strcmp(cl->data_type, "null"))
return eina_stringshare_add("void");
else
snprintf(buf, sizeof(buf), "%s", cl->data_type);
for (char *p = strchr(buf, '.'); p; p = strchr(p, '.'))
*p = '_';
return eina_stringshare_add(buf);
}

View File

@ -556,6 +556,9 @@ START_TEST(eolian_simple_parsing)
fail_if(strcmp(eolian_class_legacy_prefix_get(class), "evas_object_simple"));
fail_if(strcmp(eolian_class_eo_prefix_get(class), "efl_canvas_object_simple"));
fail_if(strcmp(eolian_class_data_type_get(class), "Evas_Simple_Data"));
Eina_Stringshare *dt = eolian_class_c_data_type_get(class);
fail_if(strcmp(dt, "Evas_Simple_Data"));
eina_stringshare_del(dt);
/* c get func */
fail_if(!(string = eolian_class_c_get_function_name_get(class)));