#!/bin/awk -f # # Copyright © 2021 Nick Bowler # # Generate a test for whether a particuar combination of type specifiers # represents a valid type, for internal use by the declaration parser. # # License WTFPL2: Do What The Fuck You Want To Public License, version 2. # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. END { print "/*" if (FILENAME) { print " * Automatically generated by gen-typemap.awk from " FILENAME } else { print " * Automatically generated by gen-typemap.awk" } print " * Do not edit." print " */" } BEGIN { OFS = "\n\t | " count = 0 } $0 ~ /^[abcdefghijklmnopqrstuvwxyz_]/ { long = 0 for (i = 1; i <= NF; i++) { if ($i == "long") { if (long++) { $i = "llong" } } sub(/_/, "", $i) $i = "1ul<<(CDECL_TYPE_" toupper($i) "-CDECL_SPEC_TYPE)" } types[count++] = $0 } END { print "static inline int typemap_is_valid(unsigned long map)\n{" print "\tswitch (map) {" for (i = 0; i < count; i++) { print "\tcase " types[i] ":" } print "\t\treturn 1;" print "\t}\n" print "\treturn 0;" print "}" }