eolian: move ownable checks to validation stage
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Fri, 8 Sep 2017 12:22:13 +0000 (14:22 +0200)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Wed, 13 Sep 2017 21:58:47 +0000 (23:58 +0200)
src/lib/eolian/database_validate.c
src/lib/eolian/eo_parser.c

index 6df55d4b18b5300ceba858b5d5390e5e4e7fbfd8..a1774433136f0475e23248df283af4219990e1a3 100644 (file)
@@ -130,6 +130,14 @@ _validate_typedecl(const Eolian_Typedecl *tp)
 static Eina_Bool
 _validate_type(const Eolian_Type *tp)
 {
+   char buf[256];
+
+   if ((tp->is_own || tp->freefunc) && !database_type_is_ownable(tp))
+     {
+        snprintf(buf, sizeof(buf), "type '%s' is not ownable", tp->full_name);
+        return _type_error(tp, buf);
+     }
+
    switch (tp->type)
      {
       case EOLIAN_TYPE_VOID:
@@ -147,7 +155,6 @@ _validate_type(const Eolian_Type *tp)
            tpp = eolian_type_typedecl_get(tp);
            if (!tpp)
              {
-                char buf[256];
                 snprintf(buf, sizeof(buf), "undefined type %s", tp->full_name);
                 return _type_error(tp, buf);
              }
@@ -161,7 +168,6 @@ _validate_type(const Eolian_Type *tp)
            /* FIXME: pass unit properly */
            if (!eolian_type_class_get(NULL, tp))
              {
-                char buf[256];
                 snprintf(buf, sizeof(buf), "undefined class %s "
                          "(likely wrong namespacing)", tp->full_name);
                 return _type_error(tp, buf);
index 8e035f672fca6f9fa5356b591fa8afe7a55b7b2e..a0e5c83c2c85a78c5b6daa30dd0a21522b328b2a 100644 (file)
@@ -739,14 +739,7 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref, Eina_Bool allow_sarray)
            pline = ls->line_number;
            pcolumn = ls->column;
            check_next(ls, '(');
-           eo_lexer_context_push(ls);
            def = parse_type_void(ls, allow_ref, EINA_FALSE);
-           if (!database_type_is_ownable(def))
-             {
-                eo_lexer_context_restore(ls);
-                eo_lexer_syntax_error(ls, "ownable type expected");
-             }
-           eo_lexer_context_pop(ls);
            FILL_BASE(def->base, ls, line, col);
            def->is_own = EINA_TRUE;
            check_match(ls, ')', '(', pline, pcolumn);
@@ -759,14 +752,7 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref, Eina_Bool allow_sarray)
            pline = ls->line_number;
            pcolumn = ls->column;
            check_next(ls, '(');
-           eo_lexer_context_push(ls);
            def = parse_type_void(ls, allow_ref, EINA_FALSE);
-           if (!database_type_is_ownable(def))
-             {
-                eo_lexer_context_restore(ls);
-                eo_lexer_syntax_error(ls, "freeable type expected");
-             }
-           eo_lexer_context_pop(ls);
            check_next(ls, ',');
            check(ls, TOK_VALUE);
            def->freefunc = eina_stringshare_ref(ls->t.value.s);