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_ASTSWITCHSTATEMENT |
| 9 | #define SKSL_ASTSWITCHSTATEMENT |
| 10 | |
| 11 | #include "SkSLASTStatement.h" |
| 12 | #include "SkSLASTSwitchCase.h" |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * A 'switch' statement. |
| 18 | */ |
| 19 | struct ASTSwitchStatement : public ASTStatement { |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 20 | ASTSwitchStatement(int offset, bool isStatic, std::unique_ptr<ASTExpression> value, |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 21 | std::vector<std::unique_ptr<ASTSwitchCase>> cases) |
Ethan Nicholas | 5b5f096 | 2017-09-11 13:50:14 -0700 | [diff] [blame] | 22 | : INHERITED(offset, kSwitch_Kind) |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 23 | , fIsStatic(isStatic) |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 24 | , fValue(std::move(value)) |
| 25 | , fCases(std::move(cases)) {} |
| 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 += String::printf("switch (%s) {\n", fValue->description().c_str()); |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 33 | for (const auto& c : fCases) { |
| 34 | result += c->description(); |
| 35 | } |
| 36 | result += "}"; |
| 37 | return result; |
| 38 | } |
| 39 | |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 40 | bool fIsStatic; |
Ethan Nicholas | af19769 | 2017-02-27 13:26:45 -0500 | [diff] [blame] | 41 | const std::unique_ptr<ASTExpression> fValue; |
| 42 | const std::vector<std::unique_ptr<ASTSwitchCase>> fCases; |
| 43 | |
| 44 | typedef ASTStatement INHERITED; |
| 45 | }; |
| 46 | |
| 47 | } // namespace |
| 48 | |
| 49 | #endif |