eolian: add optional warning for regular classes in ext list
authorDaniel Kolesa <d.kolesa@samsung.com>
Fri, 30 Nov 2018 13:12:15 +0000 (14:12 +0100)
committerHermet Park <hermetpark@gmail.com>
Wed, 5 Dec 2018 05:52:40 +0000 (14:52 +0900)
As per T7240, we intend to disallow multi-class inheritance in Eo
at some point. In order to achieve that, it is necessary to find
out which classes still use multi-class inheritance and change
them accordingly.

Eo multi-class inheritance is not actually multi-class, as doing
so will simply treat all the other classes as interfaces, which
is misleading and poor design on its own.

By setting EOLIAN_CLASS_REGULAR_AS_EXT_WARN environment variable,
Eolian will now warn about such classes, allowing them to be
fixed.

Closes T7365.

src/lib/eolian/database_validate.c

index b44fc1221d0864dd646b4c230d88798b33a2fa8b..a96e38901056f7f80e14aefcbf79c81383940f42 100644 (file)
@@ -12,6 +12,7 @@ typedef struct _Validate_State
 {
    Eina_Bool warned;
    Eina_Bool event_redef;
+   Eina_Bool ext_regular;
 } Validate_State;
 
 static Eina_Bool
@@ -848,6 +849,23 @@ _validate_class(Validate_State *vals, Eolian_Class *cl,
 
    EINA_LIST_FOREACH(cl->extends, l, icl)
      {
+        if (!valid && vals->ext_regular) switch (icl->type)
+          {
+           case EOLIAN_CLASS_REGULAR:
+           case EOLIAN_CLASS_ABSTRACT:
+             /* regular class in extensions list, forbidden */
+             {
+                char buf[PATH_MAX];
+                snprintf(buf, sizeof(buf), "regular classes ('%s') cannot appear in extensions list of '%s'",
+                         icl->base.name, cl->base.name);
+                _obj_error(&cl->base, buf);
+                vals->warned = EINA_TRUE;
+                break;
+             }
+           default:
+             /* it's ok, interfaces are allowed */
+             break;
+          }
         if (!_validate_class(vals, icl, nhash, ehash, chash))
           return EINA_FALSE;
      }
@@ -928,7 +946,8 @@ database_validate(const Eolian_Unit *src)
 
    Validate_State vals = {
       EINA_FALSE,
-      !!getenv("EOLIAN_EVENT_REDEF_WARN")
+      !!getenv("EOLIAN_EVENT_REDEF_WARN"),
+      !!getenv("EOLIAN_CLASS_REGULAR_AS_EXT_WARN")
    };
 
    /* do an initial pass to refill inherits */