Debian Codegraph @

src/sksl/ir/SkSLSwitchCase.h

raw
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_SWITCHCASE
9 #define SKSL_SWITCHCASE
10
11 #include "include/private/base/SkAssert.h"
12 #include "src/sksl/SkSLDefines.h"
13 #include "src/sksl/SkSLPosition.h"
14 #include "src/sksl/ir/SkSLIRNode.h"
15 #include "src/sksl/ir/SkSLStatement.h"
16
17 #include <memory>
18 #include <string>
19 #include <utility>
20
21 namespace SkSL {
22
23 /**
24 * A single case of a 'switch' statement.
25 */
26 class SwitchCase final : public Statement {
27 public:
28 inline static constexpr Kind kIRNodeKind = Kind::kSwitchCase;
29
30 static std::unique_ptr<SwitchCase> Make(Position pos,
31 SKSL_INT value,
32 std::unique_ptr<Statement> statement);
33
34 static std::unique_ptr<SwitchCase> MakeDefault(Position pos,
35 std::unique_ptr<Statement> statement);
36
37 bool isDefault() const {
38 return fDefault;
39 }
40
41 SKSL_INT value() const {
42 SkASSERT(!this->isDefault());
43 return fValue;
44 }
45
46 std::unique_ptr<Statement>& statement() {
47 return fStatement;
48 }
49
50 const std::unique_ptr<Statement>& statement() const {
51 return fStatement;
52 }
53
54 std::string description() const override;
55
56 private:
57 SwitchCase(Position pos, bool isDefault, SKSL_INT value, std::unique_ptr<Statement> statement)
58 : INHERITED(pos, kIRNodeKind)
59 , fDefault(isDefault)
60 , fValue(std::move(value))
61 , fStatement(std::move(statement)) {}
62
63 bool fDefault;
64 SKSL_INT fValue;
65 std::unique_ptr<Statement> fStatement;
66
67 using INHERITED = Statement;
68 };
69
70 } // namespace SkSL
71
72 #endif