ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 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" |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 13 | #include "SkSLSymbolTable.h" |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 14 | |
| 15 | namespace SkSL { |
| 16 | |
| 17 | /** |
| 18 | * A 'for' statement. |
| 19 | */ |
| 20 | struct ForStatement : public Statement { |
| 21 | ForStatement(Position position, std::unique_ptr<Statement> initializer, |
| 22 | std::unique_ptr<Expression> test, std::unique_ptr<Expression> next, |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 23 | std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 24 | : INHERITED(position, kFor_Kind) |
| 25 | , fInitializer(std::move(initializer)) |
| 26 | , fTest(std::move(test)) |
| 27 | , fNext(std::move(next)) |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 28 | , fStatement(std::move(statement)) |
| 29 | , fSymbols(symbols) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 30 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame^] | 31 | SkString description() const override { |
| 32 | SkString result("for ("); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 33 | 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; |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 52 | const std::shared_ptr<SymbolTable> fSymbols; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 53 | |
| 54 | typedef Statement INHERITED; |
| 55 | }; |
| 56 | |
| 57 | } // namespace |
| 58 | |
| 59 | #endif |