Replace ConstructorExpression::(Is|As)* with Castable

Change-Id: I18e9768fef36b79cb0e65c6eb79fd147013c54f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34317
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent d6ae990811
commit 19fe07236e
15 changed files with 26 additions and 72 deletions

View File

@@ -35,6 +35,7 @@
#include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type/void_type.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/uint_literal.h"
#include "src/ast/variable.h"
#include "src/context.h"

View File

@@ -16,9 +16,6 @@
#include <assert.h>
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type_constructor_expression.h"
namespace tint {
namespace ast {
@@ -31,23 +28,5 @@ ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default;
ConstructorExpression::ConstructorExpression(const Source& source)
: Base(source) {}
bool ConstructorExpression::IsScalarConstructor() const {
return false;
}
bool ConstructorExpression::IsTypeConstructor() const {
return false;
}
ScalarConstructorExpression* ConstructorExpression::AsScalarConstructor() {
assert(IsScalarConstructor());
return static_cast<ScalarConstructorExpression*>(this);
}
TypeConstructorExpression* ConstructorExpression::AsTypeConstructor() {
assert(IsTypeConstructor());
return static_cast<TypeConstructorExpression*>(this);
}
} // namespace ast
} // namespace tint

View File

@@ -20,25 +20,12 @@
namespace tint {
namespace ast {
class ScalarConstructorExpression;
class TypeConstructorExpression;
/// Base class for constructor style expressions
class ConstructorExpression
: public Castable<ConstructorExpression, Expression> {
public:
~ConstructorExpression() override;
/// @returns true if this is a scalar constructor
virtual bool IsScalarConstructor() const;
/// @returns true if this is a type constructor
virtual bool IsTypeConstructor() const;
/// @returns this as a scalar constructor expression
ScalarConstructorExpression* AsScalarConstructor();
/// @returns this as a type constructor expression
TypeConstructorExpression* AsTypeConstructor();
protected:
/// Constructor
ConstructorExpression();

View File

@@ -31,10 +31,6 @@ ScalarConstructorExpression::ScalarConstructorExpression(
ScalarConstructorExpression::~ScalarConstructorExpression() = default;
bool ScalarConstructorExpression::IsScalarConstructor() const {
return true;
}
bool ScalarConstructorExpression::IsValid() const {
return literal_ != nullptr;
}

View File

@@ -41,9 +41,6 @@ class ScalarConstructorExpression
ScalarConstructorExpression(ScalarConstructorExpression&&);
~ScalarConstructorExpression() override;
/// @returns true if this is a scalar constructor
bool IsScalarConstructor() const override;
/// Set the literal value
/// @param literal the literal
void set_literal(Literal* literal) { literal_ = literal; }

View File

@@ -33,10 +33,6 @@ TypeConstructorExpression::TypeConstructorExpression(
TypeConstructorExpression::~TypeConstructorExpression() = default;
bool TypeConstructorExpression::IsTypeConstructor() const {
return true;
}
bool TypeConstructorExpression::IsValid() const {
if (values_.empty()) {
return true;

View File

@@ -44,9 +44,6 @@ class TypeConstructorExpression
TypeConstructorExpression(TypeConstructorExpression&&);
~TypeConstructorExpression() override;
/// @returns true if this is a type constructor
bool IsTypeConstructor() const override;
/// Set the type
/// @param type the type
void set_type(type::Type* type) { type_ = type; }

View File

@@ -53,7 +53,7 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
TypeConstructorExpression t;
EXPECT_TRUE(t.IsTypeConstructor());
EXPECT_TRUE(t.Is<ast::TypeConstructorExpression>());
}
TEST_F(TypeConstructorExpressionTest, IsValid) {