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 | |
| 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')
| -rw-r--r-- | src/actualize.c | 2 | ||||
| -rw-r--r-- | src/ast.c | 33 |
2 files changed, 17 insertions, 18 deletions
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) |
