• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_AST_CASE_STATEMENT_H_
16 #define SRC_AST_CASE_STATEMENT_H_
17 
18 #include <vector>
19 
20 #include "src/ast/block_statement.h"
21 #include "src/ast/int_literal_expression.h"
22 
23 namespace tint {
24 namespace ast {
25 
26 /// A list of case literals
27 using CaseSelectorList = std::vector<const IntLiteralExpression*>;
28 
29 /// A case statement
30 class CaseStatement : public Castable<CaseStatement, Statement> {
31  public:
32   /// Constructor
33   /// @param pid the identifier of the program that owns this node
34   /// @param src the source of this node
35   /// @param selectors the case selectors
36   /// @param body the case body
37   CaseStatement(ProgramID pid,
38                 const Source& src,
39                 CaseSelectorList selectors,
40                 const BlockStatement* body);
41   /// Move constructor
42   CaseStatement(CaseStatement&&);
43   ~CaseStatement() override;
44 
45   /// @returns true if this is a default statement
IsDefault()46   bool IsDefault() const { return selectors.empty(); }
47 
48   /// Clones this node and all transitive child nodes using the `CloneContext`
49   /// `ctx`.
50   /// @param ctx the clone context
51   /// @return the newly cloned node
52   const CaseStatement* Clone(CloneContext* ctx) const override;
53 
54   /// The case selectors, empty if none set
55   const CaseSelectorList selectors;
56 
57   /// The case body
58   const BlockStatement* const body;
59 };
60 
61 /// A list of case statements
62 using CaseStatementList = std::vector<const CaseStatement*>;
63 
64 }  // namespace ast
65 }  // namespace tint
66 
67 #endif  // SRC_AST_CASE_STATEMENT_H_
68