Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLSwitchCase.h
Go to the documentation of this file.
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
16
17#include <memory>
18#include <string>
19#include <utility>
20
21namespace SkSL {
22
23/**
24 * A single case of a 'switch' statement.
25 */
26class SwitchCase final : public Statement {
27public:
28 inline static constexpr Kind kIRNodeKind = Kind::kSwitchCase;
29
30 static std::unique_ptr<SwitchCase> Make(Position pos,
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
56private:
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
SkPoint pos
#define SkASSERT(cond)
Definition SkAssert.h:116
int64_t SKSL_INT
Definition SkSLDefines.h:16
static std::unique_ptr< SwitchCase > MakeDefault(Position pos, std::unique_ptr< Statement > statement)
SKSL_INT value() const
bool isDefault() const
const std::unique_ptr< Statement > & statement() const
std::string description() const override
static std::unique_ptr< SwitchCase > Make(Position pos, SKSL_INT value, std::unique_ptr< Statement > statement)
std::unique_ptr< Statement > & statement()
static constexpr Kind kIRNodeKind
StatementKind
Definition SkSLIRNode.h:43
Definition ref_ptr.h:256