dan sinclair | f148f08 | 2022-10-19 15:55:02 +0000 | [diff] [blame] | 1 | // Copyright 2022 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef SRC_TINT_AST_CASE_SELECTOR_H_ |
| 16 | #define SRC_TINT_AST_CASE_SELECTOR_H_ |
| 17 | |
| 18 | #include <vector> |
| 19 | |
| 20 | #include "src/tint/ast/block_statement.h" |
| 21 | #include "src/tint/ast/expression.h" |
| 22 | |
| 23 | namespace tint::ast { |
| 24 | |
| 25 | /// A case selector |
| 26 | class CaseSelector final : public Castable<CaseSelector, Node> { |
| 27 | public: |
| 28 | /// Constructor |
| 29 | /// @param pid the identifier of the program that owns this node |
| 30 | /// @param nid the unique node identifier |
| 31 | /// @param src the source of this node |
| 32 | /// @param expr the selector expression, |nullptr| for a `default` selector |
| 33 | CaseSelector(ProgramID pid, NodeID nid, const Source& src, const Expression* expr = nullptr); |
| 34 | /// Move constructor |
| 35 | CaseSelector(CaseSelector&&); |
| 36 | ~CaseSelector() override; |
| 37 | |
| 38 | /// @returns true if this is a default statement |
| 39 | bool IsDefault() const { return expr == nullptr; } |
| 40 | |
| 41 | /// Clones this node and all transitive child nodes using the `CloneContext` `ctx`. |
| 42 | /// @param ctx the clone context |
| 43 | /// @return the newly cloned node |
| 44 | const CaseSelector* Clone(CloneContext* ctx) const override; |
| 45 | |
| 46 | /// The selector, nullptr for a default selector |
| 47 | const Expression* const expr = nullptr; |
| 48 | }; |
| 49 | |
| 50 | } // namespace tint::ast |
| 51 | |
| 52 | #endif // SRC_TINT_AST_CASE_SELECTOR_H_ |