scc

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

commit 7d47a7ba40f28736fffc6dde3bd07a4258373cc8
parent 65279cc59e7e5ee4c64be38923608cc552ec74d6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  4 Sep 2015 18:38:37 +0200

Simplify Switch()

It is better call directly to convert() instead of check the type
in Switch(). This patch also adds code to recover the error in
case of non integer expression.

Diffstat:
Mcc1/stmt.c | 12+++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -195,16 +195,10 @@ Switch(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) expect(SWITCH); expect ('('); - cond = eval(expr()); - /* TODO: why can I not call directly to convert here? */ - switch (BTYPE(cond)) { - case INT: - case ENUM: - cond = convert(cond, inttype, 0); - break; - default: - error("incorrect type in switch statement"); + if ((cond = convert(expr(), inttype, 0)) == NULL) { + errorp("incorrect type in switch statement"); + cond = constnode(zero); } expect (')');