From: Nick Bowler Date: Thu, 23 Jun 2011 00:30:52 +0000 (-0400) Subject: Kill typemap_is_valid. X-Git-Tag: v1~171 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/90d2c82cd8b19562c71965d1bfa8e4b612ea4026 Kill typemap_is_valid. 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. --- diff --git a/src/parse-decl.c b/src/parse-decl.c index e9756e3..39a3e3c 100644 --- a/src/parse-decl.c +++ b/src/parse-decl.c @@ -15,11 +15,6 @@ static int verify_specs(struct cdecl_declspec *s) 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: diff --git a/src/typemap.c b/src/typemap.c index 0e5b41c..61456dd 100644 --- a/src/typemap.c +++ b/src/typemap.c @@ -36,16 +36,6 @@ static unsigned long add_typespec(unsigned long map, struct cdecl_declspec *s) return map | (1ul<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; @@ -56,8 +46,17 @@ unsigned long cdecl__build_typemap(struct cdecl_declspec *s) 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; + } } diff --git a/src/typemap.h b/src/typemap.h index 285ff29..f69eac4 100644 --- a/src/typemap.h +++ b/src/typemap.h @@ -1,7 +1,6 @@ #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