2020-03-02 20:47:43 +00:00
|
|
|
// 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 <assert.h>
|
|
|
|
|
|
|
|
#include "src/ast/assignment_statement.h"
|
2020-07-27 15:25:00 +00:00
|
|
|
#include "src/ast/block_statement.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
#include "src/ast/break_statement.h"
|
2020-07-21 13:42:05 +00:00
|
|
|
#include "src/ast/call_statement.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
#include "src/ast/case_statement.h"
|
|
|
|
#include "src/ast/continue_statement.h"
|
2020-07-25 03:34:33 +00:00
|
|
|
#include "src/ast/discard_statement.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
#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"
|
2020-03-30 22:46:48 +00:00
|
|
|
#include "src/ast/variable_decl_statement.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace ast {
|
|
|
|
|
|
|
|
Statement::Statement() = default;
|
|
|
|
|
|
|
|
Statement::Statement(const Source& source) : Node(source) {}
|
|
|
|
|
2020-04-09 18:52:06 +00:00
|
|
|
Statement::Statement(Statement&&) = default;
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
Statement::~Statement() = default;
|
|
|
|
|
2020-04-09 18:52:06 +00:00
|
|
|
bool Statement::IsAssign() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:25:00 +00:00
|
|
|
bool Statement::IsBlock() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:52:06 +00:00
|
|
|
bool Statement::IsBreak() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Statement::IsCase() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:42:05 +00:00
|
|
|
bool Statement::IsCall() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:52:06 +00:00
|
|
|
bool Statement::IsContinue() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-25 03:34:33 +00:00
|
|
|
bool Statement::IsDiscard() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:52:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-11 14:11:55 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:52:10 +00:00
|
|
|
const AssignmentStatement* Statement::AsAssign() const {
|
|
|
|
assert(IsAssign());
|
|
|
|
return static_cast<const AssignmentStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:25:00 +00:00
|
|
|
const BlockStatement* Statement::AsBlock() const {
|
|
|
|
assert(IsBlock());
|
|
|
|
return static_cast<const BlockStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:52:10 +00:00
|
|
|
const BreakStatement* Statement::AsBreak() const {
|
|
|
|
assert(IsBreak());
|
|
|
|
return static_cast<const BreakStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:42:05 +00:00
|
|
|
const CallStatement* Statement::AsCall() const {
|
|
|
|
assert(IsCall());
|
|
|
|
return static_cast<const CallStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:52:10 +00:00
|
|
|
const CaseStatement* Statement::AsCase() const {
|
|
|
|
assert(IsCase());
|
|
|
|
return static_cast<const CaseStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ContinueStatement* Statement::AsContinue() const {
|
|
|
|
assert(IsContinue());
|
|
|
|
return static_cast<const ContinueStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-07-25 03:34:33 +00:00
|
|
|
const DiscardStatement* Statement::AsDiscard() const {
|
|
|
|
assert(IsDiscard());
|
|
|
|
return static_cast<const DiscardStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:52:10 +00:00
|
|
|
const ElseStatement* Statement::AsElse() const {
|
|
|
|
assert(IsElse());
|
|
|
|
return static_cast<const ElseStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const FallthroughStatement* Statement::AsFallthrough() const {
|
|
|
|
assert(IsFallthrough());
|
|
|
|
return static_cast<const FallthroughStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const IfStatement* Statement::AsIf() const {
|
|
|
|
assert(IsIf());
|
|
|
|
return static_cast<const IfStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const LoopStatement* Statement::AsLoop() const {
|
|
|
|
assert(IsLoop());
|
|
|
|
return static_cast<const LoopStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ReturnStatement* Statement::AsReturn() const {
|
|
|
|
assert(IsReturn());
|
|
|
|
return static_cast<const ReturnStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SwitchStatement* Statement::AsSwitch() const {
|
|
|
|
assert(IsSwitch());
|
|
|
|
return static_cast<const SwitchStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const VariableDeclStatement* Statement::AsVariableDecl() const {
|
|
|
|
assert(IsVariableDecl());
|
|
|
|
return static_cast<const VariableDeclStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
AssignmentStatement* Statement::AsAssign() {
|
|
|
|
assert(IsAssign());
|
|
|
|
return static_cast<AssignmentStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:25:00 +00:00
|
|
|
BlockStatement* Statement::AsBlock() {
|
|
|
|
assert(IsBlock());
|
|
|
|
return static_cast<BlockStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
BreakStatement* Statement::AsBreak() {
|
|
|
|
assert(IsBreak());
|
|
|
|
return static_cast<BreakStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:42:05 +00:00
|
|
|
CallStatement* Statement::AsCall() {
|
|
|
|
assert(IsCall());
|
|
|
|
return static_cast<CallStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
CaseStatement* Statement::AsCase() {
|
|
|
|
assert(IsCase());
|
|
|
|
return static_cast<CaseStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContinueStatement* Statement::AsContinue() {
|
|
|
|
assert(IsContinue());
|
|
|
|
return static_cast<ContinueStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-07-25 03:34:33 +00:00
|
|
|
DiscardStatement* Statement::AsDiscard() {
|
|
|
|
assert(IsDiscard());
|
|
|
|
return static_cast<DiscardStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
ElseStatement* Statement::AsElse() {
|
|
|
|
assert(IsElse());
|
|
|
|
return static_cast<ElseStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
FallthroughStatement* Statement::AsFallthrough() {
|
|
|
|
assert(IsFallthrough());
|
|
|
|
return static_cast<FallthroughStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
IfStatement* Statement::AsIf() {
|
|
|
|
assert(IsIf());
|
|
|
|
return static_cast<IfStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
LoopStatement* Statement::AsLoop() {
|
|
|
|
assert(IsLoop());
|
|
|
|
return static_cast<LoopStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnStatement* Statement::AsReturn() {
|
|
|
|
assert(IsReturn());
|
|
|
|
return static_cast<ReturnStatement*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
SwitchStatement* Statement::AsSwitch() {
|
|
|
|
assert(IsSwitch());
|
|
|
|
return static_cast<SwitchStatement*>(this);
|
|
|
|
}
|
|
|
|
|
2020-03-30 22:46:48 +00:00
|
|
|
VariableDeclStatement* Statement::AsVariableDecl() {
|
|
|
|
assert(IsVariableDecl());
|
|
|
|
return static_cast<VariableDeclStatement*>(this);
|
2020-03-02 20:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ast
|
|
|
|
} // namespace tint
|