scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 3ae3ab16c27973a7fdee2bd6daad1aad9cc9910c
parent 7761303503062221973c8bd9bad4cb019cebe7f6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 27 Jul 2015 09:44:34 +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()

Diffstat:
cc1/cpp.c | 19+++++++++++++++++++
cc1/symbol.c | 1+
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git 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 @@ -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},