Just do the check when building the map in the first place. This
enables more useful error messages, too: the case where there are no
type specifiers at all is certainly worth diagnosing separately from
other kinds of nonsense.
if (typemap == -1)
return -1;
- if (!cdecl__typemap_is_valid(typemap)) {
- fprintf(stderr, "conflicting type specifiers\n");
- return -1;
- }
-
for (struct cdecl_declspec *c = s; c; c = c->next) {
switch (cdecl_spec_kind(c)) {
case CDECL_SPEC_TYPE:
return map | (1ul<<s->type);
}
-bool cdecl__typemap_is_valid(unsigned long map)
-{
- switch (map) {
-# include "validtypes.h"
- return true;
- }
-
- return false;
-}
-
unsigned long cdecl__build_typemap(struct cdecl_declspec *s)
{
unsigned long map = 0;
map = add_typespec(map, c);
if (map == -1)
- break;
+ return -1;
}
- return map;
+ switch (map) {
+ case 0:
+ fprintf(stderr, "no type specifiers\n");
+ return -1;
+# include "validtypes.h"
+ return map;
+ default:
+ fprintf(stderr, "conflicting type specifiers\n");
+ return -1;
+ }
}
#ifndef CDECL_TYPEMAP_H_
#define CDECL_TYPEMAP_H_
-_Bool cdecl__typemap_is_valid(unsigned long map);
unsigned long cdecl__build_typemap(struct cdecl_declspec *s);
#endif