diff options
| -rw-r--r-- | include/ek/ast.h | 8 | ||||
| -rw-r--r-- | src/actualize.c | 2 | ||||
| -rw-r--r-- | src/ast.c | 33 |
3 files changed, 25 insertions, 18 deletions
diff --git a/include/ek/ast.h b/include/ek/ast.h index 610efb6..9107e8a 100644 --- a/include/ek/ast.h +++ b/include/ek/ast.h @@ -665,11 +665,19 @@ struct ast *clone_ast_list(struct ast *l); struct type *clone_type(struct type *n); struct type *clone_type_list(struct type *l); +#if defined(DEBUG) void ast_dump_list(int depth, struct ast *root); void ast_dump(int depth, struct ast *node); void type_dump_list(struct type *root); void type_dump(struct type *node); +#else +#define ast_dump_list(depth, root) +#define ast_dump(depth, root) + +#define type_dump_list(root) +#define type_dump(root) +#endif /* DEBUG */ void ast_append(struct ast **list, struct ast *elem); void type_append(struct type **list, struct type *elem); diff --git a/src/actualize.c b/src/actualize.c index 0ea94a9..ca9e31e 100644 --- a/src/actualize.c +++ b/src/actualize.c @@ -18,6 +18,7 @@ #include <ek/vec.h> #define UNUSED(x) do { (void)(x); } while (0) +#define MAYBE_UNUSED(x) UNUSED(x) struct act_stack { struct ast *node; @@ -2142,6 +2143,7 @@ static int actualize_struct(struct act_state *state, struct ast *def = file_scope_find_type(scope, id); int ret = scope_add_expd_struct(scope, def, types, node); + MAYBE_UNUSED(ret); assert(ret == 0); foreach_node(n, struct_body(node)) { @@ -193,19 +193,6 @@ struct type *type_prepend(struct type *list, struct type *elem) return elem; } -static void dump(int depth, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - printf("//"); - for (int i = 0; i < depth; ++i) - printf(" "); - - vprintf(fmt, args); - - va_end(args); -} - const char *primitive_str(struct type *type) { switch (type->k) { @@ -219,6 +206,13 @@ const char *primitive_str(struct type *type) return "unimp"; } +#if defined(DEBUG) +#define dump(depth, fmt, ...) \ + do { \ + printf("//%*s", 2 * depth, ""); \ + printf(fmt,##__VA_ARGS__); \ + } while (0) + void ast_dump(int depth, struct ast *n) { if (!n) { @@ -303,9 +297,9 @@ void ast_dump(int depth, struct ast *n) depth++; if (n->t) { - printf(" ("); + fputs(" (", stdout); type_dump_list(n->t); - printf(")"); + putchar(')'); } if (n->t2) @@ -314,7 +308,7 @@ void ast_dump(int depth, struct ast *n) if (n->scope) printf(" {%llu}", (unsigned long long)n->scope->number); - printf("\n"); + putchar('\n'); if (n->s) dump(depth, "%s\n", n->s); @@ -350,11 +344,11 @@ void ast_dump_list(int depth, struct ast *root) void type_dump(struct type *n) { if (!n) { - printf(" {NULL}"); + fputs(" {NULL}", stdout); return; } - printf(" "); + putchar(' '); #define DUMP(x) case x: printf(#x); break; switch (n->k) { @@ -389,6 +383,9 @@ void type_dump_list(struct type *root) } } +#undef dump +#endif /* DEBUG */ + struct ast *clone_ast(struct ast *n) { if (!n) |
