2 * Internal declarations for libcdecl.
3 * Copyright © 2021, 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/>.
18 #ifndef CDECL_INTERNAL_H_
19 #define CDECL_INTERNAL_H_
24 #define _(s) dgettext(PACKAGE, s)
27 /* Pack the 4 "kind" bits of a valid cdecl specifier value into two bits. */
28 #define PACK_KIND(x) ((( ((x>>8) - ((x)>>11)) ) >> 1) & 3)
30 /* Expand a packed "kind" to its original value. */
31 #define UNPACK_KIND(x) (0x100 << (x))
34 * Pack a valid cdecl specifier value (CDECL_TYPE_xxx, CDECL_STOR_xxx, etc.)
35 * into 8 bits. We do this by encoding the specifier kind in the upper two
36 * bits, and the enumerated sequence in the lower 6 bits. */
37 #define PACK_SPEC(x) (((x) & 0x3f) | (PACK_KIND(x) << 6))
40 * Expand a packed specifier to its original value.
42 #define UNPACK_SPEC(x) (UNPACK_KIND((x) >> 6) | ((x) & 0x3f))
45 * Pack a parser token into 7 bits.
47 * Bison normally numbers user-defined tokens sequentially starting from 258.
48 * If api.token,raw is used, then the numbering starts from 3. As we have
49 * about 50 tokens, the latter case will fit in 7 bits easily; in the former
50 * case the upper bits are constant so we don't need to store them.
52 #define PACK_TOKEN(x) ((x) & 0x7f)
55 * Expand a packed token to its original value.
57 #define UNPACK_TOKEN(x) ((x) | ((T_IDENT > 256) << 8))
60 struct cdecl_declspec;
63 void cdecl__init_i18n(void);
65 static inline void cdecl__init_i18n(void)
70 void cdecl__err(unsigned code, const char *fmt, const char *arg);
71 void cdecl__errmsg(unsigned msg);
73 struct cdecl_declspec *cdecl__normalize_specs(struct cdecl_declspec *specs);
81 size_t cdecl__advance(struct output_state *dst, size_t amount);
82 size_t cdecl__emit(struct output_state *dst, const char *src);
84 const char *cdecl__emit_specs(struct output_state *dst,
85 struct cdecl_declspec *s,
89 * If s is a (len bytes long) string corresponding to a declaration
92 * - bits 7:0 (LSB) of the return value is the packed specifier type, and
93 * - bits 15:8 of the return value is the packed parser token.
95 * Otherwise, if english_mode is nonzero and s is an "english keyword",
96 * returns the appropriate packed parser token in bits 15:8.
98 * Otherwise, PACK_TOKEN(T_IDENT) is returned in bits 15:8.
100 unsigned cdecl__to_keyword(const char *s, int len, int english_mode);