summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-06-09 16:54:43 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-06-09 16:55:24 +0100
commit375179b47fa62dba2a1168d1e4e6a7ab877f7414 (patch)
treed3cc6c60efc27c8fd78105c8bda84028fb2974b5
parent7953da836ecf9ae2d8c32566c762ca3432ae8aea (diff)
downloadefl-375179b47fa62dba2a1168d1e4e6a7ab877f7414.tar.gz
eolian: support @protected for accessors (get/set)
Previously it was only possible to set it for the whole property. @feature
-rw-r--r--src/bin/eolian/eo_generator.c2
-rw-r--r--src/bindings/luajit/eolian.lua6
-rw-r--r--src/lib/eolian/Eolian.h3
-rw-r--r--src/lib/eolian/database_function_api.c9
-rw-r--r--src/lib/eolian/eo_parser.c21
-rw-r--r--src/lib/eolian/eolian_database.h3
-rw-r--r--src/scripts/elua/modules/lualian.lua10
-rw-r--r--src/tests/eolian/data/scope.eo2
-rw-r--r--src/tests/eolian/eolian_parsing.c21
9 files changed, 51 insertions, 26 deletions
diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c
index c12975a363..cd111dd1a4 100644
--- a/src/bin/eolian/eo_generator.c
+++ b/src/bin/eolian/eo_generator.c
@@ -66,7 +66,7 @@ eo_fundef_generate(const Eolian_Class *class, const Eolian_Function *func, Eolia
Eina_Bool var_as_ret = EINA_FALSE;
const Eolian_Type *rettypet = 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);
_class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env);
diff --git a/src/bindings/luajit/eolian.lua b/src/bindings/luajit/eolian.lua
index b31f445afc..159fc0a70c 100644
--- a/src/bindings/luajit/eolian.lua
+++ b/src/bindings/luajit/eolian.lua
@@ -210,7 +210,7 @@ ffi.cdef [[
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);
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_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);
@@ -706,8 +706,8 @@ M.Function = ffi.metatype("Eolian_Function", {
return tonumber(eolian.eolian_function_type_get(self))
end,
- scope_get = function(self)
- return tonumber(eolian.eolian_function_scope_get(self))
+ scope_get = function(self, ftype)
+ return tonumber(eolian.eolian_function_scope_get(self, ftype))
end,
name_get = function(self)
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index aa00c7ea7e..1821e46a75 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -640,11 +640,12 @@ EAPI Eolian_Function_Type eolian_function_type_get(const Eolian_Function *functi
* @brief Returns the scope of a 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
*
* @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
diff --git a/src/lib/eolian/database_function_api.c b/src/lib/eolian/database_function_api.c
index 9cb117796c..bf61d440b8 100644
--- a/src/lib/eolian/database_function_api.c
+++ b/src/lib/eolian/database_function_api.c
@@ -6,10 +6,15 @@
#include "eolian_database.h"
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);
- 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
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 3176bdbc77..e6e6f70663 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -1123,7 +1123,8 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
int line, col;
Eina_Bool has_return = EINA_FALSE, has_legacy = 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);
if (is_get)
{
@@ -1144,12 +1145,24 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
prop->type = EOLIAN_PROP_SET;
}
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;
else prop->set_virtual_pure = EINA_TRUE;
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;
col = ls->column;
check_next(ls, '{');
@@ -1271,7 +1284,7 @@ parse_property(Eo_Lexer *ls)
{
case KW_at_protected:
CASE_LOCK(ls, protected, "protected qualifier")
- prop->scope = EOLIAN_SCOPE_PROTECTED;
+ prop->get_scope = prop->set_scope = EOLIAN_SCOPE_PROTECTED;
eo_lexer_get(ls);
break;
case KW_at_class:
@@ -1351,7 +1364,7 @@ parse_method(Eo_Lexer *ls)
{
case KW_at_protected:
CASE_LOCK(ls, protected, "protected qualifier")
- meth->scope = EOLIAN_SCOPE_PROTECTED;
+ meth->get_scope = meth->set_scope = EOLIAN_SCOPE_PROTECTED;
eo_lexer_get(ls);
break;
case KW_at_const:
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 8721a56927..e46192998f 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -117,7 +117,8 @@ struct _Eolian_Function
};
};
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 *set_ret_type;
Eolian_Expression *get_ret_val;
diff --git a/src/scripts/elua/modules/lualian.lua b/src/scripts/elua/modules/lualian.lua
index 8ea6f24edf..f04779fa11 100644
--- a/src/scripts/elua/modules/lualian.lua
+++ b/src/scripts/elua/modules/lualian.lua
@@ -626,14 +626,16 @@ local gen_contents = function(klass)
-- first try properties
local props = klass:functions_get(func_type.PROPERTY):to_array()
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 fread = (ftype == func_type.PROPERTY or ftype == func_type.PROP_GET)
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)
end
- if fread then
+ if fread and gscope == obj_scope.PUBLIC then
cnt[#cnt + 1] = Property(v, func_type.PROP_GET)
end
end
@@ -641,7 +643,7 @@ local gen_contents = function(klass)
-- then methods
local meths = klass:functions_get(func_type.METHOD):to_array()
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)
end
end
diff --git a/src/tests/eolian/data/scope.eo b/src/tests/eolian/data/scope.eo
index 726b1bc006..def94d1d08 100644
--- a/src/tests/eolian/data/scope.eo
+++ b/src/tests/eolian/data/scope.eo
@@ -11,6 +11,8 @@ class Scope {
@property c {
get {
}
+ set @protected {
+ }
}
foo {
}
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index 9833db3597..33befe1890 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -516,19 +516,20 @@ START_TEST(eolian_scope)
/* Property scope */
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(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(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 */
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(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(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC);
+ fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
eolian_shutdown();
}
@@ -946,16 +947,16 @@ START_TEST(eolian_class_funcs)
/* Class methods */
fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
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(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(!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(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();
}