mojoshader_preprocessor.c
changeset 687 bb36744480e8
parent 685 687e9def5cc6
child 689 5872092cbf95
equal deleted inserted replaced
686:021241f2a237 687:bb36744480e8
  1567     state->conditional_stack = conditional;
  1567     state->conditional_stack = conditional;
  1568     return conditional;
  1568     return conditional;
  1569 } // handle_pp_if
  1569 } // handle_pp_if
  1570 
  1570 
  1571 
  1571 
  1572 static inline void handle_pp_else(Context *ctx)
  1572 static void handle_pp_elif(Context *ctx)
       
  1573 {
       
  1574     const int result = reduce_pp_expression(ctx);
       
  1575     if (result == -1)
       
  1576         return;
       
  1577 
       
  1578     IncludeState *state = ctx->include_stack;
       
  1579     Conditional *cond = state->conditional_stack;
       
  1580     if (cond == NULL)
       
  1581         fail(ctx, "#elif without #if");
       
  1582     else if (cond->type == TOKEN_PP_ELSE)
       
  1583         fail(ctx, "#elif after #else");
       
  1584     else
       
  1585     {
       
  1586         cond->type = TOKEN_PP_ELIF;
       
  1587         cond->skipping = ((cond->chosen) || (!result));
       
  1588         if (!cond->chosen)
       
  1589             cond->chosen = result;
       
  1590     } // else
       
  1591 } // handle_pp_elif
       
  1592 
       
  1593 
       
  1594 static void handle_pp_else(Context *ctx)
  1573 {
  1595 {
  1574     IncludeState *state = ctx->include_stack;
  1596     IncludeState *state = ctx->include_stack;
  1575     Conditional *cond = state->conditional_stack;
  1597     Conditional *cond = state->conditional_stack;
  1576 
  1598 
  1577     if (!require_newline(state))
  1599     if (!require_newline(state))
  1651             *_token = TOKEN_EOI;
  1673             *_token = TOKEN_EOI;
  1652             *_len = 0;
  1674             *_len = 0;
  1653             return NULL;  // we're done!
  1675             return NULL;  // we're done!
  1654         } // if
  1676         } // if
  1655 
  1677 
  1656         // !!! FIXME: todo.
       
  1657         // TOKEN_PP_ELIF,
       
  1658 
       
  1659         const Conditional *cond = state->conditional_stack;
  1678         const Conditional *cond = state->conditional_stack;
  1660         const int skipping = ((cond != NULL) && (cond->skipping));
  1679         const int skipping = ((cond != NULL) && (cond->skipping));
  1661 
  1680 
  1662         Token token = lexer(state);
  1681         Token token = lexer(state);
  1663         if (token == TOKEN_EOI)
  1682         if (token == TOKEN_EOI)
  1692         } // else if
  1711         } // else if
  1693 
  1712 
  1694         else if (token == TOKEN_PP_IF)
  1713         else if (token == TOKEN_PP_IF)
  1695         {
  1714         {
  1696             handle_pp_if(ctx);
  1715             handle_pp_if(ctx);
       
  1716             continue;  // get the next thing.
       
  1717         } // else if
       
  1718 
       
  1719         else if (token == TOKEN_PP_ELIF)
       
  1720         {
       
  1721             handle_pp_elif(ctx);
  1697             continue;  // get the next thing.
  1722             continue;  // get the next thing.
  1698         } // else if
  1723         } // else if
  1699 
  1724 
  1700         else if (token == TOKEN_PP_ENDIF)
  1725         else if (token == TOKEN_PP_ENDIF)
  1701         {
  1726         {