// Copyright 2020 The Tint Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "src/ast/statement.h" #include #include "src/ast/assignment_statement.h" #include "src/ast/block_statement.h" #include "src/ast/break_statement.h" #include "src/ast/call_statement.h" #include "src/ast/case_statement.h" #include "src/ast/continue_statement.h" #include "src/ast/discard_statement.h" #include "src/ast/else_statement.h" #include "src/ast/fallthrough_statement.h" #include "src/ast/if_statement.h" #include "src/ast/loop_statement.h" #include "src/ast/return_statement.h" #include "src/ast/switch_statement.h" #include "src/ast/variable_decl_statement.h" namespace tint { namespace ast { Statement::Statement() = default; Statement::Statement(const Source& source) : Base(source) {} Statement::Statement(Statement&&) = default; Statement::~Statement() = default; bool Statement::IsAssign() const { return false; } bool Statement::IsBlock() const { return false; } bool Statement::IsBreak() const { return false; } bool Statement::IsCase() const { return false; } bool Statement::IsCall() const { return false; } bool Statement::IsContinue() const { return false; } bool Statement::IsDiscard() const { return false; } bool Statement::IsElse() const { return false; } bool Statement::IsFallthrough() const { return false; } bool Statement::IsIf() const { return false; } bool Statement::IsLoop() const { return false; } bool Statement::IsReturn() const { return false; } bool Statement::IsSwitch() const { return false; } bool Statement::IsVariableDecl() const { return false; } const char* Statement::Name() const { if (IsAssign()) { return "assignment statement"; } if (IsBlock()) { return "block statement"; } if (IsBreak()) { return "break statement"; } if (IsCase()) { return "case statement"; } if (IsCall()) { return "function call"; } if (IsContinue()) { return "continue statement"; } if (IsDiscard()) { return "discard statement"; } if (IsElse()) { return "else statement"; } if (IsFallthrough()) { return "fallthrough statement"; } if (IsIf()) { return "if statement"; } if (IsLoop()) { return "loop statement"; } if (IsReturn()) { return "return statement"; } if (IsSwitch()) { return "switch statement"; } if (IsVariableDecl()) { return "variable declaration"; } return "statement"; } const AssignmentStatement* Statement::AsAssign() const { assert(IsAssign()); return static_cast(this); } const BlockStatement* Statement::AsBlock() const { assert(IsBlock()); return static_cast(this); } const BreakStatement* Statement::AsBreak() const { assert(IsBreak()); return static_cast(this); } const CallStatement* Statement::AsCall() const { assert(IsCall()); return static_cast(this); } const CaseStatement* Statement::AsCase() const { assert(IsCase()); return static_cast(this); } const ContinueStatement* Statement::AsContinue() const { assert(IsContinue()); return static_cast(this); } const DiscardStatement* Statement::AsDiscard() const { assert(IsDiscard()); return static_cast(this); } const ElseStatement* Statement::AsElse() const { assert(IsElse()); return static_cast(this); } const FallthroughStatement* Statement::AsFallthrough() const { assert(IsFallthrough()); return static_cast(this); } const IfStatement* Statement::AsIf() const { assert(IsIf()); return static_cast(this); } const LoopStatement* Statement::AsLoop() const { assert(IsLoop()); return static_cast(this); } const ReturnStatement* Statement::AsReturn() const { assert(IsReturn()); return static_cast(this); } const SwitchStatement* Statement::AsSwitch() const { assert(IsSwitch()); return static_cast(this); } const VariableDeclStatement* Statement::AsVariableDecl() const { assert(IsVariableDecl()); return static_cast(this); } AssignmentStatement* Statement::AsAssign() { assert(IsAssign()); return static_cast(this); } BlockStatement* Statement::AsBlock() { assert(IsBlock()); return static_cast(this); } BreakStatement* Statement::AsBreak() { assert(IsBreak()); return static_cast(this); } CallStatement* Statement::AsCall() { assert(IsCall()); return static_cast(this); } CaseStatement* Statement::AsCase() { assert(IsCase()); return static_cast(this); } ContinueStatement* Statement::AsContinue() { assert(IsContinue()); return static_cast(this); } DiscardStatement* Statement::AsDiscard() { assert(IsDiscard()); return static_cast(this); } ElseStatement* Statement::AsElse() { assert(IsElse()); return static_cast(this); } FallthroughStatement* Statement::AsFallthrough() { assert(IsFallthrough()); return static_cast(this); } IfStatement* Statement::AsIf() { assert(IsIf()); return static_cast(this); } LoopStatement* Statement::AsLoop() { assert(IsLoop()); return static_cast(this); } ReturnStatement* Statement::AsReturn() { assert(IsReturn()); return static_cast(this); } SwitchStatement* Statement::AsSwitch() { assert(IsSwitch()); return static_cast(this); } VariableDeclStatement* Statement::AsVariableDecl() { assert(IsVariableDecl()); return static_cast(this); } } // namespace ast } // namespace tint