Commit 2be2d5ae by Olli Etuaho Committed by Commit Bot

Clean up unary node creation

When createUnaryNode() is called, the child node is guaranteed to be non-null. This enables simplifying it. BUG=angleproject:1490 TEST=angle_unittests Change-Id: Ib1d021bbbeab99a6bf1b1be470181e9efbe301c6 Reviewed-on: https://chromium-review.googlesource.com/433467Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 1ecd14b8
......@@ -3658,13 +3658,9 @@ TIntermCase *TParseContext::addDefault(const TSourceLoc &loc)
TIntermTyped *TParseContext::createUnaryMath(TOperator op,
TIntermTyped *child,
const TSourceLoc &loc,
const TType *funcReturnType)
const TSourceLoc &loc)
{
if (child == nullptr)
{
return nullptr;
}
ASSERT(child != nullptr);
switch (op)
{
......@@ -3672,6 +3668,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
if (child->getBasicType() != EbtBool || child->isMatrix() || child->isArray() ||
child->isVector())
{
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return nullptr;
}
break;
......@@ -3679,6 +3676,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
if ((child->getBasicType() != EbtInt && child->getBasicType() != EbtUInt) ||
child->isMatrix() || child->isArray())
{
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return nullptr;
}
break;
......@@ -3691,6 +3689,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
if (child->getBasicType() == EbtStruct || child->getBasicType() == EbtBool ||
child->isArray() || IsOpaqueType(child->getBasicType()))
{
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return nullptr;
}
// Operators for built-ins are already type checked against their prototype.
......@@ -3710,10 +3709,9 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
TIntermTyped *TParseContext::addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc)
{
TIntermTyped *node = createUnaryMath(op, child, loc, nullptr);
TIntermTyped *node = createUnaryMath(op, child, loc);
if (node == nullptr)
{
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return child;
}
return node;
......@@ -4409,27 +4407,13 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall,
op = fnCandidate->getBuiltInOp();
if (builtIn && op != EOpNull)
{
//
// A function call mapped to a built-in operation.
//
if (fnCandidate->getParamCount() == 1)
{
//
// Treat it like a built-in unary operator.
//
TIntermNode *unaryParamNode = argumentsNode->getSequence()->front();
callNode = createUnaryMath(op, unaryParamNode->getAsTyped(), loc,
&fnCandidate->getReturnType());
if (callNode == nullptr)
{
std::stringstream reasonStream;
reasonStream
<< "wrong operand type for built in unary function: "
<< static_cast<TIntermTyped *>(argumentsNode)->getCompleteString();
std::string reason = reasonStream.str();
error(argumentsNode->getLine(), reason.c_str(), "Internal Error");
return TIntermTyped::CreateZero(TType(EbtFloat, EbpMedium, EvqConst));
}
callNode = createUnaryMath(op, unaryParamNode->getAsTyped(), loc);
ASSERT(callNode != nullptr);
}
else
{
......
......@@ -406,13 +406,9 @@ class TParseContext : angle::NonCopyable
TIntermTyped *left,
TIntermTyped *right,
const TSourceLoc &loc);
// The funcReturnType parameter is expected to be non-null when the operation is a built-in
// function.
// It is expected to be null for other unary operators.
TIntermTyped *createUnaryMath(TOperator op,
TIntermTyped *child,
const TSourceLoc &loc,
const TType *funcReturnType);
const TSourceLoc &loc);
// Return true if the checks pass
bool binaryOpCommonCheck(TOperator op,
......
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