Eolian: extend const attributes for parameters to 'set' properties.
authorDaniel Zaoui <daniel.zaoui@samsung.com>
Thu, 27 Mar 2014 13:16:32 +0000 (15:16 +0200)
committerDaniel Zaoui <daniel.zaoui@samsung.com>
Thu, 27 Mar 2014 13:19:22 +0000 (15:19 +0200)
When const is used for parameters into 'set' properties, the generator
doesn't prepend 'const'.
This fixes this bad behavior.

src/bin/eolian/eo1_generator.c
src/bin/eolian/legacy_generator.c
src/lib/eolian/Eolian.h
src/lib/eolian/eo_lexer.c
src/lib/eolian/eo_lexer.rl
src/lib/eolian/eolian_database.c
src/lib/eolian/eolian_database.h

index 36cb4fb406349e3242466ae970788513280d2fba..fa3804e8ac89178a6461883e3a354aac509aeb29 100644 (file)
@@ -196,7 +196,7 @@ eo1_fundef_generate(const char *classname, Eolian_Function func, Eolian_Function
         Eina_Bool add_star = EINA_FALSE;
         Eolian_Parameter_Dir pdir;
         eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, &pdesc);
-        Eina_Bool is_const = eolian_parameter_get_const_attribute_get(data);
+        Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == GET);
         if (ftype == GET) {
              add_star = EINA_TRUE;
              pdir = EOLIAN_OUT_PARAM;
@@ -390,7 +390,7 @@ eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Fun
                   void* data = eina_list_data_get(l);
                   eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, &retname, NULL);
                   var_as_ret = EINA_TRUE;
-                  ret_const = eolian_parameter_get_const_attribute_get(data);
+                  ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
                }
           }
      }
@@ -413,13 +413,13 @@ eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Fun
         const char *pname;
         const char *ptype;
         eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, NULL);
-        Eina_Bool is_const = eolian_parameter_get_const_attribute_get(data);
+        Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == GET);
         eina_strbuf_append_printf(va_args, "   %s%s %s = va_arg(*list, %s%s);\n",
               ftype == GET && is_const?"const ":"", ptype, pname,
               ftype == GET && is_const?"const ":"", _varg_upgr(ptype));
         eina_strbuf_append_printf(params, ", %s", pname);
         eina_strbuf_append_printf(full_params, ", %s%s %s",
-              ftype == GET && eolian_parameter_get_const_attribute_get(data)?"const ":"",
+              ftype == GET && eolian_parameter_const_attribute_get(data, ftype == GET)?"const ":"",
               ptype, pname);
      }
    if (!var_as_ret)
@@ -430,15 +430,15 @@ eo1_bind_func_generate(const char *classname, Eolian_Function funcid, Eolian_Fun
              const char *ptype;
              Eolian_Parameter_Dir pdir;
              eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, NULL);
-             Eina_Bool is_const = eolian_parameter_get_const_attribute_get(data);
+             Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == GET);
              Eina_Bool had_star = !!strchr(ptype, '*');
              if (ftype == UNRESOLVED || ftype == METHOD_FUNC) add_star = (pdir == EOLIAN_OUT_PARAM);
              eina_strbuf_append_printf(va_args, "   %s%s%s%s%s = va_arg(*list, %s%s%s%s);\n",
-                   ftype == GET && is_const?"const ":"", ptype, had_star?"":" ", add_star?"*":"", pname,
-                   ftype == GET && is_const?"const ":"", add_star ? ptype : _varg_upgr(ptype), !had_star && add_star?" ":"", add_star?"*":"");
+                   is_const?"const ":"", ptype, had_star?"":" ", add_star?"*":"", pname,
+                   is_const?"const ":"", add_star ? ptype : _varg_upgr(ptype), !had_star && add_star?" ":"", add_star?"*":"");
              eina_strbuf_append_printf(params, ", %s", pname);
              eina_strbuf_append_printf(full_params, ", %s%s%s%s%s",
-                   ftype == GET && eolian_parameter_get_const_attribute_get(data)?"const ":"",
+                   is_const?"const ":"",
                    ptype, had_star?"":" ", add_star?"*":"", pname);
           }
      }
index 99ed371b4f6070da99e595a9e4a5cdd8e0bfe6cf..2a3ca705e975472f6d42f6f4a672ac6d31c8a5b9 100644 (file)
@@ -111,7 +111,7 @@ _eapi_decl_func_generate(const char *classname, Eolian_Function funcid, Eolian_F
         eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, &pdesc);
         leg_param_idx++;
         eina_strbuf_append_printf(fparam, ", %s%s %s",
-              eolian_parameter_get_const_attribute_get(data)?"const":"",
+              eolian_parameter_const_attribute_get(data, ftype == GET)?"const":"",
               ptype, pname);
         eina_strbuf_append_printf(descparam, " * @param[in] %s %s\n", pname, pdesc?pdesc:"No description supplied.");
         if (eolian_parameter_is_nonull((Eolian_Function_Parameter)data))
@@ -141,7 +141,7 @@ _eapi_decl_func_generate(const char *classname, Eolian_Function funcid, Eolian_F
             if (ftype == SET) pdir = EOLIAN_IN_PARAM;
             leg_param_idx++;
             eina_strbuf_append_printf(fparam, ", %s%s%s%s%s",
-                  eolian_parameter_get_const_attribute_get(data)?"const":"",
+                  eolian_parameter_const_attribute_get(data, ftype == GET)?"const":"",
                   ptype, had_star?"":" ", add_star?"*":"", pname);
             const char *dir_str = str_dir[(int)pdir];
             eina_strbuf_append_printf(descparam, " * @param[%s] %s %s\n", dir_str, pname, pdesc?pdesc:"No description supplied.");
@@ -224,7 +224,7 @@ _eapi_func_generate(const char *classname, Eolian_Function funcid, Eolian_Functi
                   void* data = eina_list_data_get(l);
                   eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, &retname, NULL);
                   var_as_ret = EINA_TRUE;
-                  ret_const = eolian_parameter_get_const_attribute_get(data);
+                  ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
                }
           }
      }
@@ -270,7 +270,7 @@ _eapi_func_generate(const char *classname, Eolian_Function funcid, Eolian_Functi
         const char *ptype;
         eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, NULL);
         eina_strbuf_append_printf(fparam, ", %s%s %s",
-              ftype == GET && eolian_parameter_get_const_attribute_get(data)?"const ":"",
+              eolian_parameter_const_attribute_get(data, ftype == GET)?"const ":"",
               ptype, pname);
         if (eina_strbuf_length_get(eoparam)) eina_strbuf_append(eoparam, ", ");
         eina_strbuf_append_printf(eoparam, "%s", pname);
@@ -286,7 +286,7 @@ _eapi_func_generate(const char *classname, Eolian_Function funcid, Eolian_Functi
             Eina_Bool had_star = !!strchr(ptype, '*');
             if (ftype == UNRESOLVED || ftype == METHOD_FUNC) add_star = (pdir == EOLIAN_OUT_PARAM);
             eina_strbuf_append_printf(fparam, ", %s%s%s%s%s",
-                  ftype == GET && eolian_parameter_get_const_attribute_get(data)?"const ":"",
+                  eolian_parameter_const_attribute_get(data, ftype == GET)?"const ":"",
                   ptype, had_star?"":" ", add_star?"*":"", pname);
             if (eina_strbuf_length_get(eoparam)) eina_strbuf_append(eoparam, ", ");
             eina_strbuf_append_printf(eoparam, "%s", pname);
index d1b3bc4fe33a07e65fd98a593d585665e2e71075..951e521a41dfd7706fa6cbcb73cb25c05a6f67ef 100644 (file)
@@ -423,11 +423,12 @@ EAPI Eina_Stringshare *eolian_parameter_name_get(const Eolian_Function_Parameter
  * parameter in the get operation.
  *
  * @param[in] param_desc parameter handle
+ * @param[in] is_get indicates if the information needed is for get or set.
  * @return EINA_TRUE if const in get, EINA_FALSE otherwise
  *
  * @ingroup Eolian
  */
-EAPI Eina_Bool eolian_parameter_get_const_attribute_get(Eolian_Function_Parameter param_desc);
+EAPI Eina_Bool eolian_parameter_const_attribute_get(Eolian_Function_Parameter param_desc, Eina_Bool is_get);
 
 /*
  * @brief Indicates if a parameter cannot be NULL.
index 08c36b3b1c45dc1c34f3f4b041999a9b6c57d613..d772e1624f38fed3639bbedca6362b5f46443c69 100644 (file)
@@ -4434,22 +4434,18 @@ eo_tokenizer_database_fill(const char *filename)
                         accessor->comment);
                   Eo_Accessor_Param *acc_param;
                   Eina_List *m2;
-                  /* Only in get access, we check const attribute */
-                  if (accessor->type == GETTER)
+                  EINA_LIST_FOREACH(accessor->params, m2, acc_param)
                     {
-                       EINA_LIST_FOREACH(accessor->params, m2, acc_param)
+                       Eolian_Function_Parameter desc = eolian_function_parameter_get(foo_id, acc_param->name);
+                       if (!desc)
                          {
-                            Eolian_Function_Parameter desc = eolian_function_parameter_get(foo_id, acc_param->name);
-                            if (!desc)
-                              {
-                                 printf("Error - %s not known as parameter of property %s\n", acc_param->name, prop->name);
-                              }
-                            else
-                               if (strstr(acc_param->attrs, "const"))
-                                 {
-                                    database_parameter_get_const_attribute_set(desc, EINA_TRUE);
-                                 }
+                            printf("Error - %s not known as parameter of property %s\n", acc_param->name, prop->name);
                          }
+                       else
+                          if (strstr(acc_param->attrs, "const"))
+                            {
+                               database_parameter_const_attribute_set(desc, accessor->type == GETTER, EINA_TRUE);
+                            }
                     }
                }
              database_class_function_add(kls->name, foo_id);
index 3c1fe2c364f08f4e3f7ad62ab8aad80378462fb6..e30ba1eb5b66a9eb54b86e10bf44eb11bd854e1d 100644 (file)
@@ -1408,22 +1408,18 @@ eo_tokenizer_database_fill(const char *filename)
                         accessor->comment);
                   Eo_Accessor_Param *acc_param;
                   Eina_List *m2;
-                  /* Only in get access, we check const attribute */
-                  if (accessor->type == GETTER)
+                  EINA_LIST_FOREACH(accessor->params, m2, acc_param)
                     {
-                       EINA_LIST_FOREACH(accessor->params, m2, acc_param)
+                       Eolian_Function_Parameter desc = eolian_function_parameter_get(foo_id, acc_param->name);
+                       if (!desc)
                          {
-                            Eolian_Function_Parameter desc = eolian_function_parameter_get(foo_id, acc_param->name);
-                            if (!desc)
-                              {
-                                 printf("Error - %s not known as parameter of property %s\n", acc_param->name, prop->name);
-                              }
-                            else
-                               if (strstr(acc_param->attrs, "const"))
-                                 {
-                                    database_parameter_get_const_attribute_set(desc, EINA_TRUE);
-                                 }
+                            printf("Error - %s not known as parameter of property %s\n", acc_param->name, prop->name);
                          }
+                       else
+                          if (strstr(acc_param->attrs, "const"))
+                            {
+                               database_parameter_const_attribute_set(desc, accessor->type == GETTER, EINA_TRUE);
+                            }
                     }
                }
              database_class_function_add(kls->name, foo_id);
index c24533ddb3bf6cc1f9bfa98fe94785b01ffa6949..f296c742cceebb30f60b54c24c80447164724682 100644 (file)
@@ -52,7 +52,8 @@ typedef struct
    Eina_Stringshare *type;
    Eina_Stringshare *description;
    Eolian_Parameter_Dir param_dir;
-   Eina_Bool is_const :1; /* True if const in this function (e.g get) but not const in the opposite one (e.g set) */
+   Eina_Bool is_const_on_get :1; /* True if const in this the get property */
+   Eina_Bool is_const_on_set :1; /* True if const in this the set property */
    Eina_Bool nonull :1; /* True if this argument cannot be NULL */
    Eina_Bool own :1; /* True if the ownership of this argument passes to the caller/callee */
 } _Parameter_Desc;
@@ -790,19 +791,25 @@ eolian_parameter_information_get(Eolian_Function_Parameter param_desc, Eolian_Pa
 }
 
 void
-database_parameter_get_const_attribute_set(Eolian_Function_Parameter param_desc, Eina_Bool is_const)
+database_parameter_const_attribute_set(Eolian_Function_Parameter param_desc, Eina_Bool is_get, Eina_Bool is_const)
 {
    _Parameter_Desc *param = (_Parameter_Desc *)param_desc;
    EINA_SAFETY_ON_NULL_RETURN(param);
-   param->is_const = is_const;
+   if (is_get)
+      param->is_const_on_get = is_const;
+   else
+      param->is_const_on_set = is_const;
 }
 
 EAPI Eina_Bool
-eolian_parameter_get_const_attribute_get(Eolian_Function_Parameter param_desc)
+eolian_parameter_const_attribute_get(Eolian_Function_Parameter param_desc, Eina_Bool is_get)
 {
    _Parameter_Desc *param = (_Parameter_Desc *)param_desc;
    EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE);
-   return param->is_const;
+   if (is_get)
+      return param->is_const_on_get;
+   else
+      return param->is_const_on_set;
 }
 
 void
index 44ce8ad42fb624742562fef019074d426de422d9..797fe5936f45f394555c7b4d9e3db78e5fd1d359 100644 (file)
@@ -86,7 +86,7 @@ Eolian_Function_Parameter database_property_value_add(Eolian_Function foo_id, co
 /* Add a parameter to a method */
 Eolian_Function_Parameter database_method_parameter_add(Eolian_Function foo_id, Eolian_Parameter_Dir param_dir, const char *type, const char *name, const char *description);
 
-void database_parameter_get_const_attribute_set(Eolian_Function_Parameter param_desc, Eina_Bool is_const);
+void database_parameter_const_attribute_set(Eolian_Function_Parameter param_desc, Eina_Bool is_get, Eina_Bool is_const);
 
 void database_parameter_nonull_set(Eolian_Function_Parameter, Eina_Bool nonull);