3 * Copyright © 2023-2024 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();
33 /* Note: the following options enable gperf-wordwrap.awk to do its thing */
34 %define word-array-name wordlist_wrapped
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)
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
78 unsigned cdecl__to_keyword(const char *s, int len, int english_mode)
80 const struct keyword *k;
82 if ((k = in_word_set(s, len))) {
83 uint_least16_t x = k->val;
85 if (english_mode || !(x & 0x8000)) {
90 return (PACK_TOKEN(T_IDENT)<<8);
93 static const char *wordlist_func(const struct keyword *k)
95 unsigned x = (k->val >> 8) & 0x7f;
99 return cdecl__token_name(UNPACK_TOKEN(x));