commit dfb4776b82942448a8daa298b2ba280117f4ddce
Author:     Roberto E. Vargas Caballero <k...@shike2.com>
AuthorDate: Thu Aug 13 17:23:35 2015 +0200
Commit:     Roberto E. Vargas Caballero <k...@shike2.com>
CommitDate: Thu Aug 13 17:23:35 2015 +0200

    Simplify conditional compilation

diff --git a/cc1/cpp.c b/cc1/cpp.c
index a645809..49f246e 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -484,7 +484,10 @@ ifclause(int negate, int isifdef)
 
        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,39 +518,23 @@ ifclause(int negate, int isifdef)
 static void
 cppif(void)
 {
-       setnamespace(NS_CPP);
        disexpand = 0;
-       next();
        ifclause(0, 0);
 }
 
 static void
 ifdef(void)
 {
-       setnamespace(NS_CPP);
-       next();
        ifclause(0, 1);
 }
 
 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,16 +544,30 @@ elseclause(void)
 
        status = (ifstatus[cppctx-1] ^= 1);
        cppoff += (status) ? -1 : 1;
+}
+
+static void
+cppelse(void)
+{
+       elseclause();
        next();
 }
 
 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
@@ -599,7 +600,7 @@ cpp(void)
                {IF, cppif},
                {ELIF, elif},
                {IFNDEF, ifndef},
-               {ELSE, elseclause},
+               {ELSE, cppelse},
                {ENDIF, endif},
                {UNDEF, undef},
                {PRAGMA, pragma},

Reply via email to