Commit 69c11b5d by Olli Etuaho

Move validation from Intermediate::addUnaryMath to ParseContext

Intermediate should only have logic for creating node objects, validation of parameter types belongs in ParseContext. BUG=angleproject:952 TEST=angle_unittests, WebGL conformance tests Change-Id: Ie90697641fabb2a837ccc4571a93616d63ea64e6 Reviewed-on: https://chromium-review.googlesource.com/262414Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent 7a26a1ad
......@@ -127,52 +127,8 @@ TIntermTyped *TIntermediate::addIndex(
// Returns the added node.
//
TIntermTyped *TIntermediate::addUnaryMath(
TOperator op, TIntermNode *childNode, const TSourceLoc &line)
TOperator op, TIntermTyped *child, const TSourceLoc &line)
{
TIntermUnary *node;
TIntermTyped *child = childNode->getAsTyped();
if (child == NULL)
{
mInfoSink.info.message(EPrefixInternalError, line,
"Bad type in AddUnaryMath");
return NULL;
}
switch (op)
{
case EOpLogicalNot:
if (child->getBasicType() != EbtBool ||
child->isMatrix() ||
child->isArray() ||
child->isVector())
{
return NULL;
}
break;
case EOpBitwiseNot:
if ((child->getBasicType() != EbtInt && child->getBasicType() != EbtUInt) ||
child->isMatrix() ||
child->isArray())
{
return NULL;
}
break;
case EOpPostIncrement:
case EOpPreIncrement:
case EOpPostDecrement:
case EOpPreDecrement:
case EOpNegative:
case EOpPositive:
if (child->getBasicType() == EbtStruct ||
child->isArray())
{
return NULL;
}
default:
break;
}
TIntermConstantUnion *childTempConstant = 0;
if (child->getAsConstantUnion())
childTempConstant = child->getAsConstantUnion();
......@@ -180,7 +136,7 @@ TIntermTyped *TIntermediate::addUnaryMath(
//
// Make a new node for the operator.
//
node = new TIntermUnary(op);
TIntermUnary *node = new TIntermUnary(op);
node->setLine(line);
node->setOperand(child);
......
......@@ -35,7 +35,7 @@ class TIntermediate
TIntermTyped *addIndex(
TOperator op, TIntermTyped *base, TIntermTyped *index, const TSourceLoc &);
TIntermTyped *addUnaryMath(
TOperator op, TIntermNode *child, const TSourceLoc &);
TOperator op, TIntermTyped *child, const TSourceLoc &line);
TIntermAggregate *growAggregate(
TIntermNode *left, TIntermNode *right, const TSourceLoc &);
TIntermAggregate *makeAggregate(TIntermNode *node, const TSourceLoc &);
......
......@@ -2697,10 +2697,54 @@ TIntermCase *TParseContext::addDefault(const TSourceLoc &loc)
return node;
}
TIntermTyped *TParseContext::createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
{
if (child == nullptr)
{
return nullptr;
}
switch (op)
{
case EOpLogicalNot:
if (child->getBasicType() != EbtBool ||
child->isMatrix() ||
child->isArray() ||
child->isVector())
{
return nullptr;
}
break;
case EOpBitwiseNot:
if ((child->getBasicType() != EbtInt && child->getBasicType() != EbtUInt) ||
child->isMatrix() ||
child->isArray())
{
return nullptr;
}
break;
case EOpPostIncrement:
case EOpPreIncrement:
case EOpPostDecrement:
case EOpPreDecrement:
case EOpNegative:
case EOpPositive:
if (child->getBasicType() == EbtStruct ||
child->isArray())
{
return nullptr;
}
default:
break;
}
return intermediate.addUnaryMath(op, child, loc);
}
TIntermTyped *TParseContext::addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
{
TIntermTyped *node = intermediate.addUnaryMath(op, child, loc);
if (node == 0)
TIntermTyped *node = createUnaryMath(op, child, loc);
if (node == nullptr)
{
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
recover();
......@@ -3048,7 +3092,7 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
//
// Treat it like a built-in unary operator.
//
callNode = intermediate.addUnaryMath(op, node, loc);
callNode = createUnaryMath(op, node->getAsTyped(), loc);
if (callNode == nullptr)
{
std::stringstream extraInfoStream;
......@@ -3063,12 +3107,12 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
if (returnType.getBasicType() == EbtBool)
{
// Bool types should not have precision, so we'll override any precision
// that might have been set by addUnaryMath.
// that might have been set by createUnaryMath.
callNode->setType(returnType);
}
else
{
// addUnaryMath has set the precision of the node based on the operand.
// createUnaryMath has set the precision of the node based on the operand.
callNode->setTypePreservePrecision(returnType);
}
}
......
......@@ -191,6 +191,7 @@ struct TParseContext {
const TSourceLoc &loc);
TIntermTyped *createAssign(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc);
TIntermTyped *createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
// Return true if the checks pass
bool binaryOpCommonCheck(TOperator op, TIntermTyped *left, TIntermTyped *right,
......
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