]> git.draconx.ca Git - cdecl99.git/commitdiff
Kill typemap_is_valid.
authorNick Bowler <nbowler@draconx.ca>
Thu, 23 Jun 2011 00:30:52 +0000 (20:30 -0400)
committerNick Bowler <nbowler@draconx.ca>
Thu, 23 Jun 2011 00:30:52 +0000 (20:30 -0400)
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.

src/parse-decl.c
src/typemap.c
src/typemap.h

index e9756e390e4df54e485ff7a81a5aeea0fc8968f5..39a3e3cd0161aecc15e8dcdb81d2cf699d7c51f8 100644 (file)
@@ -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:
index 0e5b41c49b73ee95cba18bf770e59a5345fc7c36..61456dd4a31a644393731af2afa3aed9273926bd 100644 (file)
@@ -36,16 +36,6 @@ static unsigned long add_typespec(unsigned long map, struct cdecl_declspec *s)
        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;
@@ -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;
+       }
 }
index 285ff2913f808f737c182809d9bffe80a7a01c62..f69eac496243b059d27b8e78fe7dc2f023aa18b2 100644 (file)
@@ -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