]> git.draconx.ca Git - cdecl99.git/blob - src/gen-typemap.awk
Release 1.3.
[cdecl99.git] / src / gen-typemap.awk
1 #!/bin/awk -f
2 #
3 # Copyright © 2021 Nick Bowler
4 #
5 # Generate a test for whether a particuar combination of type specifiers
6 # represents a valid type, for internal use by the declaration parser.
7 #
8 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
9 # This is free software: you are free to do what the fuck you want to.
10 # There is NO WARRANTY, to the extent permitted by law.
11
12 END {
13   print "/*"
14   if (FILENAME) {
15     print " * Automatically generated by gen-typemap.awk from " FILENAME
16   } else {
17     print " * Automatically generated by gen-typemap.awk"
18   }
19   print " * Do not edit."
20   print " */"
21 }
22
23 BEGIN {
24   OFS = "\n\t   | "
25   count = 0
26 }
27
28 $0 ~ /^[abcdefghijklmnopqrstuvwxyz_]/ {
29   long = 0
30   for (i = 1; i <= NF; i++) {
31     if ($i == "long") {
32       if (long++) {
33         $i = "llong"
34       }
35     }
36
37     sub(/_/, "", $i)
38     $i = "1ul<<(CDECL_TYPE_" toupper($i) "-CDECL_SPEC_TYPE)"
39   }
40   types[count++] = $0
41 }
42
43 END {
44   print "static inline int typemap_is_valid(unsigned long map)\n{"
45   print "\tswitch (map) {"
46
47   for (i = 0; i < count; i++) {
48     print "\tcase " types[i] ":"
49   }
50
51   print "\t\treturn 1;"
52   print "\t}\n"
53   print "\treturn 0;"
54   print "}"
55 }