# HG changeset patch # User Ryan C. Gordon # Date 1234670434 18000 # Node ID 99d1cf8a18a39cd910ee3403f4fe8a14f26d456c # Parent 899d7618efefd357b8c165f1a42a1ff7d35f5fe1 Implemented #else preprocessor directive. diff -r 899d7618efef -r 99d1cf8a18a3 mojoshader_preprocessor.c --- a/mojoshader_preprocessor.c Sat Feb 14 17:59:55 2009 -0500 +++ b/mojoshader_preprocessor.c Sat Feb 14 23:00:34 2009 -0500 @@ -807,6 +807,26 @@ } // 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 @@ // !!! FIXME: todo. // TOKEN_PP_DEFINE, // TOKEN_PP_IF, - // TOKEN_PP_ELSE, // TOKEN_PP_ELIF, const Conditional *cond = state->conditional_stack; @@ -919,6 +938,12 @@ 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.