]> git.draconx.ca Git - cdecl99.git/blobdiff - test/typegen.sh
Add a tool to generate random declarations.
[cdecl99.git] / test / typegen.sh
diff --git a/test/typegen.sh b/test/typegen.sh
new file mode 100755 (executable)
index 0000000..1658d5d
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# Copyright © 2011 Nick Bowler
+#
+# 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.
+
+cat <<EOF
+/* This file was automatically generated by $0 $*. */
+struct cdecl_declspec *s, *p;
+EOF
+
+i=0
+while read line
+do
+       case "$line" in
+       [[:alpha:]_]*)
+               :
+               ;;
+       *)
+               printf '%s\n' "$line";
+               continue
+               ;;
+       esac
+
+       cat <<EOF
+case $i:
+       s = NULL;
+EOF
+
+       set $line
+       while test $# -gt 0
+       do
+               token=`printf '%s' "$1" | tr [:lower:] [:upper:] | tr -d _`
+               cat <<EOF
+       p = s;
+       s = malloc_nofail(sizeof *s);
+       *s = (struct cdecl_declspec) {
+               .type = CDECL_TYPE_$token,
+               .next = p,
+       };
+EOF
+               shift
+       done
+
+       i=`expr $i + 1`
+       cat <<EOF
+       return s;
+EOF
+done
+
+cat <<EOF
+default:
+       assert(0);
+#define TOTAL_TYPES $i
+EOF