Refactor location tracking.
R=kbr@chromium.org
Review URL: https://codereview.appspot.com/9078046
git-svn-id: https://angleproject.googlecode.com/svn/trunk@2202 736b8ea6-26fd-11df-bfd4-992fa37f6226
TRAC #23333
Authored-by: alokp@chromium.org
Signed-off-by: Shannon Woods
Signed-off-by Nicolas Capens
Merged-by: Jamie Madill
diff --git a/src/compiler/Intermediate.cpp b/src/compiler/Intermediate.cpp
index 7042657..537b14b 100644
--- a/src/compiler/Intermediate.cpp
+++ b/src/compiler/Intermediate.cpp
@@ -141,7 +141,7 @@
//
// Returns the added node.
//
-TIntermSymbol* TIntermediate::addSymbol(int id, const TString& name, const TType& type, TSourceLoc line)
+TIntermSymbol* TIntermediate::addSymbol(int id, const TString& name, const TType& type, const TSourceLoc& line)
{
TIntermSymbol* node = new TIntermSymbol(id, name, type);
node->setLine(line);
@@ -154,7 +154,7 @@
//
// Returns the added node.
//
-TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc line)
+TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc& line)
{
switch (op) {
case EOpEqual:
@@ -210,8 +210,6 @@
// one and promote it to the right type.
//
TIntermBinary* node = new TIntermBinary(op);
- if (line == 0)
- line = right->getLine();
node->setLine(line);
node->setLeft(left);
@@ -240,15 +238,13 @@
//
// Returns the added node.
//
-TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc line)
+TIntermTyped* TIntermediate::addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc& line)
{
//
// Like adding binary math, except the conversion can only go
// from right to left.
//
TIntermBinary* node = new TIntermBinary(op);
- if (line == 0)
- line = left->getLine();
node->setLine(line);
TIntermTyped* child = addConversion(op, left->getType(), right);
@@ -270,11 +266,9 @@
// Returns the added node.
// The caller should set the type of the returned node.
//
-TIntermTyped* TIntermediate::addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc line)
+TIntermTyped* TIntermediate::addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, const TSourceLoc& line)
{
TIntermBinary* node = new TIntermBinary(op);
- if (line == 0)
- line = index->getLine();
node->setLine(line);
node->setLeft(base);
node->setRight(index);
@@ -289,13 +283,13 @@
//
// Returns the added node.
//
-TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode, TSourceLoc line)
+TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode, const TSourceLoc& line)
{
TIntermUnary* node;
TIntermTyped* child = childNode->getAsTyped();
if (child == 0) {
- infoSink.info.message(EPrefixInternalError, "Bad type in AddUnaryMath", line);
+ infoSink.info.message(EPrefixInternalError, line, "Bad type in AddUnaryMath");
return 0;
}
@@ -360,8 +354,6 @@
// Make a new node for the operator.
//
node = new TIntermUnary(op);
- if (line == 0)
- line = child->getLine();
node->setLine(line);
node->setOperand(child);
@@ -388,7 +380,7 @@
// Returns an aggregate node, which could be the one passed in if
// it was already an aggregate but no operator was set.
//
-TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperator op, TSourceLoc line)
+TIntermAggregate* TIntermediate::setAggregateOperator(TIntermNode* node, TOperator op, const TSourceLoc& line)
{
TIntermAggregate* aggNode;
@@ -403,8 +395,6 @@
//
aggNode = new TIntermAggregate();
aggNode->getSequence().push_back(node);
- if (line == 0)
- line = node->getLine();
}
} else
aggNode = new TIntermAggregate();
@@ -413,8 +403,7 @@
// Set the operator.
//
aggNode->setOp(op);
- if (line != 0)
- aggNode->setLine(line);
+ aggNode->setLine(line);
return aggNode;
}
@@ -505,7 +494,7 @@
case EbtUInt: newOp = EOpConvFloatToUInt; break;
case EbtBool: newOp = EOpConvBoolToFloat; break;
default:
- infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Bad promotion node");
return 0;
}
break;
@@ -515,7 +504,7 @@
case EbtUInt: newOp = EOpConvBoolToUInt; break;
case EbtFloat: newOp = EOpConvFloatToBool; break;
default:
- infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Bad promotion node");
return 0;
}
break;
@@ -525,7 +514,7 @@
case EbtBool: newOp = EOpConvBoolToInt; break;
case EbtFloat: newOp = EOpConvFloatToInt; break;
default:
- infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Bad promotion node");
return 0;
}
break;
@@ -535,12 +524,12 @@
case EbtBool: newOp = EOpConvBoolToUInt; break;
case EbtFloat: newOp = EOpConvFloatToUInt; break;
default:
- infoSink.info.message(EPrefixInternalError, "Bad promotion node", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Bad promotion node");
return 0;
}
break;
default:
- infoSink.info.message(EPrefixInternalError, "Bad promotion type", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Bad promotion type");
return 0;
}
@@ -560,7 +549,7 @@
// Returns the resulting aggregate, unless 0 was passed in for
// both existing nodes.
//
-TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc line)
+TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc& line)
{
if (left == 0 && right == 0)
return 0;
@@ -577,8 +566,7 @@
if (right)
aggNode->getSequence().push_back(right);
- if (line != 0)
- aggNode->setLine(line);
+ aggNode->setLine(line);
return aggNode;
}
@@ -588,7 +576,7 @@
//
// Returns an aggregate, unless 0 was passed in for the existing node.
//
-TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, TSourceLoc line)
+TIntermAggregate* TIntermediate::makeAggregate(TIntermNode* node, const TSourceLoc& line)
{
if (node == 0)
return 0;
@@ -596,10 +584,7 @@
TIntermAggregate* aggNode = new TIntermAggregate;
aggNode->getSequence().push_back(node);
- if (line != 0)
- aggNode->setLine(line);
- else
- aggNode->setLine(node->getLine());
+ aggNode->setLine(line);
return aggNode;
}
@@ -611,7 +596,7 @@
//
// Returns the selection node created.
//
-TIntermNode* TIntermediate::addSelection(TIntermTyped* cond, TIntermNodePair nodePair, TSourceLoc line)
+TIntermNode* TIntermediate::addSelection(TIntermTyped* cond, TIntermNodePair nodePair, const TSourceLoc& line)
{
//
// For compile time constant selections, prune the code and
@@ -632,7 +617,7 @@
}
-TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, TSourceLoc line)
+TIntermTyped* TIntermediate::addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc& line)
{
if (left->getType().getQualifier() == EvqConst && right->getType().getQualifier() == EvqConst) {
return right;
@@ -652,7 +637,7 @@
//
// Returns the selection node created, or 0 if one could not be.
//
-TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc line)
+TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, const TSourceLoc& line)
{
//
// Get compatible types.
@@ -695,7 +680,7 @@
// Returns the constant union node created.
//
-TIntermConstantUnion* TIntermediate::addConstantUnion(ConstantUnion* unionArrayPointer, const TType& t, TSourceLoc line)
+TIntermConstantUnion* TIntermediate::addConstantUnion(ConstantUnion* unionArrayPointer, const TType& t, const TSourceLoc& line)
{
TIntermConstantUnion* node = new TIntermConstantUnion(unionArrayPointer, t);
node->setLine(line);
@@ -703,7 +688,7 @@
return node;
}
-TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, TSourceLoc line)
+TIntermTyped* TIntermediate::addSwizzle(TVectorFields& fields, const TSourceLoc& line)
{
TIntermAggregate* node = new TIntermAggregate(EOpSequence);
@@ -726,7 +711,7 @@
//
// Create loop nodes.
//
-TIntermNode* TIntermediate::addLoop(TLoopType type, TIntermNode* init, TIntermTyped* cond, TIntermTyped* expr, TIntermNode* body, TSourceLoc line)
+TIntermNode* TIntermediate::addLoop(TLoopType type, TIntermNode* init, TIntermTyped* cond, TIntermTyped* expr, TIntermNode* body, const TSourceLoc& line)
{
TIntermNode* node = new TIntermLoop(type, init, cond, expr, body);
node->setLine(line);
@@ -737,12 +722,12 @@
//
// Add branches.
//
-TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TSourceLoc line)
+TIntermBranch* TIntermediate::addBranch(TOperator branchOp, const TSourceLoc& line)
{
return addBranch(branchOp, 0, line);
}
-TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expression, TSourceLoc line)
+TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expression, const TSourceLoc& line)
{
TIntermBranch* node = new TIntermBranch(branchOp, expression);
node->setLine(line);
@@ -922,7 +907,7 @@
// This function only handles scalars, vectors, and matrices.
if (left->isArray() || right->isArray())
{
- infoSink.info.message(EPrefixInternalError, "Invalid operation for arrays", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Invalid operation for arrays");
return false;
}
@@ -1040,7 +1025,7 @@
}
else
{
- infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Missing elses");
return false;
}
@@ -1094,7 +1079,7 @@
}
else
{
- infoSink.info.message(EPrefixInternalError, "Missing elses", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Missing elses");
return false;
}
@@ -1273,7 +1258,7 @@
{
if (getType().getBasicType() != EbtFloat || node->getBasicType() != EbtFloat)
{
- infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix multiply", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Constant Folding cannot be done for matrix multiply");
return 0;
}
@@ -1313,7 +1298,7 @@
case EbtFloat:
if (rightUnionArray[i] == 0.0f)
{
- infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
+ infoSink.info.message(EPrefixWarning, getLine(), "Divide by zero error during constant folding");
tempConstArray[i].setFConst(unionArray[i].getFConst() < 0 ? -FLT_MAX : FLT_MAX);
}
else
@@ -1325,7 +1310,7 @@
case EbtInt:
if (rightUnionArray[i] == 0)
{
- infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
+ infoSink.info.message(EPrefixWarning, getLine(), "Divide by zero error during constant folding");
tempConstArray[i].setIConst(INT_MAX);
}
else
@@ -1337,7 +1322,7 @@
case EbtUInt:
if (rightUnionArray[i] == 0)
{
- infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
+ infoSink.info.message(EPrefixWarning, getLine(), "Divide by zero error during constant folding");
tempConstArray[i].setUConst(UINT_MAX);
}
else
@@ -1347,7 +1332,7 @@
break;
default:
- infoSink.info.message(EPrefixInternalError, "Constant folding cannot be done for \"/\"", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Constant folding cannot be done for \"/\"");
return 0;
}
}
@@ -1358,7 +1343,7 @@
{
if (node->getBasicType() != EbtFloat)
{
- infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for matrix times vector", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Constant Folding cannot be done for matrix times vector");
return 0;
}
@@ -1389,7 +1374,7 @@
{
if (getType().getBasicType() != EbtFloat)
{
- infoSink.info.message(EPrefixInternalError, "Constant Folding cannot be done for vector times matrix", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Constant Folding cannot be done for vector times matrix");
return 0;
}
@@ -1552,7 +1537,7 @@
return tempNode;
default:
- infoSink.info.message(EPrefixInternalError, "Invalid operator for constant folding", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Invalid operator for constant folding");
return 0;
}
tempNode = new TIntermConstantUnion(tempConstArray, returnType);
@@ -1578,7 +1563,7 @@
case EbtInt: tempConstArray[i].setIConst(-unionArray[i].getIConst()); break;
case EbtUInt: tempConstArray[i].setUConst(static_cast<unsigned int>(-static_cast<int>(unionArray[i].getUConst()))); break;
default:
- infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Unary operation not folded into constant");
return 0;
}
break;
@@ -1588,7 +1573,7 @@
{
case EbtBool: tempConstArray[i].setBConst(!unionArray[i].getBConst()); break;
default:
- infoSink.info.message(EPrefixInternalError, "Unary operation not folded into constant", getLine());
+ infoSink.info.message(EPrefixInternalError, getLine(), "Unary operation not folded into constant");
return 0;
}
break;
@@ -1627,7 +1612,7 @@
leftUnionArray[i].setFConst(static_cast<float>(node->getFConst(i)));
break;
default:
- infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Cannot promote");
return 0;
}
break;
@@ -1646,7 +1631,7 @@
leftUnionArray[i].setIConst(static_cast<int>(node->getFConst(i)));
break;
default:
- infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Cannot promote");
return 0;
}
break;
@@ -1665,7 +1650,7 @@
leftUnionArray[i].setUConst(static_cast<unsigned int>(node->getFConst(i)));
break;
default:
- infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Cannot promote");
return 0;
}
break;
@@ -1684,13 +1669,13 @@
leftUnionArray[i].setBConst(node->getFConst(i) != 0.0f);
break;
default:
- infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Cannot promote");
return 0;
}
break;
default:
- infoSink.info.message(EPrefixInternalError, "Incorrect data type found", node->getLine());
+ infoSink.info.message(EPrefixInternalError, node->getLine(), "Incorrect data type found");
return 0;
}