reader/wgsl: Add support for [[override]]

The Resolver, Inspector, and backends already handle this form of the
attribute correctly, so this is straightforward.

Fixed: tint:755
Change-Id: I8c394f1e58d64827d8a53b81402e30a472ca5441
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50844
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price 2021-05-14 11:48:03 +00:00 committed by Commit Bot service account
parent 222fae1c8c
commit df8b2783a4
2 changed files with 49 additions and 9 deletions

View File

@ -3101,13 +3101,20 @@ Maybe<ast::Decoration*> ParserImpl::decoration() {
if (s == kOverrideDecoration) { if (s == kOverrideDecoration) {
const char* use = "override decoration"; const char* use = "override decoration";
return expect_paren_block(use, [&]() -> Result {
auto val = expect_positive_sint(use);
if (val.errored)
return Failure::kErrored;
return create<ast::OverrideDecoration>(t.source(), val.value); if (peek().IsParenLeft()) {
}); // [[override(x)]]
return expect_paren_block(use, [&]() -> Result {
auto val = expect_positive_sint(use);
if (val.errored)
return Failure::kErrored;
return create<ast::OverrideDecoration>(t.source(), val.value);
});
} else {
// [[override]]
return create<ast::OverrideDecoration>(t.source());
}
} }
return Failure::kNoMatch; return Failure::kNoMatch;

View File

@ -112,9 +112,42 @@ TEST_F(ParserImplTest, GlobalConstantDec_Override_WithId) {
ASSERT_NE(e->constructor(), nullptr); ASSERT_NE(e->constructor(), nullptr);
EXPECT_TRUE(e->constructor()->Is<ast::ConstructorExpression>()); EXPECT_TRUE(e->constructor()->Is<ast::ConstructorExpression>());
EXPECT_TRUE( auto* override_deco =
ast::HasDecoration<ast::OverrideDecoration>(e.value->decorations())); ast::GetDecoration<ast::OverrideDecoration>(e.value->decorations());
EXPECT_EQ(e.value->constant_id(), 7u); ASSERT_NE(override_deco, nullptr);
EXPECT_TRUE(override_deco->HasValue());
EXPECT_EQ(override_deco->value(), 7u);
}
TEST_F(ParserImplTest, GlobalConstantDec_Override_WithoutId) {
auto p = parser("[[override]] let a : f32 = 1.");
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
EXPECT_TRUE(decos.matched);
auto e = p->global_constant_decl(decos.value);
EXPECT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr);
EXPECT_TRUE(e->is_const());
EXPECT_EQ(e->symbol(), p->builder().Symbols().Get("a"));
ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->Is<ast::F32>());
EXPECT_EQ(e->source().range.begin.line, 1u);
EXPECT_EQ(e->source().range.begin.column, 18u);
EXPECT_EQ(e->source().range.end.line, 1u);
EXPECT_EQ(e->source().range.end.column, 19u);
ASSERT_NE(e->constructor(), nullptr);
EXPECT_TRUE(e->constructor()->Is<ast::ConstructorExpression>());
auto* override_deco =
ast::GetDecoration<ast::OverrideDecoration>(e.value->decorations());
ASSERT_NE(override_deco, nullptr);
EXPECT_FALSE(override_deco->HasValue());
} }
TEST_F(ParserImplTest, GlobalConstantDec_Override_MissingId) { TEST_F(ParserImplTest, GlobalConstantDec_Override_MissingId) {