Flutter Engine
The Flutter Engine
SkSLSwitchStatement.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_SWITCHSTATEMENT
9#define SKSL_SWITCHSTATEMENT
10
17
18#include <memory>
19#include <string>
20#include <utility>
21
22namespace SkSL {
23
24class Context;
25class SymbolTable;
26
27/**
28 * A 'switch' statement.
29 */
30class SwitchStatement final : public Statement {
31public:
32 inline static constexpr Kind kIRNodeKind = Kind::kSwitch;
33
35 std::unique_ptr<Expression> value,
36 std::unique_ptr<Statement> caseBlock)
38 , fValue(std::move(value))
39 , fCaseBlock(std::move(caseBlock)) {}
40
41 // Create a `switch` statement with an array of case-values and case-statements.
42 // Coerces case values to the proper type and reports an error if cases are duplicated.
43 // Reports errors via the ErrorReporter.
44 static std::unique_ptr<Statement> Convert(const Context& context,
46 std::unique_ptr<Expression> value,
47 ExpressionArray caseValues,
48 StatementArray caseStatements,
49 std::unique_ptr<SymbolTable> symbolTable);
50
51 // Create a `switch` statement with a Block containing only SwitchCases. The SwitchCase block
52 // must already contain non-overlapping, correctly-typed case values. Reports errors via ASSERT.
53 static std::unique_ptr<Statement> Make(const Context& context,
55 std::unique_ptr<Expression> value,
56 std::unique_ptr<Statement> caseBlock);
57
58 std::unique_ptr<Expression>& value() {
59 return fValue;
60 }
61
62 const std::unique_ptr<Expression>& value() const {
63 return fValue;
64 }
65
66 std::unique_ptr<Statement>& caseBlock() {
67 return fCaseBlock;
68 }
69
70 const std::unique_ptr<Statement>& caseBlock() const {
71 return fCaseBlock;
72 }
73
75 return fCaseBlock->as<Block>().children();
76 }
77
78 const StatementArray& cases() const {
79 return fCaseBlock->as<Block>().children();
80 }
81
82 std::string description() const override;
83
84private:
85 std::unique_ptr<Expression> fValue;
86 std::unique_ptr<Statement> fCaseBlock; // must be a Block containing only SwitchCase statements
87
88 using INHERITED = Statement;
89};
90
91} // namespace SkSL
92
93#endif
SkPoint pos
Statement(Position pos, Kind kind)
Definition: SkSLStatement.h:23
std::unique_ptr< Expression > & value()
std::string description() const override
static constexpr Kind kIRNodeKind
std::unique_ptr< Statement > & caseBlock()
SwitchStatement(Position pos, std::unique_ptr< Expression > value, std::unique_ptr< Statement > caseBlock)
const std::unique_ptr< Expression > & value() const
const StatementArray & cases() const
const std::unique_ptr< Statement > & caseBlock() const
static std::unique_ptr< Statement > Make(const Context &context, Position pos, std::unique_ptr< Expression > value, std::unique_ptr< Statement > caseBlock)
static std::unique_ptr< Statement > Convert(const Context &context, Position pos, std::unique_ptr< Expression > value, ExpressionArray caseValues, StatementArray caseStatements, std::unique_ptr< SymbolTable > symbolTable)
StatementArray & cases()
StatementKind
Definition: SkSLIRNode.h:43
Definition: ref_ptr.h:256