shithub: scc

Download patch

ref: 72c078099ff413a22007b90784238bb294dd7dbe
parent: 59bd5c1817e75e8f3c072c444958516691d75b6a
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Jun 18 05:27:35 EDT 2022

cc1: Simplify unary()

Some logic about how to deal with sizeof was in unary(), but there
is a function (sizeexp()) which does almost all the work about
sizeof, so it makes more sense to move all the logic to that function.

--- a/src/cmd/cc/cc1/expr.c
+++ b/src/cmd/cc/cc1/expr.c
@@ -764,7 +764,9 @@
 {
 	Type *tp;
 
-	expect('(');
+	if (!accept('('))
+		return typeof(cast());
+
 	switch (yytoken) {
 	case TYPE:
 	case TYPEIDEN:
@@ -775,6 +777,7 @@
 		break;
 	}
 	expect(')');
+
 	return tp;
 }
 
@@ -830,7 +833,7 @@
 	case '*': op = OPTR;  fun = content;      break;
 	case SIZEOF:
 		next();
-		tp = (yytoken == '(') ? sizeexp() : typeof(unary());
+		tp = sizeexp();
 		if (!(tp->prop & TDEFINED))
 			errorp("sizeof applied to an incomplete type");
 		return sizeofnode(tp);