summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-09-19 17:36:48 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 11:54:23 +0200
commit12c3bdee3e4fd046f3c2c5b8a8361d1975277215 (patch)
tree74da0e1765c6e8b287edc1f7fc62e3ef7ec15c9e
parentaf7cc32343293f3ae5f4aa1102ad781e40413dbe (diff)
eolian gen2: initial header generation
-rw-r--r--src/Makefile_Eolian.am4
-rw-r--r--src/bin/eolian2/headers.c134
-rw-r--r--src/bin/eolian2/headers.h8
-rw-r--r--src/bin/eolian2/main.c42
4 files changed, 182 insertions, 6 deletions
diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am
index 654194a3a3..af99b08447 100644
--- a/src/Makefile_Eolian.am
+++ b/src/Makefile_Eolian.am
@@ -75,7 +75,9 @@ bin_eolian2_eolian_gen2_SOURCES = \
75 bin/eolian2/main.c \ 75 bin/eolian2/main.c \
76 bin/eolian2/main.h \ 76 bin/eolian2/main.h \
77 bin/eolian2/types.c \ 77 bin/eolian2/types.c \
78 bin/eolian2/types.h 78 bin/eolian2/types.h \
79 bin/eolian2/headers.c \
80 bin/eolian2/headers.h
79 81
80bin_eolian2_eolian_gen2_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EOLIAN_CFLAGS@ 82bin_eolian2_eolian_gen2_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EOLIAN_CFLAGS@
81bin_eolian2_eolian_gen2_LDADD = @USE_EOLIAN_LIBS@ 83bin_eolian2_eolian_gen2_LDADD = @USE_EOLIAN_LIBS@
diff --git a/src/bin/eolian2/headers.c b/src/bin/eolian2/headers.c
new file mode 100644
index 0000000000..cfa4a1e50b
--- /dev/null
+++ b/src/bin/eolian2/headers.c
@@ -0,0 +1,134 @@
1#include "main.h"
2
3const char *
4_cl_type_str_get(const Eolian_Class *cl, Eina_Bool uc)
5{
6 switch (eolian_class_type_get(cl))
7 {
8 case EOLIAN_CLASS_REGULAR:
9 case EOLIAN_CLASS_ABSTRACT:
10 return uc ? "CLASS" : "class";
11 case EOLIAN_CLASS_MIXIN:
12 return uc ? "MIXIN" : "mixin";
13 case EOLIAN_CLASS_INTERFACE:
14 return uc ? "INTERFACE" : "interface";
15 default:
16 return NULL;
17 }
18}
19
20static void
21_gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
22 Eolian_Function_Type ftype, Eina_Strbuf *buf)
23{
24}
25
26void
27eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy)
28{
29 if (!cl)
30 return;
31
32 char *cname = NULL, *cnameu = NULL, *cnamel = NULL;
33
34 cname = eo_gen_c_full_name_get(eolian_class_full_name_get(cl));
35 if (!cname)
36 goto end;
37
38 cnameu = strdup(cname);
39 if (!cnameu)
40 goto end;
41 eina_str_toupper(&cnameu);
42
43 cnamel = strdup(cname);
44 if (!cnamel)
45 goto end;
46 eina_str_tolower(&cnamel);
47
48 /* class definition */
49
50 eina_strbuf_append_printf(buf, "#define %s_%s %s_%s_get()\n\n",
51 cnameu, _cl_type_str_get(cl, EINA_TRUE),
52 cnamel, _cl_type_str_get(cl, EINA_FALSE));
53
54 eina_strbuf_append_printf(buf, "EWAPI const Efl_Class *%s_%s_get(void);\n\n",
55 cnamel, _cl_type_str_get(cl, EINA_FALSE));
56
57 /* method section */
58 {
59 Eina_Iterator *itr = eolian_class_implements_get(cl);
60 if (!itr)
61 goto events;
62
63 const Eolian_Implement *imp;
64 EINA_ITERATOR_FOREACH(itr, imp)
65 {
66 if (eolian_implement_class_get(imp) != cl)
67 continue;
68 Eolian_Function_Type ftype = EOLIAN_UNRESOLVED;
69 const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype);
70 switch (ftype)
71 {
72 case EOLIAN_PROP_GET:
73 case EOLIAN_PROP_SET:
74 _gen_func(cl, fid, ftype, buf);
75 break;
76 case EOLIAN_PROPERTY:
77 _gen_func(cl, fid, EOLIAN_PROP_SET, buf);
78 _gen_func(cl, fid, EOLIAN_PROP_GET, buf);
79 break;
80 default:
81 _gen_func(cl, fid, EOLIAN_UNRESOLVED, buf);
82 }
83 }
84 eina_iterator_free(itr);
85 }
86
87events:
88 /* event section */
89 {
90 Eina_Iterator *itr = eolian_class_events_get(cl);
91 Eolian_Event *ev;
92 EINA_ITERATOR_FOREACH(itr, ev)
93 {
94 Eina_Stringshare *evn = eolian_event_c_name_get(ev);
95 Eolian_Object_Scope evs = eolian_event_scope_get(ev);
96
97 if (evs == EOLIAN_SCOPE_PRIVATE)
98 continue;
99
100 if (eolian_event_is_beta(ev))
101 {
102 eina_strbuf_append_printf(buf, "\n#ifndef %s_BETA\n", cnameu);
103 eina_strbuf_append_printf(buf, "#define %s_BETA\n", cnameu);
104 }
105 if (evs == EOLIAN_SCOPE_PROTECTED)
106 {
107 if (!eolian_event_is_beta(ev))
108 eina_strbuf_append_char(buf, '\n');
109 eina_strbuf_append_printf(buf, "#ifndef %s_PROTECTED\n", cnameu);
110 eina_strbuf_append_printf(buf, "#define %s_PROTECTED\n", cnameu);
111 }
112
113 if (!eolian_event_is_beta(ev) && evs == EOLIAN_SCOPE_PUBLIC)
114 eina_strbuf_append_char(buf, '\n');
115
116 eina_strbuf_append_printf(buf, "EOAPI extern const "
117 "Efl_Event_Description _%s;\n", evn);
118 eina_strbuf_append_printf(buf, "#define %s (&(_%s))\n", evn, evn);
119
120 if (evs == EOLIAN_SCOPE_PROTECTED)
121 eina_strbuf_append(buf, "#endif\n");
122 if (eolian_event_is_beta(ev))
123 eina_strbuf_append(buf, "#endif\n");
124
125 eina_stringshare_del(evn);
126 }
127 eina_iterator_free(itr);
128 }
129
130end:
131 free(cname);
132 free(cnameu);
133 free(cnamel);
134}
diff --git a/src/bin/eolian2/headers.h b/src/bin/eolian2/headers.h
new file mode 100644
index 0000000000..55b4c071b0
--- /dev/null
+++ b/src/bin/eolian2/headers.h
@@ -0,0 +1,8 @@
1#ifndef EOLIAN_GEN_HEADERS_H
2#define EOLIAN_GEN_HEADERS_H
3
4#include "main.h"
5
6void eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy);
7
8#endif
diff --git a/src/bin/eolian2/main.c b/src/bin/eolian2/main.c
index 731f1b1f52..fb0773c649 100644
--- a/src/bin/eolian2/main.c
+++ b/src/bin/eolian2/main.c
@@ -7,6 +7,7 @@
7 7
8#include "main.h" 8#include "main.h"
9#include "types.h" 9#include "types.h"
10#include "headers.h"
10 11
11int _eolian_gen_log_dom = -1; 12int _eolian_gen_log_dom = -1;
12 13
@@ -133,6 +134,27 @@ _include_guard(const char *fname, const char *gname, Eina_Strbuf *buf)
133 return g; 134 return g;
134} 135}
135 136
137static const char *
138_get_filename(const char *path)
139{
140 if (!path)
141 return NULL;
142 const char *ret1 = strrchr(path, '/');
143 const char *ret2 = strrchr(path, '\\');
144 if (!ret1 && !ret2)
145 return path;
146 if (ret1 && ret2)
147 {
148 if (ret1 > ret2)
149 return ret1 + 1;
150 else
151 return ret2 + 1;
152 }
153 if (ret1)
154 return ret1 + 1;
155 return ret2 + 1;
156}
157
136static Eina_Bool 158static Eina_Bool
137_write_file(const char *fname, const Eina_Strbuf *buf, Eina_Bool append) 159_write_file(const char *fname, const Eina_Strbuf *buf, Eina_Bool append)
138{ 160{
@@ -232,9 +254,19 @@ _write_header(const char *ofname, const char *ifname, Eina_Bool legacy)
232 eina_strbuf_free(cltd); 254 eina_strbuf_free(cltd);
233 } 255 }
234 256
235 Eina_Bool ret = _write_file(ofname, buf, EINA_FALSE); 257 const Eolian_Class *cl = eolian_class_get_by_file(ifname);
236 eina_strbuf_free(buf); 258 eo_gen_header_gen(cl, buf, legacy);
237 return ret; 259 if (cl || !legacy)
260 {
261 buf = _include_guard(_get_filename(ofname), NULL, buf);
262 if (_write_file(ofname, buf, EINA_FALSE))
263 {
264 eina_strbuf_free(buf);
265 return EINA_TRUE;
266 }
267 }
268
269 return EINA_FALSE;
238} 270}
239 271
240static Eina_Bool 272static Eina_Bool
@@ -391,9 +423,9 @@ main(int argc, char **argv)
391 char *inoext = strdup(input); 423 char *inoext = strdup(input);
392 inoext[ext - input] = '\0'; 424 inoext[ext - input] = '\0';
393 _fill_all_outs(outs, inoext); 425 _fill_all_outs(outs, inoext);
426 free(inoext);
394 427
395 inoext[ext - input] = '.'; 428 const char *eobn = _get_filename(input);
396 char *eobn = basename(inoext);
397 429
398 if (!gen_what) 430 if (!gen_what)
399 gen_what = GEN_H | GEN_H_LEGACY | GEN_C; 431 gen_what = GEN_H | GEN_H_LEGACY | GEN_C;