mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Replace Expression::(Is|As)* with Castable
Change-Id: I6ab98ed8b198f1b3b42ce1f09a6c4f992d65fe95 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34316 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -33,10 +33,6 @@ ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) =
|
||||
|
||||
ArrayAccessorExpression::~ArrayAccessorExpression() = default;
|
||||
|
||||
bool ArrayAccessorExpression::IsArrayAccessor() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArrayAccessorExpression::IsValid() const {
|
||||
if (array_ == nullptr || !array_->IsValid())
|
||||
return false;
|
||||
|
||||
@@ -57,9 +57,6 @@ class ArrayAccessorExpression
|
||||
/// @returns the index expression
|
||||
Expression* idx_expr() const { return idx_expr_; }
|
||||
|
||||
/// @returns true if this is an array accessor expression
|
||||
bool IsArrayAccessor() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
|
||||
|
||||
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
|
||||
ArrayAccessorExpression exp;
|
||||
EXPECT_TRUE(exp.IsArrayAccessor());
|
||||
EXPECT_TRUE(exp.Is<ast::ArrayAccessorExpression>());
|
||||
}
|
||||
|
||||
TEST_F(ArrayAccessorExpressionTest, IsValid) {
|
||||
|
||||
@@ -34,10 +34,6 @@ BinaryExpression::BinaryExpression(BinaryExpression&&) = default;
|
||||
|
||||
BinaryExpression::~BinaryExpression() = default;
|
||||
|
||||
bool BinaryExpression::IsBinary() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryExpression::IsValid() const {
|
||||
if (lhs_ == nullptr || !lhs_->IsValid()) {
|
||||
return false;
|
||||
|
||||
@@ -125,9 +125,6 @@ class BinaryExpression : public Castable<BinaryExpression, Expression> {
|
||||
/// @returns the right side expression
|
||||
Expression* rhs() const { return rhs_; }
|
||||
|
||||
/// @returns true if this is a op expression
|
||||
bool IsBinary() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(BinaryExpressionTest, IsBinaryal) {
|
||||
BinaryExpression r;
|
||||
EXPECT_TRUE(r.IsBinary());
|
||||
EXPECT_TRUE(r.Is<ast::BinaryExpression>());
|
||||
}
|
||||
|
||||
TEST_F(BinaryExpressionTest, IsValid) {
|
||||
|
||||
@@ -30,10 +30,6 @@ BitcastExpression::BitcastExpression(const Source& source,
|
||||
BitcastExpression::BitcastExpression(BitcastExpression&&) = default;
|
||||
BitcastExpression::~BitcastExpression() = default;
|
||||
|
||||
bool BitcastExpression::IsBitcast() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BitcastExpression::IsValid() const {
|
||||
if (expr_ == nullptr || !expr_->IsValid())
|
||||
return false;
|
||||
|
||||
@@ -55,9 +55,6 @@ class BitcastExpression : public Castable<BitcastExpression, Expression> {
|
||||
/// @returns the expression
|
||||
Expression* expr() const { return expr_; }
|
||||
|
||||
/// @returns true if this is a bitcast expression
|
||||
bool IsBitcast() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
|
||||
|
||||
TEST_F(BitcastExpressionTest, IsBitcast) {
|
||||
BitcastExpression exp;
|
||||
EXPECT_TRUE(exp.IsBitcast());
|
||||
EXPECT_TRUE(exp.Is<ast::BitcastExpression>());
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, IsValid) {
|
||||
|
||||
@@ -31,10 +31,6 @@ CallExpression::CallExpression(CallExpression&&) = default;
|
||||
|
||||
CallExpression::~CallExpression() = default;
|
||||
|
||||
bool CallExpression::IsCall() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CallExpression::IsValid() const {
|
||||
if (func_ == nullptr || !func_->IsValid())
|
||||
return false;
|
||||
|
||||
@@ -54,9 +54,6 @@ class CallExpression : public Castable<CallExpression, Expression> {
|
||||
/// @returns the parameters
|
||||
const ExpressionList& params() const { return params_; }
|
||||
|
||||
/// @returns true if this is a call expression
|
||||
bool IsCall() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
|
||||
TEST_F(CallExpressionTest, IsCall) {
|
||||
auto* func = create<IdentifierExpression>("func");
|
||||
CallExpression stmt(func, {});
|
||||
EXPECT_TRUE(stmt.IsCall());
|
||||
EXPECT_TRUE(stmt.Is<ast::CallExpression>());
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, IsValid) {
|
||||
|
||||
@@ -31,10 +31,6 @@ ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default;
|
||||
ConstructorExpression::ConstructorExpression(const Source& source)
|
||||
: Base(source) {}
|
||||
|
||||
bool ConstructorExpression::IsConstructor() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConstructorExpression::IsScalarConstructor() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,9 +29,6 @@ class ConstructorExpression
|
||||
public:
|
||||
~ConstructorExpression() override;
|
||||
|
||||
/// @returns true if this is an constructor expression
|
||||
bool IsConstructor() const override;
|
||||
|
||||
/// @returns true if this is a scalar constructor
|
||||
virtual bool IsScalarConstructor() const;
|
||||
/// @returns true if this is a type constructor
|
||||
|
||||
@@ -14,18 +14,6 @@
|
||||
|
||||
#include "src/ast/expression.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "src/ast/array_accessor_expression.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/bitcast_expression.h"
|
||||
#include "src/ast/call_expression.h"
|
||||
#include "src/ast/constructor_expression.h"
|
||||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/member_accessor_expression.h"
|
||||
#include "src/ast/type/alias_type.h"
|
||||
#include "src/ast/unary_op_expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
@@ -42,116 +30,5 @@ void Expression::set_result_type(type::Type* type) {
|
||||
result_type_ = type->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
bool Expression::IsArrayAccessor() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::IsBitcast() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::IsCall() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::IsIdentifier() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::IsConstructor() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::IsMemberAccessor() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::IsBinary() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Expression::IsUnaryOp() const {
|
||||
return false;
|
||||
}
|
||||
const ArrayAccessorExpression* Expression::AsArrayAccessor() const {
|
||||
assert(IsArrayAccessor());
|
||||
return static_cast<const ArrayAccessorExpression*>(this);
|
||||
}
|
||||
|
||||
const BitcastExpression* Expression::AsBitcast() const {
|
||||
assert(IsBitcast());
|
||||
return static_cast<const BitcastExpression*>(this);
|
||||
}
|
||||
|
||||
const BinaryExpression* Expression::AsBinary() const {
|
||||
assert(IsBinary());
|
||||
return static_cast<const BinaryExpression*>(this);
|
||||
}
|
||||
|
||||
const CallExpression* Expression::AsCall() const {
|
||||
assert(IsCall());
|
||||
return static_cast<const CallExpression*>(this);
|
||||
}
|
||||
|
||||
const ConstructorExpression* Expression::AsConstructor() const {
|
||||
assert(IsConstructor());
|
||||
return static_cast<const ConstructorExpression*>(this);
|
||||
}
|
||||
|
||||
const IdentifierExpression* Expression::AsIdentifier() const {
|
||||
assert(IsIdentifier());
|
||||
return static_cast<const IdentifierExpression*>(this);
|
||||
}
|
||||
|
||||
const MemberAccessorExpression* Expression::AsMemberAccessor() const {
|
||||
assert(IsMemberAccessor());
|
||||
return static_cast<const MemberAccessorExpression*>(this);
|
||||
}
|
||||
|
||||
const UnaryOpExpression* Expression::AsUnaryOp() const {
|
||||
assert(IsUnaryOp());
|
||||
return static_cast<const UnaryOpExpression*>(this);
|
||||
}
|
||||
|
||||
ArrayAccessorExpression* Expression::AsArrayAccessor() {
|
||||
assert(IsArrayAccessor());
|
||||
return static_cast<ArrayAccessorExpression*>(this);
|
||||
}
|
||||
|
||||
BitcastExpression* Expression::AsBitcast() {
|
||||
assert(IsBitcast());
|
||||
return static_cast<BitcastExpression*>(this);
|
||||
}
|
||||
|
||||
BinaryExpression* Expression::AsBinary() {
|
||||
assert(IsBinary());
|
||||
return static_cast<BinaryExpression*>(this);
|
||||
}
|
||||
|
||||
CallExpression* Expression::AsCall() {
|
||||
assert(IsCall());
|
||||
return static_cast<CallExpression*>(this);
|
||||
}
|
||||
|
||||
ConstructorExpression* Expression::AsConstructor() {
|
||||
assert(IsConstructor());
|
||||
return static_cast<ConstructorExpression*>(this);
|
||||
}
|
||||
|
||||
IdentifierExpression* Expression::AsIdentifier() {
|
||||
assert(IsIdentifier());
|
||||
return static_cast<IdentifierExpression*>(this);
|
||||
}
|
||||
|
||||
MemberAccessorExpression* Expression::AsMemberAccessor() {
|
||||
assert(IsMemberAccessor());
|
||||
return static_cast<MemberAccessorExpression*>(this);
|
||||
}
|
||||
|
||||
UnaryOpExpression* Expression::AsUnaryOp() {
|
||||
assert(IsUnaryOp());
|
||||
return static_cast<UnaryOpExpression*>(this);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
@@ -25,15 +25,6 @@
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
class ArrayAccessorExpression;
|
||||
class BinaryExpression;
|
||||
class BitcastExpression;
|
||||
class CallExpression;
|
||||
class IdentifierExpression;
|
||||
class ConstructorExpression;
|
||||
class MemberAccessorExpression;
|
||||
class UnaryOpExpression;
|
||||
|
||||
/// Base expression class
|
||||
class Expression : public Castable<Expression, Node> {
|
||||
public:
|
||||
@@ -51,57 +42,6 @@ class Expression : public Castable<Expression, Node> {
|
||||
return result_type_ ? result_type_->type_name() : "not set";
|
||||
}
|
||||
|
||||
/// @returns true if this is an array accessor expression
|
||||
virtual bool IsArrayAccessor() const;
|
||||
/// @returns true if this is a bitcast expression
|
||||
virtual bool IsBitcast() const;
|
||||
/// @returns true if this is a call expression
|
||||
virtual bool IsCall() const;
|
||||
/// @returns true if this is an identifier expression
|
||||
virtual bool IsIdentifier() const;
|
||||
/// @returns true if this is an constructor expression
|
||||
virtual bool IsConstructor() const;
|
||||
/// @returns true if this is a member accessor expression
|
||||
virtual bool IsMemberAccessor() const;
|
||||
/// @returns true if this is a binary expression
|
||||
virtual bool IsBinary() const;
|
||||
/// @returns true if this is a unary op expression
|
||||
virtual bool IsUnaryOp() const;
|
||||
|
||||
/// @returns the expression as an array accessor
|
||||
const ArrayAccessorExpression* AsArrayAccessor() const;
|
||||
/// @returns the expression as a bitcast
|
||||
const BitcastExpression* AsBitcast() const;
|
||||
/// @returns the expression as a call
|
||||
const CallExpression* AsCall() const;
|
||||
/// @returns the expression as an identifier
|
||||
const IdentifierExpression* AsIdentifier() const;
|
||||
/// @returns the expression as an constructor
|
||||
const ConstructorExpression* AsConstructor() const;
|
||||
/// @returns the expression as a member accessor
|
||||
const MemberAccessorExpression* AsMemberAccessor() const;
|
||||
/// @returns the expression as a binary expression
|
||||
const BinaryExpression* AsBinary() const;
|
||||
/// @returns the expression as a unary op expression
|
||||
const UnaryOpExpression* AsUnaryOp() const;
|
||||
|
||||
/// @returns the expression as an array accessor
|
||||
ArrayAccessorExpression* AsArrayAccessor();
|
||||
/// @returns the expression as a bitcast
|
||||
BitcastExpression* AsBitcast();
|
||||
/// @returns the expression as a call
|
||||
CallExpression* AsCall();
|
||||
/// @returns the expression as an identifier
|
||||
IdentifierExpression* AsIdentifier();
|
||||
/// @returns the expression as an constructor
|
||||
ConstructorExpression* AsConstructor();
|
||||
/// @returns the expression as a member accessor
|
||||
MemberAccessorExpression* AsMemberAccessor();
|
||||
/// @returns the expression as a binary expression
|
||||
BinaryExpression* AsBinary();
|
||||
/// @returns the expression as a unary op expression
|
||||
UnaryOpExpression* AsUnaryOp();
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
Expression();
|
||||
|
||||
@@ -28,10 +28,6 @@ IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
|
||||
|
||||
IdentifierExpression::~IdentifierExpression() = default;
|
||||
|
||||
bool IdentifierExpression::IsIdentifier() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IdentifierExpression::IsValid() const {
|
||||
return !name_.empty();
|
||||
}
|
||||
|
||||
@@ -61,9 +61,6 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
|
||||
/// @returns true if this identifier is for an intrinsic
|
||||
bool IsIntrinsic() const { return intrinsic_ != Intrinsic::kNone; }
|
||||
|
||||
/// @returns true if this is an identifier expression
|
||||
bool IsIdentifier() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(IdentifierExpressionTest, IsIdentifier) {
|
||||
IdentifierExpression i("ident");
|
||||
EXPECT_TRUE(i.IsIdentifier());
|
||||
EXPECT_TRUE(i.Is<ast::IdentifierExpression>());
|
||||
}
|
||||
|
||||
TEST_F(IdentifierExpressionTest, IsValid) {
|
||||
|
||||
@@ -33,10 +33,6 @@ MemberAccessorExpression::MemberAccessorExpression(MemberAccessorExpression&&) =
|
||||
|
||||
MemberAccessorExpression::~MemberAccessorExpression() = default;
|
||||
|
||||
bool MemberAccessorExpression::IsMemberAccessor() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MemberAccessorExpression::IsValid() const {
|
||||
if (struct_ == nullptr || !struct_->IsValid()) {
|
||||
return false;
|
||||
|
||||
@@ -59,9 +59,6 @@ class MemberAccessorExpression
|
||||
/// @returns the member expression
|
||||
IdentifierExpression* member() const { return member_; }
|
||||
|
||||
/// @returns true if this is a member accessor expression
|
||||
bool IsMemberAccessor() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
|
||||
MemberAccessorExpression stmt;
|
||||
EXPECT_TRUE(stmt.IsMemberAccessor());
|
||||
EXPECT_TRUE(stmt.Is<ast::MemberAccessorExpression>());
|
||||
}
|
||||
|
||||
TEST_F(MemberAccessorExpressionTest, IsValid) {
|
||||
|
||||
@@ -31,10 +31,6 @@ UnaryOpExpression::UnaryOpExpression(UnaryOpExpression&&) = default;
|
||||
|
||||
UnaryOpExpression::~UnaryOpExpression() = default;
|
||||
|
||||
bool UnaryOpExpression::IsUnaryOp() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnaryOpExpression::IsValid() const {
|
||||
return expr_ != nullptr && expr_->IsValid();
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ class UnaryOpExpression : public Castable<UnaryOpExpression, Expression> {
|
||||
/// @returns the expression
|
||||
Expression* expr() const { return expr_; }
|
||||
|
||||
/// @returns true if this is an as expression
|
||||
bool IsUnaryOp() const override;
|
||||
|
||||
/// @returns true if the node is valid
|
||||
bool IsValid() const override;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
|
||||
|
||||
TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
|
||||
UnaryOpExpression u;
|
||||
EXPECT_TRUE(u.IsUnaryOp());
|
||||
EXPECT_TRUE(u.Is<ast::UnaryOpExpression>());
|
||||
}
|
||||
|
||||
TEST_F(UnaryOpExpressionTest, IsValid) {
|
||||
|
||||
Reference in New Issue
Block a user