summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-06-02 11:43:01 +0000
committerBruno Haible <bruno@clisp.org>2003-06-02 11:43:01 +0000
commitfcd638a42fbfdf82a97d34a36a5e8b0f58bd0eff (patch)
treefe0e7857e3d0dfb128f0a9ba3dc637a72ac54fda
parenteba9cf38227f23a240f6ac9c614a2676e955acda (diff)
downloadgperf-fcd638a42fbfdf82a97d34a36a5e8b0f58bd0eff.tar.gz
Support for abbreviated struct declarations.
-rw-r--r--ChangeLog11
-rw-r--r--doc/gperf.texi18
-rw-r--r--src/input.cc2
-rw-r--r--tests/Makefile.in2
-rw-r--r--tests/incomplete.exp125
-rw-r--r--tests/incomplete.gperf14
6 files changed, 168 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 27e8918..f437628 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2003-05-31 Bruno Haible <bruno@clisp.org>
+
+ * doc/gperf.texi (User-supplied Struct): Mention the possibility of an
+ abbreviated struct declaration.
+ * src/input.cc (Input::read_input): Support struct declarations of the
+ form "struct foo;".
+ * tests/incomplete.gperf: New file.
+ * tests/incomplete.exp: New file.
+ * tests/Makefile.in (check-test): Check incomplete.gperf too.
+ Reported by Rob Leslie <rob@mars.org>.
+
2003-05-20 Bruno Haible <bruno@clisp.org>
* doc/Makefile.in (gperf.ps): Don't use $< in a target rule.
diff --git a/doc/gperf.texi b/doc/gperf.texi
index 6d75300..7a92e91 100644
--- a/doc/gperf.texi
+++ b/doc/gperf.texi
@@ -380,7 +380,7 @@ input:
@example
@group
-struct months @{ char *name; int number; int days; int leap_days; @};
+struct month @{ char *name; int number; int days; int leap_days; @};
%%
january, 1, 31, 31
february, 2, 28, 29
@@ -403,6 +403,18 @@ other fields are a pair of consecutive percent signs, @samp{%%},
appearing left justified in the first column, as in the UNIX utility
@code{lex}.
+If the @code{struct} has already been declared in an include file, it can
+be mentioned in an abbreviated form, like this:
+
+@example
+@group
+struct month;
+%%
+january, 1, 31, 31
+...
+@end group
+@end example
+
@node Gperf Declarations, C Code Inclusion, User-supplied Struct, Declarations
@subsubsection Gperf Declarations
@@ -628,9 +640,9 @@ feature:
%@{
#include <assert.h>
/* This section of code is inserted directly into the output. */
-int return_month_days (struct months *months, int is_leap_year);
+int return_month_days (struct month *months, int is_leap_year);
%@}
-struct months @{ char *name; int number; int days; int leap_days; @};
+struct month @{ char *name; int number; int days; int leap_days; @};
%%
january, 1, 31, 31
february, 2, 28, 29
diff --git a/src/input.cc b/src/input.cc
index 0c0c819..1b2c459 100644
--- a/src/input.cc
+++ b/src/input.cc
@@ -713,7 +713,7 @@ Input::read_input ()
_struct_decl = struct_decl;
/* Set _struct_tag to the naked "struct something". */
const char *p;
- for (p = struct_decl; *p && *p != '{' && *p != '\n'; p++)
+ for (p = struct_decl; *p && *p != '{' && *p != ';' && *p != '\n'; p++)
;
for (; p > struct_decl;)
if (p[-1] == '\n' || p[-1] == ' ' || p[-1] == '\t')
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 2cd4f65..ad24806 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -162,6 +162,8 @@ check-test:
diff $(srcdir)/charsets.exp charsets.out
$(GPERF) -C -E -G -I -t < $(srcdir)/languages.gperf > languages.out
diff $(srcdir)/languages.exp languages.out
+ $(GPERF) -t < $(srcdir)/incomplete.gperf > incomplete.out
+ diff $(srcdir)/incomplete.exp incomplete.out
# prints out the help message
-$(GPERF) -h > test-6.out
diff $(srcdir)/test-6.exp test-6.out
diff --git a/tests/incomplete.exp b/tests/incomplete.exp
new file mode 100644
index 0000000..8cb0e78
--- /dev/null
+++ b/tests/incomplete.exp
@@ -0,0 +1,125 @@
+/* C code produced by gperf version 3.0 */
+/* Command-line: ../src/gperf -t */
+/* Computed positions: -k'1,3' */
+
+#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
+/* The character set is not based on ISO-646. */
+error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
+#endif
+
+struct month;
+
+#define TOTAL_KEYWORDS 12
+#define MIN_WORD_LENGTH 3
+#define MAX_WORD_LENGTH 9
+#define MIN_HASH_VALUE 3
+#define MAX_HASH_VALUE 18
+/* maximum key range = 16, duplicates = 0 */
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static unsigned int
+hash (str, len)
+ register const char *str;
+ register unsigned int len;
+{
+ static unsigned char asso_values[] =
+ {
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 5, 5, 5,
+ 0, 19, 5, 0, 19, 19, 0, 19, 10, 0,
+ 0, 5, 0, 19, 0, 0, 0, 19, 0, 19,
+ 19, 0, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19
+ };
+ return len + asso_values[(unsigned char)str[2]] + asso_values[(unsigned char)str[0]];
+}
+
+#ifdef __GNUC__
+__inline
+#endif
+struct month *
+in_word_set (str, len)
+ register const char *str;
+ register unsigned int len;
+{
+ static struct month wordlist[] =
+ {
+ {""}, {""}, {""},
+ {"may", 5, 31, 31},
+ {"june", 6, 30, 30},
+ {"march", 3, 31, 31},
+ {""},
+ {"january", 1, 31, 31},
+ {"november", 11, 30, 30},
+ {"september", 9, 30, 30},
+ {"april", 4, 30, 30},
+ {"august", 8, 31, 31},
+ {"october", 10, 31, 31},
+ {"december", 12, 31, 31},
+ {"july", 7, 31, 31},
+ {""}, {""}, {""},
+ {"february", 2, 28, 29}
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register int key = hash (str, len);
+
+ if (key <= MAX_HASH_VALUE && key >= 0)
+ {
+ register const char *s = wordlist[key].name;
+
+ if (*str == *s && !strcmp (str + 1, s + 1))
+ return &wordlist[key];
+ }
+ }
+ return 0;
+}
diff --git a/tests/incomplete.gperf b/tests/incomplete.gperf
new file mode 100644
index 0000000..f5296b1
--- /dev/null
+++ b/tests/incomplete.gperf
@@ -0,0 +1,14 @@
+struct month;
+%%
+january, 1, 31, 31
+february, 2, 28, 29
+march, 3, 31, 31
+april, 4, 30, 30
+may, 5, 31, 31
+june, 6, 30, 30
+july, 7, 31, 31
+august, 8, 31, 31
+september, 9, 30, 30
+october, 10, 31, 31
+november, 11, 30, 30
+december, 12, 31, 31