summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-09-22 13:55:37 +0300
committerYakov Goldberg <yakov.g@samsung.com>2014-10-02 10:12:04 +0300
commit39f502168f3b0f9d74889a702e945c14af9e9643 (patch)
treede1c2915663242fac6cb25444136e33d6c7dd2a5
parent9718fc75836d45d8dc334e63f278764a0785819d (diff)
Generator: code moving
-rw-r--r--src/lib/generator.c171
1 files changed, 43 insertions, 128 deletions
diff --git a/src/lib/generator.c b/src/lib/generator.c
index d15d83a..3bfccf1 100644
--- a/src/lib/generator.c
+++ b/src/lib/generator.c
@@ -37,12 +37,8 @@ typedef struct
37} Widget_Context; 37} Widget_Context;
38 38
39static Eina_Bool 39static Eina_Bool
40_c_generator_generator_interface_source_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
41static Eina_Bool
42_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf); 40_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf);
43static Eina_Bool 41static Eina_Bool
44_c_generator_generator_interface_resource_generate(const Gui_Resource *res, Eina_Strbuf *buf);
45static Eina_Bool
46_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf); 42_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
47static Eina_Bool 43static Eina_Bool
48_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf); 44_c_generator_generator_interface_widget_create(const Gui_Widget *wdg, Eina_Strbuf *buf);
@@ -52,24 +48,6 @@ static Eina_Bool
52_c_generator_generator_interface_widget_content_set(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf); 48_c_generator_generator_interface_widget_content_set(const Gui_Widget *wdg, const Gui_Widget_Property *prop, Eina_Strbuf *buf);
53static Eina_Bool 49static Eina_Bool
54_c_generator_generator_interface_widget_item_add(const Gui_Widget *wdg, const Item_Container_Item *item, const char *item_name, Eina_Strbuf *buf); 50_c_generator_generator_interface_widget_item_add(const Gui_Widget *wdg, const Item_Container_Item *item, const char *item_name, Eina_Strbuf *buf);
55static Eina_Bool
56_c_generator_generator_interface_header_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
57static Eina_Bool
58_c_generator_generator_interface_header_sequence_generate(const char *seq_name, Global_Gen_Context *gl_ctx);
59static Eina_Bool
60_c_generator_generator_interface_header_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf);
61static Eina_Bool
62_c_generator_generator_interface_header_postscript_generate(const Gui_Context *ctx EINA_UNUSED, Eina_Strbuf *buf);
63static Eina_Bool
64_c_generator_generator_interface_header_public_variables_generate(const Eina_List *public_entities_list, Eina_Strbuf *buf);
65
66/* Structure to hold data about widgets, which must be created with CREATE callbacks. */
67typedef struct
68{
69 EINA_INLIST;
70 const char *wdg_name;
71 const char *cb_name;
72} Wdg_Cb_Pair;
73 51
74/* Check if current dep_id is in list of Dep_Ids */ 52/* Check if current dep_id is in list of Dep_Ids */
75static Eina_Bool 53static Eina_Bool
@@ -579,7 +557,14 @@ _ctx_to_file_save(const Gui_Context *ctx)
579 gl_gen_ctx.public_main_wdgs = NULL; 557 gl_gen_ctx.public_main_wdgs = NULL;
580 gl_gen_ctx.formatted_project_name = _project_name_format((char *) gui_context_project_name_get(ctx)); 558 gl_gen_ctx.formatted_project_name = _project_name_format((char *) gui_context_project_name_get(ctx));
581 559
582 _c_generator_generator_interface_source_preamble_generate(ctx, gl_gen_ctx.buf); 560 eina_strbuf_append_printf(gl_gen_ctx.buf,
561 "#include <Elementary.h>\n"
562 "#include \"elm_widget_container.h\"\n"
563 "#include \"elm_interface_scrollable.h\"\n"
564 "#include \"%s.h\"\n\n", filename);
565
566 eina_strbuf_append_printf(gl_gen_ctx.buf,
567 "static GUI %s;\n\n", PUB_WIDGETS);
583 eina_strbuf_append_printf(gl_gen_ctx.buf, "__GLOBAL_NAMES__"); 568 eina_strbuf_append_printf(gl_gen_ctx.buf, "__GLOBAL_NAMES__");
584 569
585 /* Add declarations of resource callbacks. */ 570 /* Add declarations of resource callbacks. */
@@ -588,7 +573,12 @@ _ctx_to_file_save(const Gui_Context *ctx)
588 EINA_LIST_FOREACH(res_lst, itr, res_id) 573 EINA_LIST_FOREACH(res_lst, itr, res_id)
589 { 574 {
590 const Gui_Resource *res = gui_context_resource_get(res_id); 575 const Gui_Resource *res = gui_context_resource_get(res_id);
591 if (res) _c_generator_generator_interface_resource_generate(res, gl_gen_ctx.buf); 576 if (res && resource_type_get(res) == RESOURCE_EO_CALLBACK)
577 {
578 eina_strbuf_append_printf(gl_gen_ctx.buf,
579 "extern Eina_Bool\n%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n",
580 resource_value_get(res));
581 }
592 } 582 }
593 583
594 /* Add declaration of image paths. 584 /* Add declaration of image paths.
@@ -679,15 +669,38 @@ _ctx_to_file_save(const Gui_Context *ctx)
679 669
680 /* Generate header file. */ 670 /* Generate header file. */
681 eina_strbuf_reset(gl_gen_ctx.buf); 671 eina_strbuf_reset(gl_gen_ctx.buf);
682 _c_generator_generator_interface_header_preamble_generate(ctx, gl_gen_ctx.buf); 672 eina_strbuf_append_printf(gl_gen_ctx.buf,
673 "#ifndef _%s_h\n"
674 "#define _%s_h\n", filename, filename);
675 eina_strbuf_append_printf(gl_gen_ctx.buf,
676 "#include <Eo.h>\n"
677 "#include <Elementary.h>\n\n");
683 678
684 _c_generator_generator_interface_header_public_variables_generate(gl_gen_ctx.public_entities, gl_gen_ctx.buf); 679 Dep_Id *dep_id;
680 eina_strbuf_append_printf(gl_gen_ctx.buf, "typedef struct\n{\n");
681 EINA_LIST_FOREACH(gl_gen_ctx.public_entities, itr, dep_id)
682 {
683 switch (dep_type_get(dep_id))
684 {
685 case DEP_TYPE_WIDGET:
686 eina_strbuf_append_printf(gl_gen_ctx.buf, " Eo *%s;\n", dep_name_get(dep_id));
687 break;
688 case DEP_TYPE_ITEM:
689 eina_strbuf_append_printf(gl_gen_ctx.buf, " Elm_Object_Item *%s;\n", dep_name_get(dep_id));
690 break;
691 default: break;
692 }
693 }
694 eina_strbuf_append_printf(gl_gen_ctx.buf, "} GUI;\n\n");
685 EINA_LIST_FOREACH(gl_gen_ctx.public_entities, itr, seq_id) 695 EINA_LIST_FOREACH(gl_gen_ctx.public_entities, itr, seq_id)
686 { 696 {
687 if (dep_type_get(seq_id) == DEP_TYPE_RESOURCE) 697 if (dep_type_get(seq_id) == DEP_TYPE_RESOURCE)
688 { 698 {
689 const Gui_Sequence *seq = sequence_get(seq_id); 699 const Gui_Sequence *seq = sequence_get(seq_id);
690 if (seq) _c_generator_generator_interface_header_sequence_generate(sequence_name_get(seq), &gl_gen_ctx); 700 if (seq)
701 eina_strbuf_append_printf(gl_gen_ctx.buf,
702 "Eina_Bool\n%s_%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n\n",
703 gl_gen_ctx.formatted_project_name, sequence_name_get(seq));
691 } 704 }
692 } 705 }
693 706
@@ -696,8 +709,9 @@ _ctx_to_file_save(const Gui_Context *ctx)
696 eina_strbuf_append_printf(gl_gen_ctx.buf, "void\n%s_create();\n\n", dep_name_get(wdg_id)); 709 eina_strbuf_append_printf(gl_gen_ctx.buf, "void\n%s_create();\n\n", dep_name_get(wdg_id));
697 } 710 }
698 711
699 _c_generator_generator_interface_header_main_function_generate(ctx, gl_gen_ctx.buf); 712 eina_strbuf_append_printf(gl_gen_ctx.buf, "GUI *%s_gui_get();\n", gl_gen_ctx.formatted_project_name);
700 _c_generator_generator_interface_header_postscript_generate(ctx, gl_gen_ctx.buf); 713
714 eina_strbuf_append_printf(gl_gen_ctx.buf, "#endif\n");
701 fprintf(fp_h, "%s", eina_strbuf_string_get(gl_gen_ctx.buf)); 715 fprintf(fp_h, "%s", eina_strbuf_string_get(gl_gen_ctx.buf));
702 716
703 eina_strbuf_free(gl_gen_ctx.buf); 717 eina_strbuf_free(gl_gen_ctx.buf);
@@ -733,22 +747,6 @@ generator_ctx_source_generate(const Gui_Context *ctx, Generator_Export_Format fo
733} 747}
734 748
735static Eina_Bool 749static Eina_Bool
736_c_generator_generator_interface_source_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf)
737{
738 const char *filename = gui_context_export_filename_get(ctx);
739 eina_strbuf_append_printf(buf,
740 "#include <Elementary.h>\n"
741 "#include \"elm_widget_container.h\"\n"
742 "#include \"elm_interface_scrollable.h\"\n"
743 "#include \"%s.h\"\n\n", filename);
744
745 eina_strbuf_append_printf(buf,
746 "static GUI %s;\n\n", PUB_WIDGETS);
747
748 return EINA_TRUE;
749}
750
751static Eina_Bool
752_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf) 750_c_generator_generator_interface_global_names_generate(const Eina_List *global_entities, Eina_Strbuf *buf)
753{ 751{
754 /* Append global widgets names */ 752 /* Append global widgets names */
@@ -780,22 +778,6 @@ _c_generator_generator_interface_global_names_generate(const Eina_List *global_e
780} 778}
781 779
782static Eina_Bool 780static Eina_Bool
783_c_generator_generator_interface_resource_generate(const Gui_Resource *res, Eina_Strbuf *buf)
784{
785 switch (resource_type_get(res))
786 {
787 case RESOURCE_EO_CALLBACK:
788 eina_strbuf_append_printf(buf,
789 "extern Eina_Bool\n%s(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);\n",
790 resource_value_get(res));
791 break;
792 default:
793 return EINA_FALSE;
794 }
795 return EINA_TRUE;
796}
797
798static Eina_Bool
799_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf) 781_c_generator_generator_interface_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf)
800{ 782{
801 Dep_Id *dep_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR); 783 Dep_Id *dep_id = gui_context_dep_id_by_name_get(ctx, BIGBANG_STR);
@@ -991,70 +973,3 @@ _c_generator_generator_interface_widget_item_add(const Gui_Widget *wdg, const It
991 return EINA_TRUE; 973 return EINA_TRUE;
992} 974}
993 975
994static Eina_Bool
995_c_generator_generator_interface_header_main_function_generate(const Gui_Context *ctx, Eina_Strbuf *buf)
996{
997 /* Add get_gui function . */
998 char *project_name = (char *) gui_context_project_name_get(ctx);
999 char *formatted = _project_name_format(project_name);
1000 eina_strbuf_append_printf(buf, "GUI *%s_gui_get();\n", formatted);
1001 free(formatted);
1002 return EINA_TRUE;
1003}
1004
1005static Eina_Bool
1006_c_generator_generator_interface_header_sequence_generate(const char *seq_name, Global_Gen_Context *gl_ctx)
1007{
1008 /* Add get_gui function . */
1009 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",
1010 gl_ctx->formatted_project_name, seq_name);
1011 return EINA_TRUE;
1012}
1013
1014static Eina_Bool
1015_c_generator_generator_interface_header_preamble_generate(const Gui_Context *ctx, Eina_Strbuf *buf)
1016{
1017 /* FIXME: add concatenation here*/
1018 const char *filename = gui_context_export_filename_get(ctx);
1019 eina_strbuf_append_printf(buf,
1020 "#ifndef _%s_h\n"
1021 "#define _%s_h\n", filename, filename);
1022 eina_strbuf_append_printf(buf,
1023 "#include <Eo.h>\n"
1024 "#include <Elementary.h>\n\n");
1025
1026 return EINA_TRUE;
1027}
1028
1029static Eina_Bool
1030_c_generator_generator_interface_header_postscript_generate(const Gui_Context *ctx EINA_UNUSED, Eina_Strbuf *buf)
1031{
1032 eina_strbuf_append_printf(buf, "#endif\n");
1033
1034 return EINA_TRUE;
1035}
1036
1037static Eina_Bool
1038_c_generator_generator_interface_header_public_variables_generate(const Eina_List *public_entities_list, Eina_Strbuf *buf)
1039{
1040 const Eina_List *itr;
1041 Dep_Id *dep_id;
1042 eina_strbuf_append_printf(buf, "typedef struct\n{\n");
1043 EINA_LIST_FOREACH(public_entities_list, itr, dep_id)
1044 {
1045 switch (dep_type_get(dep_id))
1046 {
1047 case DEP_TYPE_WIDGET:
1048 eina_strbuf_append_printf(buf, " Eo *%s;\n", dep_name_get(dep_id));
1049 break;
1050 case DEP_TYPE_ITEM:
1051 eina_strbuf_append_printf(buf, " Elm_Object_Item *%s;\n", dep_name_get(dep_id));
1052 break;
1053 case DEP_TYPE_RESOURCE: break;
1054 default: return EINA_FALSE;
1055 }
1056 }
1057 eina_strbuf_append_printf(buf, "} GUI;\n\n");
1058 return EINA_TRUE;
1059}
1060