Fix parsing GLSL loop conditions that declare a variable
Now the variable declaration is included in the AST, so that the loop
body may refer to the variable. The variable declaration is placed in
a block that wraps the loop. This way we can still only have
TIntermTyped loop conditions in the AST, which keeps the code dealing
with loops fairly simple and type safe.
This change includes reversing the return value of executeInitializer,
so that it returns true on success and false on error. This is more in
line with other ParseContext member functions.
BUG=angleproject:2073
TEST=angle_end2end_tests
Change-Id: I5c4ecbf1b438d3fff6d6237c0dcf191e2a19664c
Reviewed-on: https://chromium-review.googlesource.com/539639
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp
index da72e38..f608a67 100644
--- a/src/tests/gl_tests/GLSLTest.cpp
+++ b/src/tests/gl_tests/GLSLTest.cpp
@@ -3080,6 +3080,36 @@
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
+// Test that a loop condition that has an initializer declares a variable.
+TEST_P(GLSLTest_ES3, ConditionInitializerDeclaresVariable)
+{
+ const std::string &fragmentShader =
+ "#version 300 es\n"
+ "precision highp float;\n"
+ "out vec4 my_FragColor;\n"
+ "void main()\n"
+ "{\n"
+ " float i = 0.0;\n"
+ " while (bool foo = (i < 1.5))\n"
+ " {\n"
+ " if (!foo)\n"
+ " {\n"
+ " ++i;\n"
+ " }\n"
+ " if (i > 3.5)\n"
+ " {\n"
+ " break;\n"
+ " }\n"
+ " ++i;\n"
+ " }\n"
+ " my_FragColor = vec4(i * 0.5 - 1.0, i * 0.5, 0.0, 1.0);\n"
+ "}\n";
+
+ ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
+ drawQuad(program.get(), "inputAttribute", 0.5f);
+ EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
+}
+
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(GLSLTest,
ES2_D3D9(),