summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-09-22 07:43:06 +0300
committerYakov Goldberg <yakov.g@samsung.com>2014-10-01 17:14:47 +0300
commit6796971cd1c372c128c4a59e69167ce53e6154b6 (patch)
treeef9fc602a3aaef464602fff7aeb994ccc5089472
parent15bc4c8cdf60521bf8af5f2e5f9e84dbc1673b1e (diff)
Generator: refactor sequence generation.
Sequences are now generated first. Widgets don't invoke sequence generation anymore.
-rw-r--r--src/lib/generator.c292
1 files changed, 116 insertions, 176 deletions
diff --git a/src/lib/generator.c b/src/lib/generator.c
index f524920..1056988 100644
--- a/src/lib/generator.c
+++ b/src/lib/generator.c
@@ -17,21 +17,24 @@ typedef struct
17 Eina_Strbuf *buf; /* buffer to print data into it */ 17 Eina_Strbuf *buf; /* buffer to print data into it */
18 Eina_List *global_names; /* widget's names, which must be global */ 18 Eina_List *global_names; /* widget's names, which must be global */
19 Eina_List *public_names; /* widget's names, which must be public */ 19 Eina_List *public_names; /* widget's names, which must be public */
20 Eina_Hash *created_sequences_hash; 20 Eina_List *public_main_wdgs;
21 char *formatted_project_name;
21} Global_Gen_Context; 22} Global_Gen_Context;
22 23
23/* Structure to hold data about func being generated. */
24typedef struct 24typedef struct
25{ 25{
26 Global_Gen_Context *gl_ctx; 26 Global_Gen_Context *gl_ctx;
27 Eina_List *declarations; /* List of the variables declared inside the function. */ 27 Eina_Strbuf *buf;
28} Sequence_Context;
28 29
29 /*FIXME: Not used*/ 30/* Structure to hold data about func being generated for a main widget. */
30#if 0 31typedef struct
31 Eina_List *decl; /* List of the functions that have to be declared */ 32{
32#endif 33 Global_Gen_Context *gl_ctx;
33 Eina_Strbuf *buf; /* pointer to the beginning of func context's buffer */ 34 Eina_List *declarations; /* List of the variables declared inside the function. */
34} Function_Context; 35 Eina_Strbuf *buf;
36 Eina_Strbuf *body;
37} Widget_Context;
35 38
36static Eina_Bool 39static Eina_Bool
37_c_generator_generator_interface_source_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf); 40_c_generator_generator_interface_source_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
@@ -42,14 +45,6 @@ _c_generator_generator_interface_resource_generate(const Gui_Resource *res, Eina
42static Eina_Bool 45static Eina_Bool
43_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf); 46_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
44static Eina_Bool 47static Eina_Bool
45_c_generator_generator_interface_sequence_begin_generate(const Gui_Sequence *seq, Eina_Strbuf *buf);
46static Eina_Bool
47_c_generator_generator_interface_sequence_end_generate(const Gui_Sequence *seq EINA_UNUSED, Eina_Strbuf *buf);
48static Eina_Bool
49_c_generator_generator_interface_widget_creation_invoke(const Gui_Widget *wdg, Eina_Strbuf *buf);
50static Eina_Bool
51_c_generator_generator_interface_user_callback_invoke(const Gui_Action *action, Eina_Strbuf *buf);
52static Eina_Bool
53_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf); 48_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf);
54static Eina_Bool 49static Eina_Bool
55_c_generator_generator_interface_widget_property_add(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf); 50_c_generator_generator_interface_widget_property_add(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf);
@@ -60,7 +55,7 @@ _c_generator_generator_interface_widget_item_add(const Gui_Widget *wdg, const It
60static Eina_Bool 55static Eina_Bool
61_c_generator_generator_interface_header_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf); 56_c_generator_generator_interface_header_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
62static Eina_Bool 57static Eina_Bool
63_c_generator_generator_interface_header_sequence_generate(const char *seq_name, Eina_Strbuf *buf); 58_c_generator_generator_interface_header_sequence_generate(const char *seq_name, Global_Gen_Context *gl_ctx);
64static Eina_Bool 59static Eina_Bool
65_c_generator_generator_interface_header_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf); 60_c_generator_generator_interface_header_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
66static Eina_Bool 61static Eina_Bool
@@ -99,9 +94,6 @@ typedef struct
99 const char *cb_name; 94 const char *cb_name;
100} Wdg_Cb_Pair; 95} Wdg_Cb_Pair;
101 96
102static void
103_sequence_generate(Gui_Session *session, Gui_Sequence *seq, Global_Gen_Context *gl_ctx);
104
105/* Check if current string is in list of Variable_Data* */ 97/* Check if current string is in list of Variable_Data* */
106static Eina_Bool 98static Eina_Bool
107_is_in_list(Eina_List *lst, const char *str) 99_is_in_list(Eina_List *lst, const char *str)
@@ -272,24 +264,24 @@ _format_string_add(const Gui_Context *ctx, Gui_Value *gui_value, Eina_Strbuf *p)
272static Eina_Bool 264static Eina_Bool
273_wdg_prop_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data) 265_wdg_prop_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data)
274{ 266{
275 Function_Context *foo_ctx = data; 267 Widget_Context *wdg_ctx = data;
276 return _c_generator_generator_interface_widget_property_add(wdg, prop, foo_ctx->buf); 268 return _c_generator_generator_interface_widget_property_add(wdg, prop, wdg_ctx->body);
277} 269}
278 270
279static Eina_Bool 271static Eina_Bool
280_content_set_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data) 272_content_set_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data)
281{ 273{
282 Function_Context *foo_ctx = data; 274 Widget_Context *wdg_ctx = data;
283 return _c_generator_generator_interface_widget_content_set(wdg, prop, foo_ctx->buf); 275 return _c_generator_generator_interface_widget_content_set(wdg, prop, wdg_ctx->body);
284} 276}
285 277
286/* Recursively iteration function, generate items creation code. */ 278/* Recursively iteration function, generate items creation code. */
287static void 279static void
288_item_iterate(Gui_Session *session, Function_Context *foo_ctx, const Gui_Widget *wdg, const Item_Container_Item *wit) 280_item_iterate(Gui_Session *session, Widget_Context *wdg_ctx, const Gui_Widget *wdg, const Item_Container_Item *wit)
289{ 281{
290 const Gui_Widget_Property *prop = item_container_item_prop_get(wit); 282 const Gui_Widget_Property *prop = item_container_item_prop_get(wit);
291 const Op_Desc *op_desc; 283 const Op_Desc *op_desc;
292 Gui_Value *val; 284 Eina_List *itr;
293 285
294 Eina_Stringshare *class_id = wdg_class_name_get(wdg); 286 Eina_Stringshare *class_id = wdg_class_name_get(wdg);
295 if (!class_id) 287 if (!class_id)
@@ -304,25 +296,6 @@ _item_iterate(Gui_Session *session, Function_Context *foo_ctx, const Gui_Widget
304 return; 296 return;
305 } 297 }
306 298
307 Eina_List *itr, *values_lst = prop_value_get(prop);
308 /* Make some special checks for parameters.
309 * If there is callback, then need to generate sequence.
310 * If item is public, need to declare it's variable and assign as public. */
311 int i = 0;
312 EINA_LIST_FOREACH(values_lst, itr, val)
313 {
314 if (gui_value_type_get(val) == GUI_TYPE_CB)
315 {
316 Dep_Id *dep_id = DEP_ID_GET(val);
317 if (dep_id)
318 {
319 Gui_Sequence *seq = sequence_get(dep_id);
320 if (seq) _sequence_generate(session, seq, foo_ctx->gl_ctx);
321 }
322 }
323 i++;
324 }
325
326 /* Check if item is public or has subitems. 299 /* Check if item is public or has subitems.
327 * If TRUE, variable need to be declared and assigned. */ 300 * If TRUE, variable need to be declared and assigned. */
328 const char *wit_name = NULL; 301 const char *wit_name = NULL;
@@ -331,15 +304,15 @@ _item_iterate(Gui_Session *session, Function_Context *foo_ctx, const Gui_Widget
331 Dep_Id *dep_id = item_container_item_dep_id_get(wit); 304 Dep_Id *dep_id = item_container_item_dep_id_get(wit);
332 wit_name = dep_name_get(dep_id); 305 wit_name = dep_name_get(dep_id);
333 Variable_Data *item_vd = VAR_DATA_NEW(VAR_ITEM, wit_name); 306 Variable_Data *item_vd = VAR_DATA_NEW(VAR_ITEM, wit_name);
334 foo_ctx->declarations = eina_list_append(foo_ctx->declarations, item_vd); 307 wdg_ctx->declarations = eina_list_append(wdg_ctx->declarations, item_vd);
335 } 308 }
336 309
337 _c_generator_generator_interface_widget_item_add(wdg, wit, wit_name, foo_ctx->buf); 310 _c_generator_generator_interface_widget_item_add(wdg, wit, wit_name, wdg_ctx->body);
338 311
339 if (item_container_item_public_get(wit)) 312 if (item_container_item_public_get(wit))
340 { 313 {
341 Variable_Data *item_vd = VAR_DATA_NEW(VAR_ITEM, wit_name); 314 Variable_Data *item_vd = VAR_DATA_NEW(VAR_ITEM, wit_name);
342 foo_ctx->gl_ctx->public_names = eina_list_append(foo_ctx->gl_ctx->public_names, item_vd); 315 wdg_ctx->gl_ctx->public_names = eina_list_append(wdg_ctx->gl_ctx->public_names, item_vd);
343 } 316 }
344 317
345 Dep_Id *dep_id_itr; 318 Dep_Id *dep_id_itr;
@@ -347,16 +320,16 @@ _item_iterate(Gui_Session *session, Function_Context *foo_ctx, const Gui_Widget
347 { 320 {
348 Dep_Data *dep_data = gui_context_dep_data_get(dep_id_itr); 321 Dep_Data *dep_data = gui_context_dep_data_get(dep_id_itr);
349 Item_Container_Item *witr = dep_data_item_get(dep_data); 322 Item_Container_Item *witr = dep_data_item_get(dep_data);
350 _item_iterate(session, foo_ctx, wdg, witr); 323 _item_iterate(session, wdg_ctx, wdg, witr);
351 } 324 }
352} 325}
353 326
354static Eina_Bool 327static Eina_Bool
355_item_add_generate(Gui_Session *session, const Gui_Widget *wdg, const Item_Container_Item *wit, void *data EINA_UNUSED) 328_item_add_generate(Gui_Session *session, const Gui_Widget *wdg, const Item_Container_Item *wit, void *data EINA_UNUSED)
356{ 329{
357 Function_Context *foo_ctx = data; 330 Widget_Context *wdg_ctx = data;
358 331
359 _item_iterate(session, foo_ctx, wdg, wit); 332 _item_iterate(session, wdg_ctx, wdg, wit);
360 333
361 /*FIXME: this is probaaly not needed as items are created consequently. */ 334 /*FIXME: this is probaaly not needed as items are created consequently. */
362#if 0 335#if 0
@@ -366,21 +339,6 @@ _item_add_generate(Gui_Session *session, const Gui_Widget *wdg, const Item_Conta
366 return EINA_TRUE; 339 return EINA_TRUE;
367} 340}
368 341
369/* Delete context */
370static void
371_function_ctx_free(Function_Context *foo_ctx)
372{
373 Variable_Data *vd;
374 EINA_LIST_FREE(foo_ctx->declarations, vd)
375 {
376 free(vd->var_name);
377 free(vd);
378 }
379
380 eina_strbuf_free(foo_ctx->buf);
381 free(foo_ctx);
382}
383
384/* Generate eo_add string for current widget. */ 342/* Generate eo_add string for current widget. */
385static Eina_Bool 343static Eina_Bool
386_wdg_add_generate(Gui_Session *session, const Gui_Widget *wdg, void *data) 344_wdg_add_generate(Gui_Session *session, const Gui_Widget *wdg, void *data)
@@ -391,15 +349,15 @@ _wdg_add_generate(Gui_Session *session, const Gui_Widget *wdg, void *data)
391 goto bad_end; 349 goto bad_end;
392 } 350 }
393 351
394 Function_Context *foo_ctx = data; 352 Widget_Context *wdg_ctx = data;
395 353
396 if (_c_generator_generator_interface_widget_create(wdg, foo_ctx->buf)) 354 if (_c_generator_generator_interface_widget_create(wdg, wdg_ctx->body))
397 { 355 {
398 session_wdg_existence_set(session, wdg, EINA_TRUE); 356 session_wdg_existence_set(session, wdg, EINA_TRUE);
399 if (wdg_public_get(wdg)) 357 if (wdg_public_get(wdg))
400 { 358 {
401 Variable_Data *vd = VAR_DATA_NEW(VAR_EO, wdg_name_get(wdg)); 359 Variable_Data *vd = VAR_DATA_NEW(VAR_EO, wdg_name_get(wdg));
402 foo_ctx->gl_ctx->public_names = eina_list_append(foo_ctx->gl_ctx->public_names, vd); 360 wdg_ctx->gl_ctx->public_names = eina_list_append(wdg_ctx->gl_ctx->public_names, vd);
403 } 361 }
404 } 362 }
405 363
@@ -410,53 +368,51 @@ bad_end:
410 368
411/* Recursively generate context for widget and its children. */ 369/* Recursively generate context for widget and its children. */
412static void 370static void
413_iter_widget(Gui_Session *session, Global_Gen_Context *gl_ctx, Function_Context *foo_ctx, Gui_Widget *wdg) 371_iter_widget(Gui_Session *session, Global_Gen_Context *gl_ctx, Widget_Context *wdg_ctx, Gui_Widget *wdg)
414{ 372{
415 if (session_wdg_exists(session, wdg)) return; 373 if (session_wdg_exists(session, wdg)) return;
416 /* Add widget's name into the list of valiable declarations. */ 374 /* Add widget's name into the list of valiable declarations. */
417 Variable_Data *vd = VAR_DATA_NEW(VAR_EO, wdg_name_get(wdg)); 375 Variable_Data *vd = VAR_DATA_NEW(VAR_EO, wdg_name_get(wdg));
418 foo_ctx->declarations = eina_list_append(foo_ctx->declarations, vd); 376 wdg_ctx->declarations = eina_list_append(wdg_ctx->declarations, vd);
419 377
420 if (manager_widget_create(session, wdg, MODE_GENERATOR, foo_ctx)) 378 if (manager_widget_create(session, wdg, MODE_GENERATOR, wdg_ctx))
421 { 379 {
422 Eina_List *itr; 380 Eina_List *itr;
423 Dep_Id *wid; 381 Dep_Id *wid;
424 382
425 manager_widget_configure(session, wdg, MODE_GENERATOR, foo_ctx); 383 manager_widget_configure(session, wdg, MODE_GENERATOR, wdg_ctx);
426 EINA_LIST_FOREACH(wdg_children_list_get(wdg), itr, wid) 384 EINA_LIST_FOREACH(wdg_children_list_get(wdg), itr, wid)
427 { 385 {
428 Gui_Widget *w = wdg_get(wid); 386 Gui_Widget *w = wdg_get(wid);
429 if (w) _iter_widget(session, gl_ctx, foo_ctx, w); 387 if (w) _iter_widget(session, gl_ctx, wdg_ctx, w);
430 } 388 }
431 /* If the widget is a win, we have to apply its visibility property. */ 389 /* If the widget is a win, we have to apply its visibility property. */
432 if (IS_WIN(wdg)) 390 if (IS_WIN(wdg))
433 { 391 {
434 Gui_Widget_Property *prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, VISIBILITY_SET); 392 Gui_Widget_Property *prop = wdg_prop_get(wdg, DB_DEF_EVAS_OBJECT_CLASS, VISIBILITY_SET);
435 _wdg_prop_add_generate(session, wdg, prop, foo_ctx); 393 _wdg_prop_add_generate(session, wdg, prop, wdg_ctx);
436 } 394 }
437 } 395 }
438} 396}
439 397
440/* Generate a creation function for a widget. */ 398/* Generate a creation function for a widget. */
441static void 399static void
442_wdg_creation_function_generate(Gui_Session *session, Gui_Widget *wdg, Global_Gen_Context *gl_ctx) 400_wdg_creation_function_generate(Gui_Session *session, Gui_Widget *wdg, Widget_Context *wdg_ctx)
443{ 401{
444 Eina_List *itr; 402 Global_Gen_Context *gl_ctx = wdg_ctx->gl_ctx;
445
446 const char *wdg_name = wdg_name_get(wdg); 403 const char *wdg_name = wdg_name_get(wdg);
447 if (session_wdg_exists(session, wdg)) return; 404 if (session_wdg_exists(session, wdg)) return;
448 405
449 Function_Context *foo_ctx = calloc(1, sizeof(*foo_ctx)); 406 gl_ctx->public_main_wdgs = eina_list_append(gl_ctx->public_main_wdgs, wdg_name);
450 foo_ctx->buf = eina_strbuf_new();
451 foo_ctx->gl_ctx = gl_ctx;
452 407
453 _iter_widget(session, gl_ctx, foo_ctx, wdg); 408 wdg_ctx->body = eina_strbuf_new();
409 _iter_widget(session, gl_ctx, wdg_ctx, wdg);
454 410
455 eina_strbuf_append_printf(gl_ctx->buf, "static void\n_create_%s()\n{\n", wdg_name); 411 eina_strbuf_append_printf(wdg_ctx->buf, "void\n%s_create()\n{\n", wdg_name);
456 412
457 /* Add definitions of variables */ 413 /* Add definitions of variables */
458 Variable_Data *vd; 414 Variable_Data *vd;
459 EINA_LIST_FOREACH(foo_ctx->declarations, itr, vd) 415 EINA_LIST_FREE(wdg_ctx->declarations, vd)
460 { 416 {
461 if (vd->var_type == VAR_EO) 417 if (vd->var_type == VAR_EO)
462 { 418 {
@@ -464,52 +420,42 @@ _wdg_creation_function_generate(Gui_Session *session, Gui_Widget *wdg, Global_Ge
464 { 420 {
465 continue; 421 continue;
466 } 422 }
467 eina_strbuf_append_printf(gl_ctx->buf, " Eo *%s;\n", vd->var_name); 423 eina_strbuf_append_printf(wdg_ctx->buf, " Eo *%s;\n", vd->var_name);
424 free(vd->var_name);
425 free(vd);
468 } 426 }
469 else if (vd->var_type == VAR_ITEM) 427 else if (vd->var_type == VAR_ITEM)
470 { 428 {
471 eina_strbuf_append_printf(gl_ctx->buf, " Elm_Object_Item *%s;\n", vd->var_name); 429 eina_strbuf_append_printf(wdg_ctx->buf, " Elm_Object_Item *%s;\n", vd->var_name);
430 free(vd->var_name);
431 free(vd);
472 } 432 }
473 } 433 }
474 434 eina_strbuf_append_printf(wdg_ctx->buf, "\n%s", eina_strbuf_string_get(wdg_ctx->body));
475 eina_strbuf_append_printf(gl_ctx->buf, "\n%s", eina_strbuf_string_get(foo_ctx->buf)); 435 eina_strbuf_free(wdg_ctx->body);
476 eina_strbuf_append_printf(gl_ctx->buf, "}\n\n"); 436 eina_strbuf_append_printf(wdg_ctx->buf, "}\n\n");
477
478 _function_ctx_free(foo_ctx);
479} 437}
480 438
481static void 439static void
482_sequence_generate(Gui_Session *session, Gui_Sequence *seq, Global_Gen_Context *gl_ctx) 440_sequence_generate(Gui_Session *session, Gui_Sequence *seq, Sequence_Context *seq_ctx)
483{ 441{
484 Eina_List *itr; 442 Eina_List *itr;
485 Gui_Action *action; 443 Gui_Action *action;
444 Global_Gen_Context *gl_ctx = seq_ctx->gl_ctx;
486 const Gui_Context *ctx = gl_ctx->ctx; 445 const Gui_Context *ctx = gl_ctx->ctx;
487 446
488 const char *seq_name = sequence_name_get(seq); 447 const char *seq_name = sequence_name_get(seq);
489 printf("Generate %s\n", seq_name); 448 printf("Generate %s\n", seq_name);
490 if (eina_hash_find(gl_ctx->created_sequences_hash, seq_name))
491 {
492 printf(" ...already generated\n");
493 return;
494 }
495 eina_hash_set(gl_ctx->created_sequences_hash, seq_name, &seq_name); // data is not important
496 449
497 Function_Context *foo_ctx = calloc(1, sizeof(*foo_ctx)); 450 eina_strbuf_append_printf(seq_ctx->buf,
498 foo_ctx->buf = eina_strbuf_new(); 451 "%sEina_Bool\n%s_%s(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)\n{\n",
499 foo_ctx->gl_ctx = gl_ctx; 452 sequence_public_get(seq) ? "" : "static ", seq_ctx->gl_ctx->formatted_project_name, seq_name);
500
501 _c_generator_generator_interface_sequence_begin_generate(seq, foo_ctx->buf);
502 453
503 /* if sequence is public, need to declare it in header. */ 454 /* if sequence is public, need to declare it in header. */
504 if (sequence_public_get(seq)) 455 if (sequence_public_get(seq))
505 { 456 {
506 char _buf[1000] = {'\0'}; 457 Variable_Data *item_vd = VAR_DATA_NEW(VAR_SEQUENCE, seq_name);
507 char *formatted_project_name = _project_name_format((char *) gui_context_project_name_get(ctx)); 458 seq_ctx->gl_ctx->public_names = eina_list_append(seq_ctx->gl_ctx->public_names, item_vd);
508 sprintf(_buf, "%s_%s", formatted_project_name, sequence_name_get(seq));
509
510 Variable_Data *item_vd = VAR_DATA_NEW(VAR_SEQUENCE, _buf);
511 foo_ctx->gl_ctx->public_names = eina_list_append(foo_ctx->gl_ctx->public_names, item_vd);
512 free(formatted_project_name);
513 } 459 }
514 EINA_LIST_FOREACH(sequence_actions_list_get(seq), itr, action) 460 EINA_LIST_FOREACH(sequence_actions_list_get(seq), itr, action)
515 { 461 {
@@ -524,14 +470,7 @@ _sequence_generate(Gui_Session *session, Gui_Sequence *seq, Global_Gen_Context *
524 ERR("Failed to find \"%p\" widget.", wdg_id); 470 ERR("Failed to find \"%p\" widget.", wdg_id);
525 continue; 471 continue;
526 } 472 }
527 const char *par = wdg_parent_name_get(w); 473 eina_strbuf_append_printf(seq_ctx->buf, " %s_create();\n\n", wdg_name_get(w));
528 if (par && (!_is_in_list(gl_ctx->global_names, par)))
529 {
530 Variable_Data *vd = VAR_DATA_NEW(VAR_EO, par);
531 gl_ctx->global_names = eina_list_append(gl_ctx->global_names, vd);
532 }
533 _wdg_creation_function_generate(session, w, gl_ctx);
534 _c_generator_generator_interface_widget_creation_invoke(w, foo_ctx->buf);
535 break; 474 break;
536 } 475 }
537 case MODIF_ACTION: 476 case MODIF_ACTION:
@@ -567,12 +506,20 @@ _sequence_generate(Gui_Session *session, Gui_Sequence *seq, Global_Gen_Context *
567 Variable_Data *vd = VAR_DATA_NEW(VAR_EO, wdg_name); 506 Variable_Data *vd = VAR_DATA_NEW(VAR_EO, wdg_name);
568 gl_ctx->global_names = eina_list_append(gl_ctx->global_names, vd); 507 gl_ctx->global_names = eina_list_append(gl_ctx->global_names, vd);
569 } 508 }
570 manager_widget_property_add(session, wdg, prop, MODE_GENERATOR, foo_ctx); 509 Widget_Context wdg_ctx;
510 wdg_ctx.body = eina_strbuf_new();
511 manager_widget_property_add(session, wdg, prop, MODE_GENERATOR, &wdg_ctx);
512 eina_strbuf_append_printf(seq_ctx->buf, "%s", eina_strbuf_string_get(wdg_ctx.body));
513 eina_strbuf_free(wdg_ctx.body);
571 break; 514 break;
572 } 515 }
573 case USER_ACTION: 516 case USER_ACTION:
574 { 517 {
575 _c_generator_generator_interface_user_callback_invoke(action, foo_ctx->buf); 518 Dep_Id *dep_id = action_dep_id_get(action);
519 const Gui_Resource *res = gui_context_resource_get(dep_id);
520 const char *user_func = resource_value_get(res);
521 //const char *user_data = action_user_data_get(action);
522 eina_strbuf_append_printf(seq_ctx->buf, " if (!%s(%s, obj, desc, event_info)) return EO_CALLBACK_STOP;\n", user_func, "NULL");
576 break; 523 break;
577 } 524 }
578 case NO_ACTION: 525 case NO_ACTION:
@@ -581,18 +528,14 @@ _sequence_generate(Gui_Session *session, Gui_Sequence *seq, Global_Gen_Context *
581 printf("ZZZ - Fix here %s-%d\n", __FUNCTION__, __LINE__); 528 printf("ZZZ - Fix here %s-%d\n", __FUNCTION__, __LINE__);
582 } 529 }
583 } 530 }
584 _c_generator_generator_interface_sequence_end_generate(seq, foo_ctx->buf); 531 eina_strbuf_append_printf(seq_ctx->buf, " return EO_CALLBACK_CONTINUE;\n}\n\n");
585
586 eina_strbuf_append_printf(gl_ctx->buf, "\n%s", eina_strbuf_string_get(foo_ctx->buf));
587
588 _function_ctx_free(foo_ctx);
589} 532}
590 533
591/* Generate string for given callback. */ 534/* Generate string for given callback. */
592static Eina_Bool 535static Eina_Bool
593_wdg_cb_add_generate(Gui_Session *session, const Gui_Widget *wdg, const Gui_Widget_Callback *cb, void *data) 536_wdg_cb_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Callback *cb, void *data)
594{ 537{
595 Function_Context *foo_ctx = data; 538 Widget_Context *wdg_ctx = data;
596 Eina_Bool ret = EINA_TRUE; 539 Eina_Bool ret = EINA_TRUE;
597 const char *cb_name = NULL; 540 const char *cb_name = NULL;
598 const Gui_Context *ctx = wdg_context_get(wdg); 541 const Gui_Context *ctx = wdg_context_get(wdg);
@@ -610,7 +553,6 @@ _wdg_cb_add_generate(Gui_Session *session, const Gui_Widget *wdg, const Gui_Widg
610 if (seq) 553 if (seq)
611 { 554 {
612 char _buf[1000] = {'\0'}; 555 char _buf[1000] = {'\0'};
613 _sequence_generate(session, seq, foo_ctx->gl_ctx);
614 char *formatted = (char *) _project_name_format((char *) gui_context_project_name_get(ctx)); 556 char *formatted = (char *) _project_name_format((char *) gui_context_project_name_get(ctx));
615 sprintf(_buf, "%s_%s", formatted, sequence_name_get(seq)); 557 sprintf(_buf, "%s_%s", formatted, sequence_name_get(seq));
616 free(formatted); 558 free(formatted);
@@ -625,7 +567,7 @@ _wdg_cb_add_generate(Gui_Session *session, const Gui_Widget *wdg, const Gui_Widg
625 char *event_name = _c_plugin_eo_event_name_get(wdg_class_name_get(wdg), cb_type); 567 char *event_name = _c_plugin_eo_event_name_get(wdg_class_name_get(wdg), cb_type);
626 if (event_name) 568 if (event_name)
627 { 569 {
628 eina_strbuf_append_printf(foo_ctx->buf, " eo_do(%s, eo_event_callback_add(%s, %s, NULL));\n", 570 eina_strbuf_append_printf(wdg_ctx->body, " eo_do(%s, eo_event_callback_add(%s, %s, NULL));\n",
629 wdg_name_get(wdg), event_name, 571 wdg_name_get(wdg), event_name,
630 cb_name); 572 cb_name);
631 free(event_name); 573 free(event_name);
@@ -668,10 +610,11 @@ _ctx_to_file_save(const Gui_Context *ctx)
668 /* Define global generator context */ 610 /* Define global generator context */
669 Global_Gen_Context gl_gen_ctx; 611 Global_Gen_Context gl_gen_ctx;
670 gl_gen_ctx.ctx = ctx; 612 gl_gen_ctx.ctx = ctx;
671 gl_gen_ctx.created_sequences_hash = eina_hash_string_superfast_new(NULL);
672 gl_gen_ctx.buf = eina_strbuf_new(); 613 gl_gen_ctx.buf = eina_strbuf_new();
673 gl_gen_ctx.global_names = NULL; 614 gl_gen_ctx.global_names = NULL;
674 gl_gen_ctx.public_names = NULL; 615 gl_gen_ctx.public_names = NULL;
616 gl_gen_ctx.public_main_wdgs = NULL;
617 gl_gen_ctx.formatted_project_name = _project_name_format((char *) gui_context_project_name_get(ctx));
675 618
676 _c_generator_generator_interface_source_preamble_generate(ctx, gl_gen_ctx.buf); 619 _c_generator_generator_interface_source_preamble_generate(ctx, gl_gen_ctx.buf);
677 eina_strbuf_append_printf(gl_gen_ctx.buf, "__GLOBAL_NAMES__"); 620 eina_strbuf_append_printf(gl_gen_ctx.buf, "__GLOBAL_NAMES__");
@@ -729,7 +672,36 @@ _ctx_to_file_save(const Gui_Context *ctx)
729 EINA_LIST_FOREACH(seqs_list, itr, seq_id) 672 EINA_LIST_FOREACH(seqs_list, itr, seq_id)
730 { 673 {
731 Gui_Sequence *seq = sequence_get(seq_id); 674 Gui_Sequence *seq = sequence_get(seq_id);
732 if (seq) _sequence_generate(session, seq, &gl_gen_ctx); 675 if (seq)
676 {
677 Sequence_Context seq_ctx;
678 seq_ctx.gl_ctx = &gl_gen_ctx;
679 seq_ctx.buf = eina_strbuf_new();
680 _sequence_generate(session, seq, &seq_ctx);
681 eina_strbuf_append_printf(gl_gen_ctx.buf, "%s", eina_strbuf_string_get(seq_ctx.buf));
682 eina_strbuf_free(seq_ctx.buf);
683 }
684 }
685
686 Eina_List* wdgs_list = gui_context_wdg_list_get(ctx);
687 Dep_Id *wdg_id;
688 EINA_LIST_FOREACH(wdgs_list, itr, wdg_id)
689 {
690 Gui_Widget *wdg = wdg_get(wdg_id);
691 if (wdg)
692 {
693 if (!session_wdg_exists(session, wdg))
694 {
695 Widget_Context wdg_ctx;
696 wdg_ctx.gl_ctx = &gl_gen_ctx;
697 wdg_ctx.buf = eina_strbuf_new();
698 wdg_ctx.declarations = NULL;
699 printf("Generate %s\n", wdg_name_get(wdg));
700 _wdg_creation_function_generate(session, wdg, &wdg_ctx);
701 eina_strbuf_append_printf(gl_gen_ctx.buf, "%s", eina_strbuf_string_get(wdg_ctx.buf));
702 eina_strbuf_free(wdg_ctx.buf);
703 }
704 }
733 } 705 }
734 706
735 Eina_Strbuf *global_names_buf = eina_strbuf_new(); 707 Eina_Strbuf *global_names_buf = eina_strbuf_new();
@@ -751,9 +723,16 @@ _ctx_to_file_save(const Gui_Context *ctx)
751 { 723 {
752 if (vd->var_type == VAR_SEQUENCE) 724 if (vd->var_type == VAR_SEQUENCE)
753 { 725 {
754 _c_generator_generator_interface_header_sequence_generate(vd->var_name, gl_gen_ctx.buf); 726 _c_generator_generator_interface_header_sequence_generate(vd->var_name, &gl_gen_ctx);
755 } 727 }
756 } 728 }
729
730 const char *wdg_name;
731 EINA_LIST_FREE(gl_gen_ctx.public_main_wdgs, wdg_name)
732 {
733 eina_strbuf_append_printf(gl_gen_ctx.buf, "void\n%s_create();\n\n", wdg_name);
734 }
735
757 _c_generator_generator_interface_header_main_function_generate(ctx, gl_gen_ctx.buf); 736 _c_generator_generator_interface_header_main_function_generate(ctx, gl_gen_ctx.buf);
758 _c_generator_generator_interface_header_postscript_generate(ctx, gl_gen_ctx.buf); 737 _c_generator_generator_interface_header_postscript_generate(ctx, gl_gen_ctx.buf);
759 fprintf(fp_h, "%s", eina_strbuf_string_get(gl_gen_ctx.buf)); 738 fprintf(fp_h, "%s", eina_strbuf_string_get(gl_gen_ctx.buf));
@@ -769,7 +748,7 @@ _ctx_to_file_save(const Gui_Context *ctx)
769 free(vd->var_name); 748 free(vd->var_name);
770 free(vd); 749 free(vd);
771 } 750 }
772 eina_hash_free(gl_gen_ctx.created_sequences_hash); 751 free(gl_gen_ctx.formatted_project_name);
773 752
774 session_del(session); 753 session_del(session);
775 754
@@ -879,45 +858,6 @@ _c_generator_generator_interface_main_function_generate(const Gui_Context *ctx,
879} 858}
880 859
881static Eina_Bool 860static Eina_Bool
882_c_generator_generator_interface_sequence_begin_generate(const Gui_Sequence *seq, Eina_Strbuf *buf)
883{
884 const Gui_Context *ctx = sequence_ctx_get(seq);
885 const char *sequence_name = sequence_name_get(seq);
886 char *formatted_project_name = _project_name_format((char *) gui_context_project_name_get(ctx));
887 eina_strbuf_append_printf(buf,
888 "%sEina_Bool\n%s_%s(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)\n{\n",
889 sequence_public_get(seq) ? "" : "static ", formatted_project_name, sequence_name);
890 free(formatted_project_name);
891 return EINA_TRUE;
892}
893
894static Eina_Bool
895_c_generator_generator_interface_sequence_end_generate(const Gui_Sequence *seq EINA_UNUSED, Eina_Strbuf *buf)
896{
897 eina_strbuf_append_printf(buf, " return EO_CALLBACK_CONTINUE;\n}\n\n");
898 return EINA_TRUE;
899}
900
901static Eina_Bool
902_c_generator_generator_interface_widget_creation_invoke(const Gui_Widget *wdg, Eina_Strbuf *buf)
903{
904 eina_strbuf_append_printf(buf, " _create_%s();\n\n", wdg_name_get(wdg));
905 return EINA_TRUE;
906}
907
908static Eina_Bool
909_c_generator_generator_interface_user_callback_invoke(const Gui_Action *action, Eina_Strbuf *buf)
910{
911 Dep_Id *dep_id = action_dep_id_get(action);
912 const Gui_Resource *res = gui_context_resource_get(dep_id);
913 const char *user_func = resource_value_get(res);
914 //const char *user_data = action_user_data_get(action);
915 if (!res) return EINA_FALSE;
916 eina_strbuf_append_printf(buf, " if (!%s(%s, obj, desc, event_info)) return EO_CALLBACK_STOP;\n", user_func, "NULL");
917 return EINA_TRUE;
918}
919
920static Eina_Bool
921_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf) 861_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf)
922{ 862{
923 const char *parent_id = wdg_parent_name_get(wdg); 863 const char *parent_id = wdg_parent_name_get(wdg);
@@ -1100,11 +1040,11 @@ _c_generator_generator_interface_header_main_function_generate(const Gui_Context
1100} 1040}
1101 1041
1102static Eina_Bool 1042static Eina_Bool
1103_c_generator_generator_interface_header_sequence_generate(const char *seq_name, Eina_Strbuf *buf) 1043_c_generator_generator_interface_header_sequence_generate(const char *seq_name, Global_Gen_Context *gl_ctx)
1104{ 1044{
1105 /* Add get_gui function . */ 1045 /* Add get_gui function . */
1106 eina_strbuf_append_printf(buf, "Eina_Bool\n%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n\n", 1046 eina_strbuf_append_printf(gl_ctx->buf, "Eina_Bool\n%s_%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n\n",
1107 seq_name); 1047 gl_ctx->formatted_project_name, seq_name);
1108 return EINA_TRUE; 1048 return EINA_TRUE;
1109} 1049}
1110 1050