eolian: improve function_full_c_name_get API

It's now generalized to work properly with legacy functions
as well as correctly append suffixes. Thus, it can be easily
used with the documentation generator and in other places.

@feature
This commit is contained in:
Daniel Kolesa 2015-07-08 12:09:56 +01:00
parent ef65806ce4
commit 825349c7b8
13 changed files with 136 additions and 98 deletions

View File

@ -76,21 +76,7 @@ void
_class_func_env_create(const Eolian_Class *class, const char *funcname, Eolian_Function_Type ftype, _eolian_class_func_vars *env) _class_func_env_create(const Eolian_Class *class, const char *funcname, Eolian_Function_Type ftype, _eolian_class_func_vars *env)
{ {
char *p; char *p;
const char *ret;
const char *suffix = "";
const char *legacy = NULL;
const Eolian_Function *funcid = eolian_class_function_get_by_name(class, funcname, ftype); const Eolian_Function *funcid = eolian_class_function_get_by_name(class, funcname, ftype);
if (ftype == EOLIAN_PROP_GET)
{
suffix = "_get";
legacy = eolian_function_legacy_get(funcid, ftype);
}
else if (ftype == EOLIAN_PROP_SET)
{
suffix = "_set";
legacy = eolian_function_legacy_get(funcid, ftype);
}
else legacy = eolian_function_legacy_get(funcid, EOLIAN_METHOD);
_eolian_class_vars tmp_env; _eolian_class_vars tmp_env;
_class_env_create(class, NULL, &tmp_env); _class_env_create(class, NULL, &tmp_env);
@ -98,28 +84,21 @@ _class_func_env_create(const Eolian_Class *class, const char *funcname, Eolian_F
p = strncpy(env->upper_func, funcname, PATH_MAX - 1); p = strncpy(env->upper_func, funcname, PATH_MAX - 1);
eina_str_toupper(&p); eina_str_toupper(&p);
ret = eolian_function_full_c_name_get(funcid); Eolian_Function_Type aftype = ftype;
sprintf(p = env->upper_eo_func, "%s%s", ret, suffix); if (aftype == EOLIAN_PROPERTY) aftype = EOLIAN_METHOD;
Eina_Stringshare *fname = eolian_function_full_c_name_get(funcid, aftype, EINA_FALSE);
strcpy(p = env->upper_eo_func, fname);
eina_str_toupper(&p); eina_str_toupper(&p);
sprintf(p = env->lower_eo_func, "%s%s", ret, suffix); strcpy(p = env->lower_eo_func, fname);
eina_str_tolower(&p); eina_str_tolower(&p);
eina_stringshare_del(ret); eina_stringshare_del(fname);
Eina_Stringshare *lname = eolian_function_full_c_name_get(funcid, aftype, EINA_TRUE);
env->legacy_func[0] = '\0'; env->legacy_func[0] = '\0';
if (legacy && !strcmp(legacy, "null")) goto end; if (!lname) return;
if (legacy) strcpy(p = env->legacy_func, lname);
{ eina_stringshare_del(lname);
sprintf(p = env->legacy_func, "%s", legacy);
goto end;
}
legacy = eolian_class_legacy_prefix_get(class);
if (legacy && !strcmp(legacy, "null")) goto end;
sprintf(env->legacy_func, "%s_%s%s", legacy?legacy:tmp_env.lower_classname, funcname, suffix);
end:
return;
} }
void void

View File

@ -23,7 +23,7 @@ _indent_line(Eina_Strbuf *buf, int ind)
: DOC_LINE_LIMIT) : DOC_LINE_LIMIT)
static void static void
_generate_ref(const char *refn, Eina_Strbuf *wbuf) _generate_ref(const char *refn, Eina_Strbuf *wbuf, Eina_Bool use_legacy)
{ {
const Eolian_Declaration *decl = eolian_declaration_get_by_name(refn); const Eolian_Declaration *decl = eolian_declaration_get_by_name(refn);
if (decl) if (decl)
@ -46,7 +46,7 @@ _generate_ref(const char *refn, Eina_Strbuf *wbuf)
if (tp) if (tp)
{ {
if (!eolian_type_struct_field_get(tp, sfx + 1)) goto noref; if (!eolian_type_struct_field_get(tp, sfx + 1)) goto noref;
_generate_ref(bname, wbuf); _generate_ref(bname, wbuf, use_legacy);
eina_strbuf_append(wbuf, sfx); eina_strbuf_append(wbuf, sfx);
eina_stringshare_del(bname); eina_stringshare_del(bname);
return; return;
@ -57,7 +57,7 @@ _generate_ref(const char *refn, Eina_Strbuf *wbuf)
{ {
const Eolian_Enum_Type_Field *efl = eolian_type_enum_field_get(tp, sfx + 1); const Eolian_Enum_Type_Field *efl = eolian_type_enum_field_get(tp, sfx + 1);
if (!efl) goto noref; if (!efl) goto noref;
_generate_ref(bname, wbuf); _generate_ref(bname, wbuf, use_legacy);
Eina_Stringshare *str = eolian_type_enum_field_c_name_get(efl); Eina_Stringshare *str = eolian_type_enum_field_c_name_get(efl);
eina_strbuf_append_char(wbuf, '.'); eina_strbuf_append_char(wbuf, '.');
eina_strbuf_append(wbuf, str); eina_strbuf_append(wbuf, str);
@ -101,14 +101,9 @@ _generate_ref(const char *refn, Eina_Strbuf *wbuf)
if (!fn) goto noref; if (!fn) goto noref;
Eina_Stringshare *fcn = eolian_function_full_c_name_get(fn); Eina_Stringshare *fcn = eolian_function_full_c_name_get(fn, ftype, use_legacy);
eina_strbuf_append(wbuf, fcn); eina_strbuf_append(wbuf, fcn);
eina_stringshare_del(fcn); eina_stringshare_del(fcn);
if ((ftype == EOLIAN_PROP_GET) || (ftype == EOLIAN_PROPERTY))
eina_strbuf_append(wbuf, "_get");
else if (ftype == EOLIAN_PROP_SET)
eina_strbuf_append(wbuf, "_set");
return; return;
noref: noref:
eina_strbuf_append(wbuf, refn); eina_strbuf_append(wbuf, refn);
@ -116,7 +111,7 @@ noref:
int int
_append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf, _append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf,
Eina_Strbuf *wbuf) Eina_Strbuf *wbuf, Eina_Bool use_legacy)
{ {
while (*desc) while (*desc)
{ {
@ -140,7 +135,7 @@ _append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf,
++desc; ++desc;
if (*(desc - 1) == '.') --desc; if (*(desc - 1) == '.') --desc;
Eina_Stringshare *refn = eina_stringshare_add_length(ref, desc - ref); Eina_Stringshare *refn = eina_stringshare_add_length(ref, desc - ref);
_generate_ref(refn, wbuf); _generate_ref(refn, wbuf, use_legacy);
eina_stringshare_del(refn); eina_stringshare_del(refn);
} }
else else
@ -204,12 +199,12 @@ _append_since(const char *since, int indent, int curl, Eina_Strbuf *buf)
void void
_gen_doc_brief(const char *summary, const char *since, int indent, _gen_doc_brief(const char *summary, const char *since, int indent,
Eina_Strbuf *buf) Eina_Strbuf *buf, Eina_Bool use_legacy)
{ {
int curl = 4 + indent; int curl = 4 + indent;
Eina_Strbuf *wbuf = eina_strbuf_new(); Eina_Strbuf *wbuf = eina_strbuf_new();
eina_strbuf_append(buf, "/** "); eina_strbuf_append(buf, "/** ");
curl = _append_section(summary, indent, curl, buf, wbuf); curl = _append_section(summary, indent, curl, buf, wbuf, use_legacy);
eina_strbuf_free(wbuf); eina_strbuf_free(wbuf);
curl = _append_since(since, indent, curl, buf); curl = _append_since(since, indent, curl, buf);
if ((curl + 3) > DOC_LIMIT(indent)) if ((curl + 3) > DOC_LIMIT(indent))
@ -224,7 +219,7 @@ _gen_doc_brief(const char *summary, const char *since, int indent,
void void
_gen_doc_full(const char *summary, const char *description, const char *since, _gen_doc_full(const char *summary, const char *description, const char *since,
int indent, Eina_Strbuf *buf) int indent, Eina_Strbuf *buf, Eina_Bool use_legacy)
{ {
int curl = 0; int curl = 0;
Eina_Strbuf *wbuf = eina_strbuf_new(); Eina_Strbuf *wbuf = eina_strbuf_new();
@ -232,13 +227,13 @@ _gen_doc_full(const char *summary, const char *description, const char *since,
curl += _indent_line(buf, indent); curl += _indent_line(buf, indent);
eina_strbuf_append(buf, " * @brief "); eina_strbuf_append(buf, " * @brief ");
curl += sizeof(" * @brief ") - 1; curl += sizeof(" * @brief ") - 1;
_append_section(summary, indent, curl, buf, wbuf); _append_section(summary, indent, curl, buf, wbuf, use_legacy);
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
_indent_line(buf, indent); _indent_line(buf, indent);
eina_strbuf_append(buf, " *\n"); eina_strbuf_append(buf, " *\n");
curl = _indent_line(buf, indent); curl = _indent_line(buf, indent);
eina_strbuf_append(buf, " * "); eina_strbuf_append(buf, " * ");
_append_section(description, indent, curl + 3, buf, wbuf); _append_section(description, indent, curl + 3, buf, wbuf, use_legacy);
curl = _append_since(since, indent, curl, buf); curl = _append_since(since, indent, curl, buf);
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
_indent_line(buf, indent); _indent_line(buf, indent);
@ -247,7 +242,8 @@ _gen_doc_full(const char *summary, const char *description, const char *since,
} }
Eina_Strbuf * Eina_Strbuf *
docs_generate_full(const Eolian_Documentation *doc, int indent) docs_generate_full(const Eolian_Documentation *doc, int indent,
Eina_Bool use_legacy)
{ {
if (!doc) return NULL; if (!doc) return NULL;
@ -257,14 +253,15 @@ docs_generate_full(const Eolian_Documentation *doc, int indent)
Eina_Strbuf *buf = eina_strbuf_new(); Eina_Strbuf *buf = eina_strbuf_new();
if (!desc) if (!desc)
_gen_doc_brief(sum, since, indent, buf); _gen_doc_brief(sum, since, indent, buf, use_legacy);
else else
_gen_doc_full(sum, desc, since, indent, buf); _gen_doc_full(sum, desc, since, indent, buf, use_legacy);
return buf; return buf;
} }
Eina_Strbuf * Eina_Strbuf *
docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, int indent) 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 *par = NULL;
const Eolian_Function_Parameter *vpar = NULL; const Eolian_Function_Parameter *vpar = NULL;
@ -376,7 +373,8 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, i
/* only summary, nothing else; generate standard brief doc */ /* only summary, nothing else; generate standard brief doc */
if (!desc && !par && !vpar && !rdoc && (ftype == EOLIAN_METHOD || !pdoc)) if (!desc && !par && !vpar && !rdoc && (ftype == EOLIAN_METHOD || !pdoc))
{ {
_gen_doc_brief(sum ? sum : "No description supplied.", since, indent, buf); _gen_doc_brief(sum ? sum : "No description supplied.", since, indent,
buf, use_legacy);
return buf; return buf;
} }
@ -387,7 +385,7 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, i
eina_strbuf_append(buf, " * @brief "); eina_strbuf_append(buf, " * @brief ");
curl += sizeof(" * @brief ") - 1; curl += sizeof(" * @brief ") - 1;
_append_section(sum ? sum : "No description supplied.", _append_section(sum ? sum : "No description supplied.",
indent, curl, buf, wbuf); indent, curl, buf, wbuf, use_legacy);
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
if (desc || since || par || rdoc || pdoc) if (desc || since || par || rdoc || pdoc)
@ -400,7 +398,7 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, i
{ {
curl = _indent_line(buf, indent); curl = _indent_line(buf, indent);
eina_strbuf_append(buf, " * "); eina_strbuf_append(buf, " * ");
_append_section(desc, indent, curl + 3, buf, wbuf); _append_section(desc, indent, curl + 3, buf, wbuf, use_legacy);
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
if (par || rdoc || pdoc || since) if (par || rdoc || pdoc || since)
{ {
@ -415,7 +413,7 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, i
curl = _indent_line(buf, indent); curl = _indent_line(buf, indent);
eina_strbuf_append(buf, " * "); eina_strbuf_append(buf, " * ");
_append_section(eolian_documentation_summary_get(pdoc), indent, _append_section(eolian_documentation_summary_get(pdoc), indent,
curl + 3, buf, wbuf); curl + 3, buf, wbuf, use_legacy);
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
if (pdesc) if (pdesc)
{ {
@ -423,7 +421,7 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, i
eina_strbuf_append(buf, " *\n"); eina_strbuf_append(buf, " *\n");
curl = _indent_line(buf, indent); curl = _indent_line(buf, indent);
eina_strbuf_append(buf, " * "); eina_strbuf_append(buf, " * ");
_append_section(pdesc, indent, curl + 3, buf, wbuf); _append_section(pdesc, indent, curl + 3, buf, wbuf, use_legacy);
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
} }
if (par || rdoc || since) if (par || rdoc || since)
@ -467,7 +465,7 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, i
eina_strbuf_append_char(buf, ' '); eina_strbuf_append_char(buf, ' ');
curl += 1; curl += 1;
_append_section(eolian_documentation_summary_get(adoc), _append_section(eolian_documentation_summary_get(adoc),
indent, curl, buf, wbuf); indent, curl, buf, wbuf, use_legacy);
} }
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
@ -500,7 +498,7 @@ docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, i
eina_strbuf_append(buf, " * @return "); eina_strbuf_append(buf, " * @return ");
curl += sizeof(" * @return ") - 1; curl += sizeof(" * @return ") - 1;
_append_section(eolian_documentation_summary_get(rdoc), indent, curl, _append_section(eolian_documentation_summary_get(rdoc), indent, curl,
buf, wbuf); buf, wbuf, use_legacy);
eina_strbuf_append_char(buf, '\n'); eina_strbuf_append_char(buf, '\n');
if (since) if (since)
{ {

View File

@ -9,11 +9,12 @@
* *
* @param[in] doc the documentation * @param[in] doc the documentation
* @param[in] indent by how many spaces to indent the comment from second line * @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 * @return A documentation comment
* *
*/ */
Eina_Strbuf *docs_generate_full(const Eolian_Documentation *doc, int indent); Eina_Strbuf *docs_generate_full(const Eolian_Documentation *doc, int indent, Eina_Bool use_legacy);
/* /*
* @brief Generate function documentation * @brief Generate function documentation
@ -21,11 +22,12 @@ Eina_Strbuf *docs_generate_full(const Eolian_Documentation *doc, int indent);
* @param[in] fid te function * @param[in] fid te function
* @param[in] type the function type (either METHOD, PROP_GET, PROP_SET) * @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] 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 * @return A documentation comment
* *
*/ */
Eina_Strbuf *docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, int indent); Eina_Strbuf *docs_generate_function(const Eolian_Function *fid, Eolian_Function_Type ftype, int indent, Eina_Bool use_legacy);
#endif #endif

View File

@ -120,7 +120,7 @@ eo_fundef_generate(const Eolian_Class *class, const Eolian_Function *func, Eolia
} }
else else
{ {
Eina_Strbuf *dbuf = docs_generate_function(func, ftype, 0); Eina_Strbuf *dbuf = docs_generate_function(func, ftype, 0, EINA_FALSE);
eina_strbuf_append(str_func, eina_strbuf_string_get(dbuf)); eina_strbuf_append(str_func, eina_strbuf_string_get(dbuf));
eina_strbuf_append_char(str_func, '\n'); eina_strbuf_append_char(str_func, '\n');
eina_strbuf_free(dbuf); eina_strbuf_free(dbuf);
@ -251,7 +251,7 @@ eo_header_generate(const Eolian_Class *class, Eina_Strbuf *buf)
if (doc) if (doc)
{ {
Eina_Strbuf *cdoc = docs_generate_full(doc, 0); Eina_Strbuf *cdoc = docs_generate_full(doc, 0, EINA_FALSE);
if (cdoc) if (cdoc)
{ {
eina_strbuf_append(buf, eina_strbuf_string_get(cdoc)); eina_strbuf_append(buf, eina_strbuf_string_get(cdoc));
@ -309,7 +309,7 @@ eo_header_generate(const Eolian_Class *class, Eina_Strbuf *buf)
if (evdoc) if (evdoc)
{ {
Eina_Strbuf *evdbuf = docs_generate_full(evdoc, 0); Eina_Strbuf *evdbuf = docs_generate_full(evdoc, 0, EINA_FALSE);
eina_strbuf_append(str_ev, eina_strbuf_string_get(evdbuf)); eina_strbuf_append(str_ev, eina_strbuf_string_get(evdbuf));
eina_strbuf_append_char(str_ev, '\n'); eina_strbuf_append_char(str_ev, '\n');
eina_strbuf_free(evdbuf); eina_strbuf_free(evdbuf);
@ -819,7 +819,6 @@ eo_source_end_generate(const Eolian_Class *class, Eina_Strbuf *buf)
Eolian_Function_Type ftype; Eolian_Function_Type ftype;
const Eolian_Function *fnid = NULL; const Eolian_Function *fnid = NULL;
const char *funcname = NULL; const char *funcname = NULL;
const char *rets;
const char *names[] = { "", "getter ", "setter " }; const char *names[] = { "", "getter ", "setter " };
@ -874,8 +873,6 @@ eo_source_end_generate(const Eolian_Class *class, Eina_Strbuf *buf)
goto end; goto end;
} }
rets = eolian_function_full_c_name_get(fnid);
const char *class_str = ""; const char *class_str = "";
if (eolian_function_is_class(fnid)) class_str = "CLASS_"; if (eolian_function_is_class(fnid)) class_str = "CLASS_";
@ -884,25 +881,32 @@ eo_source_end_generate(const Eolian_Class *class, Eina_Strbuf *buf)
case EOLIAN_PROP_SET: case EOLIAN_PROP_GET: case EOLIAN_PROPERTY: case EOLIAN_PROP_SET: case EOLIAN_PROP_GET: case EOLIAN_PROPERTY:
if (ftype != EOLIAN_PROP_GET) if (ftype != EOLIAN_PROP_GET)
{ {
eina_strbuf_append_printf(str_op, "\n EO_OP_%sFUNC_OVERRIDE(%s_set, %s_%s_set),", Eina_Stringshare *rets = eolian_function_full_c_name_get(fnid, EOLIAN_PROP_SET, EINA_FALSE);
eina_strbuf_append_printf(str_op, "\n EO_OP_%sFUNC_OVERRIDE(%s, %s_%s_set),",
class_str, rets, implname, funcname); class_str, rets, implname, funcname);
eo_bind_func_generate(class, fnid, EOLIAN_PROP_SET, str_bodyf, impl_desc, &impl_env); eo_bind_func_generate(class, fnid, EOLIAN_PROP_SET, str_bodyf, impl_desc, &impl_env);
eina_stringshare_del(rets);
} }
if (ftype != EOLIAN_PROP_SET) if (ftype != EOLIAN_PROP_SET)
{ {
eina_strbuf_append_printf(str_op, "\n EO_OP_%sFUNC_OVERRIDE(%s_get, %s_%s_get),", Eina_Stringshare *rets = eolian_function_full_c_name_get(fnid, EOLIAN_PROP_GET, EINA_FALSE);
eina_strbuf_append_printf(str_op, "\n EO_OP_%sFUNC_OVERRIDE(%s, %s_%s_get),",
class_str, rets, implname, funcname); class_str, rets, implname, funcname);
eo_bind_func_generate(class, fnid, EOLIAN_PROP_GET, str_bodyf, impl_desc, &impl_env); eo_bind_func_generate(class, fnid, EOLIAN_PROP_GET, str_bodyf, impl_desc, &impl_env);
eina_stringshare_del(rets);
} }
break; break;
default: default:
eina_strbuf_append_printf(str_op, "\n EO_OP_%sFUNC_OVERRIDE(%s, %s_%s),", {
class_str, rets, implname, funcname); Eina_Stringshare *rets = eolian_function_full_c_name_get(fnid, ftype, EINA_FALSE);
eo_bind_func_generate(class, fnid, ftype, str_bodyf, impl_desc, &impl_env); eina_strbuf_append_printf(str_op, "\n EO_OP_%sFUNC_OVERRIDE(%s, %s_%s),",
break; class_str, rets, implname, funcname);
eo_bind_func_generate(class, fnid, ftype, str_bodyf, impl_desc, &impl_env);
eina_stringshare_del(rets);
break;
}
} }
eina_stringshare_del(rets);
} }
eina_iterator_free(itr); eina_iterator_free(itr);

View File

@ -97,7 +97,7 @@ _eapi_decl_func_generate(const Eolian_Class *class, const Eolian_Function *funci
} }
else else
{ {
Eina_Strbuf *dbuf = docs_generate_function(funcid, ftype, 0); Eina_Strbuf *dbuf = docs_generate_function(funcid, ftype, 0, EINA_TRUE);
eina_strbuf_append_char(fbody, '\n'); eina_strbuf_append_char(fbody, '\n');
eina_strbuf_append(fbody, eina_strbuf_string_get(dbuf)); eina_strbuf_append(fbody, eina_strbuf_string_get(dbuf));
eina_strbuf_append_char(fbody, '\n'); eina_strbuf_append_char(fbody, '\n');
@ -387,7 +387,7 @@ legacy_header_generate(const Eolian_Class *class, Eina_Strbuf *buf)
const Eolian_Documentation *doc = eolian_class_documentation_get(class); const Eolian_Documentation *doc = eolian_class_documentation_get(class);
if (doc) if (doc)
{ {
Eina_Strbuf *cdoc = docs_generate_full(doc, 0); Eina_Strbuf *cdoc = docs_generate_full(doc, 0, EINA_TRUE);
if (cdoc) if (cdoc)
{ {
eina_strbuf_append(buf, eina_strbuf_string_get(cdoc)); eina_strbuf_append(buf, eina_strbuf_string_get(cdoc));

View File

@ -120,7 +120,7 @@ _generate_eo_header_file(char *filename, const char *eo_filename)
Eina_Strbuf *buffer = eina_strbuf_new(); Eina_Strbuf *buffer = eina_strbuf_new();
if (!types_header_generate(eo_filename, buffer, EINA_TRUE)) if (!types_header_generate(eo_filename, buffer, EINA_TRUE, EINA_FALSE))
{ {
fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename); fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename);
goto end; goto end;
@ -166,7 +166,7 @@ _generate_stub_header_file(char *filename, const char *eo_filename)
Eina_Strbuf *buffer = eina_strbuf_new(); Eina_Strbuf *buffer = eina_strbuf_new();
if (!types_header_generate(eo_filename, buffer, EINA_FALSE)) if (!types_header_generate(eo_filename, buffer, EINA_FALSE, EINA_FALSE))
{ {
fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename); fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename);
goto end; goto end;
@ -259,7 +259,7 @@ _generate_legacy_header_file(char *filename, const char *eo_filename)
Eina_Strbuf *buffer = eina_strbuf_new(); Eina_Strbuf *buffer = eina_strbuf_new();
if (!types_header_generate(eo_filename, buffer, EINA_TRUE)) if (!types_header_generate(eo_filename, buffer, EINA_TRUE, EINA_TRUE))
{ {
fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename); fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename);
goto end; goto end;

View File

@ -34,9 +34,9 @@ _concat_name(const Eolian_Type *tp)
} }
static Eina_Strbuf * static Eina_Strbuf *
_type_generate(const Eolian_Type *tp, Eina_Bool full) _type_generate(const Eolian_Type *tp, Eina_Bool full, Eina_Bool use_legacy)
{ {
Eina_Strbuf *buf = docs_generate_full(eolian_type_documentation_get(tp), 0); Eina_Strbuf *buf = docs_generate_full(eolian_type_documentation_get(tp), 0, use_legacy);
if (!buf) buf = eina_strbuf_new(); if (!buf) buf = eina_strbuf_new();
else eina_strbuf_append_char(buf, '\n'); else eina_strbuf_append_char(buf, '\n');
Eolian_Type_Type tp_type = eolian_type_type_get(tp); Eolian_Type_Type tp_type = eolian_type_type_get(tp);
@ -79,7 +79,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool full)
const char *nl = strrchr(eina_strbuf_string_get(buf), '\n'); const char *nl = strrchr(eina_strbuf_string_get(buf), '\n');
if (nl) if (nl)
{ {
Eina_Strbuf *fbuf = docs_generate_full(fdoc, strlen(nl)); Eina_Strbuf *fbuf = docs_generate_full(fdoc, strlen(nl), use_legacy);
if (fbuf) if (fbuf)
eina_strbuf_append_printf(buf, " %s", eina_strbuf_append_printf(buf, " %s",
eina_strbuf_string_get(fbuf)); eina_strbuf_string_get(fbuf));
@ -145,7 +145,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool full)
const char *nl = strrchr(eina_strbuf_string_get(buf), '\n'); const char *nl = strrchr(eina_strbuf_string_get(buf), '\n');
if (nl) if (nl)
{ {
Eina_Strbuf *fbuf = docs_generate_full(fdoc, strlen(nl)); Eina_Strbuf *fbuf = docs_generate_full(fdoc, strlen(nl), use_legacy);
if (fbuf) if (fbuf)
eina_strbuf_append_printf(buf, " %s", eina_strbuf_append_printf(buf, " %s",
eina_strbuf_string_get(fbuf)); eina_strbuf_string_get(fbuf));
@ -170,7 +170,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool full)
} }
Eina_Bool Eina_Bool
types_header_generate(const char *eo_filename, Eina_Strbuf *buf, Eina_Bool full) types_header_generate(const char *eo_filename, Eina_Strbuf *buf, Eina_Bool full, Eina_Bool use_legacy)
{ {
const Eolian_Declaration *decl; const Eolian_Declaration *decl;
@ -198,7 +198,7 @@ types_header_generate(const char *eo_filename, Eina_Strbuf *buf, Eina_Bool full)
continue; continue;
} }
Eina_Strbuf *tbuf = _type_generate(tp, full); Eina_Strbuf *tbuf = _type_generate(tp, full, use_legacy);
if (tbuf) if (tbuf)
{ {
eina_strbuf_append(buf, eina_strbuf_string_get(tbuf)); eina_strbuf_append(buf, eina_strbuf_string_get(tbuf));

View File

@ -9,11 +9,12 @@
* @param[in] eo_filename Eo filename * @param[in] eo_filename Eo filename
* @param[inout] buf buffer to fill * @param[inout] buf buffer to fill
* @param[in]full whether to generate full type definitions * @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. * @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 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); Eina_Bool types_class_typedef_generate(const char *eo_filename, Eina_Strbuf *buf);

View File

@ -164,7 +164,7 @@ function_name(Eolian_Function const& func)
inline std::string inline std::string
function_impl(Eolian_Function const& func) function_impl(Eolian_Function const& func)
{ {
const char *s = ::eolian_function_full_c_name_get(&func); const char *s = ::eolian_function_full_c_name_get(&func, EOLIAN_METHOD, EINA_FALSE);
std::string ret(s); std::string ret(s);
::eina_stringshare_del(s); ::eina_stringshare_del(s);
return ret; return ret;

View File

@ -206,7 +206,7 @@ ffi.cdef [[
Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id); Eolian_Function_Type eolian_function_type_get(const Eolian_Function *function_id);
Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id); Eolian_Object_Scope eolian_function_scope_get(const Eolian_Function *function_id);
const char *eolian_function_name_get(const Eolian_Function *function_id); const char *eolian_function_name_get(const Eolian_Function *function_id);
const char *eolian_function_full_c_name_get(const Eolian_Function *function_id); const char *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype, Eina_Bool use_legacy);
const Eolian_Function *eolian_class_function_get_by_name(const Eolian_Class *klass, const char *func_name, Eolian_Function_Type f_type); const Eolian_Function *eolian_class_function_get_by_name(const Eolian_Class *klass, const char *func_name, Eolian_Function_Type f_type);
const char *eolian_function_legacy_get(const Eolian_Function *function_id, Eolian_Function_Type f_type); const char *eolian_function_legacy_get(const Eolian_Function *function_id, Eolian_Function_Type f_type);
const Eolian_Documentation *eolian_function_documentation_get(const Eolian_Function *function_id, Eolian_Function_Type f_type); const Eolian_Documentation *eolian_function_documentation_get(const Eolian_Function *function_id, Eolian_Function_Type f_type);
@ -617,8 +617,8 @@ M.Function = ffi.metatype("Eolian_Function", {
return ffi.string(v) return ffi.string(v)
end, end,
full_c_name_get = function(self) full_c_name_get = function(self, ftype, use_legacy)
local v = eolian.eolian_function_full_c_name_get(self) local v = eolian.eolian_function_full_c_name_get(self, ftype, use_legacy or false)
if v == nil then return nil end if v == nil then return nil end
return ffi_stringshare(v) return ffi_stringshare(v)
end, end,

View File

@ -648,16 +648,23 @@ EAPI Eina_Stringshare *eolian_function_name_get(const Eolian_Function *function_
* @brief Returns the full C name of a function. * @brief Returns the full C name of a function.
* *
* @param[in] function_id Id of the function * @param[in] function_id Id of the function
* @param[in] ftype The type of function to get the name for
* @param[in] use_legacy If true, legacy prefix or name will be used when available
* @return the function name * @return the function name
* *
* It's here because the C API names are deduplicated (prefix of function and * It's here because the C API names are deduplicated (prefix of function and
* suffix of prefix merge if applicable) and this helps generators not write * suffix of prefix merge if applicable) and this helps generators not write
* the same code over and over. * the same code over and over.
*
* If legacy name is supplied for the given type and use_legacy is set, it
* will be used. Also, if the given type is PROP_GET or PROPERTY, a "_get"
* suffix will be applied when not using legacy name, and "_set" for PROP_SET.
*
* Also, you're responsible for deleting the stringshare. * Also, you're responsible for deleting the stringshare.
* *
* @ingroup Eolian * @ingroup Eolian
*/ */
EAPI Eina_Stringshare *eolian_function_full_c_name_get(const Eolian_Function *function_id); EAPI Eina_Stringshare *eolian_function_full_c_name_get(const Eolian_Function *function_id, Eolian_Function_Type ftype, Eina_Bool use_legacy);
/* /*
* @brief Get a function in a class by its name and type * @brief Get a function in a class by its name and type

View File

@ -27,10 +27,16 @@ eolian_function_name_get(const Eolian_Function *fid)
} }
static const char * static const char *
get_eo_prefix(const Eolian_Function *foo_id, char *buf) _get_eo_prefix(const Eolian_Function *foo_id, char *buf, Eina_Bool use_legacy)
{ {
char *tmp = buf; char *tmp = buf;
if (foo_id->klass->eo_prefix) if (use_legacy && foo_id->klass->legacy_prefix)
{
if (!strcmp(foo_id->klass->legacy_prefix, "null"))
return NULL;
return foo_id->klass->legacy_prefix;
}
else if (!use_legacy && foo_id->klass->eo_prefix)
return foo_id->klass->eo_prefix; return foo_id->klass->eo_prefix;
strcpy(buf, foo_id->klass->full_name); strcpy(buf, foo_id->klass->full_name);
eina_str_tolower(&buf); eina_str_tolower(&buf);
@ -39,10 +45,39 @@ get_eo_prefix(const Eolian_Function *foo_id, char *buf)
} }
EAPI Eina_Stringshare * EAPI Eina_Stringshare *
eolian_function_full_c_name_get(const Eolian_Function *foo_id) eolian_function_full_c_name_get(const Eolian_Function *foo_id,
Eolian_Function_Type ftype,
Eina_Bool use_legacy)
{ {
switch (ftype)
{
case EOLIAN_UNRESOLVED:
case EOLIAN_METHOD:
case EOLIAN_PROPERTY:
case EOLIAN_PROP_GET:
if (foo_id->get_legacy && use_legacy)
{
if (!strcmp(foo_id->get_legacy, "null"))
return NULL;
return eina_stringshare_ref(foo_id->get_legacy);
}
break;
case EOLIAN_PROP_SET:
if (foo_id->set_legacy && use_legacy)
{
if (!strcmp(foo_id->set_legacy, "null"))
return NULL;
return eina_stringshare_ref(foo_id->set_legacy);
}
break;
}
char tbuf[512]; char tbuf[512];
const char *prefix = get_eo_prefix(foo_id, tbuf); const char *prefix = _get_eo_prefix(foo_id, tbuf, use_legacy);
if (!prefix)
return NULL;
const char *funcn = eolian_function_name_get(foo_id); const char *funcn = eolian_function_name_get(foo_id);
const char *last_p = strrchr(prefix, '_'); const char *last_p = strrchr(prefix, '_');
const char *func_p = strchr(funcn, '_'); const char *func_p = strchr(funcn, '_');
@ -55,11 +90,17 @@ eolian_function_full_c_name_get(const Eolian_Function *foo_id)
if (!func_p) len = strlen(funcn); if (!func_p) len = strlen(funcn);
else len = func_p - funcn; else len = func_p - funcn;
if ((int)strlen(last_p) != len || strncmp(last_p, funcn, len)) if (use_legacy || (int)strlen(last_p) != len || strncmp(last_p, funcn, len))
{ {
eina_strbuf_append(buf, prefix); eina_strbuf_append(buf, prefix);
eina_strbuf_append_char(buf, '_'); eina_strbuf_append_char(buf, '_');
eina_strbuf_append(buf, funcn); eina_strbuf_append(buf, funcn);
if ((ftype == EOLIAN_PROP_GET) || (ftype == EOLIAN_PROPERTY))
eina_strbuf_append(buf, "_get");
else if (ftype == EOLIAN_PROP_SET)
eina_strbuf_append(buf, "_set");
ret = eina_stringshare_add(eina_strbuf_string_get(buf)); ret = eina_stringshare_add(eina_strbuf_string_get(buf));
eina_strbuf_free(buf); eina_strbuf_free(buf);
return ret; return ret;
@ -69,6 +110,12 @@ eolian_function_full_c_name_get(const Eolian_Function *foo_id)
eina_strbuf_append_n(buf, prefix, last_p - prefix); /* includes _ */ eina_strbuf_append_n(buf, prefix, last_p - prefix); /* includes _ */
eina_strbuf_append(buf, funcn); eina_strbuf_append(buf, funcn);
if ((ftype == EOLIAN_PROP_GET) || (ftype == EOLIAN_PROPERTY))
eina_strbuf_append(buf, "_get");
else if (ftype == EOLIAN_PROP_SET)
eina_strbuf_append(buf, "_set");
ret = eina_stringshare_add(eina_strbuf_string_get(buf)); ret = eina_stringshare_add(eina_strbuf_string_get(buf));
eina_strbuf_free(buf); eina_strbuf_free(buf);
return ret; return ret;

View File

@ -183,7 +183,7 @@ local Method = Node:clone {
local allocs = {} local allocs = {}
proto.allocs = allocs proto.allocs = allocs
proto.full_name = meth:full_c_name_get() proto.full_name = meth:full_c_name_get(func_type.METHOD)
local fulln = proto.full_name local fulln = proto.full_name
@ -278,7 +278,7 @@ local Property = Method:clone {
local allocs = {} local allocs = {}
proto.allocs = allocs proto.allocs = allocs
proto.full_name = prop:full_c_name_get() .. proto.suffix proto.full_name = prop:full_c_name_get(self.ftype)
local fulln = proto.full_name local fulln = proto.full_name
if #keys > 0 then if #keys > 0 then