jackdanielz pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=f08b3d28c78c0423bf854cb2a2a1ce1c0791cd8e

commit f08b3d28c78c0423bf854cb2a2a1ce1c0791cd8e
Author: Daniel Zaoui <daniel.za...@samsung.com>
Date:   Thu Nov 5 22:02:17 2015 +0200

    Add legacy generation
    
    Now legacy code can be generated via the command line argument --legacy.
    No GUI support is given for the moment.
    
    Issues can remain when objects are created. When non default constructor
    is used, the parameters can be badly generated or in the wrong order.
---
 data/layouts/factory.json    |   1 +
 src/bin/gui/egui_layout.json |   4 +
 src/bin/gui/egui_logic.c     |  16 +-
 src/bin/main.c               |  11 +-
 src/lib/database.c           |  74 +++++++-
 src/lib/database.h           |   7 +
 src/lib/generator.c          | 396 +++++++++++++++++++++++++++++++++++--------
 src/lib/generator.h          |   2 +-
 8 files changed, 421 insertions(+), 90 deletions(-)

diff --git a/data/layouts/factory.json b/data/layouts/factory.json
index 1cd4808..fb071c1 100644
--- a/data/layouts/factory.json
+++ b/data/layouts/factory.json
@@ -9,6 +9,7 @@
          },
          "Properties":
          {
+            "Elm.Win.name":["Win"],
             "Elm.Win.type":["ELM_WIN_BASIC"],
             "Elm.Win.autodel":[true],
             "Efl.Gfx.Base.size":[300, 300],
diff --git a/src/bin/gui/egui_layout.json b/src/bin/gui/egui_layout.json
index e61aff7..bacbc4e 100644
--- a/src/bin/gui/egui_layout.json
+++ b/src/bin/gui/egui_layout.json
@@ -167,6 +167,7 @@
          },
          "Properties":
          {
+            "Elm.Win.name":["Fs"],
             "Elm.Win.title":["Select file"],
             "Elm.Win.autodel":[true],
             "Efl.Gfx.Base.size":[300, 450],
@@ -361,6 +362,7 @@
          },
          "Properties":
          {
+            "Elm.Win.name":["Resources"],
             "Elm.Win.title":["Resource Manager"],
             "Elm.Win.autodel":[true],
             "Efl.Gfx.Base.size":[640, 480],
@@ -654,6 +656,7 @@
          },
          "Properties":
          {
+            "Elm.Win.name":["Settings"],
             "Elm.Win.title":["Settings Manager"],
             "Elm.Win.autodel":[true],
             "Efl.Gfx.Base.size":[640, 480],
@@ -865,6 +868,7 @@
          },
          "Properties":
          {
+            "Elm.Win.name":["Main"],
             "Elm.Win.title":["Erigo - No project"],
             "Elm.Win.icon_object":["main_logo"],
             "Efl.Gfx.Base.visible":[true],
diff --git a/src/bin/gui/egui_logic.c b/src/bin/gui/egui_logic.c
index ba44343..2e3e137 100644
--- a/src/bin/gui/egui_logic.c
+++ b/src/bin/gui/egui_logic.c
@@ -159,7 +159,7 @@ _popup_cb(Popup_Button_Type button_type, void *data)
 
         gui_context_project_filename_set((Gui_Context *) ctx, filename);
         gui_context_project_path_set((Gui_Context *) ctx, (const char *) 
parent_dir);
-        generator_ctx_source_generate(ctx, GENERATE_JSON);
+        generator_ctx_source_generate(ctx, GENERATE_JSON, EINA_FALSE);
         _canvas_name_update(ctx);
 
         free(parent_dir);
@@ -269,7 +269,7 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void 
*event)
                    gui_context_project_name_set((Gui_Context *) ctx, 
project_name);
                    gui_context_project_path_set((Gui_Context *) ctx, path);
                    gui_context_project_filename_set((Gui_Context *) ctx, 
full_filename);
-                   generator_ctx_source_generate(ctx, GENERATE_JSON);
+                   generator_ctx_source_generate(ctx, GENERATE_JSON, 
EINA_FALSE);
                    _canvas_name_update(ctx);
                    free(default_filename);
                 }
@@ -296,12 +296,12 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, 
void *event)
                 {
                  case 0:
                       {
-                         generator_ctx_source_generate(ctx, GENERATE_C | 
GENERATE_H);
+                         generator_ctx_source_generate(ctx, GENERATE_C | 
GENERATE_H, EINA_FALSE);
                          break;
                       }
                  case 1:
                       {
-                         generator_ctx_source_generate(ctx, GENERATE_CPP);
+                         generator_ctx_source_generate(ctx, GENERATE_CPP, 
EINA_FALSE);
                          break;
                       }
                 }
@@ -323,7 +323,7 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void 
*event)
                 {
                    gui_context_project_filename_set((Gui_Context *) ctx, 
filename);
                    gui_context_project_path_set((Gui_Context *) ctx, (const 
char *) parent_dir);
-                   generator_ctx_source_generate(ctx, GENERATE_JSON);
+                   generator_ctx_source_generate(ctx, GENERATE_JSON, 
EINA_FALSE);
                    _canvas_name_update(ctx);
                 }
               break;
@@ -493,7 +493,7 @@ _project_menu_item_sel_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_
                    _fs_mode_open(ITEM_SAVEAS);
                    return;
                 }
-              generator_ctx_source_generate(ctx, GENERATE_JSON);
+              generator_ctx_source_generate(ctx, GENERATE_JSON, EINA_FALSE);
               _canvas_name_update(ctx);
               break;
            }
@@ -768,7 +768,7 @@ _key_binding_save_cb(void *data)
              _fs_mode_open(ITEM_SAVEAS);
              return;
           }
-        generator_ctx_source_generate(ctx, GENERATE_JSON);
+        generator_ctx_source_generate(ctx, GENERATE_JSON, EINA_FALSE);
         _canvas_name_update(ctx);
      }
    else if (action == ITEM_SAVEAS)
@@ -804,7 +804,7 @@ _egui_project_open(const char *path)
                   gui_context_project_name_set((Gui_Context *) ctx, filename);
                   gui_context_project_path_set((Gui_Context *) ctx, _dir);
                   gui_context_project_filename_set((Gui_Context *) ctx, 
filename);
-                  generator_ctx_source_generate(ctx, GENERATE_JSON);
+                  generator_ctx_source_generate(ctx, GENERATE_JSON, 
EINA_FALSE);
                   _canvas_name_update(ctx);
 
                   free(_dir);
diff --git a/src/bin/main.c b/src/bin/main.c
index 8d08856..706d78d 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -12,7 +12,7 @@
 #endif
 
 static Eina_Bool
-_generate(const char *in_file, const char *out_path, Generator_Export_Format 
format)
+_generate(const char *in_file, const char *out_path, Generator_Export_Format 
format, Eina_Bool generate_legacy)
 {
    Gui_Context *ctx;
    const char *path;
@@ -68,7 +68,7 @@ _generate(const char *in_file, const char *out_path, 
Generator_Export_Format for
         gui_context_export_h_filename_set(ctx, out_file);
      }
 
-   generator_ctx_source_generate(ctx, format);
+   generator_ctx_source_generate(ctx, format, generate_legacy);
    gui_context_del(ctx);
    free(out_dir);
    return EINA_TRUE;
@@ -127,6 +127,7 @@ enum
 };
 
 static Generator_Export_Format export_format = GENERATE_NONE;
+static Eina_Bool generate_legacy = EINA_FALSE;
 
 int
 main(int argc, char **argv)
@@ -139,6 +140,7 @@ main(int argc, char **argv)
      {
           {"gc", no_argument, (int *) &export_format, GENERATE_C},
           {"gh", no_argument, (int *) &export_format, GENERATE_H},
+          {"legacy", no_argument, (int *) &generate_legacy, EINA_TRUE},
 /* commenting out JSON generation. */
 #if 0
           {"gjson", no_argument, (int *) &export_format, GENERATE_JSON},
@@ -174,11 +176,12 @@ main(int argc, char **argv)
 
    if (mode == MODE_HELP)
      {
-        printf("Usage: %s [-h/--help] [--gh|--gc] [-s/--simulate target_name] 
[-o OUTFILE] filename\n", argv[0]);
+        printf("Usage: %s [-h/--help] [--gh|--gc] [--legacy] [-s/--simulate 
target_name] [-o OUTFILE] filename\n", argv[0]);
         printf("       --help/-h Print this help.\n");
         printf("       --output/-o Provide output filename.\n");
         printf("       --gh Generate C header file [.h]\n");
         printf("       --gc Generate C source file [.c]");
+        printf("       --legacy Generate legacy API in C source file [.c]");
 /* commenting out JSON generation. */
 #if 0
         printf("\n       --gjson Generate JSON project file [.egui]");
@@ -271,7 +274,7 @@ main(int argc, char **argv)
      }
    else if (mode == MODE_EXPORT)
      {
-        _generate(filename, output_filename, export_format);
+        _generate(filename, output_filename, export_format, generate_legacy);
      }
 
 error_end:
diff --git a/src/lib/database.c b/src/lib/database.c
index 72c68b0..6dee252 100644
--- a/src/lib/database.c
+++ b/src/lib/database.c
@@ -36,6 +36,7 @@ struct _Op_Desc
    char *op_name_full; /* Evas_Object::visibility_set */
    const char *display_name;   /* "Visibility" */
    char *func_set_name; /*func to used in eo_do "evas_obj_visibility_set"*/
+   char *func_legacy_name; /* Legacy function name */
    void *func_set; /* Pointer to Eo2 API. T.e. func evas_obj_box_pack_end*/
    void *func_get; /* Pointer to Eo2 API. T.e. func evas_obj_box_pack_end*/
    Eina_List *params ; /* List of Op_Param_Desc */
@@ -60,10 +61,12 @@ struct _Container_Desc
 typedef struct
 {
    char *class_macro;                        /* "ELM_WIN_CLASS" */
+   char *class_legacy_add;                   /* "elm_win_add" */
    const Eo_Class* (*class_get_func)(void);  /* pointer to elm_win_class_get() 
*/
    Eina_Hash *cl_props_hash;
    Eina_List *cl_props_list;
    Eina_List *inherit_containers;
+
 } Class_Props;
 
 typedef struct
@@ -184,6 +187,7 @@ _cl_table_free_cb(void *_data)
         eina_stringshare_del(op->op_name);
         free(op->op_name_full);
         free(op->func_set_name);
+        free(op->func_legacy_name);
         free(op);
      }
    eina_list_free(data->inherit_containers);
@@ -226,6 +230,36 @@ eo_class_mro_get(const char *class_name)
  * Returns class_get function for given class name.
  * Need to free the return. */
 static char*
+_class_legacy_add_func_name_get(Eolian_Class *eolian_class)
+{
+   char *ret;
+   Eina_Strbuf *buf = eina_strbuf_new();
+
+   const char *leg_pre = eolian_class_legacy_prefix_get(eolian_class);
+   if (leg_pre)
+     {
+        eina_strbuf_append_printf(buf, "%s_", leg_pre);
+     }
+   else
+     {
+        Eina_Iterator *itr = eolian_class_namespaces_get(eolian_class);
+        const char *name;
+        EINA_ITERATOR_FOREACH(itr, name)
+          {
+             eina_strbuf_append_printf(buf, "%s_", name);
+          }
+        eina_iterator_free(itr);
+        eina_strbuf_append_printf(buf, "%s_", 
eolian_class_name_get(eolian_class));
+     }
+
+   eina_strbuf_append_printf(buf, "add");
+   ret = eina_strbuf_string_steal(buf);
+   eina_strbuf_free(buf);
+   eina_str_tolower(&ret);
+   return ret;
+}
+
+static char*
 _class_get_func_name_get(Eolian_Class *eolian_class)
 {
    char *ret;
@@ -249,10 +283,9 @@ _class_get_func_name_get(Eolian_Class *eolian_class)
 
 /* Helper for db_init() */
 static char*
-_class_func_set_name_get(const Eolian_Function *func)
+_class_func_set_name_get(const Eolian_Function *func, Eina_Bool use_legacy)
 {
    char *ret = NULL;
-   Eina_Strbuf *buf = eina_strbuf_new();
 
    Eolian_Function_Type f_type = eolian_function_type_get(func);
 
@@ -262,12 +295,16 @@ _class_func_set_name_get(const Eolian_Function *func)
     * */
    f_type = ((f_type == EOLIAN_PROPERTY) ? EOLIAN_PROP_SET : f_type);
 
-   Eina_Stringshare *_full_c_name = eolian_function_full_c_name_get(func, 
f_type, EINA_FALSE);
-   eina_strbuf_append_printf(buf, "%s", _full_c_name);
+   Eina_Stringshare *_full_c_name = eolian_function_full_c_name_get(func, 
f_type, use_legacy);
+   if (_full_c_name)
+     {
+        Eina_Strbuf *buf = eina_strbuf_new();
+        eina_strbuf_append_printf(buf, "%s", _full_c_name);
 
-   ret = strdup(eina_strbuf_string_get(buf));
-   eina_strbuf_free(buf);
-   eina_stringshare_del(_full_c_name);
+        ret = strdup(eina_strbuf_string_get(buf));
+        eina_strbuf_free(buf);
+        eina_stringshare_del(_full_c_name);
+     }
    return ret;
 }
 
@@ -562,6 +599,7 @@ _cl_table_init()
              free(str);
              str = _class_macro_get(ekl);
              class_props->class_macro = strdup(str);
+             class_props->class_legacy_add = 
_class_legacy_add_func_name_get(ekl);
              free(str);
           }
      }
@@ -1151,12 +1189,15 @@ db_init(const char *db_path, const char *all_eo_path, 
const char *black_list)
 
                   if ((f_type == EOLIAN_PROPERTY) || (f_type == 
EOLIAN_PROP_SET) || (f_type == EOLIAN_METHOD))
                     {
-                       func_set_name = _class_func_set_name_get(func);
+                       func_set_name = _class_func_set_name_get(func, 
EINA_FALSE);
                        op_desc->func_set_name = strdup(func_set_name);
                        op_desc->func_set = dlsym(RTLD_DEFAULT, 
op_desc->func_set_name);
                        if (!op_desc->func_set)
                          ERR("DLSYM not found for %s", op_desc->func_set_name);
                        free(func_set_name);
+                       char *legacy_name = _class_func_set_name_get(func, 
EINA_TRUE);
+                       if (legacy_name) op_desc->func_legacy_name = 
strdup(legacy_name);
+                       free(legacy_name);
                     }
                   /* if method is not PROPERTY or PROP_GET, NULL will be 
returned. */
                   func_get_name = _class_func_get_name_get(func);
@@ -1395,6 +1436,16 @@ db_class_func_get(const char *class_name)
 }
 
 const char*
+db_class_legacy_add_get(const char *class_name)
+{
+   Class_Props *cl_props;
+   cl_props = eina_hash_find(cl_table, class_name);
+   if (cl_props)
+     return cl_props->class_legacy_add;
+   return NULL;
+}
+
+const char*
 db_class_macro_get(const char *class_name)
 {
    Class_Props *cl_props;
@@ -1629,6 +1680,13 @@ db_op_desc_func_name_get(const Op_Desc *op_desc)
    return (op_desc ? op_desc->func_set_name : NULL);
 }
 
+/* Get func name for current op*/
+const char*
+db_op_desc_func_legacy_name_get(const Op_Desc *op_desc)
+{
+   return (op_desc ? op_desc->func_legacy_name : NULL);
+}
+
 /* Get class name for current op*/
 const char*
 db_op_desc_class_name_get(const Op_Desc *op_desc)
diff --git a/src/lib/database.h b/src/lib/database.h
index bbba54b..74e45d9 100644
--- a/src/lib/database.h
+++ b/src/lib/database.h
@@ -153,6 +153,9 @@ db_shutdown();
 void*
 db_class_func_get(const char *class_name);
 
+const char*
+db_class_legacy_add_get(const char *class_name);
+
 /* Get pointer to class macro string */
 const char*
 db_class_macro_get(const char *class_name);
@@ -239,6 +242,10 @@ db_op_desc_func_get_pointer_get(const Op_Desc *op_desc);
 const char*
 db_op_desc_func_name_get(const Op_Desc *op_desc);
 
+/* Get func legacy name for current op*/
+const char*
+db_op_desc_func_legacy_name_get(const Op_Desc *op_desc);
+
 /* Get class name for current op*/
 const char*
 db_op_desc_class_name_get(const Op_Desc *op_desc);
diff --git a/src/lib/generator.c b/src/lib/generator.c
index cc1071b..3ea9a5f 100644
--- a/src/lib/generator.c
+++ b/src/lib/generator.c
@@ -22,6 +22,7 @@ typedef struct
    char *Formatted_Project_Name;
    char *FORMATTED_PROJECT_NAME;
    Gui_Session *session;
+   Eina_Bool generate_legacy;
 } Global_Gen_Context;
 
 /* Structure to hold data about func being generated for a main widget. */
@@ -214,6 +215,68 @@ _format_string_add(Gui_Value *gui_value, Eina_Strbuf *p)
    return EINA_TRUE;
 }
 
+static Eina_Bool
+_op_name_compare(const Op_Desc *_op_desc, const char *_class_name, const char 
*_op_name)
+{
+   const char *class_name = db_op_desc_class_name_get(_op_desc);
+   const char *op_name = db_op_desc_op_name_get(_op_desc);
+   if (!strcmp(class_name, _class_name) &&
+         !strcmp(op_name, _op_name))
+     {
+        return EINA_TRUE;
+     }
+   return EINA_FALSE;
+}
+
+typedef struct
+{
+   const char *legacy_name;
+   const char *fklass;
+   const char *fname;
+   const char *klass;
+} _Eo_Legacy_Info;
+
+static _Eo_Legacy_Info eo_legacy_infos[] =
+{
+     { "evas_object_resize", DB_DEF_EFL_GFX_BASE_CLASS, SIZE_SET, NULL },
+     { "evas_object_move", DB_DEF_EFL_GFX_BASE_CLASS, POSITION_SET, NULL },
+     { "evas_object_color_set", DB_DEF_EFL_GFX_BASE_CLASS, COLOR_SET, NULL },
+     { "elm_layout_file_set", DB_DEF_EFL_FILE_INTERFACE, FILE_SET, 
DB_DEF_LAYOUT_CLASS},
+     { "elm_bg_file_set", DB_DEF_EFL_FILE_INTERFACE, FILE_SET, 
DB_DEF_BG_CLASS},
+     { "elm_image_file_set", DB_DEF_EFL_FILE_INTERFACE, FILE_SET, 
DB_DEF_ICON_CLASS},
+     { "elm_image_file_set", DB_DEF_EFL_FILE_INTERFACE, FILE_SET, 
DB_DEF_IMAGE_CLASS},
+     { "evas_object_image_file_set", DB_DEF_EFL_FILE_INTERFACE, FILE_SET, 
DB_DEF_EVAS_IMAGE_CLASS},
+     { "elm_scroller_policy_set", "Elm_Interface_Scrollable", "policy", NULL},
+     { "elm_scroller_bounce_set", "Elm_Interface_Scrollable", "bounce_allow", 
NULL},
+     { "elm_fileselector_entry_path_set", "Elm_Interface_Fileselector", 
"path", DB_DEF_FILESELECTOR_ENTRY_CLASS},
+     { "elm_fileselector_path_set", "Elm_Interface_Fileselector", "path", 
DB_DEF_FILESELECTOR_CLASS},
+     { "elm_layout_content_set", DB_DEF_CONTAINER_CLASS, CONTENT_SET, NULL },
+     { "elm_naviframe_item_push", DB_DEF_NAVIFRAME_CLASS, ITEM_PUSH, NULL },
+     { "elm_object_part_text_set", DB_DEF_WIDGET_CLASS, PART_TEXT_SET, NULL },
+     { "elm_object_style_set", DB_DEF_WIDGET_CLASS, "style", NULL },
+     { "elm_object_disabled_set", DB_DEF_WIDGET_CLASS, "disabled", NULL },
+     { NULL, NULL, NULL, NULL }
+};
+
+static const char *
+_legacy_name_find(const char *kl_name, const Op_Desc *op_desc)
+{
+   _Eo_Legacy_Info *info = &eo_legacy_infos[0];
+   const char *class_name = db_op_desc_class_name_get(op_desc);
+   const char *op_name = db_op_desc_op_name_get(op_desc);
+   while (info && info->legacy_name)
+     {
+        if (!strcmp(class_name, info->fklass) &&
+              !strcmp(op_name, info->fname) &&
+              (!info->klass || !strcmp(info->klass, kl_name)))
+          {
+             return info->legacy_name;
+          }
+        info++;
+     }
+   return NULL;
+}
+
 /* Generate string for current property. */
 static Eina_Bool
 _wdg_prop_add_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget 
*wdg, const Gui_Widget_Property *prop, void *data)
@@ -246,8 +309,55 @@ _wdg_prop_add_generate(Gui_Session *session EINA_UNUSED, 
const Gui_Widget *wdg,
      }
 
    Eina_Strbuf *buf = eina_strbuf_new();
-   eina_strbuf_append_printf(buf, "   eo_do(%s, %s(", wdg_name_get(wdg),
-                                      db_op_desc_func_name_get(op_desc));
+   const char *legacy_name = NULL;
+   if (gl_ctx->generate_legacy)
+     {
+        legacy_name = _legacy_name_find(wdg_class_name_get(wdg), op_desc);
+        if (!legacy_name) legacy_name = 
db_op_desc_func_legacy_name_get(op_desc);
+        if (!legacy_name)
+          {
+             if (_op_name_compare(op_desc, DB_DEF_EFL_GFX_BASE_CLASS, 
VISIBLE_SET))
+               {
+                  /* Legacy function depends on visibility parameter */
+                  Eina_Bool visible = EINA_FALSE;
+                  Gui_Widget_Property *prop2;
+                  prop2 = wdg_prop_get(wdg, DB_DEF_EFL_GFX_BASE_CLASS, 
VISIBLE_SET);
+                  if (prop2)
+                    {
+                       visible = INT_GET(prop_value_nth_get(prop2, 0));
+                    }
+                  legacy_name = visible ? "evas_object_show" : 
"evas_object_hide";
+                  eina_strbuf_append_printf(buf, "   %s(%s", legacy_name, 
wdg_name_get(wdg));
+                  goto finalize;
+               }
+
+             else if (_op_name_compare(op_desc, DB_DEF_BG_CLASS, COLOR_SET))
+               {
+                  /* Special case as the Eo function receives an additional 
parameter */
+                  legacy_name = "elm_bg_color_set";
+                  int r = 0, b = 0, g = 0;
+                  Gui_Widget_Property *prop2;
+                  prop2 = wdg_prop_get(wdg, DB_DEF_BG_CLASS, COLOR_SET);
+                  if (prop2)
+                    {
+                       r = INT_GET(prop_value_nth_get(prop2, 0));
+                       g = INT_GET(prop_value_nth_get(prop2, 1));
+                       b = INT_GET(prop_value_nth_get(prop2, 2));
+                    }
+                  eina_strbuf_append_printf(buf, "   %s(%s, %d, %d, %d", 
legacy_name, wdg_name_get(wdg), r, g, b);
+                  goto finalize;
+               }
+          }
+     }
+   if (legacy_name)
+     {
+        eina_strbuf_append_printf(buf, "   %s(%s, ", legacy_name, 
wdg_name_get(wdg));
+     }
+   else
+     {
+        eina_strbuf_append_printf(buf, "   eo_do(%s, %s(", wdg_name_get(wdg),
+                                  db_op_desc_func_name_get(op_desc));
+     }
 
    /* From callback but not because of item creation */
    if (wdg_ctx->inside_cb && !wdg_ctx->inside_item_creation)
@@ -278,8 +388,18 @@ _wdg_prop_add_generate(Gui_Session *session EINA_UNUSED, 
const Gui_Widget *wdg,
              return EINA_TRUE;
           }
      }
-   eina_strbuf_append_printf(wdg_ctx->buf, "%s));\n",
-         eina_strbuf_string_get(buf));
+
+finalize:
+   if (legacy_name)
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf, "%s);\n",
+                                  eina_strbuf_string_get(buf));
+     }
+   else
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf, "%s));\n",
+                                  eina_strbuf_string_get(buf));
+     }
    eina_strbuf_free(buf);
 
    return EINA_TRUE;
@@ -289,6 +409,7 @@ static Eina_Bool
 _content_set_generate(Gui_Session *session EINA_UNUSED, const Gui_Widget *wdg, 
const Gui_Widget_Property *prop, void *data)
 {
    Widget_Context *wdg_ctx = data;
+   Global_Gen_Context *gl_ctx = wdg_ctx->gl_ctx;
    const Op_Desc *op_desc;
    Gui_Value *gui_value;
    const Eina_List *itr;
@@ -309,8 +430,22 @@ _content_set_generate(Gui_Session *session EINA_UNUSED, 
const Gui_Widget *wdg, c
    const Eina_List *values_lst = prop_value_get(prop);
 
    Eina_Strbuf *buf = eina_strbuf_new();
-   eina_strbuf_append_printf(buf, "   eo_do(%s, %s(", wdg_name_get(wdg),
-                                      db_op_desc_func_name_get(op_desc));
+
+   const char *legacy_name = NULL;
+   if (gl_ctx->generate_legacy)
+     {
+        legacy_name = _legacy_name_find(wdg_class_name_get(wdg), op_desc);
+        if (!legacy_name) legacy_name = 
db_op_desc_func_legacy_name_get(op_desc);
+     }
+   if (legacy_name)
+     {
+        eina_strbuf_append_printf(buf, "   %s(%s, ", legacy_name, 
wdg_name_get(wdg));
+     }
+   else
+     {
+        eina_strbuf_append_printf(buf, "   eo_do(%s, %s(", wdg_name_get(wdg),
+              db_op_desc_func_name_get(op_desc));
+     }
 
    EINA_LIST_FOREACH(values_lst, itr, gui_value)
      {
@@ -322,8 +457,16 @@ _content_set_generate(Gui_Session *session EINA_UNUSED, 
const Gui_Widget *wdg, c
              return EINA_TRUE;
           }
      }
-   eina_strbuf_append_printf(wdg_ctx->buf, "%s));\n",
-         eina_strbuf_string_get(buf));
+   if (legacy_name)
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf, "%s);\n",
+                                  eina_strbuf_string_get(buf));
+     }
+   else
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf, "%s));\n",
+                                  eina_strbuf_string_get(buf));
+     }
    eina_strbuf_free(buf);
 
    return EINA_TRUE;
@@ -357,15 +500,25 @@ _item_iterate(Gui_Session *session, Widget_Context 
*wdg_ctx, const Gui_Widget *w
 
    /* Check if item is public or has subitems.
     * If TRUE, variable need to be declared and assigned. */
-   if (item_name)
+   const char *legacy_name = NULL;
+   if (gl_ctx->generate_legacy)
+     {
+        legacy_name = _legacy_name_find(wdg_class_name_get(wdg), op_desc);
+        if (!legacy_name) legacy_name = 
db_op_desc_func_legacy_name_get(op_desc);
+     }
+   if (legacy_name)
      {
-        eina_strbuf_append_printf(wdg_ctx->buf, "   eo_do(%s, %s = %s(",
-              wdg_name_get(wdg), item_name, db_op_desc_func_name_get(op_desc));
-        wdg_ctx->declarations = eina_list_append(wdg_ctx->declarations, 
wit_id);
+        eina_strbuf_append_printf(wdg_ctx->buf, "   %s%s%s(%s, ",
+              item_name?item_name:"", item_name?" = ":"",
+              legacy_name, wdg_name_get(wdg));
      }
    else
-        eina_strbuf_append_printf(wdg_ctx->buf, "   eo_do(%s, %s(",
-              wdg_name_get(wdg), db_op_desc_func_name_get(op_desc));
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf, "   eo_do(%s, %s%s%s(",
+              wdg_name_get(wdg), item_name?item_name:"", item_name?" = ":"",
+              db_op_desc_func_name_get(op_desc));
+     }
+   if (item_name) wdg_ctx->declarations = 
eina_list_append(wdg_ctx->declarations, wit_id);
 
    if (wdg_ctx->inside_cb)
      {
@@ -380,7 +533,14 @@ _item_iterate(Gui_Session *session, Widget_Context 
*wdg_ctx, const Gui_Widget *w
            eina_strbuf_append_printf(wdg_ctx->buf, ", ");
         _format_string_add(val, wdg_ctx->buf);
      }
-   eina_strbuf_append_printf(wdg_ctx->buf, "));\n");
+   if (legacy_name)
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf, ");\n");
+     }
+   else
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf, "));\n");
+     }
 
    /* We don't make a widget public if it is created inside a callback, cause 
we don't have any way to
     * store it and return it to the upper layer. */
@@ -436,6 +596,7 @@ static Eina_Bool
 _wdg_add_generate(Gui_Session *session, const Gui_Widget *wdg, void *data)
 {
    Widget_Context *wdg_ctx = data;
+   Global_Gen_Context *gl_ctx = wdg_ctx->gl_ctx;
 
    /* Add widget's name into the list of variable declarations. */
    wdg_ctx->declarations = eina_list_append(wdg_ctx->declarations, 
wdg_eid_get(wdg));
@@ -461,9 +622,18 @@ _wdg_add_generate(Gui_Session *session, const Gui_Widget 
*wdg, void *data)
    /* if there is no property "constructor", it means - using eo constr */
    if (!wdg_has_constructors(wdg))
      {
-        eina_strbuf_append_printf(wdg_ctx->buf, "   %s = eo_add(%s, %s);\n",
-              wdg_name_get(wdg), db_class_macro_get(class_id),
-              parent_id);
+        if (gl_ctx->generate_legacy)
+          {
+             eina_strbuf_append_printf(wdg_ctx->buf, "   %s = %s(%s);\n",
+                   wdg_name_get(wdg), db_class_legacy_add_get(class_id),
+                   parent_id);
+          }
+        else
+          {
+             eina_strbuf_append_printf(wdg_ctx->buf, "   %s = eo_add(%s, 
%s);\n",
+                   wdg_name_get(wdg), db_class_macro_get(class_id),
+                   parent_id);
+          }
      }
    else
      {
@@ -477,17 +647,21 @@ _wdg_add_generate(Gui_Session *session, const Gui_Widget 
*wdg, void *data)
              const Op_Desc *op_desc = prop_op_desc_get(prop);
              if (db_op_desc_is_constructor(op_desc))
                {
-                  eina_strbuf_append_printf(constr_buf, "%s(", 
db_op_desc_func_name_get(op_desc));
+                  if (!gl_ctx->generate_legacy)
+                     eina_strbuf_append_printf(constr_buf, "%s(", 
db_op_desc_func_name_get(op_desc));
 
                   const Eina_List *values_lst = prop_value_get(prop), *itr2;
                   Gui_Value *gui_value = NULL;
                   EINA_LIST_FOREACH(values_lst, itr2, gui_value)
                     {
                        if (values_lst != itr2)
-                         eina_strbuf_append_printf(constr_buf, ", ");
+                          eina_strbuf_append_printf(constr_buf, ", ");
                        _format_string_add(gui_value, constr_buf);
                     }
-                  eina_strbuf_append_printf(constr_buf, "),\n");
+                  if (!gl_ctx->generate_legacy)
+                     eina_strbuf_append_printf(constr_buf, "),\n");
+                  else
+                     eina_strbuf_append_printf(constr_buf, ", ");
                }
           }
         /* Remove ",\n" from the end */
@@ -496,9 +670,18 @@ _wdg_add_generate(Gui_Session *session, const Gui_Widget 
*wdg, void *data)
 
         char *str = eina_strbuf_string_steal(constr_buf);
 
-        eina_strbuf_append_printf(wdg_ctx->buf, "   %s = eo_add(%s, %s, 
%s);\n",
-              wdg_name_get(wdg), db_class_macro_get(class_id),
-              parent_id, str);
+        if (gl_ctx->generate_legacy)
+          {
+             eina_strbuf_append_printf(wdg_ctx->buf, "   %s = %s(%s, %s);\n",
+                   wdg_name_get(wdg), db_class_legacy_add_get(class_id),
+                   parent_id, str);
+          }
+        else
+          {
+             eina_strbuf_append_printf(wdg_ctx->buf, "   %s = eo_add(%s, %s, 
%s);\n",
+                   wdg_name_get(wdg), db_class_macro_get(class_id),
+                   parent_id, str);
+          }
 
         free(str);
         eina_strbuf_free(constr_buf);
@@ -543,25 +726,48 @@ _wdg_creation_function_generate(Gui_Session *session, 
Gui_Widget *wdg, Widget_Co
 
    if (!_pub_free_cb_created)
      {
-        eina_strbuf_prepend_printf(head,
-              "static Eina_Bool\n"
-              "_pubs_free_cb(void *data, Eo *obj EINA_UNUSED, const 
Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)\n"
-              "{\n"
-              "   free(data);\n"
-              "   return EINA_TRUE;\n"
-              "}\n\n");
+        if (gl_ctx->generate_legacy)
+          {
+             eina_strbuf_prepend_printf(head,
+                   "static void\n"
+                   "_pubs_free_cb(void *data, Evas *e EINA_UNUSED, Evas_Object 
*obj EINA_UNUSED, void *event_info EINA_UNUSED)\n"
+                   "{\n"
+                   "   free(data);\n"
+                   "}\n\n");
+          }
+        else
+          {
+             eina_strbuf_prepend_printf(head,
+                   "static Eina_Bool\n"
+                   "_pubs_free_cb(void *data, Eo *obj EINA_UNUSED, const 
Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)\n"
+                   "{\n"
+                   "   free(data);\n"
+                   "   return EINA_TRUE;\n"
+                   "}\n\n");
+          }
         _pub_free_cb_created = EINA_TRUE;
      }
 
-   eina_strbuf_append_printf(wdg_ctx->buf,
-         "   eo_do(%s, eo_event_callback_add(EO_BASE_EVENT_DEL, _pubs_free_cb, 
pub_widgets));",
-         wdg_name);
+   if (gl_ctx->generate_legacy)
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf,
+              "   evas_object_event_callback_add(%s, EVAS_CALLBACK_FREE, 
_pubs_free_cb, pub_widgets);",
+              wdg_name);
+     }
+   else
+     {
+        eina_strbuf_append_printf(wdg_ctx->buf,
+              "   eo_do(%s, eo_event_callback_add(EO_BASE_EVENT_DEL, 
_pubs_free_cb, pub_widgets));",
+              wdg_name);
+     }
 
    Eina_Iterator *iter = eina_hash_iterator_data_new(wdg_ctx->cbs_bufs_hash);
    Eina_Strbuf *cb_code_buf;
    EINA_ITERATOR_FOREACH(iter, cb_code_buf)
      {
-        eina_strbuf_prepend_printf(head, "%s   return EINA_TRUE;\n}\n\n", 
eina_strbuf_string_get(cb_code_buf));
+        eina_strbuf_prepend_printf(head, "%s%s}\n\n",
+              eina_strbuf_string_get(cb_code_buf),
+              !gl_ctx->generate_legacy ? "   return EINA_TRUE;\n" : "");
         eina_strbuf_free(cb_code_buf);
      }
    eina_iterator_free(iter);
@@ -579,7 +785,8 @@ _wdg_creation_function_generate(Gui_Session *session, 
Gui_Widget *wdg, Widget_Co
            case EID_TYPE_WIDGET:
                 {
                    Gui_Widget *w = wdg_get(eid);
-                   if (w) eina_strbuf_append_printf(head, "   Eo *%s;\n", 
wdg_name_get(w));
+                   if (w) eina_strbuf_append_printf(head, "   %s *%s;\n",
+                         gl_ctx->generate_legacy?"Evas_Object":"Eo", 
wdg_name_get(w));
                    break;
                 }
            case EID_TYPE_ITEM:
@@ -659,19 +866,40 @@ _wdg_cb_add_generate(Gui_Session *session, const 
Gui_Widget *wdg, const Gui_Widg
 
    if (!_wdg_cb_type_foo)
      {
-        char *event_name = 
_c_plugin_eo_event_name_get(wdg_class_name_get(wdg), cb_type);
-        if (!event_name) goto end;
-        eina_strbuf_append_printf(wdg_ctx->buf, "   eo_do(%s, 
eo_event_callback_add(%s, %s, NULL));\n",
-              wdg_name_get(wdg), event_name, _wdg_cb_type_str);
-        free(event_name);
+        if (gl_ctx->generate_legacy)
+          {
+             eina_strbuf_append_printf(wdg_ctx->buf,
+                   "   evas_object_smart_callback_add(%s, \"%s\", %s, 
NULL);\n",
+                   wdg_name_get(wdg), cb_type, _wdg_cb_type_str);
+          }
+        else
+          {
+             char *event_name = 
_c_plugin_eo_event_name_get(wdg_class_name_get(wdg), cb_type);
+             if (!event_name) goto end;
+             eina_strbuf_append_printf(wdg_ctx->buf, "   eo_do(%s, 
eo_event_callback_add(%s, %s, NULL));\n",
+                   wdg_name_get(wdg), event_name, _wdg_cb_type_str);
+             free(event_name);
+          }
 
         _wdg_cb_type_foo = eina_strbuf_new();
-        eina_strbuf_append_printf(_wdg_cb_type_foo,
-              "static Eina_Bool\n"
-              "%s(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const 
Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)\n"
-              "{\n",
-              _wdg_cb_type_str
-              );
+        if (gl_ctx->generate_legacy)
+          {
+             eina_strbuf_append_printf(_wdg_cb_type_foo,
+                   "static void\n"
+                   "%s(void *data EINA_UNUSED, Evas *obj EINA_UNUSED, void 
*event_info EINA_UNUSED)\n"
+                   "{\n",
+                   _wdg_cb_type_str
+                   );
+          }
+        else
+          {
+             eina_strbuf_append_printf(_wdg_cb_type_foo,
+                   "static Eina_Bool\n"
+                   "%s(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const 
Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)\n"
+                   "{\n",
+                   _wdg_cb_type_str
+                   );
+          }
         eina_hash_add(wdg_ctx->cbs_bufs_hash, _wdg_cb_type_str, 
_wdg_cb_type_foo);
      }
 
@@ -733,7 +961,8 @@ _wdg_cb_add_generate(Gui_Session *session, const Gui_Widget 
*wdg, const Gui_Widg
                                 case EID_TYPE_WIDGET:
                                      {
                                         Gui_Widget *w = wdg_get(eid);
-                                        if (w) 
eina_strbuf_append_printf(_wdg_cb_type_foo, "   Eo *%s;\n", wdg_name_get(w));
+                                        if (w) 
eina_strbuf_append_printf(_wdg_cb_type_foo, "   %s *%s;\n",
+                                              
gl_ctx->generate_legacy?"Evas_Object":"Eo", wdg_name_get(w));
                                         break;
                                      }
                                 case EID_TYPE_ITEM:
@@ -760,9 +989,18 @@ _wdg_cb_add_generate(Gui_Session *session, const 
Gui_Widget *wdg, const Gui_Widg
                    const char *cb_name = resource_value_get(res);
                    if (cb_name)
                      {
-                        eina_strbuf_append_printf(_wdg_cb_type_foo,
-                              "   %s(data, obj, desc, event_info);\n",
-                              cb_name);
+                        if (gl_ctx->generate_legacy)
+                          {
+                             eina_strbuf_append_printf(_wdg_cb_type_foo,
+                                   "   %s(data, obj, event_info);\n",
+                                   cb_name);
+                          }
+                        else
+                          {
+                             eina_strbuf_append_printf(_wdg_cb_type_foo,
+                                   "   %s(data, obj, desc, event_info);\n",
+                                   cb_name);
+                          }
                      }
                    break;
                 }
@@ -846,9 +1084,20 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
                {
                   const Gui_Resource *res = resource_get_from_id(eid);
                   if (res)
-                     eina_strbuf_append_printf(resources_buf,
-                           "extern Eina_Bool\n%s(void *data, Eo *obj, const 
Eo_Event_Description *desc, void *event_info);\n",
-                           resource_value_get(res));
+                    {
+                       if (gl_ctx->generate_legacy)
+                         {
+                            eina_strbuf_append_printf(resources_buf,
+                                  "extern void\n%s(void *data, Eo *obj, void 
*event_info);\n",
+                                  resource_value_get(res));
+                         }
+                       else
+                         {
+                            eina_strbuf_append_printf(resources_buf,
+                                  "extern Eina_Bool\n%s(void *data, Eo *obj, 
const Eo_Event_Description *desc, void *event_info);\n",
+                                  resource_value_get(res));
+                         }
+                    }
                }
           }
         eina_strbuf_append_printf(resources_buf, "\n");
@@ -878,15 +1127,24 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
           }
      }
 
-   eina_strbuf_append_printf(gl_ctx->c_buf,
-         "#ifndef EFL_BETA_API_SUPPORT\n#define EFL_BETA_API_SUPPORT\n#endif\n"
-         "#ifndef EFL_EO_API_SUPPORT\n#define EFL_EO_API_SUPPORT\n#endif\n"
-         "#ifndef ELM_INTERNAL_API_ARGESFSDFEFC\n#define 
ELM_INTERNAL_API_ARGESFSDFEFC\n#endif\n"
-         "#include <Elementary.h>\n"
-         "#include \"elm_widget_container.h\"\n"
-         "#include \"elm_interface_scrollable.h\"\n"
-         "#include \"elm_interface_fileselector.h\"\n"
-         "#include \"%s\"\n\n", gui_context_export_h_filename_get(ctx));
+   if (gl_ctx->generate_legacy)
+     {
+        eina_strbuf_append_printf(gl_ctx->c_buf,
+              "#include <Elementary.h>\n"
+              "#include \"%s\"\n\n", gui_context_export_h_filename_get(ctx));
+     }
+   else
+     {
+        eina_strbuf_append_printf(gl_ctx->c_buf,
+              "#ifndef EFL_BETA_API_SUPPORT\n#define 
EFL_BETA_API_SUPPORT\n#endif\n"
+              "#ifndef EFL_EO_API_SUPPORT\n#define 
EFL_EO_API_SUPPORT\n#endif\n"
+              "#ifndef ELM_INTERNAL_API_ARGESFSDFEFC\n#define 
ELM_INTERNAL_API_ARGESFSDFEFC\n#endif\n"
+              "#include <Elementary.h>\n"
+              "#include \"elm_widget_container.h\"\n"
+              "#include \"elm_interface_scrollable.h\"\n"
+              "#include \"elm_interface_fileselector.h\"\n"
+              "#include \"%s\"\n\n", gui_context_export_h_filename_get(ctx));
+     }
 
    if (gui_context_start_points_get(ctx))
      {
@@ -965,9 +1223,8 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
    free(h_macro);
    h_macro = NULL;
 
-   eina_strbuf_append_printf(gl_ctx->h_buf,
-         "#include <Eo.h>\n"
-         "#include <Elementary.h>\n\n");
+   if (!gl_ctx->generate_legacy) eina_strbuf_append_printf(gl_ctx->h_buf, 
"#include <Eo.h>\n");
+   eina_strbuf_append_printf(gl_ctx->h_buf, "#include <Elementary.h>\n\n");
 
    EINA_LIST_FOREACH((const Eina_List *)wdg_ctxs, itr, wdg_ctx)
      {
@@ -1022,7 +1279,7 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
 
 /* Save context into "project" files. */
 static void
-_ctx_to_file_save(const Gui_Context *ctx, Generator_Export_Format format)
+_ctx_to_file_save(const Gui_Context *ctx, Generator_Export_Format format, 
Eina_Bool generate_legacy)
 {
    Eina_Strbuf *filename = NULL;
    FILE *fp = NULL;
@@ -1030,6 +1287,7 @@ _ctx_to_file_save(const Gui_Context *ctx, 
Generator_Export_Format format)
    /* Define global generator context */
    Global_Gen_Context gl_gen_ctx;
    gl_gen_ctx.ctx = ctx;
+   gl_gen_ctx.generate_legacy = generate_legacy;
    gl_gen_ctx.c_buf = eina_strbuf_new();
    gl_gen_ctx.h_buf = eina_strbuf_new();
    gl_gen_ctx.global_entities = NULL;
@@ -1091,7 +1349,7 @@ end:
 }
 
 void
-generator_ctx_source_generate(const Gui_Context *ctx, Generator_Export_Format 
format)
+generator_ctx_source_generate(const Gui_Context *ctx, Generator_Export_Format 
format, Eina_Bool generate_legacy)
 {
    if (format == GENERATE_JSON)
      {
@@ -1106,6 +1364,6 @@ generator_ctx_source_generate(const Gui_Context *ctx, 
Generator_Export_Format fo
    funcs->item_add = _item_add_generate;
 
    _pub_free_cb_created = EINA_FALSE;
-   _ctx_to_file_save(ctx, format);
+   _ctx_to_file_save(ctx, format, generate_legacy);
 }
 
diff --git a/src/lib/generator.h b/src/lib/generator.h
index 00a45e9..ce02b1d 100644
--- a/src/lib/generator.h
+++ b/src/lib/generator.h
@@ -13,6 +13,6 @@ typedef enum
 
 /* Generate sources for context*/
 void
-generator_ctx_source_generate(const Gui_Context *ctx, Generator_Export_Format 
format);
+generator_ctx_source_generate(const Gui_Context *ctx, Generator_Export_Format 
format, Eina_Bool generate_legacy);
 
 #endif

-- 


Reply via email to