From 6165cca1a6ac4e548d9987a41e7bbc9420705da5 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 6 Jan 2022 12:16:11 +0000 Subject: [PATCH] reader/wgsl: Remove texel format names as keywords These were removed in https://github.com/gpuweb/gpuweb/pull/2474. `read`, `write` and `read_write` were already excluded as keywords. Fixed: tint:1359 Change-Id: I5424f780f4bd67bb336320a22dd2097ed03b4bd6 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/75360 Kokoro: Kokoro Reviewed-by: David Neto Commit-Queue: Ben Clayton --- src/reader/wgsl/lexer.cc | 70 ----------- src/reader/wgsl/lexer_test.cc | 35 ------ src/reader/wgsl/parser_impl.cc | 216 +++++++++++++++++---------------- src/reader/wgsl/token.cc | 70 ----------- src/reader/wgsl/token.h | 70 ----------- 5 files changed, 110 insertions(+), 351 deletions(-) diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc index 7e521d12b2..f8c8bfa5bd 100644 --- a/src/reader/wgsl/lexer.cc +++ b/src/reader/wgsl/lexer.cc @@ -967,76 +967,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) { return {Token::Type::kFn, source, "fn"}; if (str == "for") return {Token::Type::kFor, source, "for"}; - if (str == "bgra8unorm") - return {Token::Type::kFormatBgra8Unorm, source, "bgra8unorm"}; - if (str == "bgra8unorm_srgb") - return {Token::Type::kFormatBgra8UnormSrgb, source, "bgra8unorm_srgb"}; - if (str == "r16float") - return {Token::Type::kFormatR16Float, source, "r16float"}; - if (str == "r16sint") - return {Token::Type::kFormatR16Sint, source, "r16sint"}; - if (str == "r16uint") - return {Token::Type::kFormatR16Uint, source, "r16uint"}; - if (str == "r32float") - return {Token::Type::kFormatR32Float, source, "r32float"}; - if (str == "r32sint") - return {Token::Type::kFormatR32Sint, source, "r32sint"}; - if (str == "r32uint") - return {Token::Type::kFormatR32Uint, source, "r32uint"}; - if (str == "r8sint") - return {Token::Type::kFormatR8Sint, source, "r8sint"}; - if (str == "r8snorm") - return {Token::Type::kFormatR8Snorm, source, "r8snorm"}; - if (str == "r8uint") - return {Token::Type::kFormatR8Uint, source, "r8uint"}; - if (str == "r8unorm") - return {Token::Type::kFormatR8Unorm, source, "r8unorm"}; - if (str == "rg11b10float") - return {Token::Type::kFormatRg11B10Float, source, "rg11b10float"}; - if (str == "rg16float") - return {Token::Type::kFormatRg16Float, source, "rg16float"}; - if (str == "rg16sint") - return {Token::Type::kFormatRg16Sint, source, "rg16sint"}; - if (str == "rg16uint") - return {Token::Type::kFormatRg16Uint, source, "rg16uint"}; - if (str == "rg32float") - return {Token::Type::kFormatRg32Float, source, "rg32float"}; - if (str == "rg32sint") - return {Token::Type::kFormatRg32Sint, source, "rg32sint"}; - if (str == "rg32uint") - return {Token::Type::kFormatRg32Uint, source, "rg32uint"}; - if (str == "rg8sint") - return {Token::Type::kFormatRg8Sint, source, "rg8sint"}; - if (str == "rg8snorm") - return {Token::Type::kFormatRg8Snorm, source, "rg8snorm"}; - if (str == "rg8uint") - return {Token::Type::kFormatRg8Uint, source, "rg8uint"}; - if (str == "rg8unorm") - return {Token::Type::kFormatRg8Unorm, source, "rg8unorm"}; - if (str == "rgb10a2unorm") - return {Token::Type::kFormatRgb10A2Unorm, source, "rgb10a2unorm"}; - if (str == "rgba16float") - return {Token::Type::kFormatRgba16Float, source, "rgba16float"}; - if (str == "rgba16sint") - return {Token::Type::kFormatRgba16Sint, source, "rgba16sint"}; - if (str == "rgba16uint") - return {Token::Type::kFormatRgba16Uint, source, "rgba16uint"}; - if (str == "rgba32float") - return {Token::Type::kFormatRgba32Float, source, "rgba32float"}; - if (str == "rgba32sint") - return {Token::Type::kFormatRgba32Sint, source, "rgba32sint"}; - if (str == "rgba32uint") - return {Token::Type::kFormatRgba32Uint, source, "rgba32uint"}; - if (str == "rgba8sint") - return {Token::Type::kFormatRgba8Sint, source, "rgba8sint"}; - if (str == "rgba8snorm") - return {Token::Type::kFormatRgba8Snorm, source, "rgba8snorm"}; - if (str == "rgba8uint") - return {Token::Type::kFormatRgba8Uint, source, "rgba8uint"}; - if (str == "rgba8unorm") - return {Token::Type::kFormatRgba8Unorm, source, "rgba8unorm"}; - if (str == "rgba8unorm_srgb") - return {Token::Type::kFormatRgba8UnormSrgb, source, "rgba8unorm_srgb"}; if (str == "function") return {Token::Type::kFunction, source, "function"}; if (str == "i32") diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc index 4db3a835d7..20b3f18daa 100644 --- a/src/reader/wgsl/lexer_test.cc +++ b/src/reader/wgsl/lexer_test.cc @@ -734,41 +734,6 @@ INSTANTIATE_TEST_SUITE_P( TokenData{"false", Token::Type::kFalse}, TokenData{"fn", Token::Type::kFn}, TokenData{"for", Token::Type::kFor}, - TokenData{"bgra8unorm", Token::Type::kFormatBgra8Unorm}, - TokenData{"bgra8unorm_srgb", Token::Type::kFormatBgra8UnormSrgb}, - TokenData{"r16float", Token::Type::kFormatR16Float}, - TokenData{"r16sint", Token::Type::kFormatR16Sint}, - TokenData{"r16uint", Token::Type::kFormatR16Uint}, - TokenData{"r32float", Token::Type::kFormatR32Float}, - TokenData{"r32sint", Token::Type::kFormatR32Sint}, - TokenData{"r32uint", Token::Type::kFormatR32Uint}, - TokenData{"r8sint", Token::Type::kFormatR8Sint}, - TokenData{"r8snorm", Token::Type::kFormatR8Snorm}, - TokenData{"r8uint", Token::Type::kFormatR8Uint}, - TokenData{"r8unorm", Token::Type::kFormatR8Unorm}, - TokenData{"rg11b10float", Token::Type::kFormatRg11B10Float}, - TokenData{"rg16float", Token::Type::kFormatRg16Float}, - TokenData{"rg16sint", Token::Type::kFormatRg16Sint}, - TokenData{"rg16uint", Token::Type::kFormatRg16Uint}, - TokenData{"rg32float", Token::Type::kFormatRg32Float}, - TokenData{"rg32sint", Token::Type::kFormatRg32Sint}, - TokenData{"rg32uint", Token::Type::kFormatRg32Uint}, - TokenData{"rg8sint", Token::Type::kFormatRg8Sint}, - TokenData{"rg8snorm", Token::Type::kFormatRg8Snorm}, - TokenData{"rg8uint", Token::Type::kFormatRg8Uint}, - TokenData{"rg8unorm", Token::Type::kFormatRg8Unorm}, - TokenData{"rgb10a2unorm", Token::Type::kFormatRgb10A2Unorm}, - TokenData{"rgba16float", Token::Type::kFormatRgba16Float}, - TokenData{"rgba16sint", Token::Type::kFormatRgba16Sint}, - TokenData{"rgba16uint", Token::Type::kFormatRgba16Uint}, - TokenData{"rgba32float", Token::Type::kFormatRgba32Float}, - TokenData{"rgba32sint", Token::Type::kFormatRgba32Sint}, - TokenData{"rgba32uint", Token::Type::kFormatRgba32Uint}, - TokenData{"rgba8sint", Token::Type::kFormatRgba8Sint}, - TokenData{"rgba8snorm", Token::Type::kFormatRgba8Snorm}, - TokenData{"rgba8uint", Token::Type::kFormatRgba8Uint}, - TokenData{"rgba8unorm", Token::Type::kFormatRgba8Unorm}, - TokenData{"rgba8unorm_srgb", Token::Type::kFormatRgba8UnormSrgb}, TokenData{"function", Token::Type::kFunction}, TokenData{"i32", Token::Type::kI32}, TokenData{"if", Token::Type::kIf}, diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 17a5e5f46a..725312d2b7 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -783,112 +783,116 @@ Maybe ParserImpl::depth_texture_type() { // | RGBA32FLOAT Expect ParserImpl::expect_image_storage_type( const std::string& use) { - if (match(Token::Type::kFormatR8Unorm)) - return ast::ImageFormat::kR8Unorm; - - if (match(Token::Type::kFormatR8Snorm)) - return ast::ImageFormat::kR8Snorm; - - if (match(Token::Type::kFormatR8Uint)) - return ast::ImageFormat::kR8Uint; - - if (match(Token::Type::kFormatR8Sint)) - return ast::ImageFormat::kR8Sint; - - if (match(Token::Type::kFormatR16Uint)) - return ast::ImageFormat::kR16Uint; - - if (match(Token::Type::kFormatR16Sint)) - return ast::ImageFormat::kR16Sint; - - if (match(Token::Type::kFormatR16Float)) - return ast::ImageFormat::kR16Float; - - if (match(Token::Type::kFormatRg8Unorm)) - return ast::ImageFormat::kRg8Unorm; - - if (match(Token::Type::kFormatRg8Snorm)) - return ast::ImageFormat::kRg8Snorm; - - if (match(Token::Type::kFormatRg8Uint)) - return ast::ImageFormat::kRg8Uint; - - if (match(Token::Type::kFormatRg8Sint)) - return ast::ImageFormat::kRg8Sint; - - if (match(Token::Type::kFormatR32Uint)) - return ast::ImageFormat::kR32Uint; - - if (match(Token::Type::kFormatR32Sint)) - return ast::ImageFormat::kR32Sint; - - if (match(Token::Type::kFormatR32Float)) - return ast::ImageFormat::kR32Float; - - if (match(Token::Type::kFormatRg16Uint)) - return ast::ImageFormat::kRg16Uint; - - if (match(Token::Type::kFormatRg16Sint)) - return ast::ImageFormat::kRg16Sint; - - if (match(Token::Type::kFormatRg16Float)) - return ast::ImageFormat::kRg16Float; - - if (match(Token::Type::kFormatRgba8Unorm)) - return ast::ImageFormat::kRgba8Unorm; - - if (match(Token::Type::kFormatRgba8UnormSrgb)) - return ast::ImageFormat::kRgba8UnormSrgb; - - if (match(Token::Type::kFormatRgba8Snorm)) - return ast::ImageFormat::kRgba8Snorm; - - if (match(Token::Type::kFormatRgba8Uint)) - return ast::ImageFormat::kRgba8Uint; - - if (match(Token::Type::kFormatRgba8Sint)) - return ast::ImageFormat::kRgba8Sint; - - if (match(Token::Type::kFormatBgra8Unorm)) - return ast::ImageFormat::kBgra8Unorm; - - if (match(Token::Type::kFormatBgra8UnormSrgb)) - return ast::ImageFormat::kBgra8UnormSrgb; - - if (match(Token::Type::kFormatRgb10A2Unorm)) - return ast::ImageFormat::kRgb10A2Unorm; - - if (match(Token::Type::kFormatRg11B10Float)) - return ast::ImageFormat::kRg11B10Float; - - if (match(Token::Type::kFormatRg32Uint)) - return ast::ImageFormat::kRg32Uint; - - if (match(Token::Type::kFormatRg32Sint)) - return ast::ImageFormat::kRg32Sint; - - if (match(Token::Type::kFormatRg32Float)) - return ast::ImageFormat::kRg32Float; - - if (match(Token::Type::kFormatRgba16Uint)) - return ast::ImageFormat::kRgba16Uint; - - if (match(Token::Type::kFormatRgba16Sint)) - return ast::ImageFormat::kRgba16Sint; - - if (match(Token::Type::kFormatRgba16Float)) - return ast::ImageFormat::kRgba16Float; - - if (match(Token::Type::kFormatRgba32Uint)) - return ast::ImageFormat::kRgba32Uint; - - if (match(Token::Type::kFormatRgba32Sint)) - return ast::ImageFormat::kRgba32Sint; - - if (match(Token::Type::kFormatRgba32Float)) - return ast::ImageFormat::kRgba32Float; - - return add_error(peek().source(), "invalid format", use); + auto tok = next(); + if (tok.IsIdentifier()) { + auto s = tok.to_str(); + if (s == "bgra8unorm") { + return ast::ImageFormat::kBgra8Unorm; + } + if (s == "bgra8unorm_srgb") { + return ast::ImageFormat::kBgra8UnormSrgb; + } + if (s == "r16float") { + return ast::ImageFormat::kR16Float; + } + if (s == "r16sint") { + return ast::ImageFormat::kR16Sint; + } + if (s == "r16uint") { + return ast::ImageFormat::kR16Uint; + } + if (s == "r32float") { + return ast::ImageFormat::kR32Float; + } + if (s == "r32sint") { + return ast::ImageFormat::kR32Sint; + } + if (s == "r32uint") { + return ast::ImageFormat::kR32Uint; + } + if (s == "r8sint") { + return ast::ImageFormat::kR8Sint; + } + if (s == "r8snorm") { + return ast::ImageFormat::kR8Snorm; + } + if (s == "r8uint") { + return ast::ImageFormat::kR8Uint; + } + if (s == "r8unorm") { + return ast::ImageFormat::kR8Unorm; + } + if (s == "rg11b10float") { + return ast::ImageFormat::kRg11B10Float; + } + if (s == "rg16float") { + return ast::ImageFormat::kRg16Float; + } + if (s == "rg16sint") { + return ast::ImageFormat::kRg16Sint; + } + if (s == "rg16uint") { + return ast::ImageFormat::kRg16Uint; + } + if (s == "rg32float") { + return ast::ImageFormat::kRg32Float; + } + if (s == "rg32sint") { + return ast::ImageFormat::kRg32Sint; + } + if (s == "rg32uint") { + return ast::ImageFormat::kRg32Uint; + } + if (s == "rg8sint") { + return ast::ImageFormat::kRg8Sint; + } + if (s == "rg8snorm") { + return ast::ImageFormat::kRg8Snorm; + } + if (s == "rg8uint") { + return ast::ImageFormat::kRg8Uint; + } + if (s == "rg8unorm") { + return ast::ImageFormat::kRg8Unorm; + } + if (s == "rgb10a2unorm") { + return ast::ImageFormat::kRgb10A2Unorm; + } + if (s == "rgba16float") { + return ast::ImageFormat::kRgba16Float; + } + if (s == "rgba16sint") { + return ast::ImageFormat::kRgba16Sint; + } + if (s == "rgba16uint") { + return ast::ImageFormat::kRgba16Uint; + } + if (s == "rgba32float") { + return ast::ImageFormat::kRgba32Float; + } + if (s == "rgba32sint") { + return ast::ImageFormat::kRgba32Sint; + } + if (s == "rgba32uint") { + return ast::ImageFormat::kRgba32Uint; + } + if (s == "rgba8sint") { + return ast::ImageFormat::kRgba8Sint; + } + if (s == "rgba8snorm") { + return ast::ImageFormat::kRgba8Snorm; + } + if (s == "rgba8uint") { + return ast::ImageFormat::kRgba8Uint; + } + if (s == "rgba8unorm") { + return ast::ImageFormat::kRgba8Unorm; + } + if (s == "rgba8unorm_srgb") { + return ast::ImageFormat::kRgba8UnormSrgb; + } + } + return add_error(tok.source(), "invalid format", use); } // variable_ident_decl diff --git a/src/reader/wgsl/token.cc b/src/reader/wgsl/token.cc index 2a625bb9a5..864036c27e 100644 --- a/src/reader/wgsl/token.cc +++ b/src/reader/wgsl/token.cc @@ -145,76 +145,6 @@ std::string Token::TypeToName(Type type) { return "fn"; case Token::Type::kFor: return "for"; - case Token::Type::kFormatBgra8Unorm: - return "bgra8unorm"; - case Token::Type::kFormatBgra8UnormSrgb: - return "bgra8unorm_srgb"; - case Token::Type::kFormatR16Float: - return "r16float"; - case Token::Type::kFormatR16Sint: - return "r16sint"; - case Token::Type::kFormatR16Uint: - return "r16uint"; - case Token::Type::kFormatR32Float: - return "r32float"; - case Token::Type::kFormatR32Sint: - return "r32sint"; - case Token::Type::kFormatR32Uint: - return "r32uint"; - case Token::Type::kFormatR8Sint: - return "r8sint"; - case Token::Type::kFormatR8Snorm: - return "r8snorm"; - case Token::Type::kFormatR8Uint: - return "r8uint"; - case Token::Type::kFormatR8Unorm: - return "r8unorm"; - case Token::Type::kFormatRg11B10Float: - return "rg11b10float"; - case Token::Type::kFormatRg16Float: - return "rg16float"; - case Token::Type::kFormatRg16Sint: - return "rg16sint"; - case Token::Type::kFormatRg16Uint: - return "rg16uint"; - case Token::Type::kFormatRg32Float: - return "rg32float"; - case Token::Type::kFormatRg32Sint: - return "rg32sint"; - case Token::Type::kFormatRg32Uint: - return "rg32uint"; - case Token::Type::kFormatRg8Sint: - return "rg8sint"; - case Token::Type::kFormatRg8Snorm: - return "rg8snorm"; - case Token::Type::kFormatRg8Uint: - return "rg8uint"; - case Token::Type::kFormatRg8Unorm: - return "rg8unorm"; - case Token::Type::kFormatRgb10A2Unorm: - return "rgb10a2unorm"; - case Token::Type::kFormatRgba16Float: - return "rgba16float"; - case Token::Type::kFormatRgba16Sint: - return "rgba16sint"; - case Token::Type::kFormatRgba16Uint: - return "rgba16uint"; - case Token::Type::kFormatRgba32Float: - return "rgba32float"; - case Token::Type::kFormatRgba32Sint: - return "rgba32sint"; - case Token::Type::kFormatRgba32Uint: - return "rgba32uint"; - case Token::Type::kFormatRgba8Sint: - return "rgba8sint"; - case Token::Type::kFormatRgba8Snorm: - return "rgba8snorm"; - case Token::Type::kFormatRgba8Uint: - return "rgba8uint"; - case Token::Type::kFormatRgba8Unorm: - return "rgba8unorm"; - case Token::Type::kFormatRgba8UnormSrgb: - return "rgba8unorm_srgb"; case Token::Type::kFunction: return "function"; case Token::Type::kI32: diff --git a/src/reader/wgsl/token.h b/src/reader/wgsl/token.h index 35c8f79b68..dca21125a9 100644 --- a/src/reader/wgsl/token.h +++ b/src/reader/wgsl/token.h @@ -153,76 +153,6 @@ class Token { kFn, // A 'for' kFor, - // A 'Bgra8Unorm' format - kFormatBgra8Unorm, - // A 'Bgra8UnormSrgb' format - kFormatBgra8UnormSrgb, - // A 'R16Float' format - kFormatR16Float, - // A 'R16Sint' format - kFormatR16Sint, - // A 'R16Uint' format - kFormatR16Uint, - // A 'R32Float' format - kFormatR32Float, - // A 'R32Sint' format - kFormatR32Sint, - // A 'R32Uint' format - kFormatR32Uint, - // A 'R8Sint' format - kFormatR8Sint, - // A 'R8Snorm' format - kFormatR8Snorm, - // A 'R8Uint' format - kFormatR8Uint, - // A 'R8Unorm' format - kFormatR8Unorm, - // A 'Rg11B10Float' format - kFormatRg11B10Float, - // A 'Rg16Float' format - kFormatRg16Float, - // A 'Rg16Sint' format - kFormatRg16Sint, - // A 'Rg16Uint' format - kFormatRg16Uint, - // A 'Rg32Float' format - kFormatRg32Float, - // A 'Rg32Sint' format - kFormatRg32Sint, - // A 'Rg32Uint' format - kFormatRg32Uint, - // A 'Rg8Sint' format - kFormatRg8Sint, - // A 'Rg8Snorm' format - kFormatRg8Snorm, - // A 'Rg8Uint' format - kFormatRg8Uint, - // A 'Rg8Unorm' format - kFormatRg8Unorm, - // A 'Rgb10A2Unorm' format - kFormatRgb10A2Unorm, - // A 'Rgba16Float' format - kFormatRgba16Float, - // A 'Rgba16Sint' format - kFormatRgba16Sint, - // A 'Rgba16Uint' format - kFormatRgba16Uint, - // A 'Rgba32Float' format - kFormatRgba32Float, - // A 'Rgba32Sint' format - kFormatRgba32Sint, - // A 'Rgba32Uint' format - kFormatRgba32Uint, - // A 'Rgba8Sint' format - kFormatRgba8Sint, - // A 'Rgba8Snorm' format - kFormatRgba8Snorm, - // A 'Rgba8Uint' format - kFormatRgba8Uint, - // A 'Rgba8Unorm' format - kFormatRgba8Unorm, - // A 'Rgba8UnormSrgb' format - kFormatRgba8UnormSrgb, /// A 'function' kFunction, /// A 'i32'