From 30b6a51bb4fb3ab8a78b636bed914a22313db2bc Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 14 Feb 2009 23:00:34 -0500 Subject: [PATCH] Implemented #else preprocessor directive. --- mojoshader_preprocessor.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mojoshader_preprocessor.c b/mojoshader_preprocessor.c index 8249584e..26e5d2f1 100644 --- a/mojoshader_preprocessor.c +++ b/mojoshader_preprocessor.c @@ -807,6 +807,26 @@ static inline void handle_pp_ifndef(Context *ctx) } // handle_pp_ifndef +static inline void handle_pp_else(Context *ctx) +{ + IncludeState *state = ctx->include_stack; + Conditional *cond = state->conditional_stack; + + if (!require_newline(state)) + fail(ctx, "Invalid #else directive"); + else if (cond == NULL) + fail(ctx, "#else without #if"); + else if (cond->type == TOKEN_PP_ELSE) + fail(ctx, "#else after #else"); + else + { + // !!! FIXME: doesn't work for #elif + cond->type = TOKEN_PP_ELSE; + cond->skipping = !cond->skipping; + } // else +} // handle_pp_else + + static void handle_pp_endif(Context *ctx) { IncludeState *state = ctx->include_stack; @@ -875,7 +895,6 @@ static inline const char *_preprocessor_nexttoken(Preprocessor *_ctx, // !!! FIXME: todo. // TOKEN_PP_DEFINE, // TOKEN_PP_IF, - // TOKEN_PP_ELSE, // TOKEN_PP_ELIF, const Conditional *cond = state->conditional_stack; @@ -919,6 +938,12 @@ static inline const char *_preprocessor_nexttoken(Preprocessor *_ctx, continue; // get the next thing. } // else if + else if (token == TOKEN_PP_ELSE) + { + handle_pp_else(ctx); + continue; // get the next thing. + } // else if + // NOTE: Conditionals must be above (skipping) test. else if (skipping) continue; // just keep dumping tokens until we get end of block.