forked from enlightenment/efl
Eolian/Generator: detach Eo1 from Legacy generator.
This step is needed to clean the code and to prepare the integration of Eo2 inside Eolian. Except the eo_do invocation, there is no reason why legacy has to know about Eo.
This commit is contained in:
parent
2be615916a
commit
0987b31247
|
@ -854,3 +854,49 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
eo_source_generate(const char *classname, int eo_version EINA_UNUSED, Eina_Strbuf *buf)
|
||||
{
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
const Eina_List *itr;
|
||||
Eolian_Function fn;
|
||||
|
||||
Eina_Strbuf *str_bodyf = eina_strbuf_new();
|
||||
|
||||
if (!eo1_source_beginning_generate(classname, buf)) goto end;
|
||||
|
||||
//Properties
|
||||
EINA_LIST_FOREACH(eolian_class_functions_list_get(classname, PROPERTY_FUNC), itr, fn)
|
||||
{
|
||||
const Eolian_Function_Type ftype = eolian_function_type_get(fn);
|
||||
|
||||
Eina_Bool prop_read = ( ftype == SET ) ? EINA_FALSE : EINA_TRUE;
|
||||
Eina_Bool prop_write = ( ftype == GET ) ? EINA_FALSE : EINA_TRUE;
|
||||
|
||||
if (prop_write)
|
||||
{
|
||||
if (!eo1_bind_func_generate(classname, fn, SET, str_bodyf, NULL)) goto end;
|
||||
}
|
||||
if (prop_read)
|
||||
{
|
||||
if (!eo1_bind_func_generate(classname, fn, GET, str_bodyf, NULL)) goto end;
|
||||
}
|
||||
}
|
||||
|
||||
//Methods
|
||||
EINA_LIST_FOREACH(eolian_class_functions_list_get(classname, METHOD_FUNC), itr, fn)
|
||||
{
|
||||
if (!eo1_bind_func_generate(classname, fn, UNRESOLVED, str_bodyf, NULL)) goto end;
|
||||
}
|
||||
|
||||
eina_strbuf_append(buf, eina_strbuf_string_get(str_bodyf));
|
||||
eina_strbuf_reset(str_bodyf);
|
||||
|
||||
if (!eo1_source_end_generate(classname, buf)) goto end;
|
||||
|
||||
ret = EINA_TRUE;
|
||||
end:
|
||||
eina_strbuf_free(str_bodyf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,21 @@
|
|||
|
||||
#include<Eina.h>
|
||||
|
||||
/*
|
||||
* @brief Generate Eo source code for Eo class
|
||||
*
|
||||
* This function generates all the source code for Eo.
|
||||
*
|
||||
* @param[in] classname class name
|
||||
* @param[in] eo_version Eo version to generate
|
||||
* @param[inout] buf buffer to fill
|
||||
*
|
||||
* @return EINA_TRUE on success, EINA_FALSE on error.
|
||||
*
|
||||
*/
|
||||
Eina_Bool
|
||||
eo_source_generate(const char *classname, int eo_version, Eina_Strbuf *buf);
|
||||
|
||||
/*
|
||||
* @brief Generate beginning of Eo1 source code for Eo class
|
||||
*
|
||||
|
|
|
@ -321,18 +321,6 @@ end:
|
|||
eina_strbuf_free(eoparam);
|
||||
}
|
||||
|
||||
//TODO change replacement
|
||||
static char*
|
||||
_class_h_find(const char *classname, Eina_Strbuf *buf)
|
||||
{
|
||||
Eina_Strbuf *classreal = eina_strbuf_new();
|
||||
_template_fill(classreal, "@#OBJCLASS_CLASS", classname, "", EINA_FALSE);
|
||||
char *ret = strstr(eina_strbuf_string_get(buf), eina_strbuf_string_get(classreal));
|
||||
eina_strbuf_free(classreal);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
legacy_header_generate(const char *classname, int eo_version EINA_UNUSED, Eina_Strbuf *buf)
|
||||
{
|
||||
|
@ -371,101 +359,11 @@ legacy_header_generate(const char *classname, int eo_version EINA_UNUSED, Eina_S
|
|||
}
|
||||
|
||||
Eina_Bool
|
||||
legacy_header_append(const char *classname, int eo_version EINA_UNUSED, Eina_Strbuf *header)
|
||||
{
|
||||
const Eolian_Function_Type ftype_order[] = {CONSTRUCTOR, PROPERTY_FUNC, METHOD_FUNC};
|
||||
char tmpstr[0xFF];
|
||||
|
||||
if (!eolian_class_exists(classname))
|
||||
{
|
||||
printf ("Class \"%s\" not found in database\n", classname);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
char *clsptr = _class_h_find(classname, header);
|
||||
|
||||
if (!clsptr)
|
||||
{
|
||||
printf ("Class %s not found - append all\n", classname);
|
||||
eina_strbuf_append_char(header, '\n');
|
||||
if (!eo1_header_generate(classname, header)) return EINA_FALSE;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
printf ("Class %s found - searching for functions...\n", classname);
|
||||
|
||||
char *funcdef_pos = _nextline(strstr(clsptr, "+ sub_id)"), 1);
|
||||
char *subid_pos = _startline(clsptr, strstr(clsptr, "SUB_ID_LAST"));
|
||||
|
||||
if (!(funcdef_pos && subid_pos) || (subid_pos > funcdef_pos))
|
||||
{
|
||||
printf ("Bad insertion queues - update aborted\n");
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
Eina_Strbuf *str_subid = eina_strbuf_new();
|
||||
Eina_Strbuf *str_funcdef = eina_strbuf_new();
|
||||
|
||||
const Eina_List *l;
|
||||
void *data;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 3; i++)
|
||||
EINA_LIST_FOREACH(eolian_class_functions_list_get(classname, ftype_order[i]), l, data)
|
||||
{
|
||||
const Eolian_Function_Type ftype = eolian_function_type_get((Eolian_Function)data);
|
||||
const char *funcname = eolian_function_name_get((Eolian_Function)data);
|
||||
Eina_Bool prop_read = (ftype == PROPERTY_FUNC || ftype == GET ) ? EINA_TRUE : EINA_FALSE ;
|
||||
Eina_Bool prop_write = (ftype == PROPERTY_FUNC || ftype == SET ) ? EINA_TRUE : EINA_FALSE ;
|
||||
|
||||
if (!prop_read && !prop_write)
|
||||
{
|
||||
if (!strstr(eina_strbuf_string_get(header), funcname))
|
||||
{
|
||||
printf ("Appending eo function %s\n", funcname);
|
||||
eo1_enum_append(classname, funcname, str_subid);
|
||||
if (!eo1_fundef_generate(classname, (Eolian_Function)data, UNRESOLVED, str_funcdef)) return EINA_FALSE;
|
||||
}
|
||||
}
|
||||
if (prop_write)
|
||||
{
|
||||
sprintf(tmpstr, "%s_set", funcname);
|
||||
if (!strstr(eina_strbuf_string_get(header), tmpstr))
|
||||
{
|
||||
printf ("Appending eo function %s\n", tmpstr);
|
||||
eo1_enum_append(classname, tmpstr, str_subid);
|
||||
if (!eo1_fundef_generate(classname, (Eolian_Function)data, SET, str_funcdef)) return EINA_FALSE;
|
||||
}
|
||||
}
|
||||
if (prop_read)
|
||||
{
|
||||
sprintf(tmpstr, "%s_get", funcname);
|
||||
if (!strstr(eina_strbuf_string_get(header), tmpstr))
|
||||
{
|
||||
printf ("Appending eo function %s\n", tmpstr);
|
||||
eo1_enum_append(classname, tmpstr, str_subid);
|
||||
if (!eo1_fundef_generate(classname, (Eolian_Function)data, GET, str_funcdef)) return EINA_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *hdstr = eina_strbuf_string_get(header);
|
||||
unsigned enum_offs = subid_pos - hdstr;
|
||||
unsigned defs_offs = funcdef_pos - hdstr + eina_strbuf_length_get(str_subid);
|
||||
eina_strbuf_insert(header, eina_strbuf_string_get(str_subid), enum_offs);
|
||||
eina_strbuf_insert(header, eina_strbuf_string_get(str_funcdef), defs_offs);
|
||||
|
||||
eina_strbuf_free(str_subid);
|
||||
eina_strbuf_free(str_funcdef);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
Eina_Bool
|
||||
legacy_source_generate(const char *classname, Eina_Bool legacy, int eo_version EINA_UNUSED, Eina_Strbuf *buf)
|
||||
legacy_source_generate(const char *classname, int eo_version EINA_UNUSED, Eina_Strbuf *buf)
|
||||
{
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
const Eina_List *itr;
|
||||
Eolian_Function fn;
|
||||
|
||||
if (!eolian_class_exists(classname))
|
||||
{
|
||||
|
@ -476,10 +374,7 @@ legacy_source_generate(const char *classname, Eina_Bool legacy, int eo_version E
|
|||
Eina_Strbuf *tmpbuf = eina_strbuf_new();
|
||||
Eina_Strbuf *str_bodyf = eina_strbuf_new();
|
||||
|
||||
if (!eo1_source_beginning_generate(classname, buf)) goto end;
|
||||
|
||||
//Properties
|
||||
Eolian_Function fn;
|
||||
EINA_LIST_FOREACH(eolian_class_functions_list_get(classname, PROPERTY_FUNC), itr, fn)
|
||||
{
|
||||
const Eolian_Function_Type ftype = eolian_function_type_get(fn);
|
||||
|
@ -489,29 +384,23 @@ legacy_source_generate(const char *classname, Eina_Bool legacy, int eo_version E
|
|||
|
||||
if (prop_write)
|
||||
{
|
||||
if (!eo1_bind_func_generate(classname, fn, SET, str_bodyf, NULL)) goto end;
|
||||
if (legacy) _eapi_func_generate(classname, fn, SET, str_bodyf);
|
||||
_eapi_func_generate(classname, fn, SET, str_bodyf);
|
||||
}
|
||||
if (prop_read)
|
||||
{
|
||||
if (!eo1_bind_func_generate(classname, fn, GET, str_bodyf, NULL)) goto end;
|
||||
if (legacy) _eapi_func_generate(classname, fn, GET, str_bodyf);
|
||||
_eapi_func_generate(classname, fn, GET, str_bodyf);
|
||||
}
|
||||
}
|
||||
|
||||
//Methods
|
||||
EINA_LIST_FOREACH(eolian_class_functions_list_get(classname, METHOD_FUNC), itr, fn)
|
||||
{
|
||||
if (!eo1_bind_func_generate(classname, fn, UNRESOLVED, str_bodyf, NULL)) goto end;
|
||||
if (legacy) _eapi_func_generate(classname, fn, UNRESOLVED, str_bodyf);
|
||||
_eapi_func_generate(classname, fn, UNRESOLVED, str_bodyf);
|
||||
}
|
||||
|
||||
eina_strbuf_append(buf, eina_strbuf_string_get(str_bodyf));
|
||||
|
||||
if (!eo1_source_end_generate(classname, buf)) goto end;
|
||||
|
||||
ret = EINA_TRUE;
|
||||
end:
|
||||
eina_strbuf_free(tmpbuf);
|
||||
eina_strbuf_free(str_bodyf);
|
||||
|
||||
|
|
|
@ -19,21 +19,6 @@
|
|||
*/
|
||||
Eina_Bool legacy_header_generate(const char *classname, int eo_version, Eina_Strbuf *buf);
|
||||
|
||||
/*
|
||||
* @brief Append legacy EAPI header for Eo class
|
||||
*
|
||||
* This function needs to be used in case we want to add new functions
|
||||
* to an existing class.
|
||||
*
|
||||
* @param[in] classname class name
|
||||
* @param[in] eo_version Eo version to generate
|
||||
* @param[inout] buf buffer to fill
|
||||
*
|
||||
* @return EINA_TRUE on success, EINA_FALSE on error.
|
||||
*
|
||||
*/
|
||||
Eina_Bool legacy_header_append(const char *classname, int eo_version, Eina_Strbuf *buf);
|
||||
|
||||
/*
|
||||
* @brief Generate C source code for Eo class
|
||||
*
|
||||
|
@ -41,14 +26,13 @@ Eina_Bool legacy_header_append(const char *classname, int eo_version, Eina_Strbu
|
|||
* code from scratch.
|
||||
*
|
||||
* @param[in] classname class name
|
||||
* @param[in] legacy indicates if the legacy has to be generated
|
||||
* @param[in] eo_version Eo version to generate
|
||||
* @param[inout] buf buffer to fill
|
||||
*
|
||||
* @return EINA_TRUE on success, EINA_FALSE on error.
|
||||
*
|
||||
*/
|
||||
Eina_Bool legacy_source_generate(const char *classname, Eina_Bool legacy, int eo_version, Eina_Strbuf *buf);
|
||||
Eina_Bool legacy_source_generate(const char *classname, int eo_version, Eina_Strbuf *buf);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -45,35 +45,14 @@ _filename_get(const char *path)
|
|||
}
|
||||
|
||||
static Eina_Bool
|
||||
_generate_h_file(char *filename, const char *classname, Eina_Bool append)
|
||||
_generate_eo_h_file(char *filename, const char *classname)
|
||||
{
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
Eina_Strbuf *hfile = eina_strbuf_new();
|
||||
if (append)
|
||||
if (!eo1_header_generate(classname, hfile))
|
||||
{
|
||||
Eina_File *fn = eina_file_open(filename, EINA_FALSE);
|
||||
if (!fn)
|
||||
{
|
||||
ERR ("Cant open file \"%s\" for updating.", filename);
|
||||
goto end;
|
||||
}
|
||||
|
||||
eina_strbuf_append(hfile, (char*)eina_file_map_all(fn, EINA_FILE_SEQUENTIAL));
|
||||
eina_file_close(fn);
|
||||
|
||||
if (!legacy_header_append(classname, eo_version, hfile))
|
||||
{
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!eo1_header_generate(classname, hfile))
|
||||
{
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
|
||||
const char *htext = eina_strbuf_string_get(hfile);
|
||||
|
@ -103,65 +82,59 @@ end:
|
|||
}
|
||||
|
||||
static Eina_Bool
|
||||
_generate_c_file(char *filename, const char *classname, Eina_Bool append)
|
||||
_generate_c_file(char *filename, const char *classname)
|
||||
{
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
|
||||
Eina_Strbuf *cfile = eina_strbuf_new();
|
||||
if (!legacy_source_generate(classname, legacy_support, eo_version, cfile))
|
||||
Eina_Strbuf *eo_buf = eina_strbuf_new();
|
||||
Eina_Strbuf *legacy_buf = eina_strbuf_new();
|
||||
|
||||
if (!eo_source_generate(classname, eo_version, eo_buf))
|
||||
{
|
||||
ERR("Failed to generate source for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
|
||||
FILE* fd = fopen(filename, (append) ? "a" : "w");
|
||||
if (legacy_support)
|
||||
if (!legacy_source_generate(classname, eo_version, legacy_buf))
|
||||
{
|
||||
ERR("Failed to generate source for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
|
||||
FILE* fd = fopen(filename, "w");
|
||||
if (!fd)
|
||||
{
|
||||
ERR("Couldnt open file %s for writing", filename);
|
||||
goto end;
|
||||
}
|
||||
const char *ctext = eina_strbuf_string_get(cfile);
|
||||
if (ctext) fputs(ctext, fd);
|
||||
|
||||
const char *text = eina_strbuf_string_get(eo_buf);
|
||||
if (text) fputs(text, fd);
|
||||
text = eina_strbuf_string_get(legacy_buf);
|
||||
if (text) fputs(text, fd);
|
||||
|
||||
fclose(fd);
|
||||
|
||||
ret = EINA_TRUE;
|
||||
end:
|
||||
eina_strbuf_free(cfile);
|
||||
eina_strbuf_free(legacy_buf);
|
||||
eina_strbuf_free(eo_buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO join with header gen.
|
||||
static Eina_Bool
|
||||
_generate_legacy_header_file(char *filename, const char *classname, Eina_Bool append)
|
||||
_generate_legacy_header_file(char *filename, const char *classname)
|
||||
{
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
|
||||
Eina_Strbuf *lfile = eina_strbuf_new();
|
||||
|
||||
if (append)
|
||||
if (!legacy_header_generate(classname, eo_version, lfile))
|
||||
{
|
||||
Eina_File *fn = eina_file_open(filename, EINA_FALSE);
|
||||
if (!fn)
|
||||
{
|
||||
ERR ("Cant open file \"%s\" for updating.", filename);
|
||||
goto end;
|
||||
}
|
||||
eina_strbuf_append(lfile, (char*)eina_file_map_all(fn, EINA_FILE_SEQUENTIAL));
|
||||
eina_file_close(fn);
|
||||
|
||||
if (!legacy_header_append(classname, eo_version, lfile))
|
||||
{
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!legacy_header_generate(classname, eo_version, lfile))
|
||||
{
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
|
||||
FILE* fd = fopen(filename, "w");
|
||||
|
@ -188,50 +161,11 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_generate_eo_and_legacy_h_file(char *filename, const char *classname)
|
||||
{
|
||||
Eina_Bool ret = EINA_FALSE;
|
||||
|
||||
Eina_Strbuf *hfile = eina_strbuf_new();
|
||||
|
||||
if (!eo1_header_generate(classname, hfile))
|
||||
{
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
if (!legacy_header_generate(classname, eo_version, hfile))
|
||||
{
|
||||
ERR("Failed to generate header for %s", classname);
|
||||
goto end;
|
||||
}
|
||||
|
||||
const char *htext = eina_strbuf_string_get(hfile);
|
||||
FILE* fd = fopen(filename, "w");
|
||||
if (!fd)
|
||||
{
|
||||
ERR ("Couldnt open file %s for writing", filename);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (htext) fputs(htext, fd);
|
||||
|
||||
fclose(fd);
|
||||
|
||||
ret = EINA_TRUE;
|
||||
end:
|
||||
eina_strbuf_free(hfile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
NO_WAY_GEN,
|
||||
H_GEN,
|
||||
C_GEN,
|
||||
H_EO_APP,
|
||||
H_LEG_APP,
|
||||
H_LEG_EO_GEN
|
||||
C_GEN
|
||||
};
|
||||
int gen_opt = NO_WAY_GEN;
|
||||
|
||||
|
@ -268,8 +202,6 @@ int main(int argc, char **argv)
|
|||
{"help", no_argument, 0, 'h'},
|
||||
{"gh", no_argument, &gen_opt, H_GEN},
|
||||
{"gc", no_argument, &gen_opt, C_GEN},
|
||||
{"ah", no_argument, &gen_opt, H_EO_APP},
|
||||
{"al", no_argument, &gen_opt, H_LEG_APP},
|
||||
{"output", required_argument, 0, 'o'},
|
||||
{"legacy", no_argument, (int *)&legacy_support, EINA_TRUE},
|
||||
{"include", required_argument, 0, 'I'},
|
||||
|
@ -380,31 +312,19 @@ int main(int argc, char **argv)
|
|||
}
|
||||
switch (gen_opt)
|
||||
{
|
||||
case H_GEN: case H_EO_APP:
|
||||
case H_GEN:
|
||||
{
|
||||
INF("%s header file %s\n", (gen_opt == H_EO_APP) ? "Appending" : "Generating", output_filename);
|
||||
INF("Generating header file %s\n", output_filename);
|
||||
if (legacy_support)
|
||||
ret = ( _generate_legacy_header_file(output_filename, classname, EINA_FALSE) ? 0 : 1 );
|
||||
ret = ( _generate_legacy_header_file(output_filename, classname) ? 0 : 1 );
|
||||
else
|
||||
ret = ( _generate_h_file(output_filename, classname, EINA_FALSE) ? 0 : 1 );
|
||||
break;
|
||||
}
|
||||
case H_LEG_APP:
|
||||
{
|
||||
INF("Appending legacy file %s\n", output_filename);
|
||||
ret = _generate_legacy_header_file(output_filename, classname, EINA_TRUE)?0:1;
|
||||
break;
|
||||
}
|
||||
case H_LEG_EO_GEN:
|
||||
{
|
||||
INF("Generating eo and legacy header file %s\n", output_filename);
|
||||
ret = _generate_eo_and_legacy_h_file(output_filename, classname)?0:1;
|
||||
ret = ( _generate_eo_h_file(output_filename, classname) ? 0 : 1 );
|
||||
break;
|
||||
}
|
||||
case C_GEN:
|
||||
{
|
||||
INF("Generating source file %s\n", output_filename);
|
||||
ret = _generate_c_file(output_filename, classname, EINA_FALSE)?0:1;
|
||||
ret = _generate_c_file(output_filename, classname)?0:1;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue