eolian gen2: initial type generation bits

This commit is contained in:
Daniel Kolesa 2016-09-15 15:30:07 +02:00
parent 17885ed375
commit 341ef8fc05
5 changed files with 49 additions and 1 deletions

View File

@ -73,7 +73,9 @@ bin_PROGRAMS += \
bin_eolian2_eolian_gen2_SOURCES = \
bin/eolian2/main.c \
bin/eolian2/main.h
bin/eolian2/main.h \
bin/eolian2/types.c \
bin/eolian2/types.h
bin_eolian2_eolian_gen2_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EOLIAN_CFLAGS@
bin_eolian2_eolian_gen2_LDADD = @USE_EOLIAN_LIBS@

View File

@ -6,6 +6,7 @@
#include <libgen.h>
#include "main.h"
#include "types.h"
int _eolian_gen_log_dom = -1;
@ -201,12 +202,34 @@ _read_file(const char *fname)
return eina_strbuf_manage_new_length(cont, fs);
}
char *eo_gen_class_full_name_get(const Eolian_Class *cl)
{
Eina_Stringshare *cln = eolian_class_full_name_get(cl);
if (!cln)
return NULL;
char *buf = strdup(cln);
if (!buf)
return NULL;
for (char *p = strchr(buf, '.'); p; p = strchr(p, '.'))
*p = '_';
return buf;
}
static Eina_Bool
_write_header(const char *ofname, const char *ifname, Eina_Bool legacy)
{
INF("generating header: %s (legacy: %d)", ofname, legacy);
Eina_Strbuf *buf = eina_strbuf_new();
Eina_Strbuf *cltd = eo_gen_class_typedef_gen(ifname);
if (cltd)
{
cltd = _include_guard(ifname, "CLASS_TYPE", cltd);
eina_strbuf_append(buf, eina_strbuf_string_get(cltd));
eina_strbuf_append_char(buf, '\n');
eina_strbuf_free(cltd);
}
Eina_Bool ret = _write_file(ofname, buf, EINA_FALSE);
eina_strbuf_free(buf);
return ret;

View File

@ -31,4 +31,6 @@ extern int _eolian_gen_log_dom;
#endif
#define CRIT(...) EINA_LOG_DOM_CRIT(_eolian_gen_log_dom, __VA_ARGS__)
char *eo_gen_class_full_name_get(const Eolian_Class *cl);
#endif

15
src/bin/eolian2/types.c Normal file
View File

@ -0,0 +1,15 @@
#include "main.h"
Eina_Strbuf *eo_gen_class_typedef_gen(const char *eof)
{
const Eolian_Class *cl = eolian_class_get_by_file(eof);
if (!cl)
return NULL;
char *clfn = eo_gen_class_full_name_get(cl);
if (!clfn)
return NULL;
Eina_Strbuf *ret = eina_strbuf_new();
eina_strbuf_append_printf(ret, "typedef Eo %s;\n", clfn);
free(clfn);
return ret;
}

6
src/bin/eolian2/types.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef EOLIAN_GEN_TYPES_H
#define EOLIAN_GEN_TYPES_H
Eina_Strbuf *eo_gen_class_typedef_gen(const char *eof);
#endif