scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 79f87ebac2588c8a6cc9e4304f61b1259a7355eb
parent ccf4a8a144773066b8f63ddba1b92ff57d22ffa8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 15 Apr 2014 14:20:16 +0200

Remove stupid double check in unary()

This new double check is better than the previous double check

Diffstat:
expr.c | 102+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 50 insertions(+), 52 deletions(-)

diff --git a/expr.c b/expr.c @@ -388,63 +388,61 @@ unary(void) op = (yytoken == INC) ? OINC : ODEC; next(); return incdec(unary(), op); - case '!': op = OEXC; break; - case '&': op = OADDR; break; - case '*': op = OPTR; break; - case '+': op = OADD; break; - case '~': op = OCPL; break; - case '-': op = ONEG; break; - default: return postfix(); - } - - next(); - np = cast(); - tp = UNQUAL(np->type); - t = tp->op; - - switch (op) { - case OPTR: - switch (t) { - case ARY: case FTN: - np = addr2ptr(np); - case PTR: - tp = tp->type; + case '!': case '&': case '*': case '+': case '~': case '-': + op = yytoken; + next(); + np = cast(); + tp = UNQUAL(np->type); + t = tp->op; + switch (op) { + case '*': + op = OPTR; + switch (t) { + case ARY: case FTN: + np = addr2ptr(np); + case PTR: + tp = tp->type; + break; + default: + goto bad_operand; + } break; - default: - goto bad_operand; - } - break; - case OADDR: - if (!np->b.lvalue) - goto no_lvalue; - if (ISNODESYM(np) && np->u.sym->s.isregister) - goto reg_address; - tp = mktype(tp, PTR, NULL, 0); - break; - case OEXC: - switch (t) { - case FTN: case ARY: - np = addr2ptr(np); - case INT: case FLOAT: case PTR: - return eval(np, 1); + case '&': + op = OADDR; + if (!np->b.lvalue) + goto no_lvalue; + if (ISNODESYM(np) && np->u.sym->s.isregister) + goto reg_address; + tp = mktype(tp, PTR, NULL, 0); break; - default: - goto bad_operand; + case '!': + switch (t) { + case FTN: case ARY: + np = addr2ptr(np); + case INT: case FLOAT: case PTR: + return eval(np, 1); + break; + default: + goto bad_operand; + } + case '+': + if (t != INT) + goto bad_operand; + return np; + case '~': + op = OCPL; + if (t != INT) + goto bad_operand; + break; + case '-': + op = ONEG; + if (!isarith(t)) + goto bad_operand; } - case OADD: - if (t != INT) - goto bad_operand; - return np; - case OCPL: - if (t != INT) - goto bad_operand; - case ONEG: - if (!isarith(t)) - goto bad_operand; + return unarycode(op, tp, np); + default: return postfix(); } - return unarycode(op, tp, np); - no_lvalue: err = "lvalue required in unary expression"; goto error;