commit 7cce9dc9462e67e8ebfd5a507b49707f3a1e1013
parent ebe3eda8ec61484d26bdbb754431a19ecdaa32b4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 12 Mar 2014 11:24:21 +0100
Move ctype from types to decl
Diffstat:
M | decl.c | | | 107 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | types.c | | | 105 | ------------------------------------------------------------------------------- |
2 files changed, 107 insertions(+), 105 deletions(-)
diff --git a/decl.c b/decl.c
@@ -72,6 +72,113 @@ expected:
error: error(err, yytext);
}
+struct ctype *
+ctype(struct ctype *tp, unsigned char tok)
+{
+ register unsigned char type;
+ static char *err;
+
+ type = tp->type;
+
+
+ switch (tok) {
+ case VOID: case BOOL: case STRUCT: case UNION: case ENUM: case BITFLD:
+ if (type)
+ goto two_or_more;;
+ type = tok;
+ if (tp->c_signed || tp->c_unsigned)
+ goto invalid_sign;
+ break;
+ case CHAR:
+ if (type)
+ goto two_or_more;
+ type = CHAR;
+ break;
+ case SHORT:
+ if (type && type != INT)
+ goto two_or_more;
+ type = SHORT;
+ break;
+ case INT:
+ switch (type) {
+ case 0: type = INT; break;
+ case SHORT: type = SHORT; break;
+ case LONG: type = LONG; break;
+ default: goto two_or_more;
+ }
+ break;
+ case LONG:
+ switch (type) {
+ case 0:
+ case INT: type = LONG; break;
+ case LONG: type = LLONG; break;
+ case DOUBLE: type = LDOUBLE; break;
+ case LLONG:
+ case LDOUBLE: error("too much long");
+ }
+ break;
+ case FLOAT:
+ if (type)
+ goto two_or_more;
+ type = FLOAT;
+ if (tp->c_signed || tp->c_unsigned)
+ goto invalid_sign;
+ break;
+ case DOUBLE:
+ if (type)
+ goto two_or_more;
+ if (!type)
+ type = DOUBLE;
+ else if (type == LONG)
+ type = LDOUBLE;
+ if (tp->c_signed || tp->c_unsigned)
+ goto invalid_sign;
+ break;
+ case UNSIGNED:
+ if (tp->c_unsigned)
+ goto duplicated;
+ if (tp->c_signed)
+ goto both_sign;
+ tp->c_unsigned = 1;
+ goto check_sign;
+ case SIGNED:
+ if (tp->c_signed)
+ goto duplicated;
+ if (tp->c_unsigned)
+ goto both_sign;
+ tp->c_signed = 1;
+
+check_sign: switch (type) {
+ case VOID: case BOOL: case FLOAT: case DOUBLE: case LDOUBLE:
+ goto invalid_sign;
+ }
+ break;
+ case TYPENAME:
+ assert(!type);
+ if (tp->c_signed || tp->c_unsigned)
+ goto invalid_sign;
+ type = TYPEDEF;
+ break;
+ default:
+ assert(0);
+ }
+ tp->type = type;
+ return tp;
+
+both_sign:
+ err = "both 'signed' and 'unsigned' in declaration specifiers";
+ goto error;
+duplicated:
+ err = "duplicated '%s'";
+ goto error;
+invalid_sign:
+ err = "invalid sign modifier";
+ goto error;
+two_or_more:
+ err = "two or more basic types";
+error: error(err, yytext);
+}
+
static void structdcl(register struct ctype *tp);
static void enumdcl(struct ctype *base);
diff --git a/types.c b/types.c
@@ -83,113 +83,8 @@ decl_type(struct ctype *tp)
return new;
}
-struct ctype *
-ctype(struct ctype *tp, unsigned char tok)
-{
- register unsigned char type;
- static char *err;
-
- type = tp->type;
- switch (tok) {
- case VOID: case BOOL: case STRUCT: case UNION: case ENUM: case BITFLD:
- if (type)
- goto two_or_more;;
- type = tok;
- if (tp->c_signed || tp->c_unsigned)
- goto invalid_sign;
- break;
- case CHAR:
- if (type)
- goto two_or_more;
- type = CHAR;
- break;
- case SHORT:
- if (type && type != INT)
- goto two_or_more;
- type = SHORT;
- break;
- case INT:
- switch (type) {
- case 0: type = INT; break;
- case SHORT: type = SHORT; break;
- case LONG: type = LONG; break;
- default: goto two_or_more;
- }
- break;
- case LONG:
- switch (type) {
- case 0:
- case INT: type = LONG; break;
- case LONG: type = LLONG; break;
- case DOUBLE: type = LDOUBLE; break;
- case LLONG:
- case LDOUBLE: error("too much long");
- }
- break;
- case FLOAT:
- if (type)
- goto two_or_more;
- type = FLOAT;
- if (tp->c_signed || tp->c_unsigned)
- goto invalid_sign;
- break;
- case DOUBLE:
- if (type)
- goto two_or_more;
- if (!type)
- type = DOUBLE;
- else if (type == LONG)
- type = LDOUBLE;
- if (tp->c_signed || tp->c_unsigned)
- goto invalid_sign;
- break;
- case UNSIGNED:
- if (tp->c_unsigned)
- goto duplicated;
- if (tp->c_signed)
- goto both_sign;
- tp->c_unsigned = 1;
- goto check_sign;
- case SIGNED:
- if (tp->c_signed)
- goto duplicated;
- if (tp->c_unsigned)
- goto both_sign;
- tp->c_signed = 1;
-
-check_sign: switch (type) {
- case VOID: case BOOL: case FLOAT: case DOUBLE: case LDOUBLE:
- goto invalid_sign;
- }
- break;
- case TYPENAME:
- assert(!type);
- if (tp->c_signed || tp->c_unsigned)
- goto invalid_sign;
- type = TYPEDEF;
- break;
- default:
- assert(0);
- }
- tp->type = type;
- return tp;
-
-both_sign:
- err = "both 'signed' and 'unsigned' in declaration specifiers";
- goto error;
-duplicated:
- err = "duplicated '%s'";
- goto error;
-invalid_sign:
- err = "invalid sign modifier";
- goto error;
-two_or_more:
- err = "two or more basic types";
-error: error(err, yytext);
-}
-
#ifndef NDEBUG
#include <stdio.h>