DISTCLEANFILES =
-CLEANFILES = src/namespecs.h $(EXTRA_LTLIBRARIES)
+CLEANFILES = $(EXTRA_LTLIBRARIES)
EXTRA_DIST = bootstrap $(DX_BASEDIR)/scripts/fix-gnulib.pl m4/gnulib-cache.m4 \
- src/types.lst src/specs.lst src/namespecs.sed src/parse.y \
- src/parse.stamp src/scan.l src/scan.stamp \
- COPYING.WTFPL2 README.md INSTALL
+ src/types.lst src/parse.y src/parse.stamp src/scan.l \
+ src/scan.stamp COPYING.WTFPL2 README.md INSTALL
dist_man_MANS = doc/cdecl99.1 doc/libcdecl.3
src/scan.lo: src/parse.h
src/parse-decl.lo: src/scan.h src/parse.h src/typemap.h
src/error.lo: src/errtab.h
-src/output.lo: src/namespecs.h
+src/output.lo: src/specstr.h
test/declgen.lo: test/typegen.h
-src/namespecs.h: $(srcdir)/src/specs.lst $(srcdir)/src/namespecs.sed
- $(AM_V_GEN) sed -f $(srcdir)/src/namespecs.sed \
- < $(srcdir)/src/specs.lst > $@.tmp
- $(AM_V_at) mv -f $@.tmp $@
-
# Supporting rules for gettext.
include $(top_srcdir)/common/snippet/gettext.mk
DISTCLEANFILES += src/cmdlist.h
EXTRA_DIST += src/gen-cmdlist.awk
+src/specstr.h: src/gen-specstr.awk src/cdecl.h
+ $(AM_V_GEN) $(AWK) -f $(srcdir)/src/gen-specstr.awk \
+ $(srcdir)/src/cdecl.h >$@.tmp
+ $(AM_V_at) mv -f $@.tmp $@
+DISTCLEANFILES += src/specstr.h
+EXTRA_DIST += src/gen-specstr.awk
+
src/typemap.h: src/gen-typemap.awk src/types.lst
$(AM_V_GEN) $(AWK) -f $(srcdir)/src/gen-typemap.awk \
$(srcdir)/src/types.lst >$@.tmp
/commands.h
/errtab.h
/execute.c
-/namespecs.h
/options.h
/parse.[ch]
/scan.[ch]
+/specstr.h
/typemap.h
--- /dev/null
+#!/bin/awk -f
+#
+# Copyright © 2021 Nick Bowler
+#
+# Generate a function to return the C keyword corresponding to a specifier
+# type as a string, for internal use by the output routines.
+#
+# 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-specstr.awk from " FILENAME
+ } else {
+ print " * Automatically generated by gen-specstr.awk"
+ }
+ print " * Do not edit."
+ print " */"
+}
+
+BEGIN {
+ kinds["TYPE"] = kinds["STOR"] = kinds["QUAL"] = kinds["FUNC"] = 1
+ underscore["BOOL"] = underscore["COMPLEX"] = underscore["IMAGINARY"] = 1
+}
+
+$1 ~ /^CDECL_/ {
+ sub(/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ_].*/, "", $1)
+
+ split($1, parts, "_")
+ if (parts[2] in kinds) {
+ if (parts[3] == "IDENT") {
+ s = ""
+ } else if (parts[3] in underscore) {
+ s = "_" substr(parts[3], 1, 1) tolower(substr(parts[3], 2))
+ } else {
+ s = tolower(parts[3])
+ }
+ specs[$1] = s
+ }
+}
+
+END {
+ print "static inline const char *spec_string(unsigned type)\n{"
+ print "\tswitch (type) {"
+
+ for (s in specs) {
+ print "\tcase " s ": return \"" specs[s] "\";"
+ }
+
+ print "\t}"
+ print "\n\tassert(0);"
+ print "}"
+}
+++ /dev/null
-1i\
-/*\
- * 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.\
- */
-1i\
-/*\
- * This file is automatically generated by namespecs.sed.\
- */
-/[^_[:alpha:][:space:]]/b
-s/[[:space:]][[:space:]]*/ /g
-h
-s/_//g
-y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
-s/\([[:upper:]]*\) \([[:upper:]]*\)/case CDECL_\1_\2:/
-p
-x
-s/.* //
-s/ident//
-s/.*/ return "&";/
return ret + cdecl__advance_(buf, n, rc);
}
-static const char *explain_spec_simple(struct cdecl_declspec *s)
-{
- switch (s->type) {
-# include "namespecs.h"
- }
-
- assert(0);
-}
+#include "specstr.h"
static size_t explain_spec(char *buf, size_t n, struct cdecl_declspec *s)
{
- const char *keyword = explain_spec_simple(s);
+ const char *keyword = spec_string(s->type);
if (keyword[0] && s->ident)
return snprintf(buf, n, "%s %s", keyword, s->ident);
+++ /dev/null
-/* The complete list of declaration specifiers, in desired output order. */
-stor typedef
-stor extern
-stor static
-stor auto
-stor register
-func inline
-qual restrict
-qual volatile
-qual const
-type void
-type signed
-type unsigned
-type char
-type short
-type long
-type int
-type float
-type double
-type _Complex
-type _Imaginary
-type _Bool
-type struct
-type union
-type enum
-type ident