tint/reader/wgsl: Add source info to compound statements
Change-Id: I251dd3d061a32042368b170ba2a38d16e8b2d9dc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118320 Commit-Queue: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
0eea3c5114
commit
f6a48ee351
|
@ -1679,14 +1679,16 @@ Expect<ast::BlockStatement*> ParserImpl::expect_compound_statement(std::string_v
|
|||
// : attribute* BRACE_LEFT statement* BRACE_RIGHT
|
||||
Expect<ast::BlockStatement*> ParserImpl::expect_compound_statement(AttributeList& attrs,
|
||||
std::string_view use) {
|
||||
return expect_brace_block(use, [&]() -> Expect<ast::BlockStatement*> {
|
||||
auto stmts = expect_statements();
|
||||
auto source_start = peek().source();
|
||||
auto stmts =
|
||||
expect_brace_block(use, [&]() -> Expect<StatementList> { return expect_statements(); });
|
||||
auto source_end = last_source();
|
||||
if (stmts.errored) {
|
||||
return Failure::kErrored;
|
||||
}
|
||||
TINT_DEFER(attrs.Clear());
|
||||
return create<ast::BlockStatement>(Source{}, stmts.value, std::move(attrs));
|
||||
});
|
||||
return create<ast::BlockStatement>(Source::Combine(source_start, source_end), stmts.value,
|
||||
std::move(attrs));
|
||||
}
|
||||
|
||||
// paren_expression
|
||||
|
|
|
@ -24,6 +24,12 @@ TEST_F(ParserImplTest, CompoundStmt) {
|
|||
return 1 + b / 2;
|
||||
})");
|
||||
auto e = p->expect_compound_statement("");
|
||||
|
||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
||||
EXPECT_EQ(e->source.range.begin.column, 1u);
|
||||
EXPECT_EQ(e->source.range.end.line, 4u);
|
||||
EXPECT_EQ(e->source.range.end.column, 2u);
|
||||
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_FALSE(e.errored);
|
||||
ASSERT_EQ(e->statements.Length(), 2u);
|
||||
|
@ -34,6 +40,12 @@ TEST_F(ParserImplTest, CompoundStmt) {
|
|||
TEST_F(ParserImplTest, CompoundStmt_Empty) {
|
||||
auto p = parser("{}");
|
||||
auto e = p->expect_compound_statement("");
|
||||
|
||||
EXPECT_EQ(e->source.range.begin.line, 1u);
|
||||
EXPECT_EQ(e->source.range.begin.column, 1u);
|
||||
EXPECT_EQ(e->source.range.end.line, 1u);
|
||||
EXPECT_EQ(e->source.range.end.column, 3u);
|
||||
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
ASSERT_FALSE(e.errored);
|
||||
EXPECT_EQ(e->statements.Length(), 0u);
|
||||
|
|
Loading…
Reference in New Issue