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
|
@ -1650,21 +1650,8 @@ Expect<ast::PipelineStage> ParserImpl::expect_pipeline_stage() {
|
|||
// | 'centroid'
|
||||
// | 'sample'
|
||||
Expect<ast::InterpolationSampling> ParserImpl::expect_interpolation_sample_name() {
|
||||
auto ident = expect_ident("interpolation sample name");
|
||||
if (ident.errored) {
|
||||
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");
|
||||
return expect_enum("interpolation sampling", ast::ParseInterpolationSampling,
|
||||
ast::kInterpolationSamplingStrings);
|
||||
}
|
||||
|
||||
// interpolation_type_name
|
||||
|
@ -1672,22 +1659,8 @@ Expect<ast::InterpolationSampling> ParserImpl::expect_interpolation_sample_name(
|
|||
// | 'linear'
|
||||
// | 'flat'
|
||||
Expect<ast::InterpolationType> ParserImpl::expect_interpolation_type_name() {
|
||||
auto ident = expect_ident("interpolation type name");
|
||||
if (ident.errored) {
|
||||
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");
|
||||
return expect_enum("interpolation type", ast::ParseInterpolationType,
|
||||
ast::kInterpolationTypeStrings);
|
||||
}
|
||||
|
||||
// builtin_value_name
|
||||
|
|
|
@ -253,7 +253,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Single_DoubleTrailingComma) {
|
|||
EXPECT_TRUE(attr.errored);
|
||||
EXPECT_EQ(attr.value, nullptr);
|
||||
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) {
|
||||
|
@ -347,7 +348,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_MissingFirstValue) {
|
|||
EXPECT_TRUE(attr.errored);
|
||||
EXPECT_EQ(attr.value, nullptr);
|
||||
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) {
|
||||
|
@ -357,7 +359,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_InvalidFirstValue) {
|
|||
EXPECT_TRUE(attr.errored);
|
||||
EXPECT_EQ(attr.value, nullptr);
|
||||
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) {
|
||||
|
@ -367,7 +370,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_InvalidSecondValue) {
|
|||
EXPECT_TRUE(attr.errored);
|
||||
EXPECT_EQ(attr.value, nullptr);
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue