shithub: scc

Download patch

ref: a07bd3876a100283fe8cb101760ab6843b2869ae
parent: e33b5c0c4f3d7abd9ab3db4334ba8fa54addd8d1
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Oct 29 03:16:16 EDT 2013

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.

--- a/decl.c
+++ b/decl.c
@@ -192,15 +192,14 @@
 			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();
+				struct symbol *sym = lookup(yytext, NS_TYPEDEF);
 
-				sym = lookup(yytext, NS_TYPEDEF);
-				if (sym->ctype && tok != ';' && tok != ',') {
-					if (!tp)
-						tp = newctype();
-					tp->type = TYPEDEF;
+				if (sym->ctype) {
+					tp = ctype(tp, TYPEDEF);
 					tp->base = sym->ctype;
 					break;
 				}
@@ -207,6 +206,7 @@
 			}
 			/* it is not a type name */
 		default:
+		check_type:
 			if (!tp) {
 				if (curctx != CTX_OUTER || yytoken != IDEN)
 					return NULL;
--- a/types.c
+++ b/types.c
@@ -164,6 +164,12 @@
 			goto invalid_sign;
 		}
 		break;
+	case TYPEDEF:
+		assert(!type);
+		if (tp->c_signed || tp->c_unsigned)
+			goto invalid_sign;
+		type = TYPEDEF;
+		break;
 	default:
 		assert(0);
 	}