Commit dca3e796 by Olli Etuaho

Refactor unary math operator handling to clarify responsibilities

Shuffle the code around so that each part has a clear responsibility: IntermUnary::promote is responsible for setting the return type of the node, Intermediate::addUnaryMath is responsible for creating the node object, and ParseContext::createUnaryMath is responsible for validating the operand type. This removes duplicated bool type check for logical not. BUG=angleproject:952 TEST=angle_unittests, WebGL conformance tests Change-Id: I9f5a0abb6434ad2730441ea9199ec3f5382ebcda Reviewed-on: https://chromium-review.googlesource.com/262415Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 7f67b030
...@@ -328,55 +328,34 @@ bool TIntermOperator::isConstructor() const ...@@ -328,55 +328,34 @@ bool TIntermOperator::isConstructor() const
// Make sure the type of a unary operator is appropriate for its // Make sure the type of a unary operator is appropriate for its
// combination of operation and operand type. // combination of operation and operand type.
// //
// Returns false in nothing makes sense. void TIntermUnary::promote()
//
bool TIntermUnary::promote(TInfoSink &)
{ {
switch (mOp) switch (mOp)
{ {
case EOpLogicalNot: // Some built-ins get the type of their return value assigned elsewhere.
if (mOperand->getBasicType() != EbtBool)
return false;
break;
// bit-wise not is already checked
case EOpBitwiseNot:
break;
case EOpNegative:
case EOpPositive:
case EOpPostIncrement:
case EOpPostDecrement:
case EOpPreIncrement:
case EOpPreDecrement:
if (mOperand->getBasicType() == EbtBool)
return false;
break;
// Operators for built-ins are already type checked against their prototype
// and some of them get the type of their return value assigned elsewhere.
case EOpAny: case EOpAny:
case EOpAll: case EOpAll:
case EOpVectorLogicalNot: case EOpVectorLogicalNot:
break;
case EOpFloatBitsToInt:
case EOpFloatBitsToUint:
case EOpIntBitsToFloat: case EOpIntBitsToFloat:
case EOpUintBitsToFloat: case EOpUintBitsToFloat:
case EOpPackSnorm2x16:
case EOpPackUnorm2x16:
case EOpPackHalf2x16:
case EOpUnpackSnorm2x16: case EOpUnpackSnorm2x16:
case EOpUnpackUnorm2x16: case EOpUnpackUnorm2x16:
mType.setPrecision(EbpHigh);
break;
case EOpUnpackHalf2x16: case EOpUnpackHalf2x16:
return true; mType.setPrecision(EbpMedium);
case EOpAbs:
case EOpSign:
break; break;
default: default:
if (mOperand->getBasicType() != EbtFloat) setType(mOperand->getType());
return false;
} }
setType(mOperand->getType());
mType.setQualifier(EvqTemporary); mType.setQualifier(EvqTemporary);
return true;
} }
// //
......
...@@ -383,7 +383,7 @@ class TIntermUnary : public TIntermOperator ...@@ -383,7 +383,7 @@ class TIntermUnary : public TIntermOperator
void setOperand(TIntermTyped *operand) { mOperand = operand; } void setOperand(TIntermTyped *operand) { mOperand = operand; }
TIntermTyped *getOperand() { return mOperand; } TIntermTyped *getOperand() { return mOperand; }
bool promote(TInfoSink &); void promote();
void setUseEmulatedFunction() { mUseEmulatedFunction = true; } void setUseEmulatedFunction() { mUseEmulatedFunction = true; }
bool getUseEmulatedFunction() { return mUseEmulatedFunction; } bool getUseEmulatedFunction() { return mUseEmulatedFunction; }
......
...@@ -139,29 +139,7 @@ TIntermTyped *TIntermediate::addUnaryMath( ...@@ -139,29 +139,7 @@ TIntermTyped *TIntermediate::addUnaryMath(
TIntermUnary *node = new TIntermUnary(op); TIntermUnary *node = new TIntermUnary(op);
node->setLine(line); node->setLine(line);
node->setOperand(child); node->setOperand(child);
node->promote();
if (!node->promote(mInfoSink))
return 0;
switch (op)
{
case EOpFloatBitsToInt:
case EOpFloatBitsToUint:
case EOpIntBitsToFloat:
case EOpUintBitsToFloat:
case EOpPackSnorm2x16:
case EOpPackUnorm2x16:
case EOpPackHalf2x16:
case EOpUnpackSnorm2x16:
case EOpUnpackUnorm2x16:
node->getTypePointer()->setPrecision(EbpHigh);
break;
case EOpUnpackHalf2x16:
node->getTypePointer()->setPrecision(EbpMedium);
break;
default:
break;
}
if (childTempConstant) if (childTempConstant)
{ {
......
...@@ -2730,10 +2730,12 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op, TIntermTyped *child, ...@@ -2730,10 +2730,12 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op, TIntermTyped *child,
case EOpNegative: case EOpNegative:
case EOpPositive: case EOpPositive:
if (child->getBasicType() == EbtStruct || if (child->getBasicType() == EbtStruct ||
child->getBasicType() == EbtBool ||
child->isArray()) child->isArray())
{ {
return nullptr; return nullptr;
} }
// Operators for built-ins are already type checked against their prototype.
default: default:
break; break;
} }
......
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