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)
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
66 Eina_Bool var_as_ret = EINA_FALSE; 66 Eina_Bool var_as_ret = EINA_FALSE;
67 const Eolian_Type *rettypet = NULL; 67 const Eolian_Type *rettypet = NULL;
68 const char *rettype = NULL; 68 const char *rettype = NULL;
69 Eolian_Object_Scope scope = eolian_function_scope_get(func); 69 Eolian_Object_Scope scope = eolian_function_scope_get(func, ftype);
70 Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET); 70 Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET);
71 71
72 _class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env); 72 _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 [[
210 Eina_Iterator *eolian_class_inherits_get(const Eolian_Class *klass); 210 Eina_Iterator *eolian_class_inherits_get(const Eolian_Class *klass);
211 Eina_Iterator *eolian_class_functions_get(const Eolian_Class *klass, Eolian_Function_Type func_type); 211 Eina_Iterator *eolian_class_functions_get(const Eolian_Class *klass, Eolian_Function_Type func_type);
212 Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id); 212 Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id);
213 Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id); 213 Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
214 const char *eolian_function_name_get(const Eolian_Function *function_id); 214 const char *eolian_function_name_get(const Eolian_Function *function_id);
215 const char *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype, Eina_Bool use_legacy); 215 const char *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype, Eina_Bool use_legacy);
216 const Eolian_Function *eolian_class_function_get_by_name(const Eolian_Class *klass, const char *func_name, Eolian_Function_Type f_type); 216 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", {
706 return tonumber(eolian.eolian_function_type_get(self)) 706 return tonumber(eolian.eolian_function_type_get(self))
707 end, 707 end,
708 708
709 scope_get = function(self) 709 scope_get = function(self, ftype)
710 return tonumber(eolian.eolian_function_scope_get(self)) 710 return tonumber(eolian.eolian_function_scope_get(self, ftype))
711 end, 711 end,
712 712
713 name_get = function(self) 713 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
640 * @brief Returns the scope of a function 640 * @brief Returns the scope of a function
641 * 641 *
642 * @param[in] function_id Id of the function 642 * @param[in] function_id Id of the function
643 * @param[in] ftype The type of function to get the scope for
643 * @return the function scope 644 * @return the function scope
644 * 645 *
645 * @ingroup Eolian 646 * @ingroup Eolian
646 */ 647 */
647EAPI Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id); 648EAPI Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id, Eolian_Function_Type ftype);
648 649
649/* 650/*
650 * @brief Returns the name of a function 651 * @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 @@
6#include "eolian_database.h" 6#include "eolian_database.h"
7 7
8EAPI Eolian_Object_Scope 8EAPI Eolian_Object_Scope
9eolian_function_scope_get(const Eolian_Function *fid) 9eolian_function_scope_get(const Eolian_Function *fid, Eolian_Function_Type ftype)
10{ 10{
11 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EOLIAN_SCOPE_PUBLIC); 11 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EOLIAN_SCOPE_PUBLIC);
12 return fid->scope; 12 switch (ftype)
13 {
14 case EOLIAN_UNRESOLVED: case EOLIAN_METHOD: case EOLIAN_PROPERTY: case EOLIAN_PROP_GET: return fid->get_scope; break;
15 case EOLIAN_PROP_SET: return fid->set_scope; break;
16 default: return EOLIAN_SCOPE_PUBLIC;
17 }
13} 18}
14 19
15EAPI Eolian_Function_Type 20EAPI 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)
1123 int line, col; 1123 int line, col;
1124 Eina_Bool has_return = EINA_FALSE, has_legacy = EINA_FALSE, 1124 Eina_Bool has_return = EINA_FALSE, has_legacy = EINA_FALSE,
1125 has_eo = EINA_FALSE, has_keys = EINA_FALSE, 1125 has_eo = EINA_FALSE, has_keys = EINA_FALSE,
1126 has_values = EINA_FALSE; 1126 has_values = EINA_FALSE, has_protected = EINA_FALSE,
1127 has_virtual_pure = EINA_FALSE;
1127 Eina_Bool is_get = (ls->t.kw == KW_get); 1128 Eina_Bool is_get = (ls->t.kw == KW_get);
1128 if (is_get) 1129 if (is_get)
1129 { 1130 {
@@ -1144,12 +1145,24 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
1144 prop->type = EOLIAN_PROP_SET; 1145 prop->type = EOLIAN_PROP_SET;
1145 } 1146 }
1146 eo_lexer_get(ls); 1147 eo_lexer_get(ls);
1147 if (ls->t.kw == KW_at_virtual_pure) 1148 for (;;) switch (ls->t.kw)
1148 { 1149 {
1150 case KW_at_virtual_pure:
1151 CASE_LOCK(ls, virtual_pure, "virtual_pure qualifier");
1149 if (is_get) prop->get_virtual_pure = EINA_TRUE; 1152 if (is_get) prop->get_virtual_pure = EINA_TRUE;
1150 else prop->set_virtual_pure = EINA_TRUE; 1153 else prop->set_virtual_pure = EINA_TRUE;
1151 eo_lexer_get(ls); 1154 eo_lexer_get(ls);
1155 break;
1156 case KW_at_protected:
1157 CASE_LOCK(ls, protected, "protected qualifier");
1158 if (is_get) prop->get_scope = EOLIAN_SCOPE_PROTECTED;
1159 else prop->set_scope = EOLIAN_SCOPE_PROTECTED;
1160 eo_lexer_get(ls);
1161 break;
1162 default:
1163 goto parse_accessor;
1152 } 1164 }
1165parse_accessor:
1153 line = ls->line_number; 1166 line = ls->line_number;
1154 col = ls->column; 1167 col = ls->column;
1155 check_next(ls, '{'); 1168 check_next(ls, '{');
@@ -1271,7 +1284,7 @@ parse_property(Eo_Lexer *ls)
1271 { 1284 {
1272 case KW_at_protected: 1285 case KW_at_protected:
1273 CASE_LOCK(ls, protected, "protected qualifier") 1286 CASE_LOCK(ls, protected, "protected qualifier")
1274 prop->scope = EOLIAN_SCOPE_PROTECTED; 1287 prop->get_scope = prop->set_scope = EOLIAN_SCOPE_PROTECTED;
1275 eo_lexer_get(ls); 1288 eo_lexer_get(ls);
1276 break; 1289 break;
1277 case KW_at_class: 1290 case KW_at_class:
@@ -1351,7 +1364,7 @@ parse_method(Eo_Lexer *ls)
1351 { 1364 {
1352 case KW_at_protected: 1365 case KW_at_protected:
1353 CASE_LOCK(ls, protected, "protected qualifier") 1366 CASE_LOCK(ls, protected, "protected qualifier")
1354 meth->scope = EOLIAN_SCOPE_PROTECTED; 1367 meth->get_scope = meth->set_scope = EOLIAN_SCOPE_PROTECTED;
1355 eo_lexer_get(ls); 1368 eo_lexer_get(ls);
1356 break; 1369 break;
1357 case KW_at_const: 1370 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
117 }; 117 };
118 }; 118 };
119 Eolian_Function_Type type; 119 Eolian_Function_Type type;
120 Eolian_Object_Scope scope; 120 Eolian_Object_Scope get_scope;
121 Eolian_Object_Scope set_scope;
121 Eolian_Type *get_ret_type; 122 Eolian_Type *get_ret_type;
122 Eolian_Type *set_ret_type; 123 Eolian_Type *set_ret_type;
123 Eolian_Expression *get_ret_val; 124 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)
626 -- first try properties 626 -- first try properties
627 local props = klass:functions_get(func_type.PROPERTY):to_array() 627 local props = klass:functions_get(func_type.PROPERTY):to_array()
628 for i, v in ipairs(props) do 628 for i, v in ipairs(props) do
629 if v:scope_get() == obj_scope.PUBLIC and not v:is_c_only() then 629 local gscope = v:scope_get(func_type.PROP_GET)
630 local sscope = v:scope_get(func_type.PROP_SET)
631 if (gscope == obj_scope.PUBLIC or sscope == obj_scope.PUBLIC) and not v:is_c_only() then
630 local ftype = v:type_get() 632 local ftype = v:type_get()
631 local fread = (ftype == func_type.PROPERTY or ftype == func_type.PROP_GET) 633 local fread = (ftype == func_type.PROPERTY or ftype == func_type.PROP_GET)
632 local fwrite = (ftype == func_type.PROPERTY or ftype == func_type.PROP_SET) 634 local fwrite = (ftype == func_type.PROPERTY or ftype == func_type.PROP_SET)
633 if fwrite then 635 if fwrite and sscope == obj_scope.PUBLIC then
634 cnt[#cnt + 1] = Property(v, func_type.PROP_SET) 636 cnt[#cnt + 1] = Property(v, func_type.PROP_SET)
635 end 637 end
636 if fread then 638 if fread and gscope == obj_scope.PUBLIC then
637 cnt[#cnt + 1] = Property(v, func_type.PROP_GET) 639 cnt[#cnt + 1] = Property(v, func_type.PROP_GET)
638 end 640 end
639 end 641 end
@@ -641,7 +643,7 @@ local gen_contents = function(klass)
641 -- then methods 643 -- then methods
642 local meths = klass:functions_get(func_type.METHOD):to_array() 644 local meths = klass:functions_get(func_type.METHOD):to_array()
643 for i, v in ipairs(meths) do 645 for i, v in ipairs(meths) do
644 if v:scope_get() == obj_scope.PUBLIC and not v:is_c_only() then 646 if v:scope_get(func_type.METHOD) == obj_scope.PUBLIC and not v:is_c_only() then
645 cnt[#cnt + 1] = Method(v) 647 cnt[#cnt + 1] = Method(v)
646 end 648 end
647 end 649 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 {
11 @property c { 11 @property c {
12 get { 12 get {
13 } 13 }
14 set @protected {
15 }
14 } 16 }
15 foo { 17 foo {
16 } 18 }
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)
516 516
517 /* Property scope */ 517 /* Property scope */
518 fail_if(!(fid = eolian_class_function_get_by_name(class, "a", EOLIAN_PROPERTY))); 518 fail_if(!(fid = eolian_class_function_get_by_name(class, "a", EOLIAN_PROPERTY)));
519 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); 519 fail_if(eolian_function_scope_get(fid, EOLIAN_PROPERTY) != EOLIAN_SCOPE_PROTECTED);
520 fail_if(!(fid = eolian_class_function_get_by_name(class, "b", EOLIAN_PROPERTY))); 520 fail_if(!(fid = eolian_class_function_get_by_name(class, "b", EOLIAN_PROPERTY)));
521 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); 521 fail_if(eolian_function_scope_get(fid, EOLIAN_PROPERTY) != EOLIAN_SCOPE_PUBLIC);
522 fail_if(!(fid = eolian_class_function_get_by_name(class, "c", EOLIAN_PROPERTY))); 522 fail_if(!(fid = eolian_class_function_get_by_name(class, "c", EOLIAN_PROPERTY)));
523 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); 523 fail_if(eolian_function_scope_get(fid, EOLIAN_PROP_GET) != EOLIAN_SCOPE_PUBLIC);
524 fail_if(eolian_function_scope_get(fid, EOLIAN_PROP_SET) != EOLIAN_SCOPE_PROTECTED);
524 525
525 /* Method scope */ 526 /* Method scope */
526 fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD))); 527 fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
527 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); 528 fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
528 fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD))); 529 fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD)));
529 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); 530 fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PROTECTED);
530 fail_if(!(fid = eolian_class_function_get_by_name(class, "foobar", EOLIAN_METHOD))); 531 fail_if(!(fid = eolian_class_function_get_by_name(class, "foobar", EOLIAN_METHOD)));
531 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); 532 fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
532 533
533 eolian_shutdown(); 534 eolian_shutdown();
534} 535}
@@ -946,16 +947,16 @@ START_TEST(eolian_class_funcs)
946 /* Class methods */ 947 /* Class methods */
947 fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD))); 948 fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
948 fail_if(!eolian_function_is_class(fid)); 949 fail_if(!eolian_function_is_class(fid));
949 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); 950 fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
950 fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD))); 951 fail_if(!(fid = eolian_class_function_get_by_name(class, "bar", EOLIAN_METHOD)));
951 fail_if(eolian_function_is_class(fid)); 952 fail_if(eolian_function_is_class(fid));
952 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PUBLIC); 953 fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PUBLIC);
953 fail_if(!(fid = eolian_class_function_get_by_name(class, "baz", EOLIAN_METHOD))); 954 fail_if(!(fid = eolian_class_function_get_by_name(class, "baz", EOLIAN_METHOD)));
954 fail_if(!eolian_function_is_class(fid)); 955 fail_if(!eolian_function_is_class(fid));
955 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); 956 fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PROTECTED);
956 fail_if(!(fid = eolian_class_function_get_by_name(class, "bah", EOLIAN_METHOD))); 957 fail_if(!(fid = eolian_class_function_get_by_name(class, "bah", EOLIAN_METHOD)));
957 fail_if(eolian_function_is_class(fid)); 958 fail_if(eolian_function_is_class(fid));
958 fail_if(eolian_function_scope_get(fid) != EOLIAN_SCOPE_PROTECTED); 959 fail_if(eolian_function_scope_get(fid, EOLIAN_METHOD) != EOLIAN_SCOPE_PROTECTED);
959 960
960 eolian_shutdown(); 961 eolian_shutdown();
961} 962}