forked from enlightenment/efl
Eolian: add support for functions scope.
This patch adds support for protected functions. In the .eo file, the scope (public by default) has to be added before the function name e.g: protected foo ... To access the protected APIs, #define (CLASS)_PROTECTED is needed e.g: #define ELM_BUTTON_PROTECTED
This commit is contained in:
parent
bbba6a20b4
commit
87776ff0fa
|
@ -113,7 +113,7 @@ static const char
|
|||
tmpl_eo_subid_apnd[] = " @#EOPREFIX_SUB_ID_@#FUNC,\n";
|
||||
|
||||
static const char
|
||||
tmpl_eo_funcdef_doxygen[] = "\n\
|
||||
tmpl_eo_funcdef_doxygen[] = "\
|
||||
/**\n\
|
||||
* @def @#eoprefix_@#func\n\
|
||||
*\n\
|
||||
|
@ -163,6 +163,7 @@ eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function
|
|||
Eina_Bool var_as_ret = EINA_FALSE;
|
||||
const char *rettype = NULL;
|
||||
Eina_Bool ret_const = EINA_FALSE;
|
||||
Eolian_Function_Scope scope = eolian_function_scope_get(func);
|
||||
|
||||
char *fsuffix = "";
|
||||
rettype = eolian_function_return_type_get(func, ftype);
|
||||
|
@ -189,12 +190,17 @@ eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function
|
|||
const char *funcdesc = eolian_function_description_get(func, descname);
|
||||
|
||||
Eina_Strbuf *str_func = eina_strbuf_new();
|
||||
_template_fill(str_func, tmpl_eo_funcdef_doxygen, classname, funcname, EINA_TRUE);
|
||||
if (scope == EOLIAN_SCOPE_PROTECTED)
|
||||
eina_strbuf_append_printf(str_func, "#ifdef %s_PROTECTED\n", capclass);
|
||||
_template_fill(str_func, tmpl_eo_funcdef_doxygen, classname, funcname, EINA_FALSE);
|
||||
#ifndef EO
|
||||
_template_fill(str_func, tmpl_eo1_funcdef, classname, funcname, EINA_FALSE);
|
||||
#else
|
||||
_template_fill(str_func, tmpl_eo_funcdef, classname, funcname, EINA_FALSE);
|
||||
if (scope == EOLIAN_SCOPE_PROTECTED)
|
||||
eina_strbuf_append_printf(str_func, "#endif\n");
|
||||
#endif
|
||||
eina_strbuf_append_printf(str_func, "\n");
|
||||
|
||||
eina_strbuf_replace_all(str_func, "@#EOPREFIX", current_eo_prefix_upper);
|
||||
eina_strbuf_replace_all(str_func, "@#eoprefix", current_eo_prefix_lower);
|
||||
|
|
|
@ -110,6 +110,12 @@ typedef enum
|
|||
EOLIAN_CLASS_INTERFACE
|
||||
} Eolian_Class_Type;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EOLIAN_SCOPE_PUBLIC,
|
||||
EOLIAN_SCOPE_PROTECTED
|
||||
} Eolian_Function_Scope;
|
||||
|
||||
/*
|
||||
* @brief Parse a given .eo file and fill the database.
|
||||
*
|
||||
|
@ -281,6 +287,16 @@ EAPI Eolian_Function eolian_class_default_destructor_get(const char *class_name)
|
|||
*/
|
||||
EAPI Eolian_Function_Type eolian_function_type_get(Eolian_Function function_id);
|
||||
|
||||
/*
|
||||
* @brief Returns the scope of a function
|
||||
*
|
||||
* @param[in] function_id Id of the function
|
||||
* @return the function scope
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eolian_Function_Scope eolian_function_scope_get(Eolian_Function function_id);
|
||||
|
||||
/*
|
||||
* @brief Returns the name of a function
|
||||
*
|
||||
|
|
|
@ -67,6 +67,7 @@ typedef struct _eo_property_def
|
|||
Eina_List *keys;
|
||||
Eina_List *values;
|
||||
Eina_List *accessors;
|
||||
int scope;
|
||||
} Eo_Property_Def;
|
||||
|
||||
/* METHOD */
|
||||
|
@ -87,6 +88,7 @@ typedef struct _eo_method_def
|
|||
Eina_List *params;
|
||||
const char* legacy;
|
||||
Eina_Bool obj_const;
|
||||
int scope;
|
||||
} Eo_Method_Def;
|
||||
|
||||
/* SIGNAL */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -47,6 +47,7 @@ typedef struct _eo_tokenizer
|
|||
Eo_Event_Def *event;
|
||||
Eo_Implement_Def *impl;
|
||||
Eo_Implement_Legacy_Param_Def *impl_leg_param;
|
||||
int fscope;
|
||||
} tmp;
|
||||
|
||||
} Eo_Tokenizer;
|
||||
|
|
|
@ -33,6 +33,9 @@ static int _eo_tokenizer_log_dom = -1;
|
|||
#endif
|
||||
#define DBG(...) EINA_LOG_DOM_DBG(_eo_tokenizer_log_dom, __VA_ARGS__)
|
||||
|
||||
#define FUNC_PUBLIC 0
|
||||
#define FUNC_PROTECTED 1
|
||||
|
||||
static int _init_counter = 0;
|
||||
|
||||
int
|
||||
|
@ -152,10 +155,21 @@ _eo_tokenizer_class_get(Eo_Tokenizer *toknz, char *p)
|
|||
static Eo_Property_Def*
|
||||
_eo_tokenizer_property_get(Eo_Tokenizer *toknz, char *p)
|
||||
{
|
||||
Eo_Property_Def *prop = calloc(1, sizeof(Eo_Property_Def));
|
||||
if (prop == NULL) ABORT(toknz, "calloc Eo_Property_Def failure");
|
||||
Eo_Property_Def *prop = NULL;
|
||||
if (!strncmp(toknz->saved.tok, "protected ", 10))
|
||||
{
|
||||
toknz->saved.tok += 10;
|
||||
toknz->tmp.fscope = FUNC_PROTECTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
prop = calloc(1, sizeof(Eo_Property_Def));
|
||||
if (prop == NULL) ABORT(toknz, "calloc Eo_Property_Def failure");
|
||||
|
||||
prop->name = _eo_tokenizer_token_get(toknz, p);
|
||||
prop->name = _eo_tokenizer_token_get(toknz, p);
|
||||
prop->scope = toknz->tmp.fscope;
|
||||
toknz->tmp.fscope = FUNC_PUBLIC;
|
||||
}
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
@ -163,10 +177,21 @@ _eo_tokenizer_property_get(Eo_Tokenizer *toknz, char *p)
|
|||
static Eo_Method_Def*
|
||||
_eo_tokenizer_method_get(Eo_Tokenizer *toknz, char *p)
|
||||
{
|
||||
Eo_Method_Def *meth = calloc(1, sizeof(Eo_Method_Def));
|
||||
if (meth == NULL) ABORT(toknz, "calloc Eo_Method_Def failure");
|
||||
Eo_Method_Def *meth = NULL;
|
||||
if (!strncmp(toknz->saved.tok, "protected ", 10))
|
||||
{
|
||||
toknz->saved.tok += 10;
|
||||
toknz->tmp.fscope = FUNC_PROTECTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
meth = calloc(1, sizeof(Eo_Method_Def));
|
||||
if (meth == NULL) ABORT(toknz, "calloc Eo_Method_Def failure");
|
||||
|
||||
meth->name = _eo_tokenizer_token_get(toknz, p);
|
||||
meth->name = _eo_tokenizer_token_get(toknz, p);
|
||||
meth->scope = toknz->tmp.fscope;
|
||||
toknz->tmp.fscope = FUNC_PUBLIC;
|
||||
}
|
||||
|
||||
return meth;
|
||||
}
|
||||
|
@ -424,7 +449,7 @@ _eo_tokenizer_implement_get(Eo_Tokenizer *toknz, char *p)
|
|||
|
||||
# chars allowed on the return line.
|
||||
return_char = (alnum_u | '*' | ws | '@' | '(' | ')' | '.' | '-');
|
||||
func_name = alnum+ >save_fpc (alnum | '_' )+;
|
||||
func_name = (alnum >save_fpc (alnum | '_')+ (ws (alnum | '_')+)?);
|
||||
}%%
|
||||
|
||||
%%{
|
||||
|
@ -1374,6 +1399,7 @@ eo_tokenizer_database_fill(const char *filename)
|
|||
EINA_LIST_FOREACH(kls->properties, l, prop)
|
||||
{
|
||||
Eolian_Function foo_id = database_function_new(prop->name, EOLIAN_UNRESOLVED);
|
||||
database_function_scope_set(foo_id, prop->scope);
|
||||
EINA_LIST_FOREACH(prop->keys, m, param)
|
||||
{
|
||||
Eolian_Function_Parameter p = database_property_key_add(
|
||||
|
@ -1437,6 +1463,7 @@ eo_tokenizer_database_fill(const char *filename)
|
|||
EINA_LIST_FOREACH(kls->methods, l, meth)
|
||||
{
|
||||
Eolian_Function foo_id = database_function_new(meth->name, EOLIAN_METHOD);
|
||||
database_function_scope_set(foo_id, meth->scope);
|
||||
database_class_function_add(kls->name, foo_id);
|
||||
if (meth->ret)
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ typedef struct
|
|||
Eina_List *keys; /* list of _Parameter_Desc */
|
||||
Eina_List *params; /* list of _Parameter_Desc */
|
||||
Eolian_Function_Type type;
|
||||
Eolian_Function_Scope scope;
|
||||
Eina_Hash *data;
|
||||
Eina_Bool obj_is_const :1; /* True if the object has to be const. Useful for a few methods. */
|
||||
Eina_Bool get_virtual_pure :1;
|
||||
|
@ -379,6 +380,22 @@ database_function_new(const char *function_name, Eolian_Function_Type foo_type)
|
|||
return (Eolian_Function) fid;
|
||||
}
|
||||
|
||||
EAPI Eolian_Function_Scope
|
||||
eolian_function_scope_get(Eolian_Function function_id)
|
||||
{
|
||||
_Function_Id *fid = (_Function_Id *)function_id;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EOLIAN_SCOPE_PUBLIC);
|
||||
return fid->scope;
|
||||
}
|
||||
|
||||
void
|
||||
database_function_scope_set(Eolian_Function function_id, Eolian_Function_Scope scope)
|
||||
{
|
||||
_Function_Id *fid = (_Function_Id *)function_id;
|
||||
EINA_SAFETY_ON_NULL_RETURN(fid);
|
||||
fid->scope = scope;
|
||||
}
|
||||
|
||||
void
|
||||
database_function_type_set(Eolian_Function function_id, Eolian_Function_Type foo_type)
|
||||
{
|
||||
|
|
|
@ -109,6 +109,9 @@ void database_function_object_set_as_const(Eolian_Function foo_id, Eina_Bool is_
|
|||
Eina_Bool
|
||||
database_function_set_as_virtual_pure(Eolian_Function function_id, Eolian_Function_Type type);
|
||||
|
||||
void
|
||||
database_function_scope_set(Eolian_Function function_id, Eolian_Function_Scope scope);
|
||||
|
||||
/* Need to add API for callbacks and implements */
|
||||
|
||||
Eolian_Implement
|
||||
|
|
Loading…
Reference in New Issue