Line data Source code
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 0 : struct Block : public Statement {
20 0 : Block(Position position, std::vector<std::unique_ptr<Statement>> statements,
21 : const std::shared_ptr<SymbolTable> symbols)
22 0 : : INHERITED(position, kBlock_Kind)
23 0 : , fSymbols(std::move(symbols))
24 0 : , fStatements(std::move(statements)) {}
25 :
26 0 : String description() const override {
27 0 : String result("{");
28 0 : for (size_t i = 0; i < fStatements.size(); i++) {
29 0 : result += "\n";
30 0 : result += fStatements[i]->description();
31 : }
32 0 : result += "\n}\n";
33 0 : 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
|