summaryrefslogtreecommitdiff
path: root/src/bin/eolian/eo1_generator.c
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-06-05 10:11:13 +0300
committerDaniel Zaoui <daniel.zaoui@samsung.com>2014-06-05 10:11:13 +0300
commit5c55ce49e613a8c10ffe2040979c8bc0dd9ccbf4 (patch)
treef989a168878fc5cb4702d4d01d5fcdb497d73cc1 /src/bin/eolian/eo1_generator.c
parent97913753ea8dbb9eb544e69c96f4fbabe9347427 (diff)
Eolian: rename internal files.
This files were needed to be renamed a long time ago :-)
Diffstat (limited to 'src/bin/eolian/eo1_generator.c')
-rw-r--r--src/bin/eolian/eo1_generator.c887
1 files changed, 0 insertions, 887 deletions
diff --git a/src/bin/eolian/eo1_generator.c b/src/bin/eolian/eo1_generator.c
deleted file mode 100644
index 8e5b6f2d97..0000000000
--- a/src/bin/eolian/eo1_generator.c
+++ /dev/null
@@ -1,887 +0,0 @@
1#include <Eina.h>
2#include <string.h>
3
4#include "Eolian.h"
5#include "eo1_generator.h"
6#include "common_funcs.h"
7
8static _eolian_class_vars class_env;
9
10static const char
11tmpl_dtor[] = "\
12static void\n\
13_gen_@#class_class_destructor(Eo_Class *klass)\n\
14{\n\
15 _@#class_class_destructor(klass);\n\
16}\n\
17\n\
18";
19
20static const char
21tmpl_eo_ops_desc[] = "\
22static Eo_Op_Description _@#class_op_desc[] = {@#list_op\n\
23 EO_OP_SENTINEL\n\
24};\n\n";
25
26static const char
27tmpl_events_desc[] = "\
28static const Eo_Event_Description *_@#class_event_desc[] = {@#list_evdesc\n\
29 NULL\n\
30};\n\n";
31
32static const char
33tmpl_eo_src[] = "\
34@#functions_body\
35\n\
36@#ctor_func\
37@#dtor_func\
38@#ops_desc\
39@#events_desc\
40static const Eo_Class_Description _@#class_class_desc = {\n\
41 EO_VERSION,\n\
42 \"@#Class\",\n\
43 @#type_class,\n\
44 @#eo_class_desc_ops,\n\
45 @#Events_Desc,\n\
46 @#SizeOfData,\n\
47 @#ctor_name,\n\
48 @#dtor_name\n\
49};\n\
50\n\
51EO_DEFINE_CLASS(@#class_class_get, &_@#class_class_desc, @#list_inheritNULL);\
52";
53
54static const char
55tmpl_eo_op_desc[] = "\n EO_OP_FUNC(@#eoprefix_@#func, _@#class_@#func, \"@#desc\"),";
56
57static const char
58tmpl_eo_obj_header[] = "\
59#define @#CLASS_CLASS @#class_class_get()\n\
60\n\
61const Eo_Class *@#class_class_get(void) EINA_CONST;\n\
62\n\
63";
64
65static const char
66tmpl_eo_subid[] = "\n @#EOPREFIX_SUB_ID_@#FUNC,";
67
68static const char
69tmpl_eo_subid_apnd[] = " @#EOPREFIX_SUB_ID_@#FUNC,\n";
70
71static const char
72tmpl_eo_funcdef_doxygen[] = "\
73/**\n\
74 * @def @#eoprefix_@#func\n\
75 *\n\
76@#desc\n\
77 *\n\
78@#list_desc_param\
79@#ret_desc\
80 *\n\
81 */\n";
82
83static const char
84tmpl_eo_funcdef[] = "EAPI @#rettype @#eoprefix_@#func(@#full_params);\n";
85
86static const char
87tmpl_eo_pardesc[] =" * @param[%s] %s %s\n";
88
89#if 0
90static const char
91tmpl_eo_retdesc[] =" * @return %s\n";
92#endif
93
94static Eina_Bool
95eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Function_Type ftype, Eina_Strbuf *functext)
96{
97 const char *str_dir[] = {"in", "out", "inout"};
98 const Eina_List *l;
99 void *data;
100 char funcname[0xFF];
101 char descname[0xFF];
102 char *tmpstr = malloc(0x1FF);
103 Eina_Bool var_as_ret = EINA_FALSE;
104 const char *rettype = NULL;
105 Eina_Bool ret_const = EINA_FALSE;
106 Eolian_Function_Scope scope = eolian_function_scope_get(func);
107
108 char *fsuffix = "";
109 rettype = eolian_function_return_type_get(func, ftype);
110 if (ftype == EOLIAN_PROP_GET)
111 {
112 fsuffix = "_get";
113 if (!rettype)
114 {
115 l = eolian_parameters_list_get(func);
116 if (eina_list_count(l) == 1)
117 {
118 data = eina_list_data_get(l);
119 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, NULL, NULL);
120 var_as_ret = EINA_TRUE;
121 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
122 }
123 }
124 }
125 if (ftype == EOLIAN_PROP_SET) fsuffix = "_set";
126
127 sprintf (funcname, "%s%s", eolian_function_name_get(func), fsuffix);
128 sprintf (descname, "comment%s", fsuffix);
129 const char *funcdesc = eolian_function_description_get(func, descname);
130
131 Eina_Strbuf *str_func = eina_strbuf_new();
132 if (scope == EOLIAN_SCOPE_PROTECTED)
133 eina_strbuf_append_printf(str_func, "#ifdef %s_PROTECTED\n", class_env.upper_classname);
134 _template_fill(str_func, tmpl_eo_funcdef_doxygen, class, NULL, funcname, EINA_FALSE);
135 _template_fill(str_func, tmpl_eo_funcdef, class, NULL, funcname, EINA_FALSE);
136 if (scope == EOLIAN_SCOPE_PROTECTED)
137 eina_strbuf_append_printf(str_func, "#endif\n");
138 eina_strbuf_append_printf(str_func, "\n");
139
140 eina_strbuf_replace_all(str_func, "@#EOPREFIX", class_env.upper_eo_prefix);
141 eina_strbuf_replace_all(str_func, "@#eoprefix", class_env.lower_eo_prefix);
142
143 Eina_Strbuf *linedesc = eina_strbuf_new();
144 eina_strbuf_append(linedesc, funcdesc ? funcdesc : "No description supplied.");
145 if (eina_strbuf_length_get(linedesc))
146 {
147 eina_strbuf_replace_all(linedesc, "\n", "\n * ");
148 eina_strbuf_replace_all(linedesc, " * \n", " *\n");
149 eina_strbuf_prepend(linedesc, " * ");
150 }
151 else
152 {
153 eina_strbuf_append(linedesc, " *");
154 }
155
156 eina_strbuf_replace_all(str_func, "@#desc", eina_strbuf_string_get(linedesc));
157 eina_strbuf_free(linedesc);
158
159 Eina_Strbuf *str_par = eina_strbuf_new();
160 Eina_Strbuf *str_pardesc = eina_strbuf_new();
161 Eina_Strbuf *str_retdesc = eina_strbuf_new();
162 Eina_Strbuf *str_typecheck = eina_strbuf_new();
163
164 EINA_LIST_FOREACH(eolian_property_keys_list_get(func), l, data)
165 {
166 const char *pname;
167 const char *ptype;
168 const char *pdesc = NULL;
169 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, &pdesc);
170
171 eina_strbuf_append_printf(str_pardesc, tmpl_eo_pardesc, "in", pname, pdesc?pdesc:"No description supplied.");
172
173 if (eina_strbuf_length_get(str_par)) eina_strbuf_append(str_par, ", ");
174 eina_strbuf_append_printf(str_par, "%s %s", ptype, pname);
175 }
176
177 if (!var_as_ret)
178 {
179 EINA_LIST_FOREACH(eolian_parameters_list_get(func), l, data)
180 {
181 const char *pname;
182 const char *ptype;
183 const char *pdesc;
184 Eina_Bool add_star = EINA_FALSE;
185 Eolian_Parameter_Dir pdir;
186 eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, &pdesc);
187 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
188 if (ftype == EOLIAN_PROP_GET) {
189 add_star = EINA_TRUE;
190 pdir = EOLIAN_OUT_PARAM;
191 }
192 if (ftype == EOLIAN_PROP_SET) pdir = EOLIAN_IN_PARAM;
193 if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM);
194 Eina_Bool had_star = !!strchr(ptype, '*');
195
196 const char *dir_str = str_dir[(int)pdir];
197
198 eina_strbuf_append_printf(str_pardesc, tmpl_eo_pardesc, dir_str, pname, pdesc?pdesc:"No description supplied.");
199
200 if (eina_strbuf_length_get(str_par)) eina_strbuf_append(str_par, ", ");
201 eina_strbuf_append_printf(str_par, "%s%s%s%s%s",
202 is_const?"const ":"",
203 ptype, had_star?"":" ", add_star?"*":"", pname);
204
205 }
206 }
207
208 tmpstr[0] = '\0';
209 sprintf(tmpstr, "%s%s%s",
210 ret_const ? "const " : "",
211 rettype ? rettype : "void",
212 rettype && strchr(rettype, '*')?"":" ");
213 eina_strbuf_replace_all(str_func, "@#rettype", tmpstr);
214
215 eina_strbuf_replace_all(str_func, "@#list_param", eina_strbuf_string_get(str_par));
216 if (!eina_strbuf_length_get(str_par)) eina_strbuf_append(str_par, "void");
217 eina_strbuf_replace_all(str_func, "@#full_params", eina_strbuf_string_get(str_par));
218 eina_strbuf_replace_all(str_func, "@#list_desc_param", eina_strbuf_string_get(str_pardesc));
219 eina_strbuf_replace_all(str_func, "@#ret_desc", eina_strbuf_string_get(str_retdesc));
220 eina_strbuf_replace_all(str_func, "@#list_typecheck", eina_strbuf_string_get(str_typecheck));
221
222 free(tmpstr);
223 eina_strbuf_free(str_par);
224 eina_strbuf_free(str_retdesc);
225 eina_strbuf_free(str_pardesc);
226 eina_strbuf_free(str_typecheck);
227
228 eina_strbuf_append(functext, eina_strbuf_string_get(str_func));
229 eina_strbuf_free(str_func);
230
231 return EINA_TRUE;
232}
233
234Eina_Bool
235eo_header_generate(const Eolian_Class class, Eina_Strbuf *buf)
236{
237 const Eolian_Function_Type ftype_order[] = {EOLIAN_CTOR, EOLIAN_PROPERTY, EOLIAN_METHOD};
238 const Eina_List *l;
239 void *data;
240 char *tmpstr = malloc(0x1FF);
241 Eina_Strbuf * str_hdr = eina_strbuf_new();
242
243 const char *desc = eolian_class_description_get(class);
244 Eina_Strbuf *linedesc = eina_strbuf_new();
245 eina_strbuf_append(linedesc, "/**\n");
246 _class_env_create(class, NULL, &class_env);
247
248 if (desc)
249 {
250 eina_strbuf_append(linedesc, desc);
251 eina_strbuf_replace_all(linedesc, "\n", "\n * ");
252 }
253
254 eina_strbuf_append(linedesc, "\n */\n");
255 eina_strbuf_replace_all(linedesc, " * \n", " *\n"); /* Remove trailing whitespaces */
256 eina_strbuf_append(buf, eina_strbuf_string_get(linedesc));
257 eina_strbuf_free(linedesc);
258
259 _template_fill(str_hdr, tmpl_eo_obj_header, class, NULL, "", EINA_TRUE);
260
261 eina_strbuf_replace_all(str_hdr, "@#EOPREFIX", class_env.upper_eo_prefix);
262 eina_strbuf_replace_all(str_hdr, "@#eoprefix", class_env.lower_eo_prefix);
263
264 Eina_Strbuf *str_subid = eina_strbuf_new();
265 Eina_Strbuf *str_ev = eina_strbuf_new();
266 Eina_Strbuf *str_extrn_ev = eina_strbuf_new();
267 Eina_Strbuf *tmpbuf = eina_strbuf_new();
268
269 Eolian_Event event;
270 EINA_LIST_FOREACH(eolian_class_events_list_get(class), l, event)
271 {
272 const char *evname = NULL;
273 const char *evdesc = NULL;
274 eolian_class_event_information_get(event, &evname, NULL, &evdesc);
275
276 if (!evdesc) evdesc = "No description";
277 eina_strbuf_reset(tmpbuf);
278 eina_strbuf_append(tmpbuf, evdesc);
279 eina_strbuf_replace_all(tmpbuf, "\n", "\n * ");
280 eina_strbuf_prepend(tmpbuf," * ");
281 eina_strbuf_append_printf(str_ev, "\n/**\n%s\n */\n", eina_strbuf_string_get(tmpbuf));
282
283 _template_fill(tmpbuf, "@#CLASS_EVENT_@#FUNC", class, NULL, evname, EINA_TRUE);
284 eina_strbuf_replace_all(tmpbuf, ",", "_");
285 const char* s = eina_strbuf_string_get(tmpbuf);
286 eina_strbuf_append_printf(str_ev, "#define %s (&(_%s))\n", s, s);
287 eina_strbuf_append_printf(str_extrn_ev, "EAPI extern const Eo_Event_Description _%s;\n", s);
288 }
289
290 int i;
291 for (i = 0; i < 3; i++)
292 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, ftype_order[i]), l, data)
293 {
294 const Eolian_Function_Type ftype = eolian_function_type_get((Eolian_Function)data);
295 const char *funcname = eolian_function_name_get((Eolian_Function)data);
296 Eina_Bool prop_read = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_GET ) ? EINA_TRUE : EINA_FALSE ;
297 Eina_Bool prop_write = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_SET ) ? EINA_TRUE : EINA_FALSE ;
298
299 if (!prop_read && !prop_write)
300 {
301 _template_fill(str_subid, tmpl_eo_subid, class, NULL, funcname, EINA_FALSE);
302 eo_fundef_generate(class, (Eolian_Function)data, EOLIAN_UNRESOLVED, str_hdr);
303 }
304 if (prop_write)
305 {
306 sprintf(tmpstr, "%s_set", funcname);
307 _template_fill(str_subid, tmpl_eo_subid, class, NULL, tmpstr, EINA_FALSE);
308 eo_fundef_generate(class, (Eolian_Function)data, EOLIAN_PROP_SET, str_hdr);
309 }
310 if (prop_read)
311 {
312 sprintf(tmpstr, "%s_get", funcname);
313 _template_fill(str_subid, tmpl_eo_subid, class, NULL, tmpstr, EINA_FALSE);
314 eo_fundef_generate(class, (Eolian_Function)data, EOLIAN_PROP_GET, str_hdr);
315 }
316 eina_strbuf_replace_all(str_subid, "@#EOPREFIX", class_env.upper_eo_prefix);
317 }
318
319 eina_strbuf_replace_all(str_hdr, "@#list_subid", eina_strbuf_string_get(str_subid));
320 eina_strbuf_append(str_hdr, eina_strbuf_string_get(str_extrn_ev));
321 eina_strbuf_append(str_hdr, eina_strbuf_string_get(str_ev));
322
323 eina_strbuf_append(buf, eina_strbuf_string_get(str_hdr));
324
325 free(tmpstr);
326 eina_strbuf_free(str_subid);
327 eina_strbuf_free(str_ev);
328 eina_strbuf_free(str_extrn_ev);
329 eina_strbuf_free(tmpbuf);
330 eina_strbuf_free(str_hdr);
331
332 return EINA_TRUE;
333}
334
335static Eina_Bool
336eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf, _eolian_class_vars *impl_env)
337{
338 const char *suffix = "";
339 Eina_Bool var_as_ret = EINA_FALSE;
340 const char *rettype = NULL;
341 const char *retname = NULL;
342 Eina_Bool ret_const = EINA_FALSE;
343 Eina_Bool add_star = EINA_FALSE;
344
345 Eina_Bool need_implementation = EINA_TRUE;
346 if (!impl_env && eolian_function_is_virtual_pure(funcid, ftype)) need_implementation = EINA_FALSE;
347
348 Eina_Strbuf *fbody = eina_strbuf_new();
349 Eina_Strbuf *va_args = eina_strbuf_new();
350 Eina_Strbuf *params = eina_strbuf_new(); /* only variables names */
351 Eina_Strbuf *full_params = eina_strbuf_new(); /* variables types + names */
352
353 rettype = eolian_function_return_type_get(funcid, ftype);
354 retname = "ret";
355 if (ftype == EOLIAN_PROP_GET)
356 {
357 suffix = "_get";
358 add_star = EINA_TRUE;
359 if (!rettype)
360 {
361 const Eina_List *l = eolian_parameters_list_get(funcid);
362 if (eina_list_count(l) == 1)
363 {
364 void* data = eina_list_data_get(l);
365 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, &retname, NULL);
366 var_as_ret = EINA_TRUE;
367 ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
368 }
369 }
370 }
371 if (ftype == EOLIAN_PROP_SET)
372 {
373 suffix = "_set";
374 }
375
376 const Eina_List *l;
377 void *data;
378
379 EINA_LIST_FOREACH(eolian_property_keys_list_get(funcid), l, data)
380 {
381 const char *pname;
382 const char *ptype;
383 eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, NULL);
384 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
385 if (eina_strbuf_length_get(params)) eina_strbuf_append(params, ", ");
386 eina_strbuf_append_printf(params, "%s", pname);
387 eina_strbuf_append_printf(full_params, ", %s%s %s",
388 is_const?"const ":"",
389 ptype, pname);
390 }
391 if (!var_as_ret)
392 {
393 EINA_LIST_FOREACH(eolian_parameters_list_get(funcid), l, data)
394 {
395 const char *pname;
396 const char *ptype;
397 Eolian_Parameter_Dir pdir;
398 eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, NULL);
399 Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
400 Eina_Bool had_star = !!strchr(ptype, '*');
401 if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM);
402 if (eina_strbuf_length_get(params)) eina_strbuf_append(params, ", ");
403 eina_strbuf_append_printf(params, "%s", pname);
404 eina_strbuf_append_printf(full_params, ", %s%s%s%s%s",
405 is_const?"const ":"",
406 ptype, had_star?"":" ", add_star?"*":"", pname);
407 }
408 }
409
410 if (need_implementation)
411 {
412 Eina_Strbuf *ret_param = eina_strbuf_new();
413 eina_strbuf_append_printf(fbody, "\n");
414 eina_strbuf_append_printf(fbody, "%s%s _%s%s%s_%s%s(Eo *obj, @#Datatype_Data *pd@#full_params);\n\n",
415 ret_const?"const ":"", rettype?rettype:"void",
416 class_env.lower_classname,
417 impl_env?"_":"",
418 impl_env?impl_env->lower_classname:"",
419 eolian_function_name_get(funcid), suffix);
420
421 eina_strbuf_free(ret_param);
422 }
423 if (!impl_env)
424 {
425 Eina_Strbuf *eo_func_decl = eina_strbuf_new();
426 Eina_Bool has_params =
427 eina_list_count(eolian_property_keys_list_get(funcid)) ||
428 (!var_as_ret && eina_list_count(eolian_parameters_list_get(funcid)) != 0);
429 Eina_Bool ret_is_void = (!rettype || !strcmp(rettype, "void"));
430 eina_strbuf_append_printf(eo_func_decl,
431 "EAPI EO_%sFUNC_BODY%s(%s_%s%s",
432 ret_is_void?"VOID_":"", has_params?"V":"",
433 class_env.lower_eo_prefix, eolian_function_name_get(funcid),
434 suffix);
435 if (!ret_is_void)
436 {
437 const char *dflt_ret_val =
438 eolian_function_return_dflt_value_get(funcid, ftype);
439 eina_strbuf_append_printf(eo_func_decl, ", %s%s, %s",
440 ret_const ? "const " : "", rettype,
441 dflt_ret_val?dflt_ret_val:"0");
442
443 }
444 if (has_params)
445 {
446 eina_strbuf_append_printf(eo_func_decl, ", EO_FUNC_CALL(%s)%s",
447 eina_strbuf_string_get(params),
448 eina_strbuf_string_get(full_params));
449 }
450 eina_strbuf_append_printf(eo_func_decl, ");");
451 eina_strbuf_append_printf(fbody, "%s\n", eina_strbuf_string_get(eo_func_decl));
452 eina_strbuf_free(eo_func_decl);
453 }
454
455 if (need_implementation)
456 {
457 eina_strbuf_replace_all(fbody, "@#full_params", eina_strbuf_string_get(full_params));
458 const char *data_type = eolian_class_data_type_get(class);
459 if (data_type && !strcmp(data_type, "null"))
460 eina_strbuf_replace_all(fbody, "@#Datatype_Data", "void");
461 else
462 {
463 if (data_type) eina_strbuf_replace_all(fbody, "@#Datatype_Data", data_type);
464 else eina_strbuf_replace_all(fbody, "@#Datatype", class_env.full_classname);
465 }
466
467 if (!data_type || !strcmp(data_type, "null"))
468 eina_strbuf_replace_all(fbody, "@#Datatype", class_env.full_classname);
469 else
470 eina_strbuf_replace_all(fbody, "@#Datatype_Data", data_type);
471 }
472 eina_strbuf_append(buf, eina_strbuf_string_get(fbody));
473
474 eina_strbuf_free(va_args);
475 eina_strbuf_free(full_params);
476 eina_strbuf_free(params);
477 eina_strbuf_free(fbody);
478 return EINA_TRUE;
479}
480
481static Eina_Bool
482eo_func_desc_generate(const Eolian_Class class, const char *impl_name, const char *func_name, Eina_Strbuf *buf)
483{
484 if (impl_name)
485 _class_func_names_fill(NULL, impl_name, func_name);
486 else
487 _class_func_names_fill(class, NULL, func_name);
488
489 eina_strbuf_reset(buf);
490 eina_strbuf_append_printf(buf,
491 "\n EO_OP_FUNC(%s_ID(%s_SUB_ID_%s), _eo_obj_%s%s%s_%s),",
492 class_env.upper_eo_prefix, class_env.upper_eo_prefix, capfunc,
493 class_env.lower_classname, impl_name?"_":"", impl_name?impl_name:"",
494 func_name);
495 return EINA_TRUE;
496}
497
498static Eina_Bool
499eo_op_desc_generate(const Eolian_Class class, Eolian_Function fid, Eolian_Function_Type ftype,
500 const char *desc, Eina_Strbuf *buf)
501{
502 const char *funcname = eolian_function_name_get(fid);
503 const char *suffix = "";
504
505 eina_strbuf_reset(buf);
506 _class_func_names_fill(class, NULL, funcname);
507 if (ftype == EOLIAN_PROP_GET) suffix = "_get";
508 if (ftype == EOLIAN_PROP_SET) suffix = "_set";
509 Eina_Bool is_virtual_pure = eolian_function_is_virtual_pure(fid, ftype);
510 eina_strbuf_append_printf(buf, "\n EO_OP_FUNC(%s_%s%s, ", class_env.lower_eo_prefix, funcname, suffix);
511 if (!is_virtual_pure)
512 eina_strbuf_append_printf(buf, "_%s_%s%s, \"%s\"),", class_env.lower_classname, funcname, suffix, desc);
513 else
514 eina_strbuf_append_printf(buf, "NULL, \"%s\"),", desc);
515
516 return EINA_TRUE;
517}
518
519static Eina_Bool
520eo_source_beginning_generate(const Eolian_Class class, Eina_Strbuf *buf)
521{
522 const Eina_List *itr;
523
524 Eina_Strbuf *tmpbuf = eina_strbuf_new();
525 Eina_Strbuf *str_ev = eina_strbuf_new();
526
527 Eolian_Event event;
528 EINA_LIST_FOREACH(eolian_class_events_list_get(class), itr, event)
529 {
530 const char *evname;
531 const char *evdesc;
532 char *evdesc_line1;
533
534 eolian_class_event_information_get(event, &evname, NULL, &evdesc);
535 evdesc_line1 = _source_desc_get(evdesc);
536 _template_fill(str_ev, "@#CLASS_EVENT_@#FUNC", class, NULL, evname, EINA_TRUE);
537 eina_strbuf_replace_all(str_ev, ",", "_");
538
539 eina_strbuf_append_printf(tmpbuf,
540 "EAPI const Eo_Event_Description _%s =\n EO_EVENT_DESCRIPTION(\"%s\", \"%s\");\n",
541 eina_strbuf_string_get(str_ev), evname, evdesc_line1);
542 free(evdesc_line1);
543 }
544
545 eina_strbuf_append(buf, eina_strbuf_string_get(tmpbuf));
546
547 eina_strbuf_free(str_ev);
548 eina_strbuf_free(tmpbuf);
549 return EINA_TRUE;
550}
551
552static Eina_Bool
553eo_source_end_generate(const Eolian_Class class, Eina_Strbuf *buf)
554{
555 Eina_Bool ret = EINA_FALSE;
556 const Eina_List *itr;
557 Eolian_Function fn;
558
559 const char *str_classtype = NULL;
560 switch(eolian_class_type_get(class))
561 {
562 case EOLIAN_CLASS_REGULAR:
563 str_classtype = "EO_CLASS_TYPE_REGULAR";
564 break;
565 case EOLIAN_CLASS_ABSTRACT:
566 str_classtype = "EO_CLASS_TYPE_REGULAR_NO_INSTANT";
567 break;
568 case EOLIAN_CLASS_MIXIN:
569 str_classtype = "EO_CLASS_TYPE_MIXIN";
570 break;
571 case EOLIAN_CLASS_INTERFACE:
572 str_classtype = "EO_CLASS_TYPE_INTERFACE";
573 break;
574 default:
575 break;
576 }
577
578 if (!str_classtype)
579 {
580 ERR ("Unknown class type for class %s !", class_env.full_classname);
581 return EINA_FALSE;
582 }
583
584 Eina_Strbuf *str_end = eina_strbuf_new();
585 Eina_Strbuf *tmpbuf = eina_strbuf_new();
586 Eina_Strbuf *str_op = eina_strbuf_new();
587 Eina_Strbuf *str_func = eina_strbuf_new();
588 Eina_Strbuf *str_bodyf = eina_strbuf_new();
589 Eina_Strbuf *str_ev = eina_strbuf_new();
590
591 _template_fill(str_end, tmpl_eo_src, class, NULL, NULL, EINA_TRUE);
592
593 eina_strbuf_replace_all(str_end, "@#type_class", str_classtype);
594 eina_strbuf_replace_all(str_end, "@#EOPREFIX", class_env.upper_eo_prefix);
595 eina_strbuf_replace_all(str_end, "@#eoprefix", class_env.lower_eo_prefix);
596
597 eina_strbuf_reset(tmpbuf);
598 eina_strbuf_replace_all(str_end, "@#ctor_func", eina_strbuf_string_get(tmpbuf));
599
600 eina_strbuf_reset(tmpbuf);
601 if (eolian_class_ctor_enable_get(class))
602 _template_fill(tmpbuf, "_@#class_class_constructor", class, NULL, "", EINA_TRUE);
603 else
604 eina_strbuf_append_printf(tmpbuf, "NULL");
605 eina_strbuf_replace_all(str_end, "@#ctor_name", eina_strbuf_string_get(tmpbuf));
606
607 eina_strbuf_reset(tmpbuf);
608 if (eolian_class_dtor_enable_get(class))
609 {
610 eina_strbuf_replace_all(str_end, "@#dtor_func", eina_strbuf_string_get(tmpbuf));
611 eina_strbuf_reset(tmpbuf);
612 _template_fill(tmpbuf, "_@#class_class_destructor", class, NULL, "", EINA_TRUE);
613 eina_strbuf_replace_all(str_end, "@#dtor_name", eina_strbuf_string_get(tmpbuf));
614 }
615 else
616 {
617 eina_strbuf_replace_all(str_end, "@#dtor_func", "");
618 eina_strbuf_replace_all(str_end, "@#dtor_name", "NULL");
619 }
620
621 eina_strbuf_reset(tmpbuf);
622
623 //Implements - TODO one generate func def for all
624 Eolian_Implement impl_desc;
625 EINA_LIST_FOREACH(eolian_class_implements_list_get(class), itr, impl_desc)
626 {
627 _eolian_class_vars impl_env;
628 char implname[0xFF];
629 Eolian_Class impl_class = NULL;
630 Eolian_Function_Type ftype;
631 Eolian_Function fnid = NULL;
632 const char *funcname = NULL;
633 char *tp = implname;
634
635 if (eolian_implement_information_get(impl_desc, &impl_class, &fnid, &ftype))
636 {
637 _class_env_create(impl_class, NULL, &impl_env);
638 funcname = eolian_function_name_get(fnid);
639
640 sprintf(implname, "%s_%s", class_env.full_classname, impl_env.full_classname);
641 eina_str_tolower(&tp);
642 }
643
644 if (!fnid)
645 {
646 ERR ("Failed to generate implementation of %s - missing form super class",
647 eolian_implement_full_name_get(impl_desc));
648 goto end;
649 }
650
651 switch (ftype)
652 {
653 case EOLIAN_PROP_SET: case EOLIAN_PROP_GET: case EOLIAN_PROPERTY:
654 if (ftype != EOLIAN_PROP_GET)
655 {
656 eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_%s_set, _%s_%s_set),",
657 impl_env.lower_eo_prefix, funcname, implname, funcname);
658 eo_bind_func_generate(class, fnid, EOLIAN_PROP_SET, str_bodyf, &impl_env);
659 }
660
661 if (ftype != EOLIAN_PROP_SET)
662 {
663 eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_%s_get, _%s_%s_get),",
664 impl_env.lower_eo_prefix, funcname, implname, funcname);
665 eo_bind_func_generate(class, fnid, EOLIAN_PROP_GET, str_bodyf, &impl_env);
666 }
667 break;
668 default:
669 eina_strbuf_append_printf(str_op, "\n EO_OP_FUNC_OVERRIDE(%s_%s, _%s_%s),",
670 impl_env.lower_eo_prefix, funcname, implname, funcname);
671 eo_bind_func_generate(class, fnid, ftype, str_bodyf, &impl_env);
672 break;
673 }
674 }
675
676 //Constructors
677 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, EOLIAN_CTOR), itr, fn)
678 {
679 const char *funcname = eolian_function_name_get(fn);
680 char *desc = _source_desc_get(eolian_function_description_get(fn, "comment"));
681 eo_op_desc_generate(class, fn, EOLIAN_CTOR, desc, tmpbuf);
682 eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf));
683 free(desc);
684
685 eo_func_desc_generate(class, NULL, funcname, tmpbuf);
686 eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf));
687
688 eo_bind_func_generate(class, fn, EOLIAN_UNRESOLVED, str_bodyf, NULL);
689 }
690
691 //Properties
692 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, EOLIAN_PROPERTY), itr, fn)
693 {
694 const char *funcname = eolian_function_name_get(fn);
695 const Eolian_Function_Type ftype = eolian_function_type_get(fn);
696 char tmpstr[0xFF];
697
698 Eina_Bool prop_read = ( ftype == EOLIAN_PROP_SET ) ? EINA_FALSE : EINA_TRUE;
699 Eina_Bool prop_write = ( ftype == EOLIAN_PROP_GET ) ? EINA_FALSE : EINA_TRUE;
700
701 if (prop_write)
702 {
703 char *desc = _source_desc_get(eolian_function_description_get(fn, "comment_set"));
704
705 sprintf(tmpstr, "%s_set", funcname);
706 eo_op_desc_generate(class, fn, EOLIAN_PROP_SET, desc, tmpbuf);
707 eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf));
708 free(desc);
709
710 if (!eolian_function_is_virtual_pure(fn, EOLIAN_PROP_SET))
711 eo_func_desc_generate(class, NULL, tmpstr, tmpbuf);
712 else
713 eina_strbuf_reset(tmpbuf);
714 eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf));
715 }
716 if (prop_read)
717 {
718 char *desc = _source_desc_get(eolian_function_description_get(fn, "comment_get"));
719
720 sprintf(tmpstr, "%s_get", funcname);
721 eo_op_desc_generate(class, fn, EOLIAN_PROP_GET, desc, tmpbuf);
722 free(desc);
723 eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf));
724
725 if (!eolian_function_is_virtual_pure(fn, EOLIAN_PROP_GET))
726 eo_func_desc_generate(class, NULL, tmpstr, tmpbuf);
727 else
728 eina_strbuf_reset(tmpbuf);
729 eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf));
730 }
731 }
732
733 //Methods
734 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, EOLIAN_METHOD), itr, fn)
735 {
736 const char *funcname = eolian_function_name_get(fn);
737
738 char *desc = _source_desc_get(eolian_function_description_get(fn, "comment"));
739 eo_op_desc_generate(class, fn, EOLIAN_METHOD, desc, tmpbuf);
740 free(desc);
741 eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf));
742
743 if (!eolian_function_is_virtual_pure(fn, EOLIAN_METHOD))
744 eo_func_desc_generate(class, NULL, funcname, tmpbuf);
745 else
746 eina_strbuf_reset(tmpbuf);
747 eina_strbuf_append(str_func, eina_strbuf_string_get(tmpbuf));
748 }
749
750 Eolian_Event event;
751 EINA_LIST_FOREACH(eolian_class_events_list_get(class), itr, event)
752 {
753 const char *evname;
754
755 eolian_class_event_information_get(event, &evname, NULL, NULL);
756 _template_fill(tmpbuf, "@#CLASS_EVENT_@#FUNC", class, NULL, evname, EINA_TRUE);
757 eina_strbuf_replace_all(tmpbuf, ",", "_");
758 eina_strbuf_append_printf(str_ev, "\n %s,", eina_strbuf_string_get(tmpbuf));
759 }
760
761 eina_strbuf_reset(tmpbuf);
762 if (eina_strbuf_length_get(str_ev))
763 {
764 Eina_Strbuf *events_desc = eina_strbuf_new();
765 _template_fill(events_desc, tmpl_events_desc, class, NULL, "", EINA_TRUE);
766 eina_strbuf_replace_all(events_desc, "@#list_evdesc", eina_strbuf_string_get(str_ev));
767 eina_strbuf_replace_all(str_end, "@#events_desc", eina_strbuf_string_get(events_desc));
768 eina_strbuf_free(events_desc);
769 eina_strbuf_append_printf(tmpbuf, "_%s_event_desc", class_env.lower_classname);
770 }
771 else
772 {
773 eina_strbuf_append_printf(tmpbuf, "NULL");
774 eina_strbuf_replace_all(str_end, "@#events_desc", "");
775 }
776 eina_strbuf_replace_all(str_end, "@#Events_Desc", eina_strbuf_string_get(tmpbuf));
777
778 const char *inherit_name;
779 eina_strbuf_reset(tmpbuf);
780 EINA_LIST_FOREACH(eolian_class_inherits_list_get(class), itr, inherit_name)
781 {
782 Eolian_Class inherit_class = eolian_class_find_by_name(inherit_name);
783 _eolian_class_vars inherit_env;
784 _class_env_create(inherit_class, NULL, &inherit_env);
785 eina_strbuf_append_printf(tmpbuf, "%s_CLASS, ", inherit_env.upper_classname);
786 }
787
788 if (eina_strbuf_length_get(tmpbuf) == 0) eina_strbuf_append(tmpbuf, "NULL, ");
789 eina_strbuf_replace_all(str_end, "@#list_inherit", eina_strbuf_string_get(tmpbuf));
790
791 eina_strbuf_replace_all(str_end, "@#list_func", eina_strbuf_string_get(str_func));
792
793 eina_strbuf_reset(tmpbuf);
794 if (eina_strbuf_length_get(str_op))
795 {
796 Eina_Strbuf *ops_desc = eina_strbuf_new();
797 _template_fill(ops_desc, tmpl_eo_ops_desc, class, NULL, "", EINA_TRUE);
798 eina_strbuf_replace_all(ops_desc, "@#list_op", eina_strbuf_string_get(str_op));
799 eina_strbuf_replace_all(str_end, "@#ops_desc", eina_strbuf_string_get(ops_desc));
800 eina_strbuf_free(ops_desc);
801 _template_fill(tmpbuf,
802 "EO_CLASS_DESCRIPTION_OPS(_@#class_op_desc)",
803 class, NULL, NULL, EINA_TRUE);
804 }
805 else
806 {
807 eina_strbuf_replace_all(str_end, "@#ops_desc", "");
808 eina_strbuf_append_printf(tmpbuf, "EO_CLASS_DESCRIPTION_NOOPS()");
809 }
810
811 eina_strbuf_replace_all(str_end, "@#functions_body", eina_strbuf_string_get(str_bodyf));
812 eina_strbuf_replace_all(str_end, "@#eo_class_desc_ops", eina_strbuf_string_get(tmpbuf));
813
814 const char *data_type = eolian_class_data_type_get(class);
815 if (data_type && !strcmp(data_type, "null"))
816 eina_strbuf_replace_all(str_end, "@#SizeOfData", "0");
817 else
818 {
819 Eina_Strbuf *sizeofbuf = eina_strbuf_new();
820 eina_strbuf_append_printf(sizeofbuf, "sizeof(%s%s)",
821 data_type?data_type:class_env.full_classname,
822 data_type?"":"_Data");
823 eina_strbuf_replace_all(str_end, "@#SizeOfData", eina_strbuf_string_get(sizeofbuf));
824 eina_strbuf_free(sizeofbuf);
825 }
826 eina_strbuf_append(buf, eina_strbuf_string_get(str_end));
827
828 ret = EINA_TRUE;
829end:
830 eina_strbuf_free(tmpbuf);
831 eina_strbuf_free(str_op);
832 eina_strbuf_free(str_func);
833 eina_strbuf_free(str_bodyf);
834 eina_strbuf_free(str_end);
835 eina_strbuf_free(str_ev);
836
837 return ret;
838}
839
840Eina_Bool
841eo_source_generate(const Eolian_Class class, Eina_Strbuf *buf)
842{
843 Eina_Bool ret = EINA_FALSE;
844 const Eina_List *itr;
845 Eolian_Function fn;
846
847 Eina_Strbuf *str_bodyf = eina_strbuf_new();
848
849 if (!eo_source_beginning_generate(class, buf)) goto end;
850
851 _class_env_create(class, NULL, &class_env);
852
853 //Properties
854 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, EOLIAN_PROPERTY), itr, fn)
855 {
856 const Eolian_Function_Type ftype = eolian_function_type_get(fn);
857
858 Eina_Bool prop_read = ( ftype == EOLIAN_PROP_SET ) ? EINA_FALSE : EINA_TRUE;
859 Eina_Bool prop_write = ( ftype == EOLIAN_PROP_GET ) ? EINA_FALSE : EINA_TRUE;
860
861 if (prop_write)
862 {
863 if (!eo_bind_func_generate(class, fn, EOLIAN_PROP_SET, str_bodyf, NULL)) goto end;
864 }
865 if (prop_read)
866 {
867 if (!eo_bind_func_generate(class, fn, EOLIAN_PROP_GET, str_bodyf, NULL)) goto end;
868 }
869 }
870
871 //Methods
872 EINA_LIST_FOREACH(eolian_class_functions_list_get(class, EOLIAN_METHOD), itr, fn)
873 {
874 if (!eo_bind_func_generate(class, fn, EOLIAN_UNRESOLVED, str_bodyf, NULL)) goto end;
875 }
876
877 eina_strbuf_append(buf, eina_strbuf_string_get(str_bodyf));
878 eina_strbuf_reset(str_bodyf);
879
880 if (!eo_source_end_generate(class, buf)) goto end;
881
882 ret = EINA_TRUE;
883end:
884 eina_strbuf_free(str_bodyf);
885 return ret;
886}
887