shithub: scc

Download patch

ref: d571d1e0f46cacbc2867bd25779b745f0744fb2b
parent: 5ae4a720c0f1a1b07cbb3236903a08b71fe33e00
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Jul 5 04:36:09 EDT 2013

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.

--- a/decl.c
+++ b/decl.c
@@ -76,10 +76,10 @@
 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 @@
 				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 @@
 				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 != ',')  {