Refactor binary node creation
1. Simplify code by using asserts instead of adding internal errors to
log.
2. Add a TIntermBinary constructor that takes left and right operand
nodes as parameters.
3. Remove TIntermediate functions with trivial functionality.
BUG=angleproject:952
TEST=angle_unittests
Change-Id: I2e0e52160c9377d8efcf15f14fd59f01cb41bd83
Reviewed-on: https://chromium-review.googlesource.com/372720
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 5a79d2a..1561382 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -3631,7 +3631,18 @@
break;
}
- return intermediate.addBinaryMath(op, left, right, loc);
+ TIntermBinary *node = new TIntermBinary(op, left, right);
+ node->setLine(loc);
+
+ if (!node->promote())
+ return nullptr;
+
+ // See if we can fold constants.
+ TIntermTyped *foldedNode = node->fold(&mDiagnostics);
+ if (foldedNode)
+ return foldedNode;
+
+ return node;
}
TIntermTyped *TParseContext::addBinaryMath(TOperator op,
@@ -3674,7 +3685,13 @@
{
if (binaryOpCommonCheck(op, left, right, loc))
{
- return intermediate.addAssign(op, left, right, loc);
+ TIntermBinary *node = new TIntermBinary(op, left, right);
+ node->setLine(loc);
+
+ if (!node->promote())
+ return nullptr;
+
+ return node;
}
return nullptr;
}