Make AST path always include the current node being traversed
AST traversers tend to sometimes call traverse() functions manually
during PreVisit. Change TIntermTraverser so that even if this happens,
all the nodes are automatically added to the traversal path, instead
of having to add them manually in each individual AST traverser.
This also makes calling getParentNode() return the correct node during
InVisit.
This does cause the same node being added to the traversal path twice
in some cases, where nodes are repeatedly traversed, like in
OutputHLSL, but this should not have adverse side effects. The more
common case is that the traverse() function is called on the children
of the node being currently traversed.
This fixes a bug in OVR_multiview validation, which did not previously
call incrementDepth and decrementDepth when it should have.
BUG=angleproject:1725
TEST=angle_unittests, angle_end2end_tests
Change-Id: I6ae762eef760509ebe853eefa37dac28c16e7a9b
Reviewed-on: https://chromium-review.googlesource.com/430732
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/SimplifyLoopConditions.cpp b/src/compiler/translator/SimplifyLoopConditions.cpp
index 68fdb03..a2ed7f3 100644
--- a/src/compiler/translator/SimplifyLoopConditions.cpp
+++ b/src/compiler/translator/SimplifyLoopConditions.cpp
@@ -135,9 +135,7 @@
// Mark that we're inside a loop condition or expression, and transform the loop if needed.
- incrementDepth(node);
-
- // Note: No need to traverse the loop init node.
+ ScopedNodeInTraversalPath addToPath(this, node);
mInsideLoopInitConditionOrExpression = true;
TLoopType loopType = node->getType();
@@ -274,8 +272,7 @@
ELoopWhile, nullptr, createTempSymbol(conditionInitializer->getType()), nullptr,
whileLoopBody);
loopScope->getSequence()->push_back(whileLoop);
- queueReplacementWithParent(getAncestorNode(1), node, loopScope,
- OriginalNode::IS_DROPPED);
+ queueReplacement(node, loopScope, OriginalNode::IS_DROPPED);
}
}
@@ -283,8 +280,6 @@
if (!mFoundLoopToChange && node->getBody())
node->getBody()->traverse(this);
-
- decrementDepth();
}
} // namespace