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();
} }
...@@ -1206,90 +1215,105 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1206,90 +1215,105 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
bool boolNodeFlag = false; bool boolNodeFlag = false;
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];
} }
break; break;
case EOpMul: case EOpMul:
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:
if (getType().getBasicType() != EbtFloat || node->getBasicType() != EbtFloat) { case EOpMatrixTimesMatrix:
{
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];
for (int row = 0; row < rows; row++) { for (int row = 0; row < rows; row++) {
for (int column = 0; column < cols; column++) { for (int column = 0; column < cols; column++) {
tempConstArray[rows * column + row].setFConst(0.0f); tempConstArray[rows * column + row].setFConst(0.0f);
for (int i = 0; i < cols; i++) { for (int i = 0; i < cols; i++) {
tempConstArray[rows * column + row].setFConst(tempConstArray[rows * column + row].getFConst() + unionArray[i * rows + row].getFConst() * (rightUnionArray[column * rows + i].getFConst())); tempConstArray[rows * column + row].setFConst(tempConstArray[rows * column + row].getFConst() + unionArray[i * rows + row].getFConst() * (rightUnionArray[column * rows + i].getFConst()));
}
} }
} }
} }
break; }
case EOpDiv: break;
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: {
if (rightUnionArray[i] == 0.0f) { case EbtFloat:
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine()); if (rightUnionArray[i] == 0.0f)
tempConstArray[i].setFConst(unionArray[i].getFConst() < 0 ? -FLT_MAX : FLT_MAX); {
} else infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst()); tempConstArray[i].setFConst(unionArray[i].getFConst() < 0 ? -FLT_MAX : FLT_MAX);
break; }
else
{
tempConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst());
}
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()); {
tempConstArray[i].setIConst(INT_MAX); infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
} else tempConstArray[i].setIConst(INT_MAX);
tempConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst()); }
break; else
default: {
infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine()); tempConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst());
return 0;
} }
break;
default:
infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine());
return 0;
} }
} }
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()));
}
} }
} }
...@@ -1297,171 +1321,211 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1297,171 +1321,211 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
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()));
} }
} }
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()) { switch (getType().getBasicType())
case EbtBool: tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break; {
default: assert(false && "Default missing"); case EbtBool:
tempConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true);
break;
default:
UNREACHABLE();
break;
} }
} }
break; }
break;
case EOpLessThan: case EOpLessThan:
assert(objectSize == 1);
tempConstArray = new ConstantUnion[1];
tempConstArray->setBConst(*unionArray < *rightUnionArray);
returnType = TType(EbtBool, EbpUndefined, EvqConst);
break;
case EOpGreaterThan:
assert(objectSize == 1);
tempConstArray = new ConstantUnion[1];
tempConstArray->setBConst(*unionArray > *rightUnionArray);
returnType = TType(EbtBool, EbpUndefined, EvqConst);
break;
case EOpLessThanEqual:
{
assert(objectSize == 1); assert(objectSize == 1);
ConstantUnion constant;
constant.setBConst(*unionArray > *rightUnionArray);
tempConstArray = new ConstantUnion[1]; tempConstArray = new ConstantUnion[1];
tempConstArray->setBConst(*unionArray < *rightUnionArray); tempConstArray->setBConst(!constant.getBConst());
returnType = TType(EbtBool, EbpUndefined, EvqConst); returnType = TType(EbtBool, EbpUndefined, EvqConst);
break; break;
case EOpGreaterThan: }
case EOpGreaterThanEqual:
{
assert(objectSize == 1); assert(objectSize == 1);
ConstantUnion constant;
constant.setBConst(*unionArray < *rightUnionArray);
tempConstArray = new ConstantUnion[1]; tempConstArray = new ConstantUnion[1];
tempConstArray->setBConst(*unionArray > *rightUnionArray); tempConstArray->setBConst(!constant.getBConst());
returnType = TType(EbtBool, EbpUndefined, EvqConst); returnType = TType(EbtBool, EbpUndefined, EvqConst);
break; break;
case EOpLessThanEqual: }
{
assert(objectSize == 1);
ConstantUnion constant;
constant.setBConst(*unionArray > *rightUnionArray);
tempConstArray = new ConstantUnion[1];
tempConstArray->setBConst(!constant.getBConst());
returnType = TType(EbtBool, EbpUndefined, EvqConst);
break;
}
case EOpGreaterThanEqual:
{
assert(objectSize == 1);
ConstantUnion constant;
constant.setBConst(*unionArray < *rightUnionArray);
tempConstArray = new ConstantUnion[1];
tempConstArray->setBConst(!constant.getBConst());
returnType = TType(EbtBool, EbpUndefined, EvqConst);
break;
}
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;
}
else
{
for (int i = 0; i < objectSize; i++)
{
if (unionArray[i] != rightUnionArray[i])
{
boolNodeFlag = true; boolNodeFlag = true;
} else { break; // break out of for loop
for (int i = 0; i < objectSize; i++) {
if (unionArray[i] != rightUnionArray[i]) {
boolNodeFlag = true;
break; // break out of for loop
}
} }
} }
}
tempConstArray = new ConstantUnion[1]; tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) { if (!boolNodeFlag)
tempConstArray->setBConst(true); {
} tempConstArray->setBConst(true);
else { }
tempConstArray->setBConst(false); else
} {
tempConstArray->setBConst(false);
}
tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConst)); tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConst));
tempNode->setLine(getLine()); tempNode->setLine(getLine());
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;
}
else
{
for (int i = 0; i < objectSize; i++)
{
if (unionArray[i] == rightUnionArray[i])
{
boolNodeFlag = true; boolNodeFlag = true;
} else { break; // break out of for loop
for (int i = 0; i < objectSize; i++) {
if (unionArray[i] == rightUnionArray[i]) {
boolNodeFlag = true;
break; // break out of for loop
}
} }
} }
}
tempConstArray = new ConstantUnion[1]; tempConstArray = new ConstantUnion[1];
if (!boolNodeFlag) { if (!boolNodeFlag)
tempConstArray->setBConst(true); {
} tempConstArray->setBConst(true);
else { }
tempConstArray->setBConst(false); else
} {
tempConstArray->setBConst(false);
}
tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConst)); tempNode = new TIntermConstantUnion(tempConstArray, TType(EbtBool, EbpUndefined, EvqConst));
tempNode->setLine(getLine()); tempNode->setLine(getLine());
return tempNode; return tempNode;
default: default:
infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", getLine()); infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", getLine());
return 0; return 0;
} }
tempNode = new TIntermConstantUnion(tempConstArray, returnType); tempNode = new TIntermConstantUnion(tempConstArray, returnType);
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) { {
case EOpNegative: switch(op)
switch (getType().getBasicType()) { {
case EbtFloat: tempConstArray[i].setFConst(-unionArray[i].getFConst()); break; case EOpNegative:
case EbtInt: tempConstArray[i].setIConst(-unionArray[i].getIConst()); break; switch (getType().getBasicType())
default: {
infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine()); case EbtFloat: tempConstArray[i].setFConst(-unionArray[i].getFConst()); break;
return 0; case EbtInt: tempConstArray[i].setIConst(-unionArray[i].getIConst()); break;
} default:
break; infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine());
case EOpLogicalNot: // this code is written for possible future use, will not get executed currently return 0;
switch (getType().getBasicType()) { }
case EbtBool: tempConstArray[i].setBConst(!unionArray[i].getBConst()); break; break;
default:
infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine()); case EOpLogicalNot: // this code is written for possible future use, will not get executed currently
return 0; switch (getType().getBasicType())
} {
break; case EbtBool: tempConstArray[i].setBConst(!unionArray[i].getBConst()); break;
default: default:
return 0; infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine());
return 0;
}
break;
default:
return 0;
} }
} }
newNode = new TIntermConstantUnion(tempConstArray, getType()); newNode = new TIntermConstantUnion(tempConstArray, getType());
......
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