summaryrefslogtreecommitdiff
path: root/src/bin/eolian/headers.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 13:34:47 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 13:34:47 +0200
commit9553fd96401e2391ddc3143a64ea9d629c73fb37 (patch)
tree84a3c761a431c85693d0f8afcfeb10d14e98bd82 /src/bin/eolian/headers.c
parent4cc17ae28a960b8b009a0063fa34d74f9c8a006b (diff)
eolian gen2: move to eolian gen (as the old one is gone)devs/q66/eolian_gen_next
Diffstat (limited to 'src/bin/eolian/headers.c')
-rw-r--r--src/bin/eolian/headers.c314
1 files changed, 314 insertions, 0 deletions
diff --git a/src/bin/eolian/headers.c b/src/bin/eolian/headers.c
new file mode 100644
index 0000000..63ec73a
--- /dev/null
+++ b/src/bin/eolian/headers.c
@@ -0,0 +1,314 @@
1#include "main.h"
2#include "docs.h"
3
4static const char *
5_cl_type_str_get(const Eolian_Class *cl, Eina_Bool uc)
6{
7 switch (eolian_class_type_get(cl))
8 {
9 case EOLIAN_CLASS_REGULAR:
10 case EOLIAN_CLASS_ABSTRACT:
11 return uc ? "CLASS" : "class";
12 case EOLIAN_CLASS_MIXIN:
13 return uc ? "MIXIN" : "mixin";
14 case EOLIAN_CLASS_INTERFACE:
15 return uc ? "INTERFACE" : "interface";
16 default:
17 return NULL;
18 }
19}
20
21static const char *
22_get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir)
23{
24 if (ftype == EOLIAN_PROP_GET)
25 return "*";
26 if ((pdir == EOLIAN_OUT_PARAM) || (pdir == EOLIAN_INOUT_PARAM))
27 return "*";
28 return "";
29}
30
31static void
32_gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
33 Eina_Strbuf *buf, char *cname, char *cnameu, Eina_Bool legacy)
34{
35 Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, ftype, legacy);
36 if (!fcn)
37 return;
38
39 Eina_Bool var_as_ret = EINA_FALSE;
40 const Eolian_Type *rtp = eolian_function_return_type_get(fid, ftype);
41 if (ftype == EOLIAN_PROP_GET && !rtp)
42 {
43 void *d1, *d2;
44 Eina_Iterator *itr = eolian_property_values_get(fid, ftype);
45 if (eina_iterator_next(itr, &d1) && !eina_iterator_next(itr, &d2))
46 {
47 rtp = eolian_parameter_type_get((Eolian_Function_Parameter *)d1);
48 var_as_ret = EINA_TRUE;
49 }
50 eina_iterator_free(itr);
51 }
52
53 Eolian_Object_Scope fsc = eolian_function_scope_get(fid, ftype);
54
55 /* this one will never be satisfied in legacy */
56 if (eolian_function_is_beta(fid))
57 eina_strbuf_append_printf(buf, "#ifdef %s_BETA\n", cnameu);
58 /* XXX: is this right? we expose potentially internal stuff into legacy */
59 if (!legacy && (fsc == EOLIAN_SCOPE_PROTECTED))
60 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);
61
62 Eina_Bool hasdoc = eolian_function_documentation_get(fid, EOLIAN_UNRESOLVED) ||
63 eolian_function_documentation_get(fid, ftype);
64 if (hasdoc)
65 {
66 Eina_Strbuf *dbuf = eo_gen_docs_func_gen(fid, ftype, 0, legacy);
67 eina_strbuf_append(buf, eina_strbuf_string_get(dbuf));
68 eina_strbuf_append_char(buf, '\n');
69 eina_strbuf_free(dbuf);
70 }
71 eina_strbuf_append(buf, legacy ? "EAPI " : "EOAPI ");
72 if (rtp)
73 {
74 Eina_Stringshare *rtps = eolian_type_c_type_get(rtp);
75 eina_strbuf_append(buf, rtps);
76 if (rtps[strlen(rtps) - 1] != '*')
77 eina_strbuf_append_char(buf, ' ');
78 eina_stringshare_del(rtps);
79 }
80 else
81 eina_strbuf_append(buf, "void ");
82
83 eina_strbuf_append(buf, fcn);
84 eina_stringshare_del(fcn);
85
86 Eina_Bool first = EINA_TRUE;
87 Eina_Strbuf *flagbuf = NULL;
88 int nidx = !legacy || !eolian_function_is_class(fid);
89
90 eina_strbuf_append_char(buf, '(');
91 if (nidx)
92 {
93 if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)
94 || eolian_function_is_class(fid))
95 {
96 eina_strbuf_append(buf, "const ");
97 }
98 if (legacy)
99 eina_strbuf_append_printf(buf, "%s *obj", cname);
100 else
101 eina_strbuf_append(buf, "Eo *obj");
102 first = EINA_FALSE;
103 }
104
105 {
106 Eolian_Function_Parameter *pr = NULL;
107 Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
108 EINA_ITERATOR_FOREACH(itr, pr)
109 {
110 const Eolian_Type *prt = eolian_parameter_type_get(pr);
111 const char *prn = eolian_parameter_name_get(pr);
112 Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
113 ++nidx;
114 if (!first)
115 eina_strbuf_append(buf, ", ");
116 eina_strbuf_append_printf(buf, "%s %s", prtn, prn);
117 eina_stringshare_del(prtn);
118 first = EINA_FALSE;
119 if (!eolian_parameter_is_nonull(pr))
120 continue;
121 if (!flagbuf)
122 {
123 flagbuf = eina_strbuf_new();
124 eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
125 }
126 else
127 eina_strbuf_append_printf(flagbuf, ", %d", nidx);
128 }
129 eina_iterator_free(itr);
130 }
131
132 if (!var_as_ret)
133 {
134 Eina_Iterator *itr = NULL;
135 if (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET)
136 itr = eolian_property_values_get(fid, ftype);
137 else
138 itr = eolian_function_parameters_get(fid);
139
140 Eolian_Function_Parameter *pr = NULL;
141 EINA_ITERATOR_FOREACH(itr, pr)
142 {
143 const Eolian_Type *prt = eolian_parameter_type_get(pr);
144 const char *prn = eolian_parameter_name_get(pr);
145 Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
146
147 ++nidx;
148 if (!first)
149 eina_strbuf_append(buf, ", ");
150 eina_strbuf_append(buf, prtn);
151 if (!strchr(prtn, '*'))
152 eina_strbuf_append_char(buf, ' ');
153 eina_strbuf_append(buf,
154 _get_add_star(ftype, eolian_parameter_direction_get(pr)));
155 eina_strbuf_append(buf, prn);
156 eina_stringshare_del(prtn);
157 first = EINA_FALSE;
158 if (!eolian_parameter_is_nonull(pr))
159 continue;
160 if (!flagbuf)
161 {
162 flagbuf = eina_strbuf_new();
163 eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
164 }
165 else
166 eina_strbuf_append_printf(flagbuf, ", %d", nidx);
167 }
168
169 eina_iterator_free(itr);
170 }
171
172 if (flagbuf)
173 eina_strbuf_append_char(flagbuf, ')');
174
175 eina_strbuf_append(buf, ")");
176 if (eolian_function_return_is_warn_unused(fid, ftype))
177 {
178 if (!flagbuf)
179 flagbuf = eina_strbuf_new();
180 eina_strbuf_prepend(flagbuf, " EINA_WARN_UNUSED_RESULT");
181 }
182 if (flagbuf)
183 {
184 eina_strbuf_append(buf, eina_strbuf_string_get(flagbuf));
185 eina_strbuf_free(flagbuf);
186 }
187 eina_strbuf_append(buf, ";\n");
188
189 if (eolian_function_is_beta(fid))
190 eina_strbuf_append_printf(buf, "#endif\n");
191 if (!legacy && (fsc == EOLIAN_SCOPE_PROTECTED))
192 eina_strbuf_append_printf(buf, "#endif\n");
193}
194
195void
196eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy)
197{
198 if (!cl)
199 return;
200
201 char *cname = NULL, *cnameu = NULL, *cnamel = NULL;
202 eo_gen_class_names_get(cl, &cname, &cnameu, &cnamel);
203
204 /* class definition */
205
206 if (!legacy)
207 {
208 const Eolian_Documentation *doc = eolian_class_documentation_get(cl);
209 if (doc)
210 {
211 Eina_Strbuf *cdoc = eo_gen_docs_full_gen(doc,
212 eolian_class_full_name_get(cl), 0, EINA_FALSE);
213 if (cdoc)
214 {
215 eina_strbuf_append(buf, eina_strbuf_string_get(cdoc));
216 eina_strbuf_append_char(buf, '\n');
217 eina_strbuf_free(cdoc);
218 }
219 }
220 eina_strbuf_append_printf(buf, "#define %s_%s %s_%s_get()\n\n",
221 cnameu, _cl_type_str_get(cl, EINA_TRUE),
222 cnamel, _cl_type_str_get(cl, EINA_FALSE));
223
224 eina_strbuf_append_printf(buf, "EWAPI const Efl_Class *%s_%s_get(void);\n",
225 cnamel, _cl_type_str_get(cl, EINA_FALSE));
226 }
227
228 /* method section */
229 {
230 Eina_Iterator *itr = eolian_class_implements_get(cl);
231 if (!itr)
232 goto events;
233
234 const Eolian_Implement *imp;
235 EINA_ITERATOR_FOREACH(itr, imp)
236 {
237 if (eolian_implement_class_get(imp) != cl)
238 continue;
239 Eolian_Function_Type ftype = EOLIAN_UNRESOLVED;
240 const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype);
241 /* beta can only exist for eo api */
242 if (legacy && eolian_function_is_beta(fid))
243 continue;
244 eina_strbuf_append_char(buf, '\n');
245 switch (ftype)
246 {
247 case EOLIAN_PROP_GET:
248 case EOLIAN_PROP_SET:
249 _gen_func(fid, ftype, buf, cname, cnameu, legacy);
250 break;
251 case EOLIAN_PROPERTY:
252 _gen_func(fid, EOLIAN_PROP_SET, buf, cname, cnameu, legacy);
253 eina_strbuf_append_char(buf, '\n');
254 _gen_func(fid, EOLIAN_PROP_GET, buf, cname, cnameu, legacy);
255 break;
256 default:
257 _gen_func(fid, EOLIAN_UNRESOLVED, buf, cname, cnameu, legacy);
258 }
259 }
260 eina_iterator_free(itr);
261 }
262
263events:
264 /* event section */
265 if (!legacy)
266 {
267 Eina_Iterator *itr = eolian_class_events_get(cl);
268 Eolian_Event *ev;
269 EINA_ITERATOR_FOREACH(itr, ev)
270 {
271 Eina_Stringshare *evn = eolian_event_c_name_get(ev);
272 Eolian_Object_Scope evs = eolian_event_scope_get(ev);
273
274 if (evs == EOLIAN_SCOPE_PRIVATE)
275 continue;
276
277 if (eolian_event_is_beta(ev))
278 {
279 eina_strbuf_append_printf(buf, "\n#ifdef %s_BETA\n", cnameu);
280 }
281 if (evs == EOLIAN_SCOPE_PROTECTED)
282 {
283 if (!eolian_event_is_beta(ev))
284 eina_strbuf_append_char(buf, '\n');
285 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);
286 }
287
288 if (!eolian_event_is_beta(ev) && evs == EOLIAN_SCOPE_PUBLIC)
289 eina_strbuf_append_char(buf, '\n');
290
291 eina_strbuf_append_printf(buf, "EOAPI extern const "
292 "Efl_Event_Description _%s;\n\n", evn);
293
294 Eina_Strbuf *evdbuf = eo_gen_docs_event_gen(ev,
295 eolian_class_full_name_get(cl));
296 eina_strbuf_append(buf, eina_strbuf_string_get(evdbuf));
297 eina_strbuf_append_char(buf, '\n');
298 eina_strbuf_free(evdbuf);
299 eina_strbuf_append_printf(buf, "#define %s (&(_%s))\n", evn, evn);
300
301 if (evs == EOLIAN_SCOPE_PROTECTED)
302 eina_strbuf_append(buf, "#endif\n");
303 if (eolian_event_is_beta(ev))
304 eina_strbuf_append(buf, "#endif\n");
305
306 eina_stringshare_del(evn);
307 }
308 eina_iterator_free(itr);
309 }
310
311 free(cname);
312 free(cnameu);
313 free(cnamel);
314}