blob: d3aa06536c1e6c721828fa4e1cfaed7e5948b3ab [file] [log] [blame]
Ethan Nicholas17807552021-10-01 09:42:36 -04001/*
2 * Copyright 2021 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#ifndef SkSLProgramWriter_DEFINED
9#define SkSLProgramWriter_DEFINED
10
11#include "src/sksl/analysis/SkSLProgramVisitor.h"
12
13namespace SkSL {
14
15struct ProgramWriterTypes {
16 using Program = SkSL::Program;
17 using Expression = SkSL::Expression;
18 using Statement = SkSL::Statement;
19 using ProgramElement = SkSL::ProgramElement;
20 using UniquePtrExpression = std::unique_ptr<SkSL::Expression>;
21 using UniquePtrStatement = std::unique_ptr<SkSL::Statement>;
22};
23
24// Squelch bogus Clang warning about template vtables: https://bugs.llvm.org/show_bug.cgi?id=18733
25#if defined(__clang__)
26#pragma clang diagnostic push
27#pragma clang diagnostic ignored "-Wweak-template-vtables"
28#endif
29extern template class TProgramVisitor<ProgramWriterTypes>;
30#if defined(__clang__)
31#pragma clang diagnostic pop
32#endif
33
34class ProgramWriter : public TProgramVisitor<ProgramWriterTypes> {
35public:
36 // Subclass these methods if you want access to the unique_ptrs of IRNodes in a program.
37 // This will allow statements or expressions to be replaced during a visit.
38 bool visitExpressionPtr(std::unique_ptr<Expression>& e) override {
39 return this->visitExpression(*e);
40 }
41 bool visitStatementPtr(std::unique_ptr<Statement>& s) override {
42 return this->visitStatement(*s);
43 }
44};
45
46} // namespace SkSL
47
48#endif