Clean up ValidateMaxParameters

It doesn't need to use a traverser, since all function definitions can
be found simply by iterating over the children of the root node.

BUG=angleproject:2040
TEST=angle_unittests

Change-Id: I18a98eff9710485c0cdce73e7fffe124f7d7afb2
Reviewed-on: https://chromium-review.googlesource.com/508791
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index 1bdb06b..4ea6e75 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -852,7 +852,7 @@
     return (mDiagnostics.numErrors() == 0);
 }
 
-bool TCompiler::limitExpressionComplexity(TIntermNode *root)
+bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
 {
     TMaxDepthTraverser traverser(maxExpressionComplexity + 1);
     root->traverse(&traverser);
@@ -863,7 +863,7 @@
         return false;
     }
 
-    if (!ValidateMaxParameters::validate(root, maxFunctionParameters))
+    if (!ValidateMaxParameters(root, maxFunctionParameters))
     {
         mDiagnostics.globalError("Function has too many parameters.");
         return false;
diff --git a/src/compiler/translator/Compiler.h b/src/compiler/translator/Compiler.h
index 2614199..95544c9 100644
--- a/src/compiler/translator/Compiler.h
+++ b/src/compiler/translator/Compiler.h
@@ -156,7 +156,7 @@
     // This function should only be applied to vertex shaders.
     void initializeGLPosition(TIntermBlock *root);
     // Return true if the maximum expression complexity is below the limit.
-    bool limitExpressionComplexity(TIntermNode *root);
+    bool limitExpressionComplexity(TIntermBlock *root);
     // Get built-in extensions with default behavior.
     const TExtensionBehavior &getExtensionBehavior() const;
     const char *getSourcePath() const;
diff --git a/src/compiler/translator/ValidateMaxParameters.cpp b/src/compiler/translator/ValidateMaxParameters.cpp
index 2d0b3eb..9dccbf4 100644
--- a/src/compiler/translator/ValidateMaxParameters.cpp
+++ b/src/compiler/translator/ValidateMaxParameters.cpp
@@ -7,34 +7,23 @@
 
 #include "compiler/translator/ValidateMaxParameters.h"
 
+#include "compiler/translator/IntermNode.h"
+
 namespace sh
 {
 
-ValidateMaxParameters::ValidateMaxParameters(unsigned int maxParameters)
-    : TIntermTraverser(true, false, false), mMaxParameters(maxParameters), mValid(true)
+bool ValidateMaxParameters(TIntermBlock *root, unsigned int maxParameters)
 {
-}
-
-bool ValidateMaxParameters::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node)
-{
-    if (!mValid)
+    for (TIntermNode *node : *root->getSequence())
     {
-        return false;
+        TIntermFunctionDefinition *definition = node->getAsFunctionDefinition();
+        if (definition != nullptr &&
+            definition->getFunctionPrototype()->getSequence()->size() > maxParameters)
+        {
+            return false;
+        }
     }
-
-    if (node->getFunctionPrototype()->getSequence()->size() > mMaxParameters)
-    {
-        mValid = false;
-    }
-
-    return mValid;
-}
-
-bool ValidateMaxParameters::validate(TIntermNode *root, unsigned int maxParameters)
-{
-    ValidateMaxParameters argsTraverser(maxParameters);
-    root->traverse(&argsTraverser);
-    return argsTraverser.mValid;
+    return true;
 }
 
 }  // namespace sh
diff --git a/src/compiler/translator/ValidateMaxParameters.h b/src/compiler/translator/ValidateMaxParameters.h
index 7c73390..dec7597 100644
--- a/src/compiler/translator/ValidateMaxParameters.h
+++ b/src/compiler/translator/ValidateMaxParameters.h
@@ -8,26 +8,13 @@
 #ifndef COMPILER_TRANSLATOR_VALIDATEMAXPARAMETERS_H_
 #define COMPILER_TRANSLATOR_VALIDATEMAXPARAMETERS_H_
 
-#include "compiler/translator/IntermNode.h"
-
 namespace sh
 {
 
-class ValidateMaxParameters : public TIntermTraverser
-{
-  public:
-    // Returns false if maxParameters is exceeded.
-    static bool validate(TIntermNode *root, unsigned int maxParameters);
+class TIntermBlock;
 
-  protected:
-    bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override;
-
-  private:
-    ValidateMaxParameters(unsigned int maxParameters);
-
-    unsigned int mMaxParameters;
-    bool mValid;
-};
+// Return true if valid.
+bool ValidateMaxParameters(TIntermBlock *root, unsigned int maxParameters);
 
 }  // namespace sh