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