Use FindMainBody to retrieve node of main()'s body
The patch addresses code duplication in cases in which main()'s body node
has to be retrieved from the AST.
TEST=angle_unittests
Change-Id: I0ccee41821a5ecb2cdf09f5a928b178d6c037587
Reviewed-on: https://chromium-review.googlesource.com/561521
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/DeferGlobalInitializers.cpp b/src/compiler/translator/DeferGlobalInitializers.cpp
index 72aa69e..67ccdf6 100644
--- a/src/compiler/translator/DeferGlobalInitializers.cpp
+++ b/src/compiler/translator/DeferGlobalInitializers.cpp
@@ -106,10 +106,7 @@
TIntermBlock *initGlobalsBlock = new TIntermBlock();
initGlobalsBlock->getSequence()->swap(*deferredInitializers);
- TIntermFunctionDefinition *main = FindMain(root);
- ASSERT(main != nullptr);
- TIntermBlock *mainBody = main->getBody();
- ASSERT(mainBody != nullptr);
+ TIntermBlock *mainBody = FindMainBody(root);
mainBody->getSequence()->insert(mainBody->getSequence()->begin(), initGlobalsBlock);
}
diff --git a/src/compiler/translator/EmulateGLFragColorBroadcast.cpp b/src/compiler/translator/EmulateGLFragColorBroadcast.cpp
index 55ab980..5432f67 100644
--- a/src/compiler/translator/EmulateGLFragColorBroadcast.cpp
+++ b/src/compiler/translator/EmulateGLFragColorBroadcast.cpp
@@ -84,7 +84,7 @@
{
return;
}
- TIntermSequence *mainSequence = FindMain(root)->getBody()->getSequence();
+ TIntermSequence *mainSequence = FindMainBody(root)->getSequence();
// Now insert statements
// gl_FragData[1] = gl_FragData[0];
// ...
diff --git a/src/compiler/translator/InitializeVariables.cpp b/src/compiler/translator/InitializeVariables.cpp
index 22c1cab..d8f9de5 100644
--- a/src/compiler/translator/InitializeVariables.cpp
+++ b/src/compiler/translator/InitializeVariables.cpp
@@ -224,10 +224,7 @@
ShShaderSpec shaderSpec,
const TExtensionBehavior &extensionBehavior)
{
-
- TIntermFunctionDefinition *main = FindMain(root);
- ASSERT(main != nullptr);
- TIntermBlock *body = main->getBody();
+ TIntermBlock *body = FindMainBody(root);
InsertInitCode(body->getSequence(), vars, symbolTable, shaderVersion, shaderSpec,
extensionBehavior);
}
diff --git a/src/compiler/translator/UseInterfaceBlockFields.cpp b/src/compiler/translator/UseInterfaceBlockFields.cpp
index c1391d4..bd9666f 100644
--- a/src/compiler/translator/UseInterfaceBlockFields.cpp
+++ b/src/compiler/translator/UseInterfaceBlockFields.cpp
@@ -100,9 +100,7 @@
const InterfaceBlockList &blocks,
const TSymbolTable &symbolTable)
{
- TIntermFunctionDefinition *main = FindMain(root);
- TIntermBlock *mainBody = main->getBody();
- ASSERT(mainBody);
+ TIntermBlock *mainBody = FindMainBody(root);
InsertUseCode(mainBody->getSequence(), blocks, symbolTable);
}