wsgl parser: Migrate more code to use expect & match
Reduces code. Keeps things more consistent. Bug: tint:282 Change-Id: Iff280880eb033fbcee4c6095c2da2d4af06835b5 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32103 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
d60f0feee4
commit
f2e91857e1
|
@ -375,25 +375,21 @@ ast::type::Type* ParserImpl::texture_sampler_types() {
|
||||||
|
|
||||||
auto dim = sampled_texture_type();
|
auto dim = sampled_texture_type();
|
||||||
if (dim != ast::type::TextureDimension::kNone) {
|
if (dim != ast::type::TextureDimension::kNone) {
|
||||||
auto t = next();
|
const char* use = "sampled texture type";
|
||||||
if (!t.IsLessThan()) {
|
|
||||||
add_error(peek(), "missing '<' for sampled texture type");
|
if (!expect(use, Token::Type::kLessThan))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
auto* subtype = type_decl();
|
auto* subtype = type_decl();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (subtype == nullptr) {
|
if (subtype == nullptr) {
|
||||||
add_error(peek(), "invalid subtype for sampled texture type");
|
add_error(peek().source(), "invalid subtype", use);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = next();
|
if (!expect(use, Token::Type::kGreaterThan))
|
||||||
if (!t.IsGreaterThan()) {
|
|
||||||
add_error(peek(), "missing '>' for sampled texture type");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
return ctx_.type_mgr().Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::SampledTextureType>(dim, subtype));
|
std::make_unique<ast::type::SampledTextureType>(dim, subtype));
|
||||||
|
@ -401,25 +397,21 @@ ast::type::Type* ParserImpl::texture_sampler_types() {
|
||||||
|
|
||||||
dim = multisampled_texture_type();
|
dim = multisampled_texture_type();
|
||||||
if (dim != ast::type::TextureDimension::kNone) {
|
if (dim != ast::type::TextureDimension::kNone) {
|
||||||
auto t = next();
|
const char* use = "multisampled texture type";
|
||||||
if (!t.IsLessThan()) {
|
|
||||||
add_error(peek(), "missing '<' for multisampled texture type");
|
if (!expect(use, Token::Type::kLessThan))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
auto* subtype = type_decl();
|
auto* subtype = type_decl();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (subtype == nullptr) {
|
if (subtype == nullptr) {
|
||||||
add_error(peek(), "invalid subtype for multisampled texture type");
|
add_error(peek().source(), "invalid subtype", use);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = next();
|
if (!expect(use, Token::Type::kGreaterThan))
|
||||||
if (!t.IsGreaterThan()) {
|
|
||||||
add_error(peek(), "missing '>' for multisampled texture type");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
return ctx_.type_mgr().Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::MultisampledTextureType>(dim, subtype));
|
std::make_unique<ast::type::MultisampledTextureType>(dim, subtype));
|
||||||
|
@ -429,25 +421,21 @@ ast::type::Type* ParserImpl::texture_sampler_types() {
|
||||||
ast::AccessControl access;
|
ast::AccessControl access;
|
||||||
std::tie(storage_dim, access) = storage_texture_type();
|
std::tie(storage_dim, access) = storage_texture_type();
|
||||||
if (storage_dim != ast::type::TextureDimension::kNone) {
|
if (storage_dim != ast::type::TextureDimension::kNone) {
|
||||||
auto t = next();
|
const char* use = "storage texture type";
|
||||||
if (!t.IsLessThan()) {
|
|
||||||
add_error(peek(), "missing '<' for storage texture type");
|
if (!expect(use, Token::Type::kLessThan))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
auto format = image_storage_type();
|
auto format = image_storage_type();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (format == ast::type::ImageFormat::kNone) {
|
if (format == ast::type::ImageFormat::kNone) {
|
||||||
add_error(peek(), "invalid format for storage texture type");
|
add_error(peek().source(), "invalid format", use);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = next();
|
if (!expect(use, Token::Type::kGreaterThan))
|
||||||
if (!t.IsGreaterThan()) {
|
|
||||||
add_error(peek(), "missing '>' for storage texture type");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
return ctx_.type_mgr().Get(std::make_unique<ast::type::StorageTextureType>(
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::StorageTextureType>(
|
||||||
storage_dim, access, format));
|
storage_dim, access, format));
|
||||||
|
@ -779,11 +767,8 @@ ast::StorageClass ParserImpl::variable_storage_decoration() {
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return sc;
|
return sc;
|
||||||
|
|
||||||
auto t = next();
|
if (!expect(use, Token::Type::kGreaterThan))
|
||||||
if (!t.IsGreaterThan()) {
|
|
||||||
add_error(t, "missing > for variable decoration");
|
|
||||||
return ast::StorageClass::kNone;
|
return ast::StorageClass::kNone;
|
||||||
}
|
|
||||||
|
|
||||||
return sc;
|
return sc;
|
||||||
}
|
}
|
||||||
|
@ -847,8 +832,7 @@ ast::type::Type* ParserImpl::type_alias() {
|
||||||
// | texture_sampler_types
|
// | texture_sampler_types
|
||||||
ast::type::Type* ParserImpl::type_decl() {
|
ast::type::Type* ParserImpl::type_decl() {
|
||||||
auto t = peek();
|
auto t = peek();
|
||||||
if (t.IsIdentifier()) {
|
if (match(Token::Type::kIdentifier)) {
|
||||||
next(); // Consume the peek
|
|
||||||
auto* ty = get_constructed(t.to_str());
|
auto* ty = get_constructed(t.to_str());
|
||||||
if (ty == nullptr) {
|
if (ty == nullptr) {
|
||||||
add_error(t, "unknown constructed type '" + t.to_str() + "'");
|
add_error(t, "unknown constructed type '" + t.to_str() + "'");
|
||||||
|
@ -856,28 +840,24 @@ ast::type::Type* ParserImpl::type_decl() {
|
||||||
}
|
}
|
||||||
return ty;
|
return ty;
|
||||||
}
|
}
|
||||||
if (t.IsBool()) {
|
|
||||||
next(); // Consume the peek
|
if (match(Token::Type::kBool))
|
||||||
return ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
||||||
}
|
|
||||||
if (t.IsF32()) {
|
if (match(Token::Type::kF32))
|
||||||
next(); // Consume the peek
|
|
||||||
return ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
|
||||||
}
|
|
||||||
if (t.IsI32()) {
|
if (match(Token::Type::kI32))
|
||||||
next(); // Consume the peek
|
|
||||||
return ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
||||||
}
|
|
||||||
if (t.IsU32()) {
|
if (match(Token::Type::kU32))
|
||||||
next(); // Consume the peek
|
|
||||||
return ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
|
return ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
|
||||||
}
|
|
||||||
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
|
if (t.IsVec2() || t.IsVec3() || t.IsVec4())
|
||||||
return expect_type_decl_vector(t);
|
return expect_type_decl_vector(t);
|
||||||
}
|
|
||||||
if (t.IsPtr()) {
|
if (match(Token::Type::kPtr))
|
||||||
return expect_type_decl_pointer(t);
|
return expect_type_decl_pointer();
|
||||||
}
|
|
||||||
|
|
||||||
auto decos = decoration_list();
|
auto decos = decoration_list();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
|
@ -907,26 +887,18 @@ ast::type::Type* ParserImpl::type_decl() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::type::Type* ParserImpl::expect_type_decl_pointer(Token t) {
|
ast::type::Type* ParserImpl::expect_type_decl_pointer() {
|
||||||
next(); // Consume the peek
|
|
||||||
|
|
||||||
const char* use = "ptr declaration";
|
const char* use = "ptr declaration";
|
||||||
|
|
||||||
t = next();
|
if (!expect(use, Token::Type::kLessThan))
|
||||||
if (!t.IsLessThan()) {
|
|
||||||
add_error(t, "missing < for ptr declaration");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
auto sc = expect_storage_class(use);
|
auto sc = expect_storage_class(use);
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
t = next();
|
if (!expect(use, Token::Type::kComma))
|
||||||
if (!t.IsComma()) {
|
|
||||||
add_error(t, "missing , for ptr declaration");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
auto* subtype = type_decl();
|
auto* subtype = type_decl();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
|
@ -936,11 +908,8 @@ ast::type::Type* ParserImpl::expect_type_decl_pointer(Token t) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = next();
|
if (!expect(use, Token::Type::kGreaterThan))
|
||||||
if (!t.IsGreaterThan()) {
|
|
||||||
add_error(t, "missing > for ptr declaration");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
return ctx_.type_mgr().Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::PointerType>(subtype, sc));
|
std::make_unique<ast::type::PointerType>(subtype, sc));
|
||||||
|
@ -955,25 +924,21 @@ ast::type::Type* ParserImpl::expect_type_decl_vector(Token t) {
|
||||||
else if (t.IsVec4())
|
else if (t.IsVec4())
|
||||||
count = 4;
|
count = 4;
|
||||||
|
|
||||||
t = next();
|
const char* use = "vector";
|
||||||
if (!t.IsLessThan()) {
|
|
||||||
add_error(t, "missing < for vector");
|
if (!expect(use, Token::Type::kLessThan))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
auto* subtype = type_decl();
|
auto* subtype = type_decl();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (subtype == nullptr) {
|
if (subtype == nullptr) {
|
||||||
add_error(peek(), "unable to determine subtype for vector");
|
add_error(peek().source(), "unable to determine subtype", use);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = next();
|
if (!expect(use, Token::Type::kGreaterThan))
|
||||||
if (!t.IsGreaterThan()) {
|
|
||||||
add_error(t, "missing > for vector");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
return ctx_.type_mgr().Get(
|
return ctx_.type_mgr().Get(
|
||||||
std::make_unique<ast::type::VectorType>(subtype, count));
|
std::make_unique<ast::type::VectorType>(subtype, count));
|
||||||
|
@ -2128,13 +2093,7 @@ ast::ExpressionList ParserImpl::expect_argument_expression_list() {
|
||||||
ast::ExpressionList ret;
|
ast::ExpressionList ret;
|
||||||
ret.push_back(std::move(arg));
|
ret.push_back(std::move(arg));
|
||||||
|
|
||||||
for (;;) {
|
while (match(Token::Type::kComma)) {
|
||||||
auto t = peek();
|
|
||||||
if (!t.IsComma())
|
|
||||||
break;
|
|
||||||
|
|
||||||
next(); // Consume the peek
|
|
||||||
|
|
||||||
arg = logical_or_expression();
|
arg = logical_or_expression();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return {};
|
return {};
|
||||||
|
@ -2618,45 +2577,24 @@ std::unique_ptr<ast::AssignmentStatement> ParserImpl::assignment_stmt() {
|
||||||
// | FALSE
|
// | FALSE
|
||||||
std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
|
std::unique_ptr<ast::Literal> ParserImpl::const_literal() {
|
||||||
auto t = peek();
|
auto t = peek();
|
||||||
if (t.IsTrue()) {
|
if (match(Token::Type::kTrue)) {
|
||||||
next(); // Consume the peek
|
|
||||||
|
|
||||||
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
||||||
if (!type) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return std::make_unique<ast::BoolLiteral>(type, true);
|
return std::make_unique<ast::BoolLiteral>(type, true);
|
||||||
}
|
}
|
||||||
if (t.IsFalse()) {
|
if (match(Token::Type::kFalse)) {
|
||||||
next(); // Consume the peek
|
|
||||||
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
||||||
if (!type) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return std::make_unique<ast::BoolLiteral>(type, false);
|
return std::make_unique<ast::BoolLiteral>(type, false);
|
||||||
}
|
}
|
||||||
if (t.IsSintLiteral()) {
|
if (match(Token::Type::kSintLiteral)) {
|
||||||
next(); // Consume the peek
|
|
||||||
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
||||||
if (!type) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return std::make_unique<ast::SintLiteral>(type, t.to_i32());
|
return std::make_unique<ast::SintLiteral>(type, t.to_i32());
|
||||||
}
|
}
|
||||||
if (t.IsUintLiteral()) {
|
if (match(Token::Type::kUintLiteral)) {
|
||||||
next(); // Consume the peek
|
|
||||||
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
|
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
|
||||||
if (!type) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return std::make_unique<ast::UintLiteral>(type, t.to_u32());
|
return std::make_unique<ast::UintLiteral>(type, t.to_u32());
|
||||||
}
|
}
|
||||||
if (t.IsFloatLiteral()) {
|
if (match(Token::Type::kFloatLiteral)) {
|
||||||
next(); // Consume the peek
|
|
||||||
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
|
auto* type = ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
|
||||||
if (!type) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return std::make_unique<ast::FloatLiteral>(type, t.to_f32());
|
return std::make_unique<ast::FloatLiteral>(type, t.to_f32());
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -544,7 +544,7 @@ class ParserImpl {
|
||||||
/// Used to ensure that all decorations are consumed.
|
/// Used to ensure that all decorations are consumed.
|
||||||
bool expect_decorations_consumed(const ast::DecorationList& list);
|
bool expect_decorations_consumed(const ast::DecorationList& list);
|
||||||
|
|
||||||
ast::type::Type* expect_type_decl_pointer(Token t);
|
ast::type::Type* expect_type_decl_pointer();
|
||||||
ast::type::Type* expect_type_decl_vector(Token t);
|
ast::type::Type* expect_type_decl_vector(Token t);
|
||||||
ast::type::Type* expect_type_decl_array(ast::ArrayDecorationList decos);
|
ast::type::Type* expect_type_decl_array(ast::ArrayDecorationList decos);
|
||||||
ast::type::Type* expect_type_decl_matrix(Token t);
|
ast::type::Type* expect_type_decl_matrix(Token t);
|
||||||
|
|
|
@ -534,16 +534,16 @@ TEST_F(ParserImplErrorTest, GlobalDeclConstExprMissingRParen) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan_Old) {
|
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan_Old) {
|
||||||
EXPECT("var x : texture_sampled_1d;",
|
EXPECT("var x : texture_sampled_1d;",
|
||||||
"test.wgsl:1:28 error: missing '<' for sampled texture type\n"
|
"test.wgsl:1:27 error: expected '<' for sampled texture type\n"
|
||||||
"var x : texture_sampled_1d;\n"
|
"var x : texture_sampled_1d;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingGreaterThan_Old) {
|
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingGreaterThan_Old) {
|
||||||
EXPECT("var x : texture_sampled_1d<f32;",
|
EXPECT("var x : texture_sampled_1d<f32;",
|
||||||
"test.wgsl:1:32 error: missing '>' for sampled texture type\n"
|
"test.wgsl:1:31 error: expected '>' for sampled texture type\n"
|
||||||
"var x : texture_sampled_1d<f32;\n"
|
"var x : texture_sampled_1d<f32;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype_Old) {
|
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype_Old) {
|
||||||
|
@ -555,16 +555,16 @@ TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype_Old) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan) {
|
||||||
EXPECT("var x : texture_1d;",
|
EXPECT("var x : texture_1d;",
|
||||||
"test.wgsl:1:20 error: missing '<' for sampled texture type\n"
|
"test.wgsl:1:19 error: expected '<' for sampled texture type\n"
|
||||||
"var x : texture_1d;\n"
|
"var x : texture_1d;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingGreaterThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingGreaterThan) {
|
||||||
EXPECT("var x : texture_1d<f32;",
|
EXPECT("var x : texture_1d<f32;",
|
||||||
"test.wgsl:1:24 error: missing '>' for sampled texture type\n"
|
"test.wgsl:1:23 error: expected '>' for sampled texture type\n"
|
||||||
"var x : texture_1d<f32;\n"
|
"var x : texture_1d<f32;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype) {
|
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype) {
|
||||||
|
@ -576,16 +576,16 @@ TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureInvalidSubtype) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureMissingLessThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureMissingLessThan) {
|
||||||
EXPECT("var x : texture_multisampled_2d;",
|
EXPECT("var x : texture_multisampled_2d;",
|
||||||
"test.wgsl:1:33 error: missing '<' for multisampled texture type\n"
|
"test.wgsl:1:32 error: expected '<' for multisampled texture type\n"
|
||||||
"var x : texture_multisampled_2d;\n"
|
"var x : texture_multisampled_2d;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureMissingGreaterThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureMissingGreaterThan) {
|
||||||
EXPECT("var x : texture_multisampled_2d<f32;",
|
EXPECT("var x : texture_multisampled_2d<f32;",
|
||||||
"test.wgsl:1:37 error: missing '>' for multisampled texture type\n"
|
"test.wgsl:1:36 error: expected '>' for multisampled texture type\n"
|
||||||
"var x : texture_multisampled_2d<f32;\n"
|
"var x : texture_multisampled_2d<f32;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureInvalidSubtype) {
|
TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureInvalidSubtype) {
|
||||||
|
@ -597,16 +597,16 @@ TEST_F(ParserImplErrorTest, GlobalDeclMultisampledTextureInvalidSubtype) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan_Old) {
|
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan_Old) {
|
||||||
EXPECT("var x : texture_ro_2d;",
|
EXPECT("var x : texture_ro_2d;",
|
||||||
"test.wgsl:1:23 error: missing '<' for storage texture type\n"
|
"test.wgsl:1:22 error: expected '<' for storage texture type\n"
|
||||||
"var x : texture_ro_2d;\n"
|
"var x : texture_ro_2d;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan_Old) {
|
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan_Old) {
|
||||||
EXPECT("var x : texture_ro_2d<r8uint;",
|
EXPECT("var x : texture_ro_2d<r8uint;",
|
||||||
"test.wgsl:1:30 error: missing '>' for storage texture type\n"
|
"test.wgsl:1:29 error: expected '>' for storage texture type\n"
|
||||||
"var x : texture_ro_2d<r8uint;\n"
|
"var x : texture_ro_2d<r8uint;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingInvalidSubtype_Old) {
|
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingInvalidSubtype_Old) {
|
||||||
|
@ -618,16 +618,16 @@ TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingInvalidSubtype_Old) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingLessThan) {
|
||||||
EXPECT("var x : texture_storage_ro_2d;",
|
EXPECT("var x : texture_storage_ro_2d;",
|
||||||
"test.wgsl:1:31 error: missing '<' for storage texture type\n"
|
"test.wgsl:1:30 error: expected '<' for storage texture type\n"
|
||||||
"var x : texture_storage_ro_2d;\n"
|
"var x : texture_storage_ro_2d;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingGreaterThan) {
|
||||||
EXPECT("var x : texture_storage_ro_2d<r8uint;",
|
EXPECT("var x : texture_storage_ro_2d<r8uint;",
|
||||||
"test.wgsl:1:38 error: missing '>' for storage texture type\n"
|
"test.wgsl:1:37 error: expected '>' for storage texture type\n"
|
||||||
"var x : texture_storage_ro_2d<r8uint;\n"
|
"var x : texture_storage_ro_2d<r8uint;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingSubtype) {
|
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingSubtype) {
|
||||||
|
@ -1023,21 +1023,21 @@ TEST_F(ParserImplErrorTest, GlobalDeclVarMissingSemicolon) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingLessThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingLessThan) {
|
||||||
EXPECT("var i : ptr;",
|
EXPECT("var i : ptr;",
|
||||||
"test.wgsl:1:12 error: missing < for ptr declaration\n"
|
"test.wgsl:1:12 error: expected '<' for ptr declaration\n"
|
||||||
"var i : ptr;\n"
|
"var i : ptr;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingGreaterThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingGreaterThan) {
|
||||||
EXPECT("var i : ptr<in, u32;",
|
EXPECT("var i : ptr<in, u32;",
|
||||||
"test.wgsl:1:20 error: missing > for ptr declaration\n"
|
"test.wgsl:1:20 error: expected '>' for ptr declaration\n"
|
||||||
"var i : ptr<in, u32;\n"
|
"var i : ptr<in, u32;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingComma) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingComma) {
|
||||||
EXPECT("var i : ptr<in u32>;",
|
EXPECT("var i : ptr<in u32>;",
|
||||||
"test.wgsl:1:16 error: missing , for ptr declaration\n"
|
"test.wgsl:1:16 error: expected ',' for ptr declaration\n"
|
||||||
"var i : ptr<in u32>;\n"
|
"var i : ptr<in u32>;\n"
|
||||||
" ^^^\n");
|
" ^^^\n");
|
||||||
}
|
}
|
||||||
|
@ -1065,21 +1065,21 @@ TEST_F(ParserImplErrorTest, GlobalDeclVarStorageDeclInvalidClass) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarStorageDeclMissingGThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarStorageDeclMissingGThan) {
|
||||||
EXPECT("var<in i : i32",
|
EXPECT("var<in i : i32",
|
||||||
"test.wgsl:1:8 error: missing > for variable decoration\n"
|
"test.wgsl:1:8 error: expected '>' for variable decoration\n"
|
||||||
"var<in i : i32\n"
|
"var<in i : i32\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarVectorMissingLessThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarVectorMissingLessThan) {
|
||||||
EXPECT("var i : vec3;",
|
EXPECT("var i : vec3;",
|
||||||
"test.wgsl:1:13 error: missing < for vector\n"
|
"test.wgsl:1:13 error: expected '<' for vector\n"
|
||||||
"var i : vec3;\n"
|
"var i : vec3;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, GlobalDeclVarVectorMissingGreaterThan) {
|
TEST_F(ParserImplErrorTest, GlobalDeclVarVectorMissingGreaterThan) {
|
||||||
EXPECT("var i : vec3<u32;",
|
EXPECT("var i : vec3<u32;",
|
||||||
"test.wgsl:1:17 error: missing > for vector\n"
|
"test.wgsl:1:17 error: expected '>' for vector\n"
|
||||||
"var i : vec3<u32;\n"
|
"var i : vec3<u32;\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingLessThan_Old) {
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:19: missing '<' for sampled texture type");
|
EXPECT_EQ(p->error(), "1:19: expected '<' for sampled texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest,
|
TEST_F(ParserImplTest,
|
||||||
|
@ -122,7 +122,7 @@ TEST_F(ParserImplTest,
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:23: missing '>' for sampled texture type");
|
EXPECT_EQ(p->error(), "1:23: expected '>' for sampled texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
|
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
|
||||||
|
@ -179,7 +179,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingLessThan) {
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:11: missing '<' for sampled texture type");
|
EXPECT_EQ(p->error(), "1:11: expected '<' for sampled texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingGreaterThan) {
|
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingGreaterThan) {
|
||||||
|
@ -187,7 +187,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingGreaterThan) {
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:15: missing '>' for sampled texture type");
|
EXPECT_EQ(p->error(), "1:15: expected '>' for sampled texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
|
TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
|
||||||
|
@ -222,7 +222,7 @@ TEST_F(ParserImplTest,
|
||||||
auto* p = parser("texture_multisampled_2d");
|
auto* p = parser("texture_multisampled_2d");
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:24: missing '<' for multisampled texture type");
|
EXPECT_EQ(p->error(), "1:24: expected '<' for multisampled texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest,
|
TEST_F(ParserImplTest,
|
||||||
|
@ -230,7 +230,7 @@ TEST_F(ParserImplTest,
|
||||||
auto* p = parser("texture_multisampled_2d<u32");
|
auto* p = parser("texture_multisampled_2d<u32");
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:28: missing '>' for multisampled texture type");
|
EXPECT_EQ(p->error(), "1:28: expected '>' for multisampled texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest,
|
TEST_F(ParserImplTest,
|
||||||
|
@ -281,7 +281,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingLessThan_Old) {
|
||||||
auto* p = parser("texture_ro_1d");
|
auto* p = parser("texture_ro_1d");
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:14: missing '<' for storage texture type");
|
EXPECT_EQ(p->error(), "1:14: expected '<' for storage texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest,
|
TEST_F(ParserImplTest,
|
||||||
|
@ -289,7 +289,7 @@ TEST_F(ParserImplTest,
|
||||||
auto* p = parser("texture_wo_1d<r8unorm");
|
auto* p = parser("texture_wo_1d<r8unorm");
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:22: missing '>' for storage texture type");
|
EXPECT_EQ(p->error(), "1:22: expected '>' for storage texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) {
|
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) {
|
||||||
|
@ -338,14 +338,14 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingLessThan) {
|
||||||
auto* p = parser("texture_storage_ro_1d");
|
auto* p = parser("texture_storage_ro_1d");
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:22: missing '<' for storage texture type");
|
EXPECT_EQ(p->error(), "1:22: expected '<' for storage texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingGreaterThan) {
|
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingGreaterThan) {
|
||||||
auto* p = parser("texture_storage_ro_1d<r8unorm");
|
auto* p = parser("texture_storage_ro_1d<r8unorm");
|
||||||
auto* t = p->texture_sampler_types();
|
auto* t = p->texture_sampler_types();
|
||||||
EXPECT_EQ(t, nullptr);
|
EXPECT_EQ(t, nullptr);
|
||||||
EXPECT_EQ(p->error(), "1:30: missing '>' for storage texture type");
|
EXPECT_EQ(p->error(), "1:30: expected '>' for storage texture type");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -149,7 +149,7 @@ TEST_P(VecMissingGreaterThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto* t = p->type_decl();
|
auto* t = p->type_decl();
|
||||||
ASSERT_EQ(t, nullptr);
|
ASSERT_EQ(t, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:9: missing > for vector");
|
ASSERT_EQ(p->error(), "1:9: expected '>' for vector");
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
VecMissingGreaterThanTest,
|
VecMissingGreaterThanTest,
|
||||||
|
@ -165,7 +165,7 @@ TEST_P(VecMissingLessThanTest, Handles_Missing_GreaterThan) {
|
||||||
auto* t = p->type_decl();
|
auto* t = p->type_decl();
|
||||||
ASSERT_EQ(t, nullptr);
|
ASSERT_EQ(t, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: missing < for vector");
|
ASSERT_EQ(p->error(), "1:5: expected '<' for vector");
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
INSTANTIATE_TEST_SUITE_P(ParserImplTest,
|
||||||
VecMissingLessThanTest,
|
VecMissingLessThanTest,
|
||||||
|
@ -238,7 +238,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingLessThan) {
|
||||||
auto* t = p->type_decl();
|
auto* t = p->type_decl();
|
||||||
ASSERT_EQ(t, nullptr);
|
ASSERT_EQ(t, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:5: missing < for ptr declaration");
|
ASSERT_EQ(p->error(), "1:5: expected '<' for ptr declaration");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingGreaterThan) {
|
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingGreaterThan) {
|
||||||
|
@ -246,7 +246,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingGreaterThan) {
|
||||||
auto* t = p->type_decl();
|
auto* t = p->type_decl();
|
||||||
ASSERT_EQ(t, nullptr);
|
ASSERT_EQ(t, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:18: missing > for ptr declaration");
|
ASSERT_EQ(p->error(), "1:18: expected '>' for ptr declaration");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingComma) {
|
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingComma) {
|
||||||
|
@ -254,7 +254,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingComma) {
|
||||||
auto* t = p->type_decl();
|
auto* t = p->type_decl();
|
||||||
ASSERT_EQ(t, nullptr);
|
ASSERT_EQ(t, nullptr);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:14: missing , for ptr declaration");
|
ASSERT_EQ(p->error(), "1:14: expected ',' for ptr declaration");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingStorageClass) {
|
TEST_F(ParserImplTest, TypeDecl_Ptr_MissingStorageClass) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ TEST_F(ParserImplTest, VariableStorageDecoration_MissingGreaterThan) {
|
||||||
auto sc = p->variable_storage_decoration();
|
auto sc = p->variable_storage_decoration();
|
||||||
ASSERT_EQ(sc, ast::StorageClass::kNone);
|
ASSERT_EQ(sc, ast::StorageClass::kNone);
|
||||||
ASSERT_TRUE(p->has_error());
|
ASSERT_TRUE(p->has_error());
|
||||||
ASSERT_EQ(p->error(), "1:4: missing > for variable decoration");
|
ASSERT_EQ(p->error(), "1:4: expected '>' for variable decoration");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue