2 * Copyright © 2011, 2021, 2023 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/>.
25 # define CDECL__INLINE __inline
27 # define CDECL__INLINE inline
30 /* Compatibility typedefs */
32 typedef _Bool cdecl_bool;
34 typedef signed char cdecl_bool;
37 /* Declaration specifier kinds. */
39 CDECL_SPEC_TYPE = 256,
40 CDECL_SPEC_STOR = 512,
41 CDECL_SPEC_QUAL = 1024,
42 CDECL_SPEC_FUNC = 2048
46 CDECL_TYPE_VOID = CDECL_SPEC_TYPE,
62 CDECL_STOR_TYPEDEF = CDECL_SPEC_STOR,
67 CDECL_QUAL_RESTRICT = CDECL_SPEC_QUAL,
70 CDECL_FUNC_INLINE = CDECL_SPEC_FUNC
73 /* Declarator types. */
85 struct cdecl_declspec {
86 struct cdecl_declspec *next;
91 struct cdecl_declarator {
92 struct cdecl_declarator *child;
96 struct cdecl_pointer {
97 struct cdecl_declspec *qualifiers;
103 struct cdecl_function {
104 struct cdecl *parameters;
111 struct cdecl *cdecl_parse_decl(const char *declstr);
112 struct cdecl *cdecl_parse_english(const char *english);
113 void cdecl_free(struct cdecl *decl);
115 size_t cdecl_explain(char *buf, size_t n, struct cdecl *decl);
116 size_t cdecl_declare(char *buf, size_t n, struct cdecl *decl);
118 static CDECL__INLINE int cdecl_spec_kind(const struct cdecl_declspec *spec)
120 return spec->type & ~(CDECL_SPEC_TYPE-1u);
123 static CDECL__INLINE int cdecl_is_abstract(const struct cdecl_declarator *d)
128 return d->type != CDECL_DECL_IDENT;
131 /* Error handling. */
136 /* Obsolete error codes (no longer returned by the library) */
154 const struct cdecl_error *cdecl_get_error(void);