Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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_ASTSWITCHCASE |
| 9 | #define SKSL_ASTSWITCHCASE |
| 10 | |
| 11 | #include "SkSLASTStatement.h" |
| 12 | |
| 13 | namespace SkSL { |
| 14 | |
| 15 | /** |
| 16 | * A single case of a 'switch' statement. |
| 17 | */ |
| 18 | struct ASTSwitchCase : public ASTStatement { |
| 19 | // a null value means "default:" |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 20 | ASTSwitchCase(int offset, std::unique_ptr<ASTExpression> value, |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 21 | std::vector<std::unique_ptr<ASTStatement>> statements) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 22 | : INHERITED(offset, kSwitch_Kind) |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 23 | , fValue(std::move(value)) |
| 24 | , fStatements(std::move(statements)) {} |
| 25 | |
Ethan Nicholas | 0df1b04 | 2017-03-31 13:56:23 -0400 | [diff] [blame] | 26 | String description() const override { |
| 27 | String result; |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 28 | if (fValue) { |
| 29 | result.appendf("case %s:\n", fValue->description().c_str()); |
| 30 | } else { |
| 31 | result += "default:\n"; |
| 32 | } |
| 33 | for (const auto& s : fStatements) { |
| 34 | result += s->description() + "\n"; |
| 35 | } |
| 36 | return result; |
| 37 | } |
| 38 | |
| 39 | // null value implies "default" case |
| 40 | const std::unique_ptr<ASTExpression> fValue; |
| 41 | const std::vector<std::unique_ptr<ASTStatement>> fStatements; |
| 42 | |
| 43 | typedef ASTStatement INHERITED; |
| 44 | }; |
| 45 | |
| 46 | } // namespace |
| 47 | |
| 48 | #endif |