lang: update bluelib api usage
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
struct ivy_ast_atom_node *v = (struct ivy_ast_atom_node *)node;
|
||||
|
||||
b_string_append_cstrf(str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
v->n_content->t_str);
|
||||
b_string_append_cstrf(
|
||||
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
v->n_content->t_str);
|
||||
}
|
||||
|
||||
struct ast_node_type atom_node_ops = {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
|
||||
void block_add_terminator(struct block_parser_state *state, unsigned short tok)
|
||||
@@ -143,11 +143,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_block_node *block = (struct ivy_ast_block_node *)node;
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &block->n_expr) {
|
||||
b_queue_entry *entry = b_queue_first(&block->n_expr);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *expr
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, expr);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,12 @@ static void collect_children(
|
||||
ast_node_iterator_enqueue_node(iterator, node, cascade->n_recipient);
|
||||
}
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &cascade->n_msg) {
|
||||
b_queue_entry *entry = b_queue_first(&cascade->n_msg);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, arg);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -162,17 +162,20 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_class_node *c = (struct ivy_ast_class_node *)node;
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &c->n_properties) {
|
||||
b_queue_entry *entry = b_queue_first(&c->n_properties);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
b_queue_foreach (&it, &c->n_msg_handlers) {
|
||||
entry = b_queue_first(&c->n_msg_handlers);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -339,11 +339,12 @@ static void cond_group_collect_children(
|
||||
struct ivy_ast_cond_group_node *group
|
||||
= (struct ivy_ast_cond_group_node *)node;
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &group->n_branches) {
|
||||
b_queue_entry *entry = b_queue_first(&group->n_branches);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *branch
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, branch);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
|
||||
struct ast_node_type c_true_node_ops = {
|
||||
.n_state_size = sizeof(struct parser_state),
|
||||
.n_node_size = sizeof(struct ivy_ast_node),
|
||||
|
||||
@@ -44,12 +44,13 @@ void ivy_parser_destroy(struct ivy_parser *parser, struct ivy_ast_node **result)
|
||||
{
|
||||
struct ivy_ast_node *root = NULL;
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_iterator_begin(&parser->p_state, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
b_queue_entry *entry = b_queue_first(&parser->p_state);
|
||||
;
|
||||
while (entry) {
|
||||
struct parser_state *state
|
||||
= b_unbox(struct parser_state, it.entry, s_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
= b_unbox(struct parser_state, entry, s_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&parser->p_state, entry);
|
||||
|
||||
if (root) {
|
||||
ivy_ast_node_destroy(root);
|
||||
@@ -57,6 +58,7 @@ void ivy_parser_destroy(struct ivy_parser *parser, struct ivy_ast_node **result)
|
||||
|
||||
root = state->s_node;
|
||||
free(state);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../node.h"
|
||||
#include "expr.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <ivy/lang/operator.h>
|
||||
#include <stdio.h>
|
||||
@@ -296,7 +296,7 @@ enum ivy_status expr_finalise_arith(
|
||||
struct expr_parser_state *state, struct ivy_ast_node **expr_tree,
|
||||
enum ivy_operator_precedence minimum_precedence)
|
||||
{
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_entry *entry = NULL;
|
||||
|
||||
/* first, take all the operators still left on the operator stack and
|
||||
* add them to the output queue.
|
||||
@@ -304,7 +304,7 @@ enum ivy_status expr_finalise_arith(
|
||||
* since each set of parentheses has its own expression context,
|
||||
* we don't have to handle parentheses here */
|
||||
while (true) {
|
||||
b_queue_entry *entry = b_queue_pop_back(&state->s_operator_stack);
|
||||
entry = b_queue_pop_back(&state->s_operator_stack);
|
||||
if (!entry) {
|
||||
break;
|
||||
}
|
||||
@@ -355,20 +355,21 @@ enum ivy_status expr_finalise_arith(
|
||||
|
||||
b_queue q = B_QUEUE_INIT;
|
||||
b_queue_entry *tmp = NULL;
|
||||
b_queue_iterator_begin(&state->s_output_queue, &it);
|
||||
entry = b_queue_first(&state->s_output_queue);
|
||||
int i = 0;
|
||||
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
while (entry) {
|
||||
struct ivy_ast_node *item
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_output_queue, entry);
|
||||
|
||||
/* if the node is an operand, just push it to a temporary queue
|
||||
* and come back to it later. */
|
||||
if (item->n_type != IVY_AST_OP && item->n_type != IVY_AST_MSG) {
|
||||
/* operand */
|
||||
b_queue_push_back(&q, &item->n_entry);
|
||||
continue;
|
||||
goto next;
|
||||
}
|
||||
|
||||
const struct ivy_operator *op = NULL;
|
||||
@@ -388,7 +389,7 @@ enum ivy_status expr_finalise_arith(
|
||||
struct ivy_ast_node, tmp, n_entry);
|
||||
}
|
||||
b_queue_push_back(&q, &msg->n_base.n_entry);
|
||||
continue;
|
||||
goto next;
|
||||
}
|
||||
|
||||
struct ivy_ast_op_node *op_node = (struct ivy_ast_op_node *)item;
|
||||
@@ -397,7 +398,7 @@ enum ivy_status expr_finalise_arith(
|
||||
* queue as-is */
|
||||
if (op_node_is_complete(op_node)) {
|
||||
b_queue_push_back(&q, &item->n_entry);
|
||||
continue;
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* otherwise, pop the relevant operands from the operand
|
||||
@@ -432,6 +433,8 @@ enum ivy_status expr_finalise_arith(
|
||||
/* ...and push the newly-completed operator node to the operand
|
||||
* queue */
|
||||
b_queue_push_back(&q, &op_node->n_base.n_entry);
|
||||
next:
|
||||
entry = next;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -445,13 +448,15 @@ enum ivy_status expr_finalise_arith(
|
||||
* their operands have just been moved to the temporary operand stack
|
||||
* used above. move them back to the parser state's output queue here
|
||||
* so they can be used later. */
|
||||
b_queue_foreach (&it, &state->s_operator_stack) {
|
||||
b_queue_entry *entry = b_queue_pop_front(&q);
|
||||
if (!entry) {
|
||||
entry = b_queue_first(&state->s_operator_stack);
|
||||
while (entry) {
|
||||
b_queue_entry *entry2 = b_queue_pop_front(&q);
|
||||
if (!entry2) {
|
||||
return IVY_ERR_INTERNAL_FAILURE;
|
||||
}
|
||||
|
||||
b_queue_push_back(&state->s_output_queue, entry);
|
||||
b_queue_push_back(&state->s_output_queue, entry2);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -908,14 +913,17 @@ static struct ivy_ast_selector_node *keyword_selector_from_label_list(b_queue *l
|
||||
struct ivy_ast_selector_node *sel
|
||||
= (struct ivy_ast_selector_node *)ast_node_create(IVY_AST_SELECTOR);
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_entry *entry = b_queue_first(labels);
|
||||
b_queue_entry *next = NULL;
|
||||
|
||||
b_queue_iterator_begin(labels, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
while (entry) {
|
||||
struct ivy_token *label
|
||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
= b_unbox(struct ivy_token, entry, t_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(labels, entry);
|
||||
|
||||
b_queue_push_back(&sel->n_arg_labels, &label->t_entry);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
return sel;
|
||||
@@ -929,13 +937,17 @@ static struct ivy_ast_cascade_node *expr_finalise_cascade(
|
||||
|
||||
cascade->n_recipient = state->s_recipient;
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_iterator_begin(&state->s_cascade_msg, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
b_queue_entry *entry = b_queue_first(&state->s_cascade_msg);
|
||||
b_queue_entry *next = NULL;
|
||||
|
||||
while (entry) {
|
||||
struct ivy_ast_node *msg
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_cascade_msg, entry);
|
||||
|
||||
b_queue_push_back(&cascade->n_msg, &msg->n_entry);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
return cascade;
|
||||
@@ -950,15 +962,17 @@ static struct ivy_ast_msg_node *expr_finalise_keyword_msg(
|
||||
msg->n_recipient = state->s_recipient;
|
||||
msg->n_sel = keyword_selector_from_label_list(&state->s_labels);
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_entry *entry = b_queue_first(&state->s_args);
|
||||
b_queue_entry *next = NULL;
|
||||
|
||||
b_queue_iterator_begin(&state->s_args, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_args, entry);
|
||||
|
||||
b_queue_push_back(&msg->n_arg, &arg->n_entry);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
return msg;
|
||||
@@ -974,22 +988,28 @@ static struct ivy_ast_msg_node *expr_finalise_complex_msg(
|
||||
|
||||
state->s_msg = NULL;
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_iterator_begin(&state->s_labels, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
b_queue_entry *entry = b_queue_first(&state->s_labels);
|
||||
b_queue_entry *next = NULL;
|
||||
while (entry) {
|
||||
struct ivy_token *label
|
||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
= b_unbox(struct ivy_token, entry, t_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_labels, entry);
|
||||
b_queue_push_back(&msg->n_sel->n_arg_labels, &label->t_entry);
|
||||
|
||||
entry = next;
|
||||
}
|
||||
|
||||
b_queue_iterator_begin(&state->s_args, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
entry = b_queue_first(&state->s_args);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&state->s_args, entry);
|
||||
|
||||
b_queue_push_back(&msg->n_arg, &arg->n_entry);
|
||||
|
||||
entry = next;
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../node.h"
|
||||
#include "expr.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <ivy/lang/operator.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
struct ivy_ast_ident_node *ident = (struct ivy_ast_ident_node *)node;
|
||||
|
||||
b_string_append_cstrf(str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
ident->n_content->t_str);
|
||||
b_string_append_cstrf(
|
||||
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
ident->n_content->t_str);
|
||||
}
|
||||
|
||||
struct ast_node_type ident_node_ops = {
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
struct ivy_ast_int_node *v = (struct ivy_ast_int_node *)node;
|
||||
|
||||
b_string_append_cstrf(str, "%s (%llu)", ivy_ast_node_type_to_string(node->n_type),
|
||||
v->n_value->t_int);
|
||||
b_string_append_cstrf(
|
||||
str, "%s (%llu)", ivy_ast_node_type_to_string(node->n_type),
|
||||
v->n_value->t_int);
|
||||
}
|
||||
|
||||
struct ast_node_type int_node_ops = {
|
||||
|
||||
@@ -63,12 +63,11 @@ enum ivy_status iterate_postorder(
|
||||
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
node->n_it.it_depth = 0;
|
||||
|
||||
b_queue_iterator q_it;
|
||||
b_queue_iterator_begin(&it->it_queue, &q_it);
|
||||
b_queue_entry *entry = b_queue_first(&it->it_queue);
|
||||
|
||||
while (b_queue_iterator_is_valid(&q_it)) {
|
||||
while (entry) {
|
||||
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
|
||||
struct ivy_ast_node_iterator_entry, q_it.entry, it_entry);
|
||||
struct ivy_ast_node_iterator_entry, entry, it_entry);
|
||||
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
@@ -78,11 +77,11 @@ enum ivy_status iterate_postorder(
|
||||
|
||||
const struct ast_node_type *type = get_ast_node_type(node->n_type);
|
||||
if (type->n_collect_children) {
|
||||
it->it_insert_after = q_it.entry;
|
||||
it->it_insert_after = entry;
|
||||
type->n_collect_children(node, it);
|
||||
}
|
||||
|
||||
b_queue_iterator_next(&q_it);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
while (!b_queue_empty(&it->it_queue)) {
|
||||
@@ -111,12 +110,11 @@ enum ivy_status ivy_ast_node_iterate(
|
||||
b_queue_push_back(&it->it_queue, &node->n_it.it_entry);
|
||||
node->n_it.it_depth = 0;
|
||||
|
||||
b_queue_iterator q_it;
|
||||
b_queue_iterator_begin(&it->it_queue, &q_it);
|
||||
b_queue_entry *entry = b_queue_first(&it->it_queue);
|
||||
|
||||
while (b_queue_iterator_is_valid(&q_it)) {
|
||||
while (entry) {
|
||||
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
|
||||
struct ivy_ast_node_iterator_entry, q_it.entry, it_entry);
|
||||
struct ivy_ast_node_iterator_entry, entry, it_entry);
|
||||
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
@@ -132,11 +130,11 @@ enum ivy_status ivy_ast_node_iterate(
|
||||
|
||||
const struct ast_node_type *type = get_ast_node_type(node->n_type);
|
||||
if (type->n_collect_children) {
|
||||
it->it_insert_after = q_it.entry;
|
||||
it->it_insert_after = entry;
|
||||
type->n_collect_children(node, it);
|
||||
}
|
||||
|
||||
b_queue_iterator_next(&q_it);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
while (!b_queue_empty(&it->it_queue)) {
|
||||
|
||||
@@ -147,11 +147,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_lambda_node *lambda = (struct ivy_ast_lambda_node *)node;
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &lambda->n_arg) {
|
||||
b_queue_entry *entry = b_queue_first(&lambda->n_arg);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *expr
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, expr);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
if (lambda->n_body) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
|
||||
@@ -262,10 +262,10 @@ static void match_collect_children(
|
||||
|
||||
ast_node_iterator_enqueue_node(iterator, node, match->n_cond);
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &match->n_branches) {
|
||||
b_queue_entry *entry = b_queue_first(&match->n_branches);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *branch
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, branch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,12 @@ static void collect_children(
|
||||
iterator, node, (struct ivy_ast_node *)msg->n_sel);
|
||||
}
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &msg->n_arg) {
|
||||
b_queue_entry *entry = b_queue_first(&msg->n_arg);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *arg
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, arg);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
|
||||
struct msgh_parser_state {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -250,7 +250,7 @@ struct ivy_ast_node *ast_node_create(enum ivy_ast_node_type type)
|
||||
return node;
|
||||
}
|
||||
|
||||
void ivy_ast_node_to_string(struct ivy_ast_node *node, struct b_string *out)
|
||||
void ivy_ast_node_to_string(struct ivy_ast_node *node, b_string *out)
|
||||
{
|
||||
const struct ast_node_type *type_info = get_ast_node_type(node->n_type);
|
||||
if (!type_info) {
|
||||
@@ -304,12 +304,11 @@ void ivy_ast_node_destroy(struct ivy_ast_node *node)
|
||||
b_queue_push_back(&it.it_queue, &node->n_it.it_entry);
|
||||
node->n_it.it_depth = 0;
|
||||
|
||||
b_queue_iterator q_it;
|
||||
b_queue_iterator_begin(&it.it_queue, &q_it);
|
||||
b_queue_entry *entry = b_queue_first(&it.it_queue);
|
||||
|
||||
while (b_queue_iterator_is_valid(&q_it)) {
|
||||
while (entry) {
|
||||
struct ivy_ast_node_iterator_entry *it_entry = b_unbox(
|
||||
struct ivy_ast_node_iterator_entry, q_it.entry, it_entry);
|
||||
struct ivy_ast_node_iterator_entry, entry, it_entry);
|
||||
node = b_unbox(struct ivy_ast_node, it_entry, n_it);
|
||||
|
||||
if (!node) {
|
||||
@@ -319,11 +318,11 @@ void ivy_ast_node_destroy(struct ivy_ast_node *node)
|
||||
|
||||
const struct ast_node_type *type = get_ast_node_type(node->n_type);
|
||||
if (type->n_collect_children) {
|
||||
it.it_insert_after = q_it.entry;
|
||||
it.it_insert_after = entry;
|
||||
type->n_collect_children(node, &it);
|
||||
}
|
||||
|
||||
b_queue_iterator_next(&q_it);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
while (!b_queue_empty(&it.it_queue)) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef _AST_NODE_H_
|
||||
#define _AST_NODE_H_
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/ast.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
|
||||
@@ -46,7 +47,7 @@ typedef struct token_parse_result (*token_parse_function)(
|
||||
struct ast_node_type {
|
||||
enum ivy_status (*n_add_child)(
|
||||
struct parser_state *, struct ivy_ast_node *);
|
||||
void (*n_to_string)(struct ivy_ast_node *, struct b_string *);
|
||||
void (*n_to_string)(struct ivy_ast_node *, b_string *);
|
||||
void (*n_init_state)(struct ivy_parser *, struct parser_state *, uintptr_t);
|
||||
void (*n_collect_children)(
|
||||
struct ivy_ast_node *, struct ivy_ast_node_iterator *);
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
#include "iterate.h"
|
||||
#include <blue/object/string.h>
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
struct ivy_ast_op_node *op = (struct ivy_ast_op_node *)node;
|
||||
|
||||
b_string_append_cstrf(str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type), ivy_operator_id_to_string(op->n_op->op_id));
|
||||
b_string_append_cstrf(
|
||||
str, "%s (%s)", ivy_ast_node_type_to_string(node->n_type),
|
||||
ivy_operator_id_to_string(op->n_op->op_id));
|
||||
}
|
||||
|
||||
static void collect_children(
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <blue/object/string.h>
|
||||
|
||||
enum package_type {
|
||||
PACKAGE_NONE = 0,
|
||||
@@ -34,9 +34,13 @@ struct package_parser_state {
|
||||
struct ivy_ast_node *s_cond;
|
||||
};
|
||||
|
||||
static enum ivy_status add_package_item(struct package_parser_state *state, struct ivy_ast_node *index, struct ivy_ast_node *value)
|
||||
static enum ivy_status add_package_item(
|
||||
struct package_parser_state *state, struct ivy_ast_node *index,
|
||||
struct ivy_ast_node *value)
|
||||
{
|
||||
struct ivy_ast_pkg_static_item_node *item = (struct ivy_ast_pkg_static_item_node *)ast_node_create(IVY_AST_PKG_ITEM);
|
||||
struct ivy_ast_pkg_static_item_node *item
|
||||
= (struct ivy_ast_pkg_static_item_node *)ast_node_create(
|
||||
IVY_AST_PKG_ITEM);
|
||||
if (!item) {
|
||||
return IVY_ERR_NO_MEMORY;
|
||||
}
|
||||
@@ -64,7 +68,8 @@ static struct ivy_ast_node *finalise_package(struct package_parser_state *state)
|
||||
|
||||
switch (state->s_type) {
|
||||
case PACKAGE_STATIC:
|
||||
s = (struct ivy_ast_pkg_static_node *)ast_node_create(IVY_AST_PKG_STATIC);
|
||||
s = (struct ivy_ast_pkg_static_node *)ast_node_create(
|
||||
IVY_AST_PKG_STATIC);
|
||||
|
||||
if (!s) {
|
||||
return NULL;
|
||||
@@ -74,7 +79,8 @@ static struct ivy_ast_node *finalise_package(struct package_parser_state *state)
|
||||
state->s_items = B_QUEUE_INIT;
|
||||
return (struct ivy_ast_node *)s;
|
||||
case PACKAGE_DYNAMIC:
|
||||
d = (struct ivy_ast_pkg_dynamic_node *)ast_node_create(IVY_AST_PKG_DYNAMIC);
|
||||
d = (struct ivy_ast_pkg_dynamic_node *)ast_node_create(
|
||||
IVY_AST_PKG_DYNAMIC);
|
||||
if (!d) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -98,7 +104,8 @@ static struct ivy_ast_node *finalise_package(struct package_parser_state *state)
|
||||
static struct token_parse_result parse_equal_right_angle(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
|
||||
struct package_parser_state *state
|
||||
= parser_get_state(ctx, struct package_parser_state);
|
||||
|
||||
if (state->s_type == PACKAGE_NONE) {
|
||||
state->s_type = PACKAGE_STATIC;
|
||||
@@ -123,7 +130,9 @@ static struct token_parse_result parse_equal_right_angle(
|
||||
state->s_next_index = state->s_prev_node;
|
||||
state->s_prev_node = NULL;
|
||||
|
||||
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
|
||||
struct expr_parser_state *expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr_add_terminator(expr, IVY_SYM_COMMA);
|
||||
expr->s_subexpr_depth = 1;
|
||||
|
||||
@@ -133,7 +142,8 @@ static struct token_parse_result parse_equal_right_angle(
|
||||
static struct token_parse_result parse_comma(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
|
||||
struct package_parser_state *state
|
||||
= parser_get_state(ctx, struct package_parser_state);
|
||||
|
||||
if (state->s_type == PACKAGE_NONE) {
|
||||
state->s_type = PACKAGE_STATIC;
|
||||
@@ -144,7 +154,8 @@ static struct token_parse_result parse_comma(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA && state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
|
||||
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA
|
||||
&& state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
|
||||
/* token unexpected at this time. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
@@ -154,14 +165,17 @@ static struct token_parse_result parse_comma(
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
enum ivy_status status = add_package_item(state, state->s_next_index, state->s_prev_node);
|
||||
enum ivy_status status = add_package_item(
|
||||
state, state->s_next_index, state->s_prev_node);
|
||||
if (status != IVY_OK) {
|
||||
return PARSE_RESULT(status, 0);
|
||||
}
|
||||
|
||||
state->s_prev = IVY_SYM_COMMA;
|
||||
|
||||
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
|
||||
struct expr_parser_state *expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr_add_terminator(expr, IVY_SYM_EQUAL_RIGHT_ANGLE);
|
||||
expr->s_subexpr_depth = 1;
|
||||
|
||||
@@ -171,7 +185,8 @@ static struct token_parse_result parse_comma(
|
||||
static struct token_parse_result parse_right_brace(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
|
||||
struct package_parser_state *state
|
||||
= parser_get_state(ctx, struct package_parser_state);
|
||||
|
||||
if (state->s_type == PACKAGE_NONE) {
|
||||
state->s_type = PACKAGE_STATIC;
|
||||
@@ -181,13 +196,15 @@ static struct token_parse_result parse_right_brace(
|
||||
|
||||
switch (state->s_type) {
|
||||
case PACKAGE_STATIC:
|
||||
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA && state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
|
||||
if (state->s_prev != IVY_SYM_LEFT_BRACE && state->s_prev != IVY_SYM_COMMA
|
||||
&& state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
|
||||
/* token unexpected at this time. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_prev_node) {
|
||||
status = add_package_item(state, state->s_next_index, state->s_prev_node);
|
||||
status = add_package_item(
|
||||
state, state->s_next_index, state->s_prev_node);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -235,7 +252,8 @@ static struct token_parse_result parse_right_brace(
|
||||
static struct token_parse_result parse_for(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
|
||||
struct package_parser_state *state
|
||||
= parser_get_state(ctx, struct package_parser_state);
|
||||
|
||||
if (state->s_type == PACKAGE_NONE) {
|
||||
state->s_type = PACKAGE_DYNAMIC;
|
||||
@@ -260,7 +278,9 @@ static struct token_parse_result parse_for(
|
||||
state->s_transform = state->s_prev_node;
|
||||
state->s_prev_node = NULL;
|
||||
|
||||
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
|
||||
struct expr_parser_state *expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr_add_terminator(expr, IVY_KW_IN);
|
||||
expr->s_subexpr_depth = 1;
|
||||
|
||||
@@ -270,7 +290,8 @@ static struct token_parse_result parse_for(
|
||||
static struct token_parse_result parse_in(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
|
||||
struct package_parser_state *state
|
||||
= parser_get_state(ctx, struct package_parser_state);
|
||||
|
||||
if (state->s_type != PACKAGE_DYNAMIC) {
|
||||
/* this token cannot be used in this context. */
|
||||
@@ -291,7 +312,9 @@ static struct token_parse_result parse_in(
|
||||
state->s_item = state->s_prev_node;
|
||||
state->s_prev_node = NULL;
|
||||
|
||||
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
|
||||
struct expr_parser_state *expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr_add_terminator(expr, IVY_KW_IF);
|
||||
expr->s_subexpr_depth = 1;
|
||||
|
||||
@@ -301,7 +324,8 @@ static struct token_parse_result parse_in(
|
||||
static struct token_parse_result parse_if(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct package_parser_state *state = parser_get_state(ctx, struct package_parser_state);
|
||||
struct package_parser_state *state
|
||||
= parser_get_state(ctx, struct package_parser_state);
|
||||
|
||||
if (state->s_type != PACKAGE_DYNAMIC) {
|
||||
/* this token cannot be used in this context. */
|
||||
@@ -322,7 +346,9 @@ static struct token_parse_result parse_if(
|
||||
state->s_source = state->s_prev_node;
|
||||
state->s_prev_node = NULL;
|
||||
|
||||
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
|
||||
struct expr_parser_state *expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr_add_terminator(expr, IVY_SYM_RIGHT_BRACE);
|
||||
expr->s_subexpr_depth = 1;
|
||||
|
||||
@@ -332,8 +358,7 @@ static struct token_parse_result parse_if(
|
||||
static enum ivy_status add_child(
|
||||
struct parser_state *parent, struct ivy_ast_node *child)
|
||||
{
|
||||
struct package_parser_state *state
|
||||
= (struct package_parser_state *)parent;
|
||||
struct package_parser_state *state = (struct package_parser_state *)parent;
|
||||
|
||||
if (state->s_prev_node) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
@@ -346,19 +371,22 @@ static enum ivy_status add_child(
|
||||
static void pkg_static_collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_pkg_static_node *pkg = (struct ivy_ast_pkg_static_node *)node;
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &pkg->n_items) {
|
||||
struct ivy_ast_node *item = b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
struct ivy_ast_pkg_static_node *pkg
|
||||
= (struct ivy_ast_pkg_static_node *)node;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&pkg->n_items);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *item
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, item);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void pkg_static_item_to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
struct ivy_ast_pkg_static_item_node *item = (struct ivy_ast_pkg_static_item_node *)node;
|
||||
struct ivy_ast_pkg_static_item_node *item
|
||||
= (struct ivy_ast_pkg_static_item_node *)node;
|
||||
|
||||
b_string_append_cstr(str, ivy_ast_node_type_to_string(node->n_type));
|
||||
|
||||
@@ -370,7 +398,8 @@ static void pkg_static_item_to_string(struct ivy_ast_node *node, b_string *str)
|
||||
static void pkg_static_item_collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_pkg_static_item_node *item = (struct ivy_ast_pkg_static_item_node *)node;
|
||||
struct ivy_ast_pkg_static_item_node *item
|
||||
= (struct ivy_ast_pkg_static_item_node *)node;
|
||||
|
||||
if (item->n_index) {
|
||||
ast_node_iterator_enqueue_node(iterator, node, item->n_index);
|
||||
@@ -384,7 +413,8 @@ static void pkg_static_item_collect_children(
|
||||
static void pkg_dynamic_collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_pkg_dynamic_node *pkg = (struct ivy_ast_pkg_dynamic_node *)node;
|
||||
struct ivy_ast_pkg_dynamic_node *pkg
|
||||
= (struct ivy_ast_pkg_dynamic_node *)node;
|
||||
|
||||
if (pkg->n_transform) {
|
||||
ast_node_iterator_enqueue_node(iterator, node, pkg->n_transform);
|
||||
@@ -410,7 +440,9 @@ static void init_state(struct ivy_parser *ctx, struct parser_state *sp, uintptr_
|
||||
state->s_prev = IVY_SYM_LEFT_BRACE;
|
||||
state->s_next_implicit_index = 0;
|
||||
|
||||
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
|
||||
struct expr_parser_state *expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr_add_terminator(expr, IVY_KW_FOR);
|
||||
expr->s_subexpr_depth = 1;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -252,22 +252,19 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
b_string_append_cstr(str, "(");
|
||||
}
|
||||
|
||||
b_queue_iterator label_it = {0};
|
||||
b_queue_iterator name_it = {0};
|
||||
|
||||
b_queue_iterator_begin(&sel->n_arg_labels, &label_it);
|
||||
b_queue_iterator_begin(&sel->n_arg_names, &name_it);
|
||||
b_queue_entry *label_entry = b_queue_first(&sel->n_arg_labels);
|
||||
b_queue_entry *name_entry = b_queue_first(&sel->n_arg_names);
|
||||
|
||||
int i = 0;
|
||||
while (b_queue_iterator_is_valid(&label_it)) {
|
||||
while (label_entry) {
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(str, " ");
|
||||
}
|
||||
|
||||
struct ivy_token *label, *name;
|
||||
|
||||
label = b_unbox(struct ivy_token, label_it.entry, t_entry);
|
||||
name = b_unbox(struct ivy_token, name_it.entry, t_entry);
|
||||
label = b_unbox(struct ivy_token, label_entry, t_entry);
|
||||
name = b_unbox(struct ivy_token, name_entry, t_entry);
|
||||
|
||||
if (label && label->t_type == IVY_TOK_LABEL && label->t_str) {
|
||||
b_string_append_cstrf(str, "%s:", label->t_str);
|
||||
@@ -283,8 +280,8 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
i++;
|
||||
}
|
||||
|
||||
b_queue_iterator_next(&label_it);
|
||||
b_queue_iterator_next(&name_it);
|
||||
label_entry = b_queue_next(label_entry);
|
||||
name_entry = b_queue_next(name_entry);
|
||||
}
|
||||
|
||||
if (sel->n_msg_name && !b_queue_empty(&sel->n_arg_labels)) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "iterate.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
|
||||
static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
@@ -68,11 +68,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_fstring_node *str = (struct ivy_ast_fstring_node *)node;
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &str->n_value) {
|
||||
b_queue_entry *entry = b_queue_first(&str->n_value);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,11 +236,12 @@ static void try_collect_children(
|
||||
|
||||
ast_node_iterator_enqueue_node(iterator, node, try->n_try);
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &try->n_catch) {
|
||||
b_queue_entry *entry = b_queue_first(&try->n_catch);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *catch
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, catch);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
if (try->n_finally) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "ivy/status.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -117,11 +117,12 @@ static void collect_children(
|
||||
{
|
||||
struct ivy_ast_tuple_node *tuple = (struct ivy_ast_tuple_node *)node;
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &tuple->n_members) {
|
||||
b_queue_entry *entry = b_queue_first(&tuple->n_members);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *item
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, item);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -68,10 +68,9 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
|
||||
int i = 0;
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &unit_import->n_ident) {
|
||||
struct ivy_token *tok
|
||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||
b_queue_entry *entry = b_queue_first(&unit_import->n_ident);
|
||||
while (entry) {
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(str, ".");
|
||||
@@ -79,6 +78,7 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
|
||||
b_string_append_cstr(str, tok->t_str);
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
b_string_append_cstr(str, ")");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "ctx.h"
|
||||
#include "node.h"
|
||||
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <ivy/lang/lex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -66,10 +66,9 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
b_string_append_cstr(str, " (");
|
||||
|
||||
int i = 0;
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &unit_package->n_ident) {
|
||||
struct ivy_token *tok
|
||||
= b_unbox(struct ivy_token, it.entry, t_entry);
|
||||
b_queue_entry *entry = b_queue_first(&unit_package->n_ident);
|
||||
while (entry) {
|
||||
struct ivy_token *tok = b_unbox(struct ivy_token, entry, t_entry);
|
||||
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(str, ".");
|
||||
|
||||
@@ -58,11 +58,12 @@ static void collect_children(
|
||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *iterator)
|
||||
{
|
||||
struct ivy_ast_unit_node *unit = (struct ivy_ast_unit_node *)node;
|
||||
b_queue_iterator it = {0};
|
||||
b_queue_foreach (&it, &unit->n_children) {
|
||||
b_queue_entry *entry = b_queue_first(&unit->n_children);
|
||||
while (entry) {
|
||||
struct ivy_ast_node *child
|
||||
= b_unbox(struct ivy_ast_node, it.entry, n_entry);
|
||||
= b_unbox(struct ivy_ast_node, entry, n_entry);
|
||||
ast_node_iterator_enqueue_node(iterator, node, child);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user