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_IF_STATEMENT_H_ 16 #define SRC_SEM_IF_STATEMENT_H_ 17 18 #include "src/sem/statement.h" 19 20 // Forward declarations 21 namespace tint { 22 namespace ast { 23 class IfStatement; 24 class ElseStatement; 25 } // namespace ast 26 namespace sem { 27 class Expression; 28 } // namespace sem 29 } // namespace tint 30 31 namespace tint { 32 namespace sem { 33 34 /// Holds semantic information about an if statement 35 class IfStatement : public Castable<IfStatement, CompoundStatement> { 36 public: 37 /// Constructor 38 /// @param declaration the AST node for this if statement 39 /// @param parent the owning statement 40 /// @param function the owning function 41 IfStatement(const ast::IfStatement* declaration, 42 const CompoundStatement* parent, 43 const sem::Function* function); 44 45 /// Destructor 46 ~IfStatement() override; 47 48 /// @returns the if-statement condition expression Condition()49 const Expression* Condition() const { return condition_; } 50 51 /// Sets the if-statement condition expression 52 /// @param condition the if condition expression SetCondition(const Expression * condition)53 void SetCondition(const Expression* condition) { condition_ = condition; } 54 55 private: 56 const Expression* condition_ = nullptr; 57 }; 58 59 /// Holds semantic information about an else statement 60 class ElseStatement : public Castable<ElseStatement, CompoundStatement> { 61 public: 62 /// Constructor 63 /// @param declaration the AST node for this else statement 64 /// @param parent the owning statement 65 /// @param function the owning function 66 ElseStatement(const ast::ElseStatement* declaration, 67 const CompoundStatement* parent, 68 const sem::Function* function); 69 70 /// Destructor 71 ~ElseStatement() override; 72 73 /// @returns the else-statement condition expression Condition()74 const Expression* Condition() const { return condition_; } 75 76 /// Sets the else-statement condition expression 77 /// @param condition the else condition expression SetCondition(const Expression * condition)78 void SetCondition(const Expression* condition) { condition_ = condition; } 79 80 private: 81 const Expression* condition_ = nullptr; 82 }; 83 84 } // namespace sem 85 } // namespace tint 86 87 #endif // SRC_SEM_IF_STATEMENT_H_ 88