Implemented #elif preprocessor directive.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 23 Feb 2009 17:52:28 -0500
changeset 687 bb36744480e8
parent 686 021241f2a237
child 688 29ee34e66161
Implemented #elif preprocessor directive.
mojoshader_preprocessor.c
--- a/mojoshader_preprocessor.c	Mon Feb 23 17:49:10 2009 -0500
+++ b/mojoshader_preprocessor.c	Mon Feb 23 17:52:28 2009 -0500
@@ -1569,7 +1569,29 @@
 } // handle_pp_if
 
 
-static inline void handle_pp_else(Context *ctx)
+static void handle_pp_elif(Context *ctx)
+{
+    const int result = reduce_pp_expression(ctx);
+    if (result == -1)
+        return;
+
+    IncludeState *state = ctx->include_stack;
+    Conditional *cond = state->conditional_stack;
+    if (cond == NULL)
+        fail(ctx, "#elif without #if");
+    else if (cond->type == TOKEN_PP_ELSE)
+        fail(ctx, "#elif after #else");
+    else
+    {
+        cond->type = TOKEN_PP_ELIF;
+        cond->skipping = ((cond->chosen) || (!result));
+        if (!cond->chosen)
+            cond->chosen = result;
+    } // else
+} // handle_pp_elif
+
+
+static void handle_pp_else(Context *ctx)
 {
     IncludeState *state = ctx->include_stack;
     Conditional *cond = state->conditional_stack;
@@ -1653,9 +1675,6 @@
             return NULL;  // we're done!
         } // if
 
-        // !!! FIXME: todo.
-        // TOKEN_PP_ELIF,
-
         const Conditional *cond = state->conditional_stack;
         const int skipping = ((cond != NULL) && (cond->skipping));
 
@@ -1697,6 +1716,12 @@
             continue;  // get the next thing.
         } // else if
 
+        else if (token == TOKEN_PP_ELIF)
+        {
+            handle_pp_elif(ctx);
+            continue;  // get the next thing.
+        } // else if
+
         else if (token == TOKEN_PP_ENDIF)
         {
             handle_pp_endif(ctx);