X-Git-Url: http://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/1c3b0c0e6f9339e76e42f6393e554c7dfc58e205..a2c3dad92b2bf55488174c203563224880380c9b:/t/gen-typegen.awk diff --git a/t/gen-typegen.awk b/t/gen-typegen.awk index a3a1527..0fb1a49 100755 --- a/t/gen-typegen.awk +++ b/t/gen-typegen.awk @@ -1,6 +1,6 @@ #!/bin/awk -f # -# Copyright © 2021-2022 Nick Bowler +# Copyright © 2021-2022, 2024 Nick Bowler # # Generate a mapping from a (random) integer to a list of type specifiers # represented by struct cdecl_declspec. Used internally by declgen to @@ -34,10 +34,12 @@ $0 ~ /^[abcdefghijklmnopqrstuvwxyz_]/ { } END { - print "static inline struct cdecl_declspec *" - print "gen_raw_typespec_(unsigned type, struct cdecl_declspec *next)\n{" - print "\tstruct cdecl_declspec *s = malloc_nofail(sizeof *s);" - print "\t*s = (struct cdecl_declspec) { .next = next, .type = type };" + print "static inline struct cdecl_declspec *"; + print "gen_raw_typespec_(unsigned type, struct cdecl_declspec *next)\n{"; + print "\tstruct cdecl_declspec *s = malloc_nofail(sizeof *s);"; + print "\ts->type = type;"; + print "\ts->next = next;"; + print "\ts->ident = 0;"; print "\treturn s;\n}\n" print "static inline struct cdecl_declspec *" @@ -45,15 +47,15 @@ END { print "\tswitch (rngval) {" for (i = 0; i < count; i++) { - print "\tcase " i ":" - $0 = specs[i] + print "\tcase " i ":"; - for (j = 1; j <= NF; j++) { + n = split(specs[i], parts); + for (j = 1; j <= n; j++) { prefix = j == 1 ? "return" : ""; - printf "\t\t%6s gen_raw_typespec_(%s,\n", prefix, $j + printf "\t\t%6s gen_raw_typespec_(%s,\n", prefix, parts[j]; } - printf "\t\t%25sNULL%s;\n", "", substr("))))))))", 1, NF); + printf "\t\t%25sNULL%s;\n", "", substr("))))))))", 1, n); } print "\tdefault:\n\t\tassert(0);\n\t}" print "}\n"