eolian: support @protected for accessors (get/set)

Previously it was only possible to set it for the whole property.

@feature
This commit is contained in:
Daniel Kolesa 2016-06-09 16:54:43 +01:00
parent 7953da836e
commit 375179b47f
9 changed files with 51 additions and 26 deletions

View File

@ -66,7 +66,7 @@ eo_fundef_generate(const Eolian_Class *class, const Eolian_Function *func, Eolia
Eina_Bool var_as_ret = EINA_FALSE; Eina_Bool var_as_ret = EINA_FALSE;
const Eolian_Type *rettypet = NULL; const Eolian_Type *rettypet = NULL;
const char *rettype = NULL; const char *rettype = NULL;
Eolian_Object_Scope scope = eolian_function_scope_get(func); Eolian_Object_Scope scope = eolian_function_scope_get(func, ftype);
Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET); Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET);
_class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env); _class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env);

View File

@ -210,7 +210,7 @@ ffi.cdef [[
Eina_Iterator *eolian_class_inherits_get(const Eolian_Class *klass); Eina_Iterator *eolian_class_inherits_get(const Eolian_Class *klass);
Eina_Iterator *eolian_class_functions_get(const Eolian_Class *klass, Eolian_Function_Type func_type); Eina_Iterator *eolian_class_functions_get(const Eolian_Class *klass, Eolian_Function_Type func_type);
Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id); Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id);
Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id); Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
const char *eolian_function_name_get(const Eolian_Function *function_id); const char *eolian_function_name_get(const Eolian_Function *function_id);
const char *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype, Eina_Bool use_legacy); const char *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype, Eina_Bool use_legacy);
const Eolian_Function *eolian_class_function_get_by_name(const Eolian_Class *klass, const char *func_name, Eolian_Function_Type f_type); const Eolian_Function *eolian_class_function_get_by_name(const Eolian_Class *klass, const char *func_name, Eolian_Function_Type f_type);
@ -706,8 +706,8 @@ M.Function = ffi.metatype("Eolian_Function", {
return tonumber(eolian.eolian_function_type_get(self)) return tonumber(eolian.eolian_function_type_get(self))
end, end,
scope_get = function(self) scope_get = function(self, ftype)
return tonumber(eolian.eolian_function_scope_get(self)) return tonumber(eolian.eolian_function_scope_get(self, ftype))
end, end,
name_get = function(self) name_get = function(self)

View File

@ -640,11 +640,12 @@ EAPI Eolian_Function_Type eolian_function_type_get(const Eolian_Function *functi
* @brief Returns the scope of a function * @brief Returns the scope of a function
* *
* @param[in] function_id Id of the function * @param[in] function_id Id of the function
* @param[in] ftype The type of function to get the scope for
* @return the function scope * @return the function scope
* *
* @ingroup Eolian * @ingroup Eolian
*/ */
EAPI Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id); EAPI Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
/* /*
* @brief Returns the name of a function * @brief Returns the name of a function

View File

@ -6,10 +6,15 @@
#include "eolian_database.h" #include "eolian_database.h"
EAPI Eolian_Object_Scope EAPI Eolian_Object_Scope
eolian_function_scope_get(const Eolian_Function *fid) eolian_function_scope_get(const Eolian_Function *fid, Eolian_Function_Type ftype)
{ {
EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EOLIAN_SCOPE_PUBLIC); EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EOLIAN_SCOPE_PUBLIC);
return fid->scope; switch (ftype)
{
case EOLIAN_UNRESOLVED: case EOLIAN_METHOD: case EOLIAN_PROPERTY: case EOLIAN_PROP_GET: return fid->get_scope; break;
case EOLIAN_PROP_SET: return fid->set_scope; break;
default: return EOLIAN_SCOPE_PUBLIC;
}
} }
EAPI Eolian_Function_Type EAPI Eolian_Function_Type

View File

@ -1123,7 +1123,8 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
int line, col; int line, col;
Eina_Bool has_return = EINA_FALSE, has_legacy = EINA_FALSE, Eina_Bool has_return = EINA_FALSE, has_legacy = EINA_FALSE,
has_eo = EINA_FALSE, has_keys = EINA_FALSE, has_eo = EINA_FALSE, has_keys = EINA_FALSE,
has_values = EINA_FALSE; has_values = EINA_FALSE, has_protected = EINA_FALSE,
has_virtual_pure = EINA_FALSE;
Eina_Bool is_get = (ls->t.kw == KW_get); Eina_Bool is_get = (ls->t.kw == KW_get);
if (is_get) if (is_get)
{ {
@ -1144,12 +1145,24 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
prop->type = EOLIAN_PROP_SET; prop->type = EOLIAN_PROP_SET;
} }
eo_lexer_get(ls); eo_lexer_get(ls);
if (ls->t.kw == KW_at_virtual_pure) for (;;) switch (ls->t.kw)
{ {
case KW_at_virtual_pure:
CASE_LOCK(ls, virtual_pure, "virtual_pure qualifier");
if (is_get) prop->get_virtual_pure = EINA_TRUE; if (is_get) prop->get_virtual_pure = EINA_TRUE;
else prop->set_virtual_pure = EINA_TRUE; else prop->set_virtual_pure = EINA_TRUE;
eo_lexer_get(ls); eo_lexer_get(ls);
break;
case KW_at_protected:
CASE_LOCK(ls, protected, "protected qualifier");
if (is_get) prop->get_scope = EOLIAN_SCOPE_PROTECTED;
else prop->set_scope = EOLIAN_SCOPE_PROTECTED;
eo_lexer_get(ls);
break;
default:
goto parse_accessor;
} }
parse_accessor:
line = ls->line_number; line = ls->line_number;
col = ls->column; col = ls->column;
check_next(ls, '{'); check_next(ls, '{');
@ -1271,7 +1284,7 @@ parse_property(Eo_Lexer *ls)
{ {
case KW_at_protected: case KW_at_protected:
CASE_LOCK(ls, protected, "protected qualifier") CASE_LOCK(ls, protected, "protected qualifier")
prop->scope = EOLIAN_SCOPE_PROTECTED; prop->get_scope = prop->set_scope = EOLIAN_SCOPE_PROTECTED;
eo_lexer_get(ls); eo_lexer_get(ls);
break; break;
case KW_at_class: case KW_at_class:
@ -1351,7 +1364,7 @@ parse_method(Eo_Lexer *ls)
{ {
case KW_at_protected: case KW_at_protected:
CASE_LOCK(ls, protected, "protected qualifier") CASE_LOCK(ls, protected, "protected qualifier")
meth->scope = EOLIAN_SCOPE_PROTECTED; meth->get_scope = meth->set_scope = EOLIAN_SCOPE_PROTECTED;
eo_lexer_get(ls); eo_lexer_get(ls);
break; break;
case KW_at_const: case KW_at_const:

View File

@ -117,7 +117,8 @@ struct _Eolian_Function
}; };
}; };
Eolian_Function_Type type; Eolian_Function_Type type;
Eolian_Object_Scope scope; Eolian_Object_Scope get_scope;
Eolian_Object_Scope set_scope;
Eolian_Type *get_ret_type; Eolian_Type *get_ret_type;
Eolian_Type *set_ret_type; Eolian_Type *set_ret_type;
Eolian_Expression *get_ret_val; Eolian_Expression *get_ret_val;

View File

@ -626,14 +626,16 @@ local gen_contents = function(klass)
-- first try properties -- first try properties
local props = klass:functions_get(func_type.PROPERTY):to_array() local props = klass:functions_get(func_type.PROPERTY):to_array()
for i, v in ipairs(props) do for i, v in ipairs(props) do
if v:scope_get() == obj_scope.PUBLIC and not v:is_c_only() then local gscope = v:scope_get(func_type.PROP_GET)
local sscope = v:scope_get(func_type.PROP_SET)
if (gscope == obj_scope.PUBLIC or sscope == obj_scope.PUBLIC) and not v:is_c_only() then
local ftype = v:type_get() local ftype = v:type_get()
local fread = (ftype == func_type.PROPERTY or ftype == func_type.PROP_GET) local fread = (ftype == func_type.PROPERTY or ftype == func_type.PROP_GET)
local fwrite = (ftype == func_type.PROPERTY or ftype == func_type.PROP_SET) local fwrite = (ftype == func_type.PROPERTY or ftype == func_type.PROP_SET)
if fwrite then if fwrite and sscope == obj_scope.PUBLIC then
cnt[#cnt + 1] = Property(v, func_type.PROP_SET) cnt[#cnt + 1] = Property(v, func_type.PROP_SET)
end end
if fread then if fread and gscope == obj_scope.PUBLIC then
cnt[#cnt + 1] = Property(v, func_type.PROP_GET) cnt[#cnt + 1] = Property(v, func_type.PROP_GET)
end end
end end
@ -641,7 +643,7 @@ local gen_contents = function(klass)
-- then methods -- then methods
local meths = klass:functions_get(func_type.METHOD):to_array() local meths = klass:functions_get(func_type.METHOD):to_array()
for i, v in ipairs(meths) do for i, v in ipairs(meths) do
if v:scope_get() == obj_scope.PUBLIC and not v:is_c_only() then if v:scope_get(func_type.METHOD) == obj_scope.PUBLIC and not v:is_c_only() then
cnt[#cnt + 1] = Method(v) cnt[#cnt + 1] = Method(v)
end end
end end

View File

@ -11,6 +11,8 @@ class Scope {
@property c { @property c {
get { get {
} }
set @protected {
}
} }
foo { foo {
} }

View File

@ -516,19 +516,20 @@ START_TEST(eolian_scope)
/* Property scope */ /* Property scope */
fail_if(!(fid = eolian_class_function_get_by_name(class, "a", EOLIAN_PROPERTY))); fail_if(!(fid = eolian_class_function_get_by_name(class, "a", EOLIAN_PROPERTY)));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); fail_if(eolian_function_scope_get(fid, EOLIAN_PROPERTY) != EOLIAN_SCOPE_PROTECTED);
fail_if(!(fid = eolian_class_function_get_by_name(class, "b", EOLIAN_PROPERTY))); fail_if(!(fid = eolian_class_function_get_by_name(class, "b", EOLIAN_PROPERTY)));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); fail_if(eolian_function_scope_get(fid, EOLIAN_PROPERTY) != EOLIAN_SCOPE_PUBLIC);
fail_if(!(fid = eolian_class_function_get_by_name(class, "c", EOLIAN_PROPERTY))); fail_if(!(fid = eolian_class_function_get_by_name(class, "c", EOLIAN_PROPERTY)));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); fail_if(eolian_function_scope_get(fid, EOLIAN_PROP_GET) != EOLIAN_SCOPE_PUBLIC);
fail_if(eolian_function_scope_get(fid, EOLIAN_PROP_SET) != EOLIAN_SCOPE_PROTECTED);
/* Method scope */ /* Method scope */
fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD))); fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD))); fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD)));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PROTECTED);
fail_if(!(fid = eolian_class_function_get_by_name(class, "foobar", EOLIAN_METHOD))); fail_if(!(fid = eolian_class_function_get_by_name(class, "foobar", EOLIAN_METHOD)));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
eolian_shutdown(); eolian_shutdown();
} }
@ -946,16 +947,16 @@ START_TEST(eolian_class_funcs)
/* Class methods */ /* Class methods */
fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD))); fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
fail_if(!eolian_function_is_class(fid)); fail_if(!eolian_function_is_class(fid));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD))); fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD)));
fail_if(eolian_function_is_class(fid)); fail_if(eolian_function_is_class(fid));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
fail_if(!(fid = eolian_class_function_get_by_name(class, "baz", EOLIAN_METHOD))); fail_if(!(fid = eolian_class_function_get_by_name(class, "baz", EOLIAN_METHOD)));
fail_if(!eolian_function_is_class(fid)); fail_if(!eolian_function_is_class(fid));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PROTECTED);
fail_if(!(fid = eolian_class_function_get_by_name(class, "bah", EOLIAN_METHOD))); fail_if(!(fid = eolian_class_function_get_by_name(class, "bah", EOLIAN_METHOD)));
fail_if(eolian_function_is_class(fid)); fail_if(eolian_function_is_class(fid));
fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PROTECTED);
eolian_shutdown(); eolian_shutdown();
} }