Remove unreferenced struct types from the AST

This expands pruning unreferenced variables so that unreferenced named
struct types can also be removed from the AST.

Includes a small cleanup in GLSL output so that the output code
matching tests can test against clean output.

BUG=chromium:786535
TEST=angle_unittests

Change-Id: I20974ac99a797e478d82f9203c179d2d58fac268
Reviewed-on: https://chromium-review.googlesource.com/779519
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index 99dc04f..9a47287 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -86,7 +86,7 @@
                                  ShCompileOptions compileOptions)
     : TIntermTraverser(true, true, true, symbolTable),
       mObjSink(objSink),
-      mDeclaringVariables(false),
+      mDeclaringVariable(false),
       mClampingStrategy(clampingStrategy),
       mHashFunction(hashFunction),
       mNameMap(nameMap),
@@ -435,7 +435,7 @@
     TInfoSinkBase &out = objSink();
     out << hashVariableName(node->getName());
 
-    if (mDeclaringVariables && node->getType().isArray())
+    if (mDeclaringVariable && node->getType().isArray())
         out << ArrayString(node->getType());
 }
 
@@ -469,7 +469,7 @@
             {
                 out << " = ";
                 // RHS of initialize is not being declared.
-                mDeclaringVariables = false;
+                mDeclaringVariable = false;
             }
             break;
         case EOpAssign:
@@ -995,17 +995,20 @@
         TIntermTyped *variable          = sequence.front()->getAsTyped();
         writeLayoutQualifier(variable);
         writeVariableType(variable->getType());
-        out << " ";
-        mDeclaringVariables = true;
+        if (variable->getAsSymbolNode() == nullptr ||
+            !variable->getAsSymbolNode()->getSymbol().empty())
+        {
+            out << " ";
+        }
+        mDeclaringVariable = true;
     }
     else if (visit == InVisit)
     {
-        out << ", ";
-        mDeclaringVariables = true;
+        UNREACHABLE();
     }
     else
     {
-        mDeclaringVariables = false;
+        mDeclaringVariable = false;
     }
     return true;
 }