commit 3ae3ab16c27973a7fdee2bd6daad1aad9cc9910c
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Mon Jul 27 09:44:34 2015 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Mon Jul 27 09:44:34 2015 +0200

    Implement #if
    
    This is a basic implementation of #if, where #elsif and defined() are not
    implemented. Some work can be done to integrate cppif() and ifclause()

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 8e9f3e5..093e474 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -476,6 +476,24 @@ ifclause(int isdef)
 }
 
 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;
+}
+
+static void
 ifdef(void)
 {
        ifclause(1);
@@ -535,6 +553,7 @@ cpp(void)
                {INCLUDE, include},
                {LINE, line},
                {IFDEF, ifdef},
+               {IF, cppif},
                {IFNDEF, ifndef},
                {ELSE, elseclause},
                {ENDIF, endif},
diff --git a/cc1/symbol.c b/cc1/symbol.c
index c581dd1..8c86de2 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -262,6 +262,7 @@ ikeywords(void)
                {"include", INCLUDE, INCLUDE},
                {"line", LINE, LINE},
                {"ifdef", IFDEF, IFDEF},
+               {"if", IF, IF},
                {"else", ELSE, ELSE},
                {"ifndef", IFNDEF, IFNDEF},
                {"endif", ENDIF, ENDIF},

Reply via email to