Eolian: Support default return values from .eo file.

Now, it is possible to assign a default return value for a
method/property.
It will be used in case the function invocation makes issues, e.g eo_do
failing to find the function...
This commit is contained in:
Daniel Zaoui 2014-03-16 08:33:24 +02:00
parent d200cf29f1
commit c203df0b5d
8 changed files with 726 additions and 622 deletions

View File

@ -298,8 +298,11 @@ _eapi_func_generate(const char *classname, Eolian_Function funcid, Eolian_Functi
{
if (eina_strbuf_length_get(eoparam)) eina_strbuf_append(eoparam, ", ");
Eina_Bool had_star = !!strchr(rettype, '*');
sprintf (tmpstr, " %s%s%s%s = 0;\n",
ret_const?"const ":"", rettype, had_star?"":" ", retname);
const char *dflt_ret_val =
eolian_function_return_dflt_value_get(funcid, ftype);
sprintf (tmpstr, " %s%s%s%s = %s;\n",
ret_const?"const ":"", rettype, had_star?"":" ", retname,
dflt_ret_val?dflt_ret_val:"0");
eina_strbuf_append_printf(eoparam, "&%s", retname);
}

View File

@ -464,6 +464,22 @@ EAPI Eina_Bool eolian_parameter_is_own(Eolian_Function_Parameter param_desc);
*/
EAPI const char *eolian_function_return_type_get(Eolian_Function function_id, Eolian_Function_Type ftype);
/*
* @brief Get the return default value of a function.
*
* @param[in] function_id id of the function
* @param[in] ftype type of the function
* @return the return default value of the function
*
* The return default value is needed to return an appropriate
* value if an error occurs (eo_do failure...).
* The default value is not mandatory, so NULL can be returned.
*
* @ingroup Eolian
*/
EAPI const char *
eolian_function_return_dflt_value_get(Eolian_Function foo_id, Eolian_Function_Type ftype);
/*
* @brief Get the return comment of a function.
*

View File

@ -8,6 +8,7 @@ eo_definitions_ret_free(Eo_Ret_Def *ret)
{
if (ret->type) eina_stringshare_del(ret->type);
if (ret->comment) eina_stringshare_del(ret->comment);
if (ret->dflt_ret_val) free(ret->dflt_ret_val);
free(ret);
}

View File

@ -10,6 +10,7 @@ typedef struct _eo_ret_def
{
const char *type;
const char *comment;
const char *dflt_ret_val;
Eina_Bool warn_unused:1;
Eina_Bool own:1;
} Eo_Ret_Def;

File diff suppressed because it is too large Load Diff

View File

@ -263,6 +263,24 @@ _eo_tokenizer_return_get(Eo_Tokenizer *toknz, char *p)
ret->own = EINA_TRUE;
memset(s, ' ', 4);
}
s = strchr(toknz->saved.tok, '(');
if (s)
{
char *end = strchr(s, ')');
if (!end)
ABORT(toknz, "wrong syntax (missing ')'): %s",
_eo_tokenizer_token_get(toknz, p));
/* Current values in s and end have to be changed to ' ' to not disturb the next steps (type extraction) */
*s++ = ' ';
while (*s == ' ') s++;
*end-- = ' ';
while (end > s && *end == ' ') end--;
if (end < s)
ABORT(toknz, "empty default return value: %s",
_eo_tokenizer_token_get(toknz, p));
ret->dflt_ret_val = strndup(s, end - s + 1);
memset(s, ' ', end - s + 1);
}
*p = ';';
s = p - 1; /* Don't look at the character ';' */
/* Remove any space between the param name and ';'
@ -400,6 +418,8 @@ _eo_tokenizer_implement_get(Eo_Tokenizer *toknz, char *p)
list_separator = ',';
colon = ':';
# chars allowed on the return line.
return_char = (alnum_u | '*' | ws | '@' | '(' | ')' | '.' | '-');
}%%
%%{
@ -462,7 +482,7 @@ _eo_tokenizer_implement_get(Eo_Tokenizer *toknz, char *p)
}
rettype_comment = ws* eo_comment %end_accessor_rettype_comment;
rettype = 'return' ws+ alpha+ >save_fpc (alnum_u | '*' | ws | '@')+ %end_accessor_return end_statement rettype_comment?;
rettype = 'return' ws+ alpha+ >save_fpc return_char+ %end_accessor_return end_statement rettype_comment?;
legacy = 'legacy' ws+ ident %end_accessor_legacy end_statement;
@ -687,7 +707,7 @@ _eo_tokenizer_implement_get(Eo_Tokenizer *toknz, char *p)
meth_legacy = 'legacy' ws+ ident %end_method_legacy end_statement;
meth_rettype_comment = ws* eo_comment %end_method_rettype_comment;
meth_rettype = 'return' ws+ alpha+ >save_fpc (alnum_u | '*' | ws | '@')+ %end_method_rettype end_statement meth_rettype_comment?;
meth_rettype = 'return' ws+ alpha+ >save_fpc return_char+ %end_method_rettype end_statement meth_rettype_comment?;
meth_obj_const = 'const' %end_method_obj_const end_statement;
@ -1366,6 +1386,8 @@ eo_tokenizer_database_fill(const char *filename)
accessor->type == SETTER?SET:GET, accessor->ret->warn_unused);
database_function_return_flag_set_own(foo_id,
accessor->type == SETTER?SET:GET, accessor->ret->own);
database_function_return_dflt_val_set(foo_id,
accessor->type == SETTER?SET:GET, accessor->ret->dflt_ret_val);
}
if (accessor->legacy)
{
@ -1407,8 +1429,11 @@ eo_tokenizer_database_fill(const char *filename)
{
database_function_data_set(foo_id, EOLIAN_METHOD_RETURN_TYPE, meth->ret->type);
database_function_description_set(foo_id, EOLIAN_RETURN_COMMENT, meth->ret->comment);
database_function_return_flag_set_as_warn_unused(foo_id, METHOD_FUNC, meth->ret->warn_unused);
database_function_return_flag_set_as_warn_unused(foo_id,
METHOD_FUNC, meth->ret->warn_unused);
database_function_return_flag_set_own(foo_id, METHOD_FUNC, meth->ret->own);
database_function_return_dflt_val_set(foo_id,
METHOD_FUNC, meth->ret->dflt_ret_val);
}
database_function_description_set(foo_id, EOLIAN_COMMENT, meth->comment);
database_function_data_set(foo_id, EOLIAN_LEGACY, meth->legacy);

View File

@ -1,6 +1,10 @@
#include <Eina.h>
#include "eolian_database.h"
#define PROP_GET_RETURN_DFLT_VAL "property_get_return_dflt_val"
#define PROP_SET_RETURN_DFLT_VAL "property_set_return_dflt_val"
#define METHOD_RETURN_DFLT_VAL "method_return_dflt_val"
static Eina_Hash *_classes = NULL;
static int _database_init_count = 0;
@ -851,6 +855,33 @@ eolian_function_return_type_get(Eolian_Function foo_id, Eolian_Function_Type fty
return ret;
}
void database_function_return_dflt_val_set(Eolian_Function foo_id, Eolian_Function_Type ftype, const char *ret_dflt_value)
{
const char *key = NULL;
switch (ftype)
{
case SET: key = PROP_SET_RETURN_DFLT_VAL; break;
case GET: key = PROP_GET_RETURN_DFLT_VAL; break;
case METHOD_FUNC: key = METHOD_RETURN_DFLT_VAL; break;
default: return;
}
database_function_data_set(foo_id, key, ret_dflt_value);
}
EAPI const char *
eolian_function_return_dflt_value_get(Eolian_Function foo_id, Eolian_Function_Type ftype)
{
const char *key = NULL;
switch (ftype)
{
case SET: key = PROP_SET_RETURN_DFLT_VAL; break;
case GET: key = PROP_GET_RETURN_DFLT_VAL; break;
case UNRESOLVED: case METHOD_FUNC: key = METHOD_RETURN_DFLT_VAL; break;
default: return NULL;
}
return eolian_function_data_get(foo_id, key);
}
EAPI const char *
eolian_function_return_comment_get(Eolian_Function foo_id, Eolian_Function_Type ftype)
{

View File

@ -94,6 +94,8 @@ void database_parameter_own_set(Eolian_Function_Parameter, Eina_Bool own);
void database_function_return_type_set(Eolian_Function foo_id, Eolian_Function_Type ftype, const char *ret_type);
void database_function_return_dflt_val_set(Eolian_Function foo_id, Eolian_Function_Type ftype, const char *ret_dflt_value);
void database_function_return_flag_set_as_warn_unused(Eolian_Function foo_id,
Eolian_Function_Type ftype, Eina_Bool warn_unused);