scc

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

commit a73e3bf10ef72545a4a4c0e2c541d740cf9e4e1a
parent 2fdc51bcc25975c04b6f40f51f87712e5a1a60d8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  1 Jul 2017 18:27:31 +0200

[cc1] Move defined() logic to a function

The code of defined was a bit confusing while it was in unary(),
but this new separation helps to have better separation of
responsabilities.

Diffstat:
cc1/expr.c | 43++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -827,16 +827,36 @@ postfix(Node *lp) } } +static Node * +defined(void) +{ + Symbol *sym; + int paren; + + disexpand = 1; + next(); + paren = accept('('); + if (yytoken != IDEN && yytoken != TYPEIDEN) + cpperror("operator 'defined' requires an identifier"); + if (yytoken == TYPEIDEN || !(yylval.sym->flags & SDECLARED)) + sym = zero; + else + sym = one; + disexpand = 0; + next(); + if (paren) + expect(')'); + return constnode(sym); +} + static Node *cast(int); static Node * unary(int needdecay) { Node *(*fun)(int, Node *), *np; - Symbol *sym; int op; Type *tp; - int paren; switch (yytoken) { case '!': op = 0; fun = negation; break; @@ -859,24 +879,9 @@ unary(int needdecay) goto chk_decay; case IDEN: case TYPEIDEN: - if (lexmode != CPPMODE || strcmp(yylval.sym->name, "defined")) - goto call_postfix; - disexpand = 1; - next(); - paren = accept('('); - if (yytoken != IDEN && yytoken != TYPEIDEN) - cpperror("operator 'defined' requires an identifier"); - if (yytoken == TYPEIDEN || !(yylval.sym->flags & SDECLARED)) - sym = zero; - else - sym = one; - disexpand = 0; - next(); - if (paren) - expect(')'); - return constnode(sym); + if (lexmode == CPPMODE && !strcmp(yylval.sym->name, "defined")) + return defined(); default: - call_postfix: np = postfix(primary()); goto chk_decay; }