eolian: add APIs to get full C types of parameters/returns/fields
authorDaniel Kolesa <d.kolesa@samsung.com>
Wed, 4 Sep 2019 13:56:32 +0000 (15:56 +0200)
committerYeongjong Lee <yj34.lee@samsung.com>
Mon, 16 Sep 2019 01:23:00 +0000 (10:23 +0900)
These are needed because the type itself does not carry all the
information it needs to carry (particularly by_ref).

src/lib/eolian/Eolian.h
src/lib/eolian/database_function_api.c
src/lib/eolian/database_function_parameter_api.c
src/lib/eolian/database_type.c
src/lib/eolian/database_type_api.c
src/lib/eolian/eolian_database.h

index b054792..cee793f 100644 (file)
@@ -1904,6 +1904,23 @@ EAPI Eina_Bool eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param
 EAPI Eina_Bool eolian_parameter_is_move(const Eolian_Function_Parameter *param_desc);
 
 /*
+ * @brief Get the full C type name of the given parameter.
+ *
+ * @param[in] param_desc parameter handle
+ * @param[in] as_return if true, it will be treated as a return type
+ * @return The C type name assuming @c param_desc is not NULL.
+ *
+ * You're responsible for the stringshare. The @c as_return argument is meant
+ * for properties, where the first out-param gets made into a return, which
+ * has different typing characteristics.
+ *
+ * @see eolian_type_c_type_get
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Stringshare *eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc, Eina_Bool as_return);
+
+/*
  * @brief Get the return type of a function.
  *
  * @param[in] function_id id of the function
@@ -2002,6 +2019,21 @@ EAPI Eina_Bool eolian_function_return_is_by_ref(const Eolian_Function *foo_id, E
 EAPI Eina_Bool eolian_function_return_is_move(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
 
 /*
+ * @brief Get the full C type name of the return value.
+ *
+ * @param[in] function_id id of the function
+ * @param[in] ftype type of the function
+ * @return The C type name.
+ *
+ * You're responsible for the stringshare.
+ *
+ * @see eolian_type_c_type_get
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Stringshare *eolian_function_return_c_type_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
+
+/*
  * @brief Indicates if a function object is const.
  *
  * @param[in] function_id id of the function
@@ -2575,6 +2607,20 @@ EAPI Eina_Bool eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_F
 EAPI Eina_Bool eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl);
 
 /*
+ * @brief Get the full C type name of the struct field.
+ *
+ * @param[in] fl the field.
+ * @return The C type name.
+ *
+ * You're responsible for the stringshare.
+ *
+ * @see eolian_type_c_type_get
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Stringshare *eolian_typedecl_struct_field_c_type_get(const Eolian_Struct_Type_Field *fl);
+
+/*
  * @brief Get an iterator to all fields of an enum type.
  *
  * @param[in] tp the type declaration.
index 15bbfde..fd78164 100644 (file)
@@ -342,6 +342,46 @@ eolian_function_return_is_move(const Eolian_Function *fid,
      }
 }
 
+EAPI Eina_Stringshare *
+eolian_function_return_c_type_get(const Eolian_Function *fid,
+                                  Eolian_Function_Type ftype)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EINA_FALSE);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_UNRESOLVED, EINA_FALSE);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_PROPERTY, EINA_FALSE);
+   const Eolian_Type *tp = NULL;
+   Eina_Bool by_ref = EINA_FALSE;
+   switch (ftype)
+     {
+      case EOLIAN_METHOD:
+      case EOLIAN_FUNCTION_POINTER:
+        if (fid->type != ftype)
+          return NULL;
+        tp = fid->get_ret_type;
+        by_ref = fid->get_return_by_ref;
+        break;
+      case EOLIAN_PROP_GET:
+        if ((fid->type != EOLIAN_PROP_GET) && (fid->type != EOLIAN_PROPERTY))
+          return NULL;
+        tp = fid->get_ret_type;
+        by_ref = fid->get_return_by_ref;
+        break;
+      case EOLIAN_PROP_SET:
+        if ((fid->type != EOLIAN_PROP_SET) && (fid->type != EOLIAN_PROPERTY))
+          return NULL;
+        tp = fid->set_ret_type;
+        by_ref = fid->set_return_by_ref;
+        break;
+      default:
+        return NULL;
+     }
+   Eina_Strbuf *buf = eina_strbuf_new();
+   database_type_to_str(tp, buf, NULL, EOLIAN_C_TYPE_RETURN, by_ref);
+   Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf));
+   eina_strbuf_free(buf);
+   return ret;
+}
+
 EAPI Eina_Bool
 eolian_function_object_is_const(const Eolian_Function *fid)
 {
index 60673a5..341b287 100644 (file)
@@ -53,3 +53,17 @@ eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param)
    EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE);
    return param->by_ref;
 }
+
+EAPI Eina_Stringshare *
+eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc,
+                            Eina_Bool as_return)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(param_desc, NULL);
+   Eina_Strbuf *buf = eina_strbuf_new();
+   database_type_to_str(param_desc->type, buf, NULL,
+                        as_return ? EOLIAN_C_TYPE_RETURN : EOLIAN_C_TYPE_PARAM,
+                        param_desc->by_ref);
+   Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf));
+   eina_strbuf_free(buf);
+   return ret;
+}
\ No newline at end of file
index 70a8ad6..6381cf8 100644 (file)
@@ -101,7 +101,7 @@ _buf_add_suffix(Eina_Strbuf *buf, const char *suffix)
 void
 database_type_to_str(const Eolian_Type *tp,
                      Eina_Strbuf *buf, const char *name,
-                     Eolian_C_Type_Type ctype)
+                     Eolian_C_Type_Type ctype, Eina_Bool by_ref)
 {
    if ((tp->type == EOLIAN_TYPE_REGULAR
      || tp->type == EOLIAN_TYPE_CLASS
@@ -128,7 +128,7 @@ database_type_to_str(const Eolian_Type *tp,
      {
         /* handles arrays and pointers as they all serialize to pointers */
         database_type_to_str(tp->base_type, buf, NULL,
-                             EOLIAN_C_TYPE_DEFAULT);
+                             EOLIAN_C_TYPE_DEFAULT, EINA_FALSE);
         _buf_add_suffix(buf, "*");
         if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN))
           eina_strbuf_append(buf, " const");
@@ -137,6 +137,8 @@ database_type_to_str(const Eolian_Type *tp,
      _buf_add_suffix(buf, "*");
    if (tp->is_ptr)
      _buf_add_suffix(buf, "*");
+   if (by_ref)
+     _buf_add_suffix(buf, "*");
    _buf_add_suffix(buf, name);
 }
 
@@ -153,7 +155,7 @@ _stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
    EINA_LIST_FOREACH(tp->field_list, l, sf)
      {
         database_type_to_str(sf->type, buf, sf->base.name,
-                             EOLIAN_C_TYPE_DEFAULT);
+                             EOLIAN_C_TYPE_DEFAULT, sf->by_ref);
         eina_strbuf_append(buf, "; ");
      }
    eina_strbuf_append(buf, "}");
@@ -191,7 +193,7 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
 {
    eina_strbuf_append(buf, "typedef ");
    database_type_to_str(tp->base_type, buf, tp->base.c_name,
-                        EOLIAN_C_TYPE_DEFAULT);
+                        EOLIAN_C_TYPE_DEFAULT, EINA_FALSE);
 }
 
 void
index 2bec505..12e787d 100644 (file)
@@ -77,6 +77,17 @@ eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl)
    return fl->move;
 }
 
+EAPI Eina_Stringshare *
+eolian_typedecl_struct_field_c_type_get(const Eolian_Struct_Type_Field *fl)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
+   Eina_Strbuf *buf = eina_strbuf_new();
+   database_type_to_str(fl->type, buf, NULL, EOLIAN_C_TYPE_DEFAULT, fl->by_ref);
+   Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf));
+   eina_strbuf_free(buf);
+   return ret;
+}
+
 EAPI Eina_Iterator *
 eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp)
 {
@@ -262,7 +273,7 @@ eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype)
    Eina_Strbuf *buf;
    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
    buf = eina_strbuf_new();
-   database_type_to_str(tp, buf, NULL, ctype);
+   database_type_to_str(tp, buf, NULL, ctype, EINA_FALSE);
    ret = eina_stringshare_add(eina_strbuf_string_get(buf));
    eina_strbuf_free(buf);
    return ret;
index 8f67ab5..8a16733 100644 (file)
@@ -425,7 +425,7 @@ void database_enum_add(Eolian_Unit *unit, Eolian_Typedecl *tp);
 void database_type_del(Eolian_Type *tp);
 void database_typedecl_del(Eolian_Typedecl *tp);
 
-void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype);
+void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype, Eina_Bool by_ref);
 void database_typedecl_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf);
 
 Eolian_Typedecl *database_type_decl_find(const Eolian_Unit *src, const Eolian_Type *tp);