scc

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

commit dd90c975dcfd14bc186b498f92c69df2b7b04121
parent 6590f76d9831666123aa9aa0de715f0b56b69126
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  4 Feb 2017 22:40:04 +0100

[cc1] Fix compilation after 7c9e9d84

Negate() was used in stmt.c, but a better solution was to pass
a parameter to condexpr() instead of having negate().

Diffstat:
Mcc1/cc1.h | 2+-
Mcc1/expr.c | 6+++---
Mcc1/stmt.c | 17++++++++++-------
3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -426,7 +426,7 @@ extern TUINT ones(int nbytes); /* expr.c */ extern Node *decay(Node *), *negate(Node *np), *assign(void); extern Node *convert(Node *np, Type *tp1, char iscast); -extern Node *constexpr(void), *condexpr(void), *expr(void); +extern Node *constexpr(void), *condexpr(int neg), *expr(void); extern int isnodecmp(int op); extern int negop(int op); extern int cmpnode(Node *np, TUINT val); diff --git a/cc1/expr.c b/cc1/expr.c @@ -419,7 +419,7 @@ exp2cond(Node *np, int neg) case ONEG: case OOR: case OAND: - return node(ONEG, inttype, np, NULL); + return (neg) ? node(ONEG, inttype, np, NULL) : np; case OEQ: case ONE: case OLT: @@ -1128,11 +1128,11 @@ expr(void) } Node * -condexpr(void) +condexpr(int neg) { Node *np; - np = exp2cond(xexpr(), 0); + np = exp2cond(xexpr(), neg); if (np->flags & NCONST) warn("conditional expression is constant"); return simplify(np); diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -8,6 +8,9 @@ static char sccsid[] = "@(#) ./cc1/stmt.c"; #include "../inc/cc.h" #include "cc1.h" +#define NEGATE 1 +#define NONEGATE 0 + Symbol *curfun; static void stmt(Symbol *lbreak, Symbol *lcont, Switch *lswitch); @@ -55,12 +58,12 @@ stmtexp(Symbol *lbreak, Symbol *lcont, Switch *lswitch) } static Node * -condition(void) +condition(int neg) { Node *np; expect('('); - np = condexpr(); + np = condexpr(neg); expect(')'); return np; @@ -77,7 +80,7 @@ While(Symbol *lbreak, Symbol *lcont, Switch *lswitch) lbreak = newlabel(); expect(WHILE); - np = condition(); + np = condition(NONEGATE); emit(OJUMP, lcont); @@ -120,7 +123,7 @@ For(Symbol *lbreak, Symbol *lcont, Switch *lswitch) expect(';'); break; } - econd = (yytoken != ';') ? condexpr() : NULL; + econd = (yytoken != ';') ? condexpr(NONEGATE) : NULL; expect(';'); einc = (yytoken != ')') ? expr() : NULL; expect(')'); @@ -158,7 +161,7 @@ Dowhile(Symbol *lbreak, Symbol *lcont, Switch *lswitch) emit(OLABEL, begin); stmt(lbreak, lcont, lswitch); expect(WHILE); - np = condition(); + np = condition(NONEGATE); emit(OLABEL, lcont); emit(OBRANCH, begin); emit(OEXPR, np); @@ -305,9 +308,9 @@ If(Symbol *lbreak, Symbol *lcont, Switch *lswitch) lelse = newlabel(); expect(IF); - np = condition(); + np = condition(NEGATE); emit(OBRANCH, lelse); - emit(OEXPR, negate(np)); + emit(OEXPR, np); stmt(lbreak, lcont, lswitch); if (accept(ELSE)) { end = newlabel();