ast: Migrate all nodes over to typ::*
(except for ast::Module)
CloneContext::Clone(typ::Type) now only clones the sem::Type. Attempting
to clone both the AST and SEM type will cause the cloned AST to be
disjoint. Another change will switch this over to cloning the AST.
Bug: tint:724
Change-Id: I2baf5491365d7dc25e6b25d02bfbb46bf90fd0d9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49341
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc
index 5a11e5c..b2baa53 100644
--- a/src/ast/bitcast_expression.cc
+++ b/src/ast/bitcast_expression.cc
@@ -23,10 +23,10 @@
BitcastExpression::BitcastExpression(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
Expression* expr)
: Base(program_id, source), type_(type), expr_(expr) {
- TINT_ASSERT(type_);
+ TINT_ASSERT(type_.sem);
TINT_ASSERT(expr_);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(expr, program_id);
}
@@ -37,7 +37,7 @@
BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
- auto* ty = ctx->Clone(type());
+ auto ty = ctx->Clone(type());
auto* e = ctx->Clone(expr_);
return ctx->dst->create<BitcastExpression>(src, ty, e);
}
diff --git a/src/ast/bitcast_expression.h b/src/ast/bitcast_expression.h
index 75a5a7a..5b8baca 100644
--- a/src/ast/bitcast_expression.h
+++ b/src/ast/bitcast_expression.h
@@ -30,14 +30,14 @@
/// @param expr the expr
BitcastExpression(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
Expression* expr);
/// Move constructor
BitcastExpression(BitcastExpression&&);
~BitcastExpression() override;
/// @returns the left side expression
- sem::Type* type() const { return const_cast<sem::Type*>(type_); }
+ typ::Type type() const { return type_; }
/// @returns the expression
Expression* expr() const { return expr_; }
@@ -58,7 +58,7 @@
private:
BitcastExpression(const BitcastExpression&) = delete;
- const sem::Type* const type_;
+ typ::Type const type_;
Expression* const expr_;
};
diff --git a/src/ast/bool_literal.cc b/src/ast/bool_literal.cc
index 097ea15..c4fd8c3 100644
--- a/src/ast/bool_literal.cc
+++ b/src/ast/bool_literal.cc
@@ -23,7 +23,7 @@
BoolLiteral::BoolLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
bool value)
: Base(program_id, source, type), value_(value) {}
@@ -40,7 +40,7 @@
BoolLiteral* BoolLiteral::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
- auto* ty = ctx->Clone(type());
+ auto ty = ctx->Clone(type());
return ctx->dst->create<BoolLiteral>(src, ty, value_);
}
diff --git a/src/ast/bool_literal.h b/src/ast/bool_literal.h
index 72c44fe..faa303c 100644
--- a/src/ast/bool_literal.h
+++ b/src/ast/bool_literal.h
@@ -32,7 +32,7 @@
/// @param value the bool literals value
BoolLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
bool value);
~BoolLiteral() override;
diff --git a/src/ast/bool_literal_test.cc b/src/ast/bool_literal_test.cc
index f7a8005..a5a0535 100644
--- a/src/ast/bool_literal_test.cc
+++ b/src/ast/bool_literal_test.cc
@@ -21,24 +21,21 @@
using BoolLiteralTest = TestHelper;
TEST_F(BoolLiteralTest, True) {
- sem::Bool bool_type;
- auto* b = create<BoolLiteral>(&bool_type, true);
+ auto* b = create<BoolLiteral>(ty.bool_(), true);
ASSERT_TRUE(b->Is<BoolLiteral>());
ASSERT_TRUE(b->IsTrue());
ASSERT_FALSE(b->IsFalse());
}
TEST_F(BoolLiteralTest, False) {
- sem::Bool bool_type;
- auto* b = create<BoolLiteral>(&bool_type, false);
+ auto* b = create<BoolLiteral>(ty.bool_(), false);
ASSERT_TRUE(b->Is<BoolLiteral>());
ASSERT_FALSE(b->IsTrue());
ASSERT_TRUE(b->IsFalse());
}
TEST_F(BoolLiteralTest, Is) {
- sem::Bool bool_type;
- ast::Literal* l = create<BoolLiteral>(&bool_type, false);
+ ast::Literal* l = create<BoolLiteral>(ty.bool_(), false);
EXPECT_TRUE(l->Is<BoolLiteral>());
EXPECT_FALSE(l->Is<SintLiteral>());
EXPECT_FALSE(l->Is<FloatLiteral>());
@@ -47,9 +44,8 @@
}
TEST_F(BoolLiteralTest, ToStr) {
- sem::Bool bool_type;
- auto* t = create<BoolLiteral>(&bool_type, true);
- auto* f = create<BoolLiteral>(&bool_type, false);
+ auto* t = create<BoolLiteral>(ty.bool_(), true);
+ auto* f = create<BoolLiteral>(ty.bool_(), false);
EXPECT_EQ(str(t), "true");
EXPECT_EQ(str(f), "false");
diff --git a/src/ast/float_literal.cc b/src/ast/float_literal.cc
index 9089289..cba68c6 100644
--- a/src/ast/float_literal.cc
+++ b/src/ast/float_literal.cc
@@ -25,7 +25,7 @@
FloatLiteral::FloatLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
float value)
: Base(program_id, source, type), value_(value) {}
@@ -46,7 +46,7 @@
FloatLiteral* FloatLiteral::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
- auto* ty = ctx->Clone(type());
+ auto ty = ctx->Clone(type());
return ctx->dst->create<FloatLiteral>(src, ty, value_);
}
diff --git a/src/ast/float_literal.h b/src/ast/float_literal.h
index 05ddbfc..ea3cee4 100644
--- a/src/ast/float_literal.h
+++ b/src/ast/float_literal.h
@@ -32,7 +32,7 @@
/// @param value the float literals value
FloatLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
float value);
~FloatLiteral() override;
diff --git a/src/ast/int_literal.cc b/src/ast/int_literal.cc
index c35b923..7177787 100644
--- a/src/ast/int_literal.cc
+++ b/src/ast/int_literal.cc
@@ -21,7 +21,7 @@
IntLiteral::IntLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
uint32_t value)
: Base(program_id, source, type), value_(value) {}
diff --git a/src/ast/int_literal.h b/src/ast/int_literal.h
index 3a23a7c..eed01c7 100644
--- a/src/ast/int_literal.h
+++ b/src/ast/int_literal.h
@@ -36,7 +36,7 @@
/// @param value value of the literal
IntLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
uint32_t value);
private:
diff --git a/src/ast/literal.cc b/src/ast/literal.cc
index dd632bd..db71189 100644
--- a/src/ast/literal.cc
+++ b/src/ast/literal.cc
@@ -19,9 +19,7 @@
namespace tint {
namespace ast {
-Literal::Literal(ProgramID program_id,
- const Source& source,
- const sem::Type* type)
+Literal::Literal(ProgramID program_id, const Source& source, typ::Type type)
: Base(program_id, source), type_(type) {}
Literal::~Literal() = default;
diff --git a/src/ast/literal.h b/src/ast/literal.h
index 1351f00..abe5e12 100644
--- a/src/ast/literal.h
+++ b/src/ast/literal.h
@@ -28,7 +28,7 @@
~Literal() override;
/// @returns the type of the literal
- sem::Type* type() const { return const_cast<sem::Type*>(type_); }
+ typ::Type type() const { return type_; }
/// Writes a representation of the node to the output stream
/// @param sem the semantic info for the program
@@ -50,12 +50,10 @@
/// @param program_id the identifier of the program that owns this node
/// @param source the input source
/// @param type the type of the literal
- explicit Literal(ProgramID program_id,
- const Source& source,
- const sem::Type* type);
+ explicit Literal(ProgramID program_id, const Source& source, typ::Type type);
private:
- const sem::Type* const type_;
+ typ::Type const type_;
};
} // namespace ast
diff --git a/src/ast/sint_literal.cc b/src/ast/sint_literal.cc
index c3e0a16..804caa1 100644
--- a/src/ast/sint_literal.cc
+++ b/src/ast/sint_literal.cc
@@ -23,7 +23,7 @@
SintLiteral::SintLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
int32_t value)
: Base(program_id, source, type, static_cast<uint32_t>(value)) {}
@@ -40,7 +40,7 @@
SintLiteral* SintLiteral::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
- auto* ty = ctx->Clone(type());
+ auto ty = ctx->Clone(type());
return ctx->dst->create<SintLiteral>(src, ty, value());
}
diff --git a/src/ast/sint_literal.h b/src/ast/sint_literal.h
index 874ceb5..a20410e 100644
--- a/src/ast/sint_literal.h
+++ b/src/ast/sint_literal.h
@@ -32,7 +32,7 @@
/// @param value the signed int literals value
SintLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
int32_t value);
~SintLiteral() override;
diff --git a/src/ast/sint_literal_test.cc b/src/ast/sint_literal_test.cc
index da4121b..0d6815a 100644
--- a/src/ast/sint_literal_test.cc
+++ b/src/ast/sint_literal_test.cc
@@ -45,8 +45,7 @@
}
TEST_F(SintLiteralTest, Name_U32) {
- sem::U32 u32;
- auto* i = create<SintLiteral>(&u32, 2);
+ auto* i = create<SintLiteral>(ty.u32(), 2);
EXPECT_EQ("__sint__u32_2", i->name());
}
diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc
index ecfa60c..01c0c73 100644
--- a/src/ast/type_constructor_expression.cc
+++ b/src/ast/type_constructor_expression.cc
@@ -23,10 +23,10 @@
TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
ExpressionList values)
: Base(program_id, source), type_(type), values_(std::move(values)) {
- TINT_ASSERT(type_);
+ TINT_ASSERT(type_.sem);
for (auto* val : values_) {
TINT_ASSERT(val);
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(val, program_id);
@@ -42,7 +42,7 @@
CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
- auto* ty = ctx->Clone(type());
+ auto ty = ctx->Clone(type());
auto vals = ctx->Clone(values());
return ctx->dst->create<TypeConstructorExpression>(src, ty, vals);
}
diff --git a/src/ast/type_constructor_expression.h b/src/ast/type_constructor_expression.h
index 5b63f43..6b89a6b 100644
--- a/src/ast/type_constructor_expression.h
+++ b/src/ast/type_constructor_expression.h
@@ -33,14 +33,14 @@
/// @param values the constructor values
TypeConstructorExpression(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
ExpressionList values);
/// Move constructor
TypeConstructorExpression(TypeConstructorExpression&&);
~TypeConstructorExpression() override;
/// @returns the type
- sem::Type* type() const { return const_cast<sem::Type*>(type_); }
+ typ::Type type() const { return type_; }
/// @returns the values
const ExpressionList& values() const { return values_; }
@@ -62,7 +62,7 @@
private:
TypeConstructorExpression(const TypeConstructorExpression&) = delete;
- const sem::Type* const type_;
+ typ::Type const type_;
ExpressionList const values_;
};
diff --git a/src/ast/type_constructor_expression_test.cc b/src/ast/type_constructor_expression_test.cc
index e9e8ace..73c61ea 100644
--- a/src/ast/type_constructor_expression_test.cc
+++ b/src/ast/type_constructor_expression_test.cc
@@ -81,13 +81,12 @@
}
TEST_F(TypeConstructorExpressionTest, ToStr) {
- sem::Vector vec(ty.f32(), 3);
ExpressionList expr;
expr.push_back(Expr("expr_1"));
expr.push_back(Expr("expr_2"));
expr.push_back(Expr("expr_3"));
- auto* t = create<TypeConstructorExpression>(&vec, expr);
+ auto* t = create<TypeConstructorExpression>(ty.vec3<f32>(), expr);
EXPECT_EQ(str(t), R"(TypeConstructor[not set]{
__vec_3__f32
Identifier[not set]{expr_1}
diff --git a/src/ast/uint_literal.cc b/src/ast/uint_literal.cc
index 4280855..6b6b2cd 100644
--- a/src/ast/uint_literal.cc
+++ b/src/ast/uint_literal.cc
@@ -23,7 +23,7 @@
UintLiteral::UintLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
uint32_t value)
: Base(program_id, source, type, value) {}
@@ -40,7 +40,7 @@
UintLiteral* UintLiteral::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source());
- auto* ty = ctx->Clone(type());
+ auto ty = ctx->Clone(type());
return ctx->dst->create<UintLiteral>(src, ty, value());
}
diff --git a/src/ast/uint_literal.h b/src/ast/uint_literal.h
index 6015415..9b58eb3 100644
--- a/src/ast/uint_literal.h
+++ b/src/ast/uint_literal.h
@@ -32,7 +32,7 @@
/// @param value the uint literals value
UintLiteral(ProgramID program_id,
const Source& source,
- const sem::Type* type,
+ typ::Type type,
uint32_t value);
~UintLiteral() override;
diff --git a/src/clone_context.h b/src/clone_context.h
index 080c27b..ad02692 100644
--- a/src/clone_context.h
+++ b/src/clone_context.h
@@ -185,8 +185,7 @@
/// @return the cloned type pair
template <typename AST, typename SEM>
typ::TypePair<AST, SEM> Clone(const typ::TypePair<AST, SEM>& tp) {
- return {Clone(const_cast<ast::Type*>(tp.ast)),
- Clone(const_cast<sem::Type*>(tp.sem))};
+ return Clone(const_cast<sem::Type*>(tp.sem));
}
/// Clones the Source `s` into #dst
diff --git a/src/reader/spirv/namer_test.cc b/src/reader/spirv/namer_test.cc
index 79f271b..2ef9943 100644
--- a/src/reader/spirv/namer_test.cc
+++ b/src/reader/spirv/namer_test.cc
@@ -160,19 +160,19 @@
// Fails on second attempt.
EXPECT_FALSE(namer.RegisterWithoutId(n));
EXPECT_FALSE(success_);
- EXPECT_EQ(error(),"internal error: name already registered: abbey");
+ EXPECT_EQ(error(), "internal error: name already registered: abbey");
}
TEST_F(SpvNamerTest, RegisterWithoutId_ConflictsWithIdRegisteredName) {
Namer namer(fail_stream_);
const std::string n("abbey");
- EXPECT_TRUE(namer.Register(1,n));
+ EXPECT_TRUE(namer.Register(1, n));
EXPECT_TRUE(namer.IsRegistered(n));
// Fails on attempt to register without ID.
EXPECT_FALSE(namer.RegisterWithoutId(n));
EXPECT_FALSE(success_);
- EXPECT_EQ(error(),"internal error: name already registered: abbey");
+ EXPECT_EQ(error(), "internal error: name already registered: abbey");
}
TEST_F(SpvNamerTest, Register_Once) {
diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc
index 8d7ebb1..b97f189 100644
--- a/src/reader/wgsl/parser_impl_type_decl_test.cc
+++ b/src/reader/wgsl/parser_impl_type_decl_test.cc
@@ -151,11 +151,9 @@
INSTANTIATE_TEST_SUITE_P(
ParserImplTest,
VecTest,
- testing::Values(VecData{"vec2<f32>", 2, Source::Range{{1u, 1u}, {1u, 10u}}},
- VecData{"vec3<f32>", 3, Source::Range{{1u, 1u}, {1u, 10u}}},
- VecData{"vec4<f32>", 4, Source::Range{{1u, 1u}, {1u, 10u}}}
-
- ));
+ testing::Values(VecData{"vec2<f32>", 2, {{1u, 1u}, {1u, 10u}}},
+ VecData{"vec3<f32>", 3, {{1u, 1u}, {1u, 10u}}},
+ VecData{"vec4<f32>", 4, {{1u, 1u}, {1u, 10u}}}));
class VecMissingGreaterThanTest : public ParserImplTestWithParam<VecData> {};
@@ -657,16 +655,15 @@
INSTANTIATE_TEST_SUITE_P(
ParserImplTest,
MatrixTest,
- testing::Values(
- MatrixData{"mat2x2<f32>", 2, 2, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat2x3<f32>", 2, 3, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat2x4<f32>", 2, 4, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat3x2<f32>", 3, 2, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat3x3<f32>", 3, 3, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat3x4<f32>", 3, 4, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat4x2<f32>", 4, 2, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat4x3<f32>", 4, 3, Source::Range{{1u, 1u}, {1u, 12u}}},
- MatrixData{"mat4x4<f32>", 4, 4, Source::Range{{1u, 1u}, {1u, 12u}}}));
+ testing::Values(MatrixData{"mat2x2<f32>", 2, 2, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat2x3<f32>", 2, 3, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat2x4<f32>", 2, 4, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat3x2<f32>", 3, 2, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat3x3<f32>", 3, 3, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat3x4<f32>", 3, 4, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat4x2<f32>", 4, 2, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat4x3<f32>", 4, 3, {{1u, 1u}, {1u, 12u}}},
+ MatrixData{"mat4x4<f32>", 4, 4, {{1u, 1u}, {1u, 12u}}}));
class MatrixMissingGreaterThanTest
: public ParserImplTestWithParam<MatrixData> {};
diff --git a/src/typepair.h b/src/typepair.h
index 7e53800..c3fa0f5 100644
--- a/src/typepair.h
+++ b/src/typepair.h
@@ -101,7 +101,6 @@
sem(static_cast<const SEM*>(other.sem)) {}
/// Constructor
/// @param a the ast::Type pointer
- template <typename U>
TypePair(const AST* a) : ast(a) {} // NOLINT: explicit
/// Constructor
/// @param s the sem::Type pointer
@@ -110,6 +109,8 @@
/// @param a the ast::Type pointer
/// @param s the sem::Type pointer
TypePair(const AST* a, const SEM* s) : ast(a), sem(s) {}
+ /// Constructor
+ TypePair(std::nullptr_t) {} // NOLINT: explicit
/// @returns the ast::Type pointer
operator AST*() const { return const_cast<AST*>(ast); }