commit a07bd3876a100283fe8cb101760ab6843b2869ae
parent e33b5c0c4f3d7abd9ab3db4334ba8fa54addd8d1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 29 Oct 2013 07:16:16 +0100
Fix typedef behaviour
After using a typedef we have inserted a new keyword in our
vocabulary, so we don't have to look for the next character in
the input, because it is tedious and ugly.
Diffstat:
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/decl.c b/decl.c
@@ -192,21 +192,21 @@ specifier(void)
next();
return structdcl(tp);
case IDEN:
+ /* TODO: remove NS_TYPEDEF */
+ if (tp && tp->c_typedef && !tp->type)
+ goto check_type;
if (!tp || !tp->type) {
- struct symbol *sym;
- unsigned char tok = ahead();
-
- sym = lookup(yytext, NS_TYPEDEF);
- if (sym->ctype && tok != ';' && tok != ',') {
- if (!tp)
- tp = newctype();
- tp->type = TYPEDEF;
+ struct symbol *sym = lookup(yytext, NS_TYPEDEF);
+
+ if (sym->ctype) {
+ tp = ctype(tp, TYPEDEF);
tp->base = sym->ctype;
break;
}
}
/* it is not a type name */
default:
+ check_type:
if (!tp) {
if (curctx != CTX_OUTER || yytoken != IDEN)
return NULL;
diff --git a/types.c b/types.c
@@ -164,6 +164,12 @@ check_sign: switch (type) {
goto invalid_sign;
}
break;
+ case TYPEDEF:
+ assert(!type);
+ if (tp->c_signed || tp->c_unsigned)
+ goto invalid_sign;
+ type = TYPEDEF;
+ break;
default:
assert(0);
}