summaryrefslogtreecommitdiff
path: root/src/bin/eolian/eo_generator.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-06-27 14:47:40 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2014-06-30 17:20:39 +0100
commit7b54a0101c607cc92d299bf1662c36d6ccc5b6f3 (patch)
tree3a642784c2c71605dcc0f64cfae1fd2de74281a4 /src/bin/eolian/eo_generator.c
parentba362d350fe29ae5526a6a67e5cb26575233139b (diff)
eolian: new type API
This new API supports function pointer types, multiple type subtypes, const attribute without parsing the name string, own attribute for any partial type and more. This commit also updates the C and C++ generators so that they compile and generate correct code. @feature
Diffstat (limited to '')
-rw-r--r--src/bin/eolian/eo_generator.c49
1 files changed, 39 insertions, 10 deletions
diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c
index afea024025..5f30ff5c02 100644
--- a/src/bin/eolian/eo_generator.c
+++ b/src/bin/eolian/eo_generator.c
@@ -89,23 +89,24 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
89 char descname[0xFF]; 89 char descname[0xFF];
90 char *tmpstr = malloc(0x1FF); 90 char *tmpstr = malloc(0x1FF);
91 Eina_Bool var_as_ret = EINA_FALSE; 91 Eina_Bool var_as_ret = EINA_FALSE;
92 Eolian_Type rettypet = NULL;
92 const char *rettype = NULL; 93 const char *rettype = NULL;
93 Eina_Bool ret_const = EINA_FALSE; 94 Eina_Bool ret_const = EINA_FALSE;
94 Eolian_Function_Scope scope = eolian_function_scope_get(func); 95 Eolian_Function_Scope scope = eolian_function_scope_get(func);
95 96
96 _class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env); 97 _class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env);
97 char *fsuffix = ""; 98 char *fsuffix = "";
98 rettype = eolian_function_return_type_get(func, ftype); 99 rettypet = eolian_function_return_type_get(func, ftype);
99 if (ftype == EOLIAN_PROP_GET) 100 if (ftype == EOLIAN_PROP_GET)
100 { 101 {
101 fsuffix = "_get"; 102 fsuffix = "_get";
102 if (!rettype) 103 if (!rettypet)
103 { 104 {
104 l = eolian_parameters_list_get(func); 105 l = eolian_parameters_list_get(func);
105 if (eina_list_count(l) == 1) 106 if (eina_list_count(l) == 1)
106 { 107 {
107 data = eina_list_data_get(l); 108 data = eina_list_data_get(l);
108 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, NULL, NULL); 109 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettypet, NULL, NULL);
109 var_as_ret = EINA_TRUE; 110 var_as_ret = EINA_TRUE;
110 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE); 111 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
111 } 112 }
@@ -151,27 +152,35 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
151 152
152 EINA_LIST_FOREACH(eolian_property_keys_list_get(func), l, data) 153 EINA_LIST_FOREACH(eolian_property_keys_list_get(func), l, data)
153 { 154 {
155 Eolian_Type ptypet;
154 const char *pname; 156 const char *pname;
155 const char *ptype; 157 const char *ptype;
156 const char *pdesc = NULL; 158 const char *pdesc = NULL;
157 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, &pdesc); 159 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptypet, &pname, &pdesc);
160
161 ptype = eolian_type_c_type_get(ptypet);
158 162
159 eina_strbuf_append_printf(str_pardesc, tmpl_eo_pardesc, "in", pname, pdesc?pdesc:"No description supplied."); 163 eina_strbuf_append_printf(str_pardesc, tmpl_eo_pardesc, "in", pname, pdesc?pdesc:"No description supplied.");
160 164
161 if (eina_strbuf_length_get(str_par)) eina_strbuf_append(str_par, ", "); 165 if (eina_strbuf_length_get(str_par)) eina_strbuf_append(str_par, ", ");
162 eina_strbuf_append_printf(str_par, "%s %s", ptype, pname); 166 eina_strbuf_append_printf(str_par, "%s %s", ptype, pname);
167 eina_stringshare_del(ptype);
163 } 168 }
164 169
165 if (!var_as_ret) 170 if (!var_as_ret)
166 { 171 {
167 EINA_LIST_FOREACH(eolian_parameters_list_get(func), l, data) 172 EINA_LIST_FOREACH(eolian_parameters_list_get(func), l, data)
168 { 173 {
174 Eolian_Type ptypet;
169 const char *pname; 175 const char *pname;
170 const char *ptype; 176 const char *ptype;
171 const char *pdesc; 177 const char *pdesc;
172 Eina_Bool add_star = EINA_FALSE; 178 Eina_Bool add_star = EINA_FALSE;
173 Eolian_Parameter_Dir pdir; 179 Eolian_Parameter_Dir pdir;
174 eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, &pdesc); 180 eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptypet, &pname, &pdesc);
181
182 ptype = eolian_type_c_type_get(ptypet);
183
175 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET); 184 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
176 if (ftype == EOLIAN_PROP_GET) { 185 if (ftype == EOLIAN_PROP_GET) {
177 add_star = EINA_TRUE; 186 add_star = EINA_TRUE;
@@ -190,9 +199,12 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
190 is_const?"const ":"", 199 is_const?"const ":"",
191 ptype, had_star?"":" ", add_star?"*":"", pname); 200 ptype, had_star?"":" ", add_star?"*":"", pname);
192 201
202 eina_stringshare_del(ptype);
193 } 203 }
194 } 204 }
195 205
206 if (rettypet) rettype = eolian_type_c_type_get(rettypet);
207
196 tmpstr[0] = '\0'; 208 tmpstr[0] = '\0';
197 sprintf(tmpstr, "%s%s%s", 209 sprintf(tmpstr, "%s%s%s",
198 ret_const ? "const " : "", 210 ret_const ? "const " : "",
@@ -207,6 +219,8 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
207 eina_strbuf_replace_all(str_func, "@#ret_desc", eina_strbuf_string_get(str_retdesc)); 219 eina_strbuf_replace_all(str_func, "@#ret_desc", eina_strbuf_string_get(str_retdesc));
208 eina_strbuf_replace_all(str_func, "@#list_typecheck", eina_strbuf_string_get(str_typecheck)); 220 eina_strbuf_replace_all(str_func, "@#list_typecheck", eina_strbuf_string_get(str_typecheck));
209 221
222 if (rettype) eina_stringshare_del(rettype);
223
210 free(tmpstr); 224 free(tmpstr);
211 eina_strbuf_free(str_par); 225 eina_strbuf_free(str_par);
212 eina_strbuf_free(str_retdesc); 226 eina_strbuf_free(str_retdesc);
@@ -317,6 +331,7 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
317 _eolian_class_func_vars func_env; 331 _eolian_class_func_vars func_env;
318 const char *suffix = ""; 332 const char *suffix = "";
319 Eina_Bool var_as_ret = EINA_FALSE; 333 Eina_Bool var_as_ret = EINA_FALSE;
334 Eolian_Type rettypet = NULL;
320 const char *rettype = NULL; 335 const char *rettype = NULL;
321 const char *retname = NULL; 336 const char *retname = NULL;
322 Eina_Bool ret_const = EINA_FALSE; 337 Eina_Bool ret_const = EINA_FALSE;
@@ -330,19 +345,19 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
330 Eina_Strbuf *params = eina_strbuf_new(); /* only variables names */ 345 Eina_Strbuf *params = eina_strbuf_new(); /* only variables names */
331 Eina_Strbuf *full_params = eina_strbuf_new(); /* variables types + names */ 346 Eina_Strbuf *full_params = eina_strbuf_new(); /* variables types + names */
332 347
333 rettype = eolian_function_return_type_get(funcid, ftype); 348 rettypet = eolian_function_return_type_get(funcid, ftype);
334 retname = "ret"; 349 retname = "ret";
335 if (ftype == EOLIAN_PROP_GET) 350 if (ftype == EOLIAN_PROP_GET)
336 { 351 {
337 suffix = "_get"; 352 suffix = "_get";
338 add_star = EINA_TRUE; 353 add_star = EINA_TRUE;
339 if (!rettype) 354 if (!rettypet)
340 { 355 {
341 const Eina_List *l = eolian_parameters_list_get(funcid); 356 const Eina_List *l = eolian_parameters_list_get(funcid);
342 if (eina_list_count(l) == 1) 357 if (eina_list_count(l) == 1)
343 { 358 {
344 void* data = eina_list_data_get(l); 359 void* data = eina_list_data_get(l);
345 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, &retname, NULL); 360 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettypet, &retname, NULL);
346 var_as_ret = EINA_TRUE; 361 var_as_ret = EINA_TRUE;
347 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE); 362 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
348 } 363 }
@@ -358,24 +373,33 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
358 373
359 EINA_LIST_FOREACH(eolian_property_keys_list_get(funcid), l, data) 374 EINA_LIST_FOREACH(eolian_property_keys_list_get(funcid), l, data)
360 { 375 {
376 Eolian_Type ptypet;
361 const char *pname; 377 const char *pname;
362 const char *ptype; 378 const char *ptype;
363 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, NULL); 379 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptypet, &pname, NULL);
380
381 ptype = eolian_type_c_type_get(ptypet);
382
364 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET); 383 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
365 if (eina_strbuf_length_get(params)) eina_strbuf_append(params, ", "); 384 if (eina_strbuf_length_get(params)) eina_strbuf_append(params, ", ");
366 eina_strbuf_append_printf(params, "%s", pname); 385 eina_strbuf_append_printf(params, "%s", pname);
367 eina_strbuf_append_printf(full_params, ", %s%s %s", 386 eina_strbuf_append_printf(full_params, ", %s%s %s",
368 is_const?"const ":"", 387 is_const?"const ":"",
369 ptype, pname); 388 ptype, pname);
389 eina_stringshare_del(ptype);
370 } 390 }
371 if (!var_as_ret) 391 if (!var_as_ret)
372 { 392 {
373 EINA_LIST_FOREACH(eolian_parameters_list_get(funcid), l, data) 393 EINA_LIST_FOREACH(eolian_parameters_list_get(funcid), l, data)
374 { 394 {
395 Eolian_Type ptypet;
375 const char *pname; 396 const char *pname;
376 const char *ptype; 397 const char *ptype;
377 Eolian_Parameter_Dir pdir; 398 Eolian_Parameter_Dir pdir;
378 eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, NULL); 399 eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptypet, &pname, NULL);
400
401 ptype = eolian_type_c_type_get(ptypet);
402
379 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET); 403 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
380 Eina_Bool had_star = !!strchr(ptype, '*'); 404 Eina_Bool had_star = !!strchr(ptype, '*');
381 if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM); 405 if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM);
@@ -384,9 +408,12 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
384 eina_strbuf_append_printf(full_params, ", %s%s%s%s%s", 408 eina_strbuf_append_printf(full_params, ", %s%s%s%s%s",
385 is_const?"const ":"", 409 is_const?"const ":"",
386 ptype, had_star?"":" ", add_star?"*":"", pname); 410 ptype, had_star?"":" ", add_star?"*":"", pname);
411 eina_stringshare_del(ptype);
387 } 412 }
388 } 413 }
389 414
415 if (rettypet) rettype = eolian_type_c_type_get(rettypet);
416
390 if (need_implementation) 417 if (need_implementation)
391 { 418 {
392 Eina_Strbuf *ret_param = eina_strbuf_new(); 419 Eina_Strbuf *ret_param = eina_strbuf_new();
@@ -451,6 +478,8 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
451 } 478 }
452 eina_strbuf_append(buf, eina_strbuf_string_get(fbody)); 479 eina_strbuf_append(buf, eina_strbuf_string_get(fbody));
453 480
481 if (rettype) eina_stringshare_del(rettype);
482
454 eina_strbuf_free(va_args); 483 eina_strbuf_free(va_args);
455 eina_strbuf_free(full_params); 484 eina_strbuf_free(full_params);
456 eina_strbuf_free(params); 485 eina_strbuf_free(params);