fx.reflection: update iterator semantics
This commit is contained in:
+64
-48
@@ -71,10 +71,12 @@ struct fx_assembly_p {
|
||||
|
||||
struct fx_assembly_iterator_p {
|
||||
fx_namemap_entry *it_cur;
|
||||
fx_value it_value;
|
||||
};
|
||||
|
||||
struct fx_assembly_type_iterator_p {
|
||||
struct type *it_item;
|
||||
fx_value it_value;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
@@ -165,11 +167,11 @@ static struct map_item *map_item_next(struct map_item *item)
|
||||
struct map_bucket *bucket = item->i_entry.e_bucket;
|
||||
struct map_entry *next_item = NULL;
|
||||
if (bucket) {
|
||||
struct fx_queue_entry *q_item = fx_queue_next(
|
||||
&item->i_entry.e_entry);
|
||||
struct fx_queue_entry *q_item
|
||||
= fx_queue_next(&item->i_entry.e_entry);
|
||||
if (!q_item) {
|
||||
struct fx_bst_node *node = fx_bst_next(
|
||||
&bucket->b_entry.e_node);
|
||||
struct fx_bst_node *node
|
||||
= fx_bst_next(&bucket->b_entry.e_node);
|
||||
next_item = fx_unbox(struct map_entry, node, e_node);
|
||||
} else {
|
||||
next_item = fx_unbox(struct map_entry, q_item, e_entry);
|
||||
@@ -185,8 +187,8 @@ static struct map_item *map_item_next(struct map_item *item)
|
||||
|
||||
if (next_item->e_type == MAP_ENTRY_BUCKET) {
|
||||
bucket = (struct map_bucket *)next_item;
|
||||
struct fx_queue_entry *q_item = fx_queue_first(
|
||||
&bucket->b_items);
|
||||
struct fx_queue_entry *q_item
|
||||
= fx_queue_first(&bucket->b_items);
|
||||
next_item = fx_unbox(struct map_entry, q_item, e_entry);
|
||||
}
|
||||
|
||||
@@ -255,10 +257,8 @@ static void assembly_dump(struct fx_assembly_p *assembly)
|
||||
|
||||
fx_bst_node *cur_node = fx_bst_first(&assembly->a_types.m_entries);
|
||||
while (cur_node) {
|
||||
struct map_entry *entry = fx_unbox(
|
||||
struct map_entry,
|
||||
cur_node,
|
||||
e_node);
|
||||
struct map_entry *entry
|
||||
= fx_unbox(struct map_entry, cur_node, e_node);
|
||||
switch (entry->e_type) {
|
||||
case MAP_ENTRY_ITEM: {
|
||||
struct map_item *item = (struct map_item *)entry;
|
||||
@@ -268,8 +268,8 @@ static void assembly_dump(struct fx_assembly_p *assembly)
|
||||
|
||||
case MAP_ENTRY_BUCKET: {
|
||||
struct map_bucket *bucket = (struct map_bucket *)entry;
|
||||
fx_queue_entry *cur_qentry = fx_queue_first(
|
||||
&bucket->b_items);
|
||||
fx_queue_entry *cur_qentry
|
||||
= fx_queue_first(&bucket->b_items);
|
||||
while (cur_qentry) {
|
||||
struct map_item *item = fx_unbox(
|
||||
struct map_item,
|
||||
@@ -289,8 +289,8 @@ static void assembly_dump(struct fx_assembly_p *assembly)
|
||||
|
||||
static fx_iterator *assembly_get_types(const struct fx_assembly_p *assembly)
|
||||
{
|
||||
fx_assembly_type_iterator *it = fx_object_create(
|
||||
fx_assembly_type_iterator_get_type());
|
||||
fx_assembly_type_iterator *it
|
||||
= fx_object_create(fx_assembly_type_iterator_get_type());
|
||||
if (!it) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -299,12 +299,15 @@ static fx_iterator *assembly_get_types(const struct fx_assembly_p *assembly)
|
||||
it,
|
||||
fx_assembly_type_iterator_get_type());
|
||||
struct map_item *item = map_first_item(&assembly->a_types);
|
||||
if (item) {
|
||||
it_p->it_item = fx_unbox(struct type, item, e_map_item);
|
||||
} else {
|
||||
if (!item) {
|
||||
fx_iterator_set_status(it, FX_ERR_NO_DATA);
|
||||
return it;
|
||||
}
|
||||
|
||||
it_p->it_item = fx_unbox(struct type, item, e_map_item);
|
||||
const fx_type *ty = fx_type_get_by_id(it_p->it_item->e_type);
|
||||
it_p->it_value = FX_VALUE_OBJECT_REF(ty);
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
@@ -341,20 +344,25 @@ static void assembly_get_version(
|
||||
|
||||
fx_iterator *fx_assembly_get_all(void)
|
||||
{
|
||||
fx_assembly_iterator *it = fx_object_create(
|
||||
fx_assembly_iterator_get_type());
|
||||
fx_assembly_iterator *it
|
||||
= fx_object_create(fx_assembly_iterator_get_type());
|
||||
if (!it) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_assembly_iterator_p *it_p = fx_object_get_private(
|
||||
it,
|
||||
fx_assembly_iterator_get_type());
|
||||
struct fx_assembly_iterator_p *it_p
|
||||
= fx_object_get_private(it, fx_assembly_iterator_get_type());
|
||||
it_p->it_cur = fx_namemap_first(&assembly_map);
|
||||
if (!it_p->it_cur) {
|
||||
fx_iterator_set_status(it, FX_ERR_NO_DATA);
|
||||
return it;
|
||||
}
|
||||
|
||||
struct fx_assembly_p *assembly
|
||||
= fx_unbox(struct fx_assembly_p, it_p->it_cur, a_entry);
|
||||
|
||||
it_p->it_value = FX_VALUE_OBJECT_REF(assembly->a_self);
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
@@ -365,10 +373,8 @@ const fx_assembly *fx_assembly_get_by_name(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_assembly_p *assembly = fx_unbox(
|
||||
struct fx_assembly_p,
|
||||
entry,
|
||||
a_entry);
|
||||
struct fx_assembly_p *assembly
|
||||
= fx_unbox(struct fx_assembly_p, entry, a_entry);
|
||||
return assembly->a_self;
|
||||
}
|
||||
|
||||
@@ -483,51 +489,61 @@ static enum fx_status type_iterator_move_next(const fx_iterator *obj)
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
fx_value_unset(&it->it_value);
|
||||
struct map_item *next = map_item_next(&it->it_item->e_map_item);
|
||||
it->it_item = fx_unbox(struct type, next, e_map_item);
|
||||
return it->it_item ? FX_SUCCESS : FX_ERR_NO_DATA;
|
||||
if (!it->it_item) {
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
const fx_type *ty = fx_type_get_by_id(it->it_item->e_type);
|
||||
it->it_value = FX_VALUE_OBJECT_REF(ty);
|
||||
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_value type_iterator_get_value(const fx_iterator *obj)
|
||||
static const fx_value *type_iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_assembly_type_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
fx_assembly_type_iterator_get_type());
|
||||
if (!it->it_item) {
|
||||
return FX_VALUE_EMPTY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const fx_type *ty = fx_type_get_by_id(it->it_item->e_type);
|
||||
return FX_VALUE_OBJECT(ty);
|
||||
return &it->it_value;
|
||||
}
|
||||
|
||||
static enum fx_status assembly_iterator_move_next(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_assembly_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
fx_assembly_iterator_get_type());
|
||||
struct fx_assembly_iterator_p *it
|
||||
= fx_object_get_private(obj, fx_assembly_iterator_get_type());
|
||||
if (!it->it_cur) {
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
fx_value_unset(&it->it_value);
|
||||
it->it_cur = fx_namemap_next(&assembly_map, it->it_cur);
|
||||
return it->it_cur ? FX_SUCCESS : FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
static fx_value assembly_iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_assembly_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
fx_assembly_iterator_get_type());
|
||||
if (!it->it_cur) {
|
||||
return FX_VALUE_EMPTY;
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
struct fx_assembly_p *assembly = fx_unbox(
|
||||
struct fx_assembly_p,
|
||||
it->it_cur,
|
||||
a_entry);
|
||||
return FX_VALUE_OBJECT(assembly->a_self);
|
||||
struct fx_assembly_p *assembly
|
||||
= fx_unbox(struct fx_assembly_p, it->it_cur, a_entry);
|
||||
|
||||
it->it_value = FX_VALUE_OBJECT_REF(assembly->a_self);
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static const fx_value *assembly_iterator_get_value(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_assembly_iterator_p *it
|
||||
= fx_object_get_private(obj, fx_assembly_iterator_get_type());
|
||||
if (!it->it_cur) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &it->it_value;
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
Reference in New Issue
Block a user