translator: Refactor Constant Union shift ops.
In preparation for making them robust.
BUG=chromium:648135
Change-Id: I88fc87d8887064fda04087c56de05d8725a6fe5f
Reviewed-on: https://chromium-review.googlesource.com/387469
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/ConstantUnion.cpp b/src/compiler/translator/ConstantUnion.cpp
index 74bf570..6ef6179 100644
--- a/src/compiler/translator/ConstantUnion.cpp
+++ b/src/compiler/translator/ConstantUnion.cpp
@@ -369,17 +369,21 @@
return returnValue;
}
-TConstantUnion TConstantUnion::operator>>(const TConstantUnion &constant) const
+// static
+TConstantUnion TConstantUnion::rshift(const TConstantUnion &lhs,
+ const TConstantUnion &rhs,
+ TDiagnostics *diag,
+ const TSourceLoc &line)
{
TConstantUnion returnValue;
- ASSERT(type == constant.type);
- switch (type)
+ ASSERT((lhs.type == rhs.type) && (lhs.type == EbtInt || lhs.type == EbtUInt));
+ switch (lhs.type)
{
case EbtInt:
- returnValue.setIConst(iConst >> constant.iConst);
+ returnValue.setIConst(lhs.iConst >> rhs.iConst);
break;
case EbtUInt:
- returnValue.setUConst(uConst >> constant.uConst);
+ returnValue.setUConst(lhs.uConst >> rhs.uConst);
break;
default:
UNREACHABLE();
@@ -388,20 +392,24 @@
return returnValue;
}
-TConstantUnion TConstantUnion::operator<<(const TConstantUnion &constant) const
+// static
+TConstantUnion TConstantUnion::lshift(const TConstantUnion &lhs,
+ const TConstantUnion &rhs,
+ TDiagnostics *diag,
+ const TSourceLoc &line)
{
TConstantUnion returnValue;
// The signedness of the second parameter might be different, but we
// don't care, since the result is undefined if the second parameter is
// negative, and aliasing should not be a problem with unions.
- ASSERT(constant.type == EbtInt || constant.type == EbtUInt);
- switch (type)
+ ASSERT((lhs.type == rhs.type) && (lhs.type == EbtInt || lhs.type == EbtUInt));
+ switch (lhs.type)
{
case EbtInt:
- returnValue.setIConst(iConst << constant.iConst);
+ returnValue.setIConst(lhs.iConst << rhs.iConst);
break;
case EbtUInt:
- returnValue.setUConst(uConst << constant.uConst);
+ returnValue.setUConst(lhs.uConst << rhs.uConst);
break;
default:
UNREACHABLE();