eolian: return Eolian_Object_Type from ref resolver
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Fri, 9 Mar 2018 14:19:53 +0000 (15:19 +0100)
committerWonki Kim <wonki_.kim@samsung.com>
Tue, 10 Apr 2018 11:10:52 +0000 (20:10 +0900)
This needs only one enum and allows for better interop.

src/bindings/luajit/eolian.lua
src/lib/eolian/Eolian.h
src/lib/eolian/database_validate.c
src/lib/eolian/eolian_database.c
src/scripts/pyolian/eolian.py
src/scripts/pyolian/eolian_lib.py
src/scripts/pyolian/generator.py
src/tests/eolian/eolian_parsing.c

index 7f1b659..ac8ad59 100644 (file)
@@ -276,19 +276,6 @@ ffi.cdef [[
         EOLIAN_DOC_TOKEN_MARKUP_MONOSPACE
     } Eolian_Doc_Token_Type;
 
-    typedef enum {
-        EOLIAN_DOC_REF_INVALID = 0,
-        EOLIAN_DOC_REF_CLASS,
-        EOLIAN_DOC_REF_FUNC,
-        EOLIAN_DOC_REF_EVENT,
-        EOLIAN_DOC_REF_ALIAS,
-        EOLIAN_DOC_REF_STRUCT,
-        EOLIAN_DOC_REF_STRUCT_FIELD,
-        EOLIAN_DOC_REF_ENUM,
-        EOLIAN_DOC_REF_ENUM_FIELD,
-        EOLIAN_DOC_REF_VAR
-    } Eolian_Doc_Ref_Type;
-
     typedef struct _Eolian_Doc_Token {
         Eolian_Doc_Token_Type type;
         const char *text, *text_end;
@@ -494,7 +481,7 @@ ffi.cdef [[
     void eolian_doc_token_init(Eolian_Doc_Token *tok);
     Eolian_Doc_Token_Type eolian_doc_token_type_get(const Eolian_Doc_Token *tok);
     char *eolian_doc_token_text_get(const Eolian_Doc_Token *tok);
-    Eolian_Doc_Ref_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
+    Eolian_Object_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
 ]]
 
 local cutil = require("cutil")
@@ -1815,19 +1802,6 @@ M.doc_token_type = {
     MARKUP_MONOSPACE = 7
 }
 
-M.doc_ref_type = {
-    INVALID      = 0,
-    CLASS        = 1,
-    FUNC         = 2,
-    EVENT        = 3,
-    ALIAS        = 4,
-    STRUCT       = 5,
-    STRUCT_FIELD = 6,
-    ENUM         = 7,
-    ENUM_FIELD   = 8,
-    VAR          = 9
-}
-
 M.documentation_string_split = function(str)
     if not str then
         return {}
@@ -1881,7 +1855,7 @@ M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", {
         ref_get = function(self, unit)
             local stor = ffi.new("const void *[2]")
             local tp = tonumber(eolian.eolian_doc_token_ref_get(unit, self, stor, stor + 1))
-            local reft = M.doc_ref_type
+            local reft = M.object_type
             if tp == reft.CLASS then
                 return tp, ffi.cast("const Eolian_Class *", stor[0])
             elseif tp == reft.FUNC then
@@ -1905,7 +1879,7 @@ M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", {
             elseif tp == reft.VAR then
                 return tp, ffi.cast("const Eolian_Variable *", stor[0])
             else
-                return reft.INVALID
+                return reft.UNKNOWN
             end
         end
     }
index 4c460fa..1d34e0d 100644 (file)
@@ -449,20 +449,6 @@ typedef enum
    EOLIAN_DOC_TOKEN_MARKUP_MONOSPACE
 } Eolian_Doc_Token_Type;
 
-typedef enum
-{
-   EOLIAN_DOC_REF_INVALID = 0,
-   EOLIAN_DOC_REF_CLASS,
-   EOLIAN_DOC_REF_FUNC,
-   EOLIAN_DOC_REF_EVENT,
-   EOLIAN_DOC_REF_ALIAS,
-   EOLIAN_DOC_REF_STRUCT,
-   EOLIAN_DOC_REF_STRUCT_FIELD,
-   EOLIAN_DOC_REF_ENUM,
-   EOLIAN_DOC_REF_ENUM_FIELD,
-   EOLIAN_DOC_REF_VAR
-} Eolian_Doc_Ref_Type;
-
 typedef struct _Eolian_Doc_Token
 {
    Eolian_Doc_Token_Type type;
@@ -2779,7 +2765,7 @@ EAPI char *eolian_doc_token_text_get(const Eolian_Doc_Token *tok);
 /*
  * @brief Get the thing that a reference token references.
  *
- * Returns EOLIAN_DOC_REF_INVALID on failure (when not ref token or
+ * Returns EOLIAN_OBJECT_UNKNOWN on failure (when not ref token or
  * invalid ref, but invalid refs don't happen when database is valid).
  *
  * When the reference is a class, alias, struct, enum or var, the first data arg
@@ -2794,7 +2780,7 @@ EAPI char *eolian_doc_token_text_get(const Eolian_Doc_Token *tok);
  * @param[out] data2 the secondary data
  * @return the kind of reference this is
  */
-EAPI Eolian_Doc_Ref_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
+EAPI Eolian_Object_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
 
 #endif
 
index 90a0b54..5733db3 100644 (file)
@@ -35,7 +35,7 @@ _validate_docstr(const Eolian_Unit *src, Eina_Stringshare *str, const Eolian_Obj
         eolian_doc_token_init(&tok);
         while (ret && (doc = eolian_documentation_tokenize(doc, &tok)))
           if (eolian_doc_token_type_get(&tok) == EOLIAN_DOC_TOKEN_REF)
-            if (eolian_doc_token_ref_get(src, &tok, NULL, NULL) == EOLIAN_DOC_REF_INVALID)
+            if (eolian_doc_token_ref_get(src, &tok, NULL, NULL) == EOLIAN_OBJECT_UNKNOWN)
               {
                  char *refn = eolian_doc_token_text_get(&tok);
                  _eolian_log_line(info->file, info->line, info->column,
index 412f295..bd4d22a 100644 (file)
@@ -289,38 +289,38 @@ eolian_doc_token_text_get(const Eolian_Doc_Token *tok)
    return ptr;
 }
 
-static Eolian_Doc_Ref_Type
+static Eolian_Object_Type
 _resolve_event(const Eolian_Unit *src, char *name, const void **data,
                const void **data2)
 {
    /* never trust the user */
    if (name[0] == ',')
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    char *evname = strrchr(name, '.');
    if (!evname)
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    *evname++ = '\0';
    const Eolian_Class *cl = eolian_unit_class_by_name_get(src, name);
    if (!cl)
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    const Eolian_Event *ev = eolian_class_event_get_by_name(cl, evname);
    if (!ev)
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    if (data) *data = cl;
    if (data2) *data2 = ev;
-   return EOLIAN_DOC_REF_EVENT;
+   return EOLIAN_OBJECT_EVENT;
 }
 
-EAPI Eolian_Doc_Ref_Type
+EAPI Eolian_Object_Type
 eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
                          const void **data, const void **data2)
 {
    if (tok->type != EOLIAN_DOC_TOKEN_REF)
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    size_t nlen = tok->text_end - tok->text;
 
@@ -343,27 +343,16 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
    if (decl)
      {
        if (data) *data = decl;
-       switch (eolian_object_type_get(decl))
+       Eolian_Object_Type tp = eolian_object_type_get(decl);
+       switch (tp)
          {
           case EOLIAN_OBJECT_CLASS:
-            return EOLIAN_DOC_REF_CLASS;
           case EOLIAN_OBJECT_TYPEDECL:
-            switch (eolian_typedecl_type_get((Eolian_Typedecl *)decl))
-              {
-               case EOLIAN_TYPEDECL_ALIAS:
-                 return EOLIAN_DOC_REF_ALIAS;
-               case EOLIAN_TYPEDECL_STRUCT:
-               case EOLIAN_TYPEDECL_STRUCT_OPAQUE:
-                 return EOLIAN_DOC_REF_STRUCT;
-               case EOLIAN_TYPEDECL_ENUM:
-                 return EOLIAN_DOC_REF_ENUM;
-               default:
-                 return EOLIAN_DOC_REF_INVALID;
-              }
           case EOLIAN_OBJECT_VARIABLE:
-            return EOLIAN_DOC_REF_VAR;
+            /* we only allow certain types to be referenced */
+            return tp;
           default:
-            return EOLIAN_DOC_REF_INVALID;
+            return EOLIAN_OBJECT_UNKNOWN;
          }
      }
 
@@ -372,7 +361,7 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
    char *suffix = strrchr(name, '.');
    /* no suffix, therefore invalid */
    if (!suffix)
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    /* name will terminate before suffix, suffix will be standalone */
    *suffix++ = '\0';
@@ -384,10 +373,10 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
         const Eolian_Struct_Type_Field *fld = eolian_typedecl_struct_field_get(tpd, suffix);
         /* field itself is invalid */
         if (!fld)
-          return EOLIAN_DOC_REF_INVALID;
+          return EOLIAN_OBJECT_UNKNOWN;
         if (data) *data = tpd;
         if (data2) *data2 = fld;
-        return EOLIAN_DOC_REF_STRUCT_FIELD;
+        return EOLIAN_OBJECT_STRUCT_FIELD;
      }
 
    /* try an enum field */
@@ -397,10 +386,10 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
         const Eolian_Enum_Type_Field *fld = eolian_typedecl_enum_field_get(tpd, suffix);
         /* field itself is invalid */
         if (!fld)
-          return EOLIAN_DOC_REF_INVALID;
+          return EOLIAN_OBJECT_UNKNOWN;
         if (data) *data = tpd;
         if (data2) *data2 = fld;
-        return EOLIAN_DOC_REF_ENUM_FIELD;
+        return EOLIAN_OBJECT_ENUM_FIELD;
      }
 
    /* now it can only be a function or invalid */
@@ -416,23 +405,23 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
         suffix = strrchr(name, '.');
         /* wrong suffix, therefore invalid */
         if (!suffix)
-          return EOLIAN_DOC_REF_INVALID;
+          return EOLIAN_OBJECT_UNKNOWN;
         /* re-terminate */
         *suffix++ = '\0';
      }
 
    const Eolian_Class *cl = eolian_unit_class_by_name_get(unit, name);
    if (!cl)
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    const Eolian_Function *fid = eolian_class_function_get_by_name(cl, suffix, ftype);
    if (!fid)
-     return EOLIAN_DOC_REF_INVALID;
+     return EOLIAN_OBJECT_UNKNOWN;
 
    /* got a func */
    if (data) *data = cl;
    if (data2) *data2 = fid;
-   return EOLIAN_DOC_REF_FUNC;
+   return EOLIAN_OBJECT_FUNCTION;
 }
 
 void
index e3ce9d6..998006b 100644 (file)
@@ -234,18 +234,6 @@ class Eolian_Doc_Token_Type(IntEnum):
     MARK_TODO = 6
     MARKUP_MONOSPACE = 7
 
-class Eolian_Doc_Ref_Type(IntEnum):
-    INVALID = 0
-    CLASS = 1
-    FUNC = 2
-    EVENT = 3
-    ALIAS = 4
-    STRUCT = 5
-    STRUCT_FIELD = 6
-    ENUM = 7
-    ENUM_FIELD = 8
-    VAR = 9
-
 
 ###  internal Classes  ########################################################
 
index e226bc1..30d124f 100644 (file)
@@ -831,7 +831,7 @@ lib.eolian_doc_token_type_get.restype = c_int
 lib.eolian_doc_token_text_get.argtypes = [c_void_p,]
 lib.eolian_doc_token_text_get.restype = c_void_p  # char* TO BE FREED
 
-# EAPI Eolian_Doc_Ref_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
+# EAPI Eolian_Object_Type eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok, const void **data, const void **data2);
 #  lib.eolian_doc_token_ref_get.argtypes = [c_void_p, c_void_p, ???, ???]
 #  lib.eolian_doc_token_ref_get.restype = c_int
 
index 067d7b5..64e6abe 100755 (executable)
@@ -129,6 +129,7 @@ class Template(pyratemp.Template):
             'Documentation': eolian.Documentation,
             'Documentation_Token': eolian.Documentation_Token,
             # Eolian Enums
+            'Eolian_Object_Type': eolian.Eolian_Object_Type,
             'Eolian_Function_Type': eolian.Eolian_Function_Type,
             'Eolian_Parameter_Dir': eolian.Eolian_Parameter_Dir,
             'Eolian_Class_Type': eolian.Eolian_Class_Type,
@@ -142,9 +143,7 @@ class Template(pyratemp.Template):
             'Eolian_Variable_Type': eolian.Eolian_Variable_Type,
             'Eolian_Binary_Operator': eolian.Eolian_Binary_Operator,
             'Eolian_Unary_Operator': eolian.Eolian_Unary_Operator,
-            'Eolian_Declaration_Type': eolian.Eolian_Declaration_Type,
             'Eolian_Doc_Token_Type': eolian.Eolian_Doc_Token_Type,
-            'Eolian_Doc_Ref_Type': eolian.Eolian_Doc_Ref_Type,
         })
 
         # Call the parent __init__ func
index 00ca5ec..f333a84 100644 (file)
@@ -1256,7 +1256,7 @@ START_TEST(eolian_docs)
    fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_REF);
    txt = eolian_doc_token_text_get(&tok);
    fail_if(strcmp(txt, "pants"));
-   fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_DOC_REF_VAR);
+   fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_OBJECT_VARIABLE);
    free(txt);
    tdoc = eolian_documentation_tokenize(tdoc, &tok);
    fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_TEXT);
@@ -1267,7 +1267,7 @@ START_TEST(eolian_docs)
    fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_REF);
    txt = eolian_doc_token_text_get(&tok);
    fail_if(strcmp(txt, "Docs.meth"));
-   fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_DOC_REF_FUNC);
+   fail_if(eolian_doc_token_ref_get(unit, &tok, NULL, NULL) != EOLIAN_OBJECT_FUNCTION);
    free(txt);
    tdoc = eolian_documentation_tokenize(tdoc, &tok);
    fail_if(eolian_doc_token_type_get(&tok) != EOLIAN_DOC_TOKEN_TEXT);