Clean up direct access of ShaderVariable::arraySize

This change is pure refactoring. It's intended to help with adding
support for arrays of arrays.

BUG=angleproject:2125
TEST=angle_unittests

Change-Id: I82881a98c3c476fd6666a551ce6be255ae0de4cf
Reviewed-on: https://chromium-review.googlesource.com/733127
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/CollectVariables.cpp b/src/compiler/translator/CollectVariables.cpp
index 5eccbf2..26378dc 100644
--- a/src/compiler/translator/CollectVariables.cpp
+++ b/src/compiler/translator/CollectVariables.cpp
@@ -353,34 +353,27 @@
             info.name          = kName;
             info.mappedName    = kName;
             info.type          = GL_NONE;
-            info.arraySize     = 0;
             info.precision     = GL_NONE;
             info.staticUse     = true;
 
-            ShaderVariable nearInfo;
+            ShaderVariable nearInfo(GL_FLOAT);
             const char kNearName[] = "near";
             nearInfo.name          = kNearName;
             nearInfo.mappedName    = kNearName;
-            nearInfo.type          = GL_FLOAT;
-            nearInfo.arraySize     = 0;
             nearInfo.precision     = GL_HIGH_FLOAT;
             nearInfo.staticUse     = true;
 
-            ShaderVariable farInfo;
+            ShaderVariable farInfo(GL_FLOAT);
             const char kFarName[] = "far";
             farInfo.name          = kFarName;
             farInfo.mappedName    = kFarName;
-            farInfo.type          = GL_FLOAT;
-            farInfo.arraySize     = 0;
             farInfo.precision     = GL_HIGH_FLOAT;
             farInfo.staticUse     = true;
 
-            ShaderVariable diffInfo;
+            ShaderVariable diffInfo(GL_FLOAT);
             const char kDiffName[] = "diff";
             diffInfo.name          = kDiffName;
             diffInfo.mappedName    = kDiffName;
-            diffInfo.type          = GL_FLOAT;
-            diffInfo.arraySize     = 0;
             diffInfo.precision     = GL_HIGH_FLOAT;
             diffInfo.staticUse     = true;
 
@@ -447,7 +440,6 @@
                     info.name          = kName;
                     info.mappedName    = kName;
                     info.type          = GL_INT;
-                    info.arraySize     = 0;
                     info.precision     = GL_HIGH_INT;  // Defined by spec.
                     info.staticUse     = true;
                     info.location      = -1;
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index b7af2d7..f18fd30 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -1020,7 +1020,7 @@
 void TCompiler::initializeGLPosition(TIntermBlock *root)
 {
     InitVariableList list;
-    sh::ShaderVariable var(GL_FLOAT_VEC4, 0);
+    sh::ShaderVariable var(GL_FLOAT_VEC4);
     var.name = "gl_Position";
     list.push_back(var);
     InitializeVariables(root, list, symbolTable, shaderVersion, extensionBehavior);
diff --git a/src/compiler/translator/ShaderVars.cpp b/src/compiler/translator/ShaderVars.cpp
index 7a6e181..d51ca5b 100644
--- a/src/compiler/translator/ShaderVars.cpp
+++ b/src/compiler/translator/ShaderVars.cpp
@@ -34,9 +34,15 @@
 {
 }
 
+ShaderVariable::ShaderVariable(GLenum typeIn)
+    : type(typeIn), precision(0), arraySize(0), staticUse(false)
+{
+}
+
 ShaderVariable::ShaderVariable(GLenum typeIn, unsigned int arraySizeIn)
     : type(typeIn), precision(0), arraySize(arraySizeIn), staticUse(false)
 {
+    ASSERT(arraySizeIn != 0);
 }
 
 ShaderVariable::~ShaderVariable()
diff --git a/src/tests/compiler_tests/CollectVariables_test.cpp b/src/tests/compiler_tests/CollectVariables_test.cpp
index 5f9f5aa..2779939 100644
--- a/src/tests/compiler_tests/CollectVariables_test.cpp
+++ b/src/tests/compiler_tests/CollectVariables_test.cpp
@@ -88,7 +88,7 @@
                 foundDiff = true;
             }
 
-            EXPECT_EQ(0u, field.arraySize);
+            EXPECT_FALSE(field.isArray());
             EXPECT_FALSE(field.isStruct());
             EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, field.precision);
             EXPECT_TRUE(field.staticUse);
@@ -243,7 +243,7 @@
 
     const OutputVariable &outputVariable = outputVariables[0];
 
-    EXPECT_EQ(0u, outputVariable.arraySize);
+    EXPECT_FALSE(outputVariable.isArray());
     EXPECT_EQ(-1, outputVariable.location);
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable.precision);
     EXPECT_TRUE(outputVariable.staticUse);
@@ -268,7 +268,7 @@
 
     const OutputVariable &outputVariable = outputVariables[0];
 
-    EXPECT_EQ(0u, outputVariable.arraySize);
+    EXPECT_FALSE(outputVariable.isArray());
     EXPECT_EQ(5, outputVariable.location);
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable.precision);
     EXPECT_TRUE(outputVariable.staticUse);
@@ -292,7 +292,7 @@
 
     const Attribute &attribute = attributes[0];
 
-    EXPECT_EQ(0u, attribute.arraySize);
+    EXPECT_FALSE(attribute.isArray());
     EXPECT_EQ(5, attribute.location);
     EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, attribute.precision);
     EXPECT_TRUE(attribute.staticUse);
@@ -535,7 +535,7 @@
         varying = &varyings[1];
     }
 
-    EXPECT_EQ(0u, varying->arraySize);
+    EXPECT_FALSE(varying->isArray());
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, varying->precision);
     EXPECT_TRUE(varying->staticUse);
     EXPECT_GLENUM_EQ(GL_FLOAT, varying->type);
@@ -581,7 +581,7 @@
     const OutputVariable *outputVariable = nullptr;
     validateOutputVariableForShader(fragColorShader, 0u, "gl_FragColor", &outputVariable);
     ASSERT_NE(outputVariable, nullptr);
-    EXPECT_EQ(0u, outputVariable->arraySize);
+    EXPECT_FALSE(outputVariable->isArray());
     EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type);
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
 }
@@ -630,7 +630,7 @@
     const OutputVariable *outputVariable = nullptr;
     validateOutputVariableForShader(fragDepthShader, 0u, "gl_FragDepthEXT", &outputVariable);
     ASSERT_NE(outputVariable, nullptr);
-    EXPECT_EQ(0u, outputVariable->arraySize);
+    EXPECT_FALSE(outputVariable->isArray());
     EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type);
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
 }
@@ -653,7 +653,7 @@
     const OutputVariable *outputVariable = nullptr;
     validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepthEXT", &outputVariable);
     ASSERT_NE(outputVariable, nullptr);
-    EXPECT_EQ(0u, outputVariable->arraySize);
+    EXPECT_FALSE(outputVariable->isArray());
     EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type);
     EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, outputVariable->precision);
 }
@@ -676,7 +676,7 @@
     const OutputVariable *outputVariable = nullptr;
     validateOutputVariableForShader(fragDepthHighShader, 0u, "gl_FragDepth", &outputVariable);
     ASSERT_NE(outputVariable, nullptr);
-    EXPECT_EQ(0u, outputVariable->arraySize);
+    EXPECT_FALSE(outputVariable->isArray());
     EXPECT_GLENUM_EQ(GL_FLOAT, outputVariable->type);
     EXPECT_GLENUM_EQ(GL_HIGH_FLOAT, outputVariable->precision);
 }
@@ -704,7 +704,7 @@
     const OutputVariable *outputVariable = nullptr;
     validateOutputVariableForShader(secondaryFragColorShader, 0u, "gl_FragColor", &outputVariable);
     ASSERT_NE(outputVariable, nullptr);
-    EXPECT_EQ(0u, outputVariable->arraySize);
+    EXPECT_FALSE(outputVariable->isArray());
     EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type);
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
 
@@ -712,7 +712,7 @@
     validateOutputVariableForShader(secondaryFragColorShader, 1u, "gl_SecondaryFragColorEXT",
                                     &outputVariable);
     ASSERT_NE(outputVariable, nullptr);
-    EXPECT_EQ(0u, outputVariable->arraySize);
+    EXPECT_FALSE(outputVariable->isArray());
     EXPECT_GLENUM_EQ(GL_FLOAT_VEC4, outputVariable->type);
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, outputVariable->precision);
 }
@@ -831,7 +831,7 @@
 
     const Uniform &uniform = uniforms[0];
 
-    EXPECT_EQ(0u, uniform.arraySize);
+    EXPECT_FALSE(uniform.isArray());
     EXPECT_EQ("u", uniform.name);
     EXPECT_EQ("webgl_1", uniform.mappedName);
     EXPECT_TRUE(uniform.staticUse);
@@ -868,14 +868,14 @@
     ASSERT_EQ(2u, uniforms.size());
 
     const Uniform &uniform = uniforms[0];
-    EXPECT_EQ(0u, uniform.arraySize);
+    EXPECT_FALSE(uniform.isArray());
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniform.precision);
     EXPECT_TRUE(uniform.staticUse);
     EXPECT_GLENUM_EQ(GL_FLOAT, uniform.type);
     EXPECT_EQ("uA", uniform.name);
 
     const Uniform &uniformB = uniforms[1];
-    EXPECT_EQ(0u, uniformB.arraySize);
+    EXPECT_FALSE(uniformB.isArray());
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniformB.precision);
     EXPECT_TRUE(uniformB.staticUse);
     EXPECT_GLENUM_EQ(GL_FLOAT, uniformB.type);
@@ -901,7 +901,7 @@
     ASSERT_EQ(1u, uniforms.size());
 
     const Uniform &uniformB = uniforms[0];
-    EXPECT_EQ(0u, uniformB.arraySize);
+    EXPECT_FALSE(uniformB.isArray());
     EXPECT_GLENUM_EQ(GL_MEDIUM_FLOAT, uniformB.precision);
     EXPECT_TRUE(uniformB.staticUse);
     EXPECT_GLENUM_EQ(GL_FLOAT, uniformB.type);
diff --git a/src/tests/compiler_tests/ShaderVariable_test.cpp b/src/tests/compiler_tests/ShaderVariable_test.cpp
index 2c06400..9389788 100644
--- a/src/tests/compiler_tests/ShaderVariable_test.cpp
+++ b/src/tests/compiler_tests/ShaderVariable_test.cpp
@@ -26,13 +26,13 @@
     // };
     // B uni[2];
     ShaderVariable uni;
-    uni.arraySize = 2;
+    uni.setArraySize(2);
     uni.name = "uni";
     uni.mappedName = "m_uni";
     uni.structName = "B";
     {
         ShaderVariable a;
-        a.arraySize = 3;
+        a.setArraySize(3);
         a.name = "a";
         a.mappedName = "m_a";
         a.structName = "A";
@@ -42,7 +42,7 @@
             x.mappedName = "m_x";
             a.fields.push_back(x);
 
-            ShaderVariable y(GL_FLOAT_VEC3, 0);
+            ShaderVariable y(GL_FLOAT_VEC3);
             y.name = "y";
             y.mappedName = "m_y";
             a.fields.push_back(y);
@@ -94,17 +94,16 @@
     // };
     // uniform A uni;
     Uniform vx_a;
-    vx_a.arraySize = 0;
     vx_a.name = "uni";
     vx_a.mappedName = "m_uni";
     vx_a.structName = "A";
     {
-        ShaderVariable x(GL_FLOAT, 0);
+        ShaderVariable x(GL_FLOAT);
         x.name = "x";
         x.mappedName = "m_x";
         vx_a.fields.push_back(x);
 
-        ShaderVariable y(GL_FLOAT, 0);
+        ShaderVariable y(GL_FLOAT);
         y.name = "y";
         y.mappedName = "m_y";
         vx_a.fields.push_back(y);
@@ -116,17 +115,16 @@
     // };
     // uniform A uni;
     Uniform fx_a;
-    fx_a.arraySize = 0;
     fx_a.name = "uni";
     fx_a.mappedName = "m_uni";
     fx_a.structName = "A";
     {
-        ShaderVariable y(GL_FLOAT, 0);
+        ShaderVariable y(GL_FLOAT);
         y.name = "y";
         y.mappedName = "m_y";
         fx_a.fields.push_back(y);
 
-        ShaderVariable x(GL_FLOAT, 0);
+        ShaderVariable x(GL_FLOAT);
         x.name = "x";
         x.mappedName = "m_x";
         fx_a.fields.push_back(x);
@@ -143,17 +141,16 @@
     // };
     // uniform A uni;
     Uniform vx_a;
-    vx_a.arraySize = 0;
     vx_a.name = "uni";
     vx_a.mappedName = "m_uni";
     vx_a.structName = "A";
     {
-        ShaderVariable x(GL_FLOAT, 0);
+        ShaderVariable x(GL_FLOAT);
         x.name = "x";
         x.mappedName = "m_x";
         vx_a.fields.push_back(x);
 
-        ShaderVariable y(GL_FLOAT, 0);
+        ShaderVariable y(GL_FLOAT);
         y.name = "y";
         y.mappedName = "m_y";
         vx_a.fields.push_back(y);
@@ -165,16 +162,15 @@
     // };
     // uniform B uni;
     Uniform fx_a;
-    fx_a.arraySize = 0;
     fx_a.name = "uni";
     fx_a.mappedName = "m_uni";
     {
-        ShaderVariable x(GL_FLOAT, 0);
+        ShaderVariable x(GL_FLOAT);
         x.name = "x";
         x.mappedName = "m_x";
         fx_a.fields.push_back(x);
 
-        ShaderVariable y(GL_FLOAT, 0);
+        ShaderVariable y(GL_FLOAT);
         y.name = "y";
         y.mappedName = "m_y";
         fx_a.fields.push_back(y);
@@ -195,7 +191,6 @@
     // invariant varying float vary;
     Varying vx;
     vx.type = GL_FLOAT;
-    vx.arraySize = 0;
     vx.precision = GL_MEDIUM_FLOAT;
     vx.name = "vary";
     vx.mappedName = "m_vary";
@@ -205,7 +200,6 @@
     // varying float vary;
     Varying fx;
     fx.type = GL_FLOAT;
-    fx.arraySize = 0;
     fx.precision = GL_MEDIUM_FLOAT;
     fx.name = "vary";
     fx.mappedName = "m_vary";
@@ -428,7 +422,6 @@
     // Varying float vary1;
     Varying vx;
     vx.type        = GL_FLOAT;
-    vx.arraySize   = 0;
     vx.precision   = GL_MEDIUM_FLOAT;
     vx.name        = "vary1";
     vx.mappedName  = "m_vary1";
@@ -438,7 +431,6 @@
     // Varying float vary2;
     Varying fx;
     fx.type        = GL_FLOAT;
-    fx.arraySize   = 0;
     fx.precision   = GL_MEDIUM_FLOAT;
     fx.name        = "vary2";
     fx.mappedName  = "m_vary2";
diff --git a/src/tests/compiler_tests/VariablePacker_test.cpp b/src/tests/compiler_tests/VariablePacker_test.cpp
index 9fa3b7e..244811b 100644
--- a/src/tests/compiler_tests/VariablePacker_test.cpp
+++ b/src/tests/compiler_tests/VariablePacker_test.cpp
@@ -60,6 +60,17 @@
 static sh::GLenum nonSqMatTypes[] = {GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4, GL_FLOAT_MAT3x2,
                                      GL_FLOAT_MAT3x4, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3};
 
+// Creates either a single variable or an array variable depending on numVars.
+sh::ShaderVariable CreateShaderVariable(sh::GLenum type, int numVars)
+{
+    ASSERT(numVars != 0);
+    if (numVars == 1)
+    {
+        return sh::ShaderVariable(type);
+    }
+    return sh::ShaderVariable(type, numVars);
+}
+
 }  // anonymous namespace
 
 TEST(VariablePacking, Pack)
@@ -76,18 +87,18 @@
         int num_components_per_row = sh::GetTypePackingComponentsPerRow(type);
         // Check 1 of the type.
         vars.clear();
-        vars.push_back(sh::ShaderVariable(type, 0));
+        vars.push_back(sh::ShaderVariable(type));
         EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
 
         // Check exactly the right amount of 1 type as an array.
         int num_vars = kMaxRows / num_rows;
         vars.clear();
-        vars.push_back(sh::ShaderVariable(type, num_vars == 1 ? 0 : num_vars));
+        vars.push_back(CreateShaderVariable(type, num_vars));
         EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
 
         // test too many
         vars.clear();
-        vars.push_back(sh::ShaderVariable(type, num_vars == 0 ? 0 : (num_vars + 1)));
+        vars.push_back(CreateShaderVariable(type, num_vars + 1));
         EXPECT_FALSE(CheckVariablesInPackingLimits(kMaxRows, vars));
 
         // Check exactly the right amount of 1 type as individual vars.
@@ -96,26 +107,26 @@
         vars.clear();
         for (int ii = 0; ii < num_vars; ++ii)
         {
-            vars.push_back(sh::ShaderVariable(type, 0));
+            vars.push_back(sh::ShaderVariable(type));
         }
         EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
 
         // Check 1 too many.
-        vars.push_back(sh::ShaderVariable(type, 0));
+        vars.push_back(sh::ShaderVariable(type));
         EXPECT_FALSE(CheckVariablesInPackingLimits(kMaxRows, vars));
     }
 
     // Test example from GLSL ES 3.0 spec chapter 11.
     vars.clear();
-    vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC4, 0));
-    vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0));
-    vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0));
+    vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC4));
+    vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
+    vars.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
     vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 6));
     vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 4));
-    vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 0));
+    vars.push_back(sh::ShaderVariable(GL_FLOAT_VEC2));
     vars.push_back(sh::ShaderVariable(GL_FLOAT, 3));
     vars.push_back(sh::ShaderVariable(GL_FLOAT, 2));
-    vars.push_back(sh::ShaderVariable(GL_FLOAT, 0));
+    vars.push_back(sh::ShaderVariable(GL_FLOAT));
     EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
 }
 
@@ -158,21 +169,21 @@
         int squareSize = std::max(rows, cols);
 
         std::vector<sh::ShaderVariable> vars;
-        vars.push_back(sh::ShaderVariable(type, 0));
+        vars.push_back(sh::ShaderVariable(type));
 
         // Fill columns
         for (int row = 0; row < squareSize; row++)
         {
             for (int col = squareSize; col < 4; ++col)
             {
-                vars.push_back(sh::ShaderVariable(GL_FLOAT, 0));
+                vars.push_back(sh::ShaderVariable(GL_FLOAT));
             }
         }
 
         EXPECT_TRUE(CheckVariablesInPackingLimits(squareSize, vars));
 
         // and one scalar and packing should fail
-        vars.push_back(sh::ShaderVariable(GL_FLOAT, 0));
+        vars.push_back(sh::ShaderVariable(GL_FLOAT));
         EXPECT_FALSE(CheckVariablesInPackingLimits(squareSize, vars));
     }
 }
@@ -218,22 +229,22 @@
 
     // Test example from GLSL ES 3.0 spec chapter 11, but with structs
     std::vector<sh::ShaderVariable> vars;
-    vars.push_back(sh::ShaderVariable(GL_NONE, 0));
+    vars.push_back(sh::ShaderVariable(GL_NONE));
 
     sh::ShaderVariable &parentStruct = vars[0];
-    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC4, 0));
-    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0));
+    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC4));
+    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
 
-    parentStruct.fields.push_back(sh::ShaderVariable(GL_NONE, 0));
+    parentStruct.fields.push_back(sh::ShaderVariable(GL_NONE));
     sh::ShaderVariable &innerStruct = parentStruct.fields.back();
-    innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3, 0));
+    innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_MAT3));
     innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 6));
     innerStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 4));
 
-    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2, 0));
+    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT_VEC2));
     parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 3));
     parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 2));
-    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT, 0));
+    parentStruct.fields.push_back(sh::ShaderVariable(GL_FLOAT));
 
     EXPECT_TRUE(CheckVariablesInPackingLimits(kMaxRows, vars));
 }