scc

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

commit 2fe852042893ad264f303ed805ae09be383f5dd7
parent e023b70a083338808f7e1e8e015df581c3a72823
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  7 Jan 2016 21:32:44 +0100

Convert compare() to use the new fileds in Type

Diffstat:
cc1/expr.c | 33+++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -357,31 +357,24 @@ pcompare(char op, Node *lp, Node *rp) static Node * compare(char op, Node *lp, Node *rp) { + Type *ltp, *rtp; + lp = decay(lp); rp = decay(rp); + ltp = lp->type; + rtp = rtp->type; - switch (BTYPE(lp)) { - case INT: - case FLOAT: - switch (BTYPE(rp)) { - case INT: - case FLOAT: - arithconv(&lp, &rp); - break; - case PTR: - return pcompare(op, rp, lp); - default: - goto nocompat; - } - break; - case PTR: - return pcompare(op, lp, rp); - default: - nocompat: + if (ltp->op == PTR || rtp->op == PTR) { + return pcompare(op, rp, lp); + } else if (ltp->arith && rtp->arith) { + arithconv(&lp, &rp); + return simplify(op, inttype, lp, rp); + } else { errorp("incompatibles type in comparision"); + freetree(lp); + freetree(rp); + return constnode(zero); } - - return simplify(op, inttype, lp, rp); } int