summaryrefslogtreecommitdiff
path: root/src/bin/eolian
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2014-08-26 17:08:26 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2014-08-26 17:10:14 +0100
commitd09262b011ace191cb5e3ebc9acbfb0a99d0eba9 (patch)
treef5a95f2fe077c32b4b69499f476b1fd460b3bf9b /src/bin/eolian
parent18410e17ef455eef24c15d66e9e251d7766807f3 (diff)
eolian: stub header generator
This adds functionality into eolian_gen to generate a "stub header". The main use for this is to deal with cyclic dependencies between Eo files.
Diffstat (limited to 'src/bin/eolian')
-rw-r--r--src/bin/eolian/main.c43
-rw-r--r--src/bin/eolian/types_generator.c24
-rw-r--r--src/bin/eolian/types_generator.h3
3 files changed, 60 insertions, 10 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index 0873182117..d4e3c373f1 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -116,7 +116,7 @@ _generate_eo_header_file(char *filename, const char *eo_filename)
116 116
117 Eina_Strbuf *buffer = eina_strbuf_new(); 117 Eina_Strbuf *buffer = eina_strbuf_new();
118 118
119 if (!types_header_generate(eo_filename, buffer)) 119 if (!types_header_generate(eo_filename, buffer, EINA_TRUE))
120 { 120 {
121 ERR("Failed to generate types of file %s", eo_filename); 121 ERR("Failed to generate types of file %s", eo_filename);
122 goto end; 122 goto end;
@@ -155,6 +155,36 @@ end:
155} 155}
156 156
157static Eina_Bool 157static Eina_Bool
158_generate_stub_header_file(char *filename, const char *eo_filename)
159{
160 Eina_Bool ret = EINA_FALSE;
161
162 Eina_Strbuf *buffer = eina_strbuf_new();
163
164 if (!types_header_generate(eo_filename, buffer, EINA_FALSE))
165 {
166 ERR("Failed to generate types of file %s", eo_filename);
167 goto end;
168 }
169
170 Eina_Strbuf *ctbuf = eina_strbuf_new();
171 if (types_class_typedef_generate(eo_filename, ctbuf))
172 {
173 eina_strbuf_append_char(ctbuf, '\n');
174 eina_strbuf_prepend(buffer, eina_strbuf_string_get(ctbuf));
175 }
176 eina_strbuf_free(ctbuf);
177
178 buffer = _include_guard_enclose(_filename_get(filename), "STUBS", buffer);
179 if (_write_file(filename, buffer, EINA_FALSE))
180 ret = EINA_TRUE;
181end:
182 eina_strbuf_free(buffer);
183
184 return ret;
185}
186
187static Eina_Bool
158_generate_c_file(char *filename, const char *eo_filename, Eina_Bool legacy_support) 188_generate_c_file(char *filename, const char *eo_filename, Eina_Bool legacy_support)
159{ 189{
160 Eina_Bool ret = EINA_FALSE; 190 Eina_Bool ret = EINA_FALSE;
@@ -221,7 +251,7 @@ _generate_legacy_header_file(char *filename, const char *eo_filename)
221 251
222 Eina_Strbuf *buffer = eina_strbuf_new(); 252 Eina_Strbuf *buffer = eina_strbuf_new();
223 253
224 if (!types_header_generate(eo_filename, buffer)) 254 if (!types_header_generate(eo_filename, buffer, EINA_TRUE))
225 { 255 {
226 ERR("Failed to generate types of file %s", eo_filename); 256 ERR("Failed to generate types of file %s", eo_filename);
227 goto end; 257 goto end;
@@ -262,6 +292,7 @@ enum
262{ 292{
263 NO_WAY_GEN, 293 NO_WAY_GEN,
264 H_GEN, 294 H_GEN,
295 H_STUB_GEN,
265 C_GEN, 296 C_GEN,
266 C_IMPL_GEN 297 C_IMPL_GEN
267}; 298};
@@ -301,6 +332,7 @@ int main(int argc, char **argv)
301 {"gh", no_argument, &gen_opt, H_GEN}, 332 {"gh", no_argument, &gen_opt, H_GEN},
302 {"gc", no_argument, &gen_opt, C_GEN}, 333 {"gc", no_argument, &gen_opt, C_GEN},
303 {"gi", no_argument, &gen_opt, C_IMPL_GEN}, 334 {"gi", no_argument, &gen_opt, C_IMPL_GEN},
335 {"gs", no_argument, &gen_opt, H_STUB_GEN},
304 {"output", required_argument, 0, 'o'}, 336 {"output", required_argument, 0, 'o'},
305 {"legacy", no_argument, &legacy_support, 1}, 337 {"legacy", no_argument, &legacy_support, 1},
306 {"include", required_argument, 0, 'I'}, 338 {"include", required_argument, 0, 'I'},
@@ -341,6 +373,7 @@ int main(int argc, char **argv)
341 printf(" --output/-o Force output filename to 'outfile'\n"); 373 printf(" --output/-o Force output filename to 'outfile'\n");
342 printf(" --eo Set generator to eo mode. Must be specified\n"); 374 printf(" --eo Set generator to eo mode. Must be specified\n");
343 printf(" --gh Generate C header file [.h]\n"); 375 printf(" --gh Generate C header file [.h]\n");
376 printf(" --gs Generate C type stubs [.h]\n");
344 printf(" --gc Generate C source file [.c]\n"); 377 printf(" --gc Generate C source file [.c]\n");
345 printf(" --gi Generate C implementation source file [.c]. The output will be a series of functions that have to be filled.\n"); 378 printf(" --gi Generate C implementation source file [.c]. The output will be a series of functions that have to be filled.\n");
346 printf(" --legacy Generate legacy\n"); 379 printf(" --legacy Generate legacy\n");
@@ -400,6 +433,12 @@ int main(int argc, char **argv)
400 ret = ( _generate_eo_header_file(output_filename, eo_file_basename) ? 0 : 1 ); 433 ret = ( _generate_eo_header_file(output_filename, eo_file_basename) ? 0 : 1 );
401 break; 434 break;
402 } 435 }
436 case H_STUB_GEN:
437 {
438 INF("Generating stubs header file %s\n", output_filename);
439 ret = _generate_stub_header_file(output_filename, eo_file_basename) ? 0 : 1;
440 break;
441 }
403 case C_GEN: 442 case C_GEN:
404 { 443 {
405 INF("Generating source file %s\n", output_filename); 444 INF("Generating source file %s\n", output_filename);
diff --git a/src/bin/eolian/types_generator.c b/src/bin/eolian/types_generator.c
index acd8d5e06c..c732df13d0 100644
--- a/src/bin/eolian/types_generator.c
+++ b/src/bin/eolian/types_generator.c
@@ -37,7 +37,7 @@ _desc_generate(const char *desc, Eina_Strbuf *buf)
37} 37}
38 38
39static Eina_Strbuf * 39static Eina_Strbuf *
40_type_generate(const Eolian_Type *tp, Eina_Bool in_typedef) 40_type_generate(const Eolian_Type *tp, Eina_Bool in_typedef, Eina_Bool full)
41{ 41{
42 Eina_Strbuf *buf = eina_strbuf_new(); 42 Eina_Strbuf *buf = eina_strbuf_new();
43 _desc_generate(eolian_type_description_get(tp), buf); 43 _desc_generate(eolian_type_description_get(tp), buf);
@@ -50,8 +50,13 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
50 Eolian_Type_Type base_tp_type = eolian_type_type_get(base_tp); 50 Eolian_Type_Type base_tp_type = eolian_type_type_get(base_tp);
51 if (base_tp_type == EOLIAN_TYPE_STRUCT || base_tp_type == EOLIAN_TYPE_ENUM) 51 if (base_tp_type == EOLIAN_TYPE_STRUCT || base_tp_type == EOLIAN_TYPE_ENUM)
52 { 52 {
53 if (!full && !eolian_type_name_get(base_tp))
54 {
55 eina_strbuf_free(buf);
56 return NULL;
57 }
53 const char *name = eolian_type_name_get(tp); 58 const char *name = eolian_type_name_get(tp);
54 Eina_Strbuf *struct_buf = _type_generate(base_tp, EINA_TRUE); 59 Eina_Strbuf *struct_buf = _type_generate(base_tp, EINA_TRUE, full);
55 eina_strbuf_append_printf(buf, "typedef %s%s%s", 60 eina_strbuf_append_printf(buf, "typedef %s%s%s",
56 eina_strbuf_string_get(struct_buf), 61 eina_strbuf_string_get(struct_buf),
57 name?" ":"", name?name:""); 62 name?" ":"", name?name:"");
@@ -71,7 +76,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
71 { 76 {
72 const Eolian_Struct_Type_Field *member; 77 const Eolian_Struct_Type_Field *member;
73 char *name = _concat_name(tp); 78 char *name = _concat_name(tp);
74 if ((in_typedef && name) || tp_type == EOLIAN_TYPE_STRUCT_OPAQUE) 79 if ((in_typedef && name) || tp_type == EOLIAN_TYPE_STRUCT_OPAQUE || !full)
75 { 80 {
76 eina_strbuf_append_printf(buf, "struct %s", name); 81 eina_strbuf_append_printf(buf, "struct %s", name);
77 free(name); 82 free(name);
@@ -99,6 +104,8 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
99 { 104 {
100 const Eolian_Enum_Type_Field *member; 105 const Eolian_Enum_Type_Field *member;
101 char *name = _concat_name(tp); 106 char *name = _concat_name(tp);
107 if (!full)
108 break;
102 if (in_typedef) 109 if (in_typedef)
103 { 110 {
104 eina_strbuf_append_printf(buf, "enum %s", name); 111 eina_strbuf_append_printf(buf, "enum %s", name);
@@ -165,7 +172,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
165} 172}
166 173
167Eina_Bool 174Eina_Bool
168types_header_generate(const char *eo_filename, Eina_Strbuf *buf) 175types_header_generate(const char *eo_filename, Eina_Strbuf *buf, Eina_Bool full)
169{ 176{
170 const Eolian_Type *tp; 177 const Eolian_Type *tp;
171 178
@@ -173,7 +180,7 @@ types_header_generate(const char *eo_filename, Eina_Strbuf *buf)
173 Eina_Iterator *itr = eolian_type_aliases_get_by_file(eo_filename); 180 Eina_Iterator *itr = eolian_type_aliases_get_by_file(eo_filename);
174 EINA_ITERATOR_FOREACH(itr, tp) 181 EINA_ITERATOR_FOREACH(itr, tp)
175 { 182 {
176 Eina_Strbuf *type_buf = _type_generate(tp, EINA_TRUE); 183 Eina_Strbuf *type_buf = _type_generate(tp, EINA_TRUE, full);
177 if (type_buf) 184 if (type_buf)
178 { 185 {
179 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf)); 186 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf));
@@ -187,7 +194,7 @@ types_header_generate(const char *eo_filename, Eina_Strbuf *buf)
187 itr = eolian_type_structs_get_by_file(eo_filename); 194 itr = eolian_type_structs_get_by_file(eo_filename);
188 EINA_ITERATOR_FOREACH(itr, tp) 195 EINA_ITERATOR_FOREACH(itr, tp)
189 { 196 {
190 Eina_Strbuf *type_buf = _type_generate(tp, EINA_FALSE); 197 Eina_Strbuf *type_buf = _type_generate(tp, EINA_FALSE, full);
191 if (type_buf) 198 if (type_buf)
192 { 199 {
193 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf)); 200 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf));
@@ -197,11 +204,14 @@ types_header_generate(const char *eo_filename, Eina_Strbuf *buf)
197 } 204 }
198 eina_iterator_free(itr); 205 eina_iterator_free(itr);
199 206
207 if (!full)
208 return EINA_TRUE;
209
200 /* Generation of enums */ 210 /* Generation of enums */
201 itr = eolian_type_enums_get_by_file(eo_filename); 211 itr = eolian_type_enums_get_by_file(eo_filename);
202 EINA_ITERATOR_FOREACH(itr, tp) 212 EINA_ITERATOR_FOREACH(itr, tp)
203 { 213 {
204 Eina_Strbuf *type_buf = _type_generate(tp, EINA_FALSE); 214 Eina_Strbuf *type_buf = _type_generate(tp, EINA_FALSE, EINA_TRUE);
205 if (type_buf) 215 if (type_buf)
206 { 216 {
207 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf)); 217 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf));
diff --git a/src/bin/eolian/types_generator.h b/src/bin/eolian/types_generator.h
index 2e07b2057f..84eb15dd25 100644
--- a/src/bin/eolian/types_generator.h
+++ b/src/bin/eolian/types_generator.h
@@ -8,11 +8,12 @@
8 * 8 *
9 * @param[in] eo_filename Eo filename 9 * @param[in] eo_filename Eo filename
10 * @param[inout] buf buffer to fill 10 * @param[inout] buf buffer to fill
11 * @param[in]full whether to generate full type definitions
11 * 12 *
12 * @return EINA_TRUE on success, EINA_FALSE on error. 13 * @return EINA_TRUE on success, EINA_FALSE on error.
13 * 14 *
14 */ 15 */
15Eina_Bool types_header_generate(const char *eo_filename, Eina_Strbuf *buf); 16Eina_Bool types_header_generate(const char *eo_filename, Eina_Strbuf *buf, Eina_Bool full);
16 17
17Eina_Bool types_class_typedef_generate(const char *eo_filename, Eina_Strbuf *buf); 18Eina_Bool types_class_typedef_generate(const char *eo_filename, Eina_Strbuf *buf);
18 19