eolian: refine the ref system to suit more cases
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Wed, 8 Jun 2016 14:49:09 +0000 (15:49 +0100)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Wed, 8 Jun 2016 14:49:09 +0000 (15:49 +0100)
Now references are first class (but still restricted to one level). Unlike
pointers they only mark the type instead of introducing a whole new type.

18 files changed:
src/bin/eolian/common_funcs.c
src/bin/eolian/common_funcs.h
src/bin/eolian/docs_generator.c
src/bin/eolian/eo_generator.c
src/bin/eolian/impl_generator.c
src/bin/eolian/legacy_generator.c
src/bin/eolian/types_generator.c
src/bindings/luajit/eolian.lua
src/lib/eolian/Eolian.h
src/lib/eolian/database_function_api.c
src/lib/eolian/database_type.c
src/lib/eolian/database_type_api.c
src/lib/eolian/eo_lexer.h
src/lib/eolian/eo_parser.c
src/lib/eolian/eolian_database.h
src/tests/eolian/data/class_simple.eo
src/tests/eolian/data/struct.eo
src/tests/eolian/eolian_parsing.c

index ff82bcf..87aae20 100644 (file)
@@ -133,34 +133,9 @@ _template_fill(Eina_Strbuf *buf, const char *templ, const Eolian_Class *class, c
 const char *
 _get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir)
 {
-   switch (ftype)
-     {
-      case EOLIAN_PROP_GET:
-        if (pdir == EOLIAN_REF_PARAM)
-          return "**";
-        else
-          return "*";
-      case EOLIAN_PROP_SET:
-        if (pdir == EOLIAN_REF_PARAM)
-          return "*";
-        else
-          return "";
-      default:
-        if (pdir != EOLIAN_IN_PARAM)
-          return "*";
-        else
-          return "";
-     }
+   if (ftype == EOLIAN_PROP_GET)
+     return "*";
+   if ((pdir == EOLIAN_OUT_PARAM) || (pdir == EOLIAN_INOUT_PARAM))
+     return "*";
    return "";
 }
-
-Eina_Stringshare *
-_get_rettype(const Eolian_Type *tp, Eina_Bool add_star)
-{
-   Eina_Stringshare *rtp = eolian_type_c_type_get(tp);
-   if (!add_star || !rtp) return rtp;
-   char buf[1024];
-   snprintf(buf, sizeof(buf), "%s%s", rtp, (rtp[strlen(rtp) - 1] == '*') ? "*" : " *");
-   eina_stringshare_del(rtp);
-   return eina_stringshare_add(buf);
-}
index 1a3b4bc..b23515f 100644 (file)
@@ -64,6 +64,5 @@ void _class_env_create(const Eolian_Class *class, const char *over_classname, _e
 void _class_func_env_create(const Eolian_Class *class, const char *funcname, Eolian_Function_Type ftype EINA_UNUSED, _eolian_class_func_vars *env);
 
 const char *_get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir);
-Eina_Stringshare *_get_rettype(const Eolian_Type *tp, Eina_Bool add_star);
 
 #endif
index 1e90f12..886bf9e 100644 (file)
@@ -517,7 +517,6 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype,
         switch (dir)
           {
            case EOLIAN_IN_PARAM:
-           case EOLIAN_REF_PARAM:
              eina_strbuf_append(buf, " * @param[in] ");
              curl += sizeof(" * @param[in] ") - 1;
              break;
index 8f93944..c12975a 100644 (file)
@@ -71,7 +71,6 @@ eo_fundef_generate(const Eolian_Class *class, const Eolian_Function *func, Eolia
 
    _class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env);
    rettypet = eolian_function_return_type_get(func, ftype);
-   Eina_Bool add_rstar = eolian_function_return_is_ref(func, ftype);
    if (ftype == EOLIAN_PROP_GET && !rettypet)
      {
         itr = eolian_property_values_get(func, ftype);
@@ -144,7 +143,7 @@ eo_fundef_generate(const Eolian_Class *class, const Eolian_Function *func, Eolia
         eina_iterator_free(itr);
      }
 
-   if (rettypet) rettype = _get_rettype(rettypet, add_rstar);
+   if (rettypet) rettype = eolian_type_c_type_get(rettypet);
 
    eina_strbuf_replace_all(str_func, "@#rettype", rettype ? rettype : "void");
    if (!rettype || rettype[strlen(rettype) - 1] != '*')
@@ -318,7 +317,6 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
    Eina_Strbuf *params_init = eina_strbuf_new(); /* init of variables to default */
 
    rettypet = eolian_function_return_type_get(funcid, ftype);
-   Eina_Bool add_rstar = eolian_function_return_is_ref(funcid, ftype);
    if (rettypet)
      {
         is_auto = EINA_FALSE; /* We block auto when the function has to return something */
@@ -450,7 +448,7 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
         eina_iterator_free(itr);
      }
 
-   if (rettypet) rettype = _get_rettype(rettypet, add_rstar);
+   if (rettypet) rettype = eolian_type_c_type_get(rettypet);
 
    if (need_implementation)
      {
index f9c9468..4002dc6 100644 (file)
@@ -140,7 +140,6 @@ _prototype_generate(const Eolian_Function *foo, Eolian_Function_Type ftype, Eina
 
    printf("Generation of function %s\n", func_name);
    const Eolian_Type *rettypet = eolian_function_return_type_get(foo, ftype);
-   Eina_Bool add_rstar = eolian_function_return_is_ref(foo, ftype);
    if (ftype == EOLIAN_PROP_GET && !rettypet)
      {
         Eina_Iterator *itr = eolian_property_values_get(foo, ftype);
@@ -183,7 +182,7 @@ _prototype_generate(const Eolian_Function *foo, Eolian_Function_Type ftype, Eina
      }
 
    const char *rettype = NULL;
-   if (rettypet) rettype = _get_rettype(rettypet, add_rstar);
+   if (rettypet) rettype = eolian_type_c_type_get(rettypet);
 
    eina_strbuf_append_printf(buffer,
          "EOLIAN static %s\n%s(%sEo *obj, %s *pd%s%s)\n{\n%s\n}\n\n",
index 6a76810..fe72e13 100644 (file)
@@ -55,7 +55,6 @@ _eapi_decl_func_generate(const Eolian_Class *class, const Eolian_Function *funci
 
    _class_func_env_create(class, funcname, ftype, &func_env);
    rettypet = eolian_function_return_type_get(funcid, ftype);
-   Eina_Bool add_rstar = eolian_function_return_is_ref(funcid, ftype);
    if (ftype == EOLIAN_PROP_GET)
      {
         if (!rettypet)
@@ -150,7 +149,7 @@ _eapi_decl_func_generate(const Eolian_Class *class, const Eolian_Function *funci
    if (!eina_strbuf_length_get(fparam)) eina_strbuf_append(fparam, "void");
    if (flags) eina_strbuf_append_printf(flags, ")");
 
-   if (rettypet) rettype = _get_rettype(rettypet, add_rstar);
+   if (rettypet) rettype = eolian_type_c_type_get(rettypet);
 
    eina_strbuf_replace_all(fbody, "@#params", eina_strbuf_string_get(fparam));
    eina_strbuf_reset(fparam);
@@ -198,8 +197,7 @@ _eapi_func_generate(const Eolian_Class *class, const Eolian_Function *funcid, Eo
 
    _class_func_env_create(class, eolian_function_name_get(funcid), ftype, &func_env);
    rettypet = eolian_function_return_type_get(funcid, ftype);
-   Eina_Bool add_rstar = eolian_function_return_is_ref(funcid, ftype);
-   if (rettypet) rettype = _get_rettype(rettypet, add_rstar);
+   if (rettypet) rettype = eolian_type_c_type_get(rettypet);
    if (rettype && !strcmp(rettype, "void")) ret_is_void = EINA_TRUE;
    retname = "ret";
    if (ftype == EOLIAN_PROP_GET)
@@ -221,7 +219,7 @@ _eapi_func_generate(const Eolian_Class *class, const Eolian_Function *funcid, Eo
 
    if (func_env.legacy_func[0] == '\0') goto end;
 
-   if (!rettype && rettypet) rettype = _get_rettype(rettypet, add_rstar);
+   if (!rettype && rettypet) rettype = eolian_type_c_type_get(rettypet);
 
    if (rettype && (!ret_is_void))
      eina_strbuf_append(fbody, tmpl_eapi_body);
index fbae5e2..5995405 100644 (file)
@@ -71,9 +71,8 @@ _type_generate(const Eolian_Typedecl *tp, Eina_Bool full, Eina_Bool use_legacy)
                 {
                    const Eolian_Type *type = eolian_typedecl_struct_field_type_get(member);
                    Eina_Stringshare *c_type = eolian_type_c_type_get(type);
-                   Eina_Bool is_ref = eolian_typedecl_struct_field_is_ref(member);
-                   eina_strbuf_append_printf(buf, "  %s%s%s%s;",
-                         c_type, is_ref ? (strchr(c_type, '*') ? "*" : " *") : "", (is_ref || strchr(c_type, '*'))?"":" ",
+                   eina_strbuf_append_printf(buf, "  %s%s%s;",
+                         c_type, strchr(c_type, '*')?"":" ",
                          eolian_typedecl_struct_field_name_get(member));
                    const Eolian_Documentation *fdoc
                        = eolian_typedecl_struct_field_documentation_get(member);
index 077712c..b31f445 100644 (file)
@@ -41,8 +41,7 @@ ffi.cdef [[
     {
         EOLIAN_IN_PARAM = 0,
         EOLIAN_OUT_PARAM,
-        EOLIAN_INOUT_PARAM,
-        EOLIAN_REF_PARAM
+        EOLIAN_INOUT_PARAM
     } Eolian_Parameter_Dir;
 
     typedef enum
@@ -281,7 +280,6 @@ ffi.cdef [[
     const char *eolian_typedecl_struct_field_name_get(const Eolian_Struct_Type_Field *fl);
     const Eolian_Documentation *eolian_typedecl_struct_field_documentation_get(const Eolian_Struct_Type_Field *fl);
     const Eolian_Type *eolian_typedecl_struct_field_type_get(const Eolian_Struct_Type_Field *fl);
-    Eina_Bool eolian_typedecl_struct_field_is_ref(const Eolian_Struct_Type_Field *fl);
     Eina_Iterator *eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp);
     const Eolian_Enum_Type_Field *eolian_typedecl_enum_field_get(const Eolian_Typedecl *tp, const char *field);
     const char *eolian_typedecl_enum_field_name_get(const Eolian_Enum_Type_Field *fl);
@@ -304,6 +302,7 @@ ffi.cdef [[
     const Eolian_Class *eolian_type_class_get(const Eolian_Type *tp);
     Eina_Bool eolian_type_is_own(const Eolian_Type *tp);
     Eina_Bool eolian_type_is_const(const Eolian_Type *tp);
+    Eina_Bool eolian_type_is_ref(const Eolian_Type *tp);
 
     Eina_Bool eolian_typedecl_is_extern(const Eolian_Typedecl *tp);
 
@@ -484,10 +483,6 @@ ffi.metatype("Eolian_Struct_Type_Field", {
             local v = eolian.eolian_typedecl_struct_field_type_get(self)
             if v == nil then return nil end
             return v
-        end,
-
-        is_ref = function(self)
-            return eolian.eolian_typedecl_struct_field_is_ref(self) ~= 0
         end
     }
 })
@@ -662,6 +657,10 @@ M.Type = ffi.metatype("Eolian_Type", {
             return eolian.eolian_type_is_const(self) ~= 0
         end,
 
+        is_ref = function(self)
+            return eolian.eolian_type_is_ref(self) ~= 0
+        end,
+
         c_type_get = function(self)
             local v = eolian.eolian_type_c_type_get(self)
             if v == nil then return nil end
@@ -806,8 +805,7 @@ M.Function = ffi.metatype("Eolian_Function", {
 M.parameter_dir = {
     IN    = 0,
     OUT   = 1,
-    INOUT = 2,
-    REF   = 3
+    INOUT = 2
 }
 
 ffi.metatype("Eolian_Function_Parameter", {
index c96b0fe..aa00c7e 100644 (file)
@@ -184,8 +184,7 @@ typedef enum
 {
    EOLIAN_IN_PARAM = 0,
    EOLIAN_OUT_PARAM,
-   EOLIAN_INOUT_PARAM,
-   EOLIAN_REF_PARAM
+   EOLIAN_INOUT_PARAM
 } Eolian_Parameter_Dir;
 
 typedef enum
@@ -969,20 +968,6 @@ EAPI const Eolian_Documentation *eolian_function_return_documentation_get(const
 EAPI Eina_Bool eolian_function_return_is_warn_unused(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
 
 /*
- * @brief Indicates if a function returns a ref (pointer).
- *
- * @param[in] function_id id of the function
- * @param[in] ftype type of the function
- * @return EINA_TRUE is ref return, EINA_FALSE otherwise.
- *
- * The type of the function is needed because a given function can represent a
- * property, that can be set and get functions.
- *
- * @ingroup Eolian
- */
-EAPI Eina_Bool eolian_function_return_is_ref(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
@@ -1464,16 +1449,6 @@ EAPI const Eolian_Documentation *eolian_typedecl_struct_field_documentation_get(
 EAPI const Eolian_Type *eolian_typedecl_struct_field_type_get(const Eolian_Struct_Type_Field *fl);
 
 /*
- * @brief Check if a struct field is a reference.
- *
- * @param[in] fl the field.
- * @return EINA_TRUE if it is, EINA_FALSE otherwise.
- *
- * @ingroup Eolian
- */
-EAPI Eina_Bool eolian_typedecl_struct_field_is_ref(const Eolian_Struct_Type_Field *fl);
-
-/*
  * @brief Get an iterator to all fields of an enum type.
  *
  * @param[in] tp the type declaration.
@@ -1764,6 +1739,16 @@ EAPI Eina_Bool eolian_type_is_own(const Eolian_Type *tp);
 EAPI Eina_Bool eolian_type_is_const(const Eolian_Type *tp);
 
 /*
+ * @brief Get whether the given type is a reference.
+ *
+ * @param[in] tp the type.
+ * @return EINA_TRUE when the type is marked ref, EINA_FALSE otherwise.
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Bool eolian_type_is_ref(const Eolian_Type *tp);
+
+/*
  * @brief Get the full C type name of the given type.
  *
  * @param[in] tp the type.
index 5b989a6..9cb1177 100644 (file)
@@ -303,19 +303,6 @@ eolian_function_return_is_warn_unused(const Eolian_Function *fid,
 }
 
 EAPI Eina_Bool
-eolian_function_return_is_ref(const Eolian_Function *fid,
-                              Eolian_Function_Type ftype)
-{
-   EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EINA_FALSE);
-   switch (ftype)
-     {
-      case EOLIAN_PROP_SET: return fid->set_return_is_ref;
-      case EOLIAN_UNRESOLVED: case EOLIAN_METHOD: case EOLIAN_PROPERTY: case EOLIAN_PROP_GET: return fid->get_return_is_ref;
-      default: return EINA_FALSE;
-     }
-}
-
-EAPI Eina_Bool
 eolian_function_object_is_const(const Eolian_Function *fid)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EINA_FALSE);
index 3fa6997..1a48240 100644 (file)
@@ -70,7 +70,7 @@ database_enum_add(Eolian_Typedecl *tp)
 }
 
 void
-database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eina_Bool is_ref)
+database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
 {
    if ((tp->type == EOLIAN_TYPE_REGULAR
      || tp->type == EOLIAN_TYPE_COMPLEX
@@ -104,7 +104,7 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name,
    else
      {
         Eolian_Type *btp = tp->base_type;
-        database_type_to_str(tp->base_type, buf, NULL, EINA_FALSE);
+        database_type_to_str(tp->base_type, buf, NULL);
         if (btp->type != EOLIAN_TYPE_POINTER || btp->is_const)
            eina_strbuf_append_char(buf, ' ');
         eina_strbuf_append_char(buf, '*');
@@ -112,7 +112,7 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name,
      }
    if (tp->type == EOLIAN_TYPE_COMPLEX || tp->type == EOLIAN_TYPE_CLASS)
      eina_strbuf_append(buf, " *");
-   if (is_ref)
+   if (tp->is_ref)
      {
         if (eina_strbuf_string_get(buf)[eina_strbuf_length_get(buf) - 1] != '*')
           eina_strbuf_append_char(buf, ' ');
@@ -144,7 +144,7 @@ _stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
    eina_strbuf_append(buf, " { ");
    EINA_LIST_FOREACH(tp->field_list, l, sf)
      {
-        database_type_to_str(sf->type, buf, sf->name, sf->is_ref);
+        database_type_to_str(sf->type, buf, sf->name);
         eina_strbuf_append(buf, "; ");
      }
    eina_strbuf_append(buf, "}");
@@ -213,7 +213,7 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
 
    Eina_Strbuf *fulln = eina_strbuf_new();
    _append_name(tp, fulln);
-   database_type_to_str(tp->base_type, buf, eina_strbuf_string_get(fulln), EINA_FALSE);
+   database_type_to_str(tp->base_type, buf, eina_strbuf_string_get(fulln));
    eina_strbuf_free(fulln);
 }
 
index 268ca8e..c580404 100644 (file)
@@ -158,13 +158,6 @@ eolian_typedecl_struct_field_type_get(const Eolian_Struct_Type_Field *fl)
    return fl->type;
 }
 
-EAPI Eina_Bool
-eolian_typedecl_struct_field_is_ref(const Eolian_Struct_Type_Field *fl)
-{
-   EINA_SAFETY_ON_NULL_RETURN_VAL(fl, EINA_FALSE);
-   return fl->is_ref;
-}
-
 EAPI Eina_Iterator *
 eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp)
 {
@@ -339,6 +332,13 @@ eolian_type_is_const(const Eolian_Type *tp)
 }
 
 EAPI Eina_Bool
+eolian_type_is_ref(const Eolian_Type *tp)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
+   return tp->is_ref;
+}
+
+EAPI Eina_Bool
 eolian_typedecl_is_extern(const Eolian_Typedecl *tp)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
@@ -352,7 +352,7 @@ eolian_type_c_type_get(const Eolian_Type *tp)
    Eina_Strbuf *buf;
    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
    buf = eina_strbuf_new();
-   database_type_to_str(tp, buf, NULL, EINA_FALSE);
+   database_type_to_str(tp, buf, NULL);
    ret = eina_stringshare_add(eina_strbuf_string_get(buf));
    eina_strbuf_free(buf);
    return ret;
index 79b7302..3467ef2 100644 (file)
@@ -27,12 +27,12 @@ enum Tokens
     KW(abstract), KW(constructor), KW(constructors), KW(data), \
     KW(destructor), KW(eo), KW(eo_prefix), KW(event_prefix), KW(events), KW(free), \
     KW(get), KW(implements), KW(import), KW(interface), KW(keys), KW(legacy), \
-    KW(legacy_prefix), KW(methods), KW(mixin), KW(own), KW(params), \
+    KW(legacy_prefix), KW(methods), KW(mixin), KW(own), KW(params), KW(ref), \
     KW(set), KW(type), KW(values), KW(var), KWAT(auto), KWAT(beta), \
     KWAT(c_only), KWAT(class), KWAT(const), KWAT(empty), KWAT(extern), \
     KWAT(free), KWAT(hot), KWAT(in), KWAT(inout), KWAT(nonull), KWAT(nullable), \
     KWAT(optional), KWAT(out), KWAT(private), KWAT(property), \
-    KWAT(protected), KWAT(ref), KWAT(restart), KWAT(virtual_pure), KWAT(warn_unused), \
+    KWAT(protected), KWAT(restart), KWAT(virtual_pure), KWAT(warn_unused), \
     \
     KW(byte), KW(ubyte), KW(char), KW(short), KW(ushort), KW(int), KW(uint), \
     KW(long), KW(ulong), KW(llong), KW(ullong), \
index c38c738..3176bdb 100644 (file)
@@ -458,14 +458,14 @@ parse_expr(Eo_Lexer *ls)
    return parse_expr_bin(ls, 1);
 }
 
-static Eolian_Type *parse_type_void(Eo_Lexer *ls);
+static Eolian_Type *parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref);
 
 static Eolian_Type *
-parse_type(Eo_Lexer *ls)
+parse_type(Eo_Lexer *ls, Eina_Bool allow_ref)
 {
    Eolian_Type *ret;
    eo_lexer_context_push(ls);
-   ret = parse_type_void(ls);
+   ret = parse_type_void(ls, allow_ref);
    if (ret->type == EOLIAN_TYPE_VOID)
      {
         eo_lexer_context_restore(ls);
@@ -502,15 +502,9 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
    while (ls->t.token != '}')
      {
         const char *fname;
-        Eina_Bool is_ref = EINA_FALSE;
         Eolian_Struct_Type_Field *fdef;
         Eolian_Type *tp;
         int fline = ls->line_number, fcol = ls->column;
-        if (ls->t.kw == KW_at_ref)
-          {
-             is_ref = EINA_TRUE;
-             eo_lexer_get(ls);
-          }
         check(ls, TOK_VALUE);
         if (eina_hash_find(def->fields, ls->t.value.s))
           eo_lexer_syntax_error(ls, "double field definition");
@@ -520,11 +514,10 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
         def->field_list = eina_list_append(def->field_list, fdef);
         eo_lexer_get(ls);
         check_next(ls, ':');
-        tp = parse_type(ls);
+        tp = parse_type(ls, EINA_TRUE);
         FILL_BASE(fdef->base, ls, fline, fcol);
         fdef->type = tp;
         fdef->name = eina_stringshare_ref(fname);
-        fdef->is_ref = is_ref;
         pop_type(ls);
         check_next(ls, ';');
         FILL_DOC(ls, fdef, doc);
@@ -701,6 +694,8 @@ _parse_dep(Eo_Lexer *ls, const char *fname, const char *name)
 static Eina_Bool
 _type_is_ownable(Eolian_Type *tp)
 {
+   if (tp->is_ref)
+     return EINA_TRUE;
    if (tp->type == EOLIAN_TYPE_REGULAR)
      {
         int kwid = eo_lexer_keyword_str_to_id(tp->name);
@@ -715,7 +710,7 @@ _type_is_ownable(Eolian_Type *tp)
 }
 
 static Eolian_Type *
-parse_type_void(Eo_Lexer *ls)
+parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref)
 {
    Eolian_Type *def;
    Eina_Strbuf *buf;
@@ -729,12 +724,25 @@ parse_type_void(Eo_Lexer *ls)
            pline = ls->line_number;
            pcol = ls->column;
            check_next(ls, '(');
-           def = parse_type_void(ls);
+           def = parse_type_void(ls, allow_ref);
            FILL_BASE(def->base, ls, line, col);
            def->is_const = EINA_TRUE;
            check_match(ls, ')', '(', pline, pcol);
            goto parse_ptr;
         }
+      case KW_ref:
+        {
+           int pline, pcol;
+           eo_lexer_get(ls);
+           pline = ls->line_number;
+           pcol = ls->column;
+           check_next(ls, '(');
+           def = parse_type_void(ls, EINA_FALSE);
+           FILL_BASE(def->base, ls, line, col);
+           def->is_ref = EINA_TRUE;
+           check_match(ls, ')', '(', pline, pcol);
+           goto parse_ptr;
+        }
       case KW_own:
         {
            int pline, pcolumn;
@@ -743,7 +751,7 @@ parse_type_void(Eo_Lexer *ls)
            pcolumn = ls->column;
            check_next(ls, '(');
            eo_lexer_context_push(ls);
-           def = parse_type_void(ls);
+           def = parse_type_void(ls, allow_ref);
            if (!_type_is_ownable(def))
              {
                 eo_lexer_context_restore(ls);
@@ -763,7 +771,7 @@ parse_type_void(Eo_Lexer *ls)
            pcolumn = ls->column;
            check_next(ls, '(');
            eo_lexer_context_push(ls);
-           def = parse_type_void(ls);
+           def = parse_type_void(ls, allow_ref);
            if (!_type_is_ownable(def))
              {
                 eo_lexer_context_restore(ls);
@@ -809,19 +817,19 @@ parse_type_void(Eo_Lexer *ls)
                   def->type = EOLIAN_TYPE_COMPLEX;
                   check_next(ls, '<');
                   def->subtypes = eina_list_append(def->subtypes,
-                                                   parse_type(ls));
+                                                   parse_type(ls, EINA_FALSE));
                   pop_type(ls);
                   if (tpid == KW_hash)
                     {
                        check_next(ls, ',');
                        def->subtypes = eina_list_append(def->subtypes,
-                                                        parse_type(ls));
+                                                        parse_type(ls, EINA_FALSE));
                        pop_type(ls);
                     }
                   else if(tpid == KW_promise && test_next(ls, ','))
                     {
                        def->subtypes = eina_list_append(def->subtypes,
-                                                        parse_type(ls));
+                                                        parse_type(ls, EINA_FALSE));
                        pop_type(ls);
                     }
                   check_match(ls, '>', '<', bline, bcol);
@@ -913,7 +921,7 @@ parse_typedef(Eo_Lexer *ls)
      }
    eo_lexer_context_pop(ls);
    check_next(ls, ':');
-   def->base_type = parse_type(ls);
+   def->base_type = parse_type(ls, EINA_FALSE);
    pop_type(ls);
    check_next(ls, ';');
    FILL_DOC(ls, def, doc);
@@ -952,7 +960,7 @@ parse_variable(Eo_Lexer *ls, Eina_Bool global)
      }
    eo_lexer_context_pop(ls);
    check_next(ls, ':');
-   def->base_type = parse_type(ls);
+   def->base_type = parse_type(ls, EINA_FALSE);
    pop_type(ls);
    if ((ls->t.token == '=') && !has_extern)
      {
@@ -973,7 +981,6 @@ typedef struct _Eo_Ret_Def
    Eolian_Documentation *doc;
    Eolian_Expression *default_ret_val;
    Eina_Bool warn_unused: 1;
-   Eina_Bool is_ref: 1;
 } Eo_Ret_Def;
 
 static void
@@ -982,13 +989,12 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void)
    eo_lexer_get(ls);
    check_next(ls, ':');
    if (allow_void)
-     ret->type = parse_type_void(ls);
+     ret->type = parse_type_void(ls, EINA_TRUE);
    else
-     ret->type = parse_type(ls);
+     ret->type = parse_type(ls, EINA_TRUE);
    ret->doc = NULL;
    ret->default_ret_val = NULL;
    ret->warn_unused = EINA_FALSE;
-   ret->is_ref = EINA_FALSE;
    if (ls->t.token == '(')
      {
         int line = ls->line_number, col = ls->column;
@@ -998,7 +1004,7 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void)
         ls->expr_mode = EINA_FALSE;
         check_match(ls, ')', '(', line, col);
      }
-   Eina_Bool has_warn_unused = EINA_FALSE, has_ref = EINA_FALSE;
+   Eina_Bool has_warn_unused = EINA_FALSE;
    for (;;) switch (ls->t.kw)
      {
       case KW_at_warn_unused:
@@ -1006,11 +1012,6 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void)
         ret->warn_unused = EINA_TRUE;
         eo_lexer_get(ls);
         break;
-      case KW_at_ref:
-        CASE_LOCK(ls, ref, "ref qualifier");
-        ret->is_ref = EINA_TRUE;
-        eo_lexer_get(ls);
-        break;
       default:
         goto end;
      }
@@ -1043,20 +1044,15 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
         par->param_dir = EOLIAN_INOUT_PARAM;
         eo_lexer_get(ls);
      }
-   else if (ls->t.kw == KW_at_ref)
-     {
-        par->param_dir = EOLIAN_REF_PARAM;
-        eo_lexer_get(ls);
-     }
    else par->param_dir = EOLIAN_IN_PARAM;
    check(ls, TOK_VALUE);
    par->name = eina_stringshare_ref(ls->t.value.s);
    eo_lexer_get(ls);
    check_next(ls, ':');
    if (par->param_dir == EOLIAN_OUT_PARAM || par->param_dir == EOLIAN_INOUT_PARAM)
-     par->type = parse_type_void(ls);
+     par->type = parse_type_void(ls, EINA_TRUE);
    else
-     par->type = parse_type(ls);
+     par->type = parse_type(ls, EINA_TRUE);
    pop_type(ls);
    if ((is_vals || (par->param_dir == EOLIAN_OUT_PARAM)) && (ls->t.token == '('))
      {
@@ -1189,7 +1185,6 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
              prop->get_return_doc = ret.doc;
              prop->get_ret_val = ret.default_ret_val;
              prop->get_return_warn_unused = ret.warn_unused;
-             prop->get_return_is_ref = ret.is_ref;
           }
         else
           {
@@ -1197,7 +1192,6 @@ parse_accessor(Eo_Lexer *ls, Eolian_Function *prop)
              prop->set_return_doc = ret.doc;
              prop->set_ret_val = ret.default_ret_val;
              prop->set_return_warn_unused = ret.warn_unused;
-             prop->set_return_is_ref = ret.is_ref;
           }
         break;
       case KW_legacy:
@@ -1404,7 +1398,6 @@ body:
         meth->get_return_doc = ret.doc;
         meth->get_ret_val = ret.default_ret_val;
         meth->get_return_warn_unused = ret.warn_unused;
-        meth->get_return_is_ref = ret.is_ref;
         break;
       case KW_legacy:
         CASE_LOCK(ls, legacy, "legacy name")
@@ -1644,7 +1637,7 @@ end:
    if (ls->t.token == ':')
      {
         eo_lexer_get(ls);
-        ev->type = parse_type(ls);
+        ev->type = parse_type(ls, EINA_TRUE);
         pop_type(ls);
      }
    check(ls, ';');
index 0973336..8721a56 100644 (file)
@@ -140,8 +140,6 @@ struct _Eolian_Function
    Eina_Bool set_empty :1;
    Eina_Bool get_return_warn_unused :1; /* also used for methods */
    Eina_Bool set_return_warn_unused :1;
-   Eina_Bool get_return_is_ref: 1;
-   Eina_Bool set_return_is_ref: 1;
    Eina_Bool get_only_legacy: 1;
    Eina_Bool set_only_legacy: 1;
    Eina_Bool is_class :1;
@@ -176,6 +174,7 @@ struct _Eolian_Type
    Eina_Stringshare *freefunc;
    Eina_Bool is_const  :1;
    Eina_Bool is_own    :1;
+   Eina_Bool is_ref    :1;
 };
 
 struct _Eolian_Typedecl
@@ -234,7 +233,6 @@ struct _Eolian_Struct_Type_Field
    Eolian_Object     base;
    Eolian_Type      *type;
    Eolian_Documentation *doc;
-   Eina_Bool is_ref: 1;
 };
 
 struct _Eolian_Enum_Type_Field
@@ -303,7 +301,7 @@ void database_enum_add(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, Eina_Bool is_ref);
+void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name);
 void database_typedecl_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf);
 
 /* expressions */
index 4bae98a..8a64b92 100644 (file)
@@ -27,7 +27,7 @@ class Class_Simple {
             @in a: int; [[a]]
             @inout b: char;
             @out c: double (1337.6);
-            @ref d: int;
+            @in d: ref(int);
          }
          return: char * (null); [[comment for method return]]
       }
@@ -36,7 +36,7 @@ class Class_Simple {
          params {
             x: int;
          }
-         return: int @ref;
+         return: ref(int);
       }
    }
 }
index 842b1b2..077e499 100644 (file)
@@ -1,5 +1,5 @@
 struct Named {
-    @ref field: int;
+    field: ref(int);
     something: string;
 }
 
index 86ff77f..9833db3 100644 (file)
@@ -606,7 +606,7 @@ START_TEST(eolian_simple_parsing)
    /* Method */
    fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
    fail_if(!eolian_function_is_beta(fid));
-   fail_if(eolian_function_return_is_ref(fid, EOLIAN_METHOD));
+   fail_if(eolian_type_is_ref(eolian_function_return_type_get(fid, EOLIAN_METHOD)));
    /* Function return */
    tp = eolian_function_return_type_get(fid, EOLIAN_METHOD);
    fail_if(!tp);
@@ -641,8 +641,9 @@ START_TEST(eolian_simple_parsing)
    fail_if(v.type != EOLIAN_EXPR_DOUBLE);
    fail_if(v.value.d != 1337.6);
    fail_if(!(eina_iterator_next(iter, (void**)&param)));
-   fail_if(eolian_parameter_direction_get(param) != EOLIAN_REF_PARAM);
+   fail_if(eolian_parameter_direction_get(param) != EOLIAN_IN_PARAM);
    fail_if(strcmp(eolian_type_name_get(eolian_parameter_type_get(param)), "int"));
+   fail_if(!eolian_type_is_ref(eolian_parameter_type_get(param)));
    fail_if(strcmp(eolian_parameter_name_get(param), "d"));
    fail_if(eina_iterator_next(iter, &dummy));
    eina_iterator_free(iter);
@@ -652,7 +653,7 @@ START_TEST(eolian_simple_parsing)
    fail_if(!eolian_function_is_legacy_only(fid, EOLIAN_METHOD));
    fail_if(!eolian_function_is_c_only(fid));
    fail_if(eolian_function_is_beta(fid));
-   fail_if(!eolian_function_return_is_ref(fid, EOLIAN_METHOD));
+   fail_if(!eolian_type_is_ref(eolian_function_return_type_get(fid, EOLIAN_METHOD)));
 
    eolian_shutdown();
 }
@@ -686,12 +687,12 @@ START_TEST(eolian_struct)
    fail_if(strcmp(file, "struct.eo"));
    fail_if(!(field = eolian_typedecl_struct_field_get(tdl, "field")));
    fail_if(!(ftype = eolian_typedecl_struct_field_type_get(field)));
-   fail_if(!eolian_typedecl_struct_field_is_ref(field));
+   fail_if(!eolian_type_is_ref(ftype));
    fail_if(!(type_name = eolian_type_name_get(ftype)));
    fail_if(strcmp(type_name, "int"));
    fail_if(!(field = eolian_typedecl_struct_field_get(tdl, "something")));
    fail_if(!(ftype = eolian_typedecl_struct_field_type_get(field)));
-   fail_if(eolian_typedecl_struct_field_is_ref(field));
+   fail_if(eolian_type_is_ref(ftype));
    fail_if(!(type_name = eolian_type_c_type_get(ftype)));
    fail_if(strcmp(type_name, "const char *"));
    eina_stringshare_del(type_name);