scc

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

commit c19b3bf153c5a741945e1ed2681f2279dd0c7a28
parent f9b1884ede4720f0d2e929784a0a4a37de05709e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  1 Sep 2015 18:38:21 +0200

Simplify all the constanst casts

Diffstat:
cc1/expr.c | 13++++++-------
cc1/tests/test016.c | 6+++---
2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -40,7 +40,7 @@ promote(Node *np) if (r > RANK_UINT || tp == inttype || tp == uinttype) return np; tp = (r == RANK_UINT) ? uinttype : inttype; - return node(OCAST, tp, np, NULL); + return convert(np, tp, 1); } static void @@ -57,9 +57,9 @@ typeconv(Node **p1, Node **p2) tp2 = np2->type; if (tp1 != tp2) { if ((n = tp1->n.rank - tp2->n.rank) > 0) - np2 = node(OCAST, tp1, np2, NULL); + np2 = convert(np2, tp1, 1); else if (n < 0) - np1 = node(OCAST, tp2, np1, NULL); + np1 = convert(np1, tp2, 1); } *p1 = np1; *p2 = np2; @@ -270,7 +270,7 @@ pcompare(char op, Node *lp, Node *rp) switch (BTYPE(rp)) { case INT: if (rp->constant && SYMICMP(rp->sym, 0)) - rp = node(OCAST, pvoidtype, rp, NULL); + rp = convert(rp, pvoidtype, 1); break; case PTR: if (lp->type != rp->type) @@ -279,8 +279,7 @@ pcompare(char op, Node *lp, Node *rp) default: errorp("incompatibles type in comparision"); } - - return node(op, inttype, lp, rp); + return simplify(op, inttype, lp, rp); } static Node * @@ -404,7 +403,7 @@ assignop(char op, Node *lp, Node *rp) if (BTYPE(rp) == INT && BTYPE(lp) == PTR && rp->constant && SYMICMP(rp->sym, 0)) { - rp = node(OCAST, pvoidtype, rp, NULL); + rp = convert(rp, pvoidtype, 1); } else if ((rp = convert(rp, lp->type, 0)) == NULL) { errorp("incompatible types when assigning"); } diff --git a/cc1/tests/test016.c b/cc1/tests/test016.c @@ -20,7 +20,7 @@ A4 P p L5 A4 G1 'P :P A4 @I #I0 :I - j L6 A4 #I0 IP !I + j L6 A4 #P0 !I y #I1 L6 y #I0 @@ -34,10 +34,10 @@ A4 P pp A1 #I1 :I A2 A1 'P :P A4 A2 'P :P - j L5 A2 #I0 IP =I + j L5 A2 #P0 =I A4 @P @I #I0 :I L5 - A2 #I0 IP :P + A2 #P0 :P y A1 } ????