Fix up the indentation and alignment of TIntermConstantUnion::fold to be…

Fix up the indentation and alignment of TIntermConstantUnion::fold to be consistent with the 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@2395 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 9bd22fa9
...@@ -1181,22 +1181,31 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1181,22 +1181,31 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
ConstantUnion *unionArray = getUnionArrayPointer(); ConstantUnion *unionArray = getUnionArrayPointer();
int objectSize = getType().getObjectSize(); int objectSize = getType().getObjectSize();
if (constantNode) { // binary operations if (constantNode)
{
// binary operations
TIntermConstantUnion *node = constantNode->getAsConstantUnion(); TIntermConstantUnion *node = constantNode->getAsConstantUnion();
ConstantUnion *rightUnionArray = node->getUnionArrayPointer(); ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
TType returnType = getType(); TType returnType = getType();
// for a case like float f = 1.2 + vec4(2,3,4,5); // for a case like float f = 1.2 + vec4(2,3,4,5);
if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) { if (constantNode->getType().getObjectSize() == 1 && objectSize > 1)
{
rightUnionArray = new ConstantUnion[objectSize]; rightUnionArray = new ConstantUnion[objectSize];
for (int i = 0; i < objectSize; ++i) for (int i = 0; i < objectSize; ++i)
{
rightUnionArray[i] = *node->getUnionArrayPointer(); rightUnionArray[i] = *node->getUnionArrayPointer();
}
returnType = getType(); returnType = getType();
} else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) { }
else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1)
{
// for a case like float f = vec4(2,3,4,5) + 1.2; // for a case like float f = vec4(2,3,4,5) + 1.2;
unionArray = new ConstantUnion[constantNode->getType().getObjectSize()]; unionArray = new ConstantUnion[constantNode->getType().getObjectSize()];
for (int i = 0; i < constantNode->getType().getObjectSize(); ++i) for (int i = 0; i < constantNode->getType().getObjectSize(); ++i)
{
unionArray[i] = *getUnionArrayPointer(); unionArray[i] = *getUnionArrayPointer();
}
returnType = node->getType(); returnType = node->getType();
objectSize = constantNode->getType().getObjectSize(); objectSize = constantNode->getType().getObjectSize();
} }
...@@ -1208,14 +1217,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1208,14 +1217,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
switch(op) { switch(op) {
case EOpAdd: case EOpAdd:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {
for (int i = 0; i < objectSize; i++) for (int i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] + rightUnionArray[i]; tempConstArray[i] = unionArray[i] + rightUnionArray[i];
} }
break; break;
case EOpSub: case EOpSub:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {
for (int i = 0; i < objectSize; i++) for (int i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] - rightUnionArray[i]; tempConstArray[i] = unionArray[i] - rightUnionArray[i];
} }
...@@ -1225,17 +1234,20 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1225,17 +1234,20 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EOpVectorTimesScalar: case EOpVectorTimesScalar:
case EOpMatrixTimesScalar: case EOpMatrixTimesScalar:
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 {
for (int i = 0; i < objectSize; i++) for (int i = 0; i < objectSize; i++)
tempConstArray[i] = unionArray[i] * rightUnionArray[i]; tempConstArray[i] = unionArray[i] * rightUnionArray[i];
} }
break; break;
case EOpMatrixTimesMatrix: case EOpMatrixTimesMatrix:
if (getType().getBasicType() != EbtFloat || node->getBasicType() != EbtFloat) { {
if (getType().getBasicType() != EbtFloat || node->getBasicType() != EbtFloat)
{
infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix multiply", getLine()); infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix multiply", getLine());
return 0; return 0;
} }
{// support MSVC++6.0
int cols = getCols(); int cols = getCols();
int rows = getRows(); int rows = getRows();
tempConstArray = new ConstantUnion[cols*rows]; tempConstArray = new ConstantUnion[cols*rows];
...@@ -1249,26 +1261,38 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1249,26 +1261,38 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
} }
} }
break; break;
case EOpDiv: case EOpDiv:
{
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0 for (int i = 0; i < objectSize; i++)
for (int i = 0; i < objectSize; i++) { {
switch (getType().getBasicType()) { switch (getType().getBasicType())
{
case EbtFloat: case EbtFloat:
if (rightUnionArray[i] == 0.0f) { if (rightUnionArray[i] == 0.0f)
{
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine()); infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
tempConstArray[i].setFConst(unionArray[i].getFConst() < 0 ? -FLT_MAX : FLT_MAX); tempConstArray[i].setFConst(unionArray[i].getFConst() < 0 ? -FLT_MAX : FLT_MAX);
} else }
else
{
tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst()); tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst());
}
break; break;
case EbtInt: case EbtInt:
if (rightUnionArray[i] == 0) { if (rightUnionArray[i] == 0)
{
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine()); infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
tempConstArray[i].setIConst(INT_MAX); tempConstArray[i].setIConst(INT_MAX);
} else }
else
{
tempConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst()); tempConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst());
}
break; break;
default: default:
infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine()); infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine());
return 0; return 0;
...@@ -1278,37 +1302,41 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1278,37 +1302,41 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break; break;
case EOpMatrixTimesVector: case EOpMatrixTimesVector:
if (node->getBasicType() != EbtFloat) { {
if (node->getBasicType() != EbtFloat)
{
infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix times vector", getLine()); infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix times vector", getLine());
return 0; return 0;
} }
tempConstArray = new ConstantUnion[getNominalSize()]; tempConstArray = new ConstantUnion[getNominalSize()];
{// support MSVC++6.0
for (int size = getNominalSize(), i = 0; i < size; i++) { for (int size = getNominalSize(), i = 0; i < size; i++) {
tempConstArray[i].setFConst(0.0f); tempConstArray[i].setFConst(0.0f);
for (int j = 0; j < size; j++) { for (int j = 0; j < size; j++) {
tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j*size + i].getFConst()) * rightUnionArray[j].getFConst())); tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j*size + i].getFConst()) * rightUnionArray[j].getFConst()));
} }
} }
}
tempNode = new TIntermConstantUnion(tempConstArray, node->getType()); tempNode = new TIntermConstantUnion(tempConstArray, node->getType());
tempNode->setLine(getLine()); tempNode->setLine(getLine());
return tempNode; return tempNode;
}
case EOpVectorTimesMatrix: case EOpVectorTimesMatrix:
if (getType().getBasicType() != EbtFloat) { {
if (getType().getBasicType() != EbtFloat)
{
infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for vector times matrix", getLine()); infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for vector times matrix", getLine());
return 0; return 0;
} }
tempConstArray = new ConstantUnion[getNominalSize()]; tempConstArray = new ConstantUnion[getNominalSize()];
{// support MSVC++6.0 for (int size = getNominalSize(), i = 0; i < size; i++)
for (int size = getNominalSize(), i = 0; i < size; i++) { {
tempConstArray[i].setFConst(0.0f); tempConstArray[i].setFConst(0.0f);
for (int j = 0; j < size; j++) { for (int j = 0; j < size; j++)
{
tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j].getFConst()) * rightUnionArray[i*size + j].getFConst())); tempConstArray[i].setFConst(tempConstArray[i].getFConst() + ((unionArray[j].getFConst()) * rightUnionArray[i*size + j].getFConst()));
} }
} }
...@@ -1316,28 +1344,39 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1316,28 +1344,39 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break; break;
case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently
{
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (int i = 0; i < objectSize; i++)
{
tempConstArray[i] = unionArray[i] && rightUnionArray[i]; tempConstArray[i] = unionArray[i] && rightUnionArray[i];
} }
}
break; break;
case EOpLogicalOr: // this code is written for possible future use, will not get executed currently case EOpLogicalOr: // this code is written for possible future use, will not get executed currently
{
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (int i = 0; i < objectSize; i++)
{
tempConstArray[i] = unionArray[i] || rightUnionArray[i]; tempConstArray[i] = unionArray[i] || rightUnionArray[i];
} }
}
break; break;
case EOpLogicalXor: case EOpLogicalXor:
{
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
{// support MSVC++6.0
for (int i = 0; i < objectSize; i++) for (int i = 0; i < objectSize; i++)
switch (getType().getBasicType()) { {
case EbtBool: tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break; switch (getType().getBasicType())
default: assert(false && "Default missing"); {
case EbtBool:
tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true);
break;
default:
UNREACHABLE();
break;
}
} }
} }
break; break;
...@@ -1348,12 +1387,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1348,12 +1387,14 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
tempConstArray->setBConst(*unionArray < *rightUnionArray); tempConstArray->setBConst(*unionArray < *rightUnionArray);
returnType = TType(EbtBool, EbpUndefined, EvqConst); returnType = TType(EbtBool, EbpUndefined, EvqConst);
break; break;
case EOpGreaterThan: case EOpGreaterThan:
assert(objectSize == 1); assert(objectSize == 1);
tempConstArray = new ConstantUnion[1]; tempConstArray = new ConstantUnion[1];
tempConstArray->setBConst(*unionArray > *rightUnionArray); tempConstArray->setBConst(*unionArray > *rightUnionArray);
returnType = TType(EbtBool, EbpUndefined, EvqConst); returnType = TType(EbtBool, EbpUndefined, EvqConst);
break; break;
case EOpLessThanEqual: case EOpLessThanEqual:
{ {
assert(objectSize == 1); assert(objectSize == 1);
...@@ -1364,6 +1405,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1364,6 +1405,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
returnType = TType(EbtBool, EbpUndefined, EvqConst); returnType = TType(EbtBool, EbpUndefined, EvqConst);
break; break;
} }
case EOpGreaterThanEqual: case EOpGreaterThanEqual:
{ {
assert(objectSize == 1); assert(objectSize == 1);
...@@ -1376,12 +1418,17 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1376,12 +1418,17 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
} }
case EOpEqual: case EOpEqual:
if (getType().getBasicType() == EbtStruct) { if (getType().getBasicType() == EbtStruct)
{
if (!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray)) if (!CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true; boolNodeFlag = true;
} else { }
for (int i = 0; i < objectSize; i++) { else
if (unionArray[i] != rightUnionArray[i]) { {
for (int i = 0; i < objectSize; i++)
{
if (unionArray[i] != rightUnionArray[i])
{
boolNodeFlag = true; boolNodeFlag = true;
break; // break out of for loop break; // break out of for loop
} }
...@@ -1389,10 +1436,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1389,10 +1436,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
} }
tempConstArray = new ConstantUnion[1]; tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) { if (!boolNodeFlag)
{
tempConstArray->setBConst(true); tempConstArray->setBConst(true);
} }
else { else
{
tempConstArray->setBConst(false); tempConstArray->setBConst(false);
} }
...@@ -1402,12 +1451,17 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1402,12 +1451,17 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
return tempNode; return tempNode;
case EOpNotEqual: case EOpNotEqual:
if (getType().getBasicType() == EbtStruct) { if (getType().getBasicType() == EbtStruct)
{
if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray)) if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
boolNodeFlag = true; boolNodeFlag = true;
} else { }
for (int i = 0; i < objectSize; i++) { else
if (unionArray[i] == rightUnionArray[i]) { {
for (int i = 0; i < objectSize; i++)
{
if (unionArray[i] == rightUnionArray[i])
{
boolNodeFlag = true; boolNodeFlag = true;
break; // break out of for loop break; // break out of for loop
} }
...@@ -1415,10 +1469,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1415,10 +1469,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
} }
tempConstArray = new ConstantUnion[1]; tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) { if (!boolNodeFlag)
{
tempConstArray->setBConst(true); tempConstArray->setBConst(true);
} }
else { else
{
tempConstArray->setBConst(false); tempConstArray->setBConst(false);
} }
...@@ -1435,16 +1491,21 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1435,16 +1491,21 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
tempNode->setLine(getLine()); tempNode->setLine(getLine());
return tempNode; return tempNode;
} else { }
else
{
// //
// Do unary operations // Do unary operations
// //
TIntermConstantUnion *newNode = 0; TIntermConstantUnion *newNode = 0;
ConstantUnion* tempConstArray = new ConstantUnion[objectSize]; ConstantUnion* tempConstArray = new ConstantUnion[objectSize];
for (int i = 0; i < objectSize; i++) { for (int i = 0; i < objectSize; i++)
switch(op) { {
switch(op)
{
case EOpNegative: case EOpNegative:
switch (getType().getBasicType()) { switch (getType().getBasicType())
{
case EbtFloat: tempConstArray[i].setFConst(-unionArray[i].getFConst()); break; case EbtFloat: tempConstArray[i].setFConst(-unionArray[i].getFConst()); break;
case EbtInt: tempConstArray[i].setIConst(-unionArray[i].getIConst()); break; case EbtInt: tempConstArray[i].setIConst(-unionArray[i].getIConst()); break;
default: default:
...@@ -1452,14 +1513,17 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1452,14 +1513,17 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
return 0; return 0;
} }
break; break;
case EOpLogicalNot: // this code is written for possible future use, will not get executed currently case EOpLogicalNot: // this code is written for possible future use, will not get executed currently
switch (getType().getBasicType()) { switch (getType().getBasicType())
{
case EbtBool: tempConstArray[i].setBConst(!unionArray[i].getBConst()); break; case EbtBool: tempConstArray[i].setBConst(!unionArray[i].getBConst()); break;
default: default:
infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine()); infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine());
return 0; return 0;
} }
break; break;
default: default:
return 0; return 0;
} }
......
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