/src/skia/src/sksl/ir/SkSLIfStatement.h
Line | Count | Source |
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 | | |
11 | | #include "include/private/SkSLStatement.h" |
12 | | #include "src/sksl/ir/SkSLExpression.h" |
13 | | |
14 | | #include <memory> |
15 | | |
16 | | namespace SkSL { |
17 | | |
18 | | /** |
19 | | * An 'if' statement. |
20 | | */ |
21 | | class IfStatement final : public Statement { |
22 | | public: |
23 | | static constexpr Kind kStatementKind = Kind::kIf; |
24 | | |
25 | | IfStatement(int offset, bool isStatic, std::unique_ptr<Expression> test, |
26 | | std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse) |
27 | | : INHERITED(offset, kStatementKind) |
28 | | , fTest(std::move(test)) |
29 | | , fIfTrue(std::move(ifTrue)) |
30 | | , fIfFalse(std::move(ifFalse)) |
31 | 471k | , fIsStatic(isStatic) {} |
32 | | |
33 | | // Creates a potentially-simplified form of the if-statement. Typechecks and coerces the test |
34 | | // expression; reports errors via ErrorReporter. |
35 | | static std::unique_ptr<Statement> Convert(const Context& context, int offset, bool isStatic, |
36 | | std::unique_ptr<Expression> test, |
37 | | std::unique_ptr<Statement> ifTrue, |
38 | | std::unique_ptr<Statement> ifFalse); |
39 | | |
40 | | // Creates a potentially-simplified form of the if-statement; reports errors via ASSERT. |
41 | | static std::unique_ptr<Statement> Make(const Context& context, int offset, bool isStatic, |
42 | | std::unique_ptr<Expression> test, |
43 | | std::unique_ptr<Statement> ifTrue, |
44 | | std::unique_ptr<Statement> ifFalse); |
45 | | |
46 | 2.57k | bool isStatic() const { |
47 | 2.57k | return fIsStatic; |
48 | 2.57k | } |
49 | | |
50 | 948k | std::unique_ptr<Expression>& test() { |
51 | 948k | return fTest; |
52 | 948k | } |
53 | | |
54 | 7.02M | const std::unique_ptr<Expression>& test() const { |
55 | 7.02M | return fTest; |
56 | 7.02M | } |
57 | | |
58 | 953k | std::unique_ptr<Statement>& ifTrue() { |
59 | 953k | return fIfTrue; |
60 | 953k | } |
61 | | |
62 | 6.95M | const std::unique_ptr<Statement>& ifTrue() const { |
63 | 6.95M | return fIfTrue; |
64 | 6.95M | } |
65 | | |
66 | 950k | std::unique_ptr<Statement>& ifFalse() { |
67 | 950k | return fIfFalse; |
68 | 950k | } |
69 | | |
70 | 6.56M | const std::unique_ptr<Statement>& ifFalse() const { |
71 | 6.56M | return fIfFalse; |
72 | 6.56M | } |
73 | | |
74 | | std::unique_ptr<Statement> clone() const override; |
75 | | |
76 | | String description() const override; |
77 | | |
78 | | private: |
79 | | std::unique_ptr<Expression> fTest; |
80 | | std::unique_ptr<Statement> fIfTrue; |
81 | | std::unique_ptr<Statement> fIfFalse; |
82 | | bool fIsStatic; |
83 | | |
84 | | using INHERITED = Statement; |
85 | | }; |
86 | | |
87 | | } // namespace SkSL |
88 | | |
89 | | #endif |