Skip to content

Commit

Permalink
Implemented #else preprocessor directive.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 15, 2009
1 parent b8c6418 commit 30b6a51
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion mojoshader_preprocessor.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 30b6a51

Please sign in to comment.