summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-10-24 23:39:14 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-10-24 23:39:14 +0200
commit88083b0f14ad887d37cac49d66376ffab86e7431 (patch)
tree4395a9e113047ac5b20a09787a669a8d023807ba
parent05b395be47f49dfa9b3ded75ab1de95ef8ab07bf (diff)
eolian: check for inheritance tree function conflicts
Now a class cannot define a method/property of some name if there already is something of the same name within the inheritance tree.
-rw-r--r--src/lib/eolian/database_validate.c62
1 files changed, 41 insertions, 21 deletions
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index edd5d2c4c6..36b8c1c476 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -96,10 +96,9 @@ _ef_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
96} 96}
97 97
98static Eina_Bool 98static Eina_Bool
99_type_error(const Eolian_Type *tp, const char *msg) 99_obj_error(const Eolian_Object *o, const char *msg)
100{ 100{
101 fprintf(stderr, "eolian:%s:%d:%d: %s\n", tp->base.file, tp->base.line, 101 fprintf(stderr, "eolian:%s:%d:%d: %s\n", o->file, o->line, o->column, msg);
102 tp->base.column, msg);
103 return EINA_FALSE; 102 return EINA_FALSE;
104} 103}
105 104
@@ -172,7 +171,7 @@ _validate_type(Eolian_Type *tp)
172 if (tp->owned && !database_type_is_ownable(tp)) 171 if (tp->owned && !database_type_is_ownable(tp))
173 { 172 {
174 snprintf(buf, sizeof(buf), "type '%s' is not ownable", tp->full_name); 173 snprintf(buf, sizeof(buf), "type '%s' is not ownable", tp->full_name);
175 return _type_error(tp, buf); 174 return _obj_error(&tp->base, buf);
176 } 175 }
177 176
178 switch (tp->type) 177 switch (tp->type)
@@ -231,7 +230,7 @@ _validate_type(Eolian_Type *tp)
231 if (!tpp) 230 if (!tpp)
232 { 231 {
233 snprintf(buf, sizeof(buf), "undefined type %s", tp->full_name); 232 snprintf(buf, sizeof(buf), "undefined type %s", tp->full_name);
234 return _type_error(tp, buf); 233 return _obj_error(&tp->base, buf);
235 } 234 }
236 if (!_validate_typedecl(tpp)) 235 if (!_validate_typedecl(tpp))
237 return EINA_FALSE; 236 return EINA_FALSE;
@@ -246,7 +245,7 @@ _validate_type(Eolian_Type *tp)
246 { 245 {
247 snprintf(buf, sizeof(buf), "undefined class %s " 246 snprintf(buf, sizeof(buf), "undefined class %s "
248 "(likely wrong namespacing)", tp->full_name); 247 "(likely wrong namespacing)", tp->full_name);
249 return _type_error(tp, buf); 248 return _obj_error(&tp->base, buf);
250 } 249 }
251 if (!tp->freefunc) 250 if (!tp->freefunc)
252 tp->freefunc = eina_stringshare_add(eo_obj_free); 251 tp->freefunc = eina_stringshare_add(eo_obj_free);
@@ -288,14 +287,25 @@ _validate_param(Eolian_Function_Parameter *param)
288} 287}
289 288
290static Eina_Bool 289static Eina_Bool
291_validate_function(Eolian_Function *func) 290_validate_function(Eolian_Function *func, Eina_Hash *nhash)
292{ 291{
293 Eina_List *l; 292 Eina_List *l;
294 Eolian_Function_Parameter *param; 293 Eolian_Function_Parameter *param;
294 char buf[512];
295 295
296 if (func->base.validated) 296 if (func->base.validated)
297 return EINA_TRUE; 297 return EINA_TRUE;
298 298
299 const Eolian_Function *ofunc = eina_hash_find(nhash, func->name);
300 if (ofunc)
301 {
302 snprintf(buf, sizeof(buf),
303 "function '%s' redefined (originally at %s:%d:%d)",
304 func->name, ofunc->base.file,
305 ofunc->base.line, ofunc->base.column);
306 return _obj_error(&func->base, buf);
307 }
308
299 if (func->get_ret_type && !_validate_type(func->get_ret_type)) 309 if (func->get_ret_type && !_validate_type(func->get_ret_type))
300 return EINA_FALSE; 310 return EINA_FALSE;
301 311
@@ -364,13 +374,14 @@ _validate_implement(Eolian_Implement *impl)
364} 374}
365 375
366static Eina_Bool 376static Eina_Bool
367_validate_class(Eolian_Class *cl) 377_validate_class(Eolian_Class *cl, Eina_Hash *nhash)
368{ 378{
369 Eina_List *l; 379 Eina_List *l;
370 Eolian_Function *func; 380 Eolian_Function *func;
371 Eolian_Event *event; 381 Eolian_Event *event;
372 Eolian_Implement *impl; 382 Eolian_Implement *impl;
373 const char *iname; 383 const char *iname;
384 Eina_Bool res = EINA_TRUE;
374 385
375 if (!cl) 386 if (!cl)
376 return EINA_FALSE; /* if this happens something is very wrong though */ 387 return EINA_FALSE; /* if this happens something is very wrong though */
@@ -378,31 +389,40 @@ _validate_class(Eolian_Class *cl)
378 if (cl->base.validated) 389 if (cl->base.validated)
379 return EINA_TRUE; 390 return EINA_TRUE;
380 391
392 Eina_Bool ahash = (nhash == NULL);
393 if (ahash)
394 nhash = eina_hash_string_small_new(NULL);
395
381 EINA_LIST_FOREACH(cl->inherits, l, iname) 396 EINA_LIST_FOREACH(cl->inherits, l, iname)
382 { 397 {
383 if (!_validate_class(eina_hash_find(_classes, iname))) 398 if (!(res = _validate_class(eina_hash_find(_classes, iname), nhash)))
384 return EINA_FALSE; 399 goto freehash;
385 } 400 }
386 401
387 EINA_LIST_FOREACH(cl->properties, l, func) 402 EINA_LIST_FOREACH(cl->properties, l, func)
388 if (!_validate_function(func)) 403 if (!(res = _validate_function(func, nhash)))
389 return EINA_FALSE; 404 goto freehash;
390 405
391 EINA_LIST_FOREACH(cl->methods, l, func) 406 EINA_LIST_FOREACH(cl->methods, l, func)
392 if (!_validate_function(func)) 407 if (!(res = _validate_function(func, nhash)))
393 return EINA_FALSE; 408 goto freehash;
394 409
395 EINA_LIST_FOREACH(cl->events, l, event) 410 EINA_LIST_FOREACH(cl->events, l, event)
396 if (!_validate_event(event)) 411 if (!(res = _validate_event(event)))
397 return EINA_FALSE; 412 goto freehash;
398 413
399 EINA_LIST_FOREACH(cl->implements, l, impl) 414 EINA_LIST_FOREACH(cl->implements, l, impl)
400 if (!_validate_implement(impl)) 415 if (!(res = _validate_implement(impl)))
401 return EINA_FALSE; 416 goto freehash;
402 417
403 if (!_validate_doc(cl->doc)) 418 if (!(res = _validate_doc(cl->doc)))
404 return EINA_FALSE; 419 goto freehash;
405 420
421freehash:
422 if (ahash)
423 eina_hash_free(nhash);
424 if (!res)
425 return EINA_FALSE;
406 return _validate(&cl->base); 426 return _validate(&cl->base);
407} 427}
408 428
@@ -446,7 +466,7 @@ database_validate()
446 /* FIXME: pass unit properly */ 466 /* FIXME: pass unit properly */
447 Eina_Iterator *iter = eolian_all_classes_get(NULL); 467 Eina_Iterator *iter = eolian_all_classes_get(NULL);
448 EINA_ITERATOR_FOREACH(iter, cl) 468 EINA_ITERATOR_FOREACH(iter, cl)
449 if (cl->toplevel && !_validate_class(cl)) 469 if (cl->toplevel && !_validate_class(cl, NULL))
450 { 470 {
451 eina_iterator_free(iter); 471 eina_iterator_free(iter);
452 return EINA_FALSE; 472 return EINA_FALSE;