From 4cc17ae28a960b8b009a0063fa34d74f9c8a006b Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 7 Oct 2016 13:26:08 +0200 Subject: [PATCH] eolian gen2: remove old eolian gen --- src/Makefile_Eolian.am | 24 - src/bin/eolian/.gitignore | 1 - src/bin/eolian/common_funcs.c | 141 ---- src/bin/eolian/common_funcs.h | 68 -- src/bin/eolian/docs_generator.c | 666 ------------------ src/bin/eolian/docs_generator.h | 45 -- src/bin/eolian/eo_generator.c | 1047 ----------------------------- src/bin/eolian/eo_generator.h | 34 - src/bin/eolian/impl_generator.c | 324 --------- src/bin/eolian/impl_generator.h | 22 - src/bin/eolian/legacy_generator.c | 416 ------------ src/bin/eolian/legacy_generator.h | 36 - src/bin/eolian/main.c | 407 ----------- src/bin/eolian/types_generator.c | 225 ------- src/bin/eolian/types_generator.h | 22 - 15 files changed, 3478 deletions(-) delete mode 100644 src/bin/eolian/.gitignore delete mode 100644 src/bin/eolian/common_funcs.c delete mode 100644 src/bin/eolian/common_funcs.h delete mode 100644 src/bin/eolian/docs_generator.c delete mode 100644 src/bin/eolian/docs_generator.h delete mode 100644 src/bin/eolian/eo_generator.c delete mode 100644 src/bin/eolian/eo_generator.h delete mode 100644 src/bin/eolian/impl_generator.c delete mode 100644 src/bin/eolian/impl_generator.h delete mode 100644 src/bin/eolian/legacy_generator.c delete mode 100644 src/bin/eolian/legacy_generator.h delete mode 100644 src/bin/eolian/main.c delete mode 100644 src/bin/eolian/types_generator.c delete mode 100644 src/bin/eolian/types_generator.h diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am index e5b3fa4f38..9fc82c63c2 100644 --- a/src/Makefile_Eolian.am +++ b/src/Makefile_Eolian.am @@ -44,30 +44,6 @@ lib_eolian_libeolian_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@ ### Binary -bin_PROGRAMS += \ - bin/eolian/eolian_gen - -bin_eolian_eolian_gen_SOURCES = \ - bin/eolian/common_funcs.c \ - bin/eolian/common_funcs.h \ - bin/eolian/eo_generator.c \ - bin/eolian/eo_generator.h \ - bin/eolian/impl_generator.c \ - bin/eolian/impl_generator.h \ - bin/eolian/legacy_generator.c \ - bin/eolian/legacy_generator.h \ - bin/eolian/types_generator.c \ - bin/eolian/types_generator.h \ - bin/eolian/docs_generator.c \ - bin/eolian/docs_generator.h \ - bin/eolian/main.c - -bin_eolian_eolian_gen_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EOLIAN_CFLAGS@ -bin_eolian_eolian_gen_LDADD = @USE_EOLIAN_LIBS@ -bin_eolian_eolian_gen_DEPENDENCIES = @USE_EOLIAN_INTERNAL_LIBS@ - -### New generator - bin_PROGRAMS += \ bin/eolian2/eolian_gen2 diff --git a/src/bin/eolian/.gitignore b/src/bin/eolian/.gitignore deleted file mode 100644 index 4757034e1b..0000000000 --- a/src/bin/eolian/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/eolian_gen diff --git a/src/bin/eolian/common_funcs.c b/src/bin/eolian/common_funcs.c deleted file mode 100644 index 87aae20c80..0000000000 --- a/src/bin/eolian/common_funcs.c +++ /dev/null @@ -1,141 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "common_funcs.h" -#include "Eolian.h" - -int _eolian_gen_log_dom = -1; - -Eolian_Class *current_class; - -static void -_class_name_concatenate(const Eolian_Class *class, char *buffer) -{ - Eina_Iterator *itr = eolian_class_namespaces_get(class); - const char *name; - buffer[0] = '\0'; - EINA_ITERATOR_FOREACH(itr, name) - { - sprintf(buffer, "%s_", name); - buffer += (strlen(name) + 1); - } - sprintf(buffer, "%s", eolian_class_name_get(class)); - eina_iterator_free(itr); -} - -static char * -_fill_envs(char *dest, const char *src, size_t bufs) { - strncpy(dest, src, bufs - 1); - dest[bufs - 1] = '\0'; - return dest; -} - -void -_class_env_create(const Eolian_Class *class, const char *over_classname, _eolian_class_vars *env) -{ - if (!env) return; - - const char *eo_prefix = NULL; - char *p; - - if (!class) - _fill_envs(env->full_classname, over_classname, sizeof(env->full_classname)); - else - _class_name_concatenate(class, env->full_classname); - - /* class/CLASS*/ - p = _fill_envs(env->upper_classname, env->full_classname, sizeof(env->upper_classname)); - eina_str_toupper(&p); - p = _fill_envs(env->lower_classname, env->full_classname, sizeof(env->lower_classname)); - eina_str_tolower(&p); - - /* eo_prefix */ - if (class) eo_prefix = eolian_class_eo_prefix_get(class); - if (!eo_prefix) eo_prefix = env->full_classname; - p = _fill_envs(env->upper_eo_prefix, eo_prefix, sizeof(env->upper_eo_prefix)); - eina_str_toupper(&p); - p = _fill_envs(env->lower_eo_prefix, eo_prefix, sizeof(env->lower_eo_prefix)); - eina_str_tolower(&p); - - /* classtype */ - if (class) switch (eolian_class_type_get(class)) - { - case EOLIAN_CLASS_REGULAR: - case EOLIAN_CLASS_ABSTRACT: - strcpy(env->lower_classtype, "class"); - strcpy(env->upper_classtype, "CLASS"); - break; - case EOLIAN_CLASS_MIXIN: - strcpy(env->lower_classtype, "mixin"); - strcpy(env->upper_classtype, "MIXIN"); - break; - case EOLIAN_CLASS_INTERFACE: - strcpy(env->lower_classtype, "interface"); - strcpy(env->upper_classtype, "INTERFACE"); - break; - default: - break; - } -} - -void -_class_func_env_create(const Eolian_Class *class, const char *funcname, Eolian_Function_Type ftype, _eolian_class_func_vars *env) -{ - char *p; - const Eolian_Function *funcid = eolian_class_function_get_by_name(class, funcname, ftype); - - p = _fill_envs(env->upper_func, funcname, sizeof(env->upper_func)); - eina_str_toupper(&p); - - Eolian_Function_Type aftype = ftype; - if (aftype == EOLIAN_PROPERTY) aftype = EOLIAN_METHOD; - - Eina_Stringshare *fname = eolian_function_full_c_name_get(funcid, aftype, EINA_FALSE); - p = _fill_envs(env->upper_eo_func, fname, sizeof(env->upper_eo_func)); - eina_str_toupper(&p); - p = _fill_envs(env->lower_eo_func, fname, sizeof(env->lower_eo_func)); - eina_str_tolower(&p); - eina_stringshare_del(fname); - - Eina_Stringshare *lname = eolian_function_full_c_name_get(funcid, aftype, EINA_TRUE); - env->legacy_func[0] = '\0'; - if (!lname) return; - p = _fill_envs(env->legacy_func, lname, sizeof(env->legacy_func)); - eina_stringshare_del(lname); -} - -void -_template_fill(Eina_Strbuf *buf, const char *templ, const Eolian_Class *class, const char *classname, const char *funcname, Eina_Bool reset) -{ - _eolian_class_vars tmp_env; - _eolian_class_func_vars tmp_func_env; - _class_env_create(class, classname, &tmp_env); - if (funcname) - _class_func_env_create(class, funcname, EOLIAN_UNRESOLVED, &tmp_func_env); - if (buf) - { - if (reset) eina_strbuf_reset(buf); - if (templ) eina_strbuf_append(buf, templ); - if (funcname) - { - eina_strbuf_replace_all(buf, "@#func", funcname); - eina_strbuf_replace_all(buf, "@#FUNC", tmp_func_env.upper_func); - } - eina_strbuf_replace_all(buf, "@#classtype", tmp_env.lower_classtype); - eina_strbuf_replace_all(buf, "@#CLASSTYPE", tmp_env.upper_classtype); - eina_strbuf_replace_all(buf, "@#Class", tmp_env.full_classname); - eina_strbuf_replace_all(buf, "@#class", tmp_env.lower_classname); - eina_strbuf_replace_all(buf, "@#CLASS", tmp_env.upper_classname); - } -} - -const char * -_get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir) -{ - if (ftype == EOLIAN_PROP_GET) - return "*"; - if ((pdir == EOLIAN_OUT_PARAM) || (pdir == EOLIAN_INOUT_PARAM)) - return "*"; - return ""; -} diff --git a/src/bin/eolian/common_funcs.h b/src/bin/eolian/common_funcs.h deleted file mode 100644 index b23515fd38..0000000000 --- a/src/bin/eolian/common_funcs.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef __EOLIAN_COMMON_FUNCS_H -#define __EOLIAN_COMMON_FUNCS_H - -#include -#include - -#define EO - -extern int _eolian_gen_log_dom; - -#ifdef ERR -# undef ERR -#endif -#define ERR(...) EINA_LOG_DOM_ERR(_eolian_gen_log_dom, __VA_ARGS__) - -#ifdef DBG -# undef DBG -#endif -#define DBG(...) EINA_LOG_DOM_DBG(_eolian_gen_log_dom, __VA_ARGS__) - -#ifdef INF -# undef INF -#endif -#define INF(...) EINA_LOG_DOM_INFO(_eolian_gen_log_dom, __VA_ARGS__) - -#ifdef WRN -# undef WRN -#endif -#define WRN(...) EINA_LOG_DOM_WARN(_eolian_gen_log_dom, __VA_ARGS__) - -#ifdef CRIT -# undef CRIT -#endif -#define CRIT(...) EINA_LOG_DOM_CRIT(_eolian_gen_log_dom, __VA_ARGS__) - -typedef struct -{ - char full_classname[PATH_MAX]; - - char upper_eo_prefix[PATH_MAX]; - char lower_eo_prefix[PATH_MAX]; - - char upper_classname[PATH_MAX]; - char lower_classname[PATH_MAX]; - - char upper_classtype[PATH_MAX]; - char lower_classtype[PATH_MAX]; -}_eolian_class_vars; - -typedef struct -{ - char upper_func[PATH_MAX]; - - char upper_eo_func[PATH_MAX]; - char lower_eo_func[PATH_MAX]; - - char legacy_func[PATH_MAX]; -}_eolian_class_func_vars; - -void _template_fill(Eina_Strbuf *buf, const char *templ, const Eolian_Class *class, const char *classname, const char *funcname, Eina_Bool reset); - -void _class_env_create(const Eolian_Class *class, const char *over_classname, _eolian_class_vars *env); - -void _class_func_env_create(const Eolian_Class *class, const char *funcname, Eolian_Function_Type ftype EINA_UNUSED, _eolian_class_func_vars *env); - -const char *_get_add_star(Eolian_Function_Type ftype, Eolian_Parameter_Dir pdir); - -#endif diff --git a/src/bin/eolian/docs_generator.c b/src/bin/eolian/docs_generator.c deleted file mode 100644 index 0ee01a69ac..0000000000 --- a/src/bin/eolian/docs_generator.c +++ /dev/null @@ -1,666 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - -#include "docs_generator.h" - -static int -_indent_line(Eina_Strbuf *buf, int ind) -{ - int i; - for (i = 0; i < ind; ++i) - eina_strbuf_append_char(buf, ' '); - return ind; -} - -#define DOC_LINE_LIMIT 79 -#define DOC_LINE_TEST 59 -#define DOC_LINE_OVER 39 - -#define DOC_LIMIT(ind) ((ind > DOC_LINE_TEST) ? (ind + DOC_LINE_OVER) \ - : DOC_LINE_LIMIT) - -static void -_generate_ref(const char *refn, Eina_Strbuf *wbuf, Eina_Bool use_legacy) -{ - const Eolian_Declaration *decl = eolian_declaration_get_by_name(refn); - if (decl) - { - char *n = strdup(eolian_declaration_name_get(decl)); - char *p = n; - while ((p = strchr(p, '.'))) *p = '_'; - eina_strbuf_append(wbuf, n); - free(n); - return; - } - - /* not a plain declaration, so it must be struct/enum field or func */ - const char *sfx = strrchr(refn, '.'); - if (!sfx) goto noref; - - Eina_Stringshare *bname = eina_stringshare_add_length(refn, sfx - refn); - - const Eolian_Typedecl *tp = eolian_typedecl_struct_get_by_name(bname); - if (tp) - { - if (!eolian_typedecl_struct_field_get(tp, sfx + 1)) - { - eina_stringshare_del(bname); - goto noref; - } - _generate_ref(bname, wbuf, use_legacy); - eina_strbuf_append(wbuf, sfx); - eina_stringshare_del(bname); - return; - } - - tp = eolian_typedecl_enum_get_by_name(bname); - if (tp) - { - const Eolian_Enum_Type_Field *efl = eolian_typedecl_enum_field_get(tp, sfx + 1); - if (!efl) - { - eina_stringshare_del(bname); - goto noref; - } - _generate_ref(bname, wbuf, use_legacy); - Eina_Stringshare *str = eolian_typedecl_enum_field_c_name_get(efl); - eina_strbuf_append_char(wbuf, '.'); - eina_strbuf_append(wbuf, str); - eina_stringshare_del(str); - eina_stringshare_del(bname); - return; - } - - const Eolian_Class *cl = eolian_class_get_by_name(bname); - const Eolian_Function *fn = NULL; - Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; - if (!cl) - { - const char *mname; - if (!strcmp(sfx, ".get")) ftype = EOLIAN_PROP_GET; - else if (!strcmp(sfx, ".set")) ftype = EOLIAN_PROP_SET; - if (ftype != EOLIAN_UNRESOLVED) - { - eina_stringshare_del(bname); - mname = sfx - 1; - while ((mname != refn) && (*mname != '.')) --mname; - if (mname == refn) goto noref; - bname = eina_stringshare_add_length(refn, mname - refn); - cl = eolian_class_get_by_name(bname); - eina_stringshare_del(bname); - } - if (cl) - { - char *meth = strndup(mname + 1, sfx - mname - 1); - fn = eolian_class_function_get_by_name(cl, meth, ftype); - if (ftype == EOLIAN_UNRESOLVED) - ftype = eolian_function_type_get(fn); - free(meth); - } - } - else - { - fn = eolian_class_function_get_by_name(cl, sfx + 1, ftype); - ftype = eolian_function_type_get(fn); - } - - if (!fn) goto noref; - - Eina_Stringshare *fcn = eolian_function_full_c_name_get(fn, ftype, use_legacy); - if (!fcn) goto noref; - eina_strbuf_append(wbuf, fcn); - eina_stringshare_del(fcn); - return; -noref: - eina_strbuf_append(wbuf, refn); -} - -static int -_append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf, - Eina_Strbuf *wbuf, Eina_Bool use_legacy) -{ - Eina_Bool try_note = EINA_TRUE; - while (*desc) - { - eina_strbuf_reset(wbuf); - while (*desc && isspace(*desc) && (*desc != '\n')) - eina_strbuf_append_char(wbuf, *desc++); - if (try_note) - { -#define CHECK_NOTE(str) !strncmp(desc, str ": ", sizeof(str ":")) - if (CHECK_NOTE("Note")) - { - eina_strbuf_append(wbuf, "@note "); - desc += sizeof("Note:"); - } - else if (CHECK_NOTE("Warning")) - { - eina_strbuf_append(wbuf, "@warning "); - desc += sizeof("Warning:"); - } - else if (CHECK_NOTE("Remark")) - { - eina_strbuf_append(wbuf, "@remark "); - desc += sizeof("Remark:"); - } - else if (CHECK_NOTE("TODO")) - { - eina_strbuf_append(wbuf, "@todo "); - desc += sizeof("TODO:"); - } -#undef CHECK_NOTE - try_note = EINA_FALSE; - } - if (*desc == '\\') - { - desc++; - if ((*desc != '@') && (*desc != '$')) - eina_strbuf_append_char(wbuf, '\\'); - eina_strbuf_append_char(wbuf, *desc++); - } - else if (*desc == '@') - { - const char *ref = ++desc; - if (isalpha(*desc) || (*desc == '_')) - { - eina_strbuf_append(wbuf, "@ref "); - while (isalnum(*desc) || (*desc == '.') || (*desc == '_')) - ++desc; - if (*(desc - 1) == '.') --desc; - Eina_Stringshare *refn = eina_stringshare_add_length(ref, desc - ref); - _generate_ref(refn, wbuf, use_legacy); - eina_stringshare_del(refn); - } - else - eina_strbuf_append_char(wbuf, '@'); - } - else if (*desc == '$') - { - desc++; - if (isalpha(*desc)) - eina_strbuf_append(wbuf, "@c "); - else - eina_strbuf_append_char(wbuf, '$'); - } - while (*desc && !isspace(*desc)) - eina_strbuf_append_char(wbuf, *desc++); - int limit = DOC_LIMIT(ind); - int wlen = eina_strbuf_length_get(wbuf); - if ((int)(curl + wlen) > limit) - { - curl = 3; - eina_strbuf_append_char(buf, '\n'); - curl += _indent_line(buf, ind); - eina_strbuf_append(buf, " * "); - if (*eina_strbuf_string_get(wbuf) == ' ') - eina_strbuf_remove(wbuf, 0, 1); - } - curl += eina_strbuf_length_get(wbuf); - eina_strbuf_append(buf, eina_strbuf_string_get(wbuf)); - if (*desc == '\n') - { - desc++; - eina_strbuf_append_char(buf, '\n'); - while (*desc == '\n') - { - _indent_line(buf, ind); - eina_strbuf_append(buf, " *\n"); - desc++; - try_note = EINA_TRUE; - } - curl = _indent_line(buf, ind) + 3; - eina_strbuf_append(buf, " * "); - } - } - return curl; -} - -static int -_append_since(const char *since, int indent, int curl, Eina_Strbuf *buf) -{ - if (since) - { - eina_strbuf_append_char(buf, '\n'); - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * @since "); - eina_strbuf_append(buf, since); - curl += strlen(since) + sizeof(" * @since ") - 1; - } - return curl; -} - -static int -_append_extra(const char *el, int indent, int curl, Eina_Bool nl, Eina_Strbuf *buf) -{ - if (el) - { - eina_strbuf_append_char(buf, '\n'); - if (nl) - { - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - } - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * "); - eina_strbuf_append(buf, el); - curl += strlen(el) + sizeof(" * ") - 1; - } - return curl; -} - -static char * -_sanitize_group(const char *group) -{ - if (!group) return NULL; - char *ret = strdup(group); - char *p; - while ((p = strchr(ret, '.'))) *p = '_'; - return ret; -} - -static void -_append_group(Eina_Strbuf *buf, char *sgrp, int indent) -{ - if (!sgrp) return; - eina_strbuf_append(buf, " * @ingroup "); - eina_strbuf_append(buf, sgrp); - eina_strbuf_append_char(buf, '\n'); - _indent_line(buf, indent); - free(sgrp); -} - -static void -_gen_doc_brief(const char *summary, const char *since, const char *group, - const char *el, int indent, Eina_Strbuf *buf, - Eina_Bool use_legacy) -{ - int curl = 4 + indent; - Eina_Strbuf *wbuf = eina_strbuf_new(); - if (indent) - eina_strbuf_append(buf, "/**< "); - else - eina_strbuf_append(buf, "/** "); - curl = _append_section(summary, indent, curl, buf, wbuf, use_legacy); - eina_strbuf_free(wbuf); - curl = _append_extra(el, indent, curl, EINA_FALSE, buf); - curl = _append_since(since, indent, curl, buf); - char *sgrp = _sanitize_group(group); - if (((curl + 3) > DOC_LIMIT(indent)) || sgrp) - { - eina_strbuf_append_char(buf, '\n'); - _indent_line(buf, indent); - if (sgrp) eina_strbuf_append(buf, " *"); - } - if (sgrp) - { - eina_strbuf_append_char(buf, '\n'); - _indent_line(buf, indent); - } - _append_group(buf, sgrp, indent); - eina_strbuf_append(buf, " */"); -} - -static void -_gen_doc_full(const char *summary, const char *description, const char *since, - const char *group, const char *el, int indent, Eina_Strbuf *buf, - Eina_Bool use_legacy) -{ - int curl = 0; - Eina_Strbuf *wbuf = eina_strbuf_new(); - if (indent) - eina_strbuf_append(buf, "/**<\n"); - else - eina_strbuf_append(buf, "/**\n"); - curl += _indent_line(buf, indent); - eina_strbuf_append(buf, " * @brief "); - curl += sizeof(" * @brief ") - 1; - _append_section(summary, indent, curl, buf, wbuf, use_legacy); - eina_strbuf_append_char(buf, '\n'); - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * "); - _append_section(description, indent, curl + 3, buf, wbuf, use_legacy); - curl = _append_extra(el, indent, curl, EINA_TRUE, buf); - curl = _append_since(since, indent, curl, buf); - eina_strbuf_append_char(buf, '\n'); - _indent_line(buf, indent); - char *sgrp = _sanitize_group(group); - if (sgrp) - { - eina_strbuf_append(buf, " *\n"); - _indent_line(buf, indent); - } - _append_group(buf, sgrp, indent); - eina_strbuf_append(buf, " */"); - eina_strbuf_free(wbuf); -} - -static Eina_Strbuf * -_gen_doc_buf(const Eolian_Documentation *doc, const char *group, - const char *el, int indent, Eina_Bool use_legacy) -{ - if (!doc) return NULL; - - const char *sum = eolian_documentation_summary_get(doc); - const char *desc = eolian_documentation_description_get(doc); - const char *since = eolian_documentation_since_get(doc); - - Eina_Strbuf *buf = eina_strbuf_new(); - if (!desc) - _gen_doc_brief(sum, since, group, el, indent, buf, use_legacy); - else - _gen_doc_full(sum, desc, since, group, el, indent, buf, use_legacy); - return buf; -} - -Eina_Strbuf * -docs_generate_full(const Eolian_Documentation *doc, const char *group, - int indent, Eina_Bool use_legacy) -{ - return _gen_doc_buf(doc, group, NULL, indent, use_legacy); -} - -Eina_Strbuf * -docs_generate_event(const Eolian_Event *ev, const char *group) -{ - if (!ev) return NULL; - - const Eolian_Documentation *doc = eolian_event_documentation_get(ev); - - char buf[1024]; - const Eolian_Type *rt = eolian_event_type_get(ev); - const char *p = NULL; - if (rt) - { - p = buf; - Eina_Stringshare *rts = eolian_type_c_type_get(rt); - snprintf(buf, sizeof(buf), "@return %s", rts); - eina_stringshare_del(rts); - } - - if (!doc) - { - Eina_Strbuf *bufs = eina_strbuf_new(); - eina_strbuf_append(bufs, "/**\n * No description\n"); - if (p) - { - eina_strbuf_append(bufs, " * "); - eina_strbuf_append(bufs, p); - eina_strbuf_append_char(bufs, '\n'); - } - eina_strbuf_append(bufs, " */"); - return bufs; - } - - return _gen_doc_buf(doc, group, p, 0, EINA_FALSE); -} - -Eina_Strbuf * -docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, - int indent, Eina_Bool use_legacy) -{ - const Eolian_Function_Parameter *par = NULL; - const Eolian_Function_Parameter *vpar = NULL; - - const Eolian_Documentation *doc, *pdoc, *rdoc; - - Eina_Iterator *itr = NULL; - Eina_Iterator *vitr = NULL; - Eina_Bool force_out = EINA_FALSE; - - Eina_Strbuf *buf = eina_strbuf_new(); - Eina_Strbuf *wbuf = NULL; - - const char *sum = NULL, *desc = NULL, *since = NULL; - - int curl = 0; - - const char *group = eolian_class_full_name_get(eolian_function_class_get(fid)); - - if (ftype == EOLIAN_UNRESOLVED) - ftype = EOLIAN_METHOD; - - if (ftype == EOLIAN_METHOD) - { - doc = eolian_function_documentation_get(fid, EOLIAN_METHOD); - pdoc = NULL; - } - else - { - doc = eolian_function_documentation_get(fid, EOLIAN_PROPERTY); - pdoc = eolian_function_documentation_get(fid, ftype); - if (!doc && pdoc) doc = pdoc; - if (pdoc == doc) pdoc = NULL; - } - - rdoc = eolian_function_return_documentation_get(fid, ftype); - - if (doc) - { - sum = eolian_documentation_summary_get(doc); - desc = eolian_documentation_description_get(doc); - since = eolian_documentation_since_get(doc); - if (pdoc && eolian_documentation_since_get(pdoc)) - since = eolian_documentation_since_get(pdoc); - } - - if (ftype == EOLIAN_METHOD) - { - itr = eolian_function_parameters_get(fid); - } - else - { - itr = eolian_property_keys_get(fid, ftype); - vitr = eolian_property_values_get(fid, ftype); - if (!vitr || !eina_iterator_next(vitr, (void**)&vpar)) - { - eina_iterator_free(vitr); - vitr = NULL; - } - } - - if (!itr || !eina_iterator_next(itr, (void**)&par)) - { - eina_iterator_free(itr); - itr = NULL; - } - - /* when return is not set on getter, value becomes return instead of param */ - if (ftype == EOLIAN_PROP_GET && !eolian_function_return_type_get(fid, ftype)) - { - const Eolian_Function_Parameter *rvpar = vpar; - if (!eina_iterator_next(vitr, (void**)&vpar)) - { - /* one value - not out param */ - eina_iterator_free(vitr); - rdoc = rvpar ? eolian_parameter_documentation_get(rvpar) : NULL; - vitr = NULL; - vpar = NULL; - } - else - { - /* multiple values - always out params */ - eina_iterator_free(vitr); - vitr = eolian_property_values_get(fid, ftype); - if (!vitr) - vpar = NULL; - else if (!eina_iterator_next(vitr, (void**)&vpar)) - { - eina_iterator_free(vitr); - vitr = NULL; - vpar = NULL; - } - } - } - - if (!par) - { - /* no keys, try values */ - itr = vitr; - par = vpar; - vitr = NULL; - vpar = NULL; - if (ftype == EOLIAN_PROP_GET) - force_out = EINA_TRUE; - } - - /* only summary, nothing else; generate standard brief doc */ - if (!desc && !par && !vpar && !rdoc && (ftype == EOLIAN_METHOD || !pdoc)) - { - _gen_doc_brief(sum ? sum : "No description supplied.", since, group, - NULL, indent, buf, use_legacy); - return buf; - } - - wbuf = eina_strbuf_new(); - - eina_strbuf_append(buf, "/**\n"); - curl += _indent_line(buf, indent); - eina_strbuf_append(buf, " * @brief "); - curl += sizeof(" * @brief ") - 1; - _append_section(sum ? sum : "No description supplied.", - indent, curl, buf, wbuf, use_legacy); - - eina_strbuf_append_char(buf, '\n'); - if (desc || since || par || rdoc || pdoc) - { - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - } - - if (desc) - { - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * "); - _append_section(desc, indent, curl + 3, buf, wbuf, use_legacy); - eina_strbuf_append_char(buf, '\n'); - if (par || rdoc || pdoc || since) - { - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - } - } - - if (pdoc) - { - const char *pdesc = eolian_documentation_description_get(pdoc); - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * "); - _append_section(eolian_documentation_summary_get(pdoc), indent, - curl + 3, buf, wbuf, use_legacy); - eina_strbuf_append_char(buf, '\n'); - if (pdesc) - { - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * "); - _append_section(pdesc, indent, curl + 3, buf, wbuf, use_legacy); - eina_strbuf_append_char(buf, '\n'); - } - if (par || rdoc || since) - { - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - } - } - - while (par) - { - const Eolian_Documentation *adoc = eolian_parameter_documentation_get(par); - curl = _indent_line(buf, indent); - - Eolian_Parameter_Dir dir = EOLIAN_OUT_PARAM; - if (!force_out) - dir = eolian_parameter_direction_get(par); - - switch (dir) - { - case EOLIAN_IN_PARAM: - eina_strbuf_append(buf, " * @param[in] "); - curl += sizeof(" * @param[in] ") - 1; - break; - case EOLIAN_OUT_PARAM: - eina_strbuf_append(buf, " * @param[out] "); - curl += sizeof(" * @param[out] ") - 1; - break; - case EOLIAN_INOUT_PARAM: - eina_strbuf_append(buf, " * @param[in,out] "); - curl += sizeof(" * @param[in,out] ") - 1; - break; - } - - const char *nm = eolian_parameter_name_get(par); - eina_strbuf_append(buf, nm); - curl += strlen(nm); - - if (adoc) - { - eina_strbuf_append_char(buf, ' '); - curl += 1; - _append_section(eolian_documentation_summary_get(adoc), - indent, curl, buf, wbuf, use_legacy); - } - - eina_strbuf_append_char(buf, '\n'); - if (!eina_iterator_next(itr, (void**)&par)) - { - par = NULL; - if (vpar) - { - eina_iterator_free(itr); - itr = vitr; - par = vpar; - vitr = NULL; - vpar = NULL; - if (ftype == EOLIAN_PROP_GET) - force_out = EINA_TRUE; - } - } - - if (!par && (rdoc || since)) - { - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - } - } - eina_iterator_free(itr); - - if (rdoc) - { - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * @return "); - curl += sizeof(" * @return ") - 1; - _append_section(eolian_documentation_summary_get(rdoc), indent, curl, - buf, wbuf, use_legacy); - eina_strbuf_append_char(buf, '\n'); - if (since) - { - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - } - } - - if (since) - { - curl = _indent_line(buf, indent); - eina_strbuf_append(buf, " * @since "); - eina_strbuf_append(buf, since); - eina_strbuf_append_char(buf, '\n'); - } - - _indent_line(buf, indent); - eina_strbuf_append(buf, " *\n"); - - _indent_line(buf, indent); - _append_group(buf, _sanitize_group(group), indent); - eina_strbuf_append(buf, " */"); - eina_strbuf_free(wbuf); - return buf; -} diff --git a/src/bin/eolian/docs_generator.h b/src/bin/eolian/docs_generator.h deleted file mode 100644 index c7038ac71e..0000000000 --- a/src/bin/eolian/docs_generator.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef DOCS_GENERATOR_H -#define DOCS_GENERATOR_H - -#include -#include - -/* - * @brief Generate standard documentation - * - * @param[in] doc the documentation - * @param[in] group the group to use (can be NULL) - * @param[in] indent by how many spaces to indent the comment from second line - * @param[in] use_legacy whether to use legacy names - * - * @return A documentation comment - * - */ -Eina_Strbuf *docs_generate_full(const Eolian_Documentation *doc, const char *group, int indent, Eina_Bool use_legacy); - -/* - * @brief Generate function documentation - * - * @param[in] fid te function - * @param[in] type the function type (either METHOD, PROP_GET, PROP_SET) - * @param[in] indent by how many spaces to indent the comment from second line - * @param[in] use_legacy whether to use legacy names - * - * @return A documentation comment - * - */ -Eina_Strbuf *docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, int indent, Eina_Bool use_legacy); - -/* - * @brief Generate event documentation - * - * @param[in] ev the event - * @param[in] group the group to use (can be NULL); - * - * @return A documentation comment - * - */ -Eina_Strbuf *docs_generate_event(const Eolian_Event *ev, const char *group); - -#endif - diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c deleted file mode 100644 index 7b793a0ef2..0000000000 --- a/src/bin/eolian/eo_generator.c +++ /dev/null @@ -1,1047 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include - -#include "Eolian.h" -#include "eo_generator.h" -#include "docs_generator.h" -#include "common_funcs.h" - -static _eolian_class_vars class_env; -/* Used to store the function names that will have to be appended - * with __eolian during C generation. Needed when params have to - * be initialized and for future features. */ -static Eina_Hash *_funcs_params_init = NULL; - -static const char -tmpl_eo_ops_def[] = "\ - EFL_OPS_DEFINE(ops,@#list_op\n\ - );\n"; - -static const char -tmpl_eo_cops_def[] = "\ - EFL_OPS_DEFINE(cops,@#list_cop\n\ - );\n"; - -static const char -tmpl_eo_ops_desc[] = "\ -static Eina_Bool\n\ -_@#class_class_initializer(Efl_Class *klass)\n\ -{\n\ -@#list_ops\ -@#list_cops\ -\n\ - return efl_class_functions_set(klass, @#ref_ops, @#ref_cops);\n\ -}\n\n"; - -static const char -tmpl_eo_src[] = "\ -@#functions_body\ -\n\ -@#ctor_func\ -@#dtor_func\ -@#ops_desc\ -static const Efl_Class_Description _@#class_class_desc = {\n\ - EO_VERSION,\n\ - \"@#Class\",\n\ - @#type_class,\n\ - @#SizeOfData,\n\ - @#init_name,\n\ - @#ctor_name,\n\ - @#dtor_name\n\ -};\n\ -\n\ -EFL_DEFINE_CLASS(@#klasstype_get, &_@#class_class_desc, @#list_inheritNULL);\ -"; - -static const char -tmpl_eo_obj_header[] = "\ -#define @#CLASS_@#CLASSTYPE @#klasstype_get()\n\ -\n\ -EWAPI const Efl_Class *@#klasstype_get(void);\n\ -\n\ -"; - -static Eina_Bool -eo_fundef_generate(const Eolian_Class *class, const Eolian_Function *func, Eolian_Function_Type ftype, Eina_Strbuf *functext) -{ - _eolian_class_func_vars func_env; - Eina_Iterator *itr; - void *data, *data2; - Eina_Bool var_as_ret = EINA_FALSE; - const Eolian_Type *rettypet = NULL; - const char *rettype = NULL; - Eolian_Object_Scope scope = eolian_function_scope_get(func, ftype); - Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET); - - _class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env); - rettypet = eolian_function_return_type_get(func, ftype); - if (ftype == EOLIAN_PROP_GET && !rettypet) - { - itr = eolian_property_values_get(func, ftype); - /* We want to check if there is only one parameter */ - if (eina_iterator_next(itr, &data) && !eina_iterator_next(itr, &data2)) - { - rettypet = eolian_parameter_type_get((Eolian_Function_Parameter*)data); - var_as_ret = EINA_TRUE; - } - eina_iterator_free(itr); - } - Eina_Strbuf *str_func = eina_strbuf_new(); - if (eolian_function_is_beta(func)) - eina_strbuf_append_printf(str_func, "#ifdef %s_BETA\n", class_env.upper_classname); - if (scope == EOLIAN_SCOPE_PROTECTED) - eina_strbuf_append_printf(str_func, "#ifdef %s_PROTECTED\n", class_env.upper_classname); - - Eina_Bool hasnewdocs = eolian_function_documentation_get(func, EOLIAN_UNRESOLVED) || - eolian_function_documentation_get(func, ftype); - if (hasnewdocs) - { - Eina_Strbuf *dbuf = docs_generate_function(func, ftype, 0, EINA_FALSE); - eina_strbuf_append(str_func, eina_strbuf_string_get(dbuf)); - eina_strbuf_append_char(str_func, '\n'); - eina_strbuf_free(dbuf); - } - eina_strbuf_append_printf(str_func, "EOAPI @#rettype@#retspace%s(%sEo *obj@#full_params);\n", - func_env.lower_eo_func, - (ftype == EOLIAN_PROP_GET || - eolian_function_object_is_const(func) || - eolian_function_is_class(func))?"const ":""); - - if (scope == EOLIAN_SCOPE_PROTECTED) - eina_strbuf_append_printf(str_func, "#endif\n"); - if (eolian_function_is_beta(func)) - eina_strbuf_append_printf(str_func, "#endif\n"); - eina_strbuf_append_printf(str_func, "\n"); - - Eina_Strbuf *str_par = eina_strbuf_new(); - - itr = eolian_property_keys_get(func, ftype); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - eina_strbuf_append_printf(str_par, ", %s %s", ptype, pname); - eina_stringshare_del(ptype); - } - eina_iterator_free(itr); - - if (!var_as_ret) - { - itr = is_prop ? eolian_property_values_get(func, ftype) : eolian_function_parameters_get(func); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - Eolian_Parameter_Dir pdir = eolian_parameter_direction_get(param); - Eina_Bool had_star = !!strchr(ptype, '*'); - - eina_strbuf_append_printf(str_par, ", %s%s%s%s", - ptype, had_star?"":" ", _get_add_star(ftype, pdir), pname); - - eina_stringshare_del(ptype); - } - eina_iterator_free(itr); - } - - if (rettypet) rettype = eolian_type_c_type_get(rettypet); - - eina_strbuf_replace_all(str_func, "@#rettype", rettype ? rettype : "void"); - if (!rettype || rettype[strlen(rettype) - 1] != '*') - eina_strbuf_replace_all(str_func, "@#retspace", " "); - else - eina_strbuf_replace_all(str_func, "@#retspace", ""); - - eina_strbuf_replace_all(str_func, "@#full_params", eina_strbuf_string_get(str_par)); - - if (rettype) eina_stringshare_del(rettype); - - eina_strbuf_free(str_par); - - eina_strbuf_append(functext, eina_strbuf_string_get(str_func)); - eina_strbuf_free(str_func); - - return EINA_TRUE; -} - -Eina_Bool -eo_header_generate(const Eolian_Class *class, Eina_Strbuf *buf) -{ - Eina_Iterator *itr; - Eolian_Event *event; - Eina_Strbuf * str_hdr = eina_strbuf_new(); - - const Eolian_Documentation *doc = eolian_class_documentation_get(class); - _class_env_create(class, NULL, &class_env); - - if (doc) - { - Eina_Strbuf *cdoc = docs_generate_full(doc, eolian_class_full_name_get(class), 0, EINA_FALSE); - if (cdoc) - { - eina_strbuf_append(buf, eina_strbuf_string_get(cdoc)); - eina_strbuf_append_char(buf, '\n'); - eina_strbuf_free(cdoc); - } - } - - _template_fill(str_hdr, tmpl_eo_obj_header, class, NULL, NULL, EINA_TRUE); - - eina_strbuf_replace_all(str_hdr, "@#EOPREFIX", class_env.upper_eo_prefix); - eina_strbuf_replace_all(str_hdr, "@#eoprefix", class_env.lower_eo_prefix); - eina_strbuf_replace_all(str_hdr, "@#klasstype_get", eolian_class_c_get_function_name_get(class)); - - Eina_Strbuf *str_ev = eina_strbuf_new(); - Eina_Strbuf *str_extrn_ev = eina_strbuf_new(); - Eina_Strbuf *tmpbuf = eina_strbuf_new(); - - itr = eolian_class_events_get(class); - EINA_ITERATOR_FOREACH(itr, event) - { - Eina_Stringshare *evname = eolian_event_c_name_get(event); - Eolian_Object_Scope scope = eolian_event_scope_get(event); - - if (scope == EOLIAN_SCOPE_PRIVATE) - continue; - - if (eolian_event_is_beta(event)) - { - eina_strbuf_append_printf(str_ev, "\n#ifdef %s_BETA\n", class_env.upper_classname); - eina_strbuf_append_printf(str_extrn_ev, "#ifdef %s_BETA\n", class_env.upper_classname); - } - if (scope == EOLIAN_SCOPE_PROTECTED) - { - if (!eolian_event_is_beta(event)) - eina_strbuf_append_char(str_ev, '\n'); - eina_strbuf_append_printf(str_ev, "#ifdef %s_PROTECTED\n", class_env.upper_classname); - eina_strbuf_append_printf(str_extrn_ev, "#ifdef %s_PROTECTED\n", class_env.upper_classname); - } - - if (!eolian_event_is_beta(event) && scope == EOLIAN_SCOPE_PUBLIC) - eina_strbuf_append_char(str_ev, '\n'); - - Eina_Strbuf *evdbuf = docs_generate_event(event, eolian_class_full_name_get(class)); - eina_strbuf_append(str_ev, eina_strbuf_string_get(evdbuf)); - eina_strbuf_append_char(str_ev, '\n'); - eina_strbuf_free(evdbuf); - - eina_strbuf_append_printf(str_ev, "#define %s (&(_%s))\n", evname, evname); - eina_strbuf_append_printf(str_extrn_ev, "EOAPI extern const Efl_Event_Description _%s;\n", evname); - eina_stringshare_del(evname); - - if (scope == EOLIAN_SCOPE_PROTECTED) - { - eina_strbuf_append(str_ev, "#endif\n"); - eina_strbuf_append(str_extrn_ev, "#endif\n"); - } - if (eolian_event_is_beta(event)) - { - eina_strbuf_append(str_ev, "#endif\n"); - eina_strbuf_append(str_extrn_ev, "#endif\n"); - } - } - eina_iterator_free(itr); - - if ((itr = eolian_class_implements_get(class))) - { - const Eolian_Implement *impl; - EINA_ITERATOR_FOREACH(itr, impl) - { - if (eolian_implement_class_get(impl) != class) - continue; - Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; - const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); - switch (ftype) - { - case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: - eo_fundef_generate(class, fid, ftype, str_hdr); - break; - case EOLIAN_PROPERTY: - eo_fundef_generate(class, fid, EOLIAN_PROP_SET, str_hdr); - eo_fundef_generate(class, fid, EOLIAN_PROP_GET, str_hdr); - break; - default: - eo_fundef_generate(class, fid, EOLIAN_UNRESOLVED, str_hdr); - break; - } - } - eina_iterator_free(itr); - } - - eina_strbuf_append(str_hdr, eina_strbuf_string_get(str_extrn_ev)); - eina_strbuf_append(str_hdr, eina_strbuf_string_get(str_ev)); - - eina_strbuf_append(buf, eina_strbuf_string_get(str_hdr)); - - eina_strbuf_free(str_ev); - eina_strbuf_free(str_extrn_ev); - eina_strbuf_free(tmpbuf); - eina_strbuf_free(str_hdr); - - return EINA_TRUE; -} - -static Eina_Bool -eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf, Eolian_Implement *impl, _eolian_class_vars *impl_env) -{ - _eolian_class_func_vars func_env; - const char *suffix = ""; - Eina_Bool var_as_ret = EINA_FALSE; - const Eolian_Type *rettypet = NULL; - const char *rettype = NULL; - Eina_Iterator *itr; - void *data, *data2; - const Eolian_Expression *default_ret_val = NULL; - Eina_Bool is_empty = impl ? eolian_implement_is_empty(impl) : eolian_function_is_empty(funcid, ftype); - Eina_Bool is_auto = impl ? eolian_implement_is_auto(impl) : eolian_function_is_auto(funcid, ftype); - if (ftype != EOLIAN_PROP_GET && ftype != EOLIAN_PROP_SET) ftype = eolian_function_type_get(funcid); - Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET); - - Eina_Bool has_promise = EINA_FALSE; - const char* promise_param_name = NULL; - const char* promise_value_type = NULL; - Eina_Bool need_implementation = EINA_TRUE; - if (!impl_env && eolian_function_is_virtual_pure(funcid, ftype)) need_implementation = EINA_FALSE; - - Eina_Strbuf *fbody = eina_strbuf_new(); - Eina_Strbuf *va_args = eina_strbuf_new(); - Eina_Strbuf *params = eina_strbuf_new(); /* only variables names */ - Eina_Strbuf *full_params = eina_strbuf_new(); /* variables types + names */ - Eina_Strbuf *impl_full_params = eina_strbuf_new(); /* variables types + names */ - Eina_Strbuf *params_init = eina_strbuf_new(); /* init of variables to default */ - - rettypet = eolian_function_return_type_get(funcid, ftype); - if (rettypet) - { - is_auto = EINA_FALSE; /* We block auto when the function has to return something */ - default_ret_val = eolian_function_return_default_value_get(funcid, ftype); - } - if (ftype == EOLIAN_PROP_GET) - { - suffix = "_get"; - if (!rettypet) - { - itr = eolian_property_values_get(funcid, ftype); - /* We want to check if there is only one parameter */ - if (eina_iterator_next(itr, &data) && !eina_iterator_next(itr, &data2)) - { - Eolian_Function_Parameter *param = data; - rettypet = eolian_parameter_type_get(param); - var_as_ret = EINA_TRUE; - default_ret_val = eolian_parameter_default_value_get(param); - } - eina_iterator_free(itr); - } - } - if (ftype == EOLIAN_PROP_SET) - { - suffix = "_set"; - } - - itr = eolian_property_keys_get(funcid, ftype); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - if (eina_strbuf_length_get(params)) eina_strbuf_append(params, ", "); - eina_strbuf_append_printf(params, "%s", pname); - eina_strbuf_append_printf(full_params, ", %s %s%s", - ptype, pname, is_empty || is_auto?" EINA_UNUSED":""); - eina_strbuf_append_printf(impl_full_params, ", %s %s%s", - ptype, pname, is_empty || is_auto?" EINA_UNUSED":""); - eina_stringshare_del(ptype); - } - eina_iterator_free(itr); - if (!var_as_ret) - { - itr = is_prop ? eolian_property_values_get(funcid, ftype) : eolian_function_parameters_get(funcid); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Expression *dflt_value = eolian_parameter_default_value_get(param); - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - Eolian_Parameter_Dir pdir = eolian_parameter_direction_get(param); - Eina_Bool had_star = !!strchr(ptype, '*'); - const char *add_star = _get_add_star(ftype, pdir); - - if (eina_strbuf_length_get(params)) eina_strbuf_append(params, ", "); - - /* FIXME: this looks really bad and should not be here */ - if(!has_promise && !strcmp(ptype, "Eina_Promise *") && - (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) && pdir == EOLIAN_INOUT_PARAM) - { - has_promise = EINA_TRUE; - promise_param_name = eina_stringshare_add(pname); - promise_value_type = eolian_type_c_type_get(eolian_type_base_type_get(ptypet)); - eina_strbuf_append_printf(impl_full_params, ", Eina_Promise_Owner *%s%s", - pname, is_empty && !dflt_value ?" EINA_UNUSED":""); - eina_strbuf_append_printf(params, "__eo_promise"); - } - else - { - eina_strbuf_append_printf(impl_full_params, ", %s%s%s%s%s", - ptype, had_star?"":" ", add_star, pname, is_empty && !dflt_value ?" EINA_UNUSED":""); - eina_strbuf_append_printf(params, "%s", pname); - } - - eina_strbuf_append_printf(full_params, ", %s%s%s%s%s", - ptype, had_star?"":" ", add_star, pname, is_empty && !dflt_value ?" EINA_UNUSED":""); - if (is_auto) - { - if (ftype == EOLIAN_PROP_SET) - { - eina_strbuf_append_printf(params_init, - " %s = pd->%s;\n", pname, pname); - } - else - { - eina_strbuf_append_printf(params_init, - " if (%s) *%s = pd->%s;\n", pname, pname, pname); - } - } - else { - if (ftype != EOLIAN_PROP_SET) - { - if (dflt_value) - { - const char *val_str = NULL; - Eolian_Value val = eolian_expression_eval - (dflt_value, EOLIAN_MASK_ALL); - if (val.type) - { - val_str = eolian_expression_value_to_literal(&val); - eina_strbuf_append_printf(params_init, - " if (%s) *%s = %s;", - pname, pname, val_str); - if (eolian_expression_type_get(dflt_value) == EOLIAN_EXPR_NAME) - { - Eina_Stringshare *string = eolian_expression_serialize(dflt_value); - eina_strbuf_append_printf(params_init, " /* %s */", string); - eina_stringshare_del(string); - } - eina_strbuf_append_printf(params_init, "\n"); - } - } - } - } - eina_stringshare_del(ptype); - } - eina_iterator_free(itr); - } - - if (rettypet) rettype = eolian_type_c_type_get(rettypet); - - if (need_implementation) - { - Eina_Strbuf *ret_param = eina_strbuf_new(); - eina_strbuf_append_printf(fbody, "\n"); - /* Generation of the user function prototype declaration - not needed when @auto and @empty are indicated */ - if (!is_empty && !is_auto) - { - eina_strbuf_append_printf(fbody, "%s _%s%s%s_%s%s(%sEo *obj, @#Datatype_Data *pd%s);\n\n", - rettype?rettype:"void", - class_env.lower_classname, - impl_env?"_":"", - impl_env?impl_env->lower_classname:"", - eolian_function_name_get(funcid), suffix, - eolian_function_object_is_const(funcid)?"const ":"", - eina_strbuf_string_get(impl_full_params)); - } - - if (is_empty || is_auto || eina_strbuf_length_get(params_init)) - { - /* We need to give the internal function name to Eo. We use this hash table as indication */ - eina_hash_add(_funcs_params_init, - eina_stringshare_add(eolian_function_name_get(funcid)), (void *)ftype); - /* Generation of the intermediate function __eolian_... */ - eina_strbuf_append_printf(fbody, "static %s __eolian_%s%s%s_%s%s(%sEo *obj%s, @#Datatype_Data *pd%s%s)\n{\n", - rettype?rettype:"void", - class_env.lower_classname, - impl_env?"_":"", - impl_env?impl_env->lower_classname:"", - eolian_function_name_get(funcid), suffix, - eolian_function_object_is_const(funcid)?"const ":"", - is_empty || is_auto?" EINA_UNUSED":"", - is_empty || (is_auto && !eina_strbuf_length_get(params_init))?" EINA_UNUSED":"", - eina_strbuf_string_get(impl_full_params)); - } - if (eina_strbuf_length_get(params_init)) - { - eina_strbuf_append_printf(fbody, "%s", eina_strbuf_string_get(params_init)); - } - if (is_auto || is_empty) - { - if (rettype) - { - /* return for auto and empty */ - const char *val_str = NULL; - if (default_ret_val) - { - Eolian_Value val = eolian_expression_eval - (default_ret_val, EOLIAN_MASK_ALL); - if (val.type) - val_str = eolian_expression_value_to_literal(&val); - } - eina_strbuf_append_printf(fbody, " return %s;\n", val_str?val_str:"0"); - } - eina_strbuf_append_printf(fbody, "}\n\n"); - } - else if (eina_strbuf_length_get(params_init)) - { - /* Generation of the user function invocation, e.g return _user_foo(obj, pd, ...) */ - eina_strbuf_append_printf(fbody, " %s_%s%s%s_%s%s(obj, pd, %s);\n}\n\n", - rettype?"return ":"", - class_env.lower_classname, - impl_env?"_":"", - impl_env?impl_env->lower_classname:"", - eolian_function_name_get(funcid), suffix, - eina_strbuf_string_get(params)); - } - eina_strbuf_free(ret_param); - } - if (!impl_env) - { - Eina_Strbuf *eo_func_decl = eina_strbuf_new(); - Eina_Bool has_params = EINA_FALSE; - - itr = eolian_property_keys_get(funcid, ftype); - has_params |= (eina_iterator_next(itr, &data)); - eina_iterator_free(itr); - - if (!has_params && !var_as_ret) - { - itr = is_prop ? eolian_property_values_get(funcid, ftype) : eolian_function_parameters_get(funcid); - has_params |= (eina_iterator_next(itr, &data)); - eina_iterator_free(itr); - } - Eina_Bool ret_is_void = (!rettype || !strcmp(rettype, "void")); - _class_func_env_create(class, eolian_function_name_get(funcid), ftype, &func_env); - eina_strbuf_append_printf(eo_func_decl, - "EOAPI EFL_%sFUNC_BODY%s%s(%s", - ret_is_void?"VOID_":"", has_params?"V":"", - (ftype == EOLIAN_PROP_GET || - eolian_function_object_is_const(funcid) || - eolian_function_is_class(funcid))?"_CONST":"", func_env.lower_eo_func); - if (!ret_is_void) - { - const char *val_str = NULL; - if (default_ret_val) - { - Eolian_Value val = eolian_expression_eval - (default_ret_val, EOLIAN_MASK_ALL); - if (val.type) - val_str = eolian_expression_value_to_literal(&val); - } - eina_strbuf_append_printf(eo_func_decl, ", %s, %s", - rettype, val_str?val_str:"0"); - if (val_str && eolian_expression_type_get(default_ret_val) == EOLIAN_EXPR_NAME) - { - Eina_Stringshare *string = eolian_expression_serialize(default_ret_val); - eina_strbuf_append_printf(eo_func_decl, " /* %s */", string); - eina_stringshare_del(string); - } - } - if (has_params) - { - eina_strbuf_replace_all(full_params, " EINA_UNUSED", ""); - eina_strbuf_append_printf(eo_func_decl, ", EFL_FUNC_CALL(%s)%s", - eina_strbuf_string_get(params), - eina_strbuf_string_get(full_params)); - } - eina_strbuf_append_printf(eo_func_decl, ");"); - - if(has_promise) - { - eina_strbuf_append_printf(fbody, - "#undef _EFL_OBJECT_API_BEFORE_HOOK\n#undef _EFL_OBJECT_API_AFTER_HOOK\n#undef _EFL_OBJECT_API_CALL_HOOK\n" - "#define _EFL_OBJECT_API_BEFORE_HOOK _EINA_PROMISE_BEFORE_HOOK(%s, %s%s)\n" - "#define _EFL_OBJECT_API_AFTER_HOOK _EINA_PROMISE_AFTER_HOOK(%s)\n" - "#define _EFL_OBJECT_API_CALL_HOOK(x) _EINA_PROMISE_CALL_HOOK(EFL_FUNC_CALL(%s))\n\n", - promise_value_type, !rettype ? "void" : rettype, - eina_strbuf_string_get(impl_full_params), - promise_param_name, - eina_strbuf_string_get(params)); - } - - eina_strbuf_append_printf(fbody, "%s\n", eina_strbuf_string_get(eo_func_decl)); - - if(has_promise) - { - eina_strbuf_append_printf(fbody, "\n#undef _EFL_OBJECT_API_BEFORE_HOOK\n#undef _EFL_OBJECT_API_AFTER_HOOK\n#undef _EFL_OBJECT_API_CALL_HOOK\n" - "#define _EFL_OBJECT_API_BEFORE_HOOK\n#define _EFL_OBJECT_API_AFTER_HOOK\n" - "#define _EFL_OBJECT_API_CALL_HOOK(x) x\n"); - } - - eina_strbuf_free(eo_func_decl); - } - - if (need_implementation) - { - Eina_Bool is_cf = eolian_function_is_class(funcid); - const char *data_type = eolian_class_data_type_get(class); - if (is_cf || (data_type && !strcmp(data_type, "null"))) - eina_strbuf_replace_all(fbody, "@#Datatype_Data", "void"); - else - { - if (data_type) eina_strbuf_replace_all(fbody, "@#Datatype_Data", data_type); - else eina_strbuf_replace_all(fbody, "@#Datatype", class_env.full_classname); - } - - if (!data_type || !strcmp(data_type, "null")) - eina_strbuf_replace_all(fbody, "@#Datatype", class_env.full_classname); - else - eina_strbuf_replace_all(fbody, "@#Datatype_Data", data_type); - } - eina_strbuf_append(buf, eina_strbuf_string_get(fbody)); - - if (rettype) eina_stringshare_del(rettype); - - eina_strbuf_free(va_args); - eina_strbuf_free(full_params); - eina_strbuf_free(impl_full_params); - eina_strbuf_free(params_init); - eina_strbuf_free(params); - eina_strbuf_free(fbody); - return EINA_TRUE; -} - -static Eina_Bool -eo_op_desc_generate(const Eolian_Class *class, const Eolian_Function *fid, Eolian_Function_Type ftype, - Eina_Strbuf *buf) -{ - _eolian_class_func_vars func_env; - const char *funcname = eolian_function_name_get(fid); - const char *suffix = ""; - - eina_strbuf_reset(buf); - _class_func_env_create(class, funcname, ftype, &func_env); - if (ftype == EOLIAN_PROP_GET) suffix = "_get"; - if (ftype == EOLIAN_PROP_SET) suffix = "_set"; - Eina_Bool is_virtual_pure = eolian_function_is_virtual_pure(fid, ftype); - eina_strbuf_append_printf(buf, "\n EFL_OBJECT_OP_FUNC(%s, ", func_env.lower_eo_func); - if (!is_virtual_pure) - { - Eolian_Function_Type ftype2 = (Eolian_Function_Type) eina_hash_find(_funcs_params_init, funcname); - eina_strbuf_append_printf(buf, "%s_%s_%s%s),", - ftype == ftype2?"__eolian":"", - class_env.lower_classname, funcname, suffix); - } - else - eina_strbuf_append_printf(buf, "NULL),"); - - return EINA_TRUE; -} - -static Eina_Bool -eo_source_beginning_generate(const Eolian_Class *class, Eina_Strbuf *buf) -{ - Eina_Iterator *itr; - - Eina_Strbuf *tmpbuf = eina_strbuf_new(); - - Eolian_Event *event; - itr = eolian_class_events_get(class); - EINA_ITERATOR_FOREACH(itr, event) - { - Eina_Stringshare *evname = eolian_event_c_name_get(event); - - eina_strbuf_append_printf(tmpbuf, - "EOAPI const Efl_Event_Description _%s =\n EFL_EVENT_DESCRIPTION%s%s(\"%s\");\n", - evname, - eolian_event_is_hot(event) ? "_HOT" : "", - eolian_event_is_restart(event) ? "_RESTART" : "", - eolian_event_name_get(event)); - eina_stringshare_del(evname); - } - eina_iterator_free(itr); - - eina_strbuf_append(buf, eina_strbuf_string_get(tmpbuf)); - - eina_strbuf_free(tmpbuf); - return EINA_TRUE; -} - -static void -_desc_generate(const Eolian_Class *class, const Eolian_Function *fid, Eolian_Function_Type ftype, Eina_Strbuf *tmpbuf, Eina_Strbuf *str_op) -{ - const char *funcname = eolian_function_name_get(fid); - char tmpstr[256]; - snprintf(tmpstr, sizeof(tmpstr), "%s%s", funcname, (ftype == EOLIAN_PROP_SET) - ? "_set" : ((ftype == EOLIAN_PROP_GET) ? "_get" : "")); - - eo_op_desc_generate(class, fid, ftype, tmpbuf); - eina_strbuf_append(str_op, eina_strbuf_string_get(tmpbuf)); -} - -static Eina_Bool -eo_source_end_generate(const Eolian_Class *class, Eina_Strbuf *buf) -{ - Eina_Bool ret = EINA_FALSE; - Eina_Iterator *itr; - Eolian_Implement *impl_desc; - const char *inherit_name; - - const char *str_classtype = NULL; - switch(eolian_class_type_get(class)) - { - case EOLIAN_CLASS_REGULAR: - str_classtype = "EFL_CLASS_TYPE_REGULAR"; - break; - case EOLIAN_CLASS_ABSTRACT: - str_classtype = "EFL_CLASS_TYPE_REGULAR_NO_INSTANT"; - break; - case EOLIAN_CLASS_MIXIN: - str_classtype = "EFL_CLASS_TYPE_MIXIN"; - break; - case EOLIAN_CLASS_INTERFACE: - str_classtype = "EFL_CLASS_TYPE_INTERFACE"; - break; - default: - break; - } - - if (!str_classtype) - { - fprintf(stderr, "eolian: unknown class type for class '%s'\n", - class_env.full_classname); - return EINA_FALSE; - } - - Eina_Strbuf *str_end = eina_strbuf_new(); - Eina_Strbuf *tmpbuf = eina_strbuf_new(); - Eina_Strbuf *str_op = eina_strbuf_new(); - Eina_Strbuf *str_cop = eina_strbuf_new(); - Eina_Strbuf *str_bodyf = eina_strbuf_new(); - - _template_fill(str_end, tmpl_eo_src, class, NULL, NULL, EINA_TRUE); - - eina_strbuf_replace_all(str_end, "@#type_class", str_classtype); - eina_strbuf_replace_all(str_end, "@#EOPREFIX", class_env.upper_eo_prefix); - eina_strbuf_replace_all(str_end, "@#eoprefix", class_env.lower_eo_prefix); - eina_strbuf_replace_all(str_end, "@#klasstype_get", eolian_class_c_get_function_name_get(class)); - - eina_strbuf_reset(tmpbuf); - eina_strbuf_replace_all(str_end, "@#ctor_func", eina_strbuf_string_get(tmpbuf)); - - eina_strbuf_reset(tmpbuf); - if (eolian_class_ctor_enable_get(class)) - _template_fill(tmpbuf, "_@#class_class_constructor", class, NULL, NULL, EINA_TRUE); - else - eina_strbuf_append_printf(tmpbuf, "NULL"); - eina_strbuf_replace_all(str_end, "@#ctor_name", eina_strbuf_string_get(tmpbuf)); - - eina_strbuf_reset(tmpbuf); - if (eolian_class_dtor_enable_get(class)) - { - eina_strbuf_replace_all(str_end, "@#dtor_func", eina_strbuf_string_get(tmpbuf)); - eina_strbuf_reset(tmpbuf); - _template_fill(tmpbuf, "_@#class_class_destructor", class, NULL, NULL, EINA_TRUE); - eina_strbuf_replace_all(str_end, "@#dtor_name", eina_strbuf_string_get(tmpbuf)); - } - else - { - eina_strbuf_replace_all(str_end, "@#dtor_func", ""); - eina_strbuf_replace_all(str_end, "@#dtor_name", "NULL"); - } - - eina_strbuf_reset(tmpbuf); - - //Implements - TODO one generate func def for all - itr = eolian_class_implements_get(class); - EINA_ITERATOR_FOREACH(itr, impl_desc) - { - _eolian_class_vars impl_env; - char implname[0xFF]; - const Eolian_Class *impl_class = NULL; - Eolian_Function_Type ftype; - const Eolian_Function *fnid = NULL; - const char *funcname = NULL; - - const char *names[] = { "", "getter ", "setter " }; - - impl_class = eolian_implement_class_get(impl_desc); - - if (impl_class) - { - char *tp = implname; - if (impl_class == class) - continue; - fnid = eolian_implement_function_get(impl_desc, &ftype); - _class_env_create(impl_class, NULL, &impl_env); - funcname = eolian_function_name_get(fnid); - - Eina_Bool dflt_values = EINA_FALSE; - Eina_Iterator *pitr = NULL; - if (!eolian_implement_is_auto(impl_desc) && fnid && (ftype != EOLIAN_PROP_SET)) - { - Eolian_Function_Parameter *param; - pitr = (ftype == EOLIAN_METHOD) ? eolian_function_parameters_get(fnid) - : eolian_property_values_get(fnid, ftype); - EINA_ITERATOR_FOREACH(pitr, param) - { - const Eolian_Expression *dflt_value = eolian_parameter_default_value_get(param); - if (dflt_value) - { - Eolian_Value val = eolian_expression_eval - (dflt_value, EOLIAN_MASK_ALL); - if (val.type) - { - dflt_values = EINA_TRUE; - break; - } - } - } - eina_iterator_free(pitr); - } - - sprintf(implname, "%s_%s_%s", - (eolian_implement_is_auto(impl_desc) || eolian_implement_is_empty(impl_desc) || dflt_values)? - "__eolian":"", - class_env.full_classname, impl_env.full_classname); - eina_str_tolower(&tp); - } - - if (!fnid) - { - const char *name = names[eolian_implement_is_prop_get(impl_desc) - | (eolian_implement_is_prop_set(impl_desc) << 1)]; - fprintf(stderr, "eolian: failed to generate implementation of '%s%s' - missing from superclass\n", - name, eolian_implement_full_name_get(impl_desc)); - goto end; - } - - Eina_Strbuf *wbuf = str_op; - if (eolian_function_is_class(fnid)) wbuf = str_cop; - - switch (ftype) - { - case EOLIAN_PROP_SET: case EOLIAN_PROP_GET: case EOLIAN_PROPERTY: - if (ftype != EOLIAN_PROP_GET) - { - Eina_Stringshare *rets = eolian_function_full_c_name_get(fnid, EOLIAN_PROP_SET, EINA_FALSE); - eina_strbuf_append_printf(wbuf, "\n EFL_OBJECT_OP_FUNC(%s, %s_%s_set),", - rets, implname, funcname); - eo_bind_func_generate(class, fnid, EOLIAN_PROP_SET, str_bodyf, impl_desc, &impl_env); - eina_stringshare_del(rets); - } - - if (ftype != EOLIAN_PROP_SET) - { - Eina_Stringshare *rets = eolian_function_full_c_name_get(fnid, EOLIAN_PROP_GET, EINA_FALSE); - eina_strbuf_append_printf(wbuf, "\n EFL_OBJECT_OP_FUNC(%s, %s_%s_get),", - rets, implname, funcname); - eo_bind_func_generate(class, fnid, EOLIAN_PROP_GET, str_bodyf, impl_desc, &impl_env); - eina_stringshare_del(rets); - } - break; - default: - { - Eina_Stringshare *rets = eolian_function_full_c_name_get(fnid, ftype, EINA_FALSE); - eina_strbuf_append_printf(wbuf, "\n EFL_OBJECT_OP_FUNC(%s, %s_%s),", - rets, implname, funcname); - eo_bind_func_generate(class, fnid, ftype, str_bodyf, impl_desc, &impl_env); - eina_stringshare_del(rets); - break; - } - } - } - eina_iterator_free(itr); - - if ((itr = eolian_class_implements_get(class))) - { - const Eolian_Implement *impl; - EINA_ITERATOR_FOREACH(itr, impl) - { - if (eolian_implement_class_get(impl) != class) - continue; - Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; - const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); - - Eina_Strbuf *wbuf = str_op; - if (eolian_function_is_class(fid)) wbuf = str_cop; - - Eina_Bool prop_read = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_GET); - Eina_Bool prop_write = (ftype == EOLIAN_PROPERTY || ftype == EOLIAN_PROP_SET); - - if (!prop_read && !prop_write && !eolian_function_is_legacy_only(fid, EOLIAN_METHOD)) - _desc_generate(class, fid, EOLIAN_METHOD, tmpbuf, wbuf); - if (prop_write && !eolian_function_is_legacy_only(fid, EOLIAN_PROP_SET)) - _desc_generate(class, fid, EOLIAN_PROP_SET, tmpbuf, wbuf); - if (prop_read && !eolian_function_is_legacy_only(fid, EOLIAN_PROP_GET)) - _desc_generate(class, fid, EOLIAN_PROP_GET, tmpbuf, wbuf); - } - eina_iterator_free(itr); - } - - eina_strbuf_reset(tmpbuf); - itr = eolian_class_inherits_get(class); - EINA_ITERATOR_FOREACH(itr, inherit_name) - { - const Eolian_Class *inherit_class = eolian_class_get_by_name(inherit_name); - _eolian_class_vars inherit_env; - assert(inherit_class); - _class_env_create(inherit_class, NULL, &inherit_env); - eina_strbuf_append_printf(tmpbuf, "%s_%s, ", inherit_env.upper_classname, - inherit_env.upper_classtype); - } - eina_iterator_free(itr); - - if (eina_strbuf_length_get(tmpbuf) == 0) eina_strbuf_append(tmpbuf, "NULL, "); - eina_strbuf_replace_all(str_end, "@#list_inherit", eina_strbuf_string_get(tmpbuf)); - - Eina_Strbuf *ops_buf = eina_strbuf_new(), *cops_buf = eina_strbuf_new(); - - if (eina_strbuf_length_get(str_op)) - { - size_t stroplen = eina_strbuf_length_get(str_op); - if (eina_strbuf_string_get(str_op)[stroplen - 1] == ',') - eina_strbuf_remove(str_op, stroplen - 1, stroplen); - _template_fill(ops_buf, tmpl_eo_ops_def, class, NULL, NULL, EINA_TRUE); - eina_strbuf_replace_all(ops_buf, "@#list_op", eina_strbuf_string_get(str_op)); - } - - if (eina_strbuf_length_get(str_cop)) - { - size_t strcoplen = eina_strbuf_length_get(str_cop); - if (eina_strbuf_string_get(str_cop)[strcoplen - 1] == ',') - eina_strbuf_remove(str_cop, strcoplen - 1, strcoplen); - _template_fill(cops_buf, tmpl_eo_cops_def, class, NULL, NULL, EINA_TRUE); - eina_strbuf_replace_all(cops_buf, "@#list_cop", eina_strbuf_string_get(str_cop)); - } - - if (eina_strbuf_length_get(ops_buf) || eina_strbuf_length_get(cops_buf)) - { - Eina_Strbuf *ops_desc = eina_strbuf_new(); - _template_fill(ops_desc, tmpl_eo_ops_desc, class, NULL, NULL, EINA_TRUE); - if (eina_strbuf_length_get(ops_buf)) - { - eina_strbuf_replace_all(ops_desc, "@#list_ops", eina_strbuf_string_get(ops_buf)); - eina_strbuf_replace_all(ops_desc, "@#ref_ops", "&ops"); - } - else - { - eina_strbuf_replace_all(ops_desc, "@#list_ops", ""); - eina_strbuf_replace_all(ops_desc, "@#ref_ops", "NULL"); - } - if (eina_strbuf_length_get(cops_buf)) - { - eina_strbuf_replace_all(ops_desc, "@#list_cops", eina_strbuf_string_get(cops_buf)); - eina_strbuf_replace_all(ops_desc, "@#ref_cops", "&cops"); - } - else - { - eina_strbuf_replace_all(ops_desc, "@#list_cops", ""); - eina_strbuf_replace_all(ops_desc, "@#ref_cops", "NULL"); - } - eina_strbuf_replace_all(str_end, "@#ops_desc", eina_strbuf_string_get(ops_desc)); - eina_strbuf_free(ops_desc); - eina_strbuf_reset(tmpbuf); - _template_fill(tmpbuf, "_@#class_class_initializer", class, NULL, NULL, EINA_TRUE); - eina_strbuf_replace_all(str_end, "@#init_name", eina_strbuf_string_get(tmpbuf)); - } - else - { - eina_strbuf_replace_all(str_end, "@#ops_desc", ""); - eina_strbuf_replace_all(str_end, "@#init_name", "NULL"); - } - - eina_strbuf_free(ops_buf); - eina_strbuf_free(cops_buf); - - eina_strbuf_replace_all(str_end, "@#functions_body", eina_strbuf_string_get(str_bodyf)); - - const char *data_type = eolian_class_data_type_get(class); - if (data_type && !strcmp(data_type, "null")) - eina_strbuf_replace_all(str_end, "@#SizeOfData", "0"); - else - { - Eina_Strbuf *sizeofbuf = eina_strbuf_new(); - eina_strbuf_append_printf(sizeofbuf, "sizeof(%s%s)", - data_type?data_type:class_env.full_classname, - data_type?"":"_Data"); - eina_strbuf_replace_all(str_end, "@#SizeOfData", eina_strbuf_string_get(sizeofbuf)); - eina_strbuf_free(sizeofbuf); - } - eina_strbuf_append(buf, eina_strbuf_string_get(str_end)); - - ret = EINA_TRUE; -end: - eina_strbuf_free(tmpbuf); - eina_strbuf_free(str_op); - eina_strbuf_free(str_cop); - eina_strbuf_free(str_bodyf); - eina_strbuf_free(str_end); - - return ret; -} - -Eina_Bool -eo_source_generate(const Eolian_Class *class, Eina_Strbuf *buf) -{ - Eina_Bool ret = EINA_FALSE; - Eina_Iterator *itr = NULL; - - Eina_Strbuf *str_bodyf = eina_strbuf_new(); - - _class_env_create(class, NULL, &class_env); - _funcs_params_init = eina_hash_stringshared_new(NULL); - - if (!eo_source_beginning_generate(class, buf)) goto end; - - if ((itr = eolian_class_implements_get(class))) - { - const Eolian_Implement *impl; - EINA_ITERATOR_FOREACH(itr, impl) - { - if (eolian_implement_class_get(impl) != class) - continue; - Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; - const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); - switch (ftype) - { - case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: - if (!eo_bind_func_generate(class, fid, ftype, str_bodyf, NULL, NULL)) - goto end; - break; - case EOLIAN_PROPERTY: - if (!eo_bind_func_generate(class, fid, EOLIAN_PROP_SET, str_bodyf, NULL, NULL)) - goto end; - if (!eo_bind_func_generate(class, fid, EOLIAN_PROP_GET, str_bodyf, NULL, NULL)) - goto end; - break; - default: - if (!eo_bind_func_generate(class, fid, EOLIAN_UNRESOLVED, str_bodyf, NULL, NULL)) - goto end; - break; - } - } - eina_iterator_free(itr); - itr = NULL; - } - - eina_strbuf_append(buf, eina_strbuf_string_get(str_bodyf)); - eina_strbuf_reset(str_bodyf); - - if (!eo_source_end_generate(class, buf)) goto end; - - ret = EINA_TRUE; -end: - if (itr) eina_iterator_free(itr); - eina_hash_free(_funcs_params_init); - _funcs_params_init = NULL; - eina_strbuf_free(str_bodyf); - return ret; -} - diff --git a/src/bin/eolian/eo_generator.h b/src/bin/eolian/eo_generator.h deleted file mode 100644 index fc47a7b8ca..0000000000 --- a/src/bin/eolian/eo_generator.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef EO1_GENERATOR_H -#define EO1_GENERATOR_H - -#include - -/* - * @brief Generate Eo source code for Eo class - * - * This function generates all the source code for Eo. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -eo_source_generate(const Eolian_Class *class, Eina_Strbuf *buf); - -/* - * @brief Generate the header code for a specific Eo class. - * - * This function generates header code from scratch. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool eo_header_generate(const Eolian_Class *class, Eina_Strbuf *buf); - -#endif - diff --git a/src/bin/eolian/impl_generator.c b/src/bin/eolian/impl_generator.c deleted file mode 100644 index cd161855df..0000000000 --- a/src/bin/eolian/impl_generator.c +++ /dev/null @@ -1,324 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#include "Eolian.h" -#include "impl_generator.h" -#include "common_funcs.h" - -static _eolian_class_vars class_env; - -static Eina_Bool -_params_generate(const Eolian_Function *foo, Eolian_Function_Type ftype, Eina_Bool var_as_ret, Eina_Strbuf *params, Eina_Strbuf *short_params) -{ - Eina_Iterator *itr; - Eolian_Function_Parameter *param; - Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET); - eina_strbuf_reset(params); - eina_strbuf_reset(short_params); - itr = eolian_property_keys_get(foo, ftype); - EINA_ITERATOR_FOREACH(itr, param) - { - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - Eina_Bool had_star = !!strchr(ptype, '*'); - if (eina_strbuf_length_get(params)) - { - eina_strbuf_append(params, ", "); - eina_strbuf_append(short_params, ", "); - } - eina_strbuf_append_printf(params, "%s%s%s", - ptype, had_star?"":" ", pname); - eina_strbuf_append_printf(short_params, "%s", pname); - eina_stringshare_del(ptype); - } - eina_iterator_free(itr); - if (!var_as_ret) - { - itr = is_prop ? eolian_property_values_get(foo, ftype) : eolian_function_parameters_get(foo); - EINA_ITERATOR_FOREACH(itr, param) - { - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - Eolian_Parameter_Dir pdir = eolian_parameter_direction_get(param); - const char *add_star = _get_add_star(ftype, pdir); - Eina_Bool had_star = !!strchr(ptype, '*'); - if (eina_strbuf_length_get(params)) - { - eina_strbuf_append(params, ", "); - eina_strbuf_append(short_params, ", "); - } - eina_strbuf_append_printf(params, "%s%s%s%s", - ptype, had_star?"":" ", add_star, pname); - eina_strbuf_append_printf(short_params, "%s", pname); - eina_stringshare_del(ptype); - } - eina_iterator_free(itr); - } - return EINA_TRUE; -} - -static Eina_Bool -_function_exists(const char* func_name, Eina_Strbuf *buffer) -{ - const char *ptr = eina_strbuf_string_get(buffer); - int func_len = strlen(func_name); - while ((ptr = strstr(ptr, func_name)) != NULL) - { - switch (*(ptr - 1)) - { - case '\n': case ' ': - { - switch (*(ptr + func_len)) - { - case ' ': case '(': - return EINA_TRUE; - } - } - } - ptr++; /* so strstr doesn't fall again on func_name */ - } - return EINA_FALSE; -} - -/* Check if the type is used in the file, not if it is a typedef... */ -static Eina_Bool -_type_exists(const char* type_name, Eina_Strbuf *buffer) -{ - const char *ptr = eina_strbuf_string_get(buffer); - int type_len = strlen(type_name); - while ((ptr = strstr(ptr, type_name)) != NULL) - { - switch (*(ptr - 1)) - { - case '\n': case ' ': case ',': - { - switch (*(ptr + type_len)) - { - case '\n': case ' ': case ',': case ';': - return EINA_TRUE; - } - } - } - ptr++; /* so strstr doesn't fall again on type_name */ - } - return EINA_FALSE; -} - -static Eina_Bool -_prototype_generate(const Eolian_Function *foo, Eolian_Function_Type ftype, Eina_Strbuf *data_type_buf, Eolian_Implement *impl_desc, Eina_Strbuf *buffer) -{ - Eina_Bool var_as_ret = EINA_FALSE; - Eina_Strbuf *params = NULL, *short_params = NULL, *super_invok = NULL; - char func_name[PATH_MAX]; - char impl_name[PATH_MAX]; - const char *fname; - size_t flen; - _eolian_class_vars impl_env; - - if (!impl_desc && eolian_function_is_virtual_pure(foo, ftype)) return EINA_TRUE; - - super_invok = eina_strbuf_new(); - if (impl_desc) - { - _class_env_create(eolian_implement_class_get(impl_desc), NULL, &impl_env); - char *tmp = impl_name; - sprintf(impl_name, "%s_%s", class_env.full_classname, impl_env.full_classname); - eina_str_tolower(&tmp); - } - - sprintf(func_name, "_%s_%s%s", - impl_desc?impl_name:class_env.lower_classname, eolian_function_name_get(foo), - ftype == EOLIAN_PROP_GET?"_get": (ftype == EOLIAN_PROP_SET?"_set":"")); - - if (_function_exists(func_name, buffer)) goto end; - - printf("Generation of function %s\n", func_name); - const Eolian_Type *rettypet = eolian_function_return_type_get(foo, ftype); - if (ftype == EOLIAN_PROP_GET && !rettypet) - { - Eina_Iterator *itr = eolian_property_values_get(foo, ftype); - void *data, *data2; - /* We want to check if there is only one parameter */ - if (eina_iterator_next(itr, &data) && !eina_iterator_next(itr, &data2)) - { - Eolian_Function_Parameter *param = data; - rettypet = eolian_parameter_type_get(param); - var_as_ret = EINA_TRUE; - } - eina_iterator_free(itr); - } - - params = eina_strbuf_new(); - short_params = eina_strbuf_new(); - _params_generate(foo, ftype, var_as_ret, params, short_params); - if (eina_strbuf_length_get(params)) - eina_strbuf_prepend_printf(params, ", "); - if (eina_strbuf_length_get(short_params)) - eina_strbuf_prepend_printf(short_params, ", "); - - fname = eolian_function_name_get(foo); - if (fname) - { - flen = strlen(fname); - if (flen >= strlen("destructor")) - { - if (impl_desc && - (!strcmp(fname + flen - strlen("destructor"), "destructor"))) - { - eina_strbuf_append_printf - (super_invok, - " %s_%s(efl_super(obj, %s_%s)%s);\n", - impl_env.lower_eo_prefix, eolian_function_name_get(foo), - class_env.upper_eo_prefix, class_env.upper_classtype, - eina_strbuf_string_get(short_params)); - } - } - } - - const char *rettype = NULL; - if (rettypet) rettype = eolian_type_c_type_get(rettypet); - - eina_strbuf_append_printf(buffer, - "EOLIAN static %s\n%s(%sEo *obj, %s *pd%s%s)\n{\n%s\n}\n\n", - !rettype?"void":rettype, - func_name, - eolian_function_object_is_const(foo)?"const ":"", - !eina_strbuf_length_get(data_type_buf) ? "void" : eina_strbuf_string_get(data_type_buf), - !eina_strbuf_length_get(data_type_buf) ? " EINA_UNUSED" : "", - eina_strbuf_string_get(params), - eina_strbuf_string_get(super_invok) - ); - - if (rettype) eina_stringshare_del(rettype); - -end: - eina_strbuf_free(short_params); - eina_strbuf_free(params); - eina_strbuf_free(super_invok); - return EINA_TRUE; -} - -Eina_Bool -impl_source_generate(const Eolian_Class *class, Eina_Strbuf *buffer) -{ - Eina_Bool ret = EINA_FALSE; - Eina_Strbuf *data_type_buf = eina_strbuf_new(); - Eina_Iterator *itr; - const Eolian_Function *foo; - Eina_Strbuf *begin = eina_strbuf_new(); - char core_incl[PATH_MAX]; - - _class_env_create(class, NULL, &class_env); - - if (!_type_exists("EFL_BETA_API_SUPPORT", buffer)) - { - printf("Generation of EFL_BETA_API_SUPPORT\n"); - eina_strbuf_append_printf(begin, "#define EFL_BETA_API_SUPPORT\n"); - } - - if (!_type_exists("", buffer)) - { - printf("Generation of #include and \"%s.eo.h\"\n", class_env.lower_classname); - eina_strbuf_append_printf(begin, "#include \n#include \"%s.eo.h\"\n\n", class_env.lower_classname); - } - - /* Little calculation of the prefix of the data */ - const char *data_type = eolian_class_data_type_get(class); - if (data_type) - { - if (strcmp(data_type, "null")) - eina_strbuf_append_printf(data_type_buf, "%s", data_type); - } - else - eina_strbuf_append_printf(data_type_buf, "%s_Data", class_env.full_classname); - - /* Definition of the structure */ - const char *data_type_str = eina_strbuf_string_get(data_type_buf); - if (!_type_exists(data_type_str, buffer) && 0 != eina_strbuf_length_get(data_type_buf)) - { - printf("Generation of type %s\n", data_type_str); - eina_strbuf_append_printf(begin, "typedef struct\n{\n\n} %s;\n\n", data_type_str); - } - - if (eina_strbuf_length_get(begin)) - eina_strbuf_prepend_printf(buffer, "%s", eina_strbuf_string_get(begin)); - eina_strbuf_free(begin); - - itr = eolian_class_implements_get(class); - if (itr) - { - Eolian_Implement *impl_desc; - const char *names[] = { "", "getter ", "setter " }; - EINA_ITERATOR_FOREACH(itr, impl_desc) - { - Eolian_Function_Type ftype; - Eolian_Implement *idesc = (eolian_implement_class_get(impl_desc) == class) ? NULL : impl_desc; - if (!(foo = eolian_implement_function_get(impl_desc, &ftype))) - { - const char *name = names[eolian_implement_is_prop_get(impl_desc) - | (eolian_implement_is_prop_set(impl_desc) << 1)]; - fprintf(stderr, "eolian: failed to generate implementation of '%s%s' - missing from class\n", - name, eolian_implement_full_name_get(impl_desc)); - goto end; - } - switch (ftype) - { - case EOLIAN_PROP_SET: case EOLIAN_PROP_GET: - _prototype_generate(foo, ftype, data_type_buf, idesc, buffer); - break; - case EOLIAN_PROPERTY: - _prototype_generate(foo, EOLIAN_PROP_SET, data_type_buf, idesc, buffer); - _prototype_generate(foo, EOLIAN_PROP_GET, data_type_buf, idesc, buffer); - break; - default: - _prototype_generate(foo, eolian_function_type_get(foo), data_type_buf, idesc, buffer); - break; - } - } - eina_iterator_free(itr); - } - - if (eolian_class_ctor_enable_get(class)) - { - char func_name[100]; - sprintf(func_name, "_%s_class_constructor", class_env.lower_classname); - if (!_function_exists(func_name, buffer)) - { - printf("Generation of function %s\n", func_name); - eina_strbuf_append_printf(buffer, - "EOLIAN static void\n_%s_class_constructor(Efl_Class *klass)\n{\n\n}\n\n", - class_env.lower_classname); - } - } - - if (eolian_class_dtor_enable_get(class)) - { - char func_name[100]; - sprintf(func_name, "_%s_class_destructor", class_env.lower_classname); - if (!_function_exists(func_name, buffer)) - { - printf("Generation of function %s\n", func_name); - eina_strbuf_append_printf(buffer, "EOLIAN static void\n_%s_class_destructor(Efl_Class *klass)\n{\n\n}\n\n", - class_env.lower_classname); - } - } - printf("Removal of all inline instances of #include \"%s.eo.c\"\n", class_env.lower_classname); - snprintf(core_incl, sizeof(core_incl), "\n#include \"%s.eo.c\"\n", class_env.lower_classname); - eina_strbuf_replace_all(buffer, core_incl, "\n"); - - snprintf(core_incl, sizeof(core_incl), "\"%s.eo.c\"", class_env.lower_classname); - printf("Generation of #include \"%s.eo.c\"\n", class_env.lower_classname); - eina_strbuf_append_printf(buffer, "#include \"%s.eo.c\"\n", class_env.lower_classname); - - ret = EINA_TRUE; -end: - eina_strbuf_free(data_type_buf); - return ret; -} - diff --git a/src/bin/eolian/impl_generator.h b/src/bin/eolian/impl_generator.h deleted file mode 100644 index a4686e2b9e..0000000000 --- a/src/bin/eolian/impl_generator.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef IMPL_GENERATOR_H -#define IMPL_GENERATOR_H - -#include - -/* - * @brief Generate the implementation source code of a class - * - * This function generates all the source code of a class. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool -impl_source_generate(const Eolian_Class *class, Eina_Strbuf *buf); - -#endif - - diff --git a/src/bin/eolian/legacy_generator.c b/src/bin/eolian/legacy_generator.c deleted file mode 100644 index cf913435b3..0000000000 --- a/src/bin/eolian/legacy_generator.c +++ /dev/null @@ -1,416 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#include "Eolian.h" - -#include "legacy_generator.h" -#include "docs_generator.h" -#include "common_funcs.h" - -static _eolian_class_vars class_env; - -static const char -tmpl_eapi_funcdef[] = "EAPI @#type_return%s(@#params)@#flags;\n"; - -/*@#CLASS_CHECK(obj) @#check_ret;\n\*/ -static const char -tmpl_eapi_body[] ="\ -\n\ -EAPI @#ret_type\n\ -@#eapi_func(@#full_params)\n\ -{\n\ - return @#eo_func(@#eo_obj@#eo_params);\n\ -}\n\ -"; -static const char -tmpl_eapi_body_void[] ="\ -\n\ -EAPI void\n\ -@#eapi_func(@#full_params)\n\ -{\n\ - @#eo_func(@#eo_obj@#eo_params);\n\ -}\n\ -"; - -static void -_eapi_decl_func_generate(const Eolian_Class *class, const Eolian_Function *funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf) -{ - _eolian_class_func_vars func_env; - const char *funcname = eolian_function_name_get(funcid); - const Eolian_Type *rettypet = NULL; - const char *rettype = NULL; - Eina_Bool var_as_ret = EINA_FALSE; - Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET); - Eina_Iterator *itr; - void *data, *data2; - Eina_Strbuf *flags = NULL; - int leg_param_idx = 1; /* Index of the parameter inside the legacy function. It begins from 1 since obj is the first. */ - - Eina_Strbuf *fbody = eina_strbuf_new(); - Eina_Strbuf *fparam = eina_strbuf_new(); - - _class_func_env_create(class, funcname, ftype, &func_env); - rettypet = eolian_function_return_type_get(funcid, ftype); - if (ftype == EOLIAN_PROP_GET) - { - if (!rettypet) - { - itr = eolian_property_values_get(funcid, ftype); - /* We want to check if there is only one parameter */ - if (eina_iterator_next(itr, &data) && !eina_iterator_next(itr, &data2)) - { - rettypet = eolian_parameter_type_get((Eolian_Function_Parameter*)data); - var_as_ret = EINA_TRUE; - } - eina_iterator_free(itr); - } - } - - if (func_env.legacy_func[0] == '\0') goto end; - - Eina_Bool hasnewdocs = eolian_function_documentation_get(funcid, EOLIAN_UNRESOLVED) || - eolian_function_documentation_get(funcid, ftype); - if (hasnewdocs) - { - Eina_Strbuf *dbuf = docs_generate_function(funcid, ftype, 0, EINA_TRUE); - eina_strbuf_append_char(fbody, '\n'); - eina_strbuf_append(fbody, eina_strbuf_string_get(dbuf)); - eina_strbuf_append_char(fbody, '\n'); - eina_strbuf_free(dbuf); - } - - eina_strbuf_append_printf(fbody, tmpl_eapi_funcdef, func_env.legacy_func); - - if (!eolian_function_is_class(funcid)) - { - if (ftype == EOLIAN_PROP_GET || eolian_function_object_is_const(funcid)) - eina_strbuf_append(fparam, "const "); - eina_strbuf_append_printf(fparam, "%s *obj", class_env.full_classname); - } - - itr = eolian_property_keys_get(funcid, ftype); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - leg_param_idx++; - if (eina_strbuf_length_get(fparam)) eina_strbuf_append(fparam, ", "); - eina_strbuf_append_printf(fparam, "%s %s", ptype, pname); - eina_stringshare_del(ptype); - - if (eolian_parameter_is_nonull((Eolian_Function_Parameter*)data)) - { - if (!flags) - { - flags = eina_strbuf_new(); - eina_strbuf_append_printf(flags, " EINA_ARG_NONNULL(%d", leg_param_idx); - } - else - eina_strbuf_append_printf(flags, ", %d", leg_param_idx); - } - } - eina_iterator_free(itr); - if (!var_as_ret) - { - itr = is_prop ? eolian_property_values_get(funcid, ftype) : eolian_function_parameters_get(funcid); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - Eolian_Parameter_Dir pdir = eolian_parameter_direction_get(param); - Eina_Bool had_star = !!strchr(ptype, '*'); - - leg_param_idx++; - if (eina_strbuf_length_get(fparam)) eina_strbuf_append(fparam, ", "); - eina_strbuf_append_printf(fparam, "%s%s%s%s", - ptype, had_star?"":" ", _get_add_star(ftype, pdir), pname); - eina_stringshare_del(ptype); - if (eolian_parameter_is_nonull((Eolian_Function_Parameter*)data)) - { - if (!flags) - { - flags = eina_strbuf_new(); - eina_strbuf_append_printf(flags, " EINA_ARG_NONNULL(%d", leg_param_idx); - } - else - eina_strbuf_append_printf(flags, ", %d", leg_param_idx); - } - } - eina_iterator_free(itr); - } - if (!eina_strbuf_length_get(fparam)) eina_strbuf_append(fparam, "void"); - if (flags) eina_strbuf_append_printf(flags, ")"); - - if (rettypet) rettype = eolian_type_c_type_get(rettypet); - - eina_strbuf_replace_all(fbody, "@#params", eina_strbuf_string_get(fparam)); - eina_strbuf_reset(fparam); - eina_strbuf_append_printf(fparam, "%s%s", - rettype ? rettype : "void", - rettype && strchr(rettype, '*')?"":" "); - eina_strbuf_replace_all(fbody, "@#type_return", eina_strbuf_string_get(fparam)); - if (eolian_function_return_is_warn_unused(funcid, ftype)) - { - Eina_Bool no_nonull = !flags; - if (no_nonull) flags = eina_strbuf_new(); - eina_strbuf_prepend(flags, " EINA_WARN_UNUSED_RESULT"); - } - if (flags) - eina_strbuf_replace_all(fbody, "@#flags", eina_strbuf_string_get(flags)); - eina_strbuf_replace_all(fbody, "@#flags", (eolian_function_return_is_warn_unused(funcid, ftype)) ? " EINA_WARN_UNUSED_RESULT" : ""); - eina_strbuf_append(buf, eina_strbuf_string_get(fbody)); - - if (rettype) eina_stringshare_del(rettype); - -end: - eina_strbuf_free(flags); - eina_strbuf_free(fbody); - eina_strbuf_free(fparam); -} - -static void -_eapi_func_generate(const Eolian_Class *class, const Eolian_Function *funcid, Eolian_Function_Type ftype, Eina_Strbuf *buf) -{ - _eolian_class_func_vars func_env; - char tmpstr[0xFF]; - Eina_Bool var_as_ret = EINA_FALSE; - const Eolian_Type *rettypet = NULL; - const char *rettype = NULL; - const char *retname = NULL; - Eina_Bool ret_is_void = EINA_FALSE; - Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET); - - Eina_Strbuf *fbody = eina_strbuf_new(); - Eina_Strbuf *fparam = eina_strbuf_new(); - Eina_Strbuf *eoparam = eina_strbuf_new(); - - Eina_Iterator *itr; - void *data, *data2; - - _class_func_env_create(class, eolian_function_name_get(funcid), ftype, &func_env); - rettypet = eolian_function_return_type_get(funcid, ftype); - if (rettypet) rettype = eolian_type_c_type_get(rettypet); - if (rettype && !strcmp(rettype, "void")) ret_is_void = EINA_TRUE; - retname = "ret"; - if (ftype == EOLIAN_PROP_GET) - { - if (!rettypet) - { - itr = eolian_property_values_get(funcid, ftype); - /* We want to check if there is only one parameter */ - if (eina_iterator_next(itr, &data) && !eina_iterator_next(itr, &data2)) - { - Eolian_Function_Parameter *param = data; - rettypet = eolian_parameter_type_get(param); - retname = eolian_parameter_name_get(param); - var_as_ret = EINA_TRUE; - } - eina_iterator_free(itr); - } - } - - if (func_env.legacy_func[0] == '\0') goto end; - - if (!rettype && rettypet) rettype = eolian_type_c_type_get(rettypet); - - if (rettype && (!ret_is_void)) - eina_strbuf_append(fbody, tmpl_eapi_body); - else - eina_strbuf_append(fbody, tmpl_eapi_body_void); - - if (!eolian_function_is_class(funcid)) - { - if (ftype == EOLIAN_PROP_GET || eolian_function_object_is_const(funcid)) - eina_strbuf_append(fparam, "const "); - eina_strbuf_append_printf(fparam, "%s *obj", class_env.full_classname); - char cbuf[256]; - snprintf(cbuf, sizeof(cbuf), "(%s *)obj", class_env.full_classname); - eina_strbuf_replace_all(fbody, "@#eo_obj", cbuf); - } - else - { - Eina_Strbuf *class_buf = eina_strbuf_new(); - _template_fill(class_buf, "@#CLASS_@#CLASSTYPE", class, NULL, NULL, EINA_TRUE); - eina_strbuf_replace_all(fbody, "@#eo_obj", eina_strbuf_string_get(class_buf)); - eina_strbuf_free(class_buf); - } - eina_strbuf_replace_all(fbody, "@#eapi_func", func_env.legacy_func); - eina_strbuf_replace_all(fbody, "@#eo_func", func_env.lower_eo_func); - - tmpstr[0] = '\0'; - - itr = eolian_property_keys_get(funcid, ftype); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - if (eina_strbuf_length_get(fparam)) eina_strbuf_append(fparam, ", "); - eina_strbuf_append_printf(fparam, "%s %s", ptype, pname); - eina_stringshare_del(ptype); - eina_strbuf_append_printf(eoparam, ", %s", pname); - } - eina_iterator_free(itr); - if (!var_as_ret) - { - itr = is_prop ? eolian_property_values_get(funcid, ftype) : eolian_function_parameters_get(funcid); - EINA_ITERATOR_FOREACH(itr, data) - { - Eolian_Function_Parameter *param = data; - const Eolian_Type *ptypet = eolian_parameter_type_get(param); - const char *pname = eolian_parameter_name_get(param); - const char *ptype = eolian_type_c_type_get(ptypet); - Eolian_Parameter_Dir pdir = eolian_parameter_direction_get(param); - Eina_Bool had_star = !!strchr(ptype, '*'); - if (eina_strbuf_length_get(fparam)) eina_strbuf_append(fparam, ", "); - eina_strbuf_append_printf(fparam, "%s%s%s%s", - ptype, had_star?"":" ", _get_add_star(ftype, pdir), pname); - eina_stringshare_del(ptype); - eina_strbuf_append_printf(eoparam, ", %s", pname); - } - eina_iterator_free(itr); - } - if (!eina_strbuf_length_get(fparam)) eina_strbuf_append(fparam, "void"); - - if (rettype && (!ret_is_void)) - { - char tmp_ret_str[0xFF]; - sprintf (tmp_ret_str, "%s", rettype); - const Eolian_Expression *default_ret_val = - eolian_function_return_default_value_get(funcid, ftype); - const char *val_str = NULL; - if (default_ret_val) - { - Eolian_Value val = eolian_expression_eval_type - (default_ret_val, rettypet); - if (val.type) - val_str = eolian_expression_value_to_literal(&val); - } - Eina_Bool had_star = !!strchr(rettype, '*'); - sprintf (tmpstr, " %s%s%s = %s;\n", - rettype, had_star?"":" ", retname, - val_str?val_str:"0"); - - eina_strbuf_replace_all(fbody, "@#ret_type", tmp_ret_str); - eina_strbuf_replace_all(fbody, "@#ret_init_val", tmpstr); - } - - eina_strbuf_replace_all(fbody, "@#full_params", eina_strbuf_string_get(fparam)); - eina_strbuf_replace_all(fbody, "@#eo_params", eina_strbuf_string_get(eoparam)); - - eina_strbuf_replace_all(fbody, "@#ret_val", (rettype && !ret_is_void) ? retname : ""); - - eina_strbuf_append(buf, eina_strbuf_string_get(fbody)); - - if (rettype) eina_stringshare_del(rettype); - -end: - eina_strbuf_free(fbody); - eina_strbuf_free(fparam); - eina_strbuf_free(eoparam); -} - -Eina_Bool -legacy_header_generate(const Eolian_Class *class, Eina_Strbuf *buf) -{ - _class_env_create(class, NULL, &class_env); - - const Eolian_Documentation *doc = eolian_class_documentation_get(class); - if (doc) - { - Eina_Strbuf *cdoc = docs_generate_full(doc, eolian_class_full_name_get(class), 0, EINA_TRUE); - if (cdoc) - { - eina_strbuf_append(buf, eina_strbuf_string_get(cdoc)); - eina_strbuf_append_char(buf, '\n'); - eina_strbuf_free(cdoc); - } - } - - Eina_Iterator *itr = eolian_class_implements_get(class); - if (itr) - { - const Eolian_Implement *impl; - EINA_ITERATOR_FOREACH(itr, impl) - { - if (eolian_implement_class_get(impl) != class) - continue; - Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; - const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); - if (eolian_function_is_beta(fid)) - continue; - switch (ftype) - { - case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: - _eapi_decl_func_generate(class, fid, ftype, buf); - break; - case EOLIAN_PROPERTY: - _eapi_decl_func_generate(class, fid, EOLIAN_PROP_SET, buf); - _eapi_decl_func_generate(class, fid, EOLIAN_PROP_GET, buf); - break; - default: - _eapi_decl_func_generate(class, fid, EOLIAN_METHOD, buf); - break; - } - } - eina_iterator_free(itr); - } - return EINA_TRUE; -} - -Eina_Bool -legacy_source_generate(const Eolian_Class *class, Eina_Strbuf *buf) -{ - Eina_Bool ret = EINA_FALSE; - Eina_Iterator *itr; - - _class_env_create(class, NULL, &class_env); - - Eina_Strbuf *tmpbuf = eina_strbuf_new(); - Eina_Strbuf *str_bodyf = eina_strbuf_new(); - - if ((itr = eolian_class_implements_get(class))) - { - const Eolian_Implement *impl; - EINA_ITERATOR_FOREACH(itr, impl) - { - if (eolian_implement_class_get(impl) != class) - continue; - Eolian_Function_Type ftype = EOLIAN_UNRESOLVED; - const Eolian_Function *fid = eolian_implement_function_get(impl, &ftype); - if (eolian_function_is_beta(fid)) - continue; - switch (ftype) - { - case EOLIAN_PROP_GET: case EOLIAN_PROP_SET: - _eapi_func_generate(class, fid, ftype, str_bodyf); - break; - case EOLIAN_PROPERTY: - _eapi_func_generate(class, fid, EOLIAN_PROP_SET, str_bodyf); - _eapi_func_generate(class, fid, EOLIAN_PROP_GET, str_bodyf); - break; - default: - _eapi_func_generate(class, fid, EOLIAN_METHOD, str_bodyf); - break; - } - } - eina_iterator_free(itr); - } - - eina_strbuf_append(buf, eina_strbuf_string_get(str_bodyf)); - - ret = EINA_TRUE; - eina_strbuf_free(tmpbuf); - eina_strbuf_free(str_bodyf); - - return ret; -} diff --git a/src/bin/eolian/legacy_generator.h b/src/bin/eolian/legacy_generator.h deleted file mode 100644 index 0a69c96984..0000000000 --- a/src/bin/eolian/legacy_generator.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef __EOLIAN_LEGACY_GENERATOR_H -#define __EOLIAN_LEGACY_GENERATOR_H - -#include - -/* - * @brief Generate legacy EAPI header for Eo class - * - * This function needs to be used in case we want to generate a function - * from scratch. - * There will not be respect of the order of the Eo Op Ids. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool legacy_header_generate(const Eolian_Class *class, Eina_Strbuf *buf); - -/* - * @brief Generate C source code for Eo class - * - * This function needs to be used to generate C source code. It is generating - * code from scratch. - * - * @param[in] classname class name - * @param[inout] buf buffer to fill - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool legacy_source_generate(const Eolian_Class *class, Eina_Strbuf *buf); - -#endif - diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c deleted file mode 100644 index 55c9399937..0000000000 --- a/src/bin/eolian/main.c +++ /dev/null @@ -1,407 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#include - -#include "Eolian.h" -#include "legacy_generator.h" -#include "eo_generator.h" -#include "impl_generator.h" -#include "types_generator.h" -#include "common_funcs.h" - -static Eina_Strbuf * -_include_guard_enclose(const char *fname, const char *suffix, Eina_Strbuf *fbody) -{ - if (!fbody || !eina_strbuf_string_get(fbody)) - return fbody; - - if (!suffix) - suffix = ""; - - char incname[255]; - memset(incname, 0, sizeof(incname)); - strncpy (incname, fname, sizeof(incname) - 1); - char *p = incname; - eina_str_toupper(&p); - - Eina_Strbuf *incguard = eina_strbuf_new(); - eina_strbuf_append_printf(incguard, "#ifndef _%s_%s\n#define _%s_%s\n\n", - incname, suffix, incname, suffix); - eina_strbuf_replace_all(incguard, ".", "_"); - eina_strbuf_append(incguard, eina_strbuf_string_get(fbody)); - eina_strbuf_append(incguard, "\n#endif\n"); - eina_strbuf_free(fbody); - return incguard; -} - -static const char * -_filename_get(const char *path) -{ - if (!path) - return NULL; - const char *ret = strrchr(path, '/'); - if (!ret) - return path; - return ret + 1; -} - -static Eina_Bool -_read_file(const char *filename, Eina_Strbuf **buf) -{ - FILE *fd = fopen(filename, "rb"); - if (!fd) - { - *buf = eina_strbuf_new(); - return EINA_TRUE; - } - - fseek(fd, 0, SEEK_END); - long file_size = ftell(fd); - if (file_size < 0) - { - fprintf(stderr, "eolian: could not get length of '%s'\n", filename); - fclose(fd); - return EINA_FALSE; - } - fseek(fd, 0, SEEK_SET); - - char *content = malloc(file_size + 1); - if (!content) - { - fprintf(stderr, "eolian: could not allocate memory for '%s'\n", filename); - fclose(fd); - return EINA_FALSE; - } - - long actual_size = (long)fread(content, 1, file_size, fd); - if (actual_size != file_size) - { - fprintf(stderr, "eolian: could not read %ld bytes from '%s' (read %ld bytes)\n", - file_size, filename, actual_size); - free(content); - fclose(fd); - return EINA_FALSE; - } - - content[file_size] = '\0'; - fclose(fd); - *buf = eina_strbuf_manage_new_length(content, file_size); - return EINA_TRUE; -} - -static Eina_Bool -_write_file(const char *filename, const Eina_Strbuf *buffer, Eina_Bool append) -{ - FILE *fd = fopen(filename, append ? "ab" : "wb"); - if (!fd) - { - fprintf(stderr, "eolian: could not open '%s' for writing (%s)\n", - filename, strerror(errno)); - return EINA_FALSE; - } - - Eina_Bool ret = EINA_TRUE; - size_t blen = eina_strbuf_length_get(buffer); - - if (!blen) - goto end; - - if (fwrite(eina_strbuf_string_get(buffer), 1, blen, fd) != blen) - { - fprintf(stderr, "eolian: could not write '%s' (%s)\n", - filename, strerror(errno)); - ret = EINA_FALSE; - } - -end: - fclose(fd); - return ret; -} - -static Eina_Bool -_generate_header(const char *outf, const char *inf, Eina_Bool legacy) -{ - Eina_Strbuf *buf = eina_strbuf_new(); - - if (!types_header_generate(inf, buf, EINA_TRUE, legacy)) - { - fprintf(stderr, "eolian: could not generate types of '%s'\n", inf); - eina_strbuf_free(buf); - return EINA_FALSE; - } - - buf = _include_guard_enclose(inf, "TYPES", buf); - - Eina_Strbuf *ctbuf = eina_strbuf_new(); - if (types_class_typedef_generate(inf, ctbuf)) - { - ctbuf = _include_guard_enclose(inf, "CLASS_TYPE", ctbuf); - eina_strbuf_append_char(ctbuf, '\n'); - eina_strbuf_prepend(buf, eina_strbuf_string_get(ctbuf)); - } - eina_strbuf_free(ctbuf); - - const Eolian_Class *cl = eolian_class_get_by_file(inf); - if (cl) - { - Eina_Bool gret = legacy ? legacy_header_generate(cl, buf) - : eo_header_generate(cl, buf); - if (!gret) - { - fprintf(stderr, "eolian: could not generate header for '%s'\n", - eolian_class_name_get(cl)); - eina_strbuf_free(buf); - return EINA_FALSE; - } - } - - if (cl || !legacy) - { - buf = _include_guard_enclose(_filename_get(outf), NULL, buf); - if (_write_file(outf, buf, EINA_FALSE)) - { - eina_strbuf_free(buf); - return EINA_TRUE; - } - } - - eina_strbuf_free(buf); - return EINA_FALSE; -} - -static Eina_Bool -_generate_stub_header(const char *outf, const char *inf) -{ - Eina_Strbuf *buf = eina_strbuf_new(); - - if (!types_header_generate(inf, buf, EINA_FALSE, EINA_FALSE)) - { - fprintf(stderr, "eolian: could not generate types of '%s'\n", inf); - eina_strbuf_free(buf); - return EINA_FALSE; - } - - Eina_Strbuf *ctbuf = eina_strbuf_new(); - if (types_class_typedef_generate(inf, ctbuf)) - { - eina_strbuf_append_char(ctbuf, '\n'); - eina_strbuf_prepend(buf, eina_strbuf_string_get(ctbuf)); - } - eina_strbuf_free(ctbuf); - - buf = _include_guard_enclose(_filename_get(outf), "STUBS", buf); - - Eina_Bool ret = _write_file(outf, buf, EINA_FALSE); - eina_strbuf_free(buf); - return ret; -} - -static Eina_Bool -_generate_c(const char *outf, const char *inf, Eina_Bool legacy) -{ - Eina_Strbuf *eobuf = eina_strbuf_new(), - *lgbuf = eina_strbuf_new(); - - const Eolian_Class *cl = eolian_class_get_by_file(inf); - if (cl) - { - if (!eo_source_generate(cl, eobuf)) - { - fprintf(stderr, "eolian: could not generate source for '%s'\n", - eolian_class_name_get(cl)); - eina_strbuf_free(eobuf); - eina_strbuf_free(lgbuf); - return EINA_FALSE; - } - - if (legacy && !legacy_source_generate(cl, lgbuf)) - { - fprintf(stderr, "eolian: could not generate source for '%s'\n", - eolian_class_name_get(cl)); - eina_strbuf_free(eobuf); - eina_strbuf_free(lgbuf); - return EINA_FALSE; - } - } - - Eina_Bool ret = _write_file(outf, eobuf, EINA_FALSE) && - _write_file(outf, lgbuf, EINA_TRUE); - eina_strbuf_free(eobuf); - eina_strbuf_free(lgbuf); - return ret; -} - -static Eina_Bool -_generate_impl(const char *outf, const char *inf) -{ - const Eolian_Class *cl = eolian_class_get_by_file(inf); - if (!cl) - return EINA_FALSE; - - Eina_Strbuf *buf = NULL; - if (!_read_file(outf, &buf)) - return EINA_FALSE; - - if (!impl_source_generate(cl, buf)) - { - fprintf(stderr, "eolian: could not generate source for '%s'\n", - eolian_class_name_get(cl)); - eina_strbuf_free(buf); - return EINA_FALSE; - } - - Eina_Bool ret = _write_file(outf, buf, EINA_FALSE); - eina_strbuf_free(buf); - return ret; -} - -enum -{ - GEN_NOTHING = 0, - GEN_H, - GEN_H_STUB, - GEN_C, - GEN_C_IMPL -}; - -int -main(int argc, char **argv) -{ - int gen_what = GEN_NOTHING, do_legacy = 0, ret = 1, silent_types = 0; - Eina_Bool help = EINA_FALSE; - const char *outf = NULL; - - eina_init(); - eolian_init(); - - const char *dom = "eolian_gen"; - _eolian_gen_log_dom = eina_log_domain_register(dom, EINA_COLOR_GREEN); - if (_eolian_gen_log_dom < 0) - { - EINA_LOG_ERR("Could not register log domain: %s", dom); - goto end; - } - - eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); - - struct option opts[] = { - { "help", no_argument, NULL, 'h' }, - { "gh", no_argument, &gen_what, GEN_H }, - { "gc", no_argument, &gen_what, GEN_C }, - { "gi", no_argument, &gen_what, GEN_C_IMPL }, - { "gs", no_argument, &gen_what, GEN_H_STUB }, - { "output", required_argument, NULL, 'o' }, - { "legacy", no_argument, &do_legacy, 1 }, - { "include", required_argument, NULL, 'I' }, - { "silent-types", no_argument, &silent_types, 1 }, - { NULL, 0, NULL, 0 } - }; - - for (int opt; (opt = getopt_long(argc, argv, "vho:I:", opts, NULL)) != -1; ) - switch (opt) - { - case 0: break; - case 'o': - outf = optarg; - break; - case 'h': - help = EINA_TRUE; - break; - case 'I': - if (!eolian_directory_scan(optarg)) - { - fprintf(stderr, "eolian: could not scan '%s'\n", optarg); - goto end; - } - break; - default: - help = EINA_TRUE; - break; - } - - if (help) - { - printf("Usage: %s [-h/--help] [-I/--include input_dir] [--legacy] [--gh|--gs|--gc|--gi] [--output/-o outfile] file.eo ... \n", argv[0]); - printf(" --help/-h Print that help\n"); - printf(" --include/-I Include 'input_dir' as directory to search .eo files into\n"); - printf(" --output/-o Force output filename to 'outfile'\n"); - printf(" --gh Generate C header file [.h]\n"); - printf(" --gs Generate C type stubs [.h]\n"); - printf(" --gc Generate C source file [.c]\n"); - printf(" --gi Generate C implementation source file [.c]. The output will be a series of functions that have to be filled.\n"); - printf(" --legacy Generate legacy\n"); - printf(" --silent-types Silence type validation\n"); - ret = 0; - goto end; - } - - const char *eof = argv[optind++]; - if (!eof) - { - fprintf(stderr, "eolian: no input file\n"); - goto end; - } - - if (!eolian_file_parse(eof)) - { - fprintf(stderr, "eolian: could not parse file '%s'\n", eof); - goto end; - } - - if (!eolian_database_validate(silent_types)) - { - fprintf(stderr, "eolian: error validating database\n"); - goto end; - } - - char *eofc = strdup(eof); - char *eobn = basename(eofc); - - if (gen_what) - { - if (!outf) - { - fprintf(stderr, "eolian: no output file\n"); - free(eofc); - goto end; - } - switch (gen_what) - { - case GEN_H: - INF("Generating header file %s\n", outf); - ret = !_generate_header(outf, eobn, do_legacy); - break; - case GEN_H_STUB: - INF("Generating stub header file %s\n", outf); - ret = !_generate_stub_header(outf, eobn); - break; - case GEN_C: - INF("Generating source file %s\n", outf); - ret = !_generate_c(outf, eobn, do_legacy); - break; - case GEN_C_IMPL: - INF("Generating user source file %s\n", outf); - ret = !_generate_impl(outf, eobn); - break; - default: - ERR("Wrong generation option\n"); - break; - } - } - else - ret = 0; - - free(eofc); - -end: - eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_START, EINA_LOG_STATE_SHUTDOWN); - eina_log_domain_unregister(_eolian_gen_log_dom); - eolian_shutdown(); - eina_shutdown(); - return ret; -} diff --git a/src/bin/eolian/types_generator.c b/src/bin/eolian/types_generator.c deleted file mode 100644 index 54ed1d75b5..0000000000 --- a/src/bin/eolian/types_generator.c +++ /dev/null @@ -1,225 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include - -#include "Eolian.h" -#include "types_generator.h" -#include "docs_generator.h" -#include "common_funcs.h" - -static char * -_concat_name(const Eolian_Typedecl *tp) -{ - const char *name; - char *str = NULL; - Eina_Strbuf *buf = eina_strbuf_new(); - Eina_Iterator *itr = eolian_typedecl_namespaces_get(tp); - EINA_ITERATOR_FOREACH(itr, name) - if (name) eina_strbuf_append_printf(buf, "%s_", name); - eina_iterator_free(itr); - name = eolian_typedecl_name_get(tp); - if (name) eina_strbuf_append_printf(buf, "%s", name); - if (eina_strbuf_length_get(buf)) - { - char *tmp = str = eina_strbuf_string_steal(buf); - *tmp = toupper(*tmp); - while (*tmp) if (*tmp++ == '_' && *tmp) *tmp = toupper(*tmp); - } - eina_strbuf_free(buf); - return str; -} - -static Eina_Strbuf * -_type_generate(const Eolian_Typedecl *tp, Eina_Bool full, Eina_Bool use_legacy) -{ - char *grp = strdup(eolian_typedecl_full_name_get(tp)); - char *p = strrchr(grp, '.'); - if (p) *p = '\0'; - Eina_Strbuf *buf = docs_generate_full(eolian_typedecl_documentation_get(tp), - grp, 0, use_legacy); - free(grp); - if (!buf) buf = eina_strbuf_new(); - else eina_strbuf_append_char(buf, '\n'); - Eolian_Typedecl_Type tp_type = eolian_typedecl_type_get(tp); - switch(tp_type) - { - case EOLIAN_TYPEDECL_ALIAS: - { - Eina_Stringshare *tn = eolian_typedecl_c_type_get(tp); - eina_strbuf_append(buf, tn); - eina_stringshare_del(tn); - break; - } - case EOLIAN_TYPEDECL_STRUCT: - case EOLIAN_TYPEDECL_STRUCT_OPAQUE: - { - const Eolian_Struct_Type_Field *member; - char *name = _concat_name(tp); - if (tp_type == EOLIAN_TYPEDECL_STRUCT_OPAQUE || !full) - { - eina_strbuf_append_printf(buf, "typedef struct _%s %s", name, name); - free(name); - break; - } - eina_strbuf_append_printf(buf, "typedef struct _%s\n{\n", name); - Eina_Iterator *members = eolian_typedecl_struct_fields_get(tp); - EINA_ITERATOR_FOREACH(members, member) - { - const Eolian_Type *type = eolian_typedecl_struct_field_type_get(member); - Eina_Stringshare *c_type = NULL; - if (eolian_type_type_get(type) == EOLIAN_TYPE_STATIC_ARRAY) - { - c_type = eolian_type_c_type_get(eolian_type_base_type_get(type)); - eina_strbuf_append_printf(buf, " %s%s%s[%zu];", - c_type, strchr(c_type, '*')?"":" ", - eolian_typedecl_struct_field_name_get(member), - eolian_type_array_size_get(type)); - } - else - { - c_type = eolian_type_c_type_get(type); - eina_strbuf_append_printf(buf, " %s%s%s;", - c_type, strchr(c_type, '*')?"":" ", - eolian_typedecl_struct_field_name_get(member)); - } - eina_stringshare_del(c_type); - const Eolian_Documentation *fdoc - = eolian_typedecl_struct_field_documentation_get(member); - if (fdoc) - { - const char *nl = strrchr(eina_strbuf_string_get(buf), '\n'); - if (nl) - { - Eina_Strbuf *fbuf = docs_generate_full(fdoc, NULL, strlen(nl), use_legacy); - if (fbuf) - eina_strbuf_append_printf(buf, " %s", - eina_strbuf_string_get(fbuf)); - eina_strbuf_free(fbuf); - } - } - eina_strbuf_append(buf, "\n"); - } - eina_iterator_free(members); - eina_strbuf_append_printf(buf, "} %s", name); - free(name); - break; - } - case EOLIAN_TYPEDECL_ENUM: - { - const Eolian_Enum_Type_Field *member; - if (!full) - break; - char *name = _concat_name(tp); - eina_strbuf_append_printf(buf, "typedef enum\n{\n"); - Eina_Iterator *members = eolian_typedecl_enum_fields_get(tp); - Eina_Bool next = eina_iterator_next(members, (void**)&member); - while (next) - { - const Eolian_Expression *value = eolian_typedecl_enum_field_value_get(member, EINA_FALSE); - Eina_Stringshare *membn = eolian_typedecl_enum_field_c_name_get(member); - if (!value) - eina_strbuf_append_printf(buf, " %s", membn); - else - { - Eolian_Value val = eolian_expression_eval(value, EOLIAN_MASK_INT); - const char *lit = eolian_expression_value_to_literal(&val); - eina_strbuf_append_printf(buf, " %s = %s", membn, lit); - const char *exp = eolian_expression_serialize(value); - if (exp && strcmp(lit, exp)) - { - eina_strbuf_append_printf(buf, " /* %s */", exp); - eina_stringshare_del(exp); - } - eina_stringshare_del(lit); - } - eina_stringshare_del(membn); - const Eolian_Documentation *fdoc - = eolian_typedecl_enum_field_documentation_get(member); - next = eina_iterator_next(members, (void**)&member); - if (next) - eina_strbuf_append(buf, ","); - if (fdoc) - { - const char *nl = strrchr(eina_strbuf_string_get(buf), '\n'); - if (nl) - { - Eina_Strbuf *fbuf = docs_generate_full(fdoc, NULL, strlen(nl), use_legacy); - if (fbuf) - eina_strbuf_append_printf(buf, " %s", - eina_strbuf_string_get(fbuf)); - eina_strbuf_free(fbuf); - } - } - eina_strbuf_append(buf, "\n"); - } - eina_strbuf_append_printf(buf, "} %s", name); - free(name); - eina_iterator_free(members); - break; - } - default: - { - eina_strbuf_reset(buf); - } - } - return buf; -} - -Eina_Bool -types_header_generate(const char *eo_filename, Eina_Strbuf *buf, Eina_Bool full, Eina_Bool use_legacy) -{ - const Eolian_Declaration *decl; - - Eina_Iterator *itr = eolian_declarations_get_by_file(eo_filename); - EINA_ITERATOR_FOREACH(itr, decl) - { - Eolian_Declaration_Type dt = eolian_declaration_type_get(decl); - if (dt != EOLIAN_DECL_ALIAS && - dt != EOLIAN_DECL_STRUCT && - dt != EOLIAN_DECL_ENUM) - continue; - - if (dt == EOLIAN_DECL_ENUM && !full) - continue; - - const Eolian_Typedecl *tp = eolian_declaration_data_type_get(decl); - if (!tp || eolian_typedecl_is_extern(tp)) - continue; - - if (eolian_typedecl_type_get(tp) == EOLIAN_TYPEDECL_ALIAS) - { - const Eolian_Type *btp = eolian_typedecl_base_type_get(tp); - if (eolian_type_type_get(btp) == EOLIAN_TYPE_UNDEFINED) - continue; - } - - Eina_Strbuf *tbuf = _type_generate(tp, full, use_legacy); - if (tbuf) - { - eina_strbuf_append(buf, eina_strbuf_string_get(tbuf)); - eina_strbuf_append(buf, ";\n\n"); - eina_strbuf_free(tbuf); - } - } - eina_iterator_free(itr); - - return EINA_TRUE; -} - -Eina_Bool -types_class_typedef_generate(const char *eo_filename, Eina_Strbuf *buf) -{ - const Eolian_Class *class = eolian_class_get_by_file(eo_filename); - if (!class) - return EINA_FALSE; - - static _eolian_class_vars class_env; - _class_env_create(class, NULL, &class_env); - - eina_strbuf_append_printf(buf, "typedef Eo %s;\n", class_env.full_classname); - return EINA_TRUE; -} diff --git a/src/bin/eolian/types_generator.h b/src/bin/eolian/types_generator.h deleted file mode 100644 index 5096614217..0000000000 --- a/src/bin/eolian/types_generator.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef TYPES_GENERATOR_H -#define TYPES_GENERATOR_H - -#include - -/* - * @brief Generate the header code for the types of a specific file. - * - * @param[in] eo_filename Eo filename - * @param[inout] buf buffer to fill - * @param[in]full whether to generate full type definitions - * @param[in] use_legacy whether to use legacy names - * - * @return EINA_TRUE on success, EINA_FALSE on error. - * - */ -Eina_Bool types_header_generate(const char *eo_filename, Eina_Strbuf *buf, Eina_Bool full, Eina_Bool use_legacy); - -Eina_Bool types_class_typedef_generate(const char *eo_filename, Eina_Strbuf *buf); - -#endif -