frontend: add parameters to print_ast_node iterator function
the caller can now specify whether the nodes should be printed in pre-order or post-order, and whether the output should be indented.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#include <blue/object/string.h>
|
#include <blue/object/string.h>
|
||||||
#include <blue/term.h>
|
#include <blue/term.h>
|
||||||
#include <ivy/asm/lex.h>
|
#include <ivy/asm/lex.h>
|
||||||
@@ -132,10 +134,23 @@ extern void print_asm_lex_token(struct ivy_asm_token *tok)
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern enum ivy_status print_ast_node(
|
extern enum ivy_status print_ast_node(
|
||||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *it)
|
struct ivy_ast_node *node, enum ivy_ast_iteration_type type,
|
||||||
|
struct ivy_ast_node_iterator *it, void *arg)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < node->n_it.it_depth; i++) {
|
struct print_ast_node_args *args = arg;
|
||||||
b_puts(" ");
|
|
||||||
|
if (args && args->postorder && type != IVY_AST_ITERATION_POST) {
|
||||||
|
return IVY_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!args || !args->postorder) && type != IVY_AST_ITERATION_PRE) {
|
||||||
|
return IVY_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!args || (args && args->indent)) {
|
||||||
|
for (unsigned int i = 0; i < node->n_it.it_depth; i++) {
|
||||||
|
b_puts(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (node->n_type) {
|
switch (node->n_type) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define DEBUG_H_
|
#define DEBUG_H_
|
||||||
|
|
||||||
#include <ivy/status.h>
|
#include <ivy/status.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct ivy_token;
|
struct ivy_token;
|
||||||
struct ivy_asm_token;
|
struct ivy_asm_token;
|
||||||
@@ -9,10 +10,18 @@ struct ivy_asm_token;
|
|||||||
struct ivy_ast_node;
|
struct ivy_ast_node;
|
||||||
struct ivy_ast_node_iterator;
|
struct ivy_ast_node_iterator;
|
||||||
|
|
||||||
|
enum ivy_ast_iteration_type;
|
||||||
|
|
||||||
|
struct print_ast_node_args {
|
||||||
|
bool indent;
|
||||||
|
bool postorder;
|
||||||
|
};
|
||||||
|
|
||||||
extern void print_lex_token(struct ivy_token *tok);
|
extern void print_lex_token(struct ivy_token *tok);
|
||||||
extern void print_asm_lex_token(struct ivy_asm_token *tok);
|
extern void print_asm_lex_token(struct ivy_asm_token *tok);
|
||||||
|
|
||||||
extern enum ivy_status print_ast_node(
|
extern enum ivy_status print_ast_node(
|
||||||
struct ivy_ast_node *node, struct ivy_ast_node_iterator *it);
|
struct ivy_ast_node *node, enum ivy_ast_iteration_type type,
|
||||||
|
struct ivy_ast_node_iterator *it, void *arg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user