scc

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

commit 6624f3b6cd575a670cf4f424e4e93ae8df8a43df
parent c9a7bedda831d58121897c43f3e92badb6852f3a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 18 Apr 2014 10:06:08 +0200

Add function iszero()

This check is going to be done in a lot of different places, so
it is a good idea to have this function.

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

diff --git a/expr.c b/expr.c @@ -286,13 +286,18 @@ error: } static Node * -eval(Node *np) +iszero(Node *np) { - Node *ifyes, *ifno; + if (ISNODELOG(np)) + return np; + return compare(ONE, np, constcode(zero)); +} +static Node * +eval(Node *np) +{ if (!ISNODELOG(np)) return np; - return ternarycode(np, constcode(one), constcode(zero)); } @@ -691,10 +696,10 @@ or(void) static Node * ternary(void) { - Node *cond, *ifyes, *ifno; + Node *np, *ifyes, *ifno; Type *tp1, *tp2; - cond = or(); + np = or(); while (accept('?')) { ifyes = promote(expr()); expect(':'); @@ -703,10 +708,9 @@ ternary(void) tp2 = UNQUAL(ifno->type); if (tp1 != tp2) typeconv(&ifyes, &ifno); - cond = ternarycode(compare(ONE, cond, constcode(zero)), - ifyes, ifno); + np = ternarycode(iszero(np), ifyes, ifno); } - return cond; + return np; } static Node *