ref: 167690b43dd4a0f6279bd9e8dd6f4aa84a3ca375
parent: 3ae3ab16c27973a7fdee2bd6daad1aad9cc9910c
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Jul 27 06:50:09 EDT 2015
Join #if and #ifdef
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -451,27 +451,34 @@
}
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");
+
+ 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;
}
- sym = lookup(NS_CPP);
- next();
-
- status = (sym->flags & ISDEFINED) != 0 == isdef;
-
- if (!(ifstatus[n] = status))
+ if (negate)
+ status = !status;
+ if ((ifstatus[n] = status) == 0)
++cppoff;
}
@@ -478,31 +485,19 @@
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