2 * Copyright © 2011, 2021, 2023-2024 Nick Bowler
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <stddef.h> /* for size_t */
24 # define CDECL__INLINE __inline
26 # define CDECL__INLINE inline
29 /* Compatibility typedefs */
31 typedef _Bool cdecl_bool;
33 typedef signed char cdecl_bool;
36 #if HAVE_UNSIGNED_LONG_LONG_INT
37 typedef unsigned long long cdecl_uintmax;
38 #elif HAVE_UNSIGNED___INT64
39 typedef unsigned __int64 cdecl_uintmax;
41 typedef unsigned long cdecl_uintmax;
44 /* Declaration specifier kinds. */
46 CDECL_SPEC_TYPE = 256,
47 CDECL_SPEC_STOR = 512,
48 CDECL_SPEC_QUAL = 1024,
49 CDECL_SPEC_FUNC = 2048
53 CDECL_TYPE_VOID = CDECL_SPEC_TYPE,
69 CDECL_STOR_TYPEDEF = CDECL_SPEC_STOR,
74 CDECL_QUAL_RESTRICT = CDECL_SPEC_QUAL,
77 CDECL_FUNC_INLINE = CDECL_SPEC_FUNC
80 /* Declarator types. */
92 struct cdecl_declspec {
93 struct cdecl_declspec *next;
98 struct cdecl_declarator {
99 struct cdecl_declarator *child;
103 struct cdecl_pointer {
104 struct cdecl_declspec *qualifiers;
108 cdecl_uintmax length;
110 struct cdecl_function {
111 struct cdecl *parameters;
118 struct cdecl *cdecl_parse_decl(const char *declstr);
119 struct cdecl *cdecl_parse_english(const char *english);
120 void cdecl_free(struct cdecl *decl);
122 size_t cdecl_explain(char *buf, size_t n, struct cdecl *decl);
123 size_t cdecl_declare(char *buf, size_t n, struct cdecl *decl);
125 static CDECL__INLINE int cdecl_spec_kind(const struct cdecl_declspec *spec)
127 return spec->type & ~(CDECL_SPEC_TYPE-1u);
130 static CDECL__INLINE int cdecl_is_abstract(const struct cdecl_declarator *d)
135 return d->type != CDECL_DECL_IDENT;
138 /* Error handling. */
143 /* Obsolete error codes (no longer returned by the library) */
161 const struct cdecl_error *cdecl_get_error(void);