1 // Copyright 2021 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_SEM_SWITCH_STATEMENT_H_ 16 #define SRC_SEM_SWITCH_STATEMENT_H_ 17 18 #include "src/sem/block_statement.h" 19 20 // Forward declarations 21 namespace tint { 22 namespace ast { 23 class CaseStatement; 24 class SwitchStatement; 25 } // namespace ast 26 } // namespace tint 27 28 namespace tint { 29 namespace sem { 30 31 /// Holds semantic information about an switch statement 32 class SwitchStatement : public Castable<SwitchStatement, CompoundStatement> { 33 public: 34 /// Constructor 35 /// @param declaration the AST node for this switch statement 36 /// @param parent the owning statement 37 /// @param function the owning function 38 SwitchStatement(const ast::SwitchStatement* declaration, 39 const CompoundStatement* parent, 40 const sem::Function* function); 41 42 /// Destructor 43 ~SwitchStatement() override; 44 45 /// @return the AST node for this statement 46 const ast::SwitchStatement* Declaration() const; 47 }; 48 49 /// Holds semantic information about a switch case statement 50 class CaseStatement : public Castable<CaseStatement, CompoundStatement> { 51 public: 52 /// Constructor 53 /// @param declaration the AST node for this case statement 54 /// @param parent the owning statement 55 /// @param function the owning function 56 CaseStatement(const ast::CaseStatement* declaration, 57 const CompoundStatement* parent, 58 const sem::Function* function); 59 60 /// Destructor 61 ~CaseStatement() override; 62 63 /// @return the AST node for this statement 64 const ast::CaseStatement* Declaration() const; 65 66 /// @param body the case body block statement SetBlock(const BlockStatement * body)67 void SetBlock(const BlockStatement* body) { body_ = body; } 68 69 /// @returns the case body block statement Body()70 const BlockStatement* Body() const { return body_; } 71 72 private: 73 const BlockStatement* body_ = nullptr; 74 }; 75 76 } // namespace sem 77 } // namespace tint 78 79 #endif // SRC_SEM_SWITCH_STATEMENT_H_ 80