fx.reflection: update iterator semantics
This commit is contained in:
+47
-31
@@ -31,12 +31,14 @@ struct fx_type_p {
|
||||
struct fx_type_function_iterator_p {
|
||||
struct fx_namemap *it_src;
|
||||
struct fx_namemap_entry *it_cur;
|
||||
fx_value it_value;
|
||||
};
|
||||
|
||||
struct fx_type_property_iterator_p {
|
||||
const fx_type_info *it_cur_type;
|
||||
struct fx_namemap *it_src;
|
||||
struct fx_namemap_entry *it_cur;
|
||||
fx_value it_value;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
@@ -77,8 +79,8 @@ const fx_function *type_get_function(
|
||||
|
||||
fx_iterator *type_get_functions(const struct fx_type_p *ty)
|
||||
{
|
||||
fx_type_function_iterator *it_obj = fx_object_create(
|
||||
FX_REFLECTION_TYPE_TYPE_FUNCTION_ITERATOR);
|
||||
fx_type_function_iterator *it_obj
|
||||
= fx_object_create(FX_REFLECTION_TYPE_TYPE_FUNCTION_ITERATOR);
|
||||
struct fx_type_function_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_REFLECTION_TYPE_TYPE_FUNCTION_ITERATOR);
|
||||
@@ -95,9 +97,8 @@ const fx_property *type_get_property(
|
||||
{
|
||||
struct fx_type_info *cur = ty->ty_info;
|
||||
while (cur) {
|
||||
const fx_property *prop = fx_type_info_get_property_by_name(
|
||||
cur,
|
||||
name);
|
||||
const fx_property *prop
|
||||
= fx_type_info_get_property_by_name(cur, name);
|
||||
if (prop) {
|
||||
return prop;
|
||||
}
|
||||
@@ -114,8 +115,8 @@ const fx_property *type_get_property(
|
||||
|
||||
static fx_iterator *type_get_properties(const struct fx_type_p *ty)
|
||||
{
|
||||
fx_type_property_iterator *it_obj = fx_object_create(
|
||||
FX_REFLECTION_TYPE_TYPE_PROPERTY_ITERATOR);
|
||||
fx_type_property_iterator *it_obj
|
||||
= fx_object_create(FX_REFLECTION_TYPE_TYPE_PROPERTY_ITERATOR);
|
||||
struct fx_type_property_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_REFLECTION_TYPE_TYPE_PROPERTY_ITERATOR);
|
||||
@@ -129,8 +130,9 @@ static fx_iterator *type_get_properties(const struct fx_type_p *ty)
|
||||
break;
|
||||
}
|
||||
|
||||
const struct fx_type_info *next_type = fx_type_info_get_by_id(
|
||||
&it->it_cur_type->ty_parent_id);
|
||||
const struct fx_type_info *next_type
|
||||
= fx_type_info_get_by_id(&it->it_cur_type
|
||||
->ty_parent_id);
|
||||
if (!next_type) {
|
||||
break;
|
||||
}
|
||||
@@ -143,6 +145,10 @@ static fx_iterator *type_get_properties(const struct fx_type_p *ty)
|
||||
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
||||
}
|
||||
|
||||
struct fx_type_property *prop
|
||||
= fx_unbox(struct fx_type_property, it->it_cur, p_entry);
|
||||
it->it_value = FX_VALUE_OBJECT_REF(prop->p_prop);
|
||||
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
@@ -176,9 +182,8 @@ fx_type *__fx_type_create(struct fx_type_info *type_info)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_type_p *p = fx_object_get_private(
|
||||
out,
|
||||
FX_REFLECTION_TYPE_TYPE);
|
||||
struct fx_type_p *p
|
||||
= fx_object_get_private(out, FX_REFLECTION_TYPE_TYPE);
|
||||
p->ty_info = type_info;
|
||||
|
||||
return out;
|
||||
@@ -300,25 +305,29 @@ static enum fx_status function_iterator_move_next(const fx_iterator *obj)
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
fx_value_unset(&it->it_value);
|
||||
it->it_cur = fx_namemap_next(it->it_src, it->it_cur);
|
||||
return it->it_cur ? FX_SUCCESS : FX_ERR_NO_DATA;
|
||||
if (!it->it_cur) {
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
struct fx_type_function *func
|
||||
= fx_unbox(struct fx_type_function, it->it_cur, f_entry);
|
||||
it->it_value = FX_VALUE_OBJECT_REF(func->f_func);
|
||||
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_value function_iterator_get_value(const fx_iterator *obj)
|
||||
static const fx_value *function_iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_type_function_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_REFLECTION_TYPE_TYPE_FUNCTION_ITERATOR);
|
||||
if (!it->it_cur) {
|
||||
return FX_VALUE_EMPTY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_type_function *func = fx_unbox(
|
||||
struct fx_type_function,
|
||||
it->it_cur,
|
||||
f_entry);
|
||||
|
||||
return FX_VALUE_OBJECT(func->f_func);
|
||||
return &it->it_value;
|
||||
}
|
||||
|
||||
static enum fx_status property_iterator_move_next(const fx_iterator *obj)
|
||||
@@ -337,8 +346,9 @@ static enum fx_status property_iterator_move_next(const fx_iterator *obj)
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
const struct fx_type_info *next_type = fx_type_info_get_by_id(
|
||||
&it->it_cur_type->ty_parent_id);
|
||||
const struct fx_type_info *next_type
|
||||
= fx_type_info_get_by_id(&it->it_cur_type
|
||||
->ty_parent_id);
|
||||
if (!next_type) {
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
@@ -347,24 +357,30 @@ static enum fx_status property_iterator_move_next(const fx_iterator *obj)
|
||||
it->it_cur = fx_namemap_first(&it->it_cur_type->ty_properties);
|
||||
}
|
||||
|
||||
return it->it_cur ? FX_SUCCESS : FX_ERR_NO_DATA;
|
||||
if (!it->it_cur) {
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
struct fx_type_property *prop
|
||||
= fx_unbox(struct fx_type_property, it->it_cur, p_entry);
|
||||
it->it_value = FX_VALUE_OBJECT_REF(prop->p_prop);
|
||||
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_value property_iterator_get_value(const fx_iterator *obj)
|
||||
static const fx_value *property_iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_type_property_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_REFLECTION_TYPE_TYPE_PROPERTY_ITERATOR);
|
||||
if (!it->it_cur) {
|
||||
return FX_VALUE_EMPTY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_type_property *prop = fx_unbox(
|
||||
struct fx_type_property,
|
||||
it->it_cur,
|
||||
p_entry);
|
||||
struct fx_type_property *prop
|
||||
= fx_unbox(struct fx_type_property, it->it_cur, p_entry);
|
||||
|
||||
return FX_VALUE_OBJECT(prop->p_prop);
|
||||
return &it->it_value;
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
Reference in New Issue
Block a user