scc

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

commit 25b248b2ec25cb328aea47c140ca83f00ce2d37f
parent ec647d24eb10e22e3f54acc0e22c9a9b91a2b6f7
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 15 Aug 2015 20:37:28 +0200

Fix for condition

Condition() expects '(' before and ')' after, so it
was not a good idea call it in for. Exp2cond() does
the job.

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

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -347,6 +347,7 @@ extern void freetree(Node *np); extern Node *expr(void), *negate(Node *np), *constexpr(void); extern Node *convert(Node *np, Type *tp1, char iscast); extern Node *eval(Node *np), *iconstexpr(void), *condition(void); +extern Node *exp2cond(Node *np, char neg); /* cpp.c */ extern void icpp(void); diff --git a/cc1/expr.c b/cc1/expr.c @@ -562,7 +562,7 @@ negate(Node *np) return np; } -static Node * +Node * exp2cond(Node *np, char neg) { np = decay(np); diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -91,7 +91,7 @@ For(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) expect('('); einit = (yytoken != ';') ? expr() : NULL; expect(';'); - econd = (yytoken != ';') ? condition() : NULL; + econd = (yytoken != ';') ? exp2cond(expr(), 0) : NULL; expect(';'); einc = (yytoken != ')') ? expr() : NULL; expect(')');