Eolian: support non null parameters.

The generation is only needed in legacy headers.
This commit is contained in:
Daniel Zaoui 2014-02-23 11:19:14 +02:00
parent 8cc58ed7cb
commit 87f661e08e
7 changed files with 264 additions and 145 deletions

View File

@ -95,6 +95,8 @@ _eapi_decl_func_generate(const char *classname, Eolian_Function funcid, Eolian_F
const Eina_List *l;
void *data;
Eina_Strbuf *flags = NULL;
int leg_param_idx = 1; /* Index of the parameter inside the legacy function. It begins from 1 since obj is the first. */
EINA_LIST_FOREACH(eolian_property_keys_list_get(funcid), l, data)
{
@ -102,10 +104,21 @@ _eapi_decl_func_generate(const char *classname, Eolian_Function funcid, Eolian_F
const char *pdesc;
const char *ptype;
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, &pdesc);
leg_param_idx++;
eina_strbuf_append_printf(fparam, ", %s%s %s",
eolian_parameter_get_const_attribute_get(data)?"const":"",
ptype, pname);
eina_strbuf_append_printf(descparam, " * @param %s\n", pname);
if (eolian_parameter_is_nonull((Eolian_Function_Parameter)data))
{
if (!flags)
{
flags = eina_strbuf_new();
eina_strbuf_append_printf(flags, " EINA_ARG_NONNULL(%d", leg_param_idx);
}
else
eina_strbuf_append_printf(flags, ", %d", leg_param_idx);
}
}
if (!var_as_ret)
{
@ -116,20 +129,42 @@ _eapi_decl_func_generate(const char *classname, Eolian_Function funcid, Eolian_F
const char *ptype;
Eolian_Parameter_Dir pdir;
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, &pdesc);
leg_param_idx++;
const char *ptrstr = (umpr) ? umpr : ( (pdir == EOLIAN_IN_PARAM) ? "" : "*" );
eina_strbuf_append_printf(fparam, ", %s%s%s %s",
eolian_parameter_get_const_attribute_get(data)?"const":"",
ptype, ptrstr, pname);
eina_strbuf_append_printf(descparam, " * @param %s\n", pname);
if (eolian_parameter_is_nonull((Eolian_Function_Parameter)data))
{
if (!flags)
{
flags = eina_strbuf_new();
eina_strbuf_append_printf(flags, " EINA_ARG_NONNULL(%d", leg_param_idx);
}
else
eina_strbuf_append_printf(flags, ", %d", leg_param_idx);
}
}
}
if (flags) eina_strbuf_append_printf(flags, ")");
eina_strbuf_replace_all(fbody, "@#params", eina_strbuf_string_get(fparam));
eina_strbuf_replace_all(fbody, "@#list_desc_param", eina_strbuf_string_get(descparam));
eina_strbuf_replace_all(fbody, "@#type_return", (rettype) ? rettype : "void");
eina_strbuf_replace_all(fbody, "@#is_const", (ftype == GET || eolian_function_object_is_const(funcid)) ? "const " : "");
if (eolian_function_return_is_warn_unused(funcid, ftype))
{
Eina_Bool no_nonull = !flags;
if (no_nonull) flags = eina_strbuf_new();
eina_strbuf_prepend_printf(flags, " EINA_WARN_UNUSED_RESULT%s", !no_nonull?", ":"");
}
if (flags)
eina_strbuf_replace_all(fbody, "@#flags", eina_strbuf_string_get(flags));
eina_strbuf_replace_all(fbody, "@#flags", (eolian_function_return_is_warn_unused(funcid, ftype)) ? " EINA_WARN_UNUSED_RESULT" : "");
eina_strbuf_append(buf, eina_strbuf_string_get(fbody));
eina_strbuf_free(flags);
eina_strbuf_free(fbody);
eina_strbuf_free(fparam);
eina_strbuf_free(descparam);

View File

@ -383,6 +383,16 @@ EAPI Eina_Stringshare *eolian_parameter_name_get(const Eolian_Function_Parameter
*/
EAPI Eina_Bool eolian_parameter_get_const_attribute_get(Eolian_Function_Parameter param_desc);
/*
* @brief Indicates if a parameter cannot be NULL.
*
* @param[in] param_desc parameter handle
* @return EINA_TRUE if cannot be NULL, EINA_FALSE otherwise
*
* @ingroup Eolian
*/
EAPI Eina_Bool eolian_parameter_is_nonull(Eolian_Function_Parameter param_desc);
/*
* @brief Get the return type of a function.
*

View File

@ -29,6 +29,7 @@ typedef struct _eo_param_def
const char *type;
const char *name;
const char *comment;
Eina_Bool nonull:1;
} Eo_Param_Def;
/* ACCESSOR */

File diff suppressed because it is too large Load Diff

View File

@ -178,8 +178,23 @@ _eo_tokenizer_param_get(Eo_Tokenizer *toknz, char *p)
Eo_Param_Def *param = calloc(1, sizeof(Eo_Param_Def));
if (param == NULL) ABORT(toknz, "calloc Eo_Param_Def failure");
s = p - 1; /* Don't look at ';' */
/* Remove any space between the param name and ';'
/* If @nonull is found, we set s as the end of the string and
update the boolean. Otherwise we set the end as the character
before the ';'.
We need to modify temporarily p because we want strstr to stop
at the ';' maximum. p represents the end of the string to search
inside.
*/
*p = '\0';
s = strstr(toknz->saved.tok, "@nonull");
*p = ';';
if (s)
{
param->nonull = EINA_TRUE;
p = s;
}
s = p - 1; /* Don't look at the current character (';' or '@') */
/* Remove any space between the param name and ';'/@nonull
* This loop fixes the case where "char *name ;" becomes the type of the param.
*/
while (*s == ' ') s--;
@ -449,7 +464,7 @@ _eo_tokenizer_implement_get(Eo_Tokenizer *toknz, char *p)
}
param_comment = ws* eo_comment %end_param_comment;
param = ('@'|alpha+) >save_fpc (alnum_u | '*' | ws )+ %end_param end_statement param_comment?;
param = ('@'|alpha+) >save_fpc (alnum_u | '*' | '@' | ws )+ %end_param end_statement param_comment?;
tokenize_params := |*
ignore+; #=> show_ignore;
@ -1168,9 +1183,17 @@ eo_tokenizer_database_fill(const char *filename)
{
Eolian_Function foo_id = database_function_new(prop->name, UNRESOLVED);
EINA_LIST_FOREACH(prop->keys, m, param)
database_property_key_add(foo_id, param->type, param->name, param->comment);
{
Eolian_Function_Parameter p = database_property_key_add(
foo_id, param->type, param->name, param->comment);
database_parameter_nonull_set(p, param->nonull);
}
EINA_LIST_FOREACH(prop->values, m, param)
database_property_value_add(foo_id, param->type, param->name, param->comment);
{
Eolian_Function_Parameter p = database_property_value_add(
foo_id, param->type, param->name, param->comment);
database_parameter_nonull_set(p, param->nonull);
}
EINA_LIST_FOREACH(prop->accessors, m, accessor)
{
database_function_type_set(foo_id, (accessor->type == SETTER?SET:GET));
@ -1221,7 +1244,11 @@ eo_tokenizer_database_fill(const char *filename)
database_function_data_set(foo_id, EOLIAN_LEGACY, meth->legacy);
database_function_object_set_as_const(foo_id, meth->obj_const);
EINA_LIST_FOREACH(meth->params, m, param)
database_method_parameter_add(foo_id, (Eolian_Parameter_Dir)param->way, param->type, param->name, param->comment);
{
Eolian_Function_Parameter p = database_method_parameter_add(foo_id,
(Eolian_Parameter_Dir)param->way, param->type, param->name, param->comment);
database_parameter_nonull_set(p, param->nonull);
}
}
EINA_LIST_FOREACH(kls->implements, l, impl)

View File

@ -44,6 +44,7 @@ typedef struct
Eina_Stringshare *description;
Eolian_Parameter_Dir param_dir;
Eina_Bool is_const :1; /* True if const in this function (e.g get) but not const in the opposite one (e.g set) */
Eina_Bool nonull :1; /* True if this argument cannot be NULL */
} _Parameter_Desc;
typedef struct
@ -749,6 +750,22 @@ eolian_parameter_get_const_attribute_get(Eolian_Function_Parameter param_desc)
return param->is_const;
}
void
database_parameter_nonull_set(Eolian_Function_Parameter param_desc, Eina_Bool nonull)
{
_Parameter_Desc *param = (_Parameter_Desc *)param_desc;
EINA_SAFETY_ON_NULL_RETURN(param);
param->nonull = nonull;
}
EAPI Eina_Bool
eolian_parameter_is_nonull(Eolian_Function_Parameter param_desc)
{
_Parameter_Desc *param = (_Parameter_Desc *)param_desc;
EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE);
return param->nonull;
}
void database_function_return_type_set(Eolian_Function foo_id, Eolian_Function_Type ftype, const char *ret_type)
{
const char *key = NULL;

View File

@ -80,6 +80,8 @@ Eolian_Function_Parameter database_method_parameter_add(Eolian_Function foo_id,
void database_parameter_get_const_attribute_set(Eolian_Function_Parameter param_desc, Eina_Bool is_const);
void database_parameter_nonull_set(Eolian_Function_Parameter, Eina_Bool nonull);
void database_function_return_type_set(Eolian_Function foo_id, Eolian_Function_Type ftype, const char *ret_type);
void database_function_return_flag_set_as_warn_unused(Eolian_Function foo_id,