#ifndef _PLY_NODE_H #define _PLY_NODE_H #include #include #include "ir.h" #include "sym.h" #include "type.h" /* REEEEEEEEEEEEEEMOVE */ typedef struct node node_t; enum ntype { N_EXPR, N_IDENT, N_NUM, N_STRING, }; struct node { struct node *next, *prev, *up; enum ntype ntype; union { struct { char *func; struct node *args; } expr; struct { char *name; } ident; struct { int64_t num; } num; struct { char *data; } string; }; type_t *type; sym_t *sym; irstate_t irs; }; /* debug */ void node_print(struct node *n, FILE *fp); void node_dump (struct node *n, FILE *fp); typedef int (*walk_fn)(struct node *, void *); int node_walk(struct node *n, walk_fn pre, walk_fn post, void *ctx); int node_replace(struct node *n, struct node *new); #define node_expr_foreach(_expr, _arg) \ for ((_arg) = (_expr)->args; (_arg); (_arg) = (_arg)->next) /* constructors */ struct node *node_string(char *data); struct node *node_num (int64_t num); struct node *node_ident (char *name); struct node *node_append(struct node *n, struct node *arg); struct node *node_expr (char *func, ...); /* static inline node_t *node_head(node_t *n) */ /* { */ /* if (!n) */ /* return NULL; */ /* for (; n->prev; n = n->prev); */ /* return n; */ /* } */ /* static inline node_t *node_prev(node_t *n) */ /* { */ /* return n ? n->prev : NULL; */ /* } */ /* static inline node_t *node_next(node_t *n) */ /* { */ /* return n ? n->next : NULL; */ /* } */ /* static inline node_t *node_up(node_t *n) */ /* { */ /* return n ? n->up : NULL; */ /* } */ #endif /* _PLY_NODE_H */