Implemented #else preprocessor directive.
--- 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.