summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-09-20 15:50:37 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 11:54:23 +0200
commitec1bb92a8fb3f39ace4210ad1a8738d2f771bb9a (patch)
tree304f617d1dc04c04e2c6e6696b895784fefb964e
parent45b867ae0579cd35d4585ab41c43513e6ecd21f3 (diff)
eolian gen2: feature complete header generator (eo and legacy)
-rw-r--r--src/bin/eolian2/headers.c176
1 files changed, 118 insertions, 58 deletions
diff --git a/src/bin/eolian2/headers.c b/src/bin/eolian2/headers.c
index 69dc94f3ae..f9313b4a94 100644
--- a/src/bin/eolian2/headers.c
+++ b/src/bin/eolian2/headers.c
@@ -29,7 +29,7 @@ _get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir)
29 29
30static void 30static void
31_gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype, 31_gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
32 Eina_Strbuf *buf, char *cnameu, Eina_Bool legacy) 32 Eina_Strbuf *buf, char *cname, char *cnameu, Eina_Bool legacy)
33{ 33{
34 Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, ftype, legacy); 34 Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, ftype, legacy);
35 if (!fcn) 35 if (!fcn)
@@ -51,12 +51,14 @@ _gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
51 51
52 Eolian_Object_Scope fsc = eolian_function_scope_get(fid, ftype); 52 Eolian_Object_Scope fsc = eolian_function_scope_get(fid, ftype);
53 53
54 /* this one will never be satisfied in legacy */
54 if (eolian_function_is_beta(fid)) 55 if (eolian_function_is_beta(fid))
55 eina_strbuf_append_printf(buf, "#ifdef %s_BETA\n", cnameu); 56 eina_strbuf_append_printf(buf, "#ifdef %s_BETA\n", cnameu);
56 if (fsc == EOLIAN_SCOPE_PROTECTED) 57 /* XXX: is this right? we expose potentially internal stuff into legacy */
58 if (!legacy && (fsc == EOLIAN_SCOPE_PROTECTED))
57 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu); 59 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);
58 60
59 eina_strbuf_append(buf, "EOAPI "); 61 eina_strbuf_append(buf, legacy ? "EAPI " : "EOAPI ");
60 if (rtp) 62 if (rtp)
61 { 63 {
62 Eina_Stringshare *rtps = eolian_type_c_type_get(rtp); 64 Eina_Stringshare *rtps = eolian_type_c_type_get(rtp);
@@ -71,13 +73,24 @@ _gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
71 eina_strbuf_append(buf, fcn); 73 eina_strbuf_append(buf, fcn);
72 eina_stringshare_del(fcn); 74 eina_stringshare_del(fcn);
73 75
76 Eina_Bool first = EINA_TRUE;
77 Eina_Strbuf *flagbuf = NULL;
78 int nidx = !legacy || !eolian_function_is_class(fid);
79
74 eina_strbuf_append_char(buf, '('); 80 eina_strbuf_append_char(buf, '(');
75 if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid) 81 if (nidx)
76 || eolian_function_is_class(fid))
77 { 82 {
78 eina_strbuf_append(buf, "const "); 83 if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)
84 || eolian_function_is_class(fid))
85 {
86 eina_strbuf_append(buf, "const ");
87 }
88 if (legacy)
89 eina_strbuf_append_printf(buf, "%s *obj", cname);
90 else
91 eina_strbuf_append(buf, "Eo *obj");
92 first = EINA_FALSE;
79 } 93 }
80 eina_strbuf_append(buf, "Eo *obj");
81 94
82 { 95 {
83 Eolian_Function_Parameter *pr = NULL; 96 Eolian_Function_Parameter *pr = NULL;
@@ -87,8 +100,21 @@ _gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
87 const Eolian_Type *prt = eolian_parameter_type_get(pr); 100 const Eolian_Type *prt = eolian_parameter_type_get(pr);
88 const char *prn = eolian_parameter_name_get(pr); 101 const char *prn = eolian_parameter_name_get(pr);
89 Eina_Stringshare *prtn = eolian_type_c_type_get(prt); 102 Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
90 eina_strbuf_append_printf(buf, ", %s %s", prtn, prn); 103 ++nidx;
104 if (!first)
105 eina_strbuf_append(buf, ", ");
106 eina_strbuf_append_printf(buf, "%s %s", prtn, prn);
91 eina_stringshare_del(prtn); 107 eina_stringshare_del(prtn);
108 first = EINA_FALSE;
109 if (!eolian_parameter_is_nonull(pr))
110 continue;
111 if (!flagbuf)
112 {
113 flagbuf = eina_strbuf_new();
114 eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
115 }
116 else
117 eina_strbuf_append_printf(flagbuf, ", %d", nidx);
92 } 118 }
93 eina_iterator_free(itr); 119 eina_iterator_free(itr);
94 } 120 }
@@ -108,7 +134,9 @@ _gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
108 const char *prn = eolian_parameter_name_get(pr); 134 const char *prn = eolian_parameter_name_get(pr);
109 Eina_Stringshare *prtn = eolian_type_c_type_get(prt); 135 Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
110 136
111 eina_strbuf_append(buf, ", "); 137 ++nidx;
138 if (!first)
139 eina_strbuf_append(buf, ", ");
112 eina_strbuf_append(buf, prtn); 140 eina_strbuf_append(buf, prtn);
113 if (!strchr(prtn, '*')) 141 if (!strchr(prtn, '*'))
114 eina_strbuf_append_char(buf, ' '); 142 eina_strbuf_append_char(buf, ' ');
@@ -116,16 +144,41 @@ _gen_func(const Eolian_Function *fid, Eolian_Function_Type ftype,
116 _get_add_star(ftype, eolian_parameter_direction_get(pr))); 144 _get_add_star(ftype, eolian_parameter_direction_get(pr)));
117 eina_strbuf_append(buf, prn); 145 eina_strbuf_append(buf, prn);
118 eina_stringshare_del(prtn); 146 eina_stringshare_del(prtn);
147 first = EINA_FALSE;
148 if (!eolian_parameter_is_nonull(pr))
149 continue;
150 if (!flagbuf)
151 {
152 flagbuf = eina_strbuf_new();
153 eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
154 }
155 else
156 eina_strbuf_append_printf(flagbuf, ", %d", nidx);
119 } 157 }
120 158
121 eina_iterator_free(itr); 159 eina_iterator_free(itr);
122 } 160 }
123 161
124 eina_strbuf_append(buf, ");\n"); 162 if (flagbuf)
163 eina_strbuf_append_char(flagbuf, ')');
164
165 eina_strbuf_append(buf, ")");
166 if (eolian_function_return_is_warn_unused(fid, ftype))
167 {
168 if (!flagbuf)
169 flagbuf = eina_strbuf_new();
170 eina_strbuf_prepend(flagbuf, " EINA_WARN_UNUSED_RESULT");
171 }
172 if (flagbuf)
173 {
174 eina_strbuf_append(buf, eina_strbuf_string_get(flagbuf));
175 eina_strbuf_free(flagbuf);
176 }
177 eina_strbuf_append(buf, ";\n");
125 178
126 if (eolian_function_is_beta(fid)) 179 if (eolian_function_is_beta(fid))
127 eina_strbuf_append_printf(buf, "#endif\n"); 180 eina_strbuf_append_printf(buf, "#endif\n");
128 if (fsc == EOLIAN_SCOPE_PROTECTED) 181 if (!legacy && (fsc == EOLIAN_SCOPE_PROTECTED))
129 eina_strbuf_append_printf(buf, "#endif\n"); 182 eina_strbuf_append_printf(buf, "#endif\n");
130} 183}
131 184
@@ -153,12 +206,15 @@ eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy)
153 206
154 /* class definition */ 207 /* class definition */
155 208
156 eina_strbuf_append_printf(buf, "#define %s_%s %s_%s_get()\n\n", 209 if (!legacy)
157 cnameu, _cl_type_str_get(cl, EINA_TRUE), 210 {
158 cnamel, _cl_type_str_get(cl, EINA_FALSE)); 211 eina_strbuf_append_printf(buf, "#define %s_%s %s_%s_get()\n\n",
212 cnameu, _cl_type_str_get(cl, EINA_TRUE),
213 cnamel, _cl_type_str_get(cl, EINA_FALSE));
159 214
160 eina_strbuf_append_printf(buf, "EWAPI const Efl_Class *%s_%s_get(void);\n\n", 215 eina_strbuf_append_printf(buf, "EWAPI const Efl_Class *%s_%s_get(void);\n\n",
161 cnamel, _cl_type_str_get(cl, EINA_FALSE)); 216 cnamel, _cl_type_str_get(cl, EINA_FALSE));
217 }
162 218
163 /* method section */ 219 /* method section */
164 { 220 {
@@ -173,18 +229,21 @@ eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy)
173 continue; 229 continue;
174 Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; 230 Eolian_Function_Type ftype = EOLIAN_UNRESOLVED;
175 const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype); 231 const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype);
232 /* beta can only exist for eo api */
233 if (legacy && eolian_function_is_beta(fid))
234 continue;
176 switch (ftype) 235 switch (ftype)
177 { 236 {
178 case EOLIAN_PROP_GET: 237 case EOLIAN_PROP_GET:
179 case EOLIAN_PROP_SET: 238 case EOLIAN_PROP_SET:
180 _gen_func(fid, ftype, buf, cnameu, legacy); 239 _gen_func(fid, ftype, buf, cname, cnameu, legacy);
181 break; 240 break;
182 case EOLIAN_PROPERTY: 241 case EOLIAN_PROPERTY:
183 _gen_func(fid, EOLIAN_PROP_SET, buf, cnameu, legacy); 242 _gen_func(fid, EOLIAN_PROP_SET, buf, cname, cnameu, legacy);
184 _gen_func(fid, EOLIAN_PROP_GET, buf, cnameu, legacy); 243 _gen_func(fid, EOLIAN_PROP_GET, buf, cname, cnameu, legacy);
185 break; 244 break;
186 default: 245 default:
187 _gen_func(fid, EOLIAN_UNRESOLVED, buf, cnameu, legacy); 246 _gen_func(fid, EOLIAN_UNRESOLVED, buf, cname, cnameu, legacy);
188 } 247 }
189 } 248 }
190 eina_iterator_free(itr); 249 eina_iterator_free(itr);
@@ -192,44 +251,45 @@ eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy)
192 251
193events: 252events:
194 /* event section */ 253 /* event section */
195 { 254 if (!legacy)
196 Eina_Iterator *itr = eolian_class_events_get(cl); 255 {
197 Eolian_Event *ev; 256 Eina_Iterator *itr = eolian_class_events_get(cl);
198 EINA_ITERATOR_FOREACH(itr, ev) 257 Eolian_Event *ev;
199 { 258 EINA_ITERATOR_FOREACH(itr, ev)
200 Eina_Stringshare *evn = eolian_event_c_name_get(ev); 259 {
201 Eolian_Object_Scope evs = eolian_event_scope_get(ev); 260 Eina_Stringshare *evn = eolian_event_c_name_get(ev);
202 261 Eolian_Object_Scope evs = eolian_event_scope_get(ev);
203 if (evs == EOLIAN_SCOPE_PRIVATE) 262
204 continue; 263 if (evs == EOLIAN_SCOPE_PRIVATE)
205 264 continue;
206 if (eolian_event_is_beta(ev)) 265
207 { 266 if (eolian_event_is_beta(ev))
208 eina_strbuf_append_printf(buf, "\n#ifdef %s_BETA\n", cnameu); 267 {
209 } 268 eina_strbuf_append_printf(buf, "\n#ifdef %s_BETA\n", cnameu);
210 if (evs == EOLIAN_SCOPE_PROTECTED) 269 }
211 { 270 if (evs == EOLIAN_SCOPE_PROTECTED)
212 if (!eolian_event_is_beta(ev)) 271 {
213 eina_strbuf_append_char(buf, '\n'); 272 if (!eolian_event_is_beta(ev))
214 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu); 273 eina_strbuf_append_char(buf, '\n');
215 } 274 eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);
216 275 }
217 if (!eolian_event_is_beta(ev) && evs == EOLIAN_SCOPE_PUBLIC) 276
218 eina_strbuf_append_char(buf, '\n'); 277 if (!eolian_event_is_beta(ev) && evs == EOLIAN_SCOPE_PUBLIC)
219 278 eina_strbuf_append_char(buf, '\n');
220 eina_strbuf_append_printf(buf, "EOAPI extern const " 279
221 "Efl_Event_Description _%s;\n", evn); 280 eina_strbuf_append_printf(buf, "EOAPI extern const "
222 eina_strbuf_append_printf(buf, "#define %s (&(_%s))\n", evn, evn); 281 "Efl_Event_Description _%s;\n", evn);
223 282 eina_strbuf_append_printf(buf, "#define %s (&(_%s))\n", evn, evn);
224 if (evs == EOLIAN_SCOPE_PROTECTED) 283
225 eina_strbuf_append(buf, "#endif\n"); 284 if (evs == EOLIAN_SCOPE_PROTECTED)
226 if (eolian_event_is_beta(ev)) 285 eina_strbuf_append(buf, "#endif\n");
227 eina_strbuf_append(buf, "#endif\n"); 286 if (eolian_event_is_beta(ev))
228 287 eina_strbuf_append(buf, "#endif\n");
229 eina_stringshare_del(evn); 288
230 } 289 eina_stringshare_del(evn);
231 eina_iterator_free(itr); 290 }
232 } 291 eina_iterator_free(itr);
292 }
233 293
234end: 294end:
235 free(cname); 295 free(cname);