Move CollectVariables to sh namespace.

BUG=angle:466

Change-Id: I903ea840e333dfeb44f242a1759aed39974d0510
Reviewed-on: https://chromium-review.googlesource.com/213505
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index bcb431a..368cd2a 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -502,18 +502,18 @@
 
 void TCompiler::collectVariables(TIntermNode* root)
 {
-    CollectVariables collect(&attributes,
-                             &outputVariables,
-                             &uniforms,
-                             &varyings,
-                             &interfaceBlocks,
-                             hashFunction);
+    sh::CollectVariables collect(&attributes,
+                                 &outputVariables,
+                                 &uniforms,
+                                 &varyings,
+                                 &interfaceBlocks,
+                                 hashFunction);
     root->traverse(&collect);
 
     // For backwards compatiblity with ShGetVariableInfo, expand struct
     // uniforms and varyings into separate variables for each field.
-    ExpandVariables(uniforms, &expandedUniforms);
-    ExpandVariables(varyings, &expandedVaryings);
+    sh::ExpandVariables(uniforms, &expandedUniforms);
+    sh::ExpandVariables(varyings, &expandedVaryings);
 }
 
 bool TCompiler::enforcePackingRestrictions()
diff --git a/src/compiler/translator/VariableInfo.cpp b/src/compiler/translator/VariableInfo.cpp
index d58770f..f26c156 100644
--- a/src/compiler/translator/VariableInfo.cpp
+++ b/src/compiler/translator/VariableInfo.cpp
@@ -9,6 +9,9 @@
 #include "compiler/translator/util.h"
 #include "common/utilities.h"
 
+namespace sh
+{
+
 namespace
 {
 
@@ -24,28 +27,28 @@
     }
 }
 
-sh::BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage)
+BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage)
 {
     switch (blockStorage)
     {
-      case EbsPacked:         return sh::BLOCKLAYOUT_PACKED;
-      case EbsShared:         return sh::BLOCKLAYOUT_SHARED;
-      case EbsStd140:         return sh::BLOCKLAYOUT_STANDARD;
-      default: UNREACHABLE(); return sh::BLOCKLAYOUT_SHARED;
+      case EbsPacked:         return BLOCKLAYOUT_PACKED;
+      case EbsShared:         return BLOCKLAYOUT_SHARED;
+      case EbsStd140:         return BLOCKLAYOUT_STANDARD;
+      default: UNREACHABLE(); return BLOCKLAYOUT_SHARED;
     }
 }
 
-void ExpandUserDefinedVariable(const sh::ShaderVariable &variable,
+void ExpandUserDefinedVariable(const ShaderVariable &variable,
                                const std::string &name,
                                const std::string &mappedName,
                                bool markStaticUse,
-                               std::vector<sh::ShaderVariable> *expanded);
+                               std::vector<ShaderVariable> *expanded);
 
-void ExpandVariable(const sh::ShaderVariable &variable,
+void ExpandVariable(const ShaderVariable &variable,
                     const std::string &name,
                     const std::string &mappedName,
                     bool markStaticUse,
-                    std::vector<sh::ShaderVariable> *expanded)
+                    std::vector<ShaderVariable> *expanded)
 {
     if (variable.isStruct())
     {
@@ -53,8 +56,8 @@
         {
             for (size_t elementIndex = 0; elementIndex < variable.elementCount(); elementIndex++)
             {
-                std::string lname = name + ArrayString(elementIndex);
-                std::string lmappedName = mappedName + ArrayString(elementIndex);
+                std::string lname = name + ::ArrayString(elementIndex);
+                std::string lmappedName = mappedName + ::ArrayString(elementIndex);
                 ExpandUserDefinedVariable(variable, lname, lmappedName, markStaticUse, expanded);
             }
         }
@@ -65,7 +68,7 @@
     }
     else
     {
-        sh::ShaderVariable expandedVar = variable;
+        ShaderVariable expandedVar = variable;
 
         expandedVar.name = name;
         expandedVar.mappedName = mappedName;
@@ -86,19 +89,19 @@
     }
 }
 
-void ExpandUserDefinedVariable(const sh::ShaderVariable &variable,
+void ExpandUserDefinedVariable(const ShaderVariable &variable,
                                const std::string &name,
                                const std::string &mappedName,
                                bool markStaticUse,
-                               std::vector<sh::ShaderVariable> *expanded)
+                               std::vector<ShaderVariable> *expanded)
 {
     ASSERT(variable.isStruct());
 
-    const std::vector<sh::ShaderVariable> &fields = variable.fields;
+    const std::vector<ShaderVariable> &fields = variable.fields;
 
     for (size_t fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++)
     {
-        const sh::ShaderVariable &field = fields[fieldIndex];
+        const ShaderVariable &field = fields[fieldIndex];
         ExpandVariable(field,
                        name + "." + field.name,
                        mappedName + "." + field.mappedName,
@@ -149,10 +152,10 @@
 void CollectVariables::visitSymbol(TIntermSymbol *symbol)
 {
     ASSERT(symbol != NULL);
-    sh::ShaderVariable *var = NULL;
+    ShaderVariable *var = NULL;
     const TString &symbolName = symbol->getSymbol();
 
-    if (sh::IsVarying(symbol->getQualifier()))
+    if (IsVarying(symbol->getQualifier()))
     {
         var = FindVariable(symbolName, mVaryings);
     }
@@ -176,7 +179,7 @@
                 const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock();
                 if (interfaceBlock)
                 {
-                    sh::InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
+                    InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
                     ASSERT(namedBlock);
                     var = FindVariable(symbolName, &namedBlock->fields);
 
@@ -196,7 +199,7 @@
           case EvqFragCoord:
             if (!mFragCoordAdded)
             {
-                sh::Varying info;
+                Varying info;
                 info.name = "gl_FragCoord";
                 info.mappedName = "gl_FragCoord";
                 info.type = GL_FLOAT_VEC4;
@@ -210,7 +213,7 @@
           case EvqFrontFacing:
             if (!mFrontFacingAdded)
             {
-                sh::Varying info;
+                Varying info;
                 info.name = "gl_FrontFacing";
                 info.mappedName = "gl_FrontFacing";
                 info.type = GL_BOOL;
@@ -224,7 +227,7 @@
           case EvqPointCoord:
             if (!mPointCoordAdded)
             {
-                sh::Varying info;
+                Varying info;
                 info.name = "gl_PointCoord";
                 info.mappedName = "gl_PointCoord";
                 info.type = GL_FLOAT_VEC2;
@@ -245,7 +248,7 @@
     }
 }
 
-class NameHashingTraverser : public sh::GetVariableTraverser
+class NameHashingTraverser : public GetVariableTraverser
 {
   public:
     NameHashingTraverser(ShHashFunction64 hashFunction)
@@ -255,7 +258,7 @@
   private:
     DISALLOW_COPY_AND_ASSIGN(NameHashingTraverser);
 
-    virtual void visitVariable(sh::ShaderVariable *variable)
+    virtual void visitVariable(ShaderVariable *variable)
     {
         TString stringName = TString(variable->name.c_str());
         variable->mappedName = TIntermTraverser::hash(stringName, mHashFunction).c_str();
@@ -267,16 +270,16 @@
 // Attributes, which cannot have struct fields, are a special case
 template <>
 void CollectVariables::visitVariable(const TIntermSymbol *variable,
-                                     std::vector<sh::Attribute> *infoList) const
+                                     std::vector<Attribute> *infoList) const
 {
     ASSERT(variable);
     const TType &type = variable->getType();
     ASSERT(!type.getStruct());
 
-    sh::Attribute attribute;
+    Attribute attribute;
 
-    attribute.type = sh::GLVariableType(type);
-    attribute.precision = sh::GLVariablePrecision(type);
+    attribute.type = GLVariableType(type);
+    attribute.precision = GLVariablePrecision(type);
     attribute.name = variable->getSymbol().c_str();
     attribute.arraySize = static_cast<unsigned int>(type.getArraySize());
     attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str();
@@ -287,9 +290,9 @@
 
 template <>
 void CollectVariables::visitVariable(const TIntermSymbol *variable,
-                                     std::vector<sh::InterfaceBlock> *infoList) const
+                                     std::vector<InterfaceBlock> *infoList) const
 {
-    sh::InterfaceBlock interfaceBlock;
+    InterfaceBlock interfaceBlock;
     const TInterfaceBlock *blockType = variable->getType().getInterfaceBlock();
     ASSERT(blockType);
 
@@ -309,7 +312,7 @@
         const TString &fullFieldName = InterfaceBlockFieldName(*blockType, field);
         const TType &fieldType = *field.type();
 
-        sh::GetVariableTraverser traverser;
+        GetVariableTraverser traverser;
         traverser.traverse(fieldType, fullFieldName, &interfaceBlock.fields);
 
         interfaceBlock.fields.back().isRowMajorLayout = (fieldType.getLayoutQualifier().matrixPacking == EmpRowMajor);
@@ -364,7 +367,7 @@
             }
             else if (qualifier == EvqAttribute || qualifier == EvqVertexIn ||
                      qualifier == EvqFragmentOut || qualifier == EvqUniform ||
-                     sh::IsVarying(qualifier))
+                     IsVarying(qualifier))
             {
                 switch (qualifier)
                 {
@@ -405,7 +408,7 @@
         ASSERT(constantUnion);
 
         const TInterfaceBlock *interfaceBlock = blockNode->getType().getInterfaceBlock();
-        sh::InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
+        InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
         ASSERT(namedBlock);
         namedBlock->staticUse = true;
 
@@ -420,14 +423,16 @@
 
 template <typename VarT>
 void ExpandVariables(const std::vector<VarT> &compact,
-                     std::vector<sh::ShaderVariable> *expanded)
+                     std::vector<ShaderVariable> *expanded)
 {
     for (size_t variableIndex = 0; variableIndex < compact.size(); variableIndex++)
     {
-        const sh::ShaderVariable &variable = compact[variableIndex];
+        const ShaderVariable &variable = compact[variableIndex];
         ExpandVariable(variable, variable.name, variable.mappedName, variable.staticUse, expanded);
     }
 }
 
-template void ExpandVariables(const std::vector<sh::Uniform> &, std::vector<sh::ShaderVariable> *);
-template void ExpandVariables(const std::vector<sh::Varying> &, std::vector<sh::ShaderVariable> *);
+template void ExpandVariables(const std::vector<Uniform> &, std::vector<ShaderVariable> *);
+template void ExpandVariables(const std::vector<Varying> &, std::vector<ShaderVariable> *);
+
+}
diff --git a/src/compiler/translator/VariableInfo.h b/src/compiler/translator/VariableInfo.h
index b4b1886..5ac4c46 100644
--- a/src/compiler/translator/VariableInfo.h
+++ b/src/compiler/translator/VariableInfo.h
@@ -11,15 +11,18 @@
 
 #include "compiler/translator/IntermNode.h"
 
+namespace sh
+{
+
 // Traverses intermediate tree to collect all attributes, uniforms, varyings.
 class CollectVariables : public TIntermTraverser
 {
   public:
-    CollectVariables(std::vector<sh::Attribute> *attribs,
-                     std::vector<sh::Attribute> *outputVariables,
-                     std::vector<sh::Uniform> *uniforms,
-                     std::vector<sh::Varying> *varyings,
-                     std::vector<sh::InterfaceBlock> *interfaceBlocks,
+    CollectVariables(std::vector<Attribute> *attribs,
+                     std::vector<Attribute> *outputVariables,
+                     std::vector<Uniform> *uniforms,
+                     std::vector<Varying> *varyings,
+                     std::vector<InterfaceBlock> *interfaceBlocks,
                      ShHashFunction64 hashFunction);
 
     virtual void visitSymbol(TIntermSymbol *symbol);
@@ -33,13 +36,13 @@
     template <typename VarT>
     void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const;
 
-    std::vector<sh::Attribute> *mAttribs;
-    std::vector<sh::Attribute> *mOutputVariables;
-    std::vector<sh::Uniform> *mUniforms;
-    std::vector<sh::Varying> *mVaryings;
-    std::vector<sh::InterfaceBlock> *mInterfaceBlocks;
+    std::vector<Attribute> *mAttribs;
+    std::vector<Attribute> *mOutputVariables;
+    std::vector<Uniform> *mUniforms;
+    std::vector<Varying> *mVaryings;
+    std::vector<InterfaceBlock> *mInterfaceBlocks;
 
-    std::map<std::string, sh::InterfaceBlockField *> mInterfaceBlockFields;
+    std::map<std::string, InterfaceBlockField *> mInterfaceBlockFields;
 
     bool mPointCoordAdded;
     bool mFrontFacingAdded;
@@ -51,6 +54,8 @@
 // Expand struct variables to flattened lists of split variables
 template <typename VarT>
 void ExpandVariables(const std::vector<VarT> &compact,
-                     std::vector<sh::ShaderVariable> *expanded);
+                     std::vector<ShaderVariable> *expanded);
+
+}
 
 #endif  // COMPILER_VARIABLE_INFO_H_