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_IF_STATEMENT_H_ 16 #define SRC_AST_IF_STATEMENT_H_ 17 18 #include <utility> 19 20 #include "src/ast/else_statement.h" 21 22 namespace tint { 23 namespace ast { 24 25 /// An if statement 26 class IfStatement : public Castable<IfStatement, Statement> { 27 public: 28 /// Constructor 29 /// @param pid the identifier of the program that owns this node 30 /// @param src the source of this node 31 /// @param condition the if condition 32 /// @param body the if body 33 /// @param else_stmts the else statements 34 IfStatement(ProgramID pid, 35 const Source& src, 36 const Expression* condition, 37 const BlockStatement* body, 38 ElseStatementList else_stmts); 39 /// Move constructor 40 IfStatement(IfStatement&&); 41 ~IfStatement() override; 42 43 /// Clones this node and all transitive child nodes using the `CloneContext` 44 /// `ctx`. 45 /// @param ctx the clone context 46 /// @return the newly cloned node 47 const IfStatement* Clone(CloneContext* ctx) const override; 48 49 /// The if condition or nullptr if none set 50 const Expression* const condition; 51 52 /// The if body 53 const BlockStatement* const body; 54 55 /// The else statements 56 const ElseStatementList else_statements; 57 }; 58 59 } // namespace ast 60 } // namespace tint 61 62 #endif // SRC_AST_IF_STATEMENT_H_ 63