mojoshader.c
changeset 538 cf2872d06e8b
parent 536 5af65fe6e917
child 540 e65090ad5caa
--- a/mojoshader.c	Tue Feb 03 00:32:09 2009 -0500
+++ b/mojoshader.c	Tue Feb 03 00:50:28 2009 -0500
@@ -6533,9 +6533,6 @@
 
 static int parse_version_token(Context *ctx, const char *profilestr)
 {
-    if (isfail(ctx))  // catch preexisting errors here.
-        return FAIL;
-
     if (ctx->tokencount == 0)
         return fail(ctx, "Expected version token, got none at all.");
 
@@ -6705,10 +6702,7 @@
 {
     int rc = 0;
 
-    if (isfail(ctx))
-        return FAIL;  // just in case...catch previously unhandled fails here.
-
-    else if (ctx->output_stack_len != 0)
+    if (ctx->output_stack_len != 0)
         return fail(ctx, "BUG: output stack isn't empty on new token!");
 
     else if (ctx->tokencount == 0)
@@ -7485,6 +7479,7 @@
     MOJOSHADER_parseData *retval = NULL;
     Context *ctx = NULL;
     int rc = FAIL;
+    int failed = 0;
 
     if ( ((m == NULL) && (f != NULL)) || ((m != NULL) && (f == NULL)) )
         return &out_of_mem_data;  // supply both or neither.
@@ -7503,13 +7498,23 @@
     } // if
 
     // parse out the rest of the tokens after the version token...
-    while ( (rc > 0) && (!isfail(ctx)) )
-    {
+    while (rc > 0)
+    {
+        // reset for each token.
+        if (isfail(ctx))
+        {
+            failed = 1;
+            ctx->isfail = 0;
+        } // if
+
         // reset for every token, and consider an error if it ever overflows!
         ctx->scratchidx = 0;
 
         if ( ((uint32) rc) > ctx->tokencount )
+        {
             fail(ctx, "Corrupted or truncated shader");
+            break;
+        } // if
         else
         {
             ctx->tokens += rc;
@@ -7518,15 +7523,18 @@
         } // else
     } // while
 
-    if (!isfail(ctx))
-    {
-        ctx->parse_phase = MOJOSHADER_PARSEPHASE_DONE;
+    ctx->parse_phase = MOJOSHADER_PARSEPHASE_DONE;
+
+    if (!failed)
+    {
         process_definitions(ctx);
+        failed = isfail(ctx);
     } // if
 
-    if (!isfail(ctx))
+    if (!failed)
         ctx->profile->finalize_emitter(ctx);
 
+    ctx->isfail = failed;
     retval = build_parsedata(ctx);
     destroy_context(ctx);
     return retval;