scc

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

commit befd4b3ef6de5f64ba923e2b0b86e46609e7e1fd
parent b88cbb14faba53251ef025e788c69400ab17faec
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 14 Aug 2015 16:48:21 +0200

simplify calls to decay()

It was common check the type of the node before calling
decay(), so it is a good idea put this test inside of
decay() itself. The call to decay() in negation()
was not needed anymore because exp2cond() calls to decay().

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

diff --git a/cc1/expr.c b/cc1/expr.c @@ -272,8 +272,14 @@ decay(Node *np) { Type *tp = np->type; - if (tp->op == ARY) + switch (tp->op) { + case ARY: tp = tp->type; + case FTN: + break; + default: + return np; + } return node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL); } @@ -286,11 +292,7 @@ eval(Node *np) if (!np) return NULL; - switch (BTYPE(np)) { - case ARY: - case FTN: - np = decay(np); - } + np = decay(np); if (!isnodecmp(np->op)) return np; p = node(OCOLON, inttype, constnode(one), constnode(zero)); @@ -562,11 +564,7 @@ negate(Node *np) static Node * exp2cond(Node *np, char neg) { - switch (BTYPE(np)) { - case ARY: - case FTN: - np = decay(np); - } + np = decay(np); if (isnodecmp(np->op)) return (neg) ? negate(np) : np; return compare(ONE ^ neg, np, constnode(zero)); @@ -695,7 +693,6 @@ negation(char op, Node *np) switch (BTYPE(np)) { case FTN: case ARY: - np = decay(np); case INT: case FLOAT: case PTR: