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)
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 @@ bool TCompiler::limitExpressionComplexity(TIntermNode *root)
return false;
}
if (!ValidateMaxParameters::validate(root, maxFunctionParameters))
if (!ValidateMaxParameters(root, maxFunctionParameters))
{
mDiagnostics.globalError("Function has too many parameters.");
return false;
......
......@@ -156,7 +156,7 @@ class TCompiler : public TShHandleBase
// 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;
......
......@@ -7,34 +7,23 @@
#include "compiler/translator/ValidateMaxParameters.h"
namespace sh
{
#include "compiler/translator/IntermNode.h"
ValidateMaxParameters::ValidateMaxParameters(unsigned int maxParameters)
: TIntermTraverser(true, false, false), mMaxParameters(maxParameters), mValid(true)
namespace sh
{
}
bool ValidateMaxParameters::visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node)
bool ValidateMaxParameters(TIntermBlock *root, unsigned int maxParameters)
{
if (!mValid)
for (TIntermNode *node : *root->getSequence())
{
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
......@@ -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);
protected:
bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override;
private:
ValidateMaxParameters(unsigned int maxParameters);
class TIntermBlock;
unsigned int mMaxParameters;
bool mValid;
};
// Return true if valid.
bool ValidateMaxParameters(TIntermBlock *root, unsigned int maxParameters);
} // 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