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_FORSTATEMENT
9 : #define SKSL_FORSTATEMENT
10 :
11 : #include "SkSLExpression.h"
12 : #include "SkSLStatement.h"
13 : #include "SkSLSymbolTable.h"
14 :
15 : namespace SkSL {
16 :
17 : /**
18 : * A 'for' statement.
19 : */
20 0 : struct ForStatement : public Statement {
21 0 : ForStatement(Position position, std::unique_ptr<Statement> initializer,
22 : std::unique_ptr<Expression> test, std::unique_ptr<Expression> next,
23 : std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols)
24 0 : : INHERITED(position, kFor_Kind)
25 : , fSymbols(symbols)
26 0 : , fInitializer(std::move(initializer))
27 0 : , fTest(std::move(test))
28 0 : , fNext(std::move(next))
29 0 : , fStatement(std::move(statement)) {}
30 :
31 0 : String description() const override {
32 0 : String result("for (");
33 0 : if (fInitializer) {
34 0 : result += fInitializer->description();
35 : }
36 0 : result += " ";
37 0 : if (fTest) {
38 0 : result += fTest->description();
39 : }
40 0 : result += "; ";
41 0 : if (fNext) {
42 0 : result += fNext->description();
43 : }
44 0 : result += ") " + fStatement->description();
45 0 : return result;
46 : }
47 :
48 : // it's important to keep fSymbols defined first (and thus destroyed last) because destroying
49 : // the other fields can update symbol reference counts
50 : const std::shared_ptr<SymbolTable> fSymbols;
51 : const std::unique_ptr<Statement> fInitializer;
52 : std::unique_ptr<Expression> fTest;
53 : std::unique_ptr<Expression> fNext;
54 : const std::unique_ptr<Statement> fStatement;
55 :
56 : typedef Statement INHERITED;
57 : };
58 :
59 : } // namespace
60 :
61 : #endif
|