summaryrefslogtreecommitdiff
path: root/src/bin/eolian
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-02-21 16:52:40 +0100
committerDaniel Kolesa <d.kolesa@samsung.com>2019-02-21 16:52:40 +0100
commitb6b7317f4e1ed453db52766faa54ccc9a98a800d (patch)
tree5de4a35d918450a6d6d64f09bcd0c2c4e6d7129f /src/bin/eolian
parent95d414549b9e6838b7b2d59e105ddf6955aa8d97 (diff)
eolian gen: generate a separate file with legacy implementations
If legacy implementations are generated, eolian_gen now creates a separate file for them and includes it. The file name convention for that is <.c file name without ext>.legacy.<.c file name ext> or <.c file name>.legacy.c if it has no ext, so for example foo.eo.c becomes foo.eo.legacy.c and foo becomes foo.legacy.c. The file is generated assuming there are any legacy APIs contained inside the .eo file.
Diffstat (limited to 'src/bin/eolian')
-rw-r--r--src/bin/eolian/main.c37
-rw-r--r--src/bin/eolian/sources.c12
-rw-r--r--src/bin/eolian/sources.h2
3 files changed, 38 insertions, 13 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index 7db3429..c847b0c 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -396,21 +396,48 @@ _write_source(const Eolian_State *eos, const char *ofname,
396{ 396{
397 INF("generating source: %s", ofname); 397 INF("generating source: %s", ofname);
398 Eina_Strbuf *buf = eina_strbuf_new(); 398 Eina_Strbuf *buf = eina_strbuf_new();
399 Eina_Strbuf *lbuf = eina_strbuf_new();
400 Eina_Strbuf *oflname = eina_strbuf_new();
401 Eina_Bool ret = EINA_FALSE;
399 402
403 const char *lext = strrchr(ofname, '.');
404 if (!lext)
405 {
406 eina_strbuf_append(oflname, ofname);
407 eina_strbuf_append(oflname, ".legacy.c");
408 }
409 else
410 {
411 eina_strbuf_append_length(oflname, ofname, strlen(ofname) - strlen(lext));
412 eina_strbuf_append(oflname, ".legacy");
413 eina_strbuf_append(oflname, lext);
414 }
415 const char *lfname = eina_strbuf_string_get(oflname);
416 {
417 const char *p1 = strrchr(lfname, '/');
418 const char *p2 = strrchr(lfname, '\\');
419 lfname = (p1 || p2) ? ((p1 > p2) ? (p1 + 1) : (p2 + 1)) : lfname;
420 }
400 const Eolian_Class *cl = eolian_state_class_by_file_get(eos, ifname); 421 const Eolian_Class *cl = eolian_state_class_by_file_get(eos, ifname);
401 eo_gen_types_source_gen(eolian_state_objects_by_file_get(eos, ifname), buf); 422 eo_gen_types_source_gen(eolian_state_objects_by_file_get(eos, ifname), buf);
402 eo_gen_source_gen(cl, buf); 423 eo_gen_source_gen(cl, buf, lbuf, lfname);
403 if (cl || (eot && eina_strbuf_length_get(buf))) 424 if (cl || (eot && eina_strbuf_length_get(buf)))
404 { 425 {
405 if (_write_file(ofname, buf)) 426 if (!_write_file(ofname, buf))
427 goto done;
428 if (eina_strbuf_length_get(lbuf))
406 { 429 {
407 eina_strbuf_free(buf); 430 if (!_write_file(eina_strbuf_string_get(oflname), lbuf))
408 return EINA_TRUE; 431 goto done;
409 } 432 }
433 ret = EINA_TRUE;
410 } 434 }
411 435
436done:
412 eina_strbuf_free(buf); 437 eina_strbuf_free(buf);
413 return EINA_FALSE; 438 eina_strbuf_free(lbuf);
439 eina_strbuf_free(oflname);
440 return ret;
414} 441}
415 442
416static Eina_Bool 443static Eina_Bool
diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index e4491a2..2bcda4c 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -1091,7 +1091,8 @@ _gen_initializer(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Hash *refh)
1091} 1091}
1092 1092
1093void 1093void
1094eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf) 1094eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Strbuf *lbuf,
1095 const char *lfname)
1095{ 1096{
1096 if (!cl) 1097 if (!cl)
1097 return; 1098 return;
@@ -1122,8 +1123,6 @@ eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf)
1122 eina_iterator_free(itr); 1123 eina_iterator_free(itr);
1123 } 1124 }
1124 1125
1125 Eina_Strbuf *lbuf = eina_strbuf_new();
1126
1127 /* Eolian_Function -> Eolian_Function_Type 1126 /* Eolian_Function -> Eolian_Function_Type
1128 * maps which parts of which functions are qualified for reflection 1127 * maps which parts of which functions are qualified for reflection
1129 */ 1128 */
@@ -1236,10 +1235,9 @@ eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf)
1236 /* terminate inherits */ 1235 /* terminate inherits */
1237 eina_strbuf_append(buf, ", NULL);\n"); 1236 eina_strbuf_append(buf, ", NULL);\n");
1238 1237
1239 /* append legacy if there */ 1238 /* append legacy include if there */
1240 eina_strbuf_append(buf, eina_strbuf_string_get(lbuf)); 1239 if (eina_strbuf_length_get(lbuf))
1241 1240 eina_strbuf_append_printf(buf, "\n#include \"%s\"\n", lfname);
1242 eina_strbuf_free(lbuf);
1243 1241
1244 /* and we're done */ 1242 /* and we're done */
1245 free(cnamel); 1243 free(cnamel);
diff --git a/src/bin/eolian/sources.h b/src/bin/eolian/sources.h
index 05d7114..04d6988 100644
--- a/src/bin/eolian/sources.h
+++ b/src/bin/eolian/sources.h
@@ -3,7 +3,7 @@
3 3
4#include "main.h" 4#include "main.h"
5 5
6void eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf); 6void eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Strbuf *lbuf, const char *lfname);
7void eo_gen_impl_gen(const Eolian_Class *cl, Eina_Strbuf *buf); 7void eo_gen_impl_gen(const Eolian_Class *cl, Eina_Strbuf *buf);
8 8
9#endif 9#endif