Clean up unary and aggregate math folding
Prefer asserts instead of adding internal errors to the compiler log
when types of arguments are not as expected or the folding function
runs into an operation it can't handle. Neither of these cases should
be possible, the checks for correct argument types are solid at this
point.
In the future, when new built-in functions are added, constant folding
support for them should be added as well.
foldUnaryWithDifferentReturnType and foldUnaryWithSameReturnType are
renamed to foldUnaryNonComponentWise and foldUnaryComponentWise
respectively. These names better reflect what these functions are
doing.
The info sink member is removed from TIntermediate, since TDiagnostics
is now passed into the functions that may generate warnings instead.
BUG=angleproject:1490
TEST=angle_unittests
Change-Id: I6a08abbe29cf23f3a318032fdc46dd3dbaf4410e
Reviewed-on: https://chromium-review.googlesource.com/377959
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/Intermediate.cpp b/src/compiler/translator/Intermediate.cpp
index b6fefa4..b747945 100644
--- a/src/compiler/translator/Intermediate.cpp
+++ b/src/compiler/translator/Intermediate.cpp
@@ -58,29 +58,6 @@
}
//
-// Add one node as the parent of another that it operates on.
-//
-// Returns the added node.
-//
-TIntermTyped *TIntermediate::addUnaryMath(
- TOperator op, TIntermTyped *child, const TSourceLoc &line, const TType *funcReturnType)
-{
- //
- // Make a new node for the operator.
- //
- TIntermUnary *node = new TIntermUnary(op);
- node->setLine(line);
- node->setOperand(child);
- node->promote(funcReturnType);
-
- TIntermTyped *foldedNode = node->fold(mInfoSink);
- if (foldedNode)
- return foldedNode;
-
- return node;
-}
-
-//
// This is the safe way to change the operator on an aggregate, as it
// does lots of error checking and fixing. Especially for establishing
// a function call's operation on it's set of parameters. Sequences
@@ -388,7 +365,7 @@
// This is to be executed once the final root is put on top by the parsing
// process.
//
-TIntermAggregate *TIntermediate::postProcess(TIntermNode *root)
+TIntermAggregate *TIntermediate::PostProcess(TIntermNode *root)
{
if (root == nullptr)
return nullptr;
@@ -411,7 +388,8 @@
return aggRoot;
}
-TIntermTyped *TIntermediate::foldAggregateBuiltIn(TIntermAggregate *aggregate)
+TIntermTyped *TIntermediate::foldAggregateBuiltIn(TIntermAggregate *aggregate,
+ TDiagnostics *diagnostics)
{
switch (aggregate->getOp())
{
@@ -438,12 +416,12 @@
case EOpFaceForward:
case EOpReflect:
case EOpRefract:
- return aggregate->fold(mInfoSink);
+ return aggregate->fold(diagnostics);
default:
// TODO: Add support for folding array constructors
if (aggregate->isConstructor() && !aggregate->isArray())
{
- return aggregate->fold(mInfoSink);
+ return aggregate->fold(diagnostics);
}
// Constant folding not supported for the built-in.
return nullptr;