Replace clear_write/clone_with_ref_kind with Analysis::UpdateRefKind.
It turns out that walking an expression to update the refKind of its
embedded VariableReference is so useful that we had implemented it
twice. I will need to do it a third time in a followup CL.
Change-Id: Idd2794ea50f8c71725bb998ac8a625b36d076746
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368118
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp
index f3dbf0d..50b8268 100644
--- a/src/sksl/SkSLInliner.cpp
+++ b/src/sksl/SkSLInliner.cpp
@@ -182,23 +182,7 @@
std::unique_ptr<Expression> clone_with_ref_kind(const Expression& expr,
VariableReference::RefKind refKind) {
std::unique_ptr<Expression> clone = expr.clone();
- class SetRefKindInExpression : public ProgramWriter {
- public:
- SetRefKindInExpression(VariableReference::RefKind refKind) : fRefKind(refKind) {}
- bool visitExpression(Expression& expr) override {
- if (expr.is<VariableReference>()) {
- expr.as<VariableReference>().setRefKind(fRefKind);
- }
- return INHERITED::visitExpression(expr);
- }
-
- private:
- VariableReference::RefKind fRefKind;
-
- using INHERITED = ProgramWriter;
- };
-
- SetRefKindInExpression{refKind}.visitExpression(*clone);
+ Analysis::UpdateRefKind(clone.get(), refKind);
return clone;
}