1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2021 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef SkSLProgramWriter_DEFINED 9cb93a386Sopenharmony_ci#define SkSLProgramWriter_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "src/sksl/analysis/SkSLProgramVisitor.h" 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_cinamespace SkSL { 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_cistruct ProgramWriterTypes { 16cb93a386Sopenharmony_ci using Program = SkSL::Program; 17cb93a386Sopenharmony_ci using Expression = SkSL::Expression; 18cb93a386Sopenharmony_ci using Statement = SkSL::Statement; 19cb93a386Sopenharmony_ci using ProgramElement = SkSL::ProgramElement; 20cb93a386Sopenharmony_ci using UniquePtrExpression = std::unique_ptr<SkSL::Expression>; 21cb93a386Sopenharmony_ci using UniquePtrStatement = std::unique_ptr<SkSL::Statement>; 22cb93a386Sopenharmony_ci}; 23cb93a386Sopenharmony_ci 24cb93a386Sopenharmony_ci// Squelch bogus Clang warning about template vtables: https://bugs.llvm.org/show_bug.cgi?id=18733 25cb93a386Sopenharmony_ci#if defined(__clang__) 26cb93a386Sopenharmony_ci#pragma clang diagnostic push 27cb93a386Sopenharmony_ci#pragma clang diagnostic ignored "-Wweak-template-vtables" 28cb93a386Sopenharmony_ci#endif 29cb93a386Sopenharmony_ciextern template class TProgramVisitor<ProgramWriterTypes>; 30cb93a386Sopenharmony_ci#if defined(__clang__) 31cb93a386Sopenharmony_ci#pragma clang diagnostic pop 32cb93a386Sopenharmony_ci#endif 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ciclass ProgramWriter : public TProgramVisitor<ProgramWriterTypes> { 35cb93a386Sopenharmony_cipublic: 36cb93a386Sopenharmony_ci // Subclass these methods if you want access to the unique_ptrs of IRNodes in a program. 37cb93a386Sopenharmony_ci // This will allow statements or expressions to be replaced during a visit. 38cb93a386Sopenharmony_ci bool visitExpressionPtr(std::unique_ptr<Expression>& e) override { 39cb93a386Sopenharmony_ci return this->visitExpression(*e); 40cb93a386Sopenharmony_ci } 41cb93a386Sopenharmony_ci bool visitStatementPtr(std::unique_ptr<Statement>& s) override { 42cb93a386Sopenharmony_ci return this->visitStatement(*s); 43cb93a386Sopenharmony_ci } 44cb93a386Sopenharmony_ci}; 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_ci} // namespace SkSL 47cb93a386Sopenharmony_ci 48cb93a386Sopenharmony_ci#endif 49