blob: 8043f2e787d96dba9216227d4ef0c25926236407 [file] [log] [blame]
Ethan Nicholasaf197692017-02-27 13:26:45 -05001/*
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_SWITCHCASE
9#define SKSL_SWITCHCASE
10
Hal Canary271d4952017-02-15 11:21:32 -050011#include "SkSLExpression.h"
Ethan Nicholasaf197692017-02-27 13:26:45 -050012#include "SkSLStatement.h"
13
14namespace SkSL {
15
16/**
17 * A single case of a 'switch' statement.
18 */
19struct SwitchCase : public Statement {
20 SwitchCase(Position position, std::unique_ptr<Expression> value,
21 std::vector<std::unique_ptr<Statement>> statements)
22 : INHERITED(position, kSwitch_Kind)
23 , fValue(std::move(value))
24 , fStatements(std::move(statements)) {}
25
Ethan Nicholasf3333c82017-03-31 09:33:41 -040026 String description() const override {
27 String result;
Ethan Nicholasaf197692017-02-27 13:26:45 -050028 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 std::unique_ptr<Expression> fValue;
41 std::vector<std::unique_ptr<Statement>> fStatements;
42
43 typedef Statement INHERITED;
44};
45
46} // namespace
47
48#endif