eolian: type_typedecl_get doesn't need a unit
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Fri, 12 Jan 2018 16:52:44 +0000 (17:52 +0100)
committerWonki Kim <wonki_.kim@samsung.com>
Wed, 17 Jan 2018 09:19:29 +0000 (18:19 +0900)
14 files changed:
src/bin/eolian/headers.c
src/bin/eolian/sources.c
src/bindings/luajit/eolian.lua
src/lib/eolian/Eolian.h
src/lib/eolian/database_expr.c
src/lib/eolian/database_expr_api.c
src/lib/eolian/database_type.c
src/lib/eolian/database_type_api.c
src/lib/eolian/database_validate.c
src/lib/eolian/eolian_database.h
src/lib/eolian_cxx/grammar/klass_def.hpp
src/scripts/pyolian/eolian.py
src/scripts/pyolian/eolian_lib.py
src/tests/eolian/eolian_parsing.c

index b2fe73a..8ed0c8e 100644 (file)
@@ -16,7 +16,7 @@ _gen_param(const Eolian_Unit *src, Eina_Strbuf *buf,
            Eolian_Function_Parameter *pr, Eolian_Function_Type ftype, int *rpid)
 {
    const Eolian_Type *prt = eolian_parameter_type_get(pr);
-   const Eolian_Typedecl *ptd = eolian_type_typedecl_get(src, prt);
+   const Eolian_Typedecl *ptd = eolian_type_typedecl_get(prt);
    const char *prn = eolian_parameter_name_get(pr);
    Eina_Stringshare *prtn = eolian_type_c_type_get(src, prt, EOLIAN_C_TYPE_PARAM);
 
index a012e8c..eb7f385 100644 (file)
@@ -129,7 +129,7 @@ _append_defval(const Eolian_Unit *src, Eina_Strbuf *buf,
         eina_strbuf_append(buf, "NULL");
         return;
      }
-   const Eolian_Typedecl *tdcl = eolian_type_typedecl_get(src, btp);
+   const Eolian_Typedecl *tdcl = eolian_type_typedecl_get(btp);
    if (tdcl && (eolian_typedecl_type_get(tdcl) == EOLIAN_TYPEDECL_STRUCT))
      {
         char *sn = eo_gen_c_full_name_get(eolian_typedecl_full_name_get(tdcl));
@@ -430,7 +430,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Class *cl,
              const char *prn = eolian_parameter_name_get(pr);
              const Eolian_Type *pt = eolian_parameter_type_get(pr);
              Eina_Stringshare *ptn = eolian_type_c_type_get(src, pt, EOLIAN_C_TYPE_PARAM);
-             const Eolian_Typedecl *ptd = eolian_type_typedecl_get(src, pt);
+             const Eolian_Typedecl *ptd = eolian_type_typedecl_get(pt);
 
              Eina_Bool had_star = ptn[strlen(ptn) - 1] == '*';
              const char *add_star = _get_add_star(ftype, pd);
@@ -1061,7 +1061,7 @@ _gen_params(const Eolian_Unit *src, const Eolian_Function *fid,
              Eolian_Parameter_Dir pd = eolian_parameter_direction_get(pr);
              const char *prn = eolian_parameter_name_get(pr);
              const Eolian_Type *pt = eolian_parameter_type_get(pr);
-             const Eolian_Typedecl *ptd = eolian_type_typedecl_get(src, pt);
+             const Eolian_Typedecl *ptd = eolian_type_typedecl_get(pt);
              Eina_Stringshare *ptn = eolian_type_c_type_get(src, pt, EOLIAN_C_TYPE_PARAM);
 
              if (ptd && eolian_typedecl_type_get(ptd) == EOLIAN_TYPEDECL_FUNCTION_POINTER)
index 5ce81a0..940ad83 100644 (file)
@@ -399,7 +399,7 @@ ffi.cdef [[
     const Eolian_Type *eolian_type_base_type_get(const Eolian_Type *tp);
     const Eolian_Type *eolian_type_next_type_get(const Eolian_Type *tp);
     const Eolian_Type *eolian_typedecl_base_type_get(const Eolian_Typedecl *tp);
-    const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Unit *unit, const Eolian_Type *tp);
+    const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp);
 
     const Eolian_Type *eolian_type_aliased_base_get(const Eolian_Unit *unit, const Eolian_Type *tp);
     const Eolian_Type *eolian_typedecl_aliased_base_get(const Eolian_Unit *unit, const Eolian_Typedecl *tp);
@@ -841,8 +841,8 @@ M.Type = ffi.metatype("Eolian_Type", {
             return v
         end,
 
-        typedecl_get = function(self, unit)
-            local v = eolian.eolian_type_typedecl_get(unit, self)
+        typedecl_get = function(self)
+            local v = eolian.eolian_type_typedecl_get(self)
             if v == nil then return nil end
             return v
         end,
index 8e9017b..34b47c5 100644 (file)
@@ -1956,13 +1956,12 @@ EAPI const Eolian_Type *eolian_type_next_type_get(const Eolian_Type *tp);
  *
  * This tries to look up alias, struct and enum in that order.
  *
- * @param[in] unit the unit to look in
  * @param[in] tp the type.
  * @return the pointed to type decalration or NULL.
  *
  * @ingroup Eolian
  */
-EAPI const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Unit *unit, const Eolian_Type *tp);
+EAPI const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp);
 
 /*
  * @brief Get the lowest base type of an alias stack.
index 1b0a6d1..f22a09e 100644 (file)
@@ -522,7 +522,7 @@ eval_exp(const Eolian_Unit *unit, const Eolian_Expression *expr,
                      const Eolian_Type *etp = eolian_typedecl_base_type_get(etpd);
                      if (!etp || etp->type != EOLIAN_TYPE_REGULAR)
                        break;
-                     etpd = eolian_type_typedecl_get(unit, etp);
+                     etpd = database_type_decl_find(unit, etp);
                   }
 
                 if (!etpd) etpd = eolian_typedecl_enum_get_by_name(unit, fulln);
index adf5734..791d59e 100644 (file)
@@ -34,7 +34,7 @@ _eval_type(const Eolian_Unit *unit, const Eolian_Expression *expr,
            int  kw = eo_lexer_keyword_str_to_id(type->name);
            if (!kw || kw < KW_byte || kw >= KW_void)
              {
-                const Eolian_Typedecl *base = eolian_type_typedecl_get(unit, type);
+                const Eolian_Typedecl *base = database_type_decl_find(unit, type);
                 if (!base)
                   return err;
                 if (base->type == EOLIAN_TYPEDECL_ALIAS)
index 1400aa0..33be724 100644 (file)
@@ -79,7 +79,7 @@ database_type_is_ownable(const Eolian_Unit *unit, const Eolian_Type *tp)
         const char *ct = eo_lexer_get_c_type(kw);
         if (!ct)
           {
-             const Eolian_Typedecl *tpp = eolian_type_typedecl_get(unit, tp);
+             const Eolian_Typedecl *tpp = database_type_decl_find(unit, tp);
              if (!tpp)
                return EINA_FALSE;
              if (tpp->type == EOLIAN_TYPEDECL_FUNCTION_POINTER)
@@ -269,3 +269,23 @@ database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp,
         break;
      }
 }
+
+Eolian_Typedecl *database_type_decl_find(const Eolian_Unit *unit, const Eolian_Type *tp)
+{
+   if (tp->type != EOLIAN_TYPE_REGULAR)
+     return NULL;
+   if (tp->tdecl)
+     return tp->tdecl;
+   /* try looking up if it belongs to a struct, enum or an alias... otherwise
+    * return NULL, but first check for builtins
+    */
+   int  kw = eo_lexer_keyword_str_to_id(tp->full_name);
+   if (!kw || kw < KW_byte || kw >= KW_true)
+     {
+        Eolian_Declaration *decl = eina_hash_find(unit->state->unit.decls, tp->full_name);
+        if (decl && decl->type != EOLIAN_DECL_CLASS
+                 && decl->type != EOLIAN_DECL_VAR)
+          return decl->data;
+     }
+   return NULL;
+}
index 4528b7c..eedb42a 100644 (file)
@@ -266,23 +266,12 @@ eolian_type_next_type_get(const Eolian_Type *tp)
 }
 
 EAPI const Eolian_Typedecl *
-eolian_type_typedecl_get(const Eolian_Unit *unit, const Eolian_Type *tp)
+eolian_type_typedecl_get(const Eolian_Type *tp)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
    if (eolian_type_type_get(tp) != EOLIAN_TYPE_REGULAR)
      return NULL;
-   /* try looking up if it belongs to a struct, enum or an alias... otherwise
-    * return NULL, but first check for builtins
-    */
-   int  kw = eo_lexer_keyword_str_to_id(tp->full_name);
-   if (!kw || kw < KW_byte || kw >= KW_true)
-     {
-        Eolian_Declaration *decl = eina_hash_find(unit->state->unit.decls, tp->full_name);
-        if (decl && decl->type != EOLIAN_DECL_CLASS
-                 && decl->type != EOLIAN_DECL_VAR)
-          return decl->data;
-     }
-   return NULL;
+   return tp->tdecl;
 }
 
 EAPI const Eolian_Type *
@@ -297,7 +286,7 @@ eolian_type_aliased_base_get(const Eolian_Unit *unit, const Eolian_Type *tp)
 {
    if (!tp || tp->type != EOLIAN_TYPE_REGULAR || tp->is_ptr)
      return tp;
-   const Eolian_Typedecl *btp = eolian_type_typedecl_get(unit, tp);
+   const Eolian_Typedecl *btp = database_type_decl_find(unit, tp);
    if (btp && (btp->type == EOLIAN_TYPEDECL_ALIAS))
      return eolian_typedecl_aliased_base_get(unit, btp);
    return tp;
index fbbf26e..c5b3664 100644 (file)
@@ -252,7 +252,7 @@ _validate_type(const Eolian_Unit *src, Eolian_Type *tp)
                 return _validate(&tp->base);
              }
            /* user defined */
-           tp->tdecl = (Eolian_Typedecl *)eolian_type_typedecl_get(src, tp);
+           tp->tdecl = database_type_decl_find(src, tp);
            if (!tp->tdecl)
              {
                 snprintf(buf, sizeof(buf), "undefined type %s", tp->full_name);
index 00a3967..5f804a5 100644 (file)
@@ -341,6 +341,8 @@ void database_typedecl_del(Eolian_Typedecl *tp);
 void database_type_to_str(const Eolian_Unit *src, const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype);
 void database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp, Eina_Strbuf *buf);
 
+Eolian_Typedecl *database_type_decl_find(const Eolian_Unit *src, const Eolian_Type *tp);
+
 Eina_Bool database_type_is_ownable(const Eolian_Unit *unit, const Eolian_Type *tp);
 
 /* expressions */
index e7e6018..3872fea 100644 (file)
@@ -353,7 +353,7 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni
        if (!stp)
          {
            bool is_undefined = false;
-           Eolian_Typedecl const* decl = eolian_type_typedecl_get(unit, eolian_type);
+           Eolian_Typedecl const* decl = eolian_type_typedecl_get(eolian_type);
            typedecl_type type_type = (decl ? typedecl_type_get(decl) : typedecl_type::unknown);
            if(decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_ALIAS)
              {
index 9146f52..60bfdba 100644 (file)
@@ -1065,11 +1065,10 @@ class Type(EolianBaseObject):  # OK  (4 TODO Unit*)
         #  return _str_to_py(lib.eolian_type_c_type_get(self._obj))
         return 'FIXME'
 
-    # TODO FIXME STRANGE API (need Eolian_Unit*)
-    #  @cached_property
-    #  def typedecl(self):
-        #  c_tdecl = lib.eolian_type_typedecl_get(self._obj)
-        #  return Typedecl(c_tdecl) if c_tdecl else None
+    @cached_property
+    def typedecl(self):
+        c_tdecl = lib.eolian_type_typedecl_get(self._obj)
+        return Typedecl(c_tdecl) if c_tdecl else None
 
     @cached_property
     def base_type(self):
index 945f15d..2e67cb0 100644 (file)
@@ -550,10 +550,9 @@ lib.eolian_type_base_type_get.restype = c_void_p
 lib.eolian_type_next_type_get.argtypes = [c_void_p,]
 lib.eolian_type_next_type_get.restype = c_void_p
 
-# TODO FIXME STRANGE API (need Eolian_Unit*)
-# EAPI const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Unit *unit, const Eolian_Type *tp);
-#  lib.eolian_type_typedecl_get.argtypes = [c_void_p,]
-#  lib.eolian_type_typedecl_get.restype = c_void_p
+# EAPI const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp);
+lib.eolian_type_typedecl_get.argtypes = [c_void_p,]
+lib.eolian_type_typedecl_get.restype = c_void_p
 
 # TODO FIXME STRANGE API (need Eolian_Unit*)
 # EAPI const Eolian_Type *eolian_type_aliased_base_get(const Eolian_Unit *unit, const Eolian_Type *tp);
index 8227a56..79f611a 100644 (file)
@@ -724,7 +724,7 @@ START_TEST(eolian_struct)
    fail_if(!(type_name = eolian_type_name_get(ftype)));
    fail_if(strcmp(type_name, "Named"));
    fail_if(eolian_type_type_get(ftype) != EOLIAN_TYPE_REGULAR);
-   fail_if(eolian_typedecl_type_get(eolian_type_typedecl_get(unit, ftype))
+   fail_if(eolian_typedecl_type_get(eolian_type_typedecl_get(ftype))
        != EOLIAN_TYPEDECL_STRUCT);
 
    /* opaque struct */
@@ -736,7 +736,7 @@ START_TEST(eolian_struct)
    fail_if(!(type = eolian_function_return_type_get(func, EOLIAN_METHOD)));
    fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_REGULAR);
    fail_if(!eolian_type_is_ptr(type));
-   fail_if(!(tdl = eolian_type_typedecl_get(unit, type)));
+   fail_if(!(tdl = eolian_type_typedecl_get(type)));
    fail_if(eolian_typedecl_type_get(tdl) != EOLIAN_TYPEDECL_STRUCT);
 
    eolian_free(eos);
@@ -1536,7 +1536,7 @@ START_TEST(eolian_function_types)
    fail_if(eolian_type_is_owned(type));
    fail_if(!(type_name = eolian_type_name_get(type)));
    fail_if(strcmp(type_name, "VoidFunc"));
-   fail_if(!(arg_decl = eolian_type_typedecl_get(unit, type)));
+   fail_if(!(arg_decl = eolian_type_typedecl_get(type)));
    fail_if(eolian_typedecl_type_get(arg_decl) != EOLIAN_TYPEDECL_FUNCTION_POINTER);
 
    fail_if(!(eina_iterator_next(iter, (void**)&param)));
@@ -1547,7 +1547,7 @@ START_TEST(eolian_function_types)
    fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_REGULAR);
    fail_if(!(type_name = eolian_type_name_get(type)));
    fail_if(strcmp(type_name, "SimpleFunc"));
-   fail_if(!(arg_decl = eolian_type_typedecl_get(unit, type)));
+   fail_if(!(arg_decl = eolian_type_typedecl_get(type)));
    fail_if(eolian_typedecl_type_get(arg_decl) != EOLIAN_TYPEDECL_FUNCTION_POINTER);
 
    fail_if(eina_iterator_next(iter, &dummy));
@@ -1589,7 +1589,7 @@ START_TEST(eolian_function_as_arguments)
    fail_if(eolian_type_is_owned(type));
    fail_if(!(type_name = eolian_type_name_get(type)));
    fail_if(strcmp(type_name, "SimpleFunc"));
-   fail_if(!(arg_decl = eolian_type_typedecl_get(unit, type)));
+   fail_if(!(arg_decl = eolian_type_typedecl_get(type)));
    fail_if(eolian_typedecl_type_get(arg_decl) != EOLIAN_TYPEDECL_FUNCTION_POINTER);
 
    fail_if(eina_iterator_next(iter, &dummy));