summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-09-23 11:28:47 +0300
committerYakov Goldberg <yakov.g@samsung.com>2014-10-02 10:17:20 +0300
commit1cccd3dd9a461178a533f48bc79d3d4a3025781a (patch)
treeb7dc2d0b2e6dd6a3f3a27f4bacd7f0b20cdccf7c
parent5a9f2848e3e7cd9297759918fb74002a3e816d9c (diff)
Generator: move code moving
-rw-r--r--src/lib/generator.c456
1 files changed, 194 insertions, 262 deletions
diff --git a/src/lib/generator.c b/src/lib/generator.c
index 2d474ad..29e6084 100644
--- a/src/lib/generator.c
+++ b/src/lib/generator.c
@@ -35,20 +35,8 @@ typedef struct
35 Global_Gen_Context *gl_ctx; 35 Global_Gen_Context *gl_ctx;
36 Eina_List *declarations; /* List of the variables declared inside the function. */ 36 Eina_List *declarations; /* List of the variables declared inside the function. */
37 Eina_Strbuf *buf; 37 Eina_Strbuf *buf;
38 Eina_Strbuf *body;
39} Widget_Context; 38} Widget_Context;
40 39
41static Eina_Bool
42_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf);
43static Eina_Bool
44_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf);
45static Eina_Bool
46_c_generator_generator_interface_widget_property_add(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf);
47static Eina_Bool
48_c_generator_generator_interface_widget_content_set(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf);
49static Eina_Bool
50_c_generator_generator_interface_widget_item_add(const Gui_Widget *wdg, const Item_Container_Item *item, const char *item_name, Eina_Strbuf *buf);
51
52/* Check if current dep_id is in list of Dep_Ids */ 40/* Check if current dep_id is in list of Dep_Ids */
53static Eina_Bool 41static Eina_Bool
54_is_in_list(Eina_List *lst, Dep_Id *dep_id) 42_is_in_list(Eina_List *lst, Dep_Id *dep_id)
@@ -216,14 +204,80 @@ static Eina_Bool
216_wdg_prop_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data) 204_wdg_prop_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data)
217{ 205{
218 Widget_Context *wdg_ctx = data; 206 Widget_Context *wdg_ctx = data;
219 return _c_generator_generator_interface_widget_property_add(wdg, prop, wdg_ctx->body); 207
208 const Op_Desc *op_desc;
209 Gui_Value *gui_value;
210 Eina_List *itr;
211
212 Eina_List *values_lst = prop_value_get(prop);
213
214 Eina_Stringshare *class_id = wdg_class_name_get(wdg);
215 if (!class_id)
216 {
217 ERR("Property \"class\" is missing in widget: \"%s\"\n", wdg_name_get(wdg));
218 return EINA_FALSE;
219 }
220 op_desc = prop_op_desc_get(prop);
221 if (!op_desc)
222 {
223 ERR("Op Desc for property: \"%s\", in widget: \"%s\" was not found in hash table.\n", prop_name_get(prop), wdg_name_get(wdg));
224 return EINA_FALSE;
225 }
226
227 if (wdg_data_get(wdg, CONSTRUCTOR) && (!(strcmp(prop_name_get(prop), wdg_data_get(wdg, CONSTRUCTOR)))))
228 {
229 return EINA_FALSE;
230 }
231
232 eina_strbuf_append_printf(wdg_ctx->buf, " eo_do(%s, %s(", wdg_name_get(wdg),
233 db_op_desc_func_name_get(op_desc));
234
235 EINA_LIST_FOREACH(values_lst, itr, gui_value)
236 {
237 if (values_lst != itr)
238 eina_strbuf_append_printf(wdg_ctx->buf, ", ");
239 _format_string_add(wdg_context_get(wdg), gui_value, wdg_ctx->buf);
240 }
241 eina_strbuf_append_printf(wdg_ctx->buf, "));\n");
242
243 return EINA_TRUE;
220} 244}
221 245
222static Eina_Bool 246static Eina_Bool
223_content_set_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data) 247_content_set_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, const Gui_Widget_Property *prop, void *data)
224{ 248{
225 Widget_Context *wdg_ctx = data; 249 Widget_Context *wdg_ctx = data;
226 return _c_generator_generator_interface_widget_content_set(wdg, prop, wdg_ctx->body); 250 const Op_Desc *op_desc;
251 Gui_Value *gui_value;
252 Eina_List *itr;
253
254 Eina_Stringshare *class_id = wdg_class_name_get(wdg);
255 if (!class_id)
256 {
257 ERR("Property \"class\" is missing in widget: \"%s\"\n", wdg_name_get(wdg));
258 return EINA_FALSE;
259 }
260 op_desc = prop_op_desc_get(prop);
261 if (!op_desc)
262 {
263 ERR("Op Desc for property: \"%s\" was not found in hash table.", prop_name_get(prop));
264 return EINA_FALSE;
265 }
266
267 Eina_List *values_lst = prop_value_get(prop);
268
269 eina_strbuf_append_printf(wdg_ctx->buf, " eo_do(%s, %s(", wdg_name_get(wdg),
270 db_op_desc_func_name_get(op_desc));
271
272 EINA_LIST_FOREACH(values_lst, itr, gui_value)
273 {
274 if (values_lst != itr)
275 eina_strbuf_append_printf(wdg_ctx->buf, ", ");
276 _format_string_add(wdg_context_get(wdg), gui_value, wdg_ctx->buf);
277 }
278 eina_strbuf_append_printf(wdg_ctx->buf, "));\n");
279
280 return EINA_TRUE;
227} 281}
228 282
229/* Recursively iteration function, generate items creation code. */ 283/* Recursively iteration function, generate items creation code. */
@@ -231,9 +285,10 @@ static void
231_item_iterate(Gui_Session *session, Widget_Context *wdg_ctx, const Gui_Widget *wdg, const Item_Container_Item *wit) 285_item_iterate(Gui_Session *session, Widget_Context *wdg_ctx, const Gui_Widget *wdg, const Item_Container_Item *wit)
232{ 286{
233 const Gui_Widget_Property *prop = item_container_item_prop_get(wit); 287 const Gui_Widget_Property *prop = item_container_item_prop_get(wit);
288 Dep_Id *wit_id = item_container_item_dep_id_get(wit);
289 const char *item_name = dep_name_get(wit_id);
234 const Op_Desc *op_desc; 290 const Op_Desc *op_desc;
235 Eina_List *itr; 291 Eina_List *itr;
236 Dep_Id *wit_id = item_container_item_dep_id_get(wit);
237 292
238 Eina_Stringshare *class_id = wdg_class_name_get(wdg); 293 Eina_Stringshare *class_id = wdg_class_name_get(wdg);
239 if (!class_id) 294 if (!class_id)
@@ -255,10 +310,23 @@ _item_iterate(Gui_Session *session, Widget_Context *wdg_ctx, const Gui_Widget *w
255 wdg_ctx->declarations = eina_list_append(wdg_ctx->declarations, wit_id); 310 wdg_ctx->declarations = eina_list_append(wdg_ctx->declarations, wit_id);
256 } 311 }
257 312
258 _c_generator_generator_interface_widget_item_add(wdg, wit, dep_name_get(wit_id), wdg_ctx->body); 313 eina_strbuf_append_printf(wdg_ctx->buf, " eo_do(%s, %s%s%s(", wdg_name_get(wdg),
314 item_name ? item_name : "", item_name ? " = " : "",
315 db_op_desc_func_name_get(op_desc));
316
317 Eina_List *values_lst = prop_value_get(prop);
318 Gui_Value *val;
319 EINA_LIST_FOREACH(values_lst, itr, val)
320 {
321 if (values_lst != itr)
322 eina_strbuf_append_printf(wdg_ctx->buf, ", ");
323 _format_string_add(wdg_context_get(wdg), val, wdg_ctx->buf);
324 }
325 eina_strbuf_append_printf(wdg_ctx->buf, "));\n");
259 326
260 if (item_container_item_public_get(wit)) 327 if (item_container_item_public_get(wit))
261 { 328 {
329 eina_strbuf_append_printf(wdg_ctx->buf, " %s.%s = %s;\n", PUB_WIDGETS, item_name, item_name);
262 wdg_ctx->gl_ctx->public_entities = eina_list_append(wdg_ctx->gl_ctx->public_entities, wit_id); 330 wdg_ctx->gl_ctx->public_entities = eina_list_append(wdg_ctx->gl_ctx->public_entities, wit_id);
263 } 331 }
264 332
@@ -290,26 +358,71 @@ _item_add_generate(Gui_Session *session, const Gui_Widget *wdg, const Item_Conta
290static Eina_Bool 358static Eina_Bool
291_wdg_add_generate(Gui_Session *session, const Gui_Widget *wdg, void *data) 359_wdg_add_generate(Gui_Session *session, const Gui_Widget *wdg, void *data)
292{ 360{
361 Widget_Context *wdg_ctx = data;
362
293 if (!wdg) 363 if (!wdg)
294 { 364 {
295 WRN("Wdg is NULL"); 365 WRN("Wdg is NULL");
296 goto bad_end; 366 return EINA_FALSE;
297 } 367 }
298 368
299 Widget_Context *wdg_ctx = data; 369 const char *parent_id = wdg_parent_name_get(wdg);
370 Eina_Stringshare *class_id;
371
372 if (!parent_id) parent_id = "NULL";
300 373
301 if (_c_generator_generator_interface_widget_create(wdg, wdg_ctx->body)) 374 class_id = wdg_class_name_get(wdg);
375 if (!class_id)
302 { 376 {
303 session_wdg_existence_set(session, wdg, EINA_TRUE); 377 ERR("Property \"class\" is missing in widget: \"%s\"\n", wdg_name_get(wdg));
304 if (wdg_public_get(wdg)) 378 return EINA_FALSE;
379 }
380
381 /* if there is no property "constructor", it means - using eo constr */
382 if (!wdg_data_get(wdg, CONSTRUCTOR))
383 {
384 eina_strbuf_append_printf(wdg_ctx->buf, " %s = eo_add(%s, %s);\n",
385 wdg_name_get(wdg), db_class_macro_get(class_id),
386 parent_id);
387 }
388 else
389 {
390 /* Looking for op_id of current constructor*/
391 Op_Desc *op_desc = NULL;
392 Gui_Value *gui_value = NULL;
393 Eina_List *values_lst, *itr;
394
395 char *constr_id = wdg_data_get(wdg, CONSTRUCTOR);
396 op_desc = db_mro_op_desc_get(class_id, NULL, constr_id);
397 if (!op_desc)
398 {
399 ERR("Constructor: \"%s\" was not found in hash table.\n", constr_id);
400 return EINA_FALSE;
401 }
402
403 eina_strbuf_append_printf(wdg_ctx->buf, " %s = eo_add(%s, %s, %s(",
404 wdg_name_get(wdg), db_class_macro_get(class_id),
405 parent_id, db_op_desc_func_name_get(op_desc));
406
407 values_lst = prop_value_get(wdg_prop_get(wdg, wdg_class_name_get(wdg), constr_id));
408
409 EINA_LIST_FOREACH(values_lst, itr, gui_value)
305 { 410 {
306 wdg_ctx->gl_ctx->public_entities = eina_list_append(wdg_ctx->gl_ctx->public_entities, wdg_dep_id_get(wdg)); 411 if (values_lst != itr)
412 eina_strbuf_append_printf(wdg_ctx->buf, ", ");
413 _format_string_add(wdg_context_get(wdg), gui_value, wdg_ctx->buf);
307 } 414 }
415 eina_strbuf_append_printf(wdg_ctx->buf, "));\n");
308 } 416 }
417 if (wdg_public_get(wdg))
418 {
419 eina_strbuf_append_printf(wdg_ctx->buf, " %s.%s = %s;\n", PUB_WIDGETS, wdg_name_get(wdg), wdg_name_get(wdg));
420 wdg_ctx->gl_ctx->public_entities = eina_list_append(wdg_ctx->gl_ctx->public_entities, wdg_dep_id_get(wdg));
421 }
422
423 session_wdg_existence_set(session, wdg, EINA_TRUE);
309 424
310 return EINA_TRUE; 425 return EINA_TRUE;
311bad_end:
312 return EINA_FALSE;
313} 426}
314 427
315/* Recursively generate context for widget and its children. */ 428/* Recursively generate context for widget and its children. */
@@ -350,10 +463,10 @@ _wdg_creation_function_generate(Gui_Session *session, Gui_Widget *wdg, Widget_Co
350 463
351 gl_ctx->public_main_wdgs = eina_list_append(gl_ctx->public_main_wdgs, wdg_dep_id_get(wdg)); 464 gl_ctx->public_main_wdgs = eina_list_append(gl_ctx->public_main_wdgs, wdg_dep_id_get(wdg));
352 465
353 wdg_ctx->body = eina_strbuf_new();
354 _iter_widget(session, gl_ctx, wdg_ctx, wdg); 466 _iter_widget(session, gl_ctx, wdg_ctx, wdg);
355 467
356 eina_strbuf_append_printf(wdg_ctx->buf, "void\n%s_create()\n{\n", wdg_name); 468 Eina_Strbuf *head = eina_strbuf_new();
469 eina_strbuf_append_printf(head, "void\n%s_create()\n{\n", wdg_name);
357 470
358 /* Add definitions of variables */ 471 /* Add definitions of variables */
359 Dep_Id *dep_id; 472 Dep_Id *dep_id;
@@ -365,13 +478,13 @@ _wdg_creation_function_generate(Gui_Session *session, Gui_Widget *wdg, Widget_Co
365 case DEP_TYPE_WIDGET: 478 case DEP_TYPE_WIDGET:
366 { 479 {
367 Gui_Widget *w = wdg_get(dep_id); 480 Gui_Widget *w = wdg_get(dep_id);
368 if (w) eina_strbuf_append_printf(wdg_ctx->buf, " Eo *%s;\n", wdg_name_get(w)); 481 if (w) eina_strbuf_append_printf(head, " Eo *%s;\n", wdg_name_get(w));
369 break; 482 break;
370 } 483 }
371 case DEP_TYPE_ITEM: 484 case DEP_TYPE_ITEM:
372 { 485 {
373 Item_Container_Item *it = item_container_item_get(dep_id); 486 Item_Container_Item *it = item_container_item_get(dep_id);
374 if (it) eina_strbuf_append_printf(wdg_ctx->buf, " Elm_Object_Item *%s;\n", 487 if (it) eina_strbuf_append_printf(head, " Elm_Object_Item *%s;\n",
375 dep_name_get(dep_id)); 488 dep_name_get(dep_id));
376 break; 489 break;
377 } 490 }
@@ -379,8 +492,8 @@ _wdg_creation_function_generate(Gui_Session *session, Gui_Widget *wdg, Widget_Co
379 break; 492 break;
380 } 493 }
381 } 494 }
382 eina_strbuf_append_printf(wdg_ctx->buf, "\n%s", eina_strbuf_string_get(wdg_ctx->body)); 495 eina_strbuf_prepend_printf(wdg_ctx->buf, "%s\n", eina_strbuf_string_get(head));
383 eina_strbuf_free(wdg_ctx->body); 496 eina_strbuf_free(head);
384 eina_strbuf_append_printf(wdg_ctx->buf, "}\n\n"); 497 eina_strbuf_append_printf(wdg_ctx->buf, "}\n\n");
385} 498}
386 499
@@ -449,10 +562,10 @@ _sequence_generate(Gui_Session *session, Gui_Sequence *seq, Sequence_Context *se
449 gl_ctx->global_entities = eina_list_append(gl_ctx->global_entities, wdg_id); 562 gl_ctx->global_entities = eina_list_append(gl_ctx->global_entities, wdg_id);
450 } 563 }
451 Widget_Context wdg_ctx; 564 Widget_Context wdg_ctx;
452 wdg_ctx.body = eina_strbuf_new(); 565 wdg_ctx.buf = eina_strbuf_new();
453 manager_widget_property_add(session, wdg, prop, MODE_GENERATOR, &wdg_ctx); 566 manager_widget_property_add(session, wdg, prop, MODE_GENERATOR, &wdg_ctx);
454 eina_strbuf_append_printf(seq_ctx->buf, "%s", eina_strbuf_string_get(wdg_ctx.body)); 567 eina_strbuf_append_printf(seq_ctx->buf, "%s", eina_strbuf_string_get(wdg_ctx.buf));
455 eina_strbuf_free(wdg_ctx.body); 568 eina_strbuf_free(wdg_ctx.buf);
456 break; 569 break;
457 } 570 }
458 case USER_ACTION: 571 case USER_ACTION:
@@ -509,7 +622,7 @@ _wdg_cb_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, co
509 char *event_name = _c_plugin_eo_event_name_get(wdg_class_name_get(wdg), cb_type); 622 char *event_name = _c_plugin_eo_event_name_get(wdg_class_name_get(wdg), cb_type);
510 if (event_name) 623 if (event_name)
511 { 624 {
512 eina_strbuf_append_printf(wdg_ctx->body, " eo_do(%s, eo_event_callback_add(%s, %s, NULL));\n", 625 eina_strbuf_append_printf(wdg_ctx->buf, " eo_do(%s, eo_event_callback_add(%s, %s, NULL));\n",
513 wdg_name_get(wdg), event_name, 626 wdg_name_get(wdg), event_name,
514 cb_name); 627 cb_name);
515 free(event_name); 628 free(event_name);
@@ -524,6 +637,7 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
524 const Gui_Context *ctx = gl_ctx->ctx; 637 const Gui_Context *ctx = gl_ctx->ctx;
525 const char *filename = gui_context_export_filename_get(ctx); 638 const char *filename = gui_context_export_filename_get(ctx);
526 const Eina_List *itr; 639 const Eina_List *itr;
640 Dep_Id *dep_id;
527 641
528 Eina_Strbuf *resources_buf = eina_strbuf_new(); 642 Eina_Strbuf *resources_buf = eina_strbuf_new();
529 643
@@ -531,10 +645,6 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
531 seq_ctx.gl_ctx = gl_ctx; 645 seq_ctx.gl_ctx = gl_ctx;
532 seq_ctx.buf = eina_strbuf_new(); 646 seq_ctx.buf = eina_strbuf_new();
533 647
534 Widget_Context wdg_ctx;
535 wdg_ctx.gl_ctx = gl_ctx;
536 wdg_ctx.buf = eina_strbuf_new();
537
538 /* Add declaration of image paths. 648 /* Add declaration of image paths.
539 * Two cases are generated: 649 * Two cases are generated:
540 * - if data prefix variable is not defined, image's initial path is inserted. 650 * - if data prefix variable is not defined, image's initial path is inserted.
@@ -546,15 +656,14 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
546 for (i = 1; i < RESOURCE_SENTINEL; i <<= 1) 656 for (i = 1; i < RESOURCE_SENTINEL; i <<= 1)
547 { 657 {
548 Gui_Resource_Type type = i; 658 Gui_Resource_Type type = i;
549 Dep_Id *res_id;
550 const Eina_List *res_lst = gui_context_resource_list_get(ctx, type); 659 const Eina_List *res_lst = gui_context_resource_list_get(ctx, type);
551 if (!res_lst) continue; 660 if (!res_lst) continue;
552 if (type == RESOURCE_IMAGE || type == RESOURCE_EDJE) 661 if (type == RESOURCE_IMAGE || type == RESOURCE_EDJE)
553 { 662 {
554 Eina_Strbuf *if_buf = eina_strbuf_new(); 663 Eina_Strbuf *if_buf = eina_strbuf_new();
555 EINA_LIST_FOREACH(res_lst, itr, res_id) 664 EINA_LIST_FOREACH(res_lst, itr, dep_id)
556 { 665 {
557 const Gui_Resource *res = gui_context_resource_get(res_id); 666 const Gui_Resource *res = gui_context_resource_get(dep_id);
558 if (!res) continue; 667 if (!res) continue;
559 const char *_fn = ecore_file_file_get( 668 const char *_fn = ecore_file_file_get(
560 type == RESOURCE_EDJE?resource_edj_path_get(res):resource_value_get(res)); 669 type == RESOURCE_EDJE?resource_edj_path_get(res):resource_value_get(res));
@@ -575,9 +684,9 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
575 } 684 }
576 if (type == RESOURCE_EO_CALLBACK) 685 if (type == RESOURCE_EO_CALLBACK)
577 { 686 {
578 EINA_LIST_FOREACH(res_lst, itr, res_id) 687 EINA_LIST_FOREACH(res_lst, itr, dep_id)
579 { 688 {
580 const Gui_Resource *res = gui_context_resource_get(res_id); 689 const Gui_Resource *res = gui_context_resource_get(dep_id);
581 if (res) 690 if (res)
582 eina_strbuf_append_printf(resources_buf, 691 eina_strbuf_append_printf(resources_buf,
583 "extern Eina_Bool\n%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n", 692 "extern Eina_Bool\n%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n",
@@ -588,18 +697,20 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
588 697
589 /* Generate sequences */ 698 /* Generate sequences */
590 Eina_List* seqs_list = gui_context_seq_list_get(ctx); 699 Eina_List* seqs_list = gui_context_seq_list_get(ctx);
591 Dep_Id *seq_id; 700 EINA_LIST_FOREACH(seqs_list, itr, dep_id)
592 EINA_LIST_FOREACH(seqs_list, itr, seq_id)
593 { 701 {
594 Gui_Sequence *seq = sequence_get(seq_id); 702 Gui_Sequence *seq = sequence_get(dep_id);
595 if (seq) _sequence_generate(gl_ctx->session, seq, &seq_ctx); 703 if (seq) _sequence_generate(gl_ctx->session, seq, &seq_ctx);
596 } 704 }
597 705
598 Eina_List* wdgs_list = gui_context_wdg_list_get(ctx); 706 Eina_List* wdgs_list = gui_context_wdg_list_get(ctx);
599 Dep_Id *wdg_id; 707 Eina_Strbuf *wdgs_buf = eina_strbuf_new();
600 EINA_LIST_FOREACH(wdgs_list, itr, wdg_id) 708 Widget_Context wdg_ctx;
709 wdg_ctx.gl_ctx = gl_ctx;
710 wdg_ctx.buf = eina_strbuf_new();
711 EINA_LIST_FOREACH(wdgs_list, itr, dep_id)
601 { 712 {
602 Gui_Widget *wdg = wdg_get(wdg_id); 713 Gui_Widget *wdg = wdg_get(dep_id);
603 if (wdg) 714 if (wdg)
604 { 715 {
605 if (!session_wdg_exists(gl_ctx->session, wdg)) 716 if (!session_wdg_exists(gl_ctx->session, wdg))
@@ -607,9 +718,12 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
607 wdg_ctx.declarations = NULL; 718 wdg_ctx.declarations = NULL;
608 printf("Generate %s\n", wdg_name_get(wdg)); 719 printf("Generate %s\n", wdg_name_get(wdg));
609 _wdg_creation_function_generate(gl_ctx->session, wdg, &wdg_ctx); 720 _wdg_creation_function_generate(gl_ctx->session, wdg, &wdg_ctx);
721 eina_strbuf_append(wdgs_buf, eina_strbuf_string_get(wdg_ctx.buf));
722 eina_strbuf_reset(wdg_ctx.buf);
610 } 723 }
611 } 724 }
612 } 725 }
726 eina_strbuf_free(wdg_ctx.buf);
613 727
614 eina_strbuf_append_printf(gl_ctx->c_buf, 728 eina_strbuf_append_printf(gl_ctx->c_buf,
615 "#include <Elementary.h>\n" 729 "#include <Elementary.h>\n"
@@ -620,14 +734,35 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
620 eina_strbuf_append_printf(gl_ctx->c_buf, 734 eina_strbuf_append_printf(gl_ctx->c_buf,
621 "static GUI %s;\n\n", PUB_WIDGETS); 735 "static GUI %s;\n\n", PUB_WIDGETS);
622 736
623 _c_generator_generator_interface_global_names_generate(gl_ctx->global_entities, gl_ctx->c_buf); 737 /* Append global widgets names */
738 EINA_LIST_FOREACH(gl_ctx->global_entities, itr, dep_id)
739 {
740 switch (dep_type_get(dep_id))
741 {
742 case DEP_TYPE_WIDGET:
743 {
744 Gui_Widget *w = wdg_get(dep_id);
745 if (w) eina_strbuf_append_printf(gl_ctx->c_buf, "static Eo *%s;\n", wdg_name_get(w));
746 break;
747 }
748 case DEP_TYPE_ITEM:
749 {
750 Item_Container_Item *it = item_container_item_get(dep_id);
751 if (it) eina_strbuf_append_printf(gl_ctx->c_buf, "static Elm_Object_Item *%s;\n",
752 dep_name_get(dep_id));
753 break;
754 }
755 default:
756 break;
757 }
758 }
624 759
625 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(resources_buf)); 760 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(resources_buf));
626 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(seq_ctx.buf)); 761 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(seq_ctx.buf));
627 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(wdg_ctx.buf)); 762 eina_strbuf_append_printf(gl_ctx->c_buf,"%s", eina_strbuf_string_get(wdgs_buf));
628 763
629 seq_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR); 764 dep_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR);
630 const Gui_Resource *res = gui_context_resource_get(seq_id); 765 const Gui_Resource *res = gui_context_resource_get(dep_id);
631 if (!res) return; 766 if (!res) return;
632 const char *func_name = resource_name_get(res); 767 const char *func_name = resource_name_get(res);
633 eina_strbuf_append_printf(gl_ctx->c_buf, 768 eina_strbuf_append_printf(gl_ctx->c_buf,
@@ -651,7 +786,6 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
651 "#include <Eo.h>\n" 786 "#include <Eo.h>\n"
652 "#include <Elementary.h>\n\n"); 787 "#include <Elementary.h>\n\n");
653 788
654 Dep_Id *dep_id;
655 eina_strbuf_append_printf(gl_ctx->h_buf, "typedef struct\n{\n"); 789 eina_strbuf_append_printf(gl_ctx->h_buf, "typedef struct\n{\n");
656 EINA_LIST_FOREACH(gl_ctx->public_entities, itr, dep_id) 790 EINA_LIST_FOREACH(gl_ctx->public_entities, itr, dep_id)
657 { 791 {
@@ -667,11 +801,11 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
667 } 801 }
668 } 802 }
669 eina_strbuf_append_printf(gl_ctx->h_buf, "} GUI;\n\n"); 803 eina_strbuf_append_printf(gl_ctx->h_buf, "} GUI;\n\n");
670 EINA_LIST_FOREACH(gl_ctx->public_entities, itr, seq_id) 804 EINA_LIST_FOREACH(gl_ctx->public_entities, itr, dep_id)
671 { 805 {
672 if (dep_type_get(seq_id) == DEP_TYPE_RESOURCE) 806 if (dep_type_get(dep_id) == DEP_TYPE_RESOURCE)
673 { 807 {
674 const Gui_Sequence *seq = sequence_get(seq_id); 808 const Gui_Sequence *seq = sequence_get(dep_id);
675 if (seq) 809 if (seq)
676 eina_strbuf_append_printf(gl_ctx->h_buf, 810 eina_strbuf_append_printf(gl_ctx->h_buf,
677 "Eina_Bool\n%s_%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n\n", 811 "Eina_Bool\n%s_%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n\n",
@@ -679,9 +813,9 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
679 } 813 }
680 } 814 }
681 815
682 EINA_LIST_FREE(gl_ctx->public_main_wdgs, wdg_id) 816 EINA_LIST_FREE(gl_ctx->public_main_wdgs, dep_id)
683 { 817 {
684 eina_strbuf_append_printf(gl_ctx->h_buf, "void\n%s_create();\n\n", dep_name_get(wdg_id)); 818 eina_strbuf_append_printf(gl_ctx->h_buf, "void\n%s_create();\n\n", dep_name_get(dep_id));
685 } 819 }
686 820
687 eina_strbuf_append_printf(gl_ctx->h_buf, "GUI *%s_gui_get();\n", gl_ctx->formatted_project_name); 821 eina_strbuf_append_printf(gl_ctx->h_buf, "GUI *%s_gui_get();\n", gl_ctx->formatted_project_name);
@@ -689,7 +823,7 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
689 eina_strbuf_append_printf(gl_ctx->h_buf, "#endif\n"); 823 eina_strbuf_append_printf(gl_ctx->h_buf, "#endif\n");
690 824
691 eina_strbuf_free(seq_ctx.buf); 825 eina_strbuf_free(seq_ctx.buf);
692 eina_strbuf_free(wdg_ctx.buf); 826 eina_strbuf_free(wdgs_buf);
693 eina_strbuf_free(resources_buf); 827 eina_strbuf_free(resources_buf);
694} 828}
695 829
@@ -768,205 +902,3 @@ generator_ctx_source_generate(const Gui_Context *ctx, Generator_Export_Format fo
768 _ctx_to_file_save(ctx); 902 _ctx_to_file_save(ctx);
769} 903}
770 904
771static Eina_Bool
772_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf)
773{
774 /* Append global widgets names */
775 const Eina_List *itr;
776 Dep_Id *dep_id;
777 EINA_LIST_FOREACH(global_entities, itr, dep_id)
778 {
779 switch (dep_type_get(dep_id))
780 {
781 case DEP_TYPE_WIDGET:
782 {
783 Gui_Widget *w = wdg_get(dep_id);
784 if (w) eina_strbuf_append_printf(buf, "static Eo *%s;\n", wdg_name_get(w));
785 break;
786 }
787 case DEP_TYPE_ITEM:
788 {
789 Item_Container_Item *it = item_container_item_get(dep_id);
790 if (it) eina_strbuf_append_printf(buf, "static Elm_Object_Item *%s;\n",
791 dep_name_get(dep_id));
792 break;
793 }
794 default:
795 break;
796 }
797 }
798
799 return EINA_TRUE;
800}
801
802static Eina_Bool
803_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf)
804{
805 const char *parent_id = wdg_parent_name_get(wdg);
806 Eina_Stringshare *class_id;
807
808 if (!parent_id) parent_id = "NULL";
809
810 class_id = wdg_class_name_get(wdg);
811 if (!class_id)
812 {
813 ERR("Property \"class\" is missing in widget: \"%s\"\n", wdg_name_get(wdg));
814 return EINA_FALSE;
815 }
816
817 /* if there is no property "constructor", it means - using eo constr */
818 if (!wdg_data_get(wdg, CONSTRUCTOR))
819 {
820 eina_strbuf_append_printf(buf, " %s = eo_add(%s, %s);\n",
821 wdg_name_get(wdg), db_class_macro_get(class_id),
822 parent_id);
823 }
824 else
825 {
826 /* Looking for op_id of current constructor*/
827 Op_Desc *op_desc = NULL;
828 Gui_Value *gui_value = NULL;
829 Eina_List *values_lst, *itr;
830
831 char *constr_id = wdg_data_get(wdg, CONSTRUCTOR);
832 op_desc = db_mro_op_desc_get(class_id, NULL, constr_id);
833 if (!op_desc)
834 {
835 ERR("Constructor: \"%s\" was not found in hash table.\n", constr_id);
836 return EINA_FALSE;
837 }
838
839 eina_strbuf_append_printf(buf, " %s = eo_add(%s, %s, %s(",
840 wdg_name_get(wdg), db_class_macro_get(class_id),
841 parent_id, db_op_desc_func_name_get(op_desc));
842
843 values_lst = prop_value_get(wdg_prop_get(wdg, wdg_class_name_get(wdg), constr_id));
844
845 EINA_LIST_FOREACH(values_lst, itr, gui_value)
846 {
847 if (values_lst != itr)
848 eina_strbuf_append_printf(buf, ", ");
849 _format_string_add(wdg_context_get(wdg), gui_value, buf);
850 }
851 eina_strbuf_append_printf(buf, "));\n");
852 }
853 if (wdg_public_get(wdg))
854 {
855 eina_strbuf_append_printf(buf, " %s.%s = %s;\n", PUB_WIDGETS, wdg_name_get(wdg), wdg_name_get(wdg));
856 }
857 return EINA_TRUE;
858}
859
860static Eina_Bool
861_c_generator_generator_interface_widget_property_add(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf)
862{
863 Eina_Bool ret = EINA_TRUE;
864
865 const Op_Desc *op_desc;
866 Gui_Value *gui_value;
867 Eina_List *itr;
868
869 Eina_List *values_lst = prop_value_get(prop);
870
871 Eina_Stringshare *class_id = wdg_class_name_get(wdg);
872 if (!class_id)
873 {
874 ERR("Property \"class\" is missing in widget: \"%s\"\n", wdg_name_get(wdg));
875 return EINA_FALSE;
876 }
877 op_desc = prop_op_desc_get(prop);
878 if (!op_desc)
879 {
880 ERR("Op Desc for property: \"%s\", in widget: \"%s\" was not found in hash table.\n", prop_name_get(prop), wdg_name_get(wdg));
881 return EINA_FALSE;
882 }
883
884 if (wdg_data_get(wdg, CONSTRUCTOR) && (!(strcmp(prop_name_get(prop), wdg_data_get(wdg, CONSTRUCTOR)))))
885 {
886 return EINA_FALSE;
887 }
888
889 eina_strbuf_append_printf(buf, " eo_do(%s, %s(", wdg_name_get(wdg),
890 db_op_desc_func_name_get(op_desc));
891
892 EINA_LIST_FOREACH(values_lst, itr, gui_value)
893 {
894 if (values_lst != itr)
895 eina_strbuf_append_printf(buf, ", ");
896 _format_string_add(wdg_context_get(wdg), gui_value, buf);
897 }
898 eina_strbuf_append_printf(buf, "));\n");
899
900 return ret;
901}
902
903static Eina_Bool
904_c_generator_generator_interface_widget_content_set(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf)
905{
906 Eina_Bool ret = EINA_TRUE;
907
908 const Op_Desc *op_desc;
909 Gui_Value *gui_value;
910 Eina_List *itr;
911
912 Eina_Stringshare *class_id = wdg_class_name_get(wdg);
913 if (!class_id)
914 {
915 ERR("Property \"class\" is missing in widget: \"%s\"\n", wdg_name_get(wdg));
916 return EINA_FALSE;
917 }
918 op_desc = prop_op_desc_get(prop);
919 if (!op_desc)
920 {
921 ERR("Op Desc for property: \"%s\" was not found in hash table.", prop_name_get(prop));
922 return EINA_FALSE;
923 }
924
925 Eina_List *values_lst = prop_value_get(prop);
926
927 eina_strbuf_append_printf(buf, " eo_do(%s, %s(", wdg_name_get(wdg),
928 db_op_desc_func_name_get(op_desc));
929
930 EINA_LIST_FOREACH(values_lst, itr, gui_value)
931 {
932 if (values_lst != itr)
933 eina_strbuf_append_printf(buf, ", ");
934 _format_string_add(wdg_context_get(wdg), gui_value, buf);
935 }
936 eina_strbuf_append_printf(buf, "));\n");
937
938 return ret;
939}
940
941static Eina_Bool
942_c_generator_generator_interface_widget_item_add(const Gui_Widget *wdg, const Item_Container_Item *item, const char *item_name, Eina_Strbuf *buf)
943{
944 const Gui_Widget_Property *prop = item_container_item_prop_get(item);
945 const Op_Desc *op_desc = prop_op_desc_get(prop);
946 if (!op_desc)
947 {
948 ERR("Op Desc for property: \"%s\" was not found in hash table.", prop_name_get(prop));
949 return EINA_FALSE;
950 }
951
952 eina_strbuf_append_printf(buf, " eo_do(%s, %s%s%s(", wdg_name_get(wdg),
953 item_name ? item_name : "", item_name ? " = " : "",
954 db_op_desc_func_name_get(op_desc));
955
956 Eina_List *itr, *values_lst = prop_value_get(prop);
957 Gui_Value *val;
958 EINA_LIST_FOREACH(values_lst, itr, val)
959 {
960 if (values_lst != itr)
961 eina_strbuf_append_printf(buf, ", ");
962 _format_string_add(wdg_context_get(wdg), val, buf);
963 }
964 eina_strbuf_append_printf(buf, "));\n");
965
966 if (item_container_item_public_get(item))
967 {
968 eina_strbuf_append_printf(buf, " %s.%s = %s;\n", PUB_WIDGETS, item_name, item_name);
969 }
970 return EINA_TRUE;
971}
972