shithub: scc

Download patch

ref: 29ceb0ed7c98fa120b8421aafe1babd0baa95c69
parent: d56d3ae24cffaad777fcb4607e623e5bd5d34f8d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Apr 10 04:34:17 EDT 2014

Be no l-value by default

There is only a few operators that generate l-values, so it if better
think that all the nodes always are generated non l-values and
modify only the special cases.

--- a/code.c
+++ b/code.c
@@ -34,6 +34,7 @@
 	np->code = code;
 	np->type = tp;
 	np->u = u;
+	np->b.lvalue = 0;
 
 	return np;
 }
--- a/expr.c
+++ b/expr.c
@@ -52,7 +52,7 @@
 	char *err;
 	Node *naux;
 	Type *tp1, *tp2, *tp3;
-	uint8_t t1, t2, taux, lvalue = 0;
+	uint8_t t1, t2, taux;
 
 	tp1 = UNQUAL(np1->type), tp2 = UNQUAL(np2->type);
 	t1 = tp1->op, t2 = tp2->op;
@@ -116,7 +116,6 @@
 			np2 = bincode(OMUL, tp1,
 			              castcode(np2, tp1),
 			              sizeofcode(tp3));
-			lvalue = 1;
 			break;
 		default:
 			goto incorrect;
@@ -126,9 +125,7 @@
 		goto incorrect;
 	}
 
-	np1 = bincode(op, tp1, np1, np2);
-	np1->b.lvalue = lvalue;
-	return np1;
+	return bincode(op, tp1, np1, np2);
 
 bad_shift:
 	err = "invalid operands to shift operator";
@@ -156,7 +153,9 @@
 	if (t1 != INT && t2 != INT)
 		goto bad_subs;
 	np1 = arithmetic(OADD, np1, np2);
-	return unarycode(OARY, np1->type->type , np1);
+	np1 =  unarycode(OARY, np1->type->type , np1);
+	np1->b.lvalue = 1;
+	return np1;
 
 bad_vector:
 	err = "subscripted value is neither array nor pointer nor vector";
@@ -185,7 +184,6 @@
 			goto nocomplete;
 	case INT: case FLOAT:
 		np = unarycode(op, np->type, np);
-		np->b.lvalue = 0;
 		return np;
 	default:
 		goto bad_type;
--