scc

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

commit 97f8f317d80776d196430997bea038e80709a206
parent 4e16556fa4948d8dd822f7ed31d4e367514f7182
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  7 Jan 2016 19:39:29 +0100

Convert arithmetic() to use new type fields

Diffstat:
Mcc1/expr.c | 28++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -320,28 +320,16 @@ incorrect: static Node * arithmetic(char op, Node *lp, Node *rp) { - switch (BTYPE(lp)) { - case INT: - case FLOAT: - switch (BTYPE(rp)) { - case INT: - case FLOAT: - arithconv(&lp, &rp); - break; - case PTR: - if (op == OADD || op == OSUB) - return parithmetic(op, rp, lp); - default: - goto incorrect; - } - break; - case PTR: - return parithmetic(op, lp, rp); - default: - incorrect: + Type *ltp = lp->type, *rtp = rp->type; + + if (ltp->arith && rtp->arith) { + arithconv(&lp, &rp); + } else if ((ltp->op == PTR || rtp->op == PTR) && + op == OADD || op == OSUB) { + return parithmetic(op, rp, lp); + } else { errorp("incorrect arithmetic operands"); } - return simplify(op, lp->type, lp, rp); }