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_ASTIFSTATEMENT |
| 9 | #define SKSL_ASTIFSTATEMENT |
| 10 | |
| 11 | #include "SkSLASTStatement.h" |
| 12 | |
| 13 | namespace SkSL { |
| 14 | |
| 15 | /** |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 16 | * An 'if' statement. |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 17 | */ |
| 18 | struct ASTIfStatement : public ASTStatement { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 19 | ASTIfStatement(int offset, bool isStatic, std::unique_ptr<ASTExpression> test, |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 20 | std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 21 | : INHERITED(offset, kIf_Kind) |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 22 | , fIsStatic(isStatic) |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 23 | , fTest(std::move(test)) |
| 24 | , fIfTrue(std::move(ifTrue)) |
| 25 | , fIfFalse(std::move(ifFalse)) {} |
| 26 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 27 | String description() const override { |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 28 | String result; |
| 29 | if (fIsStatic) { |
| 30 | result += "@"; |
| 31 | } |
| 32 | result += "if ("; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 33 | result += fTest->description(); |
| 34 | result += ") "; |
| 35 | result += fIfTrue->description(); |
| 36 | if (fIfFalse) { |
| 37 | result += " else "; |
| 38 | result += fIfFalse->description(); |
| 39 | } |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 40 | return result; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 43 | const bool fIsStatic; |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 44 | const std::unique_ptr<ASTExpression> fTest; |
| 45 | const std::unique_ptr<ASTStatement> fIfTrue; |
| 46 | const std::unique_ptr<ASTStatement> fIfFalse; |
| 47 | |
| 48 | typedef ASTStatement INHERITED; |
| 49 | }; |
| 50 | |
| 51 | } // namespace |
| 52 | |
| 53 | #endif |