summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-05 16:32:17 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 11:54:23 +0200
commit9cc0ca20f4fc2f95bceda1168181f424c5240c4a (patch)
tree49d5533c98454453a72a780172da955d17e82681
parentbc9422cf0fa39b39c17a13284b461fd5c8b66ac6 (diff)
eolian gen2: some initial impl generation
-rw-r--r--src/bin/eolian2/sources.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/bin/eolian2/sources.c b/src/bin/eolian2/sources.c
index f05a741b68..7ce03e0eb0 100644
--- a/src/bin/eolian2/sources.c
+++ b/src/bin/eolian2/sources.c
@@ -48,6 +48,56 @@ _get_data_type(const Eolian_Class *cl)
48 return dtr; 48 return dtr;
49} 49}
50 50
51static Eina_Bool
52_function_exists(const char *fname, Eina_Strbuf *buf)
53{
54 const char *ptr = eina_strbuf_string_get(buf);
55 size_t flen = strlen(fname);
56 while ((ptr = strstr(ptr, fname)) != NULL)
57 {
58 switch (*(ptr - 1))
59 {
60 case '\n':
61 case ' ':
62 switch (*(ptr + flen))
63 {
64 case ' ':
65 case '(':
66 return EINA_TRUE;
67 }
68 }
69 ++ptr;
70 }
71 return EINA_FALSE;
72}
73
74/* Check if the type is used in the file, not if it is a typedef... */
75static Eina_Bool
76_type_exists(const char *tname, Eina_Strbuf *buf)
77{
78 const char *ptr = eina_strbuf_string_get(buf);
79 size_t tlen = strlen(tname);
80 while ((ptr = strstr(ptr, tname)) != NULL)
81 {
82 switch (*(ptr - 1))
83 {
84 case '\n':
85 case ' ':
86 case ',':
87 switch (*(ptr + tlen))
88 {
89 case '\n':
90 case ' ':
91 case ',':
92 case ';':
93 return EINA_TRUE;
94 }
95 }
96 ++ptr;
97 }
98 return EINA_FALSE;
99}
100
51static void 101static void
52_gen_func(const Eolian_Class *cl, const Eolian_Function *fid, 102_gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
53 Eolian_Function_Type ftype, Eina_Strbuf *buf, 103 Eolian_Function_Type ftype, Eina_Strbuf *buf,
@@ -768,4 +818,49 @@ eo_gen_impl_gen(const Eolian_Class *cl, Eina_Strbuf *buf)
768{ 818{
769 if (!cl) 819 if (!cl)
770 return; 820 return;
821
822 char *cname = NULL, *cnameu = NULL, *cnamel = NULL;
823 eo_gen_class_names_get(cl, &cname, &cnameu, &cnamel);
824
825 Eina_Strbuf *beg = eina_strbuf_new();
826
827 if (!_type_exists("EFL_BETA_API_SUPPORT", buf))
828 {
829 printf("generating EFL_BETA_API_SUPPORT...\n");
830 eina_strbuf_append(beg, "#define EFL_BETA_API_SUPPORT\n");
831 }
832
833 if (!_type_exists("<Eo.h>", buf))
834 {
835 printf("generating includes for <Eo.h> and \"%s.eo.h\"...\n", cnamel);
836 eina_strbuf_append(beg, "#include <Eo.h>\n");
837 eina_strbuf_append_printf(beg, "#include \"%s.eo.h\"\n\n", cnamel);
838 }
839
840 /* determine data type name */
841 char *dt = _get_data_type(cl);
842 char adt[128];
843 if (dt && !strcmp(dt, "null"))
844 adt[0] = '\0';
845 else if (dt)
846 snprintf(adt, sizeof(adt), "%s", dt);
847 else
848 snprintf(adt, sizeof(adt), "%s_Data", cname);
849 free(dt);
850
851 /* generate data type struct */
852 if (adt[0] && !_type_exists(adt, buf))
853 {
854 printf("generating data type structure %s...\n", adt);
855 eina_strbuf_append_printf(beg, "typedef struct\n{\n} %s;\n\n", adt);
856 }
857
858 if (eina_strbuf_length_get(beg))
859 eina_strbuf_prepend(buf, eina_strbuf_string_get(beg));
860
861 eina_strbuf_free(beg);
862
863 free(cname);
864 free(cnameu);
865 free(cnamel);
771} 866}