lang: ast: implement ast iteration
iteration is implementing without recursion, instead using type-specific callbacks to construct a queue of nodes to iterate through. ast priting is implemented using this functionality.
This commit is contained in:
@@ -59,17 +59,22 @@ enum ivy_ast_msgh_recipient_type {
|
||||
IVY_AST_MSGH_CLASS,
|
||||
};
|
||||
|
||||
struct ivy_ast_node_iterable {
|
||||
struct ivy_ast_node_iterator {
|
||||
b_queue it_queue;
|
||||
b_queue_entry *it_insert_after;
|
||||
};
|
||||
|
||||
struct ivy_ast_node_iterator_entry {
|
||||
b_queue_entry it_entry;
|
||||
unsigned int it_depth;
|
||||
};
|
||||
|
||||
typedef enum ivy_status(*ivy_ast_node_iteration_callback)(struct ivy_ast_node *, unsigned int);
|
||||
typedef enum ivy_status(*ivy_ast_node_iteration_callback)(struct ivy_ast_node *, struct ivy_ast_node_iterator *);
|
||||
|
||||
struct ivy_ast_node {
|
||||
enum ivy_ast_node_type n_type;
|
||||
b_queue_entry n_entry;
|
||||
struct ivy_ast_node_iterable n_it;
|
||||
struct ivy_ast_node_iterator_entry n_it;
|
||||
};
|
||||
|
||||
struct ivy_ast_unit_node {
|
||||
@@ -245,7 +250,10 @@ IVY_API struct ivy_ast_node *ivy_parser_dequeue_node(struct ivy_parser *parser);
|
||||
IVY_API enum ivy_status ivy_parser_push_token(
|
||||
struct ivy_parser *parser, struct ivy_token *tok);
|
||||
|
||||
IVY_API void ivy_ast_node_iterate(struct ivy_ast_node *node);
|
||||
IVY_API enum ivy_status ivy_ast_node_iterate(
|
||||
struct ivy_ast_node *node,
|
||||
struct ivy_ast_node_iterator *it,
|
||||
ivy_ast_node_iteration_callback callback);
|
||||
IVY_API void ivy_ast_node_print(struct ivy_ast_node *node);
|
||||
IVY_API void ivy_ast_node_destroy(struct ivy_ast_node *node);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user