mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-21 22:13:45 +00:00
tint/reader/wgsl: Improve errors when parsing interpolation modes
If the interpolation mode 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: I4ee52389e94c834b9d5d9b8d1e76f453a1acd4d1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105328 Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
542d27d874
commit
c889500f6e
@ -1646,25 +1646,12 @@ Expect<ast::PipelineStage> ParserImpl::expect_pipeline_stage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// interpolation_sample_name
|
// interpolation_sample_name
|
||||||
// : 'center'
|
// : 'center'
|
||||||
// | 'centroid'
|
// | 'centroid'
|
||||||
// | 'sample'
|
// | 'sample'
|
||||||
Expect<ast::InterpolationSampling> ParserImpl::expect_interpolation_sample_name() {
|
Expect<ast::InterpolationSampling> ParserImpl::expect_interpolation_sample_name() {
|
||||||
auto ident = expect_ident("interpolation sample name");
|
return expect_enum("interpolation sampling", ast::ParseInterpolationSampling,
|
||||||
if (ident.errored) {
|
ast::kInterpolationSamplingStrings);
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ident.value == "center") {
|
|
||||||
return {ast::InterpolationSampling::kCenter, ident.source};
|
|
||||||
}
|
|
||||||
if (ident.value == "centroid") {
|
|
||||||
return {ast::InterpolationSampling::kCentroid, ident.source};
|
|
||||||
}
|
|
||||||
if (ident.value == "sample") {
|
|
||||||
return {ast::InterpolationSampling::kSample, ident.source};
|
|
||||||
}
|
|
||||||
return add_error(ident.source, "invalid interpolation sampling");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolation_type_name
|
// interpolation_type_name
|
||||||
@ -1672,22 +1659,8 @@ Expect<ast::InterpolationSampling> ParserImpl::expect_interpolation_sample_name(
|
|||||||
// | 'linear'
|
// | 'linear'
|
||||||
// | 'flat'
|
// | 'flat'
|
||||||
Expect<ast::InterpolationType> ParserImpl::expect_interpolation_type_name() {
|
Expect<ast::InterpolationType> ParserImpl::expect_interpolation_type_name() {
|
||||||
auto ident = expect_ident("interpolation type name");
|
return expect_enum("interpolation type", ast::ParseInterpolationType,
|
||||||
if (ident.errored) {
|
ast::kInterpolationTypeStrings);
|
||||||
return Failure::kErrored;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ident.value == "perspective") {
|
|
||||||
return {ast::InterpolationType::kPerspective, ident.source};
|
|
||||||
}
|
|
||||||
if (ident.value == "linear") {
|
|
||||||
return {ast::InterpolationType::kLinear, ident.source};
|
|
||||||
}
|
|
||||||
if (ident.value == "flat") {
|
|
||||||
return {ast::InterpolationType::kFlat, ident.source};
|
|
||||||
}
|
|
||||||
|
|
||||||
return add_error(ident.source, "invalid interpolation type");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// builtin_value_name
|
// builtin_value_name
|
||||||
|
@ -253,7 +253,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Single_DoubleTrailingComma) {
|
|||||||
EXPECT_TRUE(attr.errored);
|
EXPECT_TRUE(attr.errored);
|
||||||
EXPECT_EQ(attr.value, nullptr);
|
EXPECT_EQ(attr.value, nullptr);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(p->error(), "1:18: expected identifier for interpolation sample name");
|
EXPECT_EQ(p->error(), R"(1:18: expected interpolation sampling
|
||||||
|
Possible values: 'center', 'centroid', 'sample')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Center) {
|
TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Center) {
|
||||||
@ -347,7 +348,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_MissingFirstValue) {
|
|||||||
EXPECT_TRUE(attr.errored);
|
EXPECT_TRUE(attr.errored);
|
||||||
EXPECT_EQ(attr.value, nullptr);
|
EXPECT_EQ(attr.value, nullptr);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(p->error(), "1:13: expected identifier for interpolation type name");
|
EXPECT_EQ(p->error(), R"(1:13: expected interpolation type
|
||||||
|
Possible values: 'flat', 'linear', 'perspective')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Attribute_Interpolate_InvalidFirstValue) {
|
TEST_F(ParserImplTest, Attribute_Interpolate_InvalidFirstValue) {
|
||||||
@ -357,7 +359,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_InvalidFirstValue) {
|
|||||||
EXPECT_TRUE(attr.errored);
|
EXPECT_TRUE(attr.errored);
|
||||||
EXPECT_EQ(attr.value, nullptr);
|
EXPECT_EQ(attr.value, nullptr);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(p->error(), "1:13: invalid interpolation type");
|
EXPECT_EQ(p->error(), R"(1:13: expected interpolation type
|
||||||
|
Possible values: 'flat', 'linear', 'perspective')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Attribute_Interpolate_InvalidSecondValue) {
|
TEST_F(ParserImplTest, Attribute_Interpolate_InvalidSecondValue) {
|
||||||
@ -367,7 +370,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_InvalidSecondValue) {
|
|||||||
EXPECT_TRUE(attr.errored);
|
EXPECT_TRUE(attr.errored);
|
||||||
EXPECT_EQ(attr.value, nullptr);
|
EXPECT_EQ(attr.value, nullptr);
|
||||||
EXPECT_TRUE(p->has_error());
|
EXPECT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(p->error(), "1:26: invalid interpolation sampling");
|
EXPECT_EQ(p->error(), R"(1:26: expected interpolation sampling. Did you mean 'sample'?
|
||||||
|
Possible values: 'center', 'centroid', 'sample')");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Attribute_Binding) {
|
TEST_F(ParserImplTest, Attribute_Binding) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user