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 #ifndef SKSL_DSLWRITER 9 #define SKSL_DSLWRITER 10 11 #include "include/core/SkTypes.h" 12 13 #include <memory> 14 15 namespace SkSL { 16 17 class Variable; 18 class Statement; 19 20 namespace dsl { 21 22 class DSLParameter; 23 class DSLStatement; 24 class DSLVarBase; 25 class DSLVar; 26 27 /** 28 * Various utility methods needed by DSL code. 29 */ 30 class DSLWriter { 31 public: 32 /** 33 * Returns the SkSL variable corresponding to a DSL var. 34 */ 35 static SkSL::Variable* Var(DSLVarBase& var); 36 37 /** 38 * Creates an SkSL variable corresponding to a DSLParameter. 39 */ 40 static std::unique_ptr<SkSL::Variable> CreateParameterVar(DSLParameter& var); 41 42 /** 43 * Returns the SkSL declaration corresponding to a DSLVar. 44 */ 45 static std::unique_ptr<SkSL::Statement> Declaration(DSLVarBase& var); 46 47 /** 48 * Adds a new declaration into an existing declaration statement. This either turns the original 49 * declaration into an unscoped block or, if it already was, appends a new statement to the end 50 * of it. 51 */ 52 static void AddVarDeclaration(DSLStatement& existing, DSLVar& additional); 53 54 /** 55 * Clears any elements or symbols which have been output. 56 */ 57 static void Reset(); 58 }; 59 60 } // namespace dsl 61 62 } // namespace SkSL 63 64 #endif 65