mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 16:37:08 +00:00
Replace Statement::(Is|As)* with Castable
Change-Id: I5520752a4b5844be0ecac7921616893d123b246a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34315 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -31,10 +31,6 @@ AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default;
|
||||
|
||||
AssignmentStatement::~AssignmentStatement() = default;
|
||||
|
||||
bool AssignmentStatement::IsAssign() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AssignmentStatement::IsValid() const {
|
||||
if (lhs_ == nullptr || !lhs_->IsValid())
|
||||
return false;
|
||||
|
||||
@@ -55,9 +55,6 @@ class AssignmentStatement : public Castable<AssignmentStatement, Statement> {
|
||||
/// @returns the right side expression
|
||||
Expression* rhs() const { return rhs_; }
|
||||
|
||||
/// @returns true if this is an assignment statement
|
||||
bool IsAssign() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ TEST_F(AssignmentStatementTest, IsAssign) {
|
||||
auto* rhs = create<ast::IdentifierExpression>("rhs");
|
||||
|
||||
AssignmentStatement stmt(lhs, rhs);
|
||||
EXPECT_TRUE(stmt.IsAssign());
|
||||
EXPECT_TRUE(stmt.Is<AssignmentStatement>());
|
||||
}
|
||||
|
||||
TEST_F(AssignmentStatementTest, IsValid) {
|
||||
|
||||
@@ -25,10 +25,6 @@ BlockStatement::BlockStatement(BlockStatement&&) = default;
|
||||
|
||||
BlockStatement::~BlockStatement() = default;
|
||||
|
||||
bool BlockStatement::IsBlock() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BlockStatement::IsValid() const {
|
||||
for (auto* stmt : *this) {
|
||||
if (stmt == nullptr || !stmt->IsValid()) {
|
||||
|
||||
@@ -87,9 +87,6 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
|
||||
return statements_.end();
|
||||
}
|
||||
|
||||
/// @returns true if this is a block statement
|
||||
bool IsBlock() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ TEST_F(BlockStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(BlockStatementTest, IsBlock) {
|
||||
BlockStatement b;
|
||||
EXPECT_TRUE(b.IsBlock());
|
||||
EXPECT_TRUE(b.Is<BlockStatement>());
|
||||
}
|
||||
|
||||
TEST_F(BlockStatementTest, IsValid) {
|
||||
|
||||
@@ -25,10 +25,6 @@ BreakStatement::BreakStatement(BreakStatement&&) = default;
|
||||
|
||||
BreakStatement::~BreakStatement() = default;
|
||||
|
||||
bool BreakStatement::IsBreak() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BreakStatement::IsValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,6 @@ class BreakStatement : public Castable<BreakStatement, Statement> {
|
||||
BreakStatement(BreakStatement&&);
|
||||
~BreakStatement() override;
|
||||
|
||||
/// @returns true if this is an break statement
|
||||
bool IsBreak() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST_F(BreakStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(BreakStatementTest, IsBreak) {
|
||||
BreakStatement stmt;
|
||||
EXPECT_TRUE(stmt.IsBreak());
|
||||
EXPECT_TRUE(stmt.Is<BreakStatement>());
|
||||
}
|
||||
|
||||
TEST_F(BreakStatementTest, IsValid) {
|
||||
|
||||
@@ -27,10 +27,6 @@ CallStatement::CallStatement(CallStatement&&) = default;
|
||||
|
||||
CallStatement::~CallStatement() = default;
|
||||
|
||||
bool CallStatement::IsCall() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CallStatement::IsValid() const {
|
||||
return call_ != nullptr && call_->IsValid();
|
||||
}
|
||||
|
||||
@@ -42,9 +42,6 @@ class CallStatement : public Castable<CallStatement, Statement> {
|
||||
/// @returns the call expression
|
||||
CallExpression* expr() const { return call_; }
|
||||
|
||||
/// @returns true if this is a call statement
|
||||
bool IsCall() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_F(CallStatementTest, Creation) {
|
||||
|
||||
TEST_F(CallStatementTest, IsCall) {
|
||||
CallStatement c;
|
||||
EXPECT_TRUE(c.IsCall());
|
||||
EXPECT_TRUE(c.Is<CallStatement>());
|
||||
}
|
||||
|
||||
TEST_F(CallStatementTest, IsValid) {
|
||||
|
||||
@@ -31,10 +31,6 @@ CaseStatement::CaseStatement(CaseStatement&&) = default;
|
||||
|
||||
CaseStatement::~CaseStatement() = default;
|
||||
|
||||
bool CaseStatement::IsCase() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CaseStatement::IsValid() const {
|
||||
return body_ != nullptr && body_->IsValid();
|
||||
}
|
||||
|
||||
@@ -70,9 +70,6 @@ class CaseStatement : public Castable<CaseStatement, Statement> {
|
||||
/// @returns the case body
|
||||
BlockStatement* body() { return body_; }
|
||||
|
||||
/// @returns true if this is a case statement
|
||||
bool IsCase() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
|
||||
|
||||
TEST_F(CaseStatementTest, IsCase) {
|
||||
CaseStatement c(create<ast::BlockStatement>());
|
||||
EXPECT_TRUE(c.IsCase());
|
||||
EXPECT_TRUE(c.Is<ast::CaseStatement>());
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsValid) {
|
||||
|
||||
@@ -25,10 +25,6 @@ ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
|
||||
|
||||
ContinueStatement::~ContinueStatement() = default;
|
||||
|
||||
bool ContinueStatement::IsContinue() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ContinueStatement::IsValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,9 +35,6 @@ class ContinueStatement : public Castable<ContinueStatement, Statement> {
|
||||
ContinueStatement(ContinueStatement&&);
|
||||
~ContinueStatement() override;
|
||||
|
||||
/// @returns true if this is an continue statement
|
||||
bool IsContinue() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST_F(ContinueStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(ContinueStatementTest, IsContinue) {
|
||||
ContinueStatement stmt;
|
||||
EXPECT_TRUE(stmt.IsContinue());
|
||||
EXPECT_TRUE(stmt.Is<ContinueStatement>());
|
||||
}
|
||||
|
||||
TEST_F(ContinueStatementTest, IsValid) {
|
||||
|
||||
@@ -25,10 +25,6 @@ DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
|
||||
|
||||
DiscardStatement::~DiscardStatement() = default;
|
||||
|
||||
bool DiscardStatement::IsDiscard() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DiscardStatement::IsValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,6 @@ class DiscardStatement : public Castable<DiscardStatement, Statement> {
|
||||
DiscardStatement(DiscardStatement&&);
|
||||
~DiscardStatement() override;
|
||||
|
||||
/// @returns true if this is a discard statement
|
||||
bool IsDiscard() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ TEST_F(DiscardStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(DiscardStatementTest, IsDiscard) {
|
||||
DiscardStatement stmt;
|
||||
EXPECT_TRUE(stmt.IsDiscard());
|
||||
EXPECT_TRUE(stmt.Is<DiscardStatement>());
|
||||
}
|
||||
|
||||
TEST_F(DiscardStatementTest, IsValid) {
|
||||
|
||||
@@ -34,10 +34,6 @@ ElseStatement::ElseStatement(ElseStatement&&) = default;
|
||||
|
||||
ElseStatement::~ElseStatement() = default;
|
||||
|
||||
bool ElseStatement::IsElse() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ElseStatement::IsValid() const {
|
||||
if (body_ == nullptr || !body_->IsValid()) {
|
||||
return false;
|
||||
|
||||
@@ -67,9 +67,6 @@ class ElseStatement : public Castable<ElseStatement, Statement> {
|
||||
/// @returns the else body
|
||||
BlockStatement* body() { return body_; }
|
||||
|
||||
/// @returns true if this is a else statement
|
||||
bool IsElse() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ TEST_F(ElseStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(ElseStatementTest, IsElse) {
|
||||
ElseStatement e(create<BlockStatement>());
|
||||
EXPECT_TRUE(e.IsElse());
|
||||
EXPECT_TRUE(e.Is<ElseStatement>());
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, HasCondition) {
|
||||
|
||||
@@ -26,10 +26,6 @@ FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default;
|
||||
|
||||
FallthroughStatement::~FallthroughStatement() = default;
|
||||
|
||||
bool FallthroughStatement::IsFallthrough() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FallthroughStatement::IsValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,9 +32,6 @@ class FallthroughStatement : public Castable<FallthroughStatement, Statement> {
|
||||
FallthroughStatement(FallthroughStatement&&);
|
||||
~FallthroughStatement() override;
|
||||
|
||||
/// @returns true if this is an fallthrough statement
|
||||
bool IsFallthrough() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST_F(FallthroughStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(FallthroughStatementTest, IsFallthrough) {
|
||||
FallthroughStatement stmt;
|
||||
EXPECT_TRUE(stmt.IsFallthrough());
|
||||
EXPECT_TRUE(stmt.Is<FallthroughStatement>());
|
||||
}
|
||||
|
||||
TEST_F(FallthroughStatementTest, IsValid) {
|
||||
|
||||
@@ -31,10 +31,6 @@ IfStatement::IfStatement(IfStatement&&) = default;
|
||||
|
||||
IfStatement::~IfStatement() = default;
|
||||
|
||||
bool IfStatement::IsIf() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IfStatement::IsValid() const {
|
||||
if (condition_ == nullptr || !condition_->IsValid()) {
|
||||
return false;
|
||||
|
||||
@@ -71,9 +71,6 @@ class IfStatement : public Castable<IfStatement, Statement> {
|
||||
/// @returns true if there are else statements
|
||||
bool has_else_statements() const { return !else_statements_.empty(); }
|
||||
|
||||
/// @returns true if this is a if statement
|
||||
bool IsIf() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ TEST_F(IfStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(IfStatementTest, IsIf) {
|
||||
IfStatement stmt(nullptr, create<BlockStatement>());
|
||||
EXPECT_TRUE(stmt.IsIf());
|
||||
EXPECT_TRUE(stmt.Is<IfStatement>());
|
||||
}
|
||||
|
||||
TEST_F(IfStatementTest, IsValid) {
|
||||
|
||||
@@ -29,10 +29,6 @@ LoopStatement::LoopStatement(LoopStatement&&) = default;
|
||||
|
||||
LoopStatement::~LoopStatement() = default;
|
||||
|
||||
bool LoopStatement::IsLoop() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoopStatement::IsValid() const {
|
||||
if (body_ == nullptr || !body_->IsValid()) {
|
||||
return false;
|
||||
|
||||
@@ -62,9 +62,6 @@ class LoopStatement : public Castable<LoopStatement, Statement> {
|
||||
return continuing_ != nullptr && !continuing_->empty();
|
||||
}
|
||||
|
||||
/// @returns true if this is a loop statement
|
||||
bool IsLoop() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ TEST_F(LoopStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(LoopStatementTest, IsLoop) {
|
||||
LoopStatement l(create<BlockStatement>(), create<BlockStatement>());
|
||||
EXPECT_TRUE(l.IsLoop());
|
||||
EXPECT_TRUE(l.Is<LoopStatement>());
|
||||
}
|
||||
|
||||
TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
|
||||
|
||||
@@ -30,10 +30,6 @@ ReturnStatement::ReturnStatement(ReturnStatement&&) = default;
|
||||
|
||||
ReturnStatement::~ReturnStatement() = default;
|
||||
|
||||
bool ReturnStatement::IsReturn() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReturnStatement::IsValid() const {
|
||||
if (value_ != nullptr) {
|
||||
return value_->IsValid();
|
||||
|
||||
@@ -51,9 +51,6 @@ class ReturnStatement : public Castable<ReturnStatement, Statement> {
|
||||
/// @returns true if the return has a value
|
||||
bool has_value() const { return value_ != nullptr; }
|
||||
|
||||
/// @returns true if this is a return statement
|
||||
bool IsReturn() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ TEST_F(ReturnStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(ReturnStatementTest, IsReturn) {
|
||||
ReturnStatement r;
|
||||
EXPECT_TRUE(r.IsReturn());
|
||||
EXPECT_TRUE(r.Is<ReturnStatement>());
|
||||
}
|
||||
|
||||
TEST_F(ReturnStatementTest, HasValue_WithoutValue) {
|
||||
|
||||
@@ -42,247 +42,51 @@ 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()) {
|
||||
if (Is<AssignmentStatement>()) {
|
||||
return "assignment statement";
|
||||
}
|
||||
if (IsBlock()) {
|
||||
if (Is<BlockStatement>()) {
|
||||
return "block statement";
|
||||
}
|
||||
if (IsBreak()) {
|
||||
if (Is<BreakStatement>()) {
|
||||
return "break statement";
|
||||
}
|
||||
if (IsCase()) {
|
||||
if (Is<CaseStatement>()) {
|
||||
return "case statement";
|
||||
}
|
||||
if (IsCall()) {
|
||||
if (Is<CallStatement>()) {
|
||||
return "function call";
|
||||
}
|
||||
if (IsContinue()) {
|
||||
if (Is<ContinueStatement>()) {
|
||||
return "continue statement";
|
||||
}
|
||||
if (IsDiscard()) {
|
||||
if (Is<DiscardStatement>()) {
|
||||
return "discard statement";
|
||||
}
|
||||
if (IsElse()) {
|
||||
if (Is<ElseStatement>()) {
|
||||
return "else statement";
|
||||
}
|
||||
if (IsFallthrough()) {
|
||||
if (Is<FallthroughStatement>()) {
|
||||
return "fallthrough statement";
|
||||
}
|
||||
if (IsIf()) {
|
||||
if (Is<IfStatement>()) {
|
||||
return "if statement";
|
||||
}
|
||||
if (IsLoop()) {
|
||||
if (Is<LoopStatement>()) {
|
||||
return "loop statement";
|
||||
}
|
||||
if (IsReturn()) {
|
||||
if (Is<ReturnStatement>()) {
|
||||
return "return statement";
|
||||
}
|
||||
if (IsSwitch()) {
|
||||
if (Is<SwitchStatement>()) {
|
||||
return "switch statement";
|
||||
}
|
||||
if (IsVariableDecl()) {
|
||||
if (Is<VariableDeclStatement>()) {
|
||||
return "variable declaration";
|
||||
}
|
||||
return "statement";
|
||||
}
|
||||
|
||||
const AssignmentStatement* Statement::AsAssign() const {
|
||||
assert(IsAssign());
|
||||
return static_cast<const AssignmentStatement*>(this);
|
||||
}
|
||||
|
||||
const BlockStatement* Statement::AsBlock() const {
|
||||
assert(IsBlock());
|
||||
return static_cast<const BlockStatement*>(this);
|
||||
}
|
||||
|
||||
const BreakStatement* Statement::AsBreak() const {
|
||||
assert(IsBreak());
|
||||
return static_cast<const BreakStatement*>(this);
|
||||
}
|
||||
|
||||
const CallStatement* Statement::AsCall() const {
|
||||
assert(IsCall());
|
||||
return static_cast<const CallStatement*>(this);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
const DiscardStatement* Statement::AsDiscard() const {
|
||||
assert(IsDiscard());
|
||||
return static_cast<const DiscardStatement*>(this);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
AssignmentStatement* Statement::AsAssign() {
|
||||
assert(IsAssign());
|
||||
return static_cast<AssignmentStatement*>(this);
|
||||
}
|
||||
|
||||
BlockStatement* Statement::AsBlock() {
|
||||
assert(IsBlock());
|
||||
return static_cast<BlockStatement*>(this);
|
||||
}
|
||||
|
||||
BreakStatement* Statement::AsBreak() {
|
||||
assert(IsBreak());
|
||||
return static_cast<BreakStatement*>(this);
|
||||
}
|
||||
|
||||
CallStatement* Statement::AsCall() {
|
||||
assert(IsCall());
|
||||
return static_cast<CallStatement*>(this);
|
||||
}
|
||||
|
||||
CaseStatement* Statement::AsCase() {
|
||||
assert(IsCase());
|
||||
return static_cast<CaseStatement*>(this);
|
||||
}
|
||||
|
||||
ContinueStatement* Statement::AsContinue() {
|
||||
assert(IsContinue());
|
||||
return static_cast<ContinueStatement*>(this);
|
||||
}
|
||||
|
||||
DiscardStatement* Statement::AsDiscard() {
|
||||
assert(IsDiscard());
|
||||
return static_cast<DiscardStatement*>(this);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
VariableDeclStatement* Statement::AsVariableDecl() {
|
||||
assert(IsVariableDecl());
|
||||
return static_cast<VariableDeclStatement*>(this);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
@@ -23,116 +23,14 @@
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
class AssignmentStatement;
|
||||
class BlockStatement;
|
||||
class BreakStatement;
|
||||
class CallStatement;
|
||||
class CaseStatement;
|
||||
class ContinueStatement;
|
||||
class DiscardStatement;
|
||||
class ElseStatement;
|
||||
class FallthroughStatement;
|
||||
class IfStatement;
|
||||
class LoopStatement;
|
||||
class ReturnStatement;
|
||||
class SwitchStatement;
|
||||
class VariableDeclStatement;
|
||||
|
||||
/// Base statement class
|
||||
class Statement : public Castable<Statement, Node> {
|
||||
public:
|
||||
~Statement() override;
|
||||
|
||||
/// @returns true if this is an assign statement
|
||||
virtual bool IsAssign() const;
|
||||
/// @returns true if this is a block statement
|
||||
virtual bool IsBlock() const;
|
||||
/// @returns true if this is a break statement
|
||||
virtual bool IsBreak() const;
|
||||
/// @returns true if this is a call statement
|
||||
virtual bool IsCall() const;
|
||||
/// @returns true if this is a case statement
|
||||
virtual bool IsCase() const;
|
||||
/// @returns true if this is a continue statement
|
||||
virtual bool IsContinue() const;
|
||||
/// @returns true if this is a discard statement
|
||||
virtual bool IsDiscard() const;
|
||||
/// @returns true if this is an else statement
|
||||
virtual bool IsElse() const;
|
||||
/// @returns true if this is a fallthrough statement
|
||||
virtual bool IsFallthrough() const;
|
||||
/// @returns true if this is an if statement
|
||||
virtual bool IsIf() const;
|
||||
/// @returns true if this is a loop statement
|
||||
virtual bool IsLoop() const;
|
||||
/// @returns true if this is a return statement
|
||||
virtual bool IsReturn() const;
|
||||
/// @returns true if this is a switch statement
|
||||
virtual bool IsSwitch() const;
|
||||
/// @returns true if this is an variable statement
|
||||
virtual bool IsVariableDecl() const;
|
||||
|
||||
/// @returns the human readable name for the statement type.
|
||||
const char* Name() const;
|
||||
|
||||
/// @returns the statement as a const assign statement
|
||||
const AssignmentStatement* AsAssign() const;
|
||||
/// @returns the statement as a const block statement
|
||||
const BlockStatement* AsBlock() const;
|
||||
/// @returns the statement as a const break statement
|
||||
const BreakStatement* AsBreak() const;
|
||||
/// @returns the statement as a const call statement
|
||||
const CallStatement* AsCall() const;
|
||||
/// @returns the statement as a const case statement
|
||||
const CaseStatement* AsCase() const;
|
||||
/// @returns the statement as a const continue statement
|
||||
const ContinueStatement* AsContinue() const;
|
||||
/// @returns the statement as a const discard statement
|
||||
const DiscardStatement* AsDiscard() const;
|
||||
/// @returns the statement as a const else statement
|
||||
const ElseStatement* AsElse() const;
|
||||
/// @returns the statement as a const fallthrough statement
|
||||
const FallthroughStatement* AsFallthrough() const;
|
||||
/// @returns the statement as a const if statement
|
||||
const IfStatement* AsIf() const;
|
||||
/// @returns the statement as a const loop statement
|
||||
const LoopStatement* AsLoop() const;
|
||||
/// @returns the statement as a const return statement
|
||||
const ReturnStatement* AsReturn() const;
|
||||
/// @returns the statement as a const switch statement
|
||||
const SwitchStatement* AsSwitch() const;
|
||||
/// @returns the statement as a const variable statement
|
||||
const VariableDeclStatement* AsVariableDecl() const;
|
||||
|
||||
/// @returns the statement as an assign statement
|
||||
AssignmentStatement* AsAssign();
|
||||
/// @returns the statement as a block statement
|
||||
BlockStatement* AsBlock();
|
||||
/// @returns the statement as a break statement
|
||||
BreakStatement* AsBreak();
|
||||
/// @returns the statement as a call statement
|
||||
CallStatement* AsCall();
|
||||
/// @returns the statement as a case statement
|
||||
CaseStatement* AsCase();
|
||||
/// @returns the statement as a continue statement
|
||||
ContinueStatement* AsContinue();
|
||||
/// @returns the statement as a discard statement
|
||||
DiscardStatement* AsDiscard();
|
||||
/// @returns the statement as a else statement
|
||||
ElseStatement* AsElse();
|
||||
/// @returns the statement as a fallthrough statement
|
||||
FallthroughStatement* AsFallthrough();
|
||||
/// @returns the statement as a if statement
|
||||
IfStatement* AsIf();
|
||||
/// @returns the statement as a loop statement
|
||||
LoopStatement* AsLoop();
|
||||
/// @returns the statement as a return statement
|
||||
ReturnStatement* AsReturn();
|
||||
/// @returns the statement as a switch statement
|
||||
SwitchStatement* AsSwitch();
|
||||
/// @returns the statement as an variable statement
|
||||
VariableDeclStatement* AsVariableDecl();
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
Statement();
|
||||
|
||||
@@ -29,10 +29,6 @@ SwitchStatement::SwitchStatement(const Source& source,
|
||||
CaseStatementList body)
|
||||
: Base(source), condition_(condition), body_(body) {}
|
||||
|
||||
bool SwitchStatement::IsSwitch() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
SwitchStatement::SwitchStatement(SwitchStatement&&) = default;
|
||||
|
||||
SwitchStatement::~SwitchStatement() = default;
|
||||
|
||||
@@ -60,9 +60,6 @@ class SwitchStatement : public Castable<SwitchStatement, Statement> {
|
||||
/// @returns the Switch body
|
||||
const CaseStatementList& body() const { return body_; }
|
||||
|
||||
/// @returns true if this is a switch statement
|
||||
bool IsSwitch() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ TEST_F(SwitchStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(SwitchStatementTest, IsSwitch) {
|
||||
SwitchStatement stmt;
|
||||
EXPECT_TRUE(stmt.IsSwitch());
|
||||
EXPECT_TRUE(stmt.Is<SwitchStatement>());
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, IsValid) {
|
||||
|
||||
@@ -30,10 +30,6 @@ VariableDeclStatement::VariableDeclStatement(VariableDeclStatement&&) = default;
|
||||
|
||||
VariableDeclStatement::~VariableDeclStatement() = default;
|
||||
|
||||
bool VariableDeclStatement::IsVariableDecl() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VariableDeclStatement::IsValid() const {
|
||||
return variable_ != nullptr && variable_->IsValid();
|
||||
}
|
||||
|
||||
@@ -48,9 +48,6 @@ class VariableDeclStatement
|
||||
/// @returns the variable
|
||||
Variable* variable() const { return variable_; }
|
||||
|
||||
/// @returns true if this is an variable statement
|
||||
bool IsVariableDecl() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ TEST_F(VariableDeclStatementTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(VariableDeclStatementTest, IsVariableDecl) {
|
||||
VariableDeclStatement s;
|
||||
EXPECT_TRUE(s.IsVariableDecl());
|
||||
EXPECT_TRUE(s.Is<VariableDeclStatement>());
|
||||
}
|
||||
|
||||
TEST_F(VariableDeclStatementTest, IsValid) {
|
||||
|
||||
Reference in New Issue
Block a user