Reland "Fix field access and indexing of complex expressions"
Evaluating either kind of expression now works like all other
expressions - evaluate the inner part, then work with the resulting
values. Added unit tests for both of these that previously failed.
With this change, writeVariableExpression is only used for
VariableReference expressions, so adjust that, too.
Reland now safe, after fix to Value::operator[]
This reverts commit 1ea6d6051e325204516661caee0efd4be4a48ddb.
Bug: skia:11178
Cq-Include-Trybots: luci.skia.skia.primary:Test-Debian10-GCC-GCE-CPU-AVX2-x86-Debug-All-Docker
Change-Id: I14782fcdfef33a47a46334447c5847976721b21f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359564
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tests/SkSLInterpreterTest.cpp b/tests/SkSLInterpreterTest.cpp
index f1ecb20..04342a9 100644
--- a/tests/SkSLInterpreterTest.cpp
+++ b/tests/SkSLInterpreterTest.cpp
@@ -444,6 +444,27 @@
test(r, "float2 main(float x, float y) { return float2(x * x, y * y); }", value2, expected2);
}
+DEF_TEST(SkSLInterpreterFieldAccessComplex, r) {
+ const char* src = R"(
+ struct P { float x; float y; };
+ P make_point() { P p; p.x = 7; p.y = 3; return p; }
+ float main() { return make_point().y; }
+ )";
+
+ float expected = 3.0f;
+ test(r, src, /*in=*/nullptr, &expected);
+}
+
+DEF_TEST(SkSLInterpreterIndexComplex, r) {
+ const char* src = R"(
+ float2x2 make_mtx() { return float2x2(1, 2, 3, 4); }
+ float main() { return make_mtx()[1][0]; }
+ )";
+
+ float expected = 3.0f;
+ test(r, src, /*in=*/nullptr, &expected);
+}
+
DEF_TEST(SkSLInterpreterCompound, r) {
struct RectAndColor { SkIRect fRect; SkColor4f fColor; };
struct ManyRects { int fNumRects; RectAndColor fRects[4]; };