scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit e0614afe4458a7fdabc4da686bae925552e4be3e
parent 7810da634afacef19f9e265883de786bf1fcb322
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 22 Apr 2014 08:01:23 +0200

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.

Diffstat:
cc1.h | 2+-
code.c | 6++----
expr.c | 17+++++++----------
3 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/cc1.h b/cc1.h @@ -209,7 +209,7 @@ typedef void (*Inst)(Node *); /* TODO: remove this typedef */ 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, diff --git a/code.c b/code.c @@ -9,10 +9,8 @@ char *opcodes[] = { [OSUB] = "-", [OMUL] = "*", [OARY] = "'", - [OINC] = ":+", - [ODEC] = ":-", - [OPINC] = ";+", - [OPDEC] = ";=", + [OINC] = ";+", + [ODEC] = ";=", [OSIZE] = "#", [OPTR] = "@", [OMOD] = "*", diff --git a/expr.c b/expr.c @@ -314,23 +314,20 @@ assignop(char op, Node *np1, Node *np2) 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 @@ postfix(void) 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 @@ unary(void) } 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;