Refactor TIntermBinary::promote to use the required coding style.

TRAC #23081 Signed-off-by: Geoff Lang Signed-off-by: Nicolas Capens Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2391 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 16242efc
...@@ -861,7 +861,8 @@ bool TIntermUnary::promote(TInfoSink&) ...@@ -861,7 +861,8 @@ bool TIntermUnary::promote(TInfoSink&)
bool TIntermBinary::promote(TInfoSink& infoSink) bool TIntermBinary::promote(TInfoSink& infoSink)
{ {
// This function only handles scalars, vectors, and matrices. // This function only handles scalars, vectors, and matrices.
if (left->isArray() || right->isArray()) { if (left->isArray() || right->isArray())
{
infoSink.info.message(EPrefixInternalError, "Invalid operation for arrays", getLine()); infoSink.info.message(EPrefixInternalError, "Invalid operation for arrays", getLine());
return false; return false;
} }
...@@ -883,7 +884,8 @@ bool TIntermBinary::promote(TInfoSink& infoSink) ...@@ -883,7 +884,8 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// Binary operations results in temporary variables unless both // Binary operations results in temporary variables unless both
// operands are const. // operands are const.
if (left->getQualifier() != EvqConst || right->getQualifier() != EvqConst) { if (left->getQualifier() != EvqConst || right->getQualifier() != EvqConst)
{
getTypePointer()->setQualifier(EvqTemporary); getTypePointer()->setQualifier(EvqTemporary);
} }
...@@ -892,8 +894,10 @@ bool TIntermBinary::promote(TInfoSink& infoSink) ...@@ -892,8 +894,10 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// //
// All scalars. Code after this test assumes this case is removed! // All scalars. Code after this test assumes this case is removed!
// //
if (size == 1) { if (size == 1)
switch (op) { {
switch (op)
{
// //
// Promote to conditional // Promote to conditional
// //
...@@ -913,7 +917,9 @@ bool TIntermBinary::promote(TInfoSink& infoSink) ...@@ -913,7 +917,9 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
case EOpLogicalOr: case EOpLogicalOr:
// Both operands must be of type bool. // Both operands must be of type bool.
if (left->getBasicType() != EbtBool || right->getBasicType() != EbtBool) if (left->getBasicType() != EbtBool || right->getBasicType() != EbtBool)
{
return false; return false;
}
setType(TType(EbtBool, EbpUndefined)); setType(TType(EbtBool, EbpUndefined));
break; break;
...@@ -927,7 +933,8 @@ bool TIntermBinary::promote(TInfoSink& infoSink) ...@@ -927,7 +933,8 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// The other operand could be a scalar, vector, or matrix. // The other operand could be a scalar, vector, or matrix.
// Are the sizes compatible? // Are the sizes compatible?
// //
if (left->getNominalSize() != right->getNominalSize()) { if (left->getNominalSize() != right->getNominalSize())
{
// If the nominal size of operands do not match: // If the nominal size of operands do not match:
// One of them must be scalar. // One of them must be scalar.
if (left->getNominalSize() != 1 && right->getNominalSize() != 1) if (left->getNominalSize() != 1 && right->getNominalSize() != 1)
...@@ -941,61 +948,98 @@ bool TIntermBinary::promote(TInfoSink& infoSink) ...@@ -941,61 +948,98 @@ bool TIntermBinary::promote(TInfoSink& infoSink)
// Can these two operands be combined? // Can these two operands be combined?
// //
TBasicType basicType = left->getBasicType(); TBasicType basicType = left->getBasicType();
switch (op) { switch (op)
{
case EOpMul: case EOpMul:
if (!left->isMatrix() && right->isMatrix()) { if (!left->isMatrix() && right->isMatrix())
{
if (left->isVector()) if (left->isVector())
{
op = EOpVectorTimesMatrix; op = EOpVectorTimesMatrix;
else { }
else
{
op = EOpMatrixTimesScalar; op = EOpMatrixTimesScalar;
setType(TType(basicType, higherPrecision, EvqTemporary, size, true)); setType(TType(basicType, higherPrecision, EvqTemporary, size, true));
} }
} else if (left->isMatrix() && !right->isMatrix()) { }
if (right->isVector()) { else if (left->isMatrix() && !right->isMatrix())
{
if (right->isVector())
{
op = EOpMatrixTimesVector; op = EOpMatrixTimesVector;
setType(TType(basicType, higherPrecision, EvqTemporary, size, false)); setType(TType(basicType, higherPrecision, EvqTemporary, size, false));
} else { }
else
{
op = EOpMatrixTimesScalar; op = EOpMatrixTimesScalar;
} }
} else if (left->isMatrix() && right->isMatrix()) { }
else if (left->isMatrix() && right->isMatrix())
{
op = EOpMatrixTimesMatrix; op = EOpMatrixTimesMatrix;
} else if (!left->isMatrix() && !right->isMatrix()) { }
if (left->isVector() && right->isVector()) { else if (!left->isMatrix() && !right->isMatrix())
{
if (left->isVector() && right->isVector())
{
// leave as component product // leave as component product
} else if (left->isVector() || right->isVector()) { }
else if (left->isVector() || right->isVector())
{
op = EOpVectorTimesScalar; op = EOpVectorTimesScalar;
setType(TType(basicType, higherPrecision, EvqTemporary, size, false)); setType(TType(basicType, higherPrecision, EvqTemporary, size, false));
} }
} else { }
else
{
infoSink.info.message(EPrefixInternalError, "Missing elses", getLine()); infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());
return false; return false;
} }
break; break;
case EOpMulAssign: case EOpMulAssign:
if (!left->isMatrix() && right->isMatrix()) { if (!left->isMatrix() && right->isMatrix())
{
if (left->isVector()) if (left->isVector())
{
op = EOpVectorTimesMatrixAssign; op = EOpVectorTimesMatrixAssign;
else { }
else
{
return false; return false;
} }
} else if (left->isMatrix() && !right->isMatrix()) { }
if (right->isVector()) { else if (left->isMatrix() && !right->isMatrix())
{
if (right->isVector())
{
return false; return false;
} else { }
else
{
op = EOpMatrixTimesScalarAssign; op = EOpMatrixTimesScalarAssign;
} }
} else if (left->isMatrix() && right->isMatrix()) { }
else if (left->isMatrix() && right->isMatrix())
{
op = EOpMatrixTimesMatrixAssign; op = EOpMatrixTimesMatrixAssign;
} else if (!left->isMatrix() && !right->isMatrix()) { }
if (left->isVector() && right->isVector()) { else if (!left->isMatrix() && !right->isMatrix())
{
if (left->isVector() && right->isVector())
{
// leave as component product // leave as component product
} else if (left->isVector() || right->isVector()) { }
else if (left->isVector() || right->isVector())
{
if (! left->isVector()) if (! left->isVector())
return false; return false;
op = EOpVectorTimesScalarAssign; op = EOpVectorTimesScalarAssign;
setType(TType(basicType, higherPrecision, EvqTemporary, size, false)); setType(TType(basicType, higherPrecision, EvqTemporary, size, false));
} }
} else { }
else
{
infoSink.info.message(EPrefixInternalError, "Missing elses", getLine()); infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());
return false; return false;
} }
......
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