Split TIntermBlock from TIntermAggregate
The new TIntermBlock node class replaces TIntermAggregate nodes with
the EOpSequence op. It represents the root node of the tree which is
a list of declarations and function definitions, and any code blocks
that can be denoted by curly braces. These include function and loop
bodies, and if-else branches.
This change enables a bunch of more compile-time type checking, and
makes the AST code easier to understand and less error-prone.
The PostProcess step that used to be done to ensure that the root node
is TIntermAggregate is removed in favor of making sure that the root
node is a TIntermBlock in the glslang.y parsing code.
Intermediate output formatting is improved to print the EOpNull error
in a clearer way.
After this patch, TIntermAggregate is still used for function
definitions, function prototypes, function parameter lists, function
calls, variable and invariant declarations and the comma (sequence)
operator.
BUG=angleproject:1490
TEST=angle_unittests, angle_end2end_tests
Change-Id: I04044affff979a11577bc1fe75d747e538b799c8
Reviewed-on: https://chromium-review.googlesource.com/393726
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/SimplifyLoopConditions.cpp b/src/compiler/translator/SimplifyLoopConditions.cpp
index da8da48..071b8b8 100644
--- a/src/compiler/translator/SimplifyLoopConditions.cpp
+++ b/src/compiler/translator/SimplifyLoopConditions.cpp
@@ -94,7 +94,7 @@
// If we're outside a loop condition, we only need to traverse nodes that may contain loops.
if (!mInsideLoopConditionOrExpression)
- return (node->getOp() == EOpSequence || node->getOp() == EOpFunction);
+ return (node->getOp() == EOpFunction);
mFoundLoopToChange = mConditionsToSimplify.match(node, getParentNode());
return !mFoundLoopToChange;
@@ -145,10 +145,9 @@
tempInitSeq.push_back(createTempInitDeclaration(node->getCondition()->deepCopy()));
insertStatementsInParentBlock(tempInitSeq);
- TIntermAggregate *newBody = new TIntermAggregate(EOpSequence);
+ TIntermBlock *newBody = new TIntermBlock();
if (node->getBody())
{
- ASSERT(node->getBody()->getOp() == EOpSequence);
newBody->getSequence()->push_back(node->getBody());
}
newBody->getSequence()->push_back(
@@ -176,10 +175,9 @@
tempInitSeq.push_back(createTempInitDeclaration(CreateBoolConstantNode(true)));
insertStatementsInParentBlock(tempInitSeq);
- TIntermAggregate *newBody = new TIntermAggregate(EOpSequence);
+ TIntermBlock *newBody = new TIntermBlock();
if (node->getBody())
{
- ASSERT(node->getBody()->getOp() == EOpSequence);
newBody->getSequence()->push_back(node->getBody());
}
newBody->getSequence()->push_back(
@@ -202,7 +200,7 @@
// bool s0 = expr;
// while (s0) { { body; } exprB; s0 = expr; }
// }
- TIntermAggregate *loopScope = new TIntermAggregate(EOpSequence);
+ TIntermBlock *loopScope = new TIntermBlock();
if (node->getInit())
{
loopScope->getSequence()->push_back(node->getInit());
@@ -210,7 +208,7 @@
loopScope->getSequence()->push_back(
createTempInitDeclaration(node->getCondition()->deepCopy()));
- TIntermAggregate *whileLoopBody = new TIntermAggregate(EOpSequence);
+ TIntermBlock *whileLoopBody = new TIntermBlock();
if (node->getBody())
{
whileLoopBody->getSequence()->push_back(node->getBody());
@@ -242,8 +240,8 @@
// for (init; expr; ) { { body; } exprB; }
TIntermTyped *loopExpression = node->getExpression();
node->setExpression(nullptr);
- TIntermAggregate *oldBody = node->getBody();
- node->setBody(new TIntermAggregate(EOpSequence));
+ TIntermBlock *oldBody = node->getBody();
+ node->setBody(new TIntermBlock());
if (oldBody != nullptr)
{
node->getBody()->getSequence()->push_back(oldBody);