2 * Parse and validate C declarations.
3 * Copyright © 2011 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 <http://www.gnu.org/licenses/>.
26 static int verify_declspecs(struct cdecl_declspec *s)
28 unsigned num_storage = 0;
29 unsigned long typemap;
31 typemap = cdecl__build_typemap(s);
35 for (struct cdecl_declspec *c = s; c; c = c->next) {
36 switch (cdecl_spec_kind(c)) {
40 if (++num_storage > 1) {
41 fprintf(stderr, "too many storage-class specifiers\n");
47 * Restrict qualifiers are only valid in the
48 * pointer qualifier list, which isn't checked here.
50 if (c->type == CDECL_QUAL_RESTRICT) {
51 fprintf(stderr, "only pointer types can be restrict-qualified.\n");
57 * We don't support functions yet.
59 fprintf(stderr, "only function declarations may have function specifiers.\n");
69 static int verify_decl(struct cdecl *decl)
71 return verify_declspecs(decl->specifiers);
74 struct cdecl *cdecl_parse_decl(const char *declstr)
76 YY_BUFFER_STATE state;
80 state = yy_scan_string(declstr);
82 yy_delete_buffer(state);
87 rc = verify_decl(decl);