From 0723a3c7f8f193db9e557edae9833f86c226539e Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 28 Feb 2023 18:47:20 +0000 Subject: [PATCH] Convert WGSL reader to utils::StringStream. This CL updates the WGSL reader to use utils::StringStream internally. Bug: tint:1686 Change-Id: I203c764bbb86e99da323fde2be2af555f158b7bf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122001 Reviewed-by: Ben Clayton Commit-Queue: Dan Sinclair Kokoro: Kokoro --- src/tint/reader/wgsl/parser_impl.cc | 4 ++-- src/tint/reader/wgsl/parser_impl_error_msg_test.cc | 8 +++++--- src/tint/reader/wgsl/parser_impl_expression_test.cc | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 1d8182189d..e4eab291af 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -214,7 +214,7 @@ ParserImpl::~ParserImpl() = default; ParserImpl::Failure::Errored ParserImpl::add_error(const Source& source, std::string_view err, std::string_view use) { - std::stringstream msg; + utils::StringStream msg; msg << err; if (!use.empty()) { msg << " for " << use; @@ -3165,7 +3165,7 @@ bool ParserImpl::expect(std::string_view use, Token::Type tok) { return false; } - std::stringstream err; + utils::StringStream err; if (tok == Token::Type::kTemplateArgsLeft && t.type() == Token::Type::kLessThan) { err << "missing closing '>'"; } else { diff --git a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc index 85e55cb518..af5089492e 100644 --- a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc +++ b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc @@ -14,6 +14,8 @@ #include "src/tint/reader/wgsl/parser_impl_test_helper.h" +#include "src/tint/utils/string_stream.h" + namespace tint::reader::wgsl { namespace { @@ -513,8 +515,8 @@ const i : vec2 = vec2(!); TEST_F(ParserImplErrorTest, GlobalDeclConstExprMaxDepth) { uint32_t kMaxDepth = 128; - std::stringstream src; - std::stringstream mkr; + utils::StringStream src; + utils::StringStream mkr; src << "const i : i32 = "; mkr << " "; for (size_t i = 0; i < kMaxDepth + 8; i++) { @@ -530,7 +532,7 @@ TEST_F(ParserImplErrorTest, GlobalDeclConstExprMaxDepth) { src << ")"; } src << ";"; - std::stringstream err; + utils::StringStream err; err << "test.wgsl:1:529 error: maximum parser recursive depth reached\n" << src.str() << "\n" << mkr.str() << "\n"; diff --git a/src/tint/reader/wgsl/parser_impl_expression_test.cc b/src/tint/reader/wgsl/parser_impl_expression_test.cc index 0de3dea890..9a6c9179b3 100644 --- a/src/tint/reader/wgsl/parser_impl_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_expression_test.cc @@ -14,6 +14,8 @@ #include "src/tint/reader/wgsl/parser_impl_test_helper.h" +#include "src/tint/utils/string_stream.h" + namespace tint::reader::wgsl { namespace { @@ -486,7 +488,7 @@ static std::vector Cases() { using ParserImplMixedBinaryOpTest = ParserImplTestWithParam; TEST_P(ParserImplMixedBinaryOpTest, Test) { - std::stringstream wgsl; + utils::StringStream wgsl; wgsl << GetParam(); auto p = parser(wgsl.str()); auto e = p->expression(); @@ -498,7 +500,7 @@ TEST_P(ParserImplMixedBinaryOpTest, Test) { EXPECT_TRUE(e.errored); EXPECT_EQ(e.value, nullptr); EXPECT_TRUE(p->has_error()); - std::stringstream expected; + utils::StringStream expected; expected << "1:3: mixing '" << GetParam().lhs_op.symbol << "' and '" << GetParam().rhs_op.symbol << "' requires parenthesis"; EXPECT_EQ(p->error(), expected.str());