Added modifier support to DSLFunction

This also includes a couple of fixes to DSLFunction error reporting.

Change-Id: Iab813143511c408df2dba7a4dc8beddea1a8e8d0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/427736
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/tests/SkSLDSLTest.cpp b/tests/SkSLDSLTest.cpp
index 9badb5e..8234f9b 100644
--- a/tests/SkSLDSLTest.cpp
+++ b/tests/SkSLDSLTest.cpp
@@ -126,7 +126,8 @@
 static SkSL::String stringize(DSLExpression& expr)         { return expr.release()->description(); }
 static SkSL::String stringize(DSLPossibleExpression& expr) { return expr.release()->description(); }
 static SkSL::String stringize(DSLBlock& blck)              { return blck.release()->description(); }
-static SkSL::String stringize(SkSL::IRNode& node)  { return node.description(); }
+static SkSL::String stringize(SkSL::IRNode& node)          { return node.description(); }
+static SkSL::String stringize(SkSL::Program& program)      { return program.description(); }
 
 template <typename T>
 static void expect_equal(skiatest::Reporter* r, int lineNumber, T& input, const char* expected) {
@@ -1978,3 +1979,24 @@
         "(sk_PerVertex.sk_Position.ww * sk_RTAdjust.yw)), 0.0, sk_PerVertex.sk_Position.w));"
         "}");
 }
+
+DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLInlining, r, ctxInfo) {
+    AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared());
+    DSLVar x(kFloat_Type, "x");
+    DSLFunction sqr(kFloat_Type, "sqr", x);
+    sqr.define(
+        Return(x * x)
+    );
+    DSLFunction(kVoid_Type, "main").define(
+        sk_FragColor() = (sqr(2), Half4(sqr(3)))
+    );
+    std::unique_ptr<SkSL::Program> program = ReleaseProgram();
+    EXPECT_EQUAL(*program,
+                 "layout(location = 0, index = 0, builtin = 10001) out half4 sk_FragColor;"
+                 "layout(builtin = 17)in bool sk_Clockwise;"
+                 "void main() {"
+                 "/* inlined: sqr */;"
+                 "/* inlined: sqr */;"
+                 "(sk_FragColor = (4.0 , half4(half(9.0))));"
+                 "}");
+}