forked from enlightenment/efl
eolian: make declaration APIs use units
This commit is contained in:
parent
f05249f30b
commit
c8aa30e698
|
@ -22,7 +22,7 @@ static void
|
|||
_generate_ref(const Eolian_Unit *src, 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(src, refn);
|
||||
if (decl)
|
||||
{
|
||||
char *n = strdup(eolian_declaration_name_get(decl));
|
||||
|
|
|
@ -318,13 +318,14 @@ void eo_gen_class_names_get(const Eolian_Class *cl, char **cname,
|
|||
}
|
||||
|
||||
static Eina_Bool
|
||||
_write_header(const Eolian_Unit *src, const char *ofname,
|
||||
_write_header(const Eolian *eos, const Eolian_Unit *src, const char *ofname,
|
||||
const char *ifname, Eina_Bool legacy)
|
||||
{
|
||||
INF("generating header: %s (legacy: %d)", ofname, legacy);
|
||||
Eina_Strbuf *buf = eina_strbuf_new();
|
||||
|
||||
eo_gen_types_header_gen(src, ifname, buf, EINA_TRUE, legacy);
|
||||
eo_gen_types_header_gen(src, eolian_declarations_get_by_file(eos, ifname),
|
||||
buf, EINA_TRUE, legacy);
|
||||
buf = _include_guard(ifname, "TYPES", buf);
|
||||
|
||||
Eina_Strbuf *cltd = eo_gen_class_typedef_gen(src, ifname);
|
||||
|
@ -353,13 +354,14 @@ _write_header(const Eolian_Unit *src, const char *ofname,
|
|||
}
|
||||
|
||||
static Eina_Bool
|
||||
_write_stub_header(const Eolian_Unit *src, const char *ofname,
|
||||
_write_stub_header(const Eolian *eos, const Eolian_Unit *src, const char *ofname,
|
||||
const char *ifname)
|
||||
{
|
||||
INF("generating stub header: %s", ofname);
|
||||
Eina_Strbuf *buf = eina_strbuf_new();
|
||||
|
||||
eo_gen_types_header_gen(src, ifname, buf, EINA_FALSE, EINA_FALSE);
|
||||
eo_gen_types_header_gen(src, eolian_declarations_get_by_file(eos, ifname),
|
||||
buf, EINA_FALSE, EINA_FALSE);
|
||||
|
||||
Eina_Strbuf *cltd = eo_gen_class_typedef_gen(src, ifname);
|
||||
if (cltd)
|
||||
|
@ -377,14 +379,14 @@ _write_stub_header(const Eolian_Unit *src, const char *ofname,
|
|||
}
|
||||
|
||||
static Eina_Bool
|
||||
_write_source(const Eolian_Unit *src, const char *ofname,
|
||||
_write_source(const Eolian *eos, const Eolian_Unit *src, const char *ofname,
|
||||
const char *ifname, Eina_Bool eot)
|
||||
{
|
||||
INF("generating source: %s", ofname);
|
||||
Eina_Strbuf *buf = eina_strbuf_new();
|
||||
|
||||
const Eolian_Class *cl = eolian_class_get_by_file(src, ifname);
|
||||
eo_gen_types_source_gen(src, ifname, buf);
|
||||
eo_gen_types_source_gen(src, eolian_declarations_get_by_file(eos, ifname), buf);
|
||||
eo_gen_source_gen(src, cl, buf);
|
||||
if (cl || (eot && eina_strbuf_length_get(buf)))
|
||||
{
|
||||
|
@ -565,13 +567,13 @@ main(int argc, char **argv)
|
|||
|
||||
Eina_Bool succ = EINA_TRUE;
|
||||
if (gen_what & GEN_H)
|
||||
succ = _write_header(src, outs[_get_bit_pos(GEN_H)], eobn, EINA_FALSE);
|
||||
succ = _write_header(eos, src, outs[_get_bit_pos(GEN_H)], eobn, EINA_FALSE);
|
||||
if (succ && (gen_what & GEN_H_LEGACY))
|
||||
succ = _write_header(src, outs[_get_bit_pos(GEN_H_LEGACY)], eobn, EINA_TRUE);
|
||||
succ = _write_header(eos, src, outs[_get_bit_pos(GEN_H_LEGACY)], eobn, EINA_TRUE);
|
||||
if (succ && (gen_what & GEN_H_STUB))
|
||||
succ = _write_stub_header(src, outs[_get_bit_pos(GEN_H_STUB)], eobn);
|
||||
succ = _write_stub_header(eos, src, outs[_get_bit_pos(GEN_H_STUB)], eobn);
|
||||
if (succ && (gen_what & GEN_C))
|
||||
succ = _write_source(src, outs[_get_bit_pos(GEN_C)], eobn, !strcmp(ext, ".eot"));
|
||||
succ = _write_source(eos, src, outs[_get_bit_pos(GEN_C)], eobn, !strcmp(ext, ".eot"));
|
||||
if (succ && (gen_what & GEN_C_IMPL))
|
||||
succ = _write_impl(src, outs[_get_bit_pos(GEN_C_IMPL)], eobn);
|
||||
|
||||
|
|
|
@ -204,12 +204,10 @@ _var_generate(const Eolian_Unit *src, const Eolian_Variable *vr, Eina_Bool legac
|
|||
}
|
||||
|
||||
void eo_gen_types_header_gen(const Eolian_Unit *src,
|
||||
const char *eof, Eina_Strbuf *buf,
|
||||
Eina_Iterator *itr, Eina_Strbuf *buf,
|
||||
Eina_Bool full, Eina_Bool legacy)
|
||||
{
|
||||
const Eolian_Declaration *decl;
|
||||
|
||||
Eina_Iterator *itr = eolian_declarations_get_by_file(eof);
|
||||
EINA_ITERATOR_FOREACH(itr, decl)
|
||||
{
|
||||
Eolian_Declaration_Type dt = eolian_declaration_type_get(decl);
|
||||
|
@ -256,14 +254,13 @@ void eo_gen_types_header_gen(const Eolian_Unit *src,
|
|||
eina_strbuf_free(tbuf);
|
||||
}
|
||||
}
|
||||
eina_iterator_free(itr);
|
||||
}
|
||||
|
||||
void eo_gen_types_source_gen(const Eolian_Unit *src,
|
||||
const char *eof, Eina_Strbuf *buf)
|
||||
Eina_Iterator *itr, Eina_Strbuf *buf)
|
||||
{
|
||||
const Eolian_Declaration *decl;
|
||||
|
||||
Eina_Iterator *itr = eolian_declarations_get_by_file(eof);
|
||||
EINA_ITERATOR_FOREACH(itr, decl)
|
||||
{
|
||||
Eolian_Declaration_Type dt = eolian_declaration_type_get(decl);
|
||||
|
@ -305,6 +302,7 @@ void eo_gen_types_source_gen(const Eolian_Unit *src,
|
|||
|
||||
eina_strbuf_append(buf, "\n");
|
||||
}
|
||||
eina_iterator_free(itr);
|
||||
}
|
||||
|
||||
Eina_Strbuf *eo_gen_class_typedef_gen(const Eolian_Unit *src, const char *eof)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef EOLIAN_GEN_TYPES_H
|
||||
#define EOLIAN_GEN_TYPES_H
|
||||
|
||||
void eo_gen_types_header_gen(const Eolian_Unit *src, const char *eof, Eina_Strbuf *buf, Eina_Bool full, Eina_Bool legacy);
|
||||
void eo_gen_types_source_gen(const Eolian_Unit *src, const char *eof, Eina_Strbuf *buf);
|
||||
void eo_gen_types_header_gen(const Eolian_Unit *src, Eina_Iterator *itr, Eina_Strbuf *buf, Eina_Bool full, Eina_Bool legacy);
|
||||
void eo_gen_types_source_gen(const Eolian_Unit *src, Eina_Iterator *itr, Eina_Strbuf *buf);
|
||||
Eina_Strbuf *eo_gen_class_typedef_gen(const Eolian_Unit *src, const char *eof);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -454,9 +454,9 @@ ffi.cdef [[
|
|||
const char *eolian_variable_full_name_get(const Eolian_Variable *var);
|
||||
Eina_Iterator *eolian_variable_namespaces_get(const Eolian_Variable *var);
|
||||
Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var);
|
||||
const Eolian_Declaration *eolian_declaration_get_by_name(const char *name);
|
||||
Eina_Iterator *eolian_declarations_get_by_file(const char *fname);
|
||||
Eina_Iterator *eolian_all_declarations_get(void);
|
||||
const Eolian_Declaration *eolian_declaration_get_by_name(const Eolian_Unit *unit, const char *name);
|
||||
Eina_Iterator *eolian_declarations_get_by_file(const Eolian *state, const char *fname);
|
||||
Eina_Iterator *eolian_all_declarations_get(const Eolian_Unit *unit);
|
||||
Eolian_Declaration_Type eolian_declaration_type_get(const Eolian_Declaration *decl);
|
||||
const char *eolian_declaration_name_get(const Eolian_Declaration *decl);
|
||||
const Eolian_Class *eolian_declaration_class_get(const Eolian_Declaration *decl);
|
||||
|
@ -554,6 +554,11 @@ ffi.metatype("Eolian", {
|
|||
return iterator.String_Iterator(eolian.eolian_all_eot_files_get(self))
|
||||
end,
|
||||
|
||||
declarations_get_by_file = function(self, fname)
|
||||
return Ptr_Iterator("const Eolian_Declaration*",
|
||||
eolian.eolian_declarations_get_by_file(self, fname))
|
||||
end,
|
||||
|
||||
unit_get = function(self)
|
||||
return ffi.cast("Eolian_Unit *", self)
|
||||
end
|
||||
|
@ -1613,22 +1618,17 @@ M.Variable = ffi.metatype("Eolian_Variable", {
|
|||
}
|
||||
})
|
||||
|
||||
M.declaration_get_by_name = function(name)
|
||||
local v = eolian.eolian_declaration_get_by_name(name)
|
||||
M.declaration_get_by_name = function(unit, name)
|
||||
local v = eolian.eolian_declaration_get_by_name(unit, name)
|
||||
if v == nil then
|
||||
return nil
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
M.declarations_get_by_file = function(fname)
|
||||
return Ptr_ITerator("const Eolian_Declaration*",
|
||||
eolian.eolian_declarations_get_by_file(fname))
|
||||
end
|
||||
|
||||
M.all_declarations_get = function()
|
||||
M.all_declarations_get = function(unit)
|
||||
return Ptr_Iterator("const Eolian_Declaration *",
|
||||
eolian.eolian_all_declarations_get())
|
||||
eolian.eolian_all_declarations_get(unit))
|
||||
end
|
||||
|
||||
M.Declaration = ffi.metatype("Eolian_Declaration", {
|
||||
|
|
|
@ -2398,12 +2398,13 @@ EAPI Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var);
|
|||
/*
|
||||
* @brief Get a declaration by name.
|
||||
*
|
||||
* @param[in] unit the unit to look in
|
||||
* @param[in] name the declaration name.
|
||||
* @return the declaration.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const char *name);
|
||||
EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const Eolian_Unit *unit, const char *name);
|
||||
|
||||
/*
|
||||
* @brief Get a list of declarations in a file.
|
||||
|
@ -2413,23 +2414,25 @@ EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const char *name);
|
|||
* or a variable. This way you can get them all in the original order they
|
||||
* were declared in, which is useful during generation.
|
||||
*
|
||||
* @param[in] state the state to look in
|
||||
* @param[in] fname the filename.
|
||||
* @return the iterator or NULL.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Iterator *eolian_declarations_get_by_file(const char *fname);
|
||||
EAPI Eina_Iterator *eolian_declarations_get_by_file(const Eolian *state, const char *fname);
|
||||
|
||||
/*
|
||||
* @brief Get an iterator to all declarations in the Eolian database.
|
||||
*
|
||||
* @param[in] unit the unit to look in
|
||||
* @return the iterator or NULL.
|
||||
*
|
||||
* Thanks to internal caching this is an O(1) operation.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Iterator *eolian_all_declarations_get(void);
|
||||
EAPI Eina_Iterator *eolian_all_declarations_get(const Eolian_Unit *unit);
|
||||
|
||||
/*
|
||||
* @brief Get the type of a declaration
|
||||
|
|
|
@ -60,7 +60,7 @@ database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type,
|
|||
}
|
||||
|
||||
EAPI const Eolian_Declaration *
|
||||
eolian_declaration_get_by_name(const char *name)
|
||||
eolian_declaration_get_by_name(const Eolian_Unit *unit EINA_UNUSED, const char *name)
|
||||
{
|
||||
if (!_decls) return NULL;
|
||||
Eina_Stringshare *shr = eina_stringshare_add(name);
|
||||
|
@ -70,7 +70,7 @@ eolian_declaration_get_by_name(const char *name)
|
|||
}
|
||||
|
||||
EAPI Eina_Iterator *
|
||||
eolian_declarations_get_by_file(const char *fname)
|
||||
eolian_declarations_get_by_file(const Eolian *state EINA_UNUSED, const char *fname)
|
||||
{
|
||||
if (!_declsf) return NULL;
|
||||
Eina_Stringshare *shr = eina_stringshare_add(fname);
|
||||
|
@ -81,7 +81,7 @@ eolian_declarations_get_by_file(const char *fname)
|
|||
}
|
||||
|
||||
EAPI Eina_Iterator *
|
||||
eolian_all_declarations_get(void)
|
||||
eolian_all_declarations_get(const Eolian_Unit *unit EINA_UNUSED)
|
||||
{
|
||||
return (_decls ? eina_hash_iterator_data_new(_decls) : NULL);
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
|
|||
memcpy(name, tok->text, nlen);
|
||||
name[nlen] = '\0';
|
||||
|
||||
const Eolian_Declaration *decl = eolian_declaration_get_by_name(name);
|
||||
const Eolian_Declaration *decl = eolian_declaration_get_by_name(unit, name);
|
||||
if (decl) switch (eolian_declaration_type_get(decl))
|
||||
{
|
||||
case EOLIAN_DECL_CLASS:
|
||||
|
|
|
@ -1136,7 +1136,7 @@ START_TEST(eolian_decl)
|
|||
fail_if(!(unit = eolian_file_parse(eos, PACKAGE_DATA_DIR"/data/decl.eo")));
|
||||
fail_if(!(class = eolian_class_get_by_name(unit, "Decl")));
|
||||
|
||||
fail_if(!(itr = eolian_declarations_get_by_file("decl.eo")));
|
||||
fail_if(!(itr = eolian_declarations_get_by_file(eos, "decl.eo")));
|
||||
|
||||
fail_if(!eina_iterator_next(itr, (void**)&decl));
|
||||
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT);
|
||||
|
@ -1172,10 +1172,10 @@ START_TEST(eolian_decl)
|
|||
|
||||
fail_if(eina_iterator_next(itr, (void**)&decl));
|
||||
|
||||
fail_if(!(decl = eolian_declaration_get_by_name("pants")));
|
||||
fail_if(!(decl = eolian_declaration_get_by_name(unit, "pants")));
|
||||
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_VAR);
|
||||
|
||||
fail_if(!(decl = eolian_declaration_get_by_name("A")));
|
||||
fail_if(!(decl = eolian_declaration_get_by_name(unit, "A")));
|
||||
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT);
|
||||
|
||||
eolian_free(eos);
|
||||
|
|
Loading…
Reference in New Issue