TOutputGLSLBase::visitLoop clarify the function slightly

Since only for loops can be unrolled, handle each type of loop only
once. This improvement was going to be part of a do-while workaround for
Mac that will instead be done at the AST level.

BUG=angleproject:891

Change-Id: Ic8ecf41aa6d9abd7a01c2230e908c85152f52b62
Reviewed-on: https://chromium-review.googlesource.com/302332
Tryjob-Request: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index 56d3275..0924e92 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -1075,8 +1075,12 @@
     TInfoSinkBase &out = objSink();
 
     incrementDepth(node);
-    // Loop header.
+
     TLoopType loopType = node->getType();
+
+    // Only for loops can be unrolled
+    ASSERT(!node->getUnrollFlag() || loopType == ELoopFor);
+
     if (loopType == ELoopFor)  // for loop
     {
         if (!node->getUnrollFlag())
@@ -1093,6 +1097,8 @@
             if (node->getExpression())
                 node->getExpression()->traverse(this);
             out << ")\n";
+
+            visitCodeBlock(node->getBody());
         }
         else
         {
@@ -1105,6 +1111,16 @@
             out << "for (int " << name << " = 0; "
                 << name << " < 1; "
                 << "++" << name << ")\n";
+
+            out << "{\n";
+            mLoopUnrollStack.push(node);
+            while (mLoopUnrollStack.satisfiesLoopCondition())
+            {
+                visitCodeBlock(node->getBody());
+                mLoopUnrollStack.step();
+            }
+            mLoopUnrollStack.pop();
+            out << "}\n";
         }
     }
     else if (loopType == ELoopWhile)  // while loop
@@ -1113,39 +1129,22 @@
         ASSERT(node->getCondition() != NULL);
         node->getCondition()->traverse(this);
         out << ")\n";
+
+        visitCodeBlock(node->getBody());
     }
     else  // do-while loop
     {
         ASSERT(loopType == ELoopDoWhile);
         out << "do\n";
-    }
 
-    // Loop body.
-    if (node->getUnrollFlag())
-    {
-        out << "{\n";
-        mLoopUnrollStack.push(node);
-        while (mLoopUnrollStack.satisfiesLoopCondition())
-        {
-            visitCodeBlock(node->getBody());
-            mLoopUnrollStack.step();
-        }
-        mLoopUnrollStack.pop();
-        out << "}\n";
-    }
-    else
-    {
         visitCodeBlock(node->getBody());
-    }
 
-    // Loop footer.
-    if (loopType == ELoopDoWhile)  // do-while loop
-    {
         out << "while (";
         ASSERT(node->getCondition() != NULL);
         node->getCondition()->traverse(this);
         out << ");\n";
     }
+
     decrementDepth();
 
     // No need to visit children. They have been already processed in