scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit dfb4776b82942448a8daa298b2ba280117f4ddce
parent f6d8f8f304878b3c0e4544d055b29482f818f13e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 13 Aug 2015 17:23:35 +0200

Simplify conditional compilation

Diffstat:
Mcc1/cpp.c | 41+++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)

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