scc

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

commit 167690b43dd4a0f6279bd9e8dd6f4aa84a3ca375
parent 3ae3ab16c27973a7fdee2bd6daad1aad9cc9910c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 27 Jul 2015 10:50:09 +0200

Join #if and #ifdef

Diffstat:
Mcc1/cpp.c | 47+++++++++++++++++++++--------------------------
1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -451,58 +451,53 @@ usererr(void) } static void -ifclause(int isdef) +ifclause(int negate, int isifdef) { Symbol *sym; unsigned n; int status; + Node *expr; if (cppctx == NR_COND-1) error("too much nesting levels of conditional inclusion"); - n = cppctx++; - if (yytoken != IDEN) { - error("no macro name given in #%s directive", - (isdef) ? "ifdef" : "ifndef"); - } - sym = lookup(NS_CPP); - next(); - - status = (sym->flags & ISDEFINED) != 0 == isdef; + if (isifdef) { + if (yytoken != IDEN) { + error("no macro name given in #%s directive", + (negate) ? "ifndef" : "ifdef"); + } + sym = lookup(NS_CPP); + next(); + status = (sym->flags & ISDEFINED) != 0; + } else { + if ((expr = iconstexpr()) == NULL) + error("parameter of #if is not an integer constant expression"); + status = expr->sym->u.i != 0; + } - if (!(ifstatus[n] = status)) + if (negate) + status = !status; + if ((ifstatus[n] = status) == 0) ++cppoff; } static void cppif(void) { - Node *expr; - int status; - unsigned n; - - if (cppctx == NR_COND-1) - error("too much nesting levels of conditional inclusion"); - n = cppctx++; - - if ((expr = iconstexpr()) == NULL) - error("parameter of #if is not an integer constant expression"); - status = expr->sym->u.i != 0; - if (!(ifstatus[n] = status)) - ++cppoff; + ifclause(0, 0); } static void ifdef(void) { - ifclause(1); + ifclause(0, 1); } static void ifndef(void) { - ifclause(0); + ifclause(1, 1); } static void