From 92bbf45f333bbf9190befc52a6bc114dc2957e41 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 7 Aug 2022 15:26:53 +0200 Subject: basic templates (generics) --- bootstrap/dump.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'bootstrap/dump.c') diff --git a/bootstrap/dump.c b/bootstrap/dump.c index 84c4bbe..dae457a 100644 --- a/bootstrap/dump.c +++ b/bootstrap/dump.c @@ -3,6 +3,8 @@ static void pritype(const struct type *ty) { + const char *kind; + assert(ty); if (ty->konst) epri("const "); @@ -44,13 +46,25 @@ pritype(const struct type *ty) { epri("%s", ty->enu.name ? ty->enu.name : "(anonymous enum)"); break; case TYstruct: - epri("%s", ty->agg.name ? ty->agg.name : "(anonymous struct)"); - break; + kind = "struct"; + goto agg; case TYunion: - epri("%s", ty->agg.name ? ty->agg.name : "(anonymous union)"); - break; + kind = "union"; + goto agg; case TYeunion: - epri("%s", ty->agg.name ? ty->agg.name : "(anonymous tagged union)"); + kind = "tagged union"; + agg: + epri("%s", ty->agg.name ? ty->agg.name : "(anonymous %s)", kind); + if (ty->agg.tpargs.n) { + epri("<"); + int n = ty->agg.tpargs.n; + for (int i = 0; i < n; ++i) { + epri("%t", ty->agg.tpargs.d[i].ty); + if (i < n - 1) + epri(", "); + } + epri("%bc", '>'); + } break; } } @@ -141,6 +155,10 @@ tok2str(struct tok tok) { } buf[i] = '\0'; strcat(buf, "'"); + } else if (tok.t == TKtype) { + return ""; + } else if (tok.t == TKexpr) { + return ""; } else { snprintf(buf, sizeof buf - 1, "`%c'", tok.t); } @@ -417,6 +435,8 @@ dumpdecl(const struct decl *decl, int ws) { } epri("}\n"); break; + case Dtepl: + assert(0); } } -- cgit v1.2.3