scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 29ceb0ed7c98fa120b8421aafe1babd0baa95c69
parent d56d3ae24cffaad777fcb4607e623e5bd5d34f8d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 10 Apr 2014 08:34:17 +0200

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.

Diffstat:
Mcode.c | 1+
Mexpr.c | 12+++++-------
2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/code.c b/code.c @@ -34,6 +34,7 @@ node(Inst code, Type *tp, union unode u, uint8_t nchilds) np->code = code; np->type = tp; np->u = u; + np->b.lvalue = 0; return np; } diff --git a/expr.c b/expr.c @@ -52,7 +52,7 @@ arithmetic(char op, Node *np1, Node *np2) 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 @@ pointer: np2 = bincode(OMUL, tp1, castcode(np2, tp1), sizeofcode(tp3)); - lvalue = 1; break; default: goto incorrect; @@ -126,9 +125,7 @@ pointer: 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 @@ array(Node *np1, Node *np2) 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 @@ incdec(Node *np, char op) goto nocomplete; case INT: case FLOAT: np = unarycode(op, np->type, np); - np->b.lvalue = 0; return np; default: goto bad_type;