[hackers] [scc] Implement #if || Roberto E. Vargas Caballero
commit 3ae3ab16c27973a7fdee2bd6daad1aad9cc9910c
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Jul 27 09:44:34 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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);
_AT_@ -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
_AT_@ -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},
Received on Mon Jul 27 2015 - 09:47:14 CEST
This archive was generated by hypermail 2.3.0
: Mon Jul 27 2015 - 09:48:12 CEST