mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 12:16:10 +00:00
tint/reader/wgsl: Improve errors when parsing address spaces
If the address space doesn't parse, then generate an error message that includes the list of possible values, and a suggestion if there was a close match. Change-Id: Id55bedfdabd693b211ce69b6dcd01b28b61f3a12 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105326 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
bea1c5cb9a
commit
c1af0f5005
@ -1383,18 +1383,7 @@ Expect<const ast::Type*> ParserImpl::expect_type_specifier_matrix(const Source&
|
|||||||
//
|
//
|
||||||
// Note, we also parse `push_constant` from the experimental extension
|
// Note, we also parse `push_constant` from the experimental extension
|
||||||
Expect<ast::AddressSpace> ParserImpl::expect_address_space(std::string_view use) {
|
Expect<ast::AddressSpace> ParserImpl::expect_address_space(std::string_view use) {
|
||||||
auto& t = peek();
|
return expect_enum("address space", ast::ParseAddressSpace, ast::kAddressSpaceStrings, use);
|
||||||
auto ident = expect_ident("address space");
|
|
||||||
if (ident.errored) {
|
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto address_space = ast::ParseAddressSpace(ident.value);
|
|
||||||
if (address_space == ast::AddressSpace::kInvalid) {
|
|
||||||
return add_error(t.source(), "invalid address space", use);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {address_space, t.source()};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct_decl
|
// struct_decl
|
||||||
|
@ -54,7 +54,8 @@ TEST_F(ParserImplTest, AddressSpace_NoMatch) {
|
|||||||
auto sc = p->expect_address_space("test");
|
auto sc = p->expect_address_space("test");
|
||||||
EXPECT_EQ(sc.errored, true);
|
EXPECT_EQ(sc.errored, true);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(p->error(), "1:1: invalid address space for test");
|
EXPECT_EQ(p->error(), R"(1:1: expected address space for test
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -1112,7 +1112,8 @@ var i : ptr<private u32>;
|
|||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingAddressSpace) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingAddressSpace) {
|
||||||
EXPECT("var i : ptr<meow, u32>;",
|
EXPECT("var i : ptr<meow, u32>;",
|
||||||
R"(test.wgsl:1:13 error: invalid address space for ptr declaration
|
R"(test.wgsl:1:13 error: expected address space for ptr declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup'
|
||||||
var i : ptr<meow, u32>;
|
var i : ptr<meow, u32>;
|
||||||
^^^^
|
^^^^
|
||||||
)");
|
)");
|
||||||
@ -1144,7 +1145,8 @@ var i : atomic<u32 x;
|
|||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarStorageDeclInvalidClass) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarStorageDeclInvalidClass) {
|
||||||
EXPECT("var<fish> i : i32",
|
EXPECT("var<fish> i : i32",
|
||||||
R"(test.wgsl:1:5 error: invalid address space for variable declaration
|
R"(test.wgsl:1:5 error: expected address space for variable declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup'
|
||||||
var<fish> i : i32
|
var<fish> i : i32
|
||||||
^^^^
|
^^^^
|
||||||
)");
|
)");
|
||||||
|
@ -165,7 +165,8 @@ TEST_F(ParserImplTest, GlobalVariableDecl_InvalidVariableDecl) {
|
|||||||
EXPECT_TRUE(e.errored);
|
EXPECT_TRUE(e.errored);
|
||||||
EXPECT_FALSE(e.matched);
|
EXPECT_FALSE(e.matched);
|
||||||
EXPECT_EQ(e.value, nullptr);
|
EXPECT_EQ(e.value, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:5: invalid address space for variable declaration");
|
EXPECT_EQ(p->error(), R"(1:5: expected address space for variable declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -272,7 +272,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingAddressSpace) {
|
|||||||
EXPECT_FALSE(t.matched);
|
EXPECT_FALSE(t.matched);
|
||||||
ASSERT_EQ(t.value, nullptr);
|
ASSERT_EQ(t.value, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: expected identifier for address space");
|
ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingType) {
|
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingType) {
|
||||||
@ -302,7 +303,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingParams) {
|
|||||||
EXPECT_FALSE(t.matched);
|
EXPECT_FALSE(t.matched);
|
||||||
ASSERT_EQ(t.value, nullptr);
|
ASSERT_EQ(t.value, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: expected identifier for address space");
|
ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDecl_Ptr_BadAddressSpace) {
|
TEST_F(ParserImplTest, TypeDecl_Ptr_BadAddressSpace) {
|
||||||
@ -312,7 +314,9 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_BadAddressSpace) {
|
|||||||
EXPECT_FALSE(t.matched);
|
EXPECT_FALSE(t.matched);
|
||||||
ASSERT_EQ(t.value, nullptr);
|
ASSERT_EQ(t.value, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: invalid address space for ptr declaration");
|
ASSERT_EQ(p->error(),
|
||||||
|
R"(1:5: expected address space for ptr declaration. Did you mean 'uniform'?
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDecl_Ptr_BadAccess) {
|
TEST_F(ParserImplTest, TypeDecl_Ptr_BadAccess) {
|
||||||
|
@ -263,7 +263,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_MissingAddressSpace) {
|
|||||||
EXPECT_FALSE(t.matched);
|
EXPECT_FALSE(t.matched);
|
||||||
ASSERT_EQ(t.value, nullptr);
|
ASSERT_EQ(t.value, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: expected identifier for address space");
|
ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_MissingType) {
|
TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_MissingType) {
|
||||||
@ -293,7 +294,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_MissingParams) {
|
|||||||
EXPECT_FALSE(t.matched);
|
EXPECT_FALSE(t.matched);
|
||||||
ASSERT_EQ(t.value, nullptr);
|
ASSERT_EQ(t.value, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: expected identifier for address space");
|
ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAddressSpace) {
|
TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAddressSpace) {
|
||||||
@ -303,7 +305,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAddressSpace) {
|
|||||||
EXPECT_FALSE(t.matched);
|
EXPECT_FALSE(t.matched);
|
||||||
ASSERT_EQ(t.value, nullptr);
|
ASSERT_EQ(t.value, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: invalid address space for ptr declaration");
|
ASSERT_EQ(p->error(),
|
||||||
|
R"(1:5: expected address space for ptr declaration. Did you mean 'uniform'?
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAccess) {
|
TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAccess) {
|
||||||
|
@ -105,7 +105,9 @@ TEST_F(ParserImplTest, VariableDecl_InvalidAddressSpace) {
|
|||||||
EXPECT_FALSE(v.matched);
|
EXPECT_FALSE(v.matched);
|
||||||
EXPECT_TRUE(v.errored);
|
EXPECT_TRUE(v.errored);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(p->error(), "1:5: invalid address space for variable declaration");
|
EXPECT_EQ(p->error(),
|
||||||
|
R"(1:5: expected address space for variable declaration. Did you mean 'uniform'?
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -63,7 +63,8 @@ TEST_F(ParserImplTest, VariableQualifier_NoMatch) {
|
|||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_TRUE(sc.errored);
|
EXPECT_TRUE(sc.errored);
|
||||||
EXPECT_FALSE(sc.matched);
|
EXPECT_FALSE(sc.matched);
|
||||||
EXPECT_EQ(p->error(), "1:2: invalid address space for variable declaration");
|
EXPECT_EQ(p->error(), R"(1:2: expected address space for variable declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableQualifier_Empty) {
|
TEST_F(ParserImplTest, VariableQualifier_Empty) {
|
||||||
@ -72,7 +73,8 @@ TEST_F(ParserImplTest, VariableQualifier_Empty) {
|
|||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_TRUE(sc.errored);
|
EXPECT_TRUE(sc.errored);
|
||||||
EXPECT_FALSE(sc.matched);
|
EXPECT_FALSE(sc.matched);
|
||||||
EXPECT_EQ(p->error(), "1:2: expected identifier for address space");
|
EXPECT_EQ(p->error(), R"(1:2: expected address space for variable declaration
|
||||||
|
Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, VariableQualifier_MissingLessThan) {
|
TEST_F(ParserImplTest, VariableQualifier_MissingLessThan) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user