3 * Copyright © 2023 Nick Bowler
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.
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.
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/>.
22 #include "cdecl-internal.h"
25 static const struct keyword *in_word_set();
31 /* Note: the following options enable gperf-wordwrap.awk to do its thing */
32 %define word-array-name wordlist_wrapped
40 _Bool, PACK_TOKEN(T_BOOL )
41 _Complex, PACK_TOKEN(T_COMPLEX )
42 _Imaginary, PACK_TOKEN(T_IMAGINARY)
43 auto, PACK_TOKEN(T_AUTO )
44 char, PACK_TOKEN(T_CHAR )
45 const, PACK_TOKEN(T_CONST )
46 double, PACK_TOKEN(T_DOUBLE )
47 enum, PACK_TOKEN(T_ENUM )
48 extern, PACK_TOKEN(T_EXTERN )
49 float, PACK_TOKEN(T_FLOAT )
50 inline, PACK_TOKEN(T_INLINE )
51 int, PACK_TOKEN(T_INT )
52 long, PACK_TOKEN(T_LONG )
53 register, PACK_TOKEN(T_REGISTER )
54 restrict, PACK_TOKEN(T_RESTRICT )
55 short, PACK_TOKEN(T_SHORT )
56 signed, PACK_TOKEN(T_SIGNED )
57 static, PACK_TOKEN(T_STATIC )
58 struct, PACK_TOKEN(T_STRUCT )
59 typedef, PACK_TOKEN(T_TYPEDEF )
60 union, PACK_TOKEN(T_UNION )
61 unsigned, PACK_TOKEN(T_UNSIGNED )
62 void, PACK_TOKEN(T_VOID )
63 volatile, PACK_TOKEN(T_VOLATILE )
65 array, PACK_TOKEN(T_ARRAY ) | 0x80
66 as, PACK_TOKEN(T_AS ) | 0x80
67 declare, PACK_TOKEN(T_DECLARE ) | 0x80
68 function, PACK_TOKEN(T_FUNCTION ) | 0x80
69 of, PACK_TOKEN(T_OF ) | 0x80
70 pointer, PACK_TOKEN(T_POINTER ) | 0x80
71 returning, PACK_TOKEN(T_RETURNING) | 0x80
72 to, PACK_TOKEN(T_TO ) | 0x80
73 type, PACK_TOKEN(T_TYPE ) | 0x80
74 variable-length, PACK_TOKEN(T_VLA ) | 0x80
76 int cdecl__to_keyword(const char *s, int len, int english_mode)
78 const struct keyword *k;
80 if ((k = in_word_set(s, len))) {
81 unsigned x = (k->token & 0x7fu);
83 if (english_mode || !(k->token & ~0x7fu)) {
84 return UNPACK_TOKEN(x);
91 static const char *wordlist_func(const struct keyword *k)
93 unsigned x = k->token & 0x7f;
97 return cdecl__token_name(UNPACK_TOKEN(x));