Commit 7d7f8c44 by Olli Etuaho

Ensure that conditional blocks and loop bodies are sequence nodes

AST transformations such as unfolding logical operations can only create nodes inside sequence (block) nodes. This patch ensures that these AST transformations work even inside conditional blocks and loop bodies that were first parsed as single statements instead of blocks. BUG=angleproject:971 TEST=WebGL conformance tests Change-Id: If98cb7be653ec7b005537b89547f4f4cf1c07c72 Reviewed-on: https://chromium-review.googlesource.com/272141Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 08a5fedd
...@@ -246,6 +246,22 @@ TIntermAggregate *TIntermediate::makeAggregate( ...@@ -246,6 +246,22 @@ TIntermAggregate *TIntermediate::makeAggregate(
return aggNode; return aggNode;
} }
// If the input node is nullptr, return nullptr.
// If the input node is a sequence (block) node, return it.
// If the input node is not a sequence node, put it inside a sequence node and return that.
TIntermAggregate *TIntermediate::ensureSequence(TIntermNode *node)
{
if (node == nullptr)
return nullptr;
TIntermAggregate *aggNode = node->getAsAggregate();
if (aggNode != nullptr && aggNode->getOp() == EOpSequence)
return aggNode;
aggNode = makeAggregate(node, node->getLine());
aggNode->setOp(EOpSequence);
return aggNode;
}
// //
// For "if" test nodes. There are three children; a condition, // For "if" test nodes. There are three children; a condition,
// a true path, and a false path. The two paths are in the // a true path, and a false path. The two paths are in the
...@@ -276,7 +292,7 @@ TIntermNode *TIntermediate::addSelection( ...@@ -276,7 +292,7 @@ TIntermNode *TIntermediate::addSelection(
} }
TIntermSelection *node = new TIntermSelection( TIntermSelection *node = new TIntermSelection(
cond, nodePair.node1, nodePair.node2); cond, ensureSequence(nodePair.node1), ensureSequence(nodePair.node2));
node->setLine(line); node->setLine(line);
return node; return node;
...@@ -399,7 +415,7 @@ TIntermNode *TIntermediate::addLoop( ...@@ -399,7 +415,7 @@ TIntermNode *TIntermediate::addLoop(
TLoopType type, TIntermNode *init, TIntermTyped *cond, TIntermTyped *expr, TLoopType type, TIntermNode *init, TIntermTyped *cond, TIntermTyped *expr,
TIntermNode *body, const TSourceLoc &line) TIntermNode *body, const TSourceLoc &line)
{ {
TIntermNode *node = new TIntermLoop(type, init, cond, expr, body); TIntermNode *node = new TIntermLoop(type, init, cond, expr, ensureSequence(body));
node->setLine(line); node->setLine(line);
return node; return node;
......
...@@ -39,6 +39,7 @@ class TIntermediate ...@@ -39,6 +39,7 @@ class TIntermediate
TIntermAggregate *growAggregate( TIntermAggregate *growAggregate(
TIntermNode *left, TIntermNode *right, const TSourceLoc &); TIntermNode *left, TIntermNode *right, const TSourceLoc &);
TIntermAggregate *makeAggregate(TIntermNode *node, const TSourceLoc &); TIntermAggregate *makeAggregate(TIntermNode *node, const TSourceLoc &);
TIntermAggregate *ensureSequence(TIntermNode *node);
TIntermAggregate *setAggregateOperator(TIntermNode *, TOperator, const TSourceLoc &); TIntermAggregate *setAggregateOperator(TIntermNode *, TOperator, const TSourceLoc &);
TIntermNode *addSelection(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &); TIntermNode *addSelection(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &);
TIntermTyped *addSelection(TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, TIntermTyped *addSelection(TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment