cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=e12456f3e7fd252640d04c44a4b75340aaede593

commit e12456f3e7fd252640d04c44a4b75340aaede593
Author: Jee-Yong Um <con...@gmail.com>
Date:   Mon Jan 4 15:15:31 2016 -0800

    edje_cc: abort when insert_before/after part doesn't exist
    
    Summary:
    edje_cc does not check whether insert_before/after part exists.
    edje_cc will notify a compilation error to developer when insert_before
    or insert_after part does not exist.
    
    T2513
    
    Reviewers: Hermet, NikaWhite
    
    Subscribers: cedric, jpeg
    
    Maniphest Tasks: T2513
    
    Differential Revision: https://phab.enlightenment.org/D3517
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/bin/edje/edje_cc.h          |  1 +
 src/bin/edje/edje_cc_handlers.c | 14 ++++++++++++--
 src/bin/edje/edje_cc_out.c      | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/src/bin/edje/edje_cc.h b/src/bin/edje/edje_cc.h
index b4da941..aa49caa 100644
--- a/src/bin/edje/edje_cc.h
+++ b/src/bin/edje/edje_cc.h
@@ -240,6 +240,7 @@ char   *mem_strdup(const char *s);
 #define SZ sizeof
 
 void    using_file(const char *filename, const char type);
+Eina_Bool needed_part_exists(Edje_Part_Collection *pc, const char *name);
 
 void    error_and_abort(Eet_File *ef, const char *fmt, ...);
 
diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c
index 5d830a3..32c8ba8 100644
--- a/src/bin/edje/edje_cc_handlers.c
+++ b/src/bin/edje/edje_cc_handlers.c
@@ -5982,11 +5982,16 @@ st_collections_group_parts_part_physics_body(void)
 static void
 st_collections_group_parts_part_insert_before(void)
 {
+   Edje_Part_Collection *pc;
    Edje_Part_Parser *epp;
+   char *name;
+
    check_arg_count(1);
 
+   pc = eina_list_data_get(eina_list_last(edje_collections));
+   name = parse_str(0);
    epp = (Edje_Part_Parser *)current_part;
-   epp->reorder.insert_before = parse_str(0);
+   epp->reorder.insert_before = name;
 }
 
 /**
@@ -6005,11 +6010,16 @@ st_collections_group_parts_part_insert_before(void)
 static void
 st_collections_group_parts_part_insert_after(void)
 {
+   Edje_Part_Collection *pc;
    Edje_Part_Parser *epp;
+   char *name;
+
    check_arg_count(1);
 
+   pc = eina_list_data_get(eina_list_last(edje_collections));
+   name = parse_str(0);
    epp = (Edje_Part_Parser *)current_part;
-   epp->reorder.insert_after = parse_str(0);
+   epp->reorder.insert_after = name;
 }
 
 /**
diff --git a/src/bin/edje/edje_cc_out.c b/src/bin/edje/edje_cc_out.c
index c5c439a..cc11fad 100644
--- a/src/bin/edje/edje_cc_out.c
+++ b/src/bin/edje/edje_cc_out.c
@@ -2609,6 +2609,8 @@ reorder_parts(void)
                        if (ep->reorder.insert_before &&
                            !strcmp(ep->reorder.insert_before, 
pc->parts[j]->name))
                          {
+                            needed_part_exists(pc, ep->reorder.insert_before);
+
                             ep2 = (Edje_Part_Parser *)pc->parts[j];
                             if (ep2->reorder.after)
                               ERR("The part \"%s\" is ambiguous ordered part.",
@@ -2619,7 +2621,7 @@ reorder_parts(void)
                             /* Need it to be able to insert an element before 
the first */
                             if (j == 0) k = 0;
                             else k = j - 1;
-                           found = EINA_TRUE;
+                            found = EINA_TRUE;
                             ep2->reorder.linked_prev += 
ep->reorder.linked_prev + 1;
                             ep->reorder.before = (Edje_Part_Parser 
*)pc->parts[j];
                             while (ep2->reorder.before)
@@ -2630,15 +2632,17 @@ reorder_parts(void)
                             break;
                          }
                        else if (ep->reorder.insert_after &&
-                           !strcmp(ep->reorder.insert_after, 
pc->parts[j]->name))
+                                !strcmp(ep->reorder.insert_after, 
pc->parts[j]->name))
                          {
+                            needed_part_exists(pc, ep->reorder.insert_after);
+
                             ep2 = (Edje_Part_Parser *)pc->parts[j];
                             if (ep2->reorder.before)
                               ERR("The part \"%s\" is ambiguous ordered 
part.", pc->parts[i]->name);
                             if (ep2->reorder.linked_next)
                               ERR("Unable to insert two or more parts in same 
part \"%s\".", pc->parts[j]->name);
                             k = j;
-                           found = EINA_TRUE;
+                            found = EINA_TRUE;
                             ep2->reorder.linked_next += 
ep->reorder.linked_next + 1;
                             ep->reorder.after = (Edje_Part_Parser 
*)pc->parts[j];
                             while (ep2->reorder.after)
@@ -4109,3 +4113,29 @@ using_file(const char *filename, const char type)
         fclose(f);
      }
 }
+
+Eina_Bool
+needed_part_exists(Edje_Part_Collection *pc, const char *name)
+{
+   Eina_Bool found;
+   unsigned int i;
+
+   found = EINA_FALSE;
+
+   for (i = 0; i < pc->parts_count; i++)
+     {
+        if (!strcmp(pc->parts[i]->name, name))
+          {
+             found = EINA_TRUE;
+             break;
+          }
+     }
+
+   if (!found)
+     {
+        ERR("Unable to find part name \"%s\" needed in group \"%s\".",
+            name, pc->part);
+        exit(-1);
+     }
+   return found;
+}

-- 


Reply via email to