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 SKSL_DSL_BLOCK 9 #define SKSL_DSL_BLOCK 10 11 #include "include/private/SkSLDefines.h" 12 #include "include/private/base/SkTArray.h" 13 #include "include/sksl/DSLStatement.h" 14 #include "include/sksl/SkSLPosition.h" 15 16 #include <memory> 17 18 namespace SkSL { 19 20 class Block; 21 class SymbolTable; 22 23 namespace dsl { 24 25 class DSLBlock { 26 public: 27 template<class... Statements> DSLBlock(Statements...statements)28 DSLBlock(Statements... statements) { 29 fStatements.reserve_back(sizeof...(statements)); 30 ((void)fStatements.push_back(DSLStatement(statements.release()).release()), ...); 31 } 32 33 DSLBlock(SkSL::StatementArray statements, std::shared_ptr<SymbolTable> symbols = nullptr, 34 Position pos = {}); 35 36 DSLBlock(SkTArray<DSLStatement> statements, std::shared_ptr<SymbolTable> symbols = nullptr, 37 Position pos = {}); 38 39 DSLBlock(DSLBlock&& other) = default; 40 DSLBlock& operator=(DSLBlock&& other) = default; 41 42 ~DSLBlock() = default; 43 44 void append(DSLStatement stmt); 45 46 std::unique_ptr<SkSL::Block> release(); 47 48 private: 49 SkSL::StatementArray fStatements; 50 std::shared_ptr<SkSL::SymbolTable> fSymbols; 51 Position fPosition; 52 }; 53 54 } // namespace dsl 55 56 } // namespace SkSL 57 58 #endif 59