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 | */ |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 7 | |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 8 | #ifndef SKSL_FORSTATEMENT |
| 9 | #define SKSL_FORSTATEMENT |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/sksl/ir/SkSLExpression.h" |
| 12 | #include "src/sksl/ir/SkSLStatement.h" |
| 13 | #include "src/sksl/ir/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 { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 21 | ForStatement(int offset, std::unique_ptr<Statement> initializer, |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 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) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 24 | : INHERITED(offset, kFor_Kind) |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 25 | , fSymbols(symbols) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 26 | , fInitializer(std::move(initializer)) |
| 27 | , fTest(std::move(test)) |
| 28 | , fNext(std::move(next)) |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 29 | , fStatement(std::move(statement)) {} |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 30 | |
Ethan Nicholas | 0054311 | 2018-07-31 09:44:36 -0400 | [diff] [blame] | 31 | std::unique_ptr<Statement> clone() const override { |
| 32 | return std::unique_ptr<Statement>(new ForStatement(fOffset, fInitializer->clone(), |
| 33 | fTest->clone(), fNext->clone(), |
| 34 | fStatement->clone(), fSymbols)); |
| 35 | } |
| 36 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 37 | String description() const override { |
| 38 | String result("for ("); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 39 | if (fInitializer) { |
| 40 | result += fInitializer->description(); |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 41 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 42 | result += " "; |
| 43 | if (fTest) { |
| 44 | result += fTest->description(); |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 45 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 46 | result += "; "; |
| 47 | if (fNext) { |
| 48 | result += fNext->description(); |
| 49 | } |
| 50 | result += ") " + fStatement->description(); |
| 51 | return result; |
| 52 | } |
| 53 | |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 54 | // it's important to keep fSymbols defined first (and thus destroyed last) because destroying |
| 55 | // the other fields can update symbol reference counts |
ethannicholas | d598f79 | 2016-07-25 10:08:54 -0700 | [diff] [blame] | 56 | const std::shared_ptr<SymbolTable> fSymbols; |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 57 | std::unique_ptr<Statement> fInitializer; |
Ethan Nicholas | 86a4340 | 2017-01-19 13:32:00 -0500 | [diff] [blame] | 58 | std::unique_ptr<Expression> fTest; |
| 59 | std::unique_ptr<Expression> fNext; |
Ethan Nicholas | cb67096 | 2017-04-20 19:31:52 -0400 | [diff] [blame] | 60 | std::unique_ptr<Statement> fStatement; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 61 | |
| 62 | typedef Statement INHERITED; |
| 63 | }; |
| 64 | |
| 65 | } // namespace |
| 66 | |
| 67 | #endif |