eolian: add API: eolian_declaration_get_by_name

Sorry for last minute new API, but this one is necessary to implement
proper verification of references in docs, which I would like to have
in 1.15. It allows you to retrieve any kind of declaration by full
namespace, so that you can check for an existence of an Eolian decl,
rather than checking every type individually.

@feature
This commit is contained in:
Daniel Kolesa 2015-07-07 10:56:53 +01:00
parent 786ab74d6d
commit cd7a78f2a5
4 changed files with 40 additions and 5 deletions

View File

@ -313,6 +313,7 @@ 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);
Eolian_Declaration_Type eolian_declaration_type_get(const Eolian_Declaration *decl);
const char *eolian_declaration_name_get(const Eolian_Declaration *decl);
@ -1266,6 +1267,14 @@ M.Variable = ffi.metatype("Eolian_Variable", {
}
})
M.declaration_get_by_name = function(name)
local v = eolian.eolian_declaration_get_by_name(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))

View File

@ -1949,6 +1949,16 @@ EAPI Eina_Iterator *eolian_variable_namespaces_get(const Eolian_Variable *var);
*/
EAPI Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var);
/*
* @brief Get a declaration by name.
*
* @param[in] name the declaration name.
* @return the declaration.
*
* @ingroup Eolian
*/
EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const char *name);
/*
* @brief Get a list of declarations in a file.
*

View File

@ -109,6 +109,16 @@ database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type,
((Eina_List*)eina_hash_find(_declsf, file), decl));
}
EAPI const Eolian_Declaration *
eolian_declaration_get_by_name(const char *name)
{
if (!_decls) return NULL;
Eina_Stringshare *shr = eina_stringshare_add(name);
const Eolian_Declaration *decl = eina_hash_find(_decls, shr);
eina_stringshare_del(shr);
return decl;
}
EAPI Eina_Iterator *
eolian_declarations_get_by_file(const char *fname)
{

View File

@ -1064,39 +1064,45 @@ START_TEST(eolian_decl)
fail_if(!(itr = eolian_declarations_get_by_file("decl.eo")));
fail_if(!eina_iterator_next(itr, (void**)&decl));
fail_if(eolian_declaration_type_get(decl) == EOLIAN_DECL_UNKNOWN);
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT);
fail_if(strcmp(eolian_declaration_name_get(decl), "A"));
fail_if(!(type = eolian_declaration_data_type_get(decl)));
fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_STRUCT);
fail_if(strcmp(eolian_type_name_get(type), "A"));
fail_if(!eina_iterator_next(itr, (void**)&decl));
fail_if(eolian_declaration_type_get(decl) == EOLIAN_DECL_UNKNOWN);
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_ENUM);
fail_if(strcmp(eolian_declaration_name_get(decl), "B"));
fail_if(!(type = eolian_declaration_data_type_get(decl)));
fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_ENUM);
fail_if(strcmp(eolian_type_name_get(type), "B"));
fail_if(!eina_iterator_next(itr, (void**)&decl));
fail_if(eolian_declaration_type_get(decl) == EOLIAN_DECL_UNKNOWN);
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_ALIAS);
fail_if(strcmp(eolian_declaration_name_get(decl), "C"));
fail_if(!(type = eolian_declaration_data_type_get(decl)));
fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_ALIAS);
fail_if(strcmp(eolian_type_name_get(type), "C"));
fail_if(!eina_iterator_next(itr, (void**)&decl));
fail_if(eolian_declaration_type_get(decl) == EOLIAN_DECL_UNKNOWN);
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_VAR);
fail_if(strcmp(eolian_declaration_name_get(decl), "pants"));
fail_if(!(var = eolian_declaration_variable_get(decl)));
fail_if(strcmp(eolian_variable_name_get(var), "pants"));
fail_if(!eina_iterator_next(itr, (void**)&decl));
fail_if(eolian_declaration_type_get(decl) == EOLIAN_DECL_UNKNOWN);
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_CLASS);
fail_if(strcmp(eolian_declaration_name_get(decl), "Decl"));
fail_if(eolian_declaration_class_get(decl) != class);
fail_if(eina_iterator_next(itr, (void**)&decl));
fail_if(!(decl = eolian_declaration_get_by_name("pants")));
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_VAR);
fail_if(!(decl = eolian_declaration_get_by_name("A")));
fail_if(eolian_declaration_type_get(decl) != EOLIAN_DECL_STRUCT);
eolian_shutdown();
}
END_TEST