/src/skia/include/private/SkSLStatement.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_STATEMENT |
9 | | #define SKSL_STATEMENT |
10 | | |
11 | | #include "include/private/SkSLIRNode.h" |
12 | | #include "include/private/SkSLSymbol.h" |
13 | | |
14 | | namespace SkSL { |
15 | | |
16 | | /** |
17 | | * Abstract supertype of all statements. |
18 | | */ |
19 | | class Statement : public IRNode { |
20 | | public: |
21 | | enum Kind { |
22 | | kBlock = (int) Symbol::Kind::kLast + 1, |
23 | | kBreak, |
24 | | kContinue, |
25 | | kDiscard, |
26 | | kDo, |
27 | | kExpression, |
28 | | kFor, |
29 | | kIf, |
30 | | kInlineMarker, |
31 | | kNop, |
32 | | kReturn, |
33 | | kSwitch, |
34 | | kSwitchCase, |
35 | | kVarDeclaration, |
36 | | |
37 | | kFirst = kBlock, |
38 | | kLast = kVarDeclaration, |
39 | | }; |
40 | | |
41 | | Statement(int offset, Kind kind) |
42 | 10.2M | : INHERITED(offset, (int) kind) { |
43 | 10.2M | SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); |
44 | 10.2M | } SkSL::Statement::Statement(int, SkSL::Statement::Kind) Line | Count | Source | 42 | 780 | : INHERITED(offset, (int) kind) { | 43 | 780 | SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); | 44 | 780 | } |
SkSL::Statement::Statement(int, SkSL::Statement::Kind) Line | Count | Source | 42 | 10.2M | : INHERITED(offset, (int) kind) { | 43 | 10.2M | SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); | 44 | 10.2M | } |
|
45 | | |
46 | 76.1M | Kind kind() const { |
47 | 76.1M | return (Kind) fKind; |
48 | 76.1M | } |
49 | | |
50 | | /** |
51 | | * Use is<T> to check the type of a statement. |
52 | | * e.g. replace `s.kind() == Statement::Kind::kReturn` with `s.is<ReturnStatement>()`. |
53 | | */ |
54 | | template <typename T> |
55 | 91.2M | bool is() const { |
56 | 91.2M | return this->fKind == T::kStatementKind; |
57 | 91.2M | } bool SkSL::Statement::is<SkSL::VarDeclaration>() const Line | Count | Source | 55 | 21.3M | bool is() const { | 56 | 21.3M | return this->fKind == T::kStatementKind; | 57 | 21.3M | } |
bool SkSL::Statement::is<SkSL::ForStatement>() const Line | Count | Source | 55 | 1.04M | bool is() const { | 56 | 1.04M | return this->fKind == T::kStatementKind; | 57 | 1.04M | } |
bool SkSL::Statement::is<SkSL::Nop>() const Line | Count | Source | 55 | 26.6k | bool is() const { | 56 | 26.6k | return this->fKind == T::kStatementKind; | 57 | 26.6k | } |
bool SkSL::Statement::is<SkSL::Block>() const Line | Count | Source | 55 | 40.6M | bool is() const { | 56 | 40.6M | return this->fKind == T::kStatementKind; | 57 | 40.6M | } |
bool SkSL::Statement::is<SkSL::InlineMarker>() const Line | Count | Source | 55 | 6.29M | bool is() const { | 56 | 6.29M | return this->fKind == T::kStatementKind; | 57 | 6.29M | } |
bool SkSL::Statement::is<SkSL::IfStatement>() const Line | Count | Source | 55 | 4.88M | bool is() const { | 56 | 4.88M | return this->fKind == T::kStatementKind; | 57 | 4.88M | } |
bool SkSL::Statement::is<SkSL::DoStatement>() const Line | Count | Source | 55 | 499k | bool is() const { | 56 | 499k | return this->fKind == T::kStatementKind; | 57 | 499k | } |
bool SkSL::Statement::is<SkSL::ExpressionStatement>() const Line | Count | Source | 55 | 3.22M | bool is() const { | 56 | 3.22M | return this->fKind == T::kStatementKind; | 57 | 3.22M | } |
bool SkSL::Statement::is<SkSL::ReturnStatement>() const Line | Count | Source | 55 | 13.1M | bool is() const { | 56 | 13.1M | return this->fKind == T::kStatementKind; | 57 | 13.1M | } |
bool SkSL::Statement::is<SkSL::SwitchStatement>() const Line | Count | Source | 55 | 7.77k | bool is() const { | 56 | 7.77k | return this->fKind == T::kStatementKind; | 57 | 7.77k | } |
bool SkSL::Statement::is<SkSL::SwitchCase>() const Line | Count | Source | 55 | 54.4k | bool is() const { | 56 | 54.4k | return this->fKind == T::kStatementKind; | 57 | 54.4k | } |
|
58 | | |
59 | | /** |
60 | | * Use as<T> to downcast statements. |
61 | | * e.g. replace `(ReturnStatement&) s` with `s.as<ReturnStatement>()`. |
62 | | */ |
63 | | template <typename T> |
64 | 48.2M | const T& as() const { |
65 | 48.2M | SkASSERT(this->is<T>()); |
66 | 48.2M | return static_cast<const T&>(*this); |
67 | 48.2M | } SkSL::VarDeclaration const& SkSL::Statement::as<SkSL::VarDeclaration>() const Line | Count | Source | 64 | 568k | const T& as() const { | 65 | 568k | SkASSERT(this->is<T>()); | 66 | 568k | return static_cast<const T&>(*this); | 67 | 568k | } |
SkSL::IfStatement const& SkSL::Statement::as<SkSL::IfStatement>() const Line | Count | Source | 64 | 131k | const T& as() const { | 65 | 131k | SkASSERT(this->is<T>()); | 66 | 131k | return static_cast<const T&>(*this); | 67 | 131k | } |
SkSL::Block const& SkSL::Statement::as<SkSL::Block>() const Line | Count | Source | 64 | 370k | const T& as() const { | 65 | 370k | SkASSERT(this->is<T>()); | 66 | 370k | return static_cast<const T&>(*this); | 67 | 370k | } |
SkSL::ExpressionStatement const& SkSL::Statement::as<SkSL::ExpressionStatement>() const Line | Count | Source | 64 | 262k | const T& as() const { | 65 | 262k | SkASSERT(this->is<T>()); | 66 | 262k | return static_cast<const T&>(*this); | 67 | 262k | } |
SkSL::ReturnStatement const& SkSL::Statement::as<SkSL::ReturnStatement>() const Line | Count | Source | 64 | 151k | const T& as() const { | 65 | 151k | SkASSERT(this->is<T>()); | 66 | 151k | return static_cast<const T&>(*this); | 67 | 151k | } |
SkSL::VarDeclaration const& SkSL::Statement::as<SkSL::VarDeclaration>() const Line | Count | Source | 64 | 6.67M | const T& as() const { | 65 | 6.67M | SkASSERT(this->is<T>()); | 66 | 6.67M | return static_cast<const T&>(*this); | 67 | 6.67M | } |
SkSL::IfStatement const& SkSL::Statement::as<SkSL::IfStatement>() const Line | Count | Source | 64 | 3.44M | const T& as() const { | 65 | 3.44M | SkASSERT(this->is<T>()); | 66 | 3.44M | return static_cast<const T&>(*this); | 67 | 3.44M | } |
SkSL::ForStatement const& SkSL::Statement::as<SkSL::ForStatement>() const Line | Count | Source | 64 | 302k | const T& as() const { | 65 | 302k | SkASSERT(this->is<T>()); | 66 | 302k | return static_cast<const T&>(*this); | 67 | 302k | } |
SkSL::DoStatement const& SkSL::Statement::as<SkSL::DoStatement>() const Line | Count | Source | 64 | 3.98k | const T& as() const { | 65 | 3.98k | SkASSERT(this->is<T>()); | 66 | 3.98k | return static_cast<const T&>(*this); | 67 | 3.98k | } |
SkSL::SwitchStatement const& SkSL::Statement::as<SkSL::SwitchStatement>() const Line | Count | Source | 64 | 6.38k | const T& as() const { | 65 | 6.38k | SkASSERT(this->is<T>()); | 66 | 6.38k | return static_cast<const T&>(*this); | 67 | 6.38k | } |
SkSL::Block const& SkSL::Statement::as<SkSL::Block>() const Line | Count | Source | 64 | 24.3M | const T& as() const { | 65 | 24.3M | SkASSERT(this->is<T>()); | 66 | 24.3M | return static_cast<const T&>(*this); | 67 | 24.3M | } |
SkSL::SwitchCase const& SkSL::Statement::as<SkSL::SwitchCase>() const Line | Count | Source | 64 | 6.16k | const T& as() const { | 65 | 6.16k | SkASSERT(this->is<T>()); | 66 | 6.16k | return static_cast<const T&>(*this); | 67 | 6.16k | } |
SkSL::ExpressionStatement const& SkSL::Statement::as<SkSL::ExpressionStatement>() const Line | Count | Source | 64 | 2.38M | const T& as() const { | 65 | 2.38M | SkASSERT(this->is<T>()); | 66 | 2.38M | return static_cast<const T&>(*this); | 67 | 2.38M | } |
SkSL::ReturnStatement const& SkSL::Statement::as<SkSL::ReturnStatement>() const Line | Count | Source | 64 | 9.26M | const T& as() const { | 65 | 9.26M | SkASSERT(this->is<T>()); | 66 | 9.26M | return static_cast<const T&>(*this); | 67 | 9.26M | } |
SkSL::InlineMarker const& SkSL::Statement::as<SkSL::InlineMarker>() const Line | Count | Source | 64 | 265k | const T& as() const { | 65 | 265k | SkASSERT(this->is<T>()); | 66 | 265k | return static_cast<const T&>(*this); | 67 | 265k | } |
|
68 | | |
69 | | template <typename T> |
70 | 20.1M | T& as() { |
71 | 20.1M | SkASSERT(this->is<T>()); |
72 | 20.1M | return static_cast<T&>(*this); |
73 | 20.1M | } SkSL::VarDeclaration& SkSL::Statement::as<SkSL::VarDeclaration>() Line | Count | Source | 70 | 131k | T& as() { | 71 | 131k | SkASSERT(this->is<T>()); | 72 | 131k | return static_cast<T&>(*this); | 73 | 131k | } |
SkSL::Block& SkSL::Statement::as<SkSL::Block>() Line | Count | Source | 70 | 384 | T& as() { | 71 | 384 | SkASSERT(this->is<T>()); | 72 | 384 | return static_cast<T&>(*this); | 73 | 384 | } |
SkSL::ExpressionStatement& SkSL::Statement::as<SkSL::ExpressionStatement>() Line | Count | Source | 70 | 119 | T& as() { | 71 | 119 | SkASSERT(this->is<T>()); | 72 | 119 | return static_cast<T&>(*this); | 73 | 119 | } |
SkSL::IfStatement& SkSL::Statement::as<SkSL::IfStatement>() Line | Count | Source | 70 | 112 | T& as() { | 71 | 112 | SkASSERT(this->is<T>()); | 72 | 112 | return static_cast<T&>(*this); | 73 | 112 | } |
SkSL::ReturnStatement& SkSL::Statement::as<SkSL::ReturnStatement>() Line | Count | Source | 70 | 113 | T& as() { | 71 | 113 | SkASSERT(this->is<T>()); | 72 | 113 | return static_cast<T&>(*this); | 73 | 113 | } |
SkSL::VarDeclaration& SkSL::Statement::as<SkSL::VarDeclaration>() Line | Count | Source | 70 | 2.56M | T& as() { | 71 | 2.56M | SkASSERT(this->is<T>()); | 72 | 2.56M | return static_cast<T&>(*this); | 73 | 2.56M | } |
SkSL::SwitchCase& SkSL::Statement::as<SkSL::SwitchCase>() Line | Count | Source | 70 | 42.5k | T& as() { | 71 | 42.5k | SkASSERT(this->is<T>()); | 72 | 42.5k | return static_cast<T&>(*this); | 73 | 42.5k | } |
SkSL::Block& SkSL::Statement::as<SkSL::Block>() Line | Count | Source | 70 | 11.6M | T& as() { | 71 | 11.6M | SkASSERT(this->is<T>()); | 72 | 11.6M | return static_cast<T&>(*this); | 73 | 11.6M | } |
SkSL::DoStatement& SkSL::Statement::as<SkSL::DoStatement>() Line | Count | Source | 70 | 1.47k | T& as() { | 71 | 1.47k | SkASSERT(this->is<T>()); | 72 | 1.47k | return static_cast<T&>(*this); | 73 | 1.47k | } |
SkSL::ExpressionStatement& SkSL::Statement::as<SkSL::ExpressionStatement>() Line | Count | Source | 70 | 841k | T& as() { | 71 | 841k | SkASSERT(this->is<T>()); | 72 | 841k | return static_cast<T&>(*this); | 73 | 841k | } |
SkSL::ForStatement& SkSL::Statement::as<SkSL::ForStatement>() Line | Count | Source | 70 | 28.0k | T& as() { | 71 | 28.0k | SkASSERT(this->is<T>()); | 72 | 28.0k | return static_cast<T&>(*this); | 73 | 28.0k | } |
SkSL::IfStatement& SkSL::Statement::as<SkSL::IfStatement>() Line | Count | Source | 70 | 942k | T& as() { | 71 | 942k | SkASSERT(this->is<T>()); | 72 | 942k | return static_cast<T&>(*this); | 73 | 942k | } |
SkSL::ReturnStatement& SkSL::Statement::as<SkSL::ReturnStatement>() Line | Count | Source | 70 | 3.90M | T& as() { | 71 | 3.90M | SkASSERT(this->is<T>()); | 72 | 3.90M | return static_cast<T&>(*this); | 73 | 3.90M | } |
SkSL::SwitchStatement& SkSL::Statement::as<SkSL::SwitchStatement>() Line | Count | Source | 70 | 1.38k | T& as() { | 71 | 1.38k | SkASSERT(this->is<T>()); | 72 | 1.38k | return static_cast<T&>(*this); | 73 | 1.38k | } |
|
74 | | |
75 | 1.06M | virtual bool isEmpty() const { |
76 | 1.06M | return false; |
77 | 1.06M | } |
78 | | |
79 | | virtual std::unique_ptr<Statement> clone() const = 0; |
80 | | |
81 | | private: |
82 | | using INHERITED = IRNode; |
83 | | }; |
84 | | |
85 | | } // namespace SkSL |
86 | | |
87 | | #endif |