Split TIntermFunctionDefinition from TIntermAggregate
This makes the code easier to understand. Function definition nodes
always have just two children, the parameters node and the function
body node, so there was no proper reason why they should be aggregate
nodes.
As a part of this change, intermediate output is modified to print
symbol table ids of functions so that debugging function id related
functionality will be easier in the future.
After this patch, TIntermAggregate is still used for 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: Ib88b4ca5d21abd5f126836ca5900d0baecabd19e
Reviewed-on: https://chromium-review.googlesource.com/394707
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/translator/DeferGlobalInitializers.cpp b/src/compiler/translator/DeferGlobalInitializers.cpp
index 39577c2..067e6ce 100644
--- a/src/compiler/translator/DeferGlobalInitializers.cpp
+++ b/src/compiler/translator/DeferGlobalInitializers.cpp
@@ -38,18 +38,16 @@
return functionNode;
}
-TIntermAggregate *CreateFunctionDefinitionNode(const char *name,
- TIntermBlock *functionBody,
- const int functionId)
+TIntermFunctionDefinition *CreateFunctionDefinitionNode(const char *name,
+ TIntermBlock *functionBody,
+ const int functionId)
{
- TIntermAggregate *functionNode = new TIntermAggregate(EOpFunction);
+ TType returnType(EbtVoid);
TIntermAggregate *paramsNode = new TIntermAggregate(EOpParameters);
- functionNode->getSequence()->push_back(paramsNode);
- functionNode->getSequence()->push_back(functionBody);
+ TIntermFunctionDefinition *functionNode =
+ new TIntermFunctionDefinition(returnType, paramsNode, functionBody);
SetInternalFunctionName(functionNode->getFunctionSymbolInfo(), name);
- TType returnType(EbtVoid);
- functionNode->setType(returnType);
functionNode->getFunctionSymbolInfo()->setId(functionId);
return functionNode;
}
@@ -156,25 +154,22 @@
{
functionBody->push_back(deferredInit);
}
- TIntermAggregate *functionDefinition =
+ TIntermFunctionDefinition *functionDefinition =
CreateFunctionDefinitionNode(functionName, functionBodyNode, initFunctionId);
root->getSequence()->push_back(functionDefinition);
// Insert call into main function
for (TIntermNode *node : *root->getSequence())
{
- TIntermAggregate *nodeAgg = node->getAsAggregate();
- if (nodeAgg != nullptr && nodeAgg->getOp() == EOpFunction &&
- nodeAgg->getFunctionSymbolInfo()->isMain())
+ TIntermFunctionDefinition *nodeFunction = node->getAsFunctionDefinition();
+ if (nodeFunction != nullptr && nodeFunction->getFunctionSymbolInfo()->isMain())
{
TIntermAggregate *functionCallNode =
CreateFunctionCallNode(functionName, initFunctionId);
- TIntermNode *mainBody = nodeAgg->getSequence()->back();
- TIntermBlock *mainBodyBlock = mainBody->getAsBlock();
- ASSERT(mainBodyBlock != nullptr);
- mainBodyBlock->getSequence()->insert(mainBodyBlock->getSequence()->begin(),
- functionCallNode);
+ TIntermBlock *mainBody = nodeFunction->getBody();
+ ASSERT(mainBody != nullptr);
+ mainBody->getSequence()->insert(mainBody->getSequence()->begin(), functionCallNode);
}
}
}