From 40c12970fd31f20312f3e194f7daf4b5e55881ba Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 14 Feb 2009 17:25:55 -0500 Subject: [PATCH] Implemented #endif preprocessor directive. --- mojoshader_preprocessor.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mojoshader_preprocessor.c b/mojoshader_preprocessor.c index 5f0efc10..d323565e 100644 --- a/mojoshader_preprocessor.c +++ b/mojoshader_preprocessor.c @@ -744,6 +744,24 @@ static void handle_pp_undef(Context *ctx) } // handle_pp_undef +static void handle_pp_endif(Context *ctx) +{ + IncludeState *state = ctx->include_stack; + Conditional *cond = state->conditional_stack; + + if (!require_newline(state)) + fail(ctx, "Invalid #endif directive"); + else if (cond == NULL) + fail(ctx, "Unmatched #endif"); + else + { + state->conditional_stack = cond->next; // pop it. + cond->next = NULL; + put_conditionals(ctx, cond); + } // else +} // handle_pp_endif + + static void unterminated_pp_condition(Context *ctx) { IncludeState *state = ctx->include_stack; @@ -763,7 +781,6 @@ static void unterminated_pp_condition(Context *ctx) // pop this conditional, we'll report the next error next time... state->conditional_stack = cond->next; // pop it. - cond->next = NULL; put_conditionals(ctx, cond); } // unterminated_pp_condition @@ -799,7 +816,6 @@ static inline const char *_preprocessor_nexttoken(Preprocessor *_ctx, // TOKEN_PP_IFNDEF, // TOKEN_PP_ELSE, // TOKEN_PP_ELIF, - // TOKEN_PP_ENDIF, const Conditional *cond = state->conditional_stack; const int skipping = ((cond != NULL) && (cond->skipping)); @@ -824,6 +840,12 @@ static inline const char *_preprocessor_nexttoken(Preprocessor *_ctx, continue; // will return at top of loop. } // else if + else if (token == TOKEN_PP_ENDIF) + { + handle_pp_endif(ctx); + continue; // get the next thing. + } // else if + // !!! FIXME: #else, #elif and #endif must be above (skipping) test. else if (skipping) {