eolian: change C type serialization API to account for returns
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Thu, 10 Aug 2017 10:12:38 +0000 (12:12 +0200)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Thu, 10 Aug 2017 10:12:38 +0000 (12:12 +0200)
This will allow proper handling of const.

src/bin/eolian/docs.c
src/bin/eolian/headers.c
src/bin/eolian/sources.c
src/bin/eolian/types.c
src/lib/eolian/Eolian.h
src/lib/eolian/database_type_api.c

index 2a29369..aa17975 100644 (file)
@@ -377,7 +377,7 @@ eo_gen_docs_event_gen(const Eolian_Unit *src, const Eolian_Event *ev,
    if (rt)
      {
         p = buf;
-        Eina_Stringshare *rts = eolian_type_c_type_get(rt);
+        Eina_Stringshare *rts = eolian_type_c_type_get(rt, EOLIAN_C_TYPE_DEFAULT);
         snprintf(buf, sizeof(buf), "@return %s", rts);
         eina_stringshare_del(rts);
      }
index 1d11da8..71d66f3 100644 (file)
@@ -58,7 +58,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
    eina_strbuf_append(buf, legacy ? "EAPI " : "EOAPI ");
    if (rtp)
      {
-        Eina_Stringshare *rtps = eolian_type_c_type_get(rtp);
+        Eina_Stringshare *rtps = eolian_type_c_type_get(rtp, EOLIAN_C_TYPE_RETURN);
         eina_strbuf_append(buf, rtps);
         if (rtps[strlen(rtps) - 1] != '*')
           eina_strbuf_append_char(buf, ' ');
@@ -96,7 +96,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
         {
            const Eolian_Type *prt = eolian_parameter_type_get(pr);
            const char *prn = eolian_parameter_name_get(pr);
-           Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
+           Eina_Stringshare *prtn = eolian_type_c_type_get(prt, EOLIAN_C_TYPE_PARAM);
            ++nidx;
            if (!first)
              eina_strbuf_append(buf, ", ");
@@ -130,7 +130,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
              const Eolian_Type *prt = eolian_parameter_type_get(pr);
              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(prt);
+             Eina_Stringshare *prtn = eolian_type_c_type_get(prt, EOLIAN_C_TYPE_PARAM);
 
              if (ptd && eolian_typedecl_type_get(ptd) == EOLIAN_TYPEDECL_FUNCTION_POINTER)
                {
index d1ab3d5..65957e8 100644 (file)
@@ -137,7 +137,7 @@ _append_defval(const Eolian_Unit *src, Eina_Strbuf *buf,
         free(sn);
         return;
      }
-   Eina_Stringshare *ctp = eolian_type_c_type_get(btp);
+   Eina_Stringshare *ctp = eolian_type_c_type_get(btp, EOLIAN_C_TYPE_DEFAULT);
    if (strchr(ctp, '*'))
      {
         eina_strbuf_append(buf, "NULL");
@@ -207,7 +207,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(pt);
+           Eina_Stringshare *ptn = eolian_type_c_type_get(pt, EOLIAN_C_TYPE_PARAM);
 
            if (eina_strbuf_length_get(params))
              eina_strbuf_append(params, ", ");
@@ -245,7 +245,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Class *cl,
              const Eolian_Expression *dfv = eolian_parameter_default_value_get(pr);
              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(pt);
+             Eina_Stringshare *ptn = eolian_type_c_type_get(pt, EOLIAN_C_TYPE_PARAM);
              const Eolian_Typedecl *ptd = eolian_type_typedecl_get(pt);
 
              Eina_Bool had_star = ptn[strlen(ptn) - 1] == '*';
@@ -317,7 +317,7 @@ _gen_func(const Eolian_Unit *src, const Eolian_Class *cl,
    if (impl_same_class && eolian_implement_is_pure_virtual(impl, ftype))
      impl_need = EINA_FALSE;
 
-   Eina_Stringshare *rtpn = rtp ? eolian_type_c_type_get(rtp)
+   Eina_Stringshare *rtpn = rtp ? eolian_type_c_type_get(rtp, EOLIAN_C_TYPE_RETURN)
                                 : eina_stringshare_add("void");
 
    char *cname = NULL, *cnamel = NULL, *ocnamel = NULL;
@@ -828,7 +828,7 @@ _gen_params(const Eolian_Function *fid, Eolian_Function_Type ftype,
         {
            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(pt);
+           Eina_Stringshare *ptn = eolian_type_c_type_get(pt, EOLIAN_C_TYPE_PARAM);
 
            eina_strbuf_append(params, ", ");
            eina_strbuf_append(params, prn);
@@ -858,7 +858,7 @@ _gen_params(const Eolian_Function *fid, Eolian_Function_Type ftype,
              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(pt);
-             Eina_Stringshare *ptn = eolian_type_c_type_get(pt);
+             Eina_Stringshare *ptn = eolian_type_c_type_get(pt, EOLIAN_C_TYPE_PARAM);
 
              if (ptd && eolian_typedecl_type_get(ptd) == EOLIAN_TYPEDECL_FUNCTION_POINTER)
                {
@@ -938,7 +938,7 @@ _gen_proto(const Eolian_Class *cl, const Eolian_Function *fid,
    eina_strbuf_append(buf, "EOLIAN static ");
    if (rtp)
      {
-        Eina_Stringshare *rtpn = eolian_type_c_type_get(rtp);
+        Eina_Stringshare *rtpn = eolian_type_c_type_get(rtp, EOLIAN_C_TYPE_RETURN);
         eina_strbuf_append(buf, rtpn);
         eina_stringshare_del(rtpn);
      }
index 9baebed..c856d7a 100644 (file)
@@ -42,7 +42,8 @@ _type_generate(const Eolian_Unit *src, const Eolian_Typedecl *tp,
                 Eina_Stringshare *ct = NULL;
                 if (eolian_type_type_get(mtp) == EOLIAN_TYPE_STATIC_ARRAY)
                   {
-                     ct = eolian_type_c_type_get(eolian_type_base_type_get(mtp));
+                     ct = eolian_type_c_type_get(eolian_type_base_type_get(mtp),
+                                                 EOLIAN_C_TYPE_DEFAULT);
                      eina_strbuf_append_printf(buf, "  %s%s%s[%zu];",
                         ct, strchr(ct, '*') ? "" : " ",
                         eolian_typedecl_struct_field_name_get(memb),
@@ -50,7 +51,7 @@ _type_generate(const Eolian_Unit *src, const Eolian_Typedecl *tp,
                   }
                 else
                   {
-                     ct = eolian_type_c_type_get(mtp);
+                     ct = eolian_type_c_type_get(mtp, EOLIAN_C_TYPE_DEFAULT);
                      eina_strbuf_append_printf(buf, "  %s%s%s;",
                         ct, strchr(ct, '*') ? "" : " ",
                         eolian_typedecl_struct_field_name_get(memb));
@@ -145,7 +146,7 @@ _type_generate(const Eolian_Unit *src, const Eolian_Typedecl *tp,
              eina_strbuf_append(buf, "void ");
            else
              {
-                Eina_Stringshare *ct = eolian_type_c_type_get(rtp);
+                Eina_Stringshare *ct = eolian_type_c_type_get(rtp, EOLIAN_C_TYPE_RETURN);
                 eina_strbuf_append_printf(buf, "%s ", ct);
              }
 
@@ -162,7 +163,7 @@ _type_generate(const Eolian_Unit *src, const Eolian_Typedecl *tp,
              {
                 const Eolian_Typedecl *ptd = eolian_type_typedecl_get(eolian_parameter_type_get(param));
                 Eina_Stringshare *pn = eolian_parameter_name_get(param);
-                Eina_Stringshare *pt = eolian_type_c_type_get(eolian_parameter_type_get(param));
+                Eina_Stringshare *pt = eolian_type_c_type_get(eolian_parameter_type_get(param), EOLIAN_C_TYPE_PARAM);
 
                 if (!pn)
                   pn = ""; // FIXME add some kind of param1/param2 control for null?
@@ -221,7 +222,7 @@ _var_generate(const Eolian_Unit *src, const Eolian_Variable *vr, Eina_Bool legac
      }
    else
      {
-        Eina_Stringshare *ct = eolian_type_c_type_get(vt);
+        Eina_Stringshare *ct = eolian_type_c_type_get(vt, EOLIAN_C_TYPE_DEFAULT);
         eina_strbuf_append_printf(buf, "EWAPI extern %s %s;", ct, fn);
         eina_stringshare_del(ct);
      }
@@ -314,7 +315,7 @@ void eo_gen_types_source_gen(const Eolian_Unit *src,
         eina_str_toupper(&fn);
 
         const Eolian_Type *vt = eolian_variable_base_type_get(vr);
-        Eina_Stringshare *ct = eolian_type_c_type_get(vt);
+        Eina_Stringshare *ct = eolian_type_c_type_get(vt, EOLIAN_C_TYPE_DEFAULT);
         eina_strbuf_append_printf(buf, "EWAPI %s %s = ", ct, fn);
         eina_stringshare_del(ct);
         free(fn);
index 8b19fd6..9f99d36 100644 (file)
@@ -236,6 +236,13 @@ typedef enum
 
 typedef enum
 {
+   EOLIAN_C_TYPE_DEFAULT = 0,
+   EOLIAN_C_TYPE_PARAM,
+   EOLIAN_C_TYPE_RETURN
+} Eolian_C_Type_Type;
+
+typedef enum
+{
    EOLIAN_EXPR_UNKNOWN = 0,
    EOLIAN_EXPR_INT,
    EOLIAN_EXPR_UINT,
@@ -1883,6 +1890,7 @@ EAPI Eina_Bool eolian_type_is_ptr(const Eolian_Type *tp);
  * @brief Get the full C type name of the given type.
  *
  * @param[in] tp the type.
+ * @param[in] ctype the context within which the C type string will be used.
  * @return The C type name assuming @c tp is not NULL.
  *
  * You're responsible for the stringshare.
@@ -1891,7 +1899,7 @@ EAPI Eina_Bool eolian_type_is_ptr(const Eolian_Type *tp);
  *
  * @ingroup Eolian
  */
-EAPI Eina_Stringshare *eolian_type_c_type_get(const Eolian_Type *tp);
+EAPI Eina_Stringshare *eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype);
 
 /*
  * @brief Get the name of the given type. For regular or complex types, this
index bbc03fd..47d994e 100644 (file)
@@ -355,7 +355,7 @@ eolian_typedecl_is_extern(const Eolian_Typedecl *tp)
 }
 
 EAPI Eina_Stringshare *
-eolian_type_c_type_get(const Eolian_Type *tp)
+eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype EINA_UNUSED)
 {
    Eina_Stringshare *ret;
    Eina_Strbuf *buf;