1 /* 2 * Copyright 2016 Google Inc. 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_BLOCK 9 #define SKSL_BLOCK 10 11 #include "SkSLStatement.h" 12 #include "SkSLSymbolTable.h" 13 14 namespace SkSL { 15 16 /** 17 * A block of multiple statements functioning as a single statement. 18 */ 19 struct Block : public Statement { BlockBlock20 Block(Position position, std::vector<std::unique_ptr<Statement>> statements, 21 const std::shared_ptr<SymbolTable> symbols) 22 : INHERITED(position, kBlock_Kind) 23 , fSymbols(std::move(symbols)) 24 , fStatements(std::move(statements)) {} 25 descriptionBlock26 SkString description() const override { 27 SkString result("{"); 28 for (size_t i = 0; i < fStatements.size(); i++) { 29 result += "\n"; 30 result += fStatements[i]->description(); 31 } 32 result += "\n}\n"; 33 return result; 34 } 35 36 // it's important to keep fStatements defined after (and thus destroyed before) fSymbols, 37 // because destroying statements can modify reference counts in symbols 38 const std::shared_ptr<SymbolTable> fSymbols; 39 const std::vector<std::unique_ptr<Statement>> fStatements; 40 41 typedef Statement INHERITED; 42 }; 43 44 } // namespace 45 46 #endif 47