Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "src/sksl/SkSLAnalysis.h" |
| 9 | |
John Stiles | 106e0cd | 2021-09-07 11:43:51 -0400 | [diff] [blame] | 10 | #include "include/private/SkFloatingPoint.h" |
Ethan Nicholas | daed259 | 2021-03-04 14:30:25 -0500 | [diff] [blame] | 11 | #include "include/private/SkSLModifiers.h" |
Ethan Nicholas | 24c1772 | 2021-03-09 13:10:59 -0500 | [diff] [blame] | 12 | #include "include/private/SkSLProgramElement.h" |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 13 | #include "include/private/SkSLSampleUsage.h" |
Ethan Nicholas | 24c1772 | 2021-03-09 13:10:59 -0500 | [diff] [blame] | 14 | #include "include/private/SkSLStatement.h" |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 15 | #include "include/sksl/SkSLErrorReporter.h" |
Brian Osman | 0018501 | 2021-02-04 16:07:11 -0500 | [diff] [blame] | 16 | #include "src/sksl/SkSLCompiler.h" |
Brian Osman | 448b2d5 | 2021-09-23 11:36:15 -0400 | [diff] [blame] | 17 | #include "src/sksl/SkSLConstantFolder.h" |
Ethan Nicholas | 1780755 | 2021-10-01 09:42:36 -0400 | [diff] [blame] | 18 | #include "src/sksl/analysis/SkSLProgramVisitor.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 19 | #include "src/sksl/ir/SkSLExpression.h" |
| 20 | #include "src/sksl/ir/SkSLProgram.h" |
Ethan Nicholas | 1780755 | 2021-10-01 09:42:36 -0400 | [diff] [blame] | 21 | #include "src/sksl/transform/SkSLProgramWriter.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 22 | |
| 23 | // ProgramElements |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 24 | #include "src/sksl/ir/SkSLExtension.h" |
| 25 | #include "src/sksl/ir/SkSLFunctionDefinition.h" |
| 26 | #include "src/sksl/ir/SkSLInterfaceBlock.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 27 | #include "src/sksl/ir/SkSLVarDeclarations.h" |
| 28 | |
| 29 | // Statements |
| 30 | #include "src/sksl/ir/SkSLBlock.h" |
| 31 | #include "src/sksl/ir/SkSLBreakStatement.h" |
| 32 | #include "src/sksl/ir/SkSLContinueStatement.h" |
| 33 | #include "src/sksl/ir/SkSLDiscardStatement.h" |
| 34 | #include "src/sksl/ir/SkSLDoStatement.h" |
| 35 | #include "src/sksl/ir/SkSLExpressionStatement.h" |
| 36 | #include "src/sksl/ir/SkSLForStatement.h" |
| 37 | #include "src/sksl/ir/SkSLIfStatement.h" |
| 38 | #include "src/sksl/ir/SkSLNop.h" |
| 39 | #include "src/sksl/ir/SkSLReturnStatement.h" |
| 40 | #include "src/sksl/ir/SkSLSwitchStatement.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 41 | |
| 42 | // Expressions |
| 43 | #include "src/sksl/ir/SkSLBinaryExpression.h" |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 44 | #include "src/sksl/ir/SkSLChildCall.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 45 | #include "src/sksl/ir/SkSLConstructor.h" |
John Stiles | e118278 | 2021-03-30 22:09:37 -0400 | [diff] [blame] | 46 | #include "src/sksl/ir/SkSLConstructorDiagonalMatrix.h" |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 47 | #include "src/sksl/ir/SkSLConstructorMatrixResize.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 48 | #include "src/sksl/ir/SkSLExternalFunctionCall.h" |
Brian Osman | be0b3b7 | 2021-01-06 14:27:35 -0500 | [diff] [blame] | 49 | #include "src/sksl/ir/SkSLExternalFunctionReference.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 50 | #include "src/sksl/ir/SkSLFieldAccess.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 51 | #include "src/sksl/ir/SkSLFunctionCall.h" |
| 52 | #include "src/sksl/ir/SkSLFunctionReference.h" |
| 53 | #include "src/sksl/ir/SkSLIndexExpression.h" |
John Stiles | 98c1f82 | 2020-09-09 14:18:53 -0400 | [diff] [blame] | 54 | #include "src/sksl/ir/SkSLInlineMarker.h" |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 55 | #include "src/sksl/ir/SkSLLiteral.h" |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 56 | #include "src/sksl/ir/SkSLPostfixExpression.h" |
| 57 | #include "src/sksl/ir/SkSLPrefixExpression.h" |
| 58 | #include "src/sksl/ir/SkSLSetting.h" |
| 59 | #include "src/sksl/ir/SkSLSwizzle.h" |
| 60 | #include "src/sksl/ir/SkSLTernaryExpression.h" |
| 61 | #include "src/sksl/ir/SkSLTypeReference.h" |
| 62 | #include "src/sksl/ir/SkSLVariableReference.h" |
| 63 | |
| 64 | namespace SkSL { |
| 65 | |
| 66 | namespace { |
| 67 | |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 68 | // Visitor that determines the merged SampleUsage for a given child in the program. |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 69 | class MergeSampleUsageVisitor : public ProgramVisitor { |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 70 | public: |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 71 | MergeSampleUsageVisitor(const Context& context, |
| 72 | const Variable& child, |
| 73 | bool writesToSampleCoords) |
| 74 | : fContext(context), fChild(child), fWritesToSampleCoords(writesToSampleCoords) {} |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 75 | |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 76 | SampleUsage visit(const Program& program) { |
| 77 | fUsage = SampleUsage(); // reset to none |
John Stiles | d7ab450 | 2020-09-24 22:41:00 -0400 | [diff] [blame] | 78 | INHERITED::visit(program); |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 79 | return fUsage; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Brian Osman | 8cdf28f | 2021-05-24 09:52:39 -0400 | [diff] [blame] | 82 | int elidedSampleCoordCount() const { return fElidedSampleCoordCount; } |
| 83 | |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 84 | protected: |
John Stiles | 933abe3 | 2020-08-28 11:58:40 -0400 | [diff] [blame] | 85 | const Context& fContext; |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 86 | const Variable& fChild; |
Brian Osman | 4d57111 | 2021-04-27 09:10:10 -0400 | [diff] [blame] | 87 | const bool fWritesToSampleCoords; |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 88 | SampleUsage fUsage; |
Brian Osman | 8cdf28f | 2021-05-24 09:52:39 -0400 | [diff] [blame] | 89 | int fElidedSampleCoordCount = 0; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 90 | |
| 91 | bool visitExpression(const Expression& e) override { |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 92 | // Looking for child(...) |
| 93 | if (e.is<ChildCall>() && &e.as<ChildCall>().child() == &fChild) { |
| 94 | // Determine the type of call at this site, and merge it with the accumulated state |
| 95 | const ExpressionArray& arguments = e.as<ChildCall>().arguments(); |
| 96 | SkASSERT(arguments.size() >= 1); |
| 97 | |
| 98 | const Expression* maybeCoords = arguments[0].get(); |
| 99 | if (maybeCoords->type() == *fContext.fTypes.fFloat2) { |
| 100 | // If the coords are a direct reference to the program's sample-coords, and those |
| 101 | // coords are never modified, we can conservatively turn this into PassThrough |
| 102 | // sampling. In all other cases, we consider it Explicit. |
| 103 | if (!fWritesToSampleCoords && maybeCoords->is<VariableReference>() && |
| 104 | maybeCoords->as<VariableReference>().variable()->modifiers().fLayout.fBuiltin == |
| 105 | SK_MAIN_COORDS_BUILTIN) { |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 106 | fUsage.merge(SampleUsage::PassThrough()); |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 107 | ++fElidedSampleCoordCount; |
| 108 | } else { |
| 109 | fUsage.merge(SampleUsage::Explicit()); |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 110 | } |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 111 | } else { |
| 112 | // child(inputColor) or child(srcColor, dstColor) -> PassThrough |
| 113 | fUsage.merge(SampleUsage::PassThrough()); |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
John Stiles | d7ab450 | 2020-09-24 22:41:00 -0400 | [diff] [blame] | 117 | return INHERITED::visitExpression(e); |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 118 | } |
| 119 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 120 | using INHERITED = ProgramVisitor; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 121 | }; |
| 122 | |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 123 | // Visitor that searches through the program for references to a particular builtin variable |
| 124 | class BuiltinVariableVisitor : public ProgramVisitor { |
| 125 | public: |
| 126 | BuiltinVariableVisitor(int builtin) : fBuiltin(builtin) {} |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 127 | |
| 128 | bool visitExpression(const Expression& e) override { |
Brian Osman | 79457ef | 2020-09-24 15:01:27 -0400 | [diff] [blame] | 129 | if (e.is<VariableReference>()) { |
John Stiles | 403a363 | 2020-08-20 12:11:48 -0400 | [diff] [blame] | 130 | const VariableReference& var = e.as<VariableReference>(); |
Ethan Nicholas | 7868692 | 2020-10-08 06:46:27 -0400 | [diff] [blame] | 131 | return var.variable()->modifiers().fLayout.fBuiltin == fBuiltin; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 132 | } |
John Stiles | d7ab450 | 2020-09-24 22:41:00 -0400 | [diff] [blame] | 133 | return INHERITED::visitExpression(e); |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 136 | int fBuiltin; |
| 137 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 138 | using INHERITED = ProgramVisitor; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 139 | }; |
| 140 | |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 141 | // Visitor that searches for child calls from a function other than main() |
Brian Osman | 04d79fc | 2021-07-02 13:25:35 -0400 | [diff] [blame] | 142 | class SampleOutsideMainVisitor : public ProgramVisitor { |
| 143 | public: |
| 144 | SampleOutsideMainVisitor() {} |
| 145 | |
| 146 | bool visitExpression(const Expression& e) override { |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 147 | if (e.is<ChildCall>()) { |
| 148 | return true; |
Brian Osman | 04d79fc | 2021-07-02 13:25:35 -0400 | [diff] [blame] | 149 | } |
| 150 | return INHERITED::visitExpression(e); |
| 151 | } |
| 152 | |
| 153 | bool visitProgramElement(const ProgramElement& p) override { |
| 154 | return p.is<FunctionDefinition>() && |
| 155 | !p.as<FunctionDefinition>().declaration().isMain() && |
| 156 | INHERITED::visitProgramElement(p); |
| 157 | } |
| 158 | |
| 159 | using INHERITED = ProgramVisitor; |
| 160 | }; |
| 161 | |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 162 | // Visitor that counts the number of nodes visited |
| 163 | class NodeCountVisitor : public ProgramVisitor { |
| 164 | public: |
John Stiles | 2c1e492 | 2020-10-01 09:14:14 -0400 | [diff] [blame] | 165 | NodeCountVisitor(int limit) : fLimit(limit) {} |
| 166 | |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 167 | int visit(const Statement& s) { |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 168 | this->visitStatement(s); |
| 169 | return fCount; |
| 170 | } |
| 171 | |
| 172 | bool visitExpression(const Expression& e) override { |
| 173 | ++fCount; |
John Stiles | 9b9415e | 2020-11-23 14:48:06 -0500 | [diff] [blame] | 174 | return (fCount >= fLimit) || INHERITED::visitExpression(e); |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | bool visitProgramElement(const ProgramElement& p) override { |
| 178 | ++fCount; |
John Stiles | 9b9415e | 2020-11-23 14:48:06 -0500 | [diff] [blame] | 179 | return (fCount >= fLimit) || INHERITED::visitProgramElement(p); |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | bool visitStatement(const Statement& s) override { |
| 183 | ++fCount; |
John Stiles | 9b9415e | 2020-11-23 14:48:06 -0500 | [diff] [blame] | 184 | return (fCount >= fLimit) || INHERITED::visitStatement(s); |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | private: |
John Stiles | 2c1e492 | 2020-10-01 09:14:14 -0400 | [diff] [blame] | 188 | int fCount = 0; |
| 189 | int fLimit; |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 190 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 191 | using INHERITED = ProgramVisitor; |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 192 | }; |
| 193 | |
Ethan Nicholas | 765d2fe | 2020-08-26 08:29:55 -0400 | [diff] [blame] | 194 | class VariableWriteVisitor : public ProgramVisitor { |
| 195 | public: |
| 196 | VariableWriteVisitor(const Variable* var) |
| 197 | : fVar(var) {} |
| 198 | |
| 199 | bool visit(const Statement& s) { |
| 200 | return this->visitStatement(s); |
| 201 | } |
| 202 | |
| 203 | bool visitExpression(const Expression& e) override { |
Brian Osman | 79457ef | 2020-09-24 15:01:27 -0400 | [diff] [blame] | 204 | if (e.is<VariableReference>()) { |
Ethan Nicholas | 765d2fe | 2020-08-26 08:29:55 -0400 | [diff] [blame] | 205 | const VariableReference& ref = e.as<VariableReference>(); |
Ethan Nicholas | 453f67f | 2020-10-09 10:43:45 -0400 | [diff] [blame] | 206 | if (ref.variable() == fVar && |
| 207 | (ref.refKind() == VariableReference::RefKind::kWrite || |
| 208 | ref.refKind() == VariableReference::RefKind::kReadWrite || |
| 209 | ref.refKind() == VariableReference::RefKind::kPointer)) { |
Ethan Nicholas | 765d2fe | 2020-08-26 08:29:55 -0400 | [diff] [blame] | 210 | return true; |
| 211 | } |
| 212 | } |
John Stiles | d7ab450 | 2020-09-24 22:41:00 -0400 | [diff] [blame] | 213 | return INHERITED::visitExpression(e); |
Ethan Nicholas | 765d2fe | 2020-08-26 08:29:55 -0400 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | private: |
| 217 | const Variable* fVar; |
| 218 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 219 | using INHERITED = ProgramVisitor; |
Ethan Nicholas | 765d2fe | 2020-08-26 08:29:55 -0400 | [diff] [blame] | 220 | }; |
| 221 | |
John Stiles | a976da7 | 2020-09-25 23:06:26 -0400 | [diff] [blame] | 222 | // If a caller doesn't care about errors, we can use this trivial reporter that just counts up. |
| 223 | class TrivialErrorReporter : public ErrorReporter { |
| 224 | public: |
John Stiles | bb8cf58 | 2021-08-26 23:34:59 -0400 | [diff] [blame] | 225 | ~TrivialErrorReporter() override { this->reportPendingErrors({}); } |
Ethan Nicholas | 3272412 | 2021-09-07 13:49:07 -0400 | [diff] [blame] | 226 | void handleError(skstd::string_view, PositionInfo) override {} |
John Stiles | a976da7 | 2020-09-25 23:06:26 -0400 | [diff] [blame] | 227 | }; |
| 228 | |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 229 | // This isn't actually using ProgramVisitor, because it only considers a subset of the fields for |
| 230 | // any given expression kind. For instance, when indexing an array (e.g. `x[1]`), we only want to |
| 231 | // know if the base (`x`) is assignable; the index expression (`1`) doesn't need to be. |
| 232 | class IsAssignableVisitor { |
| 233 | public: |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 234 | IsAssignableVisitor(ErrorReporter* errors) : fErrors(errors) {} |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 235 | |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 236 | bool visit(Expression& expr, Analysis::AssignmentInfo* info) { |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 237 | int oldErrorCount = fErrors->errorCount(); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 238 | this->visitExpression(expr); |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 239 | if (info) { |
| 240 | info->fAssignedVar = fAssignedVar; |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 241 | } |
Ethan Nicholas | 67a0a8a | 2021-01-13 12:36:02 -0500 | [diff] [blame] | 242 | return fErrors->errorCount() == oldErrorCount; |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void visitExpression(Expression& expr) { |
| 246 | switch (expr.kind()) { |
| 247 | case Expression::Kind::kVariableReference: { |
| 248 | VariableReference& varRef = expr.as<VariableReference>(); |
Ethan Nicholas | 7868692 | 2020-10-08 06:46:27 -0400 | [diff] [blame] | 249 | const Variable* var = varRef.variable(); |
Brian Osman | e49703f | 2021-04-19 11:15:24 -0400 | [diff] [blame] | 250 | if (var->modifiers().fFlags & (Modifiers::kConst_Flag | Modifiers::kUniform_Flag)) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 251 | fErrors->error(expr.fLine, |
Ethan Nicholas | e2c4999 | 2020-10-05 11:49:11 -0400 | [diff] [blame] | 252 | "cannot modify immutable variable '" + var->name() + "'"); |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 253 | } else { |
| 254 | SkASSERT(fAssignedVar == nullptr); |
| 255 | fAssignedVar = &varRef; |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 256 | } |
| 257 | break; |
| 258 | } |
| 259 | case Expression::Kind::kFieldAccess: |
Ethan Nicholas | 7a95b20 | 2020-10-09 11:55:40 -0400 | [diff] [blame] | 260 | this->visitExpression(*expr.as<FieldAccess>().base()); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 261 | break; |
| 262 | |
| 263 | case Expression::Kind::kSwizzle: { |
| 264 | const Swizzle& swizzle = expr.as<Swizzle>(); |
| 265 | this->checkSwizzleWrite(swizzle); |
Ethan Nicholas | 6b4d581 | 2020-10-12 16:11:51 -0400 | [diff] [blame] | 266 | this->visitExpression(*swizzle.base()); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 267 | break; |
| 268 | } |
John Stiles | 47c0a74 | 2021-02-09 09:30:35 -0500 | [diff] [blame] | 269 | case Expression::Kind::kIndex: |
| 270 | this->visitExpression(*expr.as<IndexExpression>().base()); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 271 | break; |
John Stiles | 47c0a74 | 2021-02-09 09:30:35 -0500 | [diff] [blame] | 272 | |
Ethan Nicholas | c898d04 | 2021-08-28 19:53:34 -0400 | [diff] [blame] | 273 | case Expression::Kind::kPoison: |
| 274 | break; |
| 275 | |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 276 | default: |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 277 | fErrors->error(expr.fLine, "cannot assign to this expression"); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 278 | break; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | private: |
| 283 | void checkSwizzleWrite(const Swizzle& swizzle) { |
| 284 | int bits = 0; |
John Stiles | 6e88e04 | 2021-02-19 14:09:38 -0500 | [diff] [blame] | 285 | for (int8_t idx : swizzle.components()) { |
| 286 | SkASSERT(idx >= SwizzleComponent::X && idx <= SwizzleComponent::W); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 287 | int bit = 1 << idx; |
| 288 | if (bits & bit) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 289 | fErrors->error(swizzle.fLine, |
John Stiles | a976da7 | 2020-09-25 23:06:26 -0400 | [diff] [blame] | 290 | "cannot write to the same swizzle field more than once"); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 291 | break; |
| 292 | } |
| 293 | bits |= bit; |
| 294 | } |
| 295 | } |
| 296 | |
John Stiles | a976da7 | 2020-09-25 23:06:26 -0400 | [diff] [blame] | 297 | ErrorReporter* fErrors; |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 298 | VariableReference* fAssignedVar = nullptr; |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 299 | |
| 300 | using INHERITED = ProgramVisitor; |
| 301 | }; |
| 302 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 303 | } // namespace |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 304 | |
| 305 | //////////////////////////////////////////////////////////////////////////////// |
| 306 | // Analysis |
| 307 | |
Brian Osman | 4d57111 | 2021-04-27 09:10:10 -0400 | [diff] [blame] | 308 | SampleUsage Analysis::GetSampleUsage(const Program& program, |
Brian Osman | 293497e | 2021-08-24 14:08:50 -0400 | [diff] [blame] | 309 | const Variable& child, |
Brian Osman | 8cdf28f | 2021-05-24 09:52:39 -0400 | [diff] [blame] | 310 | bool writesToSampleCoords, |
| 311 | int* elidedSampleCoordCount) { |
Brian Osman | 293497e | 2021-08-24 14:08:50 -0400 | [diff] [blame] | 312 | MergeSampleUsageVisitor visitor(*program.fContext, child, writesToSampleCoords); |
Brian Osman | 8cdf28f | 2021-05-24 09:52:39 -0400 | [diff] [blame] | 313 | SampleUsage result = visitor.visit(program); |
| 314 | if (elidedSampleCoordCount) { |
| 315 | *elidedSampleCoordCount += visitor.elidedSampleCoordCount(); |
| 316 | } |
| 317 | return result; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 318 | } |
| 319 | |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 320 | bool Analysis::ReferencesBuiltin(const Program& program, int builtin) { |
| 321 | BuiltinVariableVisitor visitor(builtin); |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 322 | return visitor.visit(program); |
| 323 | } |
| 324 | |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 325 | bool Analysis::ReferencesSampleCoords(const Program& program) { |
| 326 | return Analysis::ReferencesBuiltin(program, SK_MAIN_COORDS_BUILTIN); |
| 327 | } |
| 328 | |
| 329 | bool Analysis::ReferencesFragCoords(const Program& program) { |
| 330 | return Analysis::ReferencesBuiltin(program, SK_FRAGCOORD_BUILTIN); |
| 331 | } |
| 332 | |
Brian Osman | 04d79fc | 2021-07-02 13:25:35 -0400 | [diff] [blame] | 333 | bool Analysis::CallsSampleOutsideMain(const Program& program) { |
| 334 | SampleOutsideMainVisitor visitor; |
| 335 | return visitor.visit(program); |
| 336 | } |
| 337 | |
Ethan Nicholas | 98eae1e | 2021-09-01 14:37:29 -0400 | [diff] [blame] | 338 | bool Analysis::DetectVarDeclarationWithoutScope(const Statement& stmt, ErrorReporter* errors) { |
| 339 | // A variable declaration can create either a lone VarDeclaration or an unscoped Block |
| 340 | // containing multiple VarDeclaration statements. We need to detect either case. |
| 341 | const Variable* var; |
| 342 | if (stmt.is<VarDeclaration>()) { |
| 343 | // The single-variable case. No blocks at all. |
| 344 | var = &stmt.as<VarDeclaration>().var(); |
| 345 | } else if (stmt.is<Block>()) { |
| 346 | // The multiple-variable case: an unscoped, non-empty block... |
| 347 | const Block& block = stmt.as<Block>(); |
| 348 | if (block.isScope() || block.children().empty()) { |
| 349 | return false; |
| 350 | } |
| 351 | // ... holding a variable declaration. |
| 352 | const Statement& innerStmt = *block.children().front(); |
| 353 | if (!innerStmt.is<VarDeclaration>()) { |
| 354 | return false; |
| 355 | } |
| 356 | var = &innerStmt.as<VarDeclaration>().var(); |
| 357 | } else { |
| 358 | // This statement wasn't a variable declaration. No problem. |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | // Report an error. |
| 363 | SkASSERT(var); |
| 364 | if (errors) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 365 | errors->error(stmt.fLine, "variable '" + var->name() + "' must be created in a scope"); |
Ethan Nicholas | 98eae1e | 2021-09-01 14:37:29 -0400 | [diff] [blame] | 366 | } |
| 367 | return true; |
| 368 | } |
| 369 | |
John Stiles | 9b9415e | 2020-11-23 14:48:06 -0500 | [diff] [blame] | 370 | int Analysis::NodeCountUpToLimit(const FunctionDefinition& function, int limit) { |
| 371 | return NodeCountVisitor{limit}.visit(*function.body()); |
Ethan Nicholas | 6e0fa40 | 2020-08-20 14:08:23 -0400 | [diff] [blame] | 372 | } |
| 373 | |
Ethan Nicholas | 765d2fe | 2020-08-26 08:29:55 -0400 | [diff] [blame] | 374 | bool Analysis::StatementWritesToVariable(const Statement& stmt, const Variable& var) { |
| 375 | return VariableWriteVisitor(&var).visit(stmt); |
| 376 | } |
| 377 | |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 378 | bool Analysis::IsAssignable(Expression& expr, AssignmentInfo* info, ErrorReporter* errors) { |
John Stiles | a976da7 | 2020-09-25 23:06:26 -0400 | [diff] [blame] | 379 | TrivialErrorReporter trivialErrors; |
John Stiles | b21fac2 | 2020-12-04 15:36:49 -0500 | [diff] [blame] | 380 | return IsAssignableVisitor{errors ? errors : &trivialErrors}.visit(expr, info); |
John Stiles | dce4d3e | 2020-09-25 14:35:13 -0400 | [diff] [blame] | 381 | } |
| 382 | |
John Stiles | bb8cf58 | 2021-08-26 23:34:59 -0400 | [diff] [blame] | 383 | bool Analysis::UpdateVariableRefKind(Expression* expr, |
| 384 | VariableReference::RefKind kind, |
| 385 | ErrorReporter* errors) { |
John Stiles | 516704b | 2021-02-26 15:01:57 -0500 | [diff] [blame] | 386 | Analysis::AssignmentInfo info; |
| 387 | if (!Analysis::IsAssignable(*expr, &info, errors)) { |
| 388 | return false; |
| 389 | } |
| 390 | if (!info.fAssignedVar) { |
John Stiles | bb8cf58 | 2021-08-26 23:34:59 -0400 | [diff] [blame] | 391 | if (errors) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 392 | errors->error(expr->fLine, "can't assign to expression '" + expr->description() + "'"); |
John Stiles | bb8cf58 | 2021-08-26 23:34:59 -0400 | [diff] [blame] | 393 | } |
John Stiles | 516704b | 2021-02-26 15:01:57 -0500 | [diff] [blame] | 394 | return false; |
| 395 | } |
| 396 | info.fAssignedVar->setRefKind(kind); |
| 397 | return true; |
| 398 | } |
| 399 | |
John Stiles | c30fbca | 2020-11-19 16:25:49 -0500 | [diff] [blame] | 400 | bool Analysis::IsTrivialExpression(const Expression& expr) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 401 | return expr.is<Literal>() || |
John Stiles | c30fbca | 2020-11-19 16:25:49 -0500 | [diff] [blame] | 402 | expr.is<VariableReference>() || |
| 403 | (expr.is<Swizzle>() && |
| 404 | IsTrivialExpression(*expr.as<Swizzle>().base())) || |
| 405 | (expr.is<FieldAccess>() && |
| 406 | IsTrivialExpression(*expr.as<FieldAccess>().base())) || |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 407 | (expr.isAnyConstructor() && |
| 408 | expr.asAnyConstructor().argumentSpan().size() == 1 && |
| 409 | IsTrivialExpression(*expr.asAnyConstructor().argumentSpan().front())) || |
| 410 | (expr.isAnyConstructor() && |
John Stiles | c30fbca | 2020-11-19 16:25:49 -0500 | [diff] [blame] | 411 | expr.isConstantOrUniform()) || |
| 412 | (expr.is<IndexExpression>() && |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 413 | expr.as<IndexExpression>().index()->isIntLiteral() && |
John Stiles | c30fbca | 2020-11-19 16:25:49 -0500 | [diff] [blame] | 414 | IsTrivialExpression(*expr.as<IndexExpression>().base())); |
| 415 | } |
| 416 | |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 417 | bool Analysis::IsSameExpressionTree(const Expression& left, const Expression& right) { |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 418 | if (left.kind() != right.kind() || left.type() != right.type()) { |
| 419 | return false; |
| 420 | } |
| 421 | |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 422 | // This isn't a fully exhaustive list of expressions by any stretch of the imagination; for |
| 423 | // instance, `x[y+1] = x[y+1]` isn't detected because we don't look at BinaryExpressions. |
| 424 | // Since this is intended to be used for optimization purposes, handling the common cases is |
| 425 | // sufficient. |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 426 | switch (left.kind()) { |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 427 | case Expression::Kind::kLiteral: |
| 428 | return left.as<Literal>().value() == right.as<Literal>().value(); |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 429 | |
John Stiles | 7384b37 | 2021-04-01 13:48:15 -0400 | [diff] [blame] | 430 | case Expression::Kind::kConstructorArray: |
John Stiles | e3ae968 | 2021-08-05 10:35:01 -0400 | [diff] [blame] | 431 | case Expression::Kind::kConstructorArrayCast: |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 432 | case Expression::Kind::kConstructorCompound: |
| 433 | case Expression::Kind::kConstructorCompoundCast: |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 434 | case Expression::Kind::kConstructorDiagonalMatrix: |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 435 | case Expression::Kind::kConstructorMatrixResize: |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 436 | case Expression::Kind::kConstructorScalarCast: |
John Stiles | d47330f | 2021-04-08 23:25:52 -0400 | [diff] [blame] | 437 | case Expression::Kind::kConstructorStruct: |
John Stiles | 268a73f | 2021-04-07 12:30:22 -0400 | [diff] [blame] | 438 | case Expression::Kind::kConstructorSplat: { |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 439 | if (left.kind() != right.kind()) { |
| 440 | return false; |
| 441 | } |
John Stiles | 7384b37 | 2021-04-01 13:48:15 -0400 | [diff] [blame] | 442 | const AnyConstructor& leftCtor = left.asAnyConstructor(); |
| 443 | const AnyConstructor& rightCtor = right.asAnyConstructor(); |
| 444 | const auto leftSpan = leftCtor.argumentSpan(); |
| 445 | const auto rightSpan = rightCtor.argumentSpan(); |
| 446 | if (leftSpan.size() != rightSpan.size()) { |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 447 | return false; |
| 448 | } |
John Stiles | 7384b37 | 2021-04-01 13:48:15 -0400 | [diff] [blame] | 449 | for (size_t index = 0; index < leftSpan.size(); ++index) { |
| 450 | if (!IsSameExpressionTree(*leftSpan[index], *rightSpan[index])) { |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 451 | return false; |
| 452 | } |
| 453 | } |
| 454 | return true; |
| 455 | } |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 456 | case Expression::Kind::kFieldAccess: |
| 457 | return left.as<FieldAccess>().fieldIndex() == right.as<FieldAccess>().fieldIndex() && |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 458 | IsSameExpressionTree(*left.as<FieldAccess>().base(), |
| 459 | *right.as<FieldAccess>().base()); |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 460 | |
| 461 | case Expression::Kind::kIndex: |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 462 | return IsSameExpressionTree(*left.as<IndexExpression>().index(), |
| 463 | *right.as<IndexExpression>().index()) && |
| 464 | IsSameExpressionTree(*left.as<IndexExpression>().base(), |
| 465 | *right.as<IndexExpression>().base()); |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 466 | |
| 467 | case Expression::Kind::kSwizzle: |
| 468 | return left.as<Swizzle>().components() == right.as<Swizzle>().components() && |
John Stiles | 5676c57 | 2021-03-08 17:10:52 -0500 | [diff] [blame] | 469 | IsSameExpressionTree(*left.as<Swizzle>().base(), *right.as<Swizzle>().base()); |
John Stiles | 95d0bad | 2021-03-01 17:02:28 -0500 | [diff] [blame] | 470 | |
| 471 | case Expression::Kind::kVariableReference: |
| 472 | return left.as<VariableReference>().variable() == |
| 473 | right.as<VariableReference>().variable(); |
| 474 | |
| 475 | default: |
| 476 | return false; |
| 477 | } |
| 478 | } |
| 479 | |
Brian Osman | ea485e5 | 2021-01-15 13:20:32 -0500 | [diff] [blame] | 480 | class ES2IndexingVisitor : public ProgramVisitor { |
| 481 | public: |
| 482 | ES2IndexingVisitor(ErrorReporter& errors) : fErrors(errors) {} |
| 483 | |
| 484 | bool visitStatement(const Statement& s) override { |
| 485 | if (s.is<ForStatement>()) { |
| 486 | const ForStatement& f = s.as<ForStatement>(); |
| 487 | SkASSERT(f.initializer() && f.initializer()->is<VarDeclaration>()); |
| 488 | const Variable* var = &f.initializer()->as<VarDeclaration>().var(); |
| 489 | auto [iter, inserted] = fLoopIndices.insert(var); |
| 490 | SkASSERT(inserted); |
| 491 | bool result = this->visitStatement(*f.statement()); |
| 492 | fLoopIndices.erase(iter); |
| 493 | return result; |
| 494 | } |
| 495 | return INHERITED::visitStatement(s); |
| 496 | } |
| 497 | |
| 498 | bool visitExpression(const Expression& e) override { |
| 499 | if (e.is<IndexExpression>()) { |
| 500 | const IndexExpression& i = e.as<IndexExpression>(); |
John Stiles | 2dfbf99 | 2021-10-06 20:06:41 -0400 | [diff] [blame] | 501 | if (!Analysis::IsConstantIndexExpression(*i.index(), &fLoopIndices)) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 502 | fErrors.error(i.fLine, "index expression must be constant"); |
Brian Osman | ea485e5 | 2021-01-15 13:20:32 -0500 | [diff] [blame] | 503 | return true; |
| 504 | } |
| 505 | } |
| 506 | return INHERITED::visitExpression(e); |
| 507 | } |
| 508 | |
| 509 | using ProgramVisitor::visitProgramElement; |
| 510 | |
| 511 | private: |
| 512 | ErrorReporter& fErrors; |
| 513 | std::set<const Variable*> fLoopIndices; |
| 514 | using INHERITED = ProgramVisitor; |
| 515 | }; |
| 516 | |
Brian Osman | ea485e5 | 2021-01-15 13:20:32 -0500 | [diff] [blame] | 517 | void Analysis::ValidateIndexingForES2(const ProgramElement& pe, ErrorReporter& errors) { |
| 518 | ES2IndexingVisitor visitor(errors); |
| 519 | visitor.visitProgramElement(pe); |
| 520 | } |
| 521 | |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 522 | void Analysis::VerifyStaticTestsAndExpressions(const Program& program) { |
| 523 | class TestsAndExpressions : public ProgramVisitor { |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 524 | public: |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 525 | TestsAndExpressions(const Context& ctx) : fContext(ctx) {} |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 526 | |
| 527 | using ProgramVisitor::visitProgramElement; |
| 528 | |
| 529 | bool visitStatement(const Statement& stmt) override { |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 530 | if (!fContext.fConfig->fSettings.fPermitInvalidStaticTests) { |
| 531 | switch (stmt.kind()) { |
| 532 | case Statement::Kind::kIf: |
| 533 | if (stmt.as<IfStatement>().isStatic()) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 534 | fContext.fErrors->error(stmt.fLine, "static if has non-static test"); |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 535 | } |
| 536 | break; |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 537 | |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 538 | case Statement::Kind::kSwitch: |
| 539 | if (stmt.as<SwitchStatement>().isStatic()) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 540 | fContext.fErrors->error(stmt.fLine, |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 541 | "static switch has non-static test"); |
| 542 | } |
| 543 | break; |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 544 | |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 545 | default: |
| 546 | break; |
| 547 | } |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 548 | } |
| 549 | return INHERITED::visitStatement(stmt); |
| 550 | } |
| 551 | |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 552 | bool visitExpression(const Expression& expr) override { |
| 553 | switch (expr.kind()) { |
| 554 | case Expression::Kind::kFunctionCall: { |
| 555 | const FunctionDeclaration& decl = expr.as<FunctionCall>().function(); |
| 556 | if (!decl.isBuiltin() && !decl.definition()) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 557 | fContext.fErrors->error(expr.fLine, "function '" + decl.description() + |
| 558 | "' is not defined"); |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 559 | } |
| 560 | break; |
| 561 | } |
| 562 | case Expression::Kind::kExternalFunctionReference: |
| 563 | case Expression::Kind::kFunctionReference: |
Brian Osman | 3099f79 | 2021-09-01 13:12:16 -0400 | [diff] [blame] | 564 | case Expression::Kind::kMethodReference: |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 565 | case Expression::Kind::kTypeReference: |
| 566 | SkDEBUGFAIL("invalid reference-expr, should have been reported by coerce()"); |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 567 | fContext.fErrors->error(expr.fLine, "invalid expression"); |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 568 | break; |
| 569 | default: |
| 570 | if (expr.type() == *fContext.fTypes.fInvalid) { |
Ethan Nicholas | 89cfde1 | 2021-09-27 11:20:34 -0400 | [diff] [blame] | 571 | fContext.fErrors->error(expr.fLine, "invalid expression"); |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 572 | } |
| 573 | break; |
| 574 | } |
| 575 | return INHERITED::visitExpression(expr); |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | private: |
| 579 | using INHERITED = ProgramVisitor; |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 580 | const Context& fContext; |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 581 | }; |
| 582 | |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 583 | // Check all of the program's owned elements. (Built-in elements are assumed to be valid.) |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 584 | TestsAndExpressions visitor{*program.fContext}; |
John Stiles | bcaacec | 2021-10-06 20:06:55 -0400 | [diff] [blame] | 585 | for (const std::unique_ptr<ProgramElement>& element : program.fOwnedElements) { |
John Stiles | 2ecc595 | 2021-09-01 14:41:36 -0400 | [diff] [blame] | 586 | visitor.visitProgramElement(*element); |
John Stiles | 0fc6bed | 2021-09-01 11:35:59 -0400 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 590 | //////////////////////////////////////////////////////////////////////////////// |
| 591 | // ProgramVisitor |
| 592 | |
Brian Osman | 133724c | 2020-10-28 14:14:39 -0400 | [diff] [blame] | 593 | bool ProgramVisitor::visit(const Program& program) { |
| 594 | for (const ProgramElement* pe : program.elements()) { |
Brian Osman | 1179fcf | 2020-10-08 16:04:40 -0400 | [diff] [blame] | 595 | if (this->visitProgramElement(*pe)) { |
John Stiles | 933abe3 | 2020-08-28 11:58:40 -0400 | [diff] [blame] | 596 | return true; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 597 | } |
| 598 | } |
John Stiles | 933abe3 | 2020-08-28 11:58:40 -0400 | [diff] [blame] | 599 | return false; |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 600 | } |
| 601 | |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 602 | template <typename T> bool TProgramVisitor<T>::visitExpression(typename T::Expression& e) { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 603 | switch (e.kind()) { |
John Stiles | 6d02346 | 2021-10-06 12:51:10 -0400 | [diff] [blame] | 604 | case Expression::Kind::kCodeString: |
Brian Osman | be0b3b7 | 2021-01-06 14:27:35 -0500 | [diff] [blame] | 605 | case Expression::Kind::kExternalFunctionReference: |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 606 | case Expression::Kind::kFunctionReference: |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 607 | case Expression::Kind::kLiteral: |
Brian Osman | 3099f79 | 2021-09-01 13:12:16 -0400 | [diff] [blame] | 608 | case Expression::Kind::kMethodReference: |
Ethan Nicholas | 549c6b8 | 2021-06-25 12:31:44 -0400 | [diff] [blame] | 609 | case Expression::Kind::kPoison: |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 610 | case Expression::Kind::kSetting: |
| 611 | case Expression::Kind::kTypeReference: |
| 612 | case Expression::Kind::kVariableReference: |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 613 | // Leaf expressions return false |
| 614 | return false; |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 615 | |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 616 | case Expression::Kind::kBinary: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 617 | auto& b = e.template as<BinaryExpression>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 618 | return (b.left() && this->visitExpressionPtr(b.left())) || |
| 619 | (b.right() && this->visitExpressionPtr(b.right())); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 620 | } |
Brian Osman | eb0f29d | 2021-08-04 11:34:16 -0400 | [diff] [blame] | 621 | case Expression::Kind::kChildCall: { |
| 622 | // We don't visit the child variable itself, just the arguments |
| 623 | auto& c = e.template as<ChildCall>(); |
| 624 | for (auto& arg : c.arguments()) { |
| 625 | if (arg && this->visitExpressionPtr(arg)) { return true; } |
| 626 | } |
| 627 | return false; |
| 628 | } |
John Stiles | 7384b37 | 2021-04-01 13:48:15 -0400 | [diff] [blame] | 629 | case Expression::Kind::kConstructorArray: |
John Stiles | e3ae968 | 2021-08-05 10:35:01 -0400 | [diff] [blame] | 630 | case Expression::Kind::kConstructorArrayCast: |
John Stiles | 8cad637 | 2021-04-07 12:31:13 -0400 | [diff] [blame] | 631 | case Expression::Kind::kConstructorCompound: |
| 632 | case Expression::Kind::kConstructorCompoundCast: |
John Stiles | 2938eea | 2021-04-01 18:58:25 -0400 | [diff] [blame] | 633 | case Expression::Kind::kConstructorDiagonalMatrix: |
John Stiles | 5abb9e1 | 2021-04-06 13:47:19 -0400 | [diff] [blame] | 634 | case Expression::Kind::kConstructorMatrixResize: |
John Stiles | fd7252f | 2021-04-04 22:24:40 -0400 | [diff] [blame] | 635 | case Expression::Kind::kConstructorScalarCast: |
John Stiles | d47330f | 2021-04-08 23:25:52 -0400 | [diff] [blame] | 636 | case Expression::Kind::kConstructorSplat: |
| 637 | case Expression::Kind::kConstructorStruct: { |
John Stiles | 7384b37 | 2021-04-01 13:48:15 -0400 | [diff] [blame] | 638 | auto& c = e.asAnyConstructor(); |
| 639 | for (auto& arg : c.argumentSpan()) { |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 640 | if (this->visitExpressionPtr(arg)) { return true; } |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 641 | } |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 642 | return false; |
| 643 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 644 | case Expression::Kind::kExternalFunctionCall: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 645 | auto& c = e.template as<ExternalFunctionCall>(); |
Ethan Nicholas | 6e86ec9 | 2020-09-30 14:29:56 -0400 | [diff] [blame] | 646 | for (auto& arg : c.arguments()) { |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 647 | if (this->visitExpressionPtr(arg)) { return true; } |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 648 | } |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 649 | return false; |
| 650 | } |
John Stiles | d7ab450 | 2020-09-24 22:41:00 -0400 | [diff] [blame] | 651 | case Expression::Kind::kFieldAccess: |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 652 | return this->visitExpressionPtr(e.template as<FieldAccess>().base()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 653 | |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 654 | case Expression::Kind::kFunctionCall: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 655 | auto& c = e.template as<FunctionCall>(); |
Ethan Nicholas | 0dec992 | 2020-10-05 15:51:52 -0400 | [diff] [blame] | 656 | for (auto& arg : c.arguments()) { |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 657 | if (arg && this->visitExpressionPtr(arg)) { return true; } |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 658 | } |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 659 | return false; |
| 660 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 661 | case Expression::Kind::kIndex: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 662 | auto& i = e.template as<IndexExpression>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 663 | return this->visitExpressionPtr(i.base()) || this->visitExpressionPtr(i.index()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 664 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 665 | case Expression::Kind::kPostfix: |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 666 | return this->visitExpressionPtr(e.template as<PostfixExpression>().operand()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 667 | |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 668 | case Expression::Kind::kPrefix: |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 669 | return this->visitExpressionPtr(e.template as<PrefixExpression>().operand()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 670 | |
Brian Osman | 010ce6a | 2020-10-19 16:34:10 -0400 | [diff] [blame] | 671 | case Expression::Kind::kSwizzle: { |
| 672 | auto& s = e.template as<Swizzle>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 673 | return s.base() && this->visitExpressionPtr(s.base()); |
Brian Osman | 010ce6a | 2020-10-19 16:34:10 -0400 | [diff] [blame] | 674 | } |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 675 | |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 676 | case Expression::Kind::kTernary: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 677 | auto& t = e.template as<TernaryExpression>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 678 | return this->visitExpressionPtr(t.test()) || |
| 679 | (t.ifTrue() && this->visitExpressionPtr(t.ifTrue())) || |
| 680 | (t.ifFalse() && this->visitExpressionPtr(t.ifFalse())); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 681 | } |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 682 | default: |
| 683 | SkUNREACHABLE; |
| 684 | } |
| 685 | } |
| 686 | |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 687 | template <typename T> bool TProgramVisitor<T>::visitStatement(typename T::Statement& s) { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 688 | switch (s.kind()) { |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 689 | case Statement::Kind::kBreak: |
| 690 | case Statement::Kind::kContinue: |
| 691 | case Statement::Kind::kDiscard: |
John Stiles | 98c1f82 | 2020-09-09 14:18:53 -0400 | [diff] [blame] | 692 | case Statement::Kind::kInlineMarker: |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 693 | case Statement::Kind::kNop: |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 694 | // Leaf statements just return false |
| 695 | return false; |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 696 | |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 697 | case Statement::Kind::kBlock: |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 698 | for (auto& stmt : s.template as<Block>().children()) { |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 699 | if (stmt && this->visitStatementPtr(stmt)) { |
Ethan Nicholas | 7bd6043 | 2020-09-25 14:31:59 -0400 | [diff] [blame] | 700 | return true; |
| 701 | } |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 702 | } |
| 703 | return false; |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 704 | |
John Stiles | a0e56e3 | 2021-03-03 13:14:37 -0500 | [diff] [blame] | 705 | case Statement::Kind::kSwitchCase: { |
| 706 | auto& sc = s.template as<SwitchCase>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 707 | if (sc.value() && this->visitExpressionPtr(sc.value())) { |
John Stiles | a0e56e3 | 2021-03-03 13:14:37 -0500 | [diff] [blame] | 708 | return true; |
| 709 | } |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 710 | return this->visitStatementPtr(sc.statement()); |
John Stiles | a0e56e3 | 2021-03-03 13:14:37 -0500 | [diff] [blame] | 711 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 712 | case Statement::Kind::kDo: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 713 | auto& d = s.template as<DoStatement>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 714 | return this->visitExpressionPtr(d.test()) || this->visitStatementPtr(d.statement()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 715 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 716 | case Statement::Kind::kExpression: |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 717 | return this->visitExpressionPtr(s.template as<ExpressionStatement>().expression()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 718 | |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 719 | case Statement::Kind::kFor: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 720 | auto& f = s.template as<ForStatement>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 721 | return (f.initializer() && this->visitStatementPtr(f.initializer())) || |
| 722 | (f.test() && this->visitExpressionPtr(f.test())) || |
| 723 | (f.next() && this->visitExpressionPtr(f.next())) || |
| 724 | this->visitStatementPtr(f.statement()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 725 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 726 | case Statement::Kind::kIf: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 727 | auto& i = s.template as<IfStatement>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 728 | return (i.test() && this->visitExpressionPtr(i.test())) || |
| 729 | (i.ifTrue() && this->visitStatementPtr(i.ifTrue())) || |
| 730 | (i.ifFalse() && this->visitStatementPtr(i.ifFalse())); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 731 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 732 | case Statement::Kind::kReturn: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 733 | auto& r = s.template as<ReturnStatement>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 734 | return r.expression() && this->visitExpressionPtr(r.expression()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 735 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 736 | case Statement::Kind::kSwitch: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 737 | auto& sw = s.template as<SwitchStatement>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 738 | if (this->visitExpressionPtr(sw.value())) { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 739 | return true; |
| 740 | } |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 741 | for (auto& c : sw.cases()) { |
| 742 | if (this->visitStatementPtr(c)) { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 743 | return true; |
| 744 | } |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 745 | } |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 746 | return false; |
| 747 | } |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 748 | case Statement::Kind::kVarDeclaration: { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 749 | auto& v = s.template as<VarDeclaration>(); |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 750 | return v.value() && this->visitExpressionPtr(v.value()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 751 | } |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 752 | default: |
| 753 | SkUNREACHABLE; |
| 754 | } |
| 755 | } |
| 756 | |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 757 | template <typename T> bool TProgramVisitor<T>::visitProgramElement(typename T::ProgramElement& pe) { |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 758 | switch (pe.kind()) { |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 759 | case ProgramElement::Kind::kExtension: |
John Stiles | 569249b | 2020-11-03 12:18:22 -0500 | [diff] [blame] | 760 | case ProgramElement::Kind::kFunctionPrototype: |
John Stiles | d39aec0 | 2020-12-03 10:42:26 -0500 | [diff] [blame] | 761 | case ProgramElement::Kind::kInterfaceBlock: |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 762 | case ProgramElement::Kind::kModifiers: |
John Stiles | dc75a97 | 2020-11-25 16:24:55 -0500 | [diff] [blame] | 763 | case ProgramElement::Kind::kStructDefinition: |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 764 | // Leaf program elements just return false by default |
| 765 | return false; |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 766 | |
Ethan Nicholas | e659214 | 2020-09-08 10:22:09 -0400 | [diff] [blame] | 767 | case ProgramElement::Kind::kFunction: |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 768 | return this->visitStatementPtr(pe.template as<FunctionDefinition>().body()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 769 | |
Brian Osman | c021360 | 2020-10-06 14:43:32 -0400 | [diff] [blame] | 770 | case ProgramElement::Kind::kGlobalVar: |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 771 | return this->visitStatementPtr(pe.template as<GlobalVarDeclaration>().declaration()); |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 772 | |
Michael Ludwig | 8f3a836 | 2020-06-29 17:27:00 -0400 | [diff] [blame] | 773 | default: |
| 774 | SkUNREACHABLE; |
| 775 | } |
| 776 | } |
| 777 | |
John Stiles | 48b2558 | 2021-03-11 14:26:42 -0500 | [diff] [blame] | 778 | template class TProgramVisitor<ProgramVisitorTypes>; |
| 779 | template class TProgramVisitor<ProgramWriterTypes>; |
John Stiles | 70b8242 | 2020-09-30 10:55:12 -0400 | [diff] [blame] | 780 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 781 | } // namespace SkSL |