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"
26 static const struct keyword *in_word_set();
32 /* Note: the following options enable gperf-wordwrap.awk to do its thing */
33 %define word-array-name wordlist_wrapped
41 _Bool, (PACK_TOKEN(T_BOOL )<<8) | PACK_SPEC(CDECL_TYPE_BOOL)
42 _Complex, (PACK_TOKEN(T_COMPLEX )<<8) | PACK_SPEC(CDECL_TYPE_COMPLEX)
43 _Imaginary, (PACK_TOKEN(T_IMAGINARY)<<8) | PACK_SPEC(CDECL_TYPE_IMAGINARY)
44 auto, (PACK_TOKEN(T_AUTO )<<8) | PACK_SPEC(CDECL_STOR_AUTO)
45 char, (PACK_TOKEN(T_CHAR )<<8) | PACK_SPEC(CDECL_TYPE_CHAR)
46 const, (PACK_TOKEN(T_CONST )<<8) | PACK_SPEC(CDECL_QUAL_CONST)
47 double, (PACK_TOKEN(T_DOUBLE )<<8) | PACK_SPEC(CDECL_TYPE_DOUBLE)
48 enum, (PACK_TOKEN(T_ENUM )<<8) | PACK_SPEC(CDECL_TYPE_ENUM)
49 extern, (PACK_TOKEN(T_EXTERN )<<8) | PACK_SPEC(CDECL_STOR_EXTERN)
50 float, (PACK_TOKEN(T_FLOAT )<<8) | PACK_SPEC(CDECL_TYPE_FLOAT)
51 inline, (PACK_TOKEN(T_INLINE )<<8) | PACK_SPEC(CDECL_FUNC_INLINE)
52 int, (PACK_TOKEN(T_INT )<<8) | PACK_SPEC(CDECL_TYPE_INT)
53 long, (PACK_TOKEN(T_LONG )<<8) | PACK_SPEC(CDECL_TYPE_LONG)
54 register, (PACK_TOKEN(T_REGISTER )<<8) | PACK_SPEC(CDECL_STOR_REGISTER)
55 restrict, (PACK_TOKEN(T_RESTRICT )<<8) | PACK_SPEC(CDECL_QUAL_RESTRICT)
56 short, (PACK_TOKEN(T_SHORT )<<8) | PACK_SPEC(CDECL_TYPE_SHORT)
57 signed, (PACK_TOKEN(T_SIGNED )<<8) | PACK_SPEC(CDECL_TYPE_SIGNED)
58 static, (PACK_TOKEN(T_STATIC )<<8) | PACK_SPEC(CDECL_STOR_STATIC)
59 struct, (PACK_TOKEN(T_STRUCT )<<8) | PACK_SPEC(CDECL_TYPE_STRUCT)
60 typedef, (PACK_TOKEN(T_TYPEDEF )<<8) | PACK_SPEC(CDECL_STOR_TYPEDEF)
61 union, (PACK_TOKEN(T_UNION )<<8) | PACK_SPEC(CDECL_TYPE_UNION)
62 unsigned, (PACK_TOKEN(T_UNSIGNED )<<8) | PACK_SPEC(CDECL_TYPE_UNSIGNED)
63 void, (PACK_TOKEN(T_VOID )<<8) | PACK_SPEC(CDECL_TYPE_VOID)
64 volatile, (PACK_TOKEN(T_VOLATILE )<<8) | PACK_SPEC(CDECL_QUAL_VOLATILE)
66 array, (PACK_TOKEN(T_ARRAY )<<8) | 0x8000
67 as, (PACK_TOKEN(T_AS )<<8) | 0x8000
68 declare, (PACK_TOKEN(T_DECLARE )<<8) | 0x8000
69 function, (PACK_TOKEN(T_FUNCTION )<<8) | 0x8000
70 of, (PACK_TOKEN(T_OF )<<8) | 0x8000
71 pointer, (PACK_TOKEN(T_POINTER )<<8) | 0x8000
72 returning, (PACK_TOKEN(T_RETURNING)<<8) | 0x8000
73 to, (PACK_TOKEN(T_TO )<<8) | 0x8000
74 type, (PACK_TOKEN(T_TYPE )<<8) | 0x8000
75 variable-length, (PACK_TOKEN(T_VLA )<<8) | 0x8000
77 unsigned cdecl__to_keyword(const char *s, int len, int english_mode)
79 const struct keyword *k;
81 if ((k = in_word_set(s, len))) {
82 uint_least16_t x = k->val;
84 if (english_mode || !(x & 0x8000)) {
89 return (PACK_TOKEN(T_IDENT)<<8);
92 static const char *wordlist_func(const struct keyword *k)
94 unsigned x = (k->val >> 8) & 0x7f;
98 return cdecl__token_name(UNPACK_TOKEN(x));