summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-20 17:42:00 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-20 17:42:44 +0100
commit6b91b1bd128328f675f41491d317d781531d1e2d (patch)
tree7278d2973a2064309ea825b791476c557a9375bc /src
parentf64c12dc1dd6b8fa24c0ec14a5978ab05a490246 (diff)
eolian: allow keys/values in property get/set
Sometimes it is necessary to specify a different set of values for a getter or a setter. This commit allows such specializations. This also renders @const_get and @const_set useless (soon to be removed). To function correctly, this required adjustment of several public APIs as well as deprecation of eolian_function_parameter_get_by_name. This function was not used in any generator and was pretty much useless in the first place, so it was removed. @fix
Diffstat (limited to 'src')
-rw-r--r--src/bindings/luajit/eolian.lua7
-rw-r--r--src/lib/eolian/database_function.c8
-rw-r--r--src/lib/eolian/database_function_api.c33
-rw-r--r--src/lib/eolian/database_validate.c16
-rw-r--r--src/lib/eolian/eo_parser.c49
-rw-r--r--src/lib/eolian/eolian_database.h13
-rw-r--r--src/tests/eolian/data/consts.eo11
-rw-r--r--src/tests/eolian/data/object_impl.eo5
-rw-r--r--src/tests/eolian/eolian_parsing.c24
9 files changed, 100 insertions, 66 deletions
diff --git a/src/bindings/luajit/eolian.lua b/src/bindings/luajit/eolian.lua
index d806f4aa98..67ff24a54a 100644
--- a/src/bindings/luajit/eolian.lua
+++ b/src/bindings/luajit/eolian.lua
@@ -213,7 +213,6 @@ ffi.cdef [[
213 Eina_Bool eolian_function_is_legacy_only(const Eolian_Function *function_id, Eolian_Function_Type ftype); 213 Eina_Bool eolian_function_is_legacy_only(const Eolian_Function *function_id, Eolian_Function_Type ftype);
214 Eina_Bool eolian_function_is_class(const Eolian_Function *function_id); 214 Eina_Bool eolian_function_is_class(const Eolian_Function *function_id);
215 Eina_Bool eolian_function_is_c_only(const Eolian_Function *function_id); 215 Eina_Bool eolian_function_is_c_only(const Eolian_Function *function_id);
216 const Eolian_Function_Parameter *eolian_function_parameter_get_by_name(const Eolian_Function *function_id, const char *param_name);
217 Eina_Iterator *eolian_property_keys_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype); 216 Eina_Iterator *eolian_property_keys_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
218 Eina_Iterator *eolian_property_values_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype); 217 Eina_Iterator *eolian_property_values_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
219 Eina_Iterator *eolian_function_parameters_get(const Eolian_Function *function_id); 218 Eina_Iterator *eolian_function_parameters_get(const Eolian_Function *function_id);
@@ -671,12 +670,6 @@ M.Function = ffi.metatype("Eolian_Function", {
671 return eolian.eolian_function_is_c_only(self) ~= 0 670 return eolian.eolian_function_is_c_only(self) ~= 0
672 end, 671 end,
673 672
674 parameter_get_by_name = function(self, pname)
675 local v = eolian.eolian_function_parameter_get_by_name(self, pname)
676 if v == nil then return nil end
677 return v
678 end,
679
680 property_keys_get = function(self, ftype) 673 property_keys_get = function(self, ftype)
681 return Ptr_Iterator("const Eolian_Function_Parameter*", 674 return Ptr_Iterator("const Eolian_Function_Parameter*",
682 eolian.eolian_property_keys_get(self, ftype)) 675 eolian.eolian_property_keys_get(self, ftype))
diff --git a/src/lib/eolian/database_function.c b/src/lib/eolian/database_function.c
index 48fdd30554..9729077094 100644
--- a/src/lib/eolian/database_function.c
+++ b/src/lib/eolian/database_function.c
@@ -14,8 +14,12 @@ database_function_del(Eolian_Function *fid)
14 14
15 if (fid->base.file) eina_stringshare_del(fid->base.file); 15 if (fid->base.file) eina_stringshare_del(fid->base.file);
16 eina_stringshare_del(fid->name); 16 eina_stringshare_del(fid->name);
17 EINA_LIST_FREE(fid->keys, param) database_parameter_del(param); 17 EINA_LIST_FREE(fid->prop_values, param) database_parameter_del(param);
18 EINA_LIST_FREE(fid->params, param) database_parameter_del(param); 18 EINA_LIST_FREE(fid->prop_values_get, param) database_parameter_del(param);
19 EINA_LIST_FREE(fid->prop_values_set, param) database_parameter_del(param);
20 EINA_LIST_FREE(fid->prop_keys, param) database_parameter_del(param);
21 EINA_LIST_FREE(fid->prop_keys_get, param) database_parameter_del(param);
22 EINA_LIST_FREE(fid->prop_keys_set, param) database_parameter_del(param);
19 EINA_LIST_FREE(fid->ctor_of, cls_name) eina_stringshare_del(cls_name); 23 EINA_LIST_FREE(fid->ctor_of, cls_name) eina_stringshare_del(cls_name);
20 database_type_del(fid->get_ret_type); 24 database_type_del(fid->get_ret_type);
21 database_type_del(fid->set_ret_type); 25 database_type_del(fid->set_ret_type);
diff --git a/src/lib/eolian/database_function_api.c b/src/lib/eolian/database_function_api.c
index 08a8173729..6f646c847f 100644
--- a/src/lib/eolian/database_function_api.c
+++ b/src/lib/eolian/database_function_api.c
@@ -164,35 +164,44 @@ eolian_function_is_constructor(const Eolian_Function *fid, const Eolian_Class *k
164 return r; 164 return r;
165} 165}
166 166
167EAPI const Eolian_Function_Parameter * 167static Eina_List *
168eolian_function_parameter_get_by_name(const Eolian_Function *fid, const char *param_name) 168_get_prop_keys(const Eolian_Function *fid, Eolian_Function_Type ftype)
169{ 169{
170 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, NULL); 170 Eina_List *l = fid->prop_keys_get;
171 Eina_List *itr; 171 if (ftype == EOLIAN_PROP_SET) l = fid->prop_keys_set;
172 Eolian_Function_Parameter *param; 172 if (!l) return fid->prop_keys;
173 EINA_LIST_FOREACH(fid->keys, itr, param) 173 return l;
174 if (!strcmp(param->name, param_name)) return param; 174}
175 EINA_LIST_FOREACH(fid->params, itr, param) 175
176 if (!strcmp(param->name, param_name)) return param; 176static Eina_List *
177 return NULL; 177_get_prop_values(const Eolian_Function *fid, Eolian_Function_Type ftype)
178{
179 Eina_List *l = fid->prop_values_get;
180 if (ftype == EOLIAN_PROP_SET) l = fid->prop_values_set;
181 if (!l) return fid->prop_values;
182 return l;
178} 183}
179 184
180EAPI Eina_Iterator * 185EAPI Eina_Iterator *
181eolian_property_keys_get(const Eolian_Function *fid, Eolian_Function_Type ftype) 186eolian_property_keys_get(const Eolian_Function *fid, Eolian_Function_Type ftype)
182{ 187{
188 Eina_List *l = NULL;
183 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, NULL); 189 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, NULL);
184 if (ftype != EOLIAN_PROP_GET && ftype != EOLIAN_PROP_SET) 190 if (ftype != EOLIAN_PROP_GET && ftype != EOLIAN_PROP_SET)
185 return NULL; 191 return NULL;
186 return (fid->keys ? eina_list_iterator_new(fid->keys) : NULL); 192 l = _get_prop_keys(fid, ftype);
193 return (l ? eina_list_iterator_new(l) : NULL);
187} 194}
188 195
189EAPI Eina_Iterator * 196EAPI Eina_Iterator *
190eolian_property_values_get(const Eolian_Function *fid, Eolian_Function_Type ftype) 197eolian_property_values_get(const Eolian_Function *fid, Eolian_Function_Type ftype)
191{ 198{
199 Eina_List *l = NULL;
192 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, NULL); 200 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, NULL);
193 if (ftype != EOLIAN_PROP_GET && ftype != EOLIAN_PROP_SET) 201 if (ftype != EOLIAN_PROP_GET && ftype != EOLIAN_PROP_SET)
194 return NULL; 202 return NULL;
195 return (fid->params ? eina_list_iterator_new(fid->params) : NULL); 203 l = _get_prop_values(fid, ftype);
204 return (l ? eina_list_iterator_new(l) : NULL);
196} 205}
197 206
198EAPI Eina_Iterator * 207EAPI Eina_Iterator *
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index 43cd53bc4f..b1f1a9f864 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -145,13 +145,19 @@ _validate_function(const Eolian_Function *func)
145 func->set_ret_type, 0)) 145 func->set_ret_type, 0))
146 return EINA_FALSE; 146 return EINA_FALSE;
147 147
148 EINA_LIST_FOREACH(func->keys, l, param) 148#define EOLIAN_PARAMS_VALIDATE(params) \
149 if (!_validate_param(param)) 149 EINA_LIST_FOREACH(params, l, param) \
150 if (!_validate_param(param)) \
150 return EINA_FALSE; 151 return EINA_FALSE;
151 152
152 EINA_LIST_FOREACH(func->params, l, param) 153 EOLIAN_PARAMS_VALIDATE(func->prop_values);
153 if (!_validate_param(param)) 154 EOLIAN_PARAMS_VALIDATE(func->prop_values_get);
154 return EINA_FALSE; 155 EOLIAN_PARAMS_VALIDATE(func->prop_values_set);
156 EOLIAN_PARAMS_VALIDATE(func->prop_keys);
157 EOLIAN_PARAMS_VALIDATE(func->prop_keys_get);
158 EOLIAN_PARAMS_VALIDATE(func->prop_keys_set);
159
160#undef EOLIAN_PARAMS_VALIDATE
155 161
156 return EINA_TRUE; 162 return EINA_TRUE;
157} 163}
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 6a695a06ff..435079b24b 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -1083,11 +1083,25 @@ parse_legacy(Eo_Lexer *ls, const char **out)
1083} 1083}
1084 1084
1085static void 1085static void
1086parse_params(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
1087 Eina_Bool is_vals)
1088{
1089 int line, col;
1090 eo_lexer_get(ls);
1091 line = ls->line_number, col = ls->column;
1092 check_next(ls, '{');
1093 while (ls->t.token != '}')
1094 parse_param(ls, params, allow_inout, is_vals);
1095 check_match(ls, '}', '{', line, col);
1096}
1097
1098static void
1086parse_accessor(Eo_Lexer *ls, Eolian_Function *prop) 1099parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
1087{ 1100{
1088 int line, col; 1101 int line, col;
1089 Eina_Bool has_return = EINA_FALSE, has_legacy = EINA_FALSE, 1102 Eina_Bool has_return = EINA_FALSE, has_legacy = EINA_FALSE,
1090 has_eo = EINA_FALSE; 1103 has_eo = EINA_FALSE, has_keys = EINA_FALSE,
1104 has_values = EINA_FALSE;
1091 Eina_Bool is_get = (ls->t.kw == KW_get); 1105 Eina_Bool is_get = (ls->t.kw == KW_get);
1092 if (is_get) 1106 if (is_get)
1093 { 1107 {
@@ -1160,6 +1174,22 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
1160 else 1174 else
1161 prop->set_only_legacy = EINA_TRUE; 1175 prop->set_only_legacy = EINA_TRUE;
1162 break; 1176 break;
1177 case KW_keys:
1178 {
1179 Eina_List **stor;
1180 CASE_LOCK(ls, keys, "keys definition")
1181 stor = is_get ? &prop->prop_keys_get : &prop->prop_keys_set;
1182 parse_params(ls, stor, EINA_FALSE, EINA_FALSE);
1183 break;
1184 }
1185 case KW_values:
1186 {
1187 Eina_List **stor;
1188 CASE_LOCK(ls, values, "values definition")
1189 stor = is_get ? &prop->prop_values_get : &prop->prop_values_set;
1190 parse_params(ls, stor, EINA_FALSE, EINA_TRUE);
1191 break;
1192 }
1163 default: 1193 default:
1164 goto end; 1194 goto end;
1165 } 1195 }
@@ -1168,19 +1198,6 @@ end:
1168} 1198}
1169 1199
1170static void 1200static void
1171parse_params(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
1172 Eina_Bool is_vals)
1173{
1174 int line, col;
1175 eo_lexer_get(ls);
1176 line = ls->line_number, col = ls->column;
1177 check_next(ls, '{');
1178 while (ls->t.token != '}')
1179 parse_param(ls, params, allow_inout, is_vals);
1180 check_match(ls, '}', '{', line, col);
1181}
1182
1183static void
1184_interface_virtual_set(Eo_Lexer *ls, Eolian_Function *foo_id) 1201_interface_virtual_set(Eo_Lexer *ls, Eolian_Function *foo_id)
1185{ 1202{
1186 if (ls->tmp.kls->type != EOLIAN_CLASS_INTERFACE) 1203 if (ls->tmp.kls->type != EOLIAN_CLASS_INTERFACE)
@@ -1257,11 +1274,11 @@ body:
1257 break; 1274 break;
1258 case KW_keys: 1275 case KW_keys:
1259 CASE_LOCK(ls, keys, "keys definition") 1276 CASE_LOCK(ls, keys, "keys definition")
1260 parse_params(ls, &prop->keys, EINA_FALSE, EINA_FALSE); 1277 parse_params(ls, &prop->prop_keys, EINA_FALSE, EINA_FALSE);
1261 break; 1278 break;
1262 case KW_values: 1279 case KW_values:
1263 CASE_LOCK(ls, values, "values definition") 1280 CASE_LOCK(ls, values, "values definition")
1264 parse_params(ls, &prop->params, EINA_FALSE, EINA_TRUE); 1281 parse_params(ls, &prop->prop_values, EINA_FALSE, EINA_TRUE);
1265 break; 1282 break;
1266 default: 1283 default:
1267 goto end; 1284 goto end;
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 2129e9501f..0fccf5d4a4 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -111,8 +111,17 @@ struct _Eolian_Function
111 Eolian_Object base; 111 Eolian_Object base;
112 Eolian_Object set_base; 112 Eolian_Object set_base;
113 Eina_Stringshare *name; 113 Eina_Stringshare *name;
114 Eina_List *keys; /* list of Eolian_Function_Parameter */ 114 union { /* lists of Eolian_Function_Parameter */
115 Eina_List *params; /* list of Eolian_Function_Parameter */ 115 Eina_List *params;
116 struct {
117 Eina_List *prop_values;
118 Eina_List *prop_values_get;
119 Eina_List *prop_values_set;
120 Eina_List *prop_keys;
121 Eina_List *prop_keys_get;
122 Eina_List *prop_keys_set;
123 };
124 };
116 Eolian_Function_Type type; 125 Eolian_Function_Type type;
117 Eolian_Object_Scope scope; 126 Eolian_Object_Scope scope;
118 Eolian_Type *get_ret_type; 127 Eolian_Type *get_ret_type;
diff --git a/src/tests/eolian/data/consts.eo b/src/tests/eolian/data/consts.eo
index 934ad86d2e..6d084d702d 100644
--- a/src/tests/eolian/data/consts.eo
+++ b/src/tests/eolian/data/consts.eo
@@ -1,16 +1,5 @@
1class Consts { 1class Consts {
2 methods { 2 methods {
3 @property a {
4 set {
5 return: bool (true); /*@ comment for property set return */
6 }
7 get {
8 }
9 values {
10 value: int; /*@ Value description */
11 buffer: char * @const_get;
12 }
13 }
14 foo @const { 3 foo @const {
15 /*@ comment foo */ 4 /*@ comment foo */
16 params { 5 params {
diff --git a/src/tests/eolian/data/object_impl.eo b/src/tests/eolian/data/object_impl.eo
index 94bf84f071..67da2505e2 100644
--- a/src/tests/eolian/data/object_impl.eo
+++ b/src/tests/eolian/data/object_impl.eo
@@ -2,6 +2,9 @@ class Object_Impl (Base) {
2 methods { 2 methods {
3 @property a { 3 @property a {
4 set { 4 set {
5 values {
6 value: const(list<int>)*;
7 }
5 return: bool (false); 8 return: bool (false);
6 } 9 }
7 get { 10 get {
@@ -10,7 +13,7 @@ class Object_Impl (Base) {
10 part: const(char)*; 13 part: const(char)*;
11 } 14 }
12 values { 15 values {
13 value: own(list<int>*) @const_set; 16 value: own(list<int>*);
14 } 17 }
15 } 18 }
16 @property b { 19 @property b {
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index 131a9d3f69..e9495d788b 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -265,12 +265,6 @@ START_TEST(eolian_consts)
265 fail_if(!eolian_eo_file_parse(PACKAGE_DATA_DIR"/data/consts.eo")); 265 fail_if(!eolian_eo_file_parse(PACKAGE_DATA_DIR"/data/consts.eo"));
266 fail_if(!(class = eolian_class_get_by_name("Consts"))); 266 fail_if(!(class = eolian_class_get_by_name("Consts")));
267 267
268 /* Property */
269 fail_if(!(fid = eolian_class_function_get_by_name(class, "a", EOLIAN_PROPERTY)));
270 fail_if(!(param = eolian_function_parameter_get_by_name(fid, "buffer")));
271 fail_if(eolian_parameter_const_attribute_get(param, EINA_FALSE));
272 fail_if(!eolian_parameter_const_attribute_get(param, EINA_TRUE));
273
274 /* Method */ 268 /* Method */
275 fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD))); 269 fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
276 fail_if(EINA_FALSE == eolian_function_object_is_const(fid)); 270 fail_if(EINA_FALSE == eolian_function_object_is_const(fid));
@@ -1013,6 +1007,7 @@ START_TEST(eolian_null)
1013 const Eolian_Class *class; 1007 const Eolian_Class *class;
1014 const Eolian_Function *func; 1008 const Eolian_Function *func;
1015 const Eolian_Function_Parameter *param; 1009 const Eolian_Function_Parameter *param;
1010 Eina_Iterator *iter;
1016 1011
1017 eolian_init(); 1012 eolian_init();
1018 1013
@@ -1022,26 +1017,35 @@ START_TEST(eolian_null)
1022 fail_if(!(class = eolian_class_get_by_name("Null"))); 1017 fail_if(!(class = eolian_class_get_by_name("Null")));
1023 fail_if(!(func = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD))); 1018 fail_if(!(func = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
1024 1019
1020 fail_if(!(iter = eolian_function_parameters_get(func)));
1021
1025 /* no qualifiers */ 1022 /* no qualifiers */
1026 fail_if(!(param = eolian_function_parameter_get_by_name(func, "x"))); 1023 fail_if(!(eina_iterator_next(iter, (void**)&param)));
1024 fail_if(strcmp(eolian_parameter_name_get(param), "x"));
1027 fail_if(eolian_parameter_is_nullable(param)); 1025 fail_if(eolian_parameter_is_nullable(param));
1028 fail_if(eolian_parameter_is_optional(param)); 1026 fail_if(eolian_parameter_is_optional(param));
1029 1027
1030 /* nullable */ 1028 /* nullable */
1031 fail_if(!(param = eolian_function_parameter_get_by_name(func, "y"))); 1029 fail_if(!(eina_iterator_next(iter, (void**)&param)));
1030 fail_if(strcmp(eolian_parameter_name_get(param), "y"));
1032 fail_if(!eolian_parameter_is_nullable(param)); 1031 fail_if(!eolian_parameter_is_nullable(param));
1033 fail_if(eolian_parameter_is_optional(param)); 1032 fail_if(eolian_parameter_is_optional(param));
1034 1033
1035 /* optional */ 1034 /* optional */
1036 fail_if(!(param = eolian_function_parameter_get_by_name(func, "z"))); 1035 fail_if(!(eina_iterator_next(iter, (void**)&param)));
1036 fail_if(strcmp(eolian_parameter_name_get(param), "z"));
1037 fail_if(eolian_parameter_is_nullable(param)); 1037 fail_if(eolian_parameter_is_nullable(param));
1038 fail_if(!eolian_parameter_is_optional(param)); 1038 fail_if(!eolian_parameter_is_optional(param));
1039 1039
1040 /* both */ 1040 /* both */
1041 fail_if(!(param = eolian_function_parameter_get_by_name(func, "w"))); 1041 fail_if(!(eina_iterator_next(iter, (void**)&param)));
1042 fail_if(strcmp(eolian_parameter_name_get(param), "w"));
1042 fail_if(!eolian_parameter_is_nullable(param)); 1043 fail_if(!eolian_parameter_is_nullable(param));
1043 fail_if(!eolian_parameter_is_optional(param)); 1044 fail_if(!eolian_parameter_is_optional(param));
1044 1045
1046 fail_if(eina_iterator_next(iter, (void**)&param));
1047 eina_iterator_free(iter);
1048
1045 eolian_shutdown(); 1049 eolian_shutdown();
1046} 1050}
1047END_TEST 1051END_TEST