3 # Copyright © 2021-2022 Nick Bowler
5 # Generate a mapping from a (random) integer to a list of type specifiers
6 # represented by struct cdecl_declspec. Used internally by declgen to
7 # produce random valid declarations.
9 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
10 # This is free software: you are free to do what the fuck you want to.
11 # There is NO WARRANTY, to the extent permitted by law.
16 print " * Automatically generated by gen-typegen.awk from " FILENAME
18 print " * Automatically generated by gen-typegen.awk"
20 print " * Do not edit."
28 $0 ~ /^[abcdefghijklmnopqrstuvwxyz_]/ {
29 for (i = 1; i <= NF; i++) {
31 $i = "CDECL_TYPE_" toupper($i)
37 print "static inline struct cdecl_declspec *"
38 print "gen_raw_typespec_(unsigned type, struct cdecl_declspec *next)\n{"
39 print "\tstruct cdecl_declspec *s = malloc_nofail(sizeof *s);"
40 print "\t*s = (struct cdecl_declspec) { .next = next, .type = type };"
41 print "\treturn s;\n}\n"
43 print "static inline struct cdecl_declspec *"
44 print "gen_raw_typespecs(unsigned rngval)\n{"
45 print "\tswitch (rngval) {"
47 for (i = 0; i < count; i++) {
51 for (j = 1; j <= NF; j++) {
52 prefix = j == 1 ? "return" : "";
54 printf "\t\t%6s gen_raw_typespec_(%s,\n", prefix, $j
56 printf "\t\t%25sNULL%s;\n", "", substr("))))))))", 1, NF);
58 print "\tdefault:\n\t\tassert(0);\n\t}"
60 print "enum { GEN_TOTAL_TYPES = " count " };"