blob: ff03d0d7f9151b0b8c4d4854275e6955c68fe9e9 [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 */
7
8#ifndef SKSL_FORSTATEMENT
9#define SKSL_FORSTATEMENT
10
11#include "SkSLExpression.h"
12#include "SkSLStatement.h"
ethannicholasd598f792016-07-25 10:08:54 -070013#include "SkSLSymbolTable.h"
ethannicholasb3058bd2016-07-01 08:22:01 -070014
15namespace SkSL {
16
17/**
18 * A 'for' statement.
19 */
20struct ForStatement : public Statement {
21 ForStatement(Position position, std::unique_ptr<Statement> initializer,
22 std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
ethannicholasd598f792016-07-25 10:08:54 -070023 std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols)
ethannicholasb3058bd2016-07-01 08:22:01 -070024 : INHERITED(position, kFor_Kind)
25 , fInitializer(std::move(initializer))
26 , fTest(std::move(test))
27 , fNext(std::move(next))
ethannicholasd598f792016-07-25 10:08:54 -070028 , fStatement(std::move(statement))
29 , fSymbols(symbols) {}
ethannicholasb3058bd2016-07-01 08:22:01 -070030
Ethan Nicholas9e1138d2016-11-21 10:39:35 -050031 SkString description() const override {
32 SkString result("for (");
ethannicholasb3058bd2016-07-01 08:22:01 -070033 if (fInitializer) {
34 result += fInitializer->description();
35 }
36 result += " ";
37 if (fTest) {
38 result += fTest->description();
39 }
40 result += "; ";
41 if (fNext) {
42 result += fNext->description();
43 }
44 result += ") " + fStatement->description();
45 return result;
46 }
47
48 const std::unique_ptr<Statement> fInitializer;
49 const std::unique_ptr<Expression> fTest;
50 const std::unique_ptr<Expression> fNext;
51 const std::unique_ptr<Statement> fStatement;
ethannicholasd598f792016-07-25 10:08:54 -070052 const std::shared_ptr<SymbolTable> fSymbols;
ethannicholasb3058bd2016-07-01 08:22:01 -070053
54 typedef Statement INHERITED;
55};
56
57} // namespace
58
59#endif