ref: dfb4776b82942448a8daa298b2ba280117f4ddce
parent: f6d8f8f304878b3c0e4544d055b29482f818f13e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Aug 13 13:23:35 EDT 2015
Simplify conditional compilation
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -484,7 +484,10 @@
if (cppctx == NR_COND-1)
error("too much nesting levels of conditional inclusion");
+
n = cppctx++;
+ setnamespace(NS_CPP);
+ next();
if (isifdef) {
if (yytoken != IDEN) {
@@ -515,9 +518,7 @@
static void
cppif(void)
{
- setnamespace(NS_CPP);
disexpand = 0;
- next();
ifclause(0, 0);
}
@@ -524,8 +525,6 @@
static void
ifdef(void)
{
- setnamespace(NS_CPP);
- next();
ifclause(0, 1);
}
@@ -532,22 +531,10 @@
static void
ifndef(void)
{
- setnamespace(NS_CPP);
- next();
ifclause(1, 1);
}
static void
-endif(void)
-{
- if (cppctx == 0)
- error("#endif without #if");
- if (!ifstatus[--cppctx])
- --cppoff;
- next();
-}
-
-static void
elseclause(void)
{
int status;
@@ -557,6 +544,12 @@
status = (ifstatus[cppctx-1] ^= 1);
cppoff += (status) ? -1 : 1;
+}
+
+static void
+cppelse(void)
+{
+ elseclause();
next();
}
@@ -563,13 +556,21 @@
static void
elif(void)
{
- setnamespace(NS_CPP);
- disexpand = 0;
elseclause();
- ifclause(0, 0);
+ cppif();
}
static void
+endif(void)
+{
+ if (cppctx == 0)
+ error("#endif without #if");
+ if (!ifstatus[--cppctx])
+ --cppoff;
+ next();
+}
+
+static void
undef(void)
{
if (cppoff)
@@ -599,7 +600,7 @@
{IF, cppif},
{ELIF, elif},
{IFNDEF, ifndef},
- {ELSE, elseclause},
+ {ELSE, cppelse},
{ENDIF, endif},
{UNDEF, undef},
{PRAGMA, pragma},