Refactoring: make tracking parent block position in AST traversal reusable
Add a helper function to make it easier for traverser classes to insert
statements, and use it in UnfoldShortCircuitToIf.
BUG=angleproject:971
TEST=angle_end2end_tests, WebGL conformance tests
Change-Id: I141bdd8abf4b01988581e6cb27c2320bf38370ac
Reviewed-on: https://chromium-review.googlesource.com/272140
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/IntermTraverse.cpp b/src/compiler/translator/IntermTraverse.cpp
index 7a7efb7..2f401da 100644
--- a/src/compiler/translator/IntermTraverse.cpp
+++ b/src/compiler/translator/IntermTraverse.cpp
@@ -6,6 +6,35 @@
#include "compiler/translator/IntermNode.h"
+void TIntermTraverser::pushParentBlock(TIntermAggregate *node)
+{
+ if (rightToLeft)
+ mParentBlockStack.push_back(ParentBlock(node, node->getSequence()->size() - 1));
+ else
+ mParentBlockStack.push_back(ParentBlock(node, 0));
+}
+
+void TIntermTraverser::incrementParentBlockPos()
+{
+ if (rightToLeft)
+ --mParentBlockStack.back().pos;
+ else
+ ++mParentBlockStack.back().pos;
+}
+
+void TIntermTraverser::popParentBlock()
+{
+ ASSERT(!mParentBlockStack.empty());
+ mParentBlockStack.pop_back();
+}
+
+void TIntermTraverser::insertStatementsInParentBlock(const TIntermSequence &insertions)
+{
+ ASSERT(!mParentBlockStack.empty());
+ NodeInsertMultipleEntry insert(mParentBlockStack.back().node, mParentBlockStack.back().pos, insertions);
+ mInsertions.push_back(insert);
+}
+
//
// Traverse the intermediate representation tree, and
// call a node type specific function for each node.
@@ -119,6 +148,9 @@
if (visit)
{
+ if (mOp == EOpSequence)
+ it->pushParentBlock(this);
+
it->incrementDepth(this);
if (it->rightToLeft)
@@ -133,6 +165,10 @@
if (*sit != mSequence.front())
visit = it->visitAggregate(InVisit, this);
}
+ if (mOp == EOpSequence)
+ {
+ it->incrementParentBlockPos();
+ }
}
}
else
@@ -147,10 +183,17 @@
if (*sit != mSequence.back())
visit = it->visitAggregate(InVisit, this);
}
+ if (mOp == EOpSequence)
+ {
+ it->incrementParentBlockPos();
+ }
}
}
it->decrementDepth();
+
+ if (mOp == EOpSequence)
+ it->popParentBlock();
}
if (visit && it->postVisit)