shithub: scc

Download patch

ref: dd9d39f1f5a09924ab111b97e64d144075d898cd
parent: aabab2cdfb2cd0dc24ad55e4fff5d7f7ccd0de03
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Mar 9 12:51:42 EDT 2014

Use TYPE for struct, enum and unions

--- a/decl.c
+++ b/decl.c
@@ -176,6 +176,8 @@
 specifier(register struct ctype *tp,
           struct storage *store, struct qualifier *qlf)
 {
+	unsigned char tok;
+
 	for (;; next()) {
 		switch (yytoken) {
 		case TQUALIFIER:
@@ -185,18 +187,14 @@
 			store = storage(store, yyval->c);
 			break;
 		case TYPE:
-			tp = ctype(tp, yyval->c);
+			tp = ctype(tp, tok = yyval->c);
+			switch (tok) {
+			case ENUM: case STRUCT: case UNION:
+				next();
+				(tok == ENUM) ? enumdcl(tp) : structdcl(tp);
+				return true;
+			}
 			break;
-		case ENUM:
-			tp = ctype(tp, ENUM);
-			next();
-			enumdcl(tp);
-			return true;
-		case STRUCT:   case UNION:
-			tp = ctype(tp, yytoken);
-			next();
-			structdcl(tp);
-			return true;
 		case IDEN:
 			if (!tp->defined) {
 				register struct symbol *sym;
--- a/lex.c
+++ b/lex.c
@@ -135,7 +135,7 @@
 		{"do", DO, DO},
 		{"double", TYPE, DOUBLE},
 		{"else", ELSE, ELSE},
-		{"enum", ENUM, ENUM},
+		{"enum", TYPE, ENUM},
 		{"extern", STORAGE, EXTERN},
 		{"float", TYPE, FLOAT},
 		{"for", FOR, FOR},
@@ -151,10 +151,10 @@
 		{"signed", TYPE, SIGNED},
 		{"sizeof", SIZEOF, SIZEOF},
 		{"static", STORAGE, STATIC},
-		{"struct", STRUCT, STRUCT},
+		{"struct", TYPE, STRUCT},
 		{"switch", SWITCH, SWITCH},
 		{"typedef", STORAGE, TYPEDEF},
-		{"union", UNION, UNION},
+		{"union", TYPE, UNION},
 		{"unsigned", TYPE, UNSIGNED},
 		{"void", TYPE, VOID},
 		{"volatile", TQUALIFIER, VOLATILE},