• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
13 namespace SkSL {
14 
15 struct 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
29 extern template class TProgramVisitor<ProgramWriterTypes>;
30 #if defined(__clang__)
31 #pragma clang diagnostic pop
32 #endif
33 
34 class ProgramWriter : public TProgramVisitor<ProgramWriterTypes> {
35 public:
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.
visitExpressionPtr(std::unique_ptr<Expression> & e)38     bool visitExpressionPtr(std::unique_ptr<Expression>& e) override {
39         return this->visitExpression(*e);
40     }
visitStatementPtr(std::unique_ptr<Statement> & s)41     bool visitStatementPtr(std::unique_ptr<Statement>& s) override {
42         return this->visitStatement(*s);
43     }
44 };
45 
46 } // namespace SkSL
47 
48 #endif
49