Commit b427920e by Olli Etuaho Committed by Commit Bot

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/508791Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent bb580b1b
...@@ -852,7 +852,7 @@ bool TCompiler::validateOutputs(TIntermNode *root) ...@@ -852,7 +852,7 @@ bool TCompiler::validateOutputs(TIntermNode *root)
return (mDiagnostics.numErrors() == 0); return (mDiagnostics.numErrors() == 0);
} }
bool TCompiler::limitExpressionComplexity(TIntermNode *root) bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
{ {
TMaxDepthTraverser traverser(maxExpressionComplexity + 1); TMaxDepthTraverser traverser(maxExpressionComplexity + 1);
root->traverse(&traverser); root->traverse(&traverser);
...@@ -863,7 +863,7 @@ bool TCompiler::limitExpressionComplexity(TIntermNode *root) ...@@ -863,7 +863,7 @@ bool TCompiler::limitExpressionComplexity(TIntermNode *root)
return false; return false;
} }
if (!ValidateMaxParameters::validate(root, maxFunctionParameters)) if (!ValidateMaxParameters(root, maxFunctionParameters))
{ {
mDiagnostics.globalError("Function has too many parameters."); mDiagnostics.globalError("Function has too many parameters.");
return false; return false;
......
...@@ -156,7 +156,7 @@ class TCompiler : public TShHandleBase ...@@ -156,7 +156,7 @@ class TCompiler : public TShHandleBase
// This function should only be applied to vertex shaders. // This function should only be applied to vertex shaders.
void initializeGLPosition(TIntermBlock *root); void initializeGLPosition(TIntermBlock *root);
// Return true if the maximum expression complexity is below the limit. // 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. // Get built-in extensions with default behavior.
const TExtensionBehavior &getExtensionBehavior() const; const TExtensionBehavior &getExtensionBehavior() const;
const char *getSourcePath() const; const char *getSourcePath() const;
......
...@@ -7,34 +7,23 @@ ...@@ -7,34 +7,23 @@
#include "compiler/translator/ValidateMaxParameters.h" #include "compiler/translator/ValidateMaxParameters.h"
namespace sh #include "compiler/translator/IntermNode.h"
{
ValidateMaxParameters::ValidateMaxParameters(unsigned int maxParameters) namespace sh
: TIntermTraverser(true, false, false), mMaxParameters(maxParameters), mValid(true)
{ {
}
bool ValidateMaxParameters::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) bool ValidateMaxParameters(TIntermBlock *root, unsigned int maxParameters)
{ {
if (!mValid) for (TIntermNode *node : *root->getSequence())
{ {
return false; TIntermFunctionDefinition *definition = node->getAsFunctionDefinition();
if (definition != nullptr &&
definition->getFunctionPrototype()->getSequence()->size() > maxParameters)
{
return false;
}
} }
return true;
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;
} }
} // namespace sh } // namespace sh
...@@ -8,26 +8,13 @@ ...@@ -8,26 +8,13 @@
#ifndef COMPILER_TRANSLATOR_VALIDATEMAXPARAMETERS_H_ #ifndef COMPILER_TRANSLATOR_VALIDATEMAXPARAMETERS_H_
#define COMPILER_TRANSLATOR_VALIDATEMAXPARAMETERS_H_ #define COMPILER_TRANSLATOR_VALIDATEMAXPARAMETERS_H_
#include "compiler/translator/IntermNode.h"
namespace sh namespace sh
{ {
class ValidateMaxParameters : public TIntermTraverser class TIntermBlock;
{
public:
// Returns false if maxParameters is exceeded.
static bool validate(TIntermNode *root, unsigned int maxParameters);
protected:
bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override;
private:
ValidateMaxParameters(unsigned int maxParameters);
unsigned int mMaxParameters; // Return true if valid.
bool mValid; bool ValidateMaxParameters(TIntermBlock *root, unsigned int maxParameters);
};
} // namespace sh } // namespace sh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment