tint: Allow IdentifierExpressions to be templated

Required for nested template arguments, like `array<vec2<i32>, 2>`

Bug: tint:1810
Change-Id: Ibf24ec8918ef7698232cb2ea0cb786144d6f0604
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119123
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2023-02-08 23:29:28 +00:00 committed by Dawn LUCI CQ
parent 2d41a015d7
commit 057a733758
3 changed files with 11 additions and 16 deletions

View File

@ -27,10 +27,6 @@ IdentifierExpression::IdentifierExpression(ProgramID pid,
: Base(pid, nid, src), identifier(ident) {
TINT_ASSERT(AST, identifier != nullptr);
TINT_ASSERT_PROGRAM_IDS_EQUAL(AST, identifier, program_id);
// It is currently invalid for a templated identifier expression to be used as an identifier
// expression, as this should parse as a ast::TypeName.
TINT_ASSERT(AST, !ident->Is<TemplatedIdentifier>());
}
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;

View File

@ -18,6 +18,8 @@
namespace tint::ast {
namespace {
using namespace tint::number_suffixes; // NOLINT
using IdentifierExpressionTest = TestHelper;
TEST_F(IdentifierExpressionTest, Creation) {
@ -25,6 +27,15 @@ TEST_F(IdentifierExpressionTest, Creation) {
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
}
TEST_F(IdentifierExpressionTest, CreationTemplated) {
auto* i = Expr(Ident("ident", true));
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
auto* tmpl_ident = i->identifier->As<ast::TemplatedIdentifier>();
ASSERT_NE(tmpl_ident, nullptr);
EXPECT_EQ(tmpl_ident->arguments.Length(), 1_u);
EXPECT_TRUE(tmpl_ident->arguments[0]->Is<ast::BoolLiteralExpression>());
}
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
auto* i = Expr(Source{{20, 2}}, "ident");
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
@ -57,14 +68,5 @@ TEST_F(IdentifierExpressionTest, Assert_DifferentProgramID_Symbol) {
"internal compiler error");
}
TEST_F(IdentifierExpressionTest, Assert_IdentifierNotTemplated) {
EXPECT_FATAL_FAILURE(
{
ProgramBuilder b;
b.create<IdentifierExpression>(b.Ident("ident", "a", "b", "c"));
},
"internal compiler error");
}
} // namespace
} // namespace tint::ast

View File

@ -1219,9 +1219,6 @@ class ProgramBuilder {
/// @return an ast::IdentifierExpression with the given identifier
template <typename IDENTIFIER, typename = traits::EnableIfIsType<IDENTIFIER, ast::Identifier>>
const ast::IdentifierExpression* Expr(const IDENTIFIER* ident) {
static_assert(!traits::IsType<IDENTIFIER, ast::TemplatedIdentifier>,
"it is currently invalid for a templated identifier expression to be used as "
"an identifier expression, as this should parse as an ast::TypeName");
return create<ast::IdentifierExpression>(ident);
}