blob: af1975396ebbacc8aa604bfe65be4bfa3900efe2 [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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 */
Ethan Nicholas9e1138d2016-11-21 10:39:35 -05007
ethannicholasb3058bd2016-07-01 08:22:01 -07008#ifndef SKSL_BLOCK
9#define SKSL_BLOCK
10
11#include "SkSLStatement.h"
ethannicholasd598f792016-07-25 10:08:54 -070012#include "SkSLSymbolTable.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070013
14namespace SkSL {
15
16/**
17 * A block of multiple statements functioning as a single statement.
18 */
19struct Block : public Statement {
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070020 Block(int offset, std::vector<std::unique_ptr<Statement>> statements,
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040021 const std::shared_ptr<SymbolTable> symbols = nullptr)
Ethan Nicholas5b5f0962017-09-11 13:50:14 -070022 : INHERITED(offset, kBlock_Kind)
Ethan Nicholas86a43402017-01-19 13:32:00 -050023 , fSymbols(std::move(symbols))
24 , fStatements(std::move(statements)) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070025
Ethan Nicholascb670962017-04-20 19:31:52 -040026 bool isEmpty() const override {
27 for (const auto& s : fStatements) {
28 if (!s->isEmpty()) {
29 return false;
30 }
31 }
32 return true;
33 }
34
Ethan Nicholas0df1b042017-03-31 13:56:23 -040035 String description() const override {
36 String result("{");
ethannicholasb3058bd2016-07-01 08:22:01 -070037 for (size_t i = 0; i < fStatements.size(); i++) {
38 result += "\n";
39 result += fStatements[i]->description();
40 }
41 result += "\n}\n";
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050042 return result;
ethannicholasb3058bd2016-07-01 08:22:01 -070043 }
44
Ethan Nicholas86a43402017-01-19 13:32:00 -050045 // it's important to keep fStatements defined after (and thus destroyed before) fSymbols,
46 // because destroying statements can modify reference counts in symbols
Ethan Nicholas6415e0d2017-01-19 16:31:32 +000047 const std::shared_ptr<SymbolTable> fSymbols;
Ethan Nicholascb670962017-04-20 19:31:52 -040048 std::vector<std::unique_ptr<Statement>> fStatements;
ethannicholasb3058bd2016-07-01 08:22:01 -070049
50 typedef Statement INHERITED;
51};
52
53} // namespace
54
55#endif