scc

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

commit f93cb9bc73732b8af7db62172406de5a08be4b30
parent d5af55dc2fb5943cb062780a6612b0d0aa4253b7
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  4 Sep 2015 16:03:55 +0200

use content() in array()

Array() takes the content of some address, that is the same made by content(),
which has the optimization of *&, so the best way of handling it is calling
to content().

Diffstat:
Mcc1/expr.c | 51++++++++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -399,19 +399,40 @@ field(Node *np) } static Node * +content(char op, Node *np) +{ + switch (BTYPE(np)) { + case ARY: + case FTN: + case PTR: + if (np->op == OADDR) { + Node *new = np->left; + new->type = np->type->type; + free(np); + np = new; + } else { + np = node(op, np->type->type, np, NULL); + } + np->lvalue = 1; + return np; + default: + error("invalid argument of memory indirection"); + } +} + +static Node * array(Node *lp, Node *rp) { Type *tp; + Node *np; if (BTYPE(lp) != INT && BTYPE(rp) != INT) error("array subscript is not an integer"); - lp = arithmetic(OADD, lp, rp); - tp = lp->type; + np = arithmetic(OADD, lp, rp); + tp = np->type; if (tp->op != PTR) errorp("subscripted value is neither array nor pointer"); - lp = node(OPTR, tp->type, lp, NULL); - lp->lvalue = 1; - return lp; + return content(OPTR, np); } static Node * @@ -468,26 +489,6 @@ address(char op, Node *np) } static Node * -content(char op, Node *np) -{ - switch (BTYPE(np)) { - case ARY: - case FTN: - case PTR: - if (np->op == OADDR) { - Node *new = np->left; - free(np); - return new; - } - np = node(op, np->type->type, np, NULL); - np->lvalue = 1; - return np; - default: - error("invalid argument of unary '*'"); - } -} - -static Node * negation(char op, Node *np) { switch (BTYPE(np)) {