shithub: scc

Download patch

ref: e0614afe4458a7fdabc4da686bae925552e4be3e
parent: 7810da634afacef19f9e265883de786bf1fcb322
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 22 04:01:23 EDT 2014

Fix increment()

Increment was returning a unary operator, but it was returning
the same operator than exp += exp, so the backend could not
difference between them. This patch adds a second node
with the value of 1.

--- a/cc1.h
+++ b/cc1.h
@@ -209,7 +209,7 @@
 
 enum {
 	OCAST = 1, OPTR, OADD, OARY, OSIZE, OMUL, OSUB,
-	OINC, ODEC, OPINC, OPDEC, ODIV, OMOD, OSHL, OSHR,
+	OINC, ODEC, ODIV, OMOD, OSHL, OSHR,
 	OBAND, OBXOR, OBOR, OASSIGN, OA_MUL, OA_DIV,
 	OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR,
 	OA_AND, OA_XOR, OA_OR, OADDR,ONEG, OCPL, OEXC,
--- a/code.c
+++ b/code.c
@@ -9,10 +9,8 @@
 	[OSUB] = "-",
 	[OMUL] = "*",
 	[OARY] = "'",
-	[OINC] = ":+",
-	[ODEC] = ":-",
-	[OPINC] = ";+",
-	[OPDEC] =  ";=",
+	[OINC] = ";+",
+	[ODEC] =  ";=",
 	[OSIZE] = "#",
 	[OPTR] = "@",
 	[OMOD] = "*",
--- a/expr.c
+++ b/expr.c
@@ -314,23 +314,20 @@
 static Node *
 incdec(Node *np, char op)
 {
-	Type *tp;
-	uint8_t t;
 	char *err;
+	Type *tp = np->utype;
 
-	GETBTYPE(np, tp, t);
 	if (!np->b.lvalue)
 		goto nolvalue;
-	if (isconst(np->type->op))
+	if (isconst(tp->op))
 		goto const_mod;
 
-	switch (t) {
+	switch (np->typeop) {
 	case PTR:
-		if (!tp->type->defined)
+		if (!tp->defined)
 			goto nocomplete;
 	case INT: case FLOAT:
-		np = unarycode(op, np->type, np);
-		return np;
+		return arithmetic(op, np, symcode(one));
 	default:
 		goto bad_type;
 	}
@@ -444,7 +441,7 @@
 			expect(']');
 			break;
 		case DEC: case INC:
-			np1 = incdec(np1,  (yytoken == INC) ? OPINC : OPDEC);
+			np1 = incdec(np1,  (yytoken == INC) ? OINC : ODEC);
 			next();
 			break;
 		/* TODO: case '.': */
@@ -479,7 +476,7 @@
 		}
 		return sizeofcode(tp);
 	case INC: case DEC:
-		op = (yytoken == INC) ? OINC : ODEC;
+		op = (yytoken == INC) ? OA_ADD : OA_SUB;
 		next();
 		return incdec(unary(), op);
 	case '!': op = 0; fun = negation; break;