| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #ifndef _PLY_NODE_H
- #define _PLY_NODE_H
- #include <stdint.h>
- #include <stdio.h>
- #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)->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 int node_is_block(struct node *n)
- {
- if (!n || (n->ntype != N_EXPR))
- return 0;
- return n->expr.func[0] == '\0';
- }
- /* 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 */
|