summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-05-06 12:56:16 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-05-06 12:57:01 +0100
commit8df2686d9023cac7420fbad0f1d0db105c344d85 (patch)
tree1a32ab3c66f8f6a1f5c970527a9b7085c942ac43
parent4a1733f5c85e326011dfd5c69119d713abb4c7db (diff)
eolian: lift restriction on namespace/class name conflicts in library
This will allow us to name classes the same as namespaces.
-rw-r--r--src/lib/eolian/database_constructor_api.c17
-rw-r--r--src/lib/eolian/database_implement_api.c17
-rw-r--r--src/lib/eolian/eolian_database.c41
-rw-r--r--src/lib/eolian/eolian_database.h2
4 files changed, 13 insertions, 64 deletions
diff --git a/src/lib/eolian/database_constructor_api.c b/src/lib/eolian/database_constructor_api.c
index 9e44e75199..6eedefd50e 100644
--- a/src/lib/eolian/database_constructor_api.c
+++ b/src/lib/eolian/database_constructor_api.c
@@ -12,25 +12,12 @@ eolian_constructor_full_name_get(const Eolian_Constructor *ctor)
12 return ctor->full_name; 12 return ctor->full_name;
13} 13}
14 14
15static Eina_Bool
16_fill_class(Eolian_Constructor *ctor)
17{
18 const Eolian_Class *class = NULL;
19 if (ctor->klass)
20 return EINA_TRUE;
21 if (!database_class_name_validate(ctor->full_name, &class) || !class)
22 return EINA_FALSE;
23 ctor->klass = class;
24 return EINA_TRUE;
25}
26
27EAPI const Eolian_Class * 15EAPI const Eolian_Class *
28eolian_constructor_class_get(const Eolian_Constructor *ctor) 16eolian_constructor_class_get(const Eolian_Constructor *ctor)
29{ 17{
30 EINA_SAFETY_ON_NULL_RETURN_VAL(ctor, NULL); 18 EINA_SAFETY_ON_NULL_RETURN_VAL(ctor, NULL);
31 if (!_fill_class((Eolian_Constructor*)ctor)) 19 Eolian_Constructor *mctor = (Eolian_Constructor *)ctor;
32 return NULL; 20 return database_object_class_fill(ctor->full_name, &mctor->klass);
33 return ctor->klass;
34} 21}
35 22
36EAPI const Eolian_Function * 23EAPI const Eolian_Function *
diff --git a/src/lib/eolian/database_implement_api.c b/src/lib/eolian/database_implement_api.c
index 7d3fd2c1b6..8f628c4b9d 100644
--- a/src/lib/eolian/database_implement_api.c
+++ b/src/lib/eolian/database_implement_api.c
@@ -12,25 +12,12 @@ eolian_implement_full_name_get(const Eolian_Implement *impl)
12 return impl->full_name; 12 return impl->full_name;
13} 13}
14 14
15static Eina_Bool
16_fill_class(Eolian_Implement *impl)
17{
18 const Eolian_Class *class = NULL;
19 if (impl->klass)
20 return EINA_TRUE;
21 if (!database_class_name_validate(impl->full_name, &class) || !class)
22 return EINA_FALSE;
23 impl->klass = class;
24 return EINA_TRUE;
25}
26
27EAPI const Eolian_Class * 15EAPI const Eolian_Class *
28eolian_implement_class_get(const Eolian_Implement *impl) 16eolian_implement_class_get(const Eolian_Implement *impl)
29{ 17{
30 EINA_SAFETY_ON_NULL_RETURN_VAL(impl, NULL); 18 EINA_SAFETY_ON_NULL_RETURN_VAL(impl, NULL);
31 if (!_fill_class((Eolian_Implement*)impl)) 19 Eolian_Implement *mimpl = (Eolian_Implement *)impl;
32 return NULL; 20 return database_object_class_fill(impl->full_name, &mimpl->klass);
33 return impl->klass;
34} 21}
35 22
36EAPI const Eolian_Function * 23EAPI const Eolian_Function *
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index 67f056ed48..8520ca42fc 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -275,42 +275,17 @@ database_class_to_filename(const char *cname)
275 return ret; 275 return ret;
276} 276}
277 277
278/* 278const Eolian_Class *
279 * ret false -> clash, class = NULL 279database_object_class_fill(const char *class_name, const Eolian_Class **cl)
280 * ret true && class -> only one class corresponding
281 * ret true && !class -> no class corresponding
282 */
283Eina_Bool
284database_class_name_validate(const char *class_name, const Eolian_Class **cl)
285{ 280{
281 if (*cl) return *cl;
286 char *name = strdup(class_name); 282 char *name = strdup(class_name);
287 char *colon = name + 1; 283 char *ldot = strrchr(name + 1, '.');
288 const Eolian_Class *found_class = NULL; 284 if (ldot) *ldot = '\0';
289 const Eolian_Class *candidate; 285 const Eolian_Class *found = eolian_class_get_by_name(name);
290 if (cl) *cl = NULL; 286 *cl = found;
291 do
292 {
293 colon = strchr(colon, '.');
294 if (colon) *colon = '\0';
295 candidate = eolian_class_get_by_name(name);
296 if (candidate)
297 {
298 if (found_class)
299 {
300 fprintf(stderr, "eolian: name clash between classes '%s' and '%s'\n",
301 candidate->full_name,
302 found_class->full_name);
303 free(name);
304 return EINA_FALSE; // Names clash
305 }
306 found_class = candidate;
307 }
308 if (colon) *colon++ = '.';
309 }
310 while(colon);
311 if (cl) *cl = found_class;
312 free(name); 287 free(name);
313 return EINA_TRUE; 288 return found;
314} 289}
315 290
316EAPI Eina_Bool 291EAPI Eina_Bool
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index d57ea30bfa..a232ff6be9 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -284,7 +284,7 @@ int database_shutdown(void);
284 284
285char *database_class_to_filename(const char *cname); 285char *database_class_to_filename(const char *cname);
286Eina_Bool database_validate(Eina_Bool silent_types); 286Eina_Bool database_validate(Eina_Bool silent_types);
287Eina_Bool database_class_name_validate(const char *class_name, const Eolian_Class **cl); 287const Eolian_Class *database_object_class_fill(const char *class_name, const Eolian_Class **cl);
288 288
289void database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type, 289void database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type,
290 Eina_Stringshare *file, void *ptr); 290 Eina_Stringshare *file, void *ptr);