Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLIfStatement.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 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_IFSTATEMENT
9#define SKSL_IFSTATEMENT
10
15
16#include <memory>
17#include <string>
18#include <utility>
19
20namespace SkSL {
21
22class Context;
23
24/**
25 * An 'if' statement.
26 */
27class IfStatement final : public Statement {
28public:
29 inline static constexpr Kind kIRNodeKind = Kind::kIf;
30
31 IfStatement(Position pos, std::unique_ptr<Expression> test,
32 std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse)
34 , fTest(std::move(test))
35 , fIfTrue(std::move(ifTrue))
36 , fIfFalse(std::move(ifFalse)) {}
37
38 // Creates a potentially-simplified form of the if-statement. Typechecks and coerces the test
39 // expression; reports errors via ErrorReporter.
40 static std::unique_ptr<Statement> Convert(const Context& context,
42 std::unique_ptr<Expression> test,
43 std::unique_ptr<Statement> ifTrue,
44 std::unique_ptr<Statement> ifFalse);
45
46 // Creates a potentially-simplified form of the if-statement; reports errors via ASSERT.
47 static std::unique_ptr<Statement> Make(const Context& context,
49 std::unique_ptr<Expression> test,
50 std::unique_ptr<Statement> ifTrue,
51 std::unique_ptr<Statement> ifFalse);
52
53 std::unique_ptr<Expression>& test() {
54 return fTest;
55 }
56
57 const std::unique_ptr<Expression>& test() const {
58 return fTest;
59 }
60
61 std::unique_ptr<Statement>& ifTrue() {
62 return fIfTrue;
63 }
64
65 const std::unique_ptr<Statement>& ifTrue() const {
66 return fIfTrue;
67 }
68
69 std::unique_ptr<Statement>& ifFalse() {
70 return fIfFalse;
71 }
72
73 const std::unique_ptr<Statement>& ifFalse() const {
74 return fIfFalse;
75 }
76
77 std::string description() const override;
78
79private:
80 std::unique_ptr<Expression> fTest;
81 std::unique_ptr<Statement> fIfTrue;
82 std::unique_ptr<Statement> fIfFalse;
83
84 using INHERITED = Statement;
85};
86
87} // namespace SkSL
88
89#endif
SkPoint pos
static std::unique_ptr< Statement > Convert(const Context &context, Position pos, std::unique_ptr< Expression > test, std::unique_ptr< Statement > ifTrue, std::unique_ptr< Statement > ifFalse)
std::string description() const override
static std::unique_ptr< Statement > Make(const Context &context, Position pos, std::unique_ptr< Expression > test, std::unique_ptr< Statement > ifTrue, std::unique_ptr< Statement > ifFalse)
IfStatement(Position pos, std::unique_ptr< Expression > test, std::unique_ptr< Statement > ifTrue, std::unique_ptr< Statement > ifFalse)
std::unique_ptr< Expression > & test()
const std::unique_ptr< Statement > & ifFalse() const
const std::unique_ptr< Statement > & ifTrue() const
static constexpr Kind kIRNodeKind
const std::unique_ptr< Expression > & test() const
std::unique_ptr< Statement > & ifTrue()
std::unique_ptr< Statement > & ifFalse()
StatementKind
Definition SkSLIRNode.h:43
Definition ref_ptr.h:256