shithub: scc

Download patch

ref: 411c5618c377b28556835dcb7ad756b6072644e4
parent: 9c1de335c83c3160411fe897d9533f1629714577
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 14 10:44:25 EDT 2015

Reduce the number of decay() calls

Decay() is called from eval, so it is not needed anymore
all these calls to decay() around the code.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -267,10 +267,17 @@
 		error("invalid use of void expression");
 }
 
-/* TODO: put decay() call in a better place, because at this
-    moment we call dozens of calls in all the code */
-static Node *decay(Node *np);
+static Node *
+decay(Node *np)
+{
+	Type *tp = np->type;
 
+	if (tp->op == ARY)
+		tp = tp->type;
+
+	return node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL);
+}
+
 Node *
 eval(Node *np)
 {
@@ -326,17 +333,6 @@
 }
 
 static Node *
-decay(Node *np)
-{
-	Type *tp = np->type;
-
-	if (tp->op == ARY)
-		tp = tp->type;
-
-	return node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL);
-}
-
-static Node *
 constconv(Node *np, Type *newtp)
 {
 	Type *oldtp = np->type;
@@ -449,8 +445,6 @@
 
 	tp = lp->type;
 	size = sizeofnode(tp->type);
-	if (BTYPE(rp) == ARY)
-		rp = decay(rp);
 
 	if (op == OSUB && BTYPE(rp) == PTR) {
 		if (tp != rp->type)
@@ -481,8 +475,6 @@
 		case FLOAT:
 			typeconv(&lp, &rp);
 			break;
-		case ARY:
-			rp = decay(rp);
 		case PTR:
 			if (op == OADD || op == OSUB)
 				return parithmetic(op, rp, lp);
@@ -490,8 +482,6 @@
 			goto incorrect;
 		}
 		break;
-	case ARY:
-		lp = decay(lp);
 	case PTR:
 		return parithmetic(op, lp, rp);
 	default:
@@ -534,9 +524,6 @@
 		case FLOAT:
 			typeconv(&lp, &rp);
 			break;
-		case ARY:
-		case FTN:
-			rp = decay(rp);
 		case PTR:
 			return pcompare(op, rp, lp);
 		default:
@@ -543,9 +530,6 @@
 			goto nocompat;
 		}
 		break;
-	case ARY:
-	case FTN:
-		lp = decay(lp);
 	case PTR:
 		return pcompare(op, lp, rp);
 	default:
@@ -642,15 +626,12 @@
 static Node *
 assignop(char op, Node *lp, Node *rp)
 {
-	switch (BTYPE(rp)) {
-	case FTN:
-	case ARY:
-		rp = decay(rp);
-		/* PASSTHROUGH */
-	default:
-		if ((rp = convert(rp, lp->type, 0)) == NULL)
-			error("incompatible types when assigning");
-	}
+	lp = eval(lp);
+	rp = eval(rp);
+
+	if ((rp = convert(rp, lp->type, 0)) == NULL)
+		error("incompatible types when assigning");
+
 	return node(op, lp->type, lp, rp);
 }
 
@@ -692,7 +673,8 @@
 content(char op, Node *np)
 {
 	switch (BTYPE(np)) {
-	case ARY: case FTN:
+	case ARY:
+	case FTN:
 		np = decay(np);
 	case PTR:
 		np = node(op, np->type->type, np, NULL);
@@ -1133,7 +1115,7 @@
 		}
 		chklvalue(np, np->type);
 		next();
-		np = (fun)(op, np, eval(assign()));
+		np = (fun)(op, np, assign());
 	}
 }