mojoshader_preprocessor.c
changeset 624 99d1cf8a18a3
parent 623 899d7618efef
child 625 bfb4016d9404
equal deleted inserted replaced
623:899d7618efef 624:99d1cf8a18a3
   805 {
   805 {
   806     _handle_pp_ifdef(ctx, TOKEN_PP_IFNDEF);
   806     _handle_pp_ifdef(ctx, TOKEN_PP_IFNDEF);
   807 } // handle_pp_ifndef
   807 } // handle_pp_ifndef
   808 
   808 
   809 
   809 
       
   810 static inline void handle_pp_else(Context *ctx)
       
   811 {
       
   812     IncludeState *state = ctx->include_stack;
       
   813     Conditional *cond = state->conditional_stack;
       
   814 
       
   815     if (!require_newline(state))
       
   816         fail(ctx, "Invalid #else directive");
       
   817     else if (cond == NULL)
       
   818         fail(ctx, "#else without #if");
       
   819     else if (cond->type == TOKEN_PP_ELSE)
       
   820         fail(ctx, "#else after #else");
       
   821     else
       
   822     {
       
   823         // !!! FIXME: doesn't work for #elif
       
   824         cond->type = TOKEN_PP_ELSE;
       
   825         cond->skipping = !cond->skipping;
       
   826     } // else
       
   827 } // handle_pp_else
       
   828 
       
   829 
   810 static void handle_pp_endif(Context *ctx)
   830 static void handle_pp_endif(Context *ctx)
   811 {
   831 {
   812     IncludeState *state = ctx->include_stack;
   832     IncludeState *state = ctx->include_stack;
   813     Conditional *cond = state->conditional_stack;
   833     Conditional *cond = state->conditional_stack;
   814 
   834 
   873         } // if
   893         } // if
   874 
   894 
   875         // !!! FIXME: todo.
   895         // !!! FIXME: todo.
   876         // TOKEN_PP_DEFINE,
   896         // TOKEN_PP_DEFINE,
   877         // TOKEN_PP_IF,
   897         // TOKEN_PP_IF,
   878         // TOKEN_PP_ELSE,
       
   879         // TOKEN_PP_ELIF,
   898         // TOKEN_PP_ELIF,
   880 
   899 
   881         const Conditional *cond = state->conditional_stack;
   900         const Conditional *cond = state->conditional_stack;
   882         const int skipping = ((cond != NULL) && (cond->skipping));
   901         const int skipping = ((cond != NULL) && (cond->skipping));
   883 
   902 
   914         } // else if
   933         } // else if
   915 
   934 
   916         else if (token == TOKEN_PP_ENDIF)
   935         else if (token == TOKEN_PP_ENDIF)
   917         {
   936         {
   918             handle_pp_endif(ctx);
   937             handle_pp_endif(ctx);
       
   938             continue;  // get the next thing.
       
   939         } // else if
       
   940 
       
   941         else if (token == TOKEN_PP_ELSE)
       
   942         {
       
   943             handle_pp_else(ctx);
   919             continue;  // get the next thing.
   944             continue;  // get the next thing.
   920         } // else if
   945         } // else if
   921 
   946 
   922         // NOTE: Conditionals must be above (skipping) test.
   947         // NOTE: Conditionals must be above (skipping) test.
   923         else if (skipping)
   948         else if (skipping)