eolian: remove the unnecessary subtypes API

Inner type can now be retrieved as a base type of the type.
If the type has two inner types or more, there is a new API that allows you to
get the second inner type by calling it on the first one (same would apply to
getting third via second etc.).

This API is simpler to use and doesn't require an iterator.
This commit is contained in:
Daniel Kolesa 2016-06-10 14:28:19 +01:00
parent 93eadd76d6
commit 33c147f6d4
10 changed files with 56 additions and 68 deletions

View File

@ -379,15 +379,9 @@ eo_bind_func_generate(const Eolian_Class *class, const Eolian_Function *funcid,
if(!has_promise && !strcmp(ptype, "Eina_Promise *") &&
(ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) && pdir == EOLIAN_INOUT_PARAM)
{
Eina_Iterator* promise_values;
has_promise = EINA_TRUE;
promise_param_name = eina_stringshare_add(pname);
promise_values = eolian_type_subtypes_get(ptypet);
Eolian_Type* subtype;
if(eina_iterator_next(promise_values, (void**)&subtype))
{
promise_value_type = eolian_type_c_type_get(subtype);
}
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");

View File

@ -207,9 +207,8 @@ _eolian_type_cpp_type_named_get(const Eolian_Type *tp, std::string const& caller
result = "efl::eina::js::make_complex_tag<" + result;
bool has_subtypes = false;
auto subtypes = eolian_type_subtypes_get(btp);
const Eolian_Type *subtype;
EINA_ITERATOR_FOREACH(subtypes, subtype)
const Eolian_Type *subtype = eolian_type_base_type_get(btp);
while (subtype)
{
auto t = _eolian_type_cpp_type_named_get(subtype, caller_class_prefix, need_name_getter);
auto k = type_class_name(subtype);
@ -223,6 +222,7 @@ _eolian_type_cpp_type_named_get(const Eolian_Type *tp, std::string const& caller
result += ", " + t + ", ::efl::eina::js::nonclass_cls_name_getter";
}
has_subtypes = true;
subtype = eolian_type_next_type_get(subtype);
}
if (!has_subtypes)

View File

@ -274,7 +274,6 @@ ffi.cdef [[
Eina_Iterator *eolian_typedecl_all_enums_get(void);
Eolian_Type_Type eolian_type_type_get(const Eolian_Type *tp);
Eolian_Typedecl_Type eolian_typedecl_type_get(const Eolian_Typedecl *tp);
Eina_Iterator *eolian_type_subtypes_get(const Eolian_Type *tp);
Eina_Iterator *eolian_typedecl_struct_fields_get(const Eolian_Typedecl *tp);
const Eolian_Struct_Type_Field *eolian_typedecl_struct_field_get(const Eolian_Typedecl *tp, const char *field);
const char *eolian_typedecl_struct_field_name_get(const Eolian_Struct_Type_Field *fl);
@ -293,6 +292,7 @@ ffi.cdef [[
const char *eolian_typedecl_file_get(const Eolian_Typedecl *tp);
const Eolian_Type *eolian_type_base_type_get(const Eolian_Type *tp);
const Eolian_Type *eolian_type_next_type_get(const Eolian_Type *tp);
const Eolian_Type *eolian_typedecl_base_type_get(const Eolian_Typedecl *tp);
const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp);
@ -614,11 +614,6 @@ M.Type = ffi.metatype("Eolian_Type", {
return tonumber(eolian.eolian_type_type_get(self))
end,
subtypes_get = function(self)
return Ptr_Iterator("const Eolian_Type*",
eolian.eolian_type_subtypes_get(self))
end,
file_get = function(self, name)
local v = eolian.eolian_type_file_get(self)
if v == nil then return nil end
@ -631,6 +626,12 @@ M.Type = ffi.metatype("Eolian_Type", {
return v
end,
next_type_get = function(self)
local v = eolian.eolian_type_next_type_get(self)
if v == nil then return nil end
return v
end,
typedecl_get = function(self)
local v = eolian.eolian_type_typedecl_get(self)
if v == nil then return nil end

View File

@ -1651,16 +1651,6 @@ EAPI Eina_Stringshare *eolian_typedecl_free_func_get(const Eolian_Typedecl *tp);
*/
EAPI Eolian_Type_Type eolian_type_type_get(const Eolian_Type *tp);
/*
* @brief Get an iterator to all subtypes of a type.
*
* @param[in] tp the type.
* @return the iterator when @c tp is a complex type.
*
* @ingroup Eolian
*/
EAPI Eina_Iterator *eolian_type_subtypes_get(const Eolian_Type *tp);
/*
* @brief Get the filename of a type.
*
@ -1672,15 +1662,32 @@ EAPI Eina_Iterator *eolian_type_subtypes_get(const Eolian_Type *tp);
EAPI Eina_Stringshare *eolian_type_file_get(const Eolian_Type *tp);
/*
* @brief Get the base type of a pointer type.
* @brief Get the base type of a type.
*
* For pointers, this is the type before the star and for complex types,
* this is the first inner type.
*
* @param[in] tp the type.
* @return the base type when @c tp is a pointer, NULL otherwise.
* @return the base type or NULL.
*
* @ingroup Eolian
*/
EAPI const Eolian_Type *eolian_type_base_type_get(const Eolian_Type *tp);
/*
* @brief Get the next inner type of a complex type.
*
* The inner types of a complex type form a chain. Therefore, you first retrieve
* the first one via eolian_type_base_type_get and then get the next one via
* this API function called on the first inner type if necessary.
*
* @param[in] tp the type.
* @return the next type or NULL.
*
* @ingroup Eolian
*/
EAPI const Eolian_Type *eolian_type_next_type_get(const Eolian_Type *tp);
/*
* @brief Get the declaration a regular type points to.
*

View File

@ -10,11 +10,9 @@ database_type_del(Eolian_Type *tp)
{
if (!tp) return;
const char *sp;
Eolian_Type *stp;
if (tp->base.file) eina_stringshare_del(tp->base.file);
if (tp->subtypes) EINA_LIST_FREE(tp->subtypes, stp)
database_type_del(stp);
database_type_del(tp->base_type);
database_type_del(tp->next_type);
if (tp->name) eina_stringshare_del(tp->name);
if (tp->full_name) eina_stringshare_del(tp->full_name);
if (tp->namespaces) EINA_LIST_FREE(tp->namespaces, sp)

View File

@ -104,17 +104,6 @@ eolian_typedecl_type_get(const Eolian_Typedecl *tp)
return tp->type;
}
EAPI Eina_Iterator *
eolian_type_subtypes_get(const Eolian_Type *tp)
{
Eolian_Type_Type tpt;
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
tpt = tp->type;
if ((tpt != EOLIAN_TYPE_COMPLEX) || !tp->subtypes)
return NULL;
return eina_list_iterator_new(tp->subtypes);
}
EAPI Eina_Iterator *
eolian_typedecl_struct_fields_get(const Eolian_Typedecl *tp)
{
@ -262,6 +251,13 @@ eolian_type_base_type_get(const Eolian_Type *tp)
return tp->base_type;
}
EAPI const Eolian_Type *
eolian_type_next_type_get(const Eolian_Type *tp)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
return tp->next_type;
}
EAPI const Eolian_Typedecl *
eolian_type_typedecl_get(const Eolian_Type *tp)
{

View File

@ -816,20 +816,17 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref)
int bline = ls->line_number, bcol = ls->column;
def->type = EOLIAN_TYPE_COMPLEX;
check_next(ls, '<');
def->subtypes = eina_list_append(def->subtypes,
parse_type(ls, EINA_FALSE));
def->base_type = parse_type(ls, EINA_FALSE);
pop_type(ls);
if (tpid == KW_hash)
{
check_next(ls, ',');
def->subtypes = eina_list_append(def->subtypes,
parse_type(ls, EINA_FALSE));
def->base_type->next_type = parse_type(ls, EINA_FALSE);
pop_type(ls);
}
else if(tpid == KW_promise && test_next(ls, ','))
{
def->subtypes = eina_list_append(def->subtypes,
parse_type(ls, EINA_FALSE));
def->base_type->next_type = parse_type(ls, EINA_FALSE);
pop_type(ls);
}
check_match(ls, '>', '<', bline, bcol);

View File

@ -167,8 +167,8 @@ struct _Eolian_Type
{
Eolian_Object base;
Eolian_Type_Type type;
Eina_List *subtypes;
Eolian_Type *base_type;
Eolian_Type *next_type;
Eina_Stringshare *name;
Eina_Stringshare *full_name;
Eina_List *namespaces;

View File

@ -302,11 +302,11 @@ inline void type_def::set(Eolian_Type const* eolian_type)
{
complex_type_def complex
{{::eolian_type_name_get(eolian_type), {qualifiers(eolian_type), {}}, {}}, {}};
for(efl::eina::iterator<Eolian_Type const> type_iterator( ::eolian_type_subtypes_get(eolian_type))
, type_last; type_iterator != type_last; ++type_iterator)
Eolian_Type const* stp = eolian_type_base_type_get(eolian_type);
while (stp)
{
Eolian_Type const* type = &*type_iterator;
complex.subtypes.push_back({type});
complex.subtypes.push_back({stp});
stp = eolian_type_next_type_get(stp);
}
original_type = complex;
}

View File

@ -388,13 +388,12 @@ START_TEST(eolian_typedef)
fail_if(!eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eina_List *"));
eina_stringshare_del(type_name);
fail_if(!(iter = eolian_type_subtypes_get(type)));
fail_if(!eina_iterator_next(iter, (void**)&type));
fail_if(!(type = eolian_type_base_type_get(type)));
fail_if(!!eolian_type_next_type_get(type));
fail_if(!(type_name = eolian_type_c_type_get(type)));
fail_if(strcmp(type_name, "Eo *"));
fail_if(eolian_type_is_own(type));
eina_stringshare_del(type_name);
eina_iterator_free(iter);
/* List */
fail_if(!(iter = eolian_typedecl_aliases_get_by_file("typedef.eo")));
@ -441,20 +440,18 @@ START_TEST(eolian_complex_type)
fail_if(!eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eina_List *"));
eina_stringshare_del(type_name);
fail_if(!(iter = eolian_type_subtypes_get(type)));
fail_if(!eina_iterator_next(iter, (void**)&type));
fail_if(!(type = eolian_type_base_type_get(type)));
fail_if(!!eolian_type_next_type_get(type));
fail_if(!(type_name = eolian_type_c_type_get(type)));
fail_if(eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eina_Array *"));
eina_stringshare_del(type_name);
eina_iterator_free(iter);
fail_if(!(iter = eolian_type_subtypes_get(type)));
fail_if(!eina_iterator_next(iter, (void**)&type));
fail_if(!(type = eolian_type_base_type_get(type)));
fail_if(!!eolian_type_next_type_get(type));
fail_if(!(type_name = eolian_type_c_type_get(type)));
fail_if(!eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eo **"));
eina_stringshare_del(type_name);
eina_iterator_free(iter);
/* Properties parameter type */
fail_if(!(iter = eolian_property_values_get(fid, EOLIAN_PROP_GET)));
fail_if(!(eina_iterator_next(iter, (void**)&param)));
@ -466,13 +463,12 @@ START_TEST(eolian_complex_type)
fail_if(!eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eina_List *"));
eina_stringshare_del(type_name);
fail_if(!(iter = eolian_type_subtypes_get(type)));
fail_if(!eina_iterator_next(iter, (void**)&type));
fail_if(!(type = eolian_type_base_type_get(type)));
fail_if(!!eolian_type_next_type_get(type));
fail_if(!(type_name = eolian_type_c_type_get(type)));
fail_if(eolian_type_is_own(type));
fail_if(strcmp(type_name, "int"));
eina_stringshare_del(type_name);
eina_iterator_free(iter);
/* Methods return type */
fail_if(!(fid = eolian_class_function_get_by_name(class, "foo", EOLIAN_METHOD)));
@ -481,13 +477,12 @@ START_TEST(eolian_complex_type)
fail_if(!eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eina_List *"));
eina_stringshare_del(type_name);
fail_if(!(iter = eolian_type_subtypes_get(type)));
fail_if(!eina_iterator_next(iter, (void**)&type));
fail_if(!(type = eolian_type_base_type_get(type)));
fail_if(!!eolian_type_next_type_get(type));
fail_if(!(type_name = eolian_type_c_type_get(type)));
fail_if(eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eina_Stringshare *"));
eina_stringshare_del(type_name);
eina_iterator_free(iter);
/* Methods parameter type */
fail_if(!(iter = eolian_function_parameters_get(fid)));
fail_if(!(eina_iterator_next(iter, (void**)&param)));