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 <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2023-02-28 18:47:20 +00:00 committed by Dawn LUCI CQ
parent 0c184c2856
commit 0723a3c7f8
3 changed files with 11 additions and 7 deletions

View File

@ -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 {

View File

@ -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<i32> = vec2<i32>(!);
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";

View File

@ -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<Case> Cases() {
using ParserImplMixedBinaryOpTest = ParserImplTestWithParam<Case>;
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());