scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 72c078099ff413a22007b90784238bb294dd7dbe
parent 59bd5c1817e75e8f3c072c444958516691d75b6a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 18 Jun 2022 09:27:35 +0200

cc1: Simplify unary()

Some logic about how to deal with sizeof was in unary(), but there
is a function (sizeexp()) which does almost all the work about
sizeof, so it makes more sense to move all the logic to that function.

Diffstat:
Msrc/cmd/cc/cc1/expr.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/cmd/cc/cc1/expr.c b/src/cmd/cc/cc1/expr.c @@ -764,7 +764,9 @@ sizeexp(void) { Type *tp; - expect('('); + if (!accept('(')) + return typeof(cast()); + switch (yytoken) { case TYPE: case TYPEIDEN: @@ -775,6 +777,7 @@ sizeexp(void) break; } expect(')'); + return tp; } @@ -830,7 +833,7 @@ unary(void) case '*': op = OPTR; fun = content; break; case SIZEOF: next(); - tp = (yytoken == '(') ? sizeexp() : typeof(unary()); + tp = sizeexp(); if (!(tp->prop & TDEFINED)) errorp("sizeof applied to an incomplete type"); return sizeofnode(tp);