diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-08-22 15:48:52 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-08-22 15:55:46 +0300 |
| commit | dbf3ed3db10f9fa9157d661704e16ba5b73b0e84 (patch) | |
| tree | f4bc4a2d732e40294884277baf364a6fbf36b051 /src/ast.c | |
| parent | 1bb997feefda0154e975797faaacec7c47de55e0 (diff) | |
| download | ek-dbf3ed3db10f9fa9157d661704e16ba5b73b0e84.tar.gz ek-dbf3ed3db10f9fa9157d661704e16ba5b73b0e84.zip | |
disable ast dump when DEBUG=0
+ Also optimize ast dump generation a little bit
Diffstat (limited to 'src/ast.c')
| -rw-r--r-- | src/ast.c | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -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) |
