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) ...@@ -3658,13 +3658,9 @@ TIntermCase *TParseContext::addDefault(const TSourceLoc &loc)
TIntermTyped *TParseContext::createUnaryMath(TOperator op, TIntermTyped *TParseContext::createUnaryMath(TOperator op,
TIntermTyped *child, TIntermTyped *child,
const TSourceLoc &loc, const TSourceLoc &loc)
const TType *funcReturnType)
{ {
if (child == nullptr) ASSERT(child != nullptr);
{
return nullptr;
}
switch (op) switch (op)
{ {
...@@ -3672,6 +3668,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op, ...@@ -3672,6 +3668,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
if (child->getBasicType() != EbtBool || child->isMatrix() || child->isArray() || if (child->getBasicType() != EbtBool || child->isMatrix() || child->isArray() ||
child->isVector()) child->isVector())
{ {
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return nullptr; return nullptr;
} }
break; break;
...@@ -3679,6 +3676,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op, ...@@ -3679,6 +3676,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
if ((child->getBasicType() != EbtInt && child->getBasicType() != EbtUInt) || if ((child->getBasicType() != EbtInt && child->getBasicType() != EbtUInt) ||
child->isMatrix() || child->isArray()) child->isMatrix() || child->isArray())
{ {
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return nullptr; return nullptr;
} }
break; break;
...@@ -3691,6 +3689,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op, ...@@ -3691,6 +3689,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
if (child->getBasicType() == EbtStruct || child->getBasicType() == EbtBool || if (child->getBasicType() == EbtStruct || child->getBasicType() == EbtBool ||
child->isArray() || IsOpaqueType(child->getBasicType())) child->isArray() || IsOpaqueType(child->getBasicType()))
{ {
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return nullptr; return nullptr;
} }
// Operators for built-ins are already type checked against their prototype. // Operators for built-ins are already type checked against their prototype.
...@@ -3710,10 +3709,9 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op, ...@@ -3710,10 +3709,9 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
TIntermTyped *TParseContext::addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc) 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) if (node == nullptr)
{ {
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return child; return child;
} }
return node; return node;
...@@ -4409,27 +4407,13 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, ...@@ -4409,27 +4407,13 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall,
op = fnCandidate->getBuiltInOp(); op = fnCandidate->getBuiltInOp();
if (builtIn && op != EOpNull) if (builtIn && op != EOpNull)
{ {
//
// A function call mapped to a built-in operation. // A function call mapped to a built-in operation.
//
if (fnCandidate->getParamCount() == 1) if (fnCandidate->getParamCount() == 1)
{ {
//
// Treat it like a built-in unary operator. // Treat it like a built-in unary operator.
//
TIntermNode *unaryParamNode = argumentsNode->getSequence()->front(); TIntermNode *unaryParamNode = argumentsNode->getSequence()->front();
callNode = createUnaryMath(op, unaryParamNode->getAsTyped(), loc, callNode = createUnaryMath(op, unaryParamNode->getAsTyped(), loc);
&fnCandidate->getReturnType()); ASSERT(callNode != nullptr);
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));
}
} }
else else
{ {
......
...@@ -406,13 +406,9 @@ class TParseContext : angle::NonCopyable ...@@ -406,13 +406,9 @@ class TParseContext : angle::NonCopyable
TIntermTyped *left, TIntermTyped *left,
TIntermTyped *right, TIntermTyped *right,
const TSourceLoc &loc); 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 *createUnaryMath(TOperator op,
TIntermTyped *child, TIntermTyped *child,
const TSourceLoc &loc, const TSourceLoc &loc);
const TType *funcReturnType);
// Return true if the checks pass // Return true if the checks pass
bool binaryOpCommonCheck(TOperator op, 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