Promote and fold indexing nodes similarly to other binary ops
Indexing nodes now get their type set in TIntermBinary::promote, same
as math and logic ops. They are also constant folded through
TIntermBinary::fold() instead of having special functions for constant
folding them in ParseContext.
Index nodes for struct and interface block member access now always
have integer type, instead of sometimes having the type of the field
they were used to access.
Usage of TIntermBinary constructor is cleaned up so only the
constructor that takes in left and right operands is used. The type
of TIntermBinary nodes is always determined automatically.
Together these changes make the code considerably cleaner.
Note that the code for constant folding for array indexing is actually
never hit because constant folding array constructors is still
intentionally disabled in the code.
BUG=angleproject:1490
TEST=angle_unittests
Change-Id: Ifcec45257476cdb0d495c7d72e3cf2f83388e8c5
Reviewed-on: https://chromium-review.googlesource.com/377961
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/IntermTraverse.cpp b/src/compiler/translator/IntermTraverse.cpp
index 2f66ba7..79cb86d 100644
--- a/src/compiler/translator/IntermTraverse.cpp
+++ b/src/compiler/translator/IntermTraverse.cpp
@@ -147,10 +147,7 @@
ASSERT(initializer != nullptr);
TIntermSymbol *tempSymbol = createTempSymbol(initializer->getType(), qualifier);
TIntermAggregate *tempDeclaration = new TIntermAggregate(EOpDeclaration);
- TIntermBinary *tempInit = new TIntermBinary(EOpInitialize);
- tempInit->setLeft(tempSymbol);
- tempInit->setRight(initializer);
- tempInit->setType(tempSymbol->getType());
+ TIntermBinary *tempInit = new TIntermBinary(EOpInitialize, tempSymbol, initializer);
tempDeclaration->getSequence()->push_back(tempInit);
return tempDeclaration;
}
@@ -164,10 +161,7 @@
{
ASSERT(rightNode != nullptr);
TIntermSymbol *tempSymbol = createTempSymbol(rightNode->getType());
- TIntermBinary *assignment = new TIntermBinary(EOpAssign);
- assignment->setLeft(tempSymbol);
- assignment->setRight(rightNode);
- assignment->setType(tempSymbol->getType());
+ TIntermBinary *assignment = new TIntermBinary(EOpAssign, tempSymbol, rightNode);
return assignment;
}