scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit d571d1e0f46cacbc2867bd25779b745f0744fb2b
parent 5ae4a720c0f1a1b07cbb3236903a08b71fe33e00
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  5 Jul 2013 08:36:09 +0200

Remove type variable in spec

This variable is only a copy of the type field of ctype struct, so
it can be replaced by it.

Diffstat:
decl.c | 17++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/decl.c b/decl.c @@ -76,10 +76,10 @@ dirdcl(register struct ctype *tp) struct ctype * spec(void) { - unsigned char sign, type; + unsigned char sign; register struct ctype *tp = NULL; - for (type = sign = 0; ; next()) { + for (sign = 0; ; next()) { switch (yytoken) { case TYPEDEF: case EXTERN: case STATIC: case AUTO: case REGISTER: case CONST: case VOLATILE: @@ -90,13 +90,13 @@ spec(void) error("duplicated '%s'", yytext); if (sign) error("both 'signed' and 'unsigned' in declaration specifiers"); - switch (type) { + if (!tp) + tp = newctype(); + switch (tp->type) { case FLOAT: case DOUBLE: case LDOUBLE: case BOOL: goto invalid_sign; } - if (!tp) - tp = newctype(); - if ((type = sign = yytoken) == UNSIGNED) + if ((sign = yytoken) == UNSIGNED) tp->c_unsigned = 1; break; case FLOAT: case DOUBLE: case BOOL: @@ -104,15 +104,14 @@ spec(void) goto invalid_sign; case VOID: case CHAR: case SHORT: case INT: case LONG: tp = btype(tp, yytoken); - type = tp->type; break; case STRUCT: /* TODO */ case UNION: /* TODO */ case ENUM: /* TODO */ case IDEN: { - struct symbol *sym; + struct symbol *sym = find(yytext, NS_TYPEDEF); - if ((sym = find(yytext, NS_TYPEDEF)) && !type) { + if (sym && (!tp || !tp->type)) { register unsigned char tok = ahead(); if (tok != ';' && tok != ',') {