[hackers] [scc] Simplify Switch() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 4 Sep 2015 20:22:39 +0200 (CEST)

commit 7d47a7ba40f28736fffc6dde3bd07a4258373cc8
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Sep 4 18:38:37 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Sep 4 18:38:37 2015 +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.

diff --git a/cc1/stmt.c b/cc1/stmt.c
index 738329a..617e68b 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -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 (')');
 
Received on Fri Sep 04 2015 - 20:22:39 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 04 2015 - 20:24:17 CEST