]> git.draconx.ca Git - cdecl99.git/blob - src/keywords.gperf
Release 1.3.
[cdecl99.git] / src / keywords.gperf
1 %{
2 /*
3  * Copyright © 2023-2024 Nick Bowler
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18
19 #include <config.h>
20 #include <string.h>
21 #include <inttypes.h>
22 #include "cdecl-internal.h"
23 #include "cdecl.h"
24 #include "parse.h"
25
26 static const struct keyword *in_word_set();
27 %}
28
29 %readonly-tables
30 %language=ANSI-C
31 %7bit
32
33 /* Note: the following options enable gperf-wordwrap.awk to do its thing */
34 %define word-array-name wordlist_wrapped
35 %null-strings
36 %struct-type
37
38 struct keyword {
39         uint_least16_t val;
40 };
41 %%
42 _Bool,           (PACK_TOKEN(T_BOOL     )<<8) | PACK_SPEC(CDECL_TYPE_BOOL)
43 _Complex,        (PACK_TOKEN(T_COMPLEX  )<<8) | PACK_SPEC(CDECL_TYPE_COMPLEX)
44 _Imaginary,      (PACK_TOKEN(T_IMAGINARY)<<8) | PACK_SPEC(CDECL_TYPE_IMAGINARY)
45 auto,            (PACK_TOKEN(T_AUTO     )<<8) | PACK_SPEC(CDECL_STOR_AUTO)
46 char,            (PACK_TOKEN(T_CHAR     )<<8) | PACK_SPEC(CDECL_TYPE_CHAR)
47 const,           (PACK_TOKEN(T_CONST    )<<8) | PACK_SPEC(CDECL_QUAL_CONST)
48 double,          (PACK_TOKEN(T_DOUBLE   )<<8) | PACK_SPEC(CDECL_TYPE_DOUBLE)
49 enum,            (PACK_TOKEN(T_ENUM     )<<8) | PACK_SPEC(CDECL_TYPE_ENUM)
50 extern,          (PACK_TOKEN(T_EXTERN   )<<8) | PACK_SPEC(CDECL_STOR_EXTERN)
51 float,           (PACK_TOKEN(T_FLOAT    )<<8) | PACK_SPEC(CDECL_TYPE_FLOAT)
52 inline,          (PACK_TOKEN(T_INLINE   )<<8) | PACK_SPEC(CDECL_FUNC_INLINE)
53 int,             (PACK_TOKEN(T_INT      )<<8) | PACK_SPEC(CDECL_TYPE_INT)
54 long,            (PACK_TOKEN(T_LONG     )<<8) | PACK_SPEC(CDECL_TYPE_LONG)
55 register,        (PACK_TOKEN(T_REGISTER )<<8) | PACK_SPEC(CDECL_STOR_REGISTER)
56 restrict,        (PACK_TOKEN(T_RESTRICT )<<8) | PACK_SPEC(CDECL_QUAL_RESTRICT)
57 short,           (PACK_TOKEN(T_SHORT    )<<8) | PACK_SPEC(CDECL_TYPE_SHORT)
58 signed,          (PACK_TOKEN(T_SIGNED   )<<8) | PACK_SPEC(CDECL_TYPE_SIGNED)
59 static,          (PACK_TOKEN(T_STATIC   )<<8) | PACK_SPEC(CDECL_STOR_STATIC)
60 struct,          (PACK_TOKEN(T_STRUCT   )<<8) | PACK_SPEC(CDECL_TYPE_STRUCT)
61 typedef,         (PACK_TOKEN(T_TYPEDEF  )<<8) | PACK_SPEC(CDECL_STOR_TYPEDEF)
62 union,           (PACK_TOKEN(T_UNION    )<<8) | PACK_SPEC(CDECL_TYPE_UNION)
63 unsigned,        (PACK_TOKEN(T_UNSIGNED )<<8) | PACK_SPEC(CDECL_TYPE_UNSIGNED)
64 void,            (PACK_TOKEN(T_VOID     )<<8) | PACK_SPEC(CDECL_TYPE_VOID)
65 volatile,        (PACK_TOKEN(T_VOLATILE )<<8) | PACK_SPEC(CDECL_QUAL_VOLATILE)
66 # english keywords
67 array,           (PACK_TOKEN(T_ARRAY    )<<8) | 0x8000
68 as,              (PACK_TOKEN(T_AS       )<<8) | 0x8000
69 declare,         (PACK_TOKEN(T_DECLARE  )<<8) | 0x8000
70 function,        (PACK_TOKEN(T_FUNCTION )<<8) | 0x8000
71 of,              (PACK_TOKEN(T_OF       )<<8) | 0x8000
72 pointer,         (PACK_TOKEN(T_POINTER  )<<8) | 0x8000
73 returning,       (PACK_TOKEN(T_RETURNING)<<8) | 0x8000
74 to,              (PACK_TOKEN(T_TO       )<<8) | 0x8000
75 type,            (PACK_TOKEN(T_TYPE     )<<8) | 0x8000
76 variable-length, (PACK_TOKEN(T_VLA      )<<8) | 0x8000
77 %%
78 unsigned cdecl__to_keyword(const char *s, int len, int english_mode)
79 {
80         const struct keyword *k;
81
82         if ((k = in_word_set(s, len))) {
83                 uint_least16_t x = k->val;
84
85                 if (english_mode || !(x & 0x8000)) {
86                         return x & 0x7fff;
87                 }
88         }
89
90         return (PACK_TOKEN(T_IDENT)<<8);
91 }
92
93 static const char *wordlist_func(const struct keyword *k)
94 {
95         unsigned x = (k->val >> 8) & 0x7f;
96
97         if (!x)
98                 return NULL;
99         return cdecl__token_name(UNPACK_TOKEN(x));
100 }