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_ASTIFSTATEMENT |
| 9 | #define SKSL_ASTIFSTATEMENT |
| 10 | |
| 11 | #include "SkSLASTStatement.h" |
| 12 | |
| 13 | namespace SkSL { |
| 14 | |
| 15 | /** |
| 16 | * An 'if' statement. |
| 17 | */ |
| 18 | struct ASTIfStatement : public ASTStatement { |
| 19 | ASTIfStatement(Position position, std::unique_ptr<ASTExpression> test, |
| 20 | std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse) |
| 21 | : INHERITED(position, kIf_Kind) |
| 22 | , fTest(std::move(test)) |
| 23 | , fIfTrue(std::move(ifTrue)) |
| 24 | , fIfFalse(std::move(ifFalse)) {} |
| 25 | |
Ethan Nicholas | 9e1138d | 2016-11-21 10:39:35 -0500 | [diff] [blame^] | 26 | SkString description() const override { |
| 27 | SkString result("if ("); |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 28 | result += fTest->description(); |
| 29 | result += ") "; |
| 30 | result += fIfTrue->description(); |
| 31 | if (fIfFalse) { |
| 32 | result += " else "; |
| 33 | result += fIfFalse->description(); |
| 34 | } |
| 35 | return result; |
| 36 | } |
| 37 | |
| 38 | const std::unique_ptr<ASTExpression> fTest; |
| 39 | const std::unique_ptr<ASTStatement> fIfTrue; |
| 40 | const std::unique_ptr<ASTStatement> fIfFalse; |
| 41 | |
| 42 | typedef ASTStatement INHERITED; |
| 43 | }; |
| 44 | |
| 45 | } // namespace |
| 46 | |
| 47 | #endif |