Simplify calls to ast::Node::[to_]str()

Add helpers on Program and ProgramBuilder that significantly simplify
usage.
Also demangle - this also reduces a bunch of copy-pasta code.

Change-Id: I6215c346e7f6e49c20aced058a6150603253ed93
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39342
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-29 11:22:40 +00:00 committed by Commit Bot service account
parent dd1b6fca9f
commit 708dc2d040
69 changed files with 356 additions and 465 deletions

View File

@ -16,7 +16,6 @@
#include <string>
#include <unordered_set>
#include "src/demangler.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/writer/wgsl/generator.h"
@ -62,8 +61,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
tint::Program dst(src.Clone());
// Expect the demangled AST printed with to_str() to match
tint::Demangler d;
ASSERT_EQ(d.Demangle(src), d.Demangle(dst));
ASSERT_EQ(src.to_str(), dst.to_str());
// Check that none of the AST nodes or type pointers in dst are found in src
std::unordered_set<tint::ast::Node*> src_nodes;

View File

@ -499,11 +499,7 @@ int main(int argc, const char** argv) {
}
if (options.dump_ast) {
auto ast_str = program->to_str();
if (options.demangle) {
ast_str = tint::Demangler().Demangle(program->Symbols(), ast_str);
}
std::cout << std::endl << ast_str << std::endl;
std::cout << std::endl << program->to_str(options.demangle) << std::endl;
}
if (options.parse_only) {
return 1;

View File

@ -36,9 +36,7 @@ TEST_F(AccessDecorationTest, Is) {
TEST_F(AccessDecorationTest, ToStr) {
auto* d = create<AccessDecoration>(ast::AccessControl::kReadOnly);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(AccessDecoration{read_only}
EXPECT_EQ(str(d), R"(AccessDecoration{read_only}
)");
}

View File

@ -92,13 +92,10 @@ TEST_F(ArrayAccessorExpressionTest, ToStr) {
auto* idx = Expr("idx");
auto* exp = create<ArrayAccessorExpression>(ary, idx);
std::ostringstream out;
exp->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( ArrayAccessor[not set]{
Identifier[not set]{ary}
Identifier[not set]{idx}
}
EXPECT_EQ(str(exp), R"(ArrayAccessor[not set]{
Identifier[not set]{ary}
Identifier[not set]{idx}
}
)");
}

View File

@ -92,13 +92,10 @@ TEST_F(AssignmentStatementTest, ToStr) {
auto* rhs = Expr("rhs");
auto* stmt = create<AssignmentStatement>(lhs, rhs);
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Assignment{
Identifier[not set]{lhs}
Identifier[not set]{rhs}
}
EXPECT_EQ(str(stmt), R"(Assignment{
Identifier[not set]{lhs}
Identifier[not set]{rhs}
}
)");
}

View File

@ -105,13 +105,11 @@ TEST_F(BinaryExpressionTest, ToStr) {
auto* rhs = Expr("rhs");
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
std::ostringstream out;
r->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Binary[not set]{
Identifier[not set]{lhs}
equal
Identifier[not set]{rhs}
}
EXPECT_EQ(str(r), R"(Binary[not set]{
Identifier[not set]{lhs}
equal
Identifier[not set]{rhs}
}
)");
}

View File

@ -39,9 +39,7 @@ TEST_F(BindingDecorationTest, Is) {
TEST_F(BindingDecorationTest, ToStr) {
auto* d = create<BindingDecoration>(2);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(BindingDecoration{2}
EXPECT_EQ(str(d), R"(BindingDecoration{2}
)");
}

View File

@ -78,12 +78,9 @@ TEST_F(BitcastExpressionTest, ToStr) {
auto* expr = Expr("expr");
auto* exp = create<BitcastExpression>(ty.f32(), expr);
std::ostringstream out;
exp->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Bitcast[not set]<__f32>{
Identifier[not set]{expr}
}
EXPECT_EQ(str(exp), R"(Bitcast[not set]<__f32>{
Identifier[not set]{expr}
}
)");
}

View File

@ -86,11 +86,9 @@ TEST_F(BlockStatementTest, ToStr) {
create<DiscardStatement>(),
});
std::ostringstream out;
b->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Block{
Discard{}
}
EXPECT_EQ(str(b), R"(Block{
Discard{}
}
)");
}

View File

@ -59,8 +59,8 @@ TEST_F(BoolLiteralTest, ToStr) {
auto* t = create<BoolLiteral>(&bool_type, true);
auto* f = create<BoolLiteral>(&bool_type, false);
EXPECT_EQ(t->to_str(Sem()), "true");
EXPECT_EQ(f->to_str(Sem()), "false");
EXPECT_EQ(str(t), "true");
EXPECT_EQ(str(f), "false");
}
} // namespace

View File

@ -41,9 +41,7 @@ TEST_F(BreakStatementTest, IsValid) {
TEST_F(BreakStatementTest, ToStr) {
auto* stmt = create<BreakStatement>();
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Break{}
EXPECT_EQ(str(stmt), R"(Break{}
)");
}

View File

@ -39,9 +39,7 @@ TEST_F(BuiltinDecorationTest, Is) {
TEST_F(BuiltinDecorationTest, ToStr) {
auto* d = create<BuiltinDecoration>(Builtin::kFragDepth);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(BuiltinDecoration{frag_depth}
EXPECT_EQ(str(d), R"(BuiltinDecoration{frag_depth}
)");
}

View File

@ -96,13 +96,11 @@ TEST_F(CallExpressionTest, IsValid_InvalidParam) {
TEST_F(CallExpressionTest, ToStr_NoParams) {
auto* func = Expr("func");
auto* stmt = create<CallExpression>(func, ExpressionList{});
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
Identifier[not set]{func}
(
)
}
EXPECT_EQ(str(stmt), R"(Call[not set]{
Identifier[not set]{func}
(
)
}
)");
}
@ -113,15 +111,13 @@ TEST_F(CallExpressionTest, ToStr_WithParams) {
params.push_back(Expr("param2"));
auto* stmt = create<CallExpression>(func, params);
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
Identifier[not set]{func}
(
Identifier[not set]{param1}
Identifier[not set]{param2}
)
}
EXPECT_EQ(str(stmt), R"(Call[not set]{
Identifier[not set]{func}
(
Identifier[not set]{param1}
Identifier[not set]{param2}
)
}
)");
}

View File

@ -57,13 +57,11 @@ TEST_F(CallStatementTest, ToStr) {
auto* c = create<CallStatement>(
create<CallExpression>(Expr("func"), ExpressionList{}));
std::ostringstream out;
c->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
Identifier[not set]{func}
(
)
}
EXPECT_EQ(str(c), R"(Call[not set]{
Identifier[not set]{func}
(
)
}
)");
}

View File

@ -134,11 +134,9 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
});
auto* c = create<CaseStatement>(CaseSelectorList{b}, body);
std::ostringstream out;
c->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Case -2{
Discard{}
}
EXPECT_EQ(str(c), R"(Case -2{
Discard{}
}
)");
}
@ -151,11 +149,9 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
});
auto* c = create<CaseStatement>(CaseSelectorList{b}, body);
std::ostringstream out;
c->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Case 2{
Discard{}
}
EXPECT_EQ(str(c), R"(Case 2{
Discard{}
}
)");
}
@ -169,11 +165,9 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
});
auto* c = create<CaseStatement>(b, body);
std::ostringstream out;
c->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Case 1, 2{
Discard{}
}
EXPECT_EQ(str(c), R"(Case 1, 2{
Discard{}
}
)");
}
@ -183,11 +177,9 @@ TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
});
auto* c = create<CaseStatement>(CaseSelectorList{}, body);
std::ostringstream out;
c->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Default{
Discard{}
}
EXPECT_EQ(str(c), R"(Default{
Discard{}
}
)");
}

View File

@ -38,9 +38,7 @@ TEST_F(ConstantIdDecorationTest, Is) {
TEST_F(ConstantIdDecorationTest, ToStr) {
auto* d = create<ConstantIdDecoration>(1200);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(ConstantIdDecoration{1200}
EXPECT_EQ(str(d), R"(ConstantIdDecoration{1200}
)");
}

View File

@ -41,9 +41,7 @@ TEST_F(ContinueStatementTest, IsValid) {
TEST_F(ContinueStatementTest, ToStr) {
auto* stmt = create<ContinueStatement>();
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Continue{}
EXPECT_EQ(str(stmt), R"(Continue{}
)");
}

View File

@ -53,9 +53,7 @@ TEST_F(DiscardStatementTest, IsValid) {
TEST_F(DiscardStatementTest, ToStr) {
auto* stmt = create<DiscardStatement>();
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Discard{}
EXPECT_EQ(str(stmt), R"(Discard{}
)");
}

View File

@ -114,16 +114,14 @@ TEST_F(ElseStatementTest, ToStr) {
create<DiscardStatement>(),
});
auto* e = create<ElseStatement>(cond, body);
std::ostringstream out;
e->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Else{
(
ScalarConstructor[not set]{true}
)
{
Discard{}
}
EXPECT_EQ(str(e), R"(Else{
(
ScalarConstructor[not set]{true}
)
{
Discard{}
}
}
)");
}
@ -132,13 +130,11 @@ TEST_F(ElseStatementTest, ToStr_NoCondition) {
create<DiscardStatement>(),
});
auto* e = create<ElseStatement>(nullptr, body);
std::ostringstream out;
e->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Else{
{
Discard{}
}
EXPECT_EQ(str(e), R"(Else{
{
Discard{}
}
}
)");
}

View File

@ -49,9 +49,7 @@ TEST_F(FallthroughStatementTest, IsValid) {
TEST_F(FallthroughStatementTest, ToStr) {
auto* stmt = create<FallthroughStatement>();
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Fallthrough{}
EXPECT_EQ(str(stmt), R"(Fallthrough{}
)");
}

View File

@ -45,8 +45,7 @@ TEST_F(FloatLiteralTest, Is) {
TEST_F(FloatLiteralTest, ToStr) {
auto* f = create<FloatLiteral>(ty.f32(), 42.1f);
EXPECT_EQ(f->to_str(Sem()), "42.099998");
EXPECT_EQ(str(f), "42.099998");
}
TEST_F(FloatLiteralTest, ToName) {

View File

@ -244,13 +244,11 @@ TEST_F(FunctionTest, ToStr) {
},
FunctionDecorationList{});
std::ostringstream out;
f->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Function func -> __void
()
{
Discard{}
}
EXPECT_EQ(str(f), R"(Function func -> __void
()
{
Discard{}
}
)");
}
@ -261,14 +259,12 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
},
FunctionDecorationList{create<WorkgroupDecoration>(2, 4, 6)});
std::ostringstream out;
f->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Function func -> __void
WorkgroupDecoration{2 4 6}
()
{
Discard{}
}
EXPECT_EQ(str(f), R"(Function func -> __void
WorkgroupDecoration{2 4 6}
()
{
Discard{}
}
)");
}
@ -282,19 +278,17 @@ TEST_F(FunctionTest, ToStr_WithParams) {
},
FunctionDecorationList{});
std::ostringstream out;
f->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Function func -> __void
(
Variable{
var
none
__i32
}
)
{
Discard{}
EXPECT_EQ(str(f), R"(Function func -> __void
(
Variable{
var
none
__i32
}
)
{
Discard{}
}
)");
}

View File

@ -39,9 +39,7 @@ TEST_F(GroupDecorationTest, Is) {
TEST_F(GroupDecorationTest, ToStr) {
auto* d = create<GroupDecoration>(2);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(GroupDecoration{2}
EXPECT_EQ(str(d), R"(GroupDecoration{2}
)");
}

View File

@ -48,9 +48,7 @@ TEST_F(IdentifierExpressionTest, IsValid) {
TEST_F(IdentifierExpressionTest, ToStr) {
auto* i = Expr("ident");
std::ostringstream out;
i->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Identifier[not set]{ident}
EXPECT_EQ(str(i), R"(Identifier[not set]{ident}
)");
}

View File

@ -167,16 +167,14 @@ TEST_F(IfStatementTest, ToStr) {
create<BlockStatement>(StatementList{create<DiscardStatement>()});
auto* stmt = create<IfStatement>(cond, body, ElseStatementList{});
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( If{
(
Identifier[not set]{cond}
)
{
Discard{}
}
EXPECT_EQ(str(stmt), R"(If{
(
Identifier[not set]{cond}
)
{
Discard{}
}
}
)");
}
@ -195,30 +193,28 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
create<ElseStatement>(nullptr, else_body),
});
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( If{
(
Identifier[not set]{cond}
)
{
Discard{}
}
EXPECT_EQ(str(stmt), R"(If{
(
Identifier[not set]{cond}
)
{
Discard{}
}
Else{
(
Identifier[not set]{ident}
)
{
Discard{}
}
}
Else{
(
Identifier[not set]{ident}
)
{
Discard{}
}
Else{
{
Discard{}
Discard{}
}
}
Else{
{
Discard{}
Discard{}
}
}
)");
}

View File

@ -41,9 +41,7 @@ TEST_F(LocationDecorationTest, Is) {
TEST_F(LocationDecorationTest, ToStr) {
auto* d = create<LocationDecoration>(2);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(LocationDecoration{2}
EXPECT_EQ(str(d), R"(LocationDecoration{2}
)");
}

View File

@ -170,11 +170,9 @@ TEST_F(LoopStatementTest, ToStr) {
create<BlockStatement>(StatementList{create<DiscardStatement>()});
auto* l = create<LoopStatement>(body, nullptr);
std::ostringstream out;
l->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Loop{
Discard{}
}
EXPECT_EQ(str(l), R"(Loop{
Discard{}
}
)");
}
@ -186,14 +184,12 @@ TEST_F(LoopStatementTest, ToStr_WithContinuing) {
create<BlockStatement>(StatementList{create<DiscardStatement>()});
auto* l = create<LoopStatement>(body, continuing);
std::ostringstream out;
l->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Loop{
EXPECT_EQ(str(l), R"(Loop{
Discard{}
continuing {
Discard{}
continuing {
Discard{}
}
}
}
)");
}

View File

@ -77,12 +77,10 @@ TEST_F(MemberAccessorExpressionTest, IsValid_InvalidMember) {
TEST_F(MemberAccessorExpressionTest, ToStr) {
auto* stmt =
create<MemberAccessorExpression>(Expr("structure"), Expr("member"));
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( MemberAccessor[not set]{
Identifier[not set]{structure}
Identifier[not set]{member}
}
EXPECT_EQ(str(stmt), R"(MemberAccessor[not set]{
Identifier[not set]{structure}
Identifier[not set]{member}
}
)");
}

View File

@ -17,7 +17,6 @@
#include "gtest/gtest.h"
#include "src/ast/case_statement.h"
#include "src/ast/module.h"
#include "src/demangler.h"
#include "src/program.h"
#include "src/program_builder.h"
#include "src/reader/wgsl/parser.h"
@ -121,9 +120,7 @@ fn main() -> void {
Program dst(src.Clone());
// Expect the AST printed with to_str() to match
Demangler demanger;
EXPECT_EQ(demanger.Demangle(src.Symbols(), src.AST().to_str(src.Sem())),
demanger.Demangle(dst.Symbols(), dst.AST().to_str(dst.Sem())));
EXPECT_EQ(src.to_str(), dst.to_str());
// Check that none of the AST nodes or type pointers in dst are found in src
std::unordered_set<ast::Node*> src_nodes;
@ -135,7 +132,7 @@ fn main() -> void {
src_types.emplace(src_type);
}
for (auto* dst_node : dst.Nodes().Objects()) {
ASSERT_EQ(src_nodes.count(dst_node), 0u) << dst_node->str(dst.Sem());
ASSERT_EQ(src_nodes.count(dst_node), 0u) << dst.str(dst_node);
}
for (auto* dst_type : dst.Types()) {
ASSERT_EQ(src_types.count(dst_type), 0u) << dst_type->type_name();

View File

@ -39,8 +39,7 @@ TEST_F(NullLiteralTest, Is) {
TEST_F(NullLiteralTest, ToStr) {
auto* i = create<NullLiteral>(ty.i32());
EXPECT_EQ(i->to_str(Sem()), "null __i32");
EXPECT_EQ(str(i), "null __i32");
}
TEST_F(NullLiteralTest, Name_I32) {

View File

@ -75,21 +75,17 @@ TEST_F(ReturnStatementTest, IsValid_InvalidValue) {
TEST_F(ReturnStatementTest, ToStr_WithValue) {
auto* expr = Expr("expr");
auto* r = create<ReturnStatement>(expr);
std::ostringstream out;
r->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Return{
{
Identifier[not set]{expr}
}
EXPECT_EQ(str(r), R"(Return{
{
Identifier[not set]{expr}
}
}
)");
}
TEST_F(ReturnStatementTest, ToStr_WithoutValue) {
auto* r = create<ReturnStatement>();
std::ostringstream out;
r->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( Return{}
EXPECT_EQ(str(r), R"(Return{}
)");
}

View File

@ -49,9 +49,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
TEST_F(ScalarConstructorExpressionTest, ToStr) {
auto* c = Expr(true);
std::ostringstream out;
c->to_str(Sem(), out, 2);
EXPECT_EQ(out.str(), R"( ScalarConstructor[not set]{true}
EXPECT_EQ(str(c), R"(ScalarConstructor[not set]{true}
)");
}

View File

@ -45,8 +45,7 @@ TEST_F(SintLiteralTest, Is) {
TEST_F(SintLiteralTest, ToStr) {
auto* i = create<SintLiteral>(ty.i32(), -42);
EXPECT_EQ(i->to_str(Sem()), "-42");
EXPECT_EQ(str(i), "-42");
}
TEST_F(SintLiteralTest, Name_I32) {

View File

@ -38,9 +38,7 @@ TEST_F(StageDecorationTest, Is) {
TEST_F(StageDecorationTest, ToStr) {
auto* d = create<StageDecoration>(PipelineStage::kFragment);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(StageDecoration{fragment}
EXPECT_EQ(str(d), R"(StageDecoration{fragment}
)");
}

View File

@ -74,16 +74,12 @@ TEST_F(StructMemberTest, IsValid_Null_Decoration) {
TEST_F(StructMemberTest, ToStr) {
auto* st = Member("a", ty.i32(), {MemberOffset(4)});
std::ostringstream out;
st->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), " StructMember{[[ offset 4 ]] a: __i32}\n");
EXPECT_EQ(str(st), "StructMember{[[ offset 4 ]] a: __i32}\n");
}
TEST_F(StructMemberTest, ToStrNoDecorations) {
auto* st = Member("a", ty.i32());
std::ostringstream out;
st->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), " StructMember{a: __i32}\n");
EXPECT_EQ(str(st), "StructMember{a: __i32}\n");
}
} // namespace

View File

@ -92,12 +92,10 @@ TEST_F(StructTest, ToStr) {
decos.push_back(create<StructBlockDecoration>());
auto* s = create<Struct>(StructMemberList{Member("a", ty.i32())}, decos);
std::ostringstream out;
s->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"(Struct{
[[block]]
StructMember{a: __i32}
}
EXPECT_EQ(str(s), R"(Struct{
[[block]]
StructMember{a: __i32}
}
)");
}

View File

@ -136,13 +136,11 @@ TEST_F(SwitchStatementTest, ToStr_Empty) {
auto* ident = Expr("ident");
auto* stmt = create<SwitchStatement>(ident, CaseStatementList{});
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Switch{
Identifier[not set]{ident}
{
}
EXPECT_EQ(str(stmt), R"(Switch{
Identifier[not set]{ident}
{
}
}
)");
}
@ -156,15 +154,13 @@ TEST_F(SwitchStatementTest, ToStr) {
create<CaseStatement>(lit, create<BlockStatement>(StatementList{})));
auto* stmt = create<SwitchStatement>(ident, body);
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Switch{
Identifier[not set]{ident}
{
Case 2{
}
EXPECT_EQ(str(stmt), R"(Switch{
Identifier[not set]{ident}
{
Case 2{
}
}
}
)");
}

View File

@ -20,7 +20,6 @@
#include <utility>
#include "gtest/gtest.h"
#include "src/demangler.h"
#include "src/program_builder.h"
namespace tint {
@ -28,18 +27,7 @@ namespace ast {
/// Helper class for testing
template <typename BASE>
class TestHelperBase : public BASE, public ProgramBuilder {
public:
/// Demangles the given string
/// @param s the string to demangle
/// @returns the demangled string
std::string demangle(const std::string& s) {
return demanger.Demangle(Symbols(), s);
}
/// A demangler
Demangler demanger;
};
class TestHelperBase : public BASE, public ProgramBuilder {};
using TestHelper = TestHelperBase<testing::Test>;
template <typename T>

View File

@ -106,14 +106,12 @@ TEST_F(TypeConstructorExpressionTest, ToStr) {
expr.push_back(Expr("expr_3"));
auto* t = create<TypeConstructorExpression>(&vec, expr);
std::ostringstream out;
t->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( TypeConstructor[not set]{
__vec_3__f32
Identifier[not set]{expr_1}
Identifier[not set]{expr_2}
Identifier[not set]{expr_3}
}
EXPECT_EQ(str(t), R"(TypeConstructor[not set]{
__vec_3__f32
Identifier[not set]{expr_1}
Identifier[not set]{expr_2}
Identifier[not set]{expr_3}
}
)");
}

View File

@ -44,7 +44,7 @@ TEST_F(UintLiteralTest, Is) {
TEST_F(UintLiteralTest, ToStr) {
auto* u = create<UintLiteral>(ty.u32(), 42);
EXPECT_EQ(u->to_str(Sem()), "42");
EXPECT_EQ(str(u), "42");
}
} // namespace

View File

@ -68,12 +68,10 @@ TEST_F(UnaryOpExpressionTest, IsValid_InvalidExpression) {
TEST_F(UnaryOpExpressionTest, ToStr) {
auto* ident = Expr("ident");
auto* u = create<UnaryOpExpression>(UnaryOp::kNot, ident);
std::ostringstream out;
u->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( UnaryOp[not set]{
not
Identifier[not set]{ident}
}
EXPECT_EQ(str(u), R"(UnaryOp[not set]{
not
Identifier[not set]{ident}
}
)");
}

View File

@ -70,15 +70,13 @@ TEST_F(VariableDeclStatementTest, ToStr) {
auto* stmt =
create<VariableDeclStatement>(Source{Source::Location{20, 2}}, var);
std::ostringstream out;
stmt->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( VariableDeclStatement{
Variable{
a
none
__f32
}
EXPECT_EQ(str(stmt), R"(VariableDeclStatement{
Variable{
a
none
__f32
}
}
)");
}

View File

@ -102,13 +102,11 @@ TEST_F(VariableTest, IsValid_InvalidConstructor) {
TEST_F(VariableTest, to_str) {
auto* v = Var("my_var", StorageClass::kFunction, ty.f32(), nullptr,
ast::VariableDecorationList{});
std::ostringstream out;
v->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Variable{
my_var
function
__f32
}
EXPECT_EQ(str(v), R"(Variable{
my_var
function
__f32
}
)");
}
@ -145,20 +143,18 @@ TEST_F(VariableTest, Decorated_to_str) {
create<GroupDecoration>(1),
});
std::ostringstream out;
var->to_str(Sem(), out, 2);
EXPECT_EQ(demangle(out.str()), R"( Variable{
Decorations{
BindingDecoration{2}
GroupDecoration{1}
}
my_var
function
__f32
{
Identifier[not set]{expr}
}
EXPECT_EQ(str(var), R"(Variable{
Decorations{
BindingDecoration{2}
GroupDecoration{1}
}
my_var
function
__f32
{
Identifier[not set]{expr}
}
}
)");
}

View File

@ -65,9 +65,7 @@ TEST_F(WorkgroupDecorationTest, Is) {
TEST_F(WorkgroupDecorationTest, ToStr) {
auto* d = create<WorkgroupDecoration>(2, 4, 6);
std::ostringstream out;
d->to_str(Sem(), out, 0);
EXPECT_EQ(out.str(), R"(WorkgroupDecoration{2 4 6}
EXPECT_EQ(str(d), R"(WorkgroupDecoration{2 4 6}
)");
}

View File

@ -58,8 +58,4 @@ std::string Demangler::Demangle(const SymbolTable& symbols,
return ret;
}
std::string Demangler::Demangle(const Program& program) const {
return Demangle(program.Symbols(), program.AST().to_str(program.Sem()));
}
} // namespace tint

View File

@ -19,7 +19,6 @@
namespace tint {
class Program;
class SymbolTable;
/// Helper to demangle strings and replace symbols with original names
@ -36,12 +35,6 @@ class Demangler {
/// @returns the string with any symbol replacements performed.
std::string Demangle(const SymbolTable& symbols,
const std::string& str) const;
/// Returns the string returned by the `program.AST().to_str()` of the
/// program with all symbols replaced with their original names.
/// @param program the program where the symbols are registered
/// @returns the string with any symbol replacements performed.
std::string Demangle(const Program& program) const;
};
} // namespace tint

View File

@ -19,6 +19,7 @@
#include "src/ast/module.h"
#include "src/clone_context.h"
#include "src/demangler.h"
#include "src/program_builder.h"
#include "src/type_determiner.h"
@ -98,9 +99,17 @@ bool Program::IsValid() const {
return is_valid_;
}
std::string Program::to_str() const {
std::string Program::to_str(bool demangle) const {
AssertNotMoved();
return ast_->to_str(Sem());
auto str = ast_->to_str(Sem());
if (demangle) {
str = Demangler().Demangle(Symbols(), str);
}
return str;
}
std::string Program::str(const ast::Node* node) const {
return Demangler().Demangle(Symbols(), node->str(Sem()));
}
void Program::AssertNotMoved() const {

View File

@ -105,8 +105,27 @@ class Program {
/// information
bool IsValid() const;
/// @param demangle whether to automatically demangle the symbols in the
/// returned string
/// @returns a string describing this program.
std::string to_str() const;
std::string to_str(bool demangle) const;
/// @returns a demangled string describing this program.
std::string to_str() const { return to_str(true); }
/// Writes a representation of the node to the output stream
/// @note unlike str(), to_str() does not automatically demangle the string.
/// @param node the AST node
/// @param out the stream to write to
/// @param indent number of spaces to indent the node when writing
void to_str(const ast::Node* node, std::ostream& out, size_t indent) const {
node->to_str(Sem(), out, indent);
}
/// Returns a demangled, string representation of `node`.
/// @param node the AST node
/// @returns a string representation of the node
std::string str(const ast::Node* node) const;
private:
Program(const Program&) = delete;

View File

@ -19,6 +19,7 @@
#include <sstream>
#include "src/clone_context.h"
#include "src/demangler.h"
#include "src/type/struct_type.h"
namespace tint {
@ -54,6 +55,10 @@ bool ProgramBuilder::IsValid() const {
return !diagnostics_.contains_errors() && ast_->IsValid();
}
std::string ProgramBuilder::str(const ast::Node* node) const {
return Demangler().Demangle(Symbols(), node->str(Sem()));
}
void ProgramBuilder::MarkAsMoved() {
AssertNotMoved();
moved_ = true;

View File

@ -150,6 +150,12 @@ class ProgramBuilder {
return symbols_;
}
/// @returns a reference to the program's SymbolTable
const SymbolTable& Symbols() const {
AssertNotMoved();
return symbols_;
}
/// @returns a reference to the program's diagnostics
diag::List& Diagnostics() {
AssertNotMoved();
@ -175,6 +181,20 @@ class ProgramBuilder {
/// information
bool IsValid() const;
/// Writes a representation of the node to the output stream
/// @note unlike str(), to_str() does not automatically demangle the string.
/// @param node the AST node
/// @param out the stream to write to
/// @param indent number of spaces to indent the node when writing
void to_str(const ast::Node* node, std::ostream& out, size_t indent) const {
node->to_str(Sem(), out, indent);
}
/// Returns a demangled, string representation of `node`.
/// @param node the AST node
/// @returns a string representation of the node
std::string str(const ast::Node* node) const;
/// creates a new ast::Node owned by the Module. When the Module is
/// destructed, the ast::Node will also be destructed.
/// @param source the Source of the node

View File

@ -46,7 +46,7 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
const auto got = p->program().to_str();
const auto got = p->program().to_str(false);
const char* expect = R"(Module{
Function tint_symbol_1 -> __void
()
@ -217,7 +217,7 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto program_ast_str = Demangler().Demangle(p->program());
const auto program_ast_str = p->program().to_str();
EXPECT_THAT(program_ast_str, HasSubstr(R"(Module{
Function x_50 -> __u32
(

View File

@ -59,7 +59,7 @@ TEST_F(SpvParserTest, Emit_VoidFunctionWithoutParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->program());
auto got = p->program().to_str();
std::string expect = R"(Module{
Function x_100 -> __void
()
@ -83,7 +83,7 @@ TEST_F(SpvParserTest, Emit_NonVoidResultType) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->program());
auto got = p->program().to_str();
std::string expect = R"(Module{
Function x_100 -> __f32
()
@ -115,7 +115,7 @@ TEST_F(SpvParserTest, Emit_MixedParamTypes) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->program());
auto got = p->program().to_str();
std::string expect = R"(Module{
Function x_100 -> __void
(
@ -159,7 +159,7 @@ TEST_F(SpvParserTest, Emit_GenerateParamNames) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.Emit());
auto got = Demangler().Demangle(p->program());
auto got = p->program().to_str();
std::string expect = R"(Module{
Function x_100 -> __void
(

View File

@ -800,7 +800,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions())
<< assembly << p->error();
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
RTArr -> __array__u32_stride_4
S Struct{

View File

@ -328,14 +328,12 @@ TEST_P(SpvParserSwizzleTest, Sample) {
Program program(p->program());
EXPECT_TRUE(fe.success());
ASSERT_NE(result, nullptr);
std::ostringstream ss;
result->to_str(program.Sem(), ss, 0);
auto str = Demangler().Demangle(program.Symbols(), ss.str());
EXPECT_THAT(str, Eq(GetParam().expected_expr));
auto got = program.str(result);
EXPECT_EQ(got, GetParam().expected_expr);
} else {
EXPECT_EQ(result, nullptr);
EXPECT_FALSE(fe.success());
EXPECT_THAT(p->error(), Eq(GetParam().expected_error));
EXPECT_EQ(p->error(), GetParam().expected_error);
}
}

View File

@ -1504,8 +1504,8 @@ TypedExpression ParserImpl::RectifyOperandSignedness(
}
auto* type = expr.type;
if (!type) {
Fail() << "internal error: unmapped type for: "
<< expr.expr->str(builder_.Sem()) << "\n";
Fail() << "internal error: unmapped type for: " << builder_.str(expr.expr)
<< "\n";
return {};
}
if (requires_unsigned) {

View File

@ -566,10 +566,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
EXPECT_TRUE(type->Is<type::Struct>());
Program program = p->program();
std::stringstream ss;
type->As<type::Struct>()->impl()->to_str(program.Sem(), ss, 0);
EXPECT_THAT(Demangler().Demangle(program.Symbols(), ss.str()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
StructMember{field0: __u32}
StructMember{field1: __f32}
}
@ -590,10 +587,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
EXPECT_TRUE(type->Is<type::Struct>());
Program program = p->program();
std::stringstream ss;
type->As<type::Struct>()->impl()->to_str(program.Sem(), ss, 0);
EXPECT_THAT(Demangler().Demangle(program.Symbols(), ss.str()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
[[block]]
StructMember{field0: __u32}
}
@ -618,10 +612,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
EXPECT_TRUE(type->Is<type::Struct>());
Program program = p->program();
std::stringstream ss;
type->As<type::Struct>()->impl()->to_str(program.Sem(), ss, 0);
EXPECT_THAT(Demangler().Demangle(program.Symbols(), ss.str()), Eq(R"(Struct{
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
StructMember{[[ offset 0 ]] field0: __f32}
StructMember{[[ offset 8 ]] field1: __vec_2__f32}
StructMember{[[ offset 16 ]] field2: __mat_2_2__f32}

View File

@ -55,7 +55,7 @@ TEST_F(SpvParserTest, EmitFunctions_NoFunctions) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
Program program = p->program();
const auto program_ast = program.to_str();
const auto program_ast = program.to_str(false);
EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
}
@ -67,7 +67,7 @@ TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
Program program = p->program();
const auto program_ast = program.to_str();
const auto program_ast = program.to_str(false);
EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
}
@ -83,7 +83,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program();
const auto program_ast = program.to_str();
const auto program_ast = program.to_str(false);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
@ -104,7 +104,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program();
const auto program_ast = program.to_str();
const auto program_ast = program.to_str(false);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
@ -125,7 +125,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program();
const auto program_ast = program.to_str();
const auto program_ast = program.to_str(false);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
@ -148,7 +148,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program();
const auto program_ast = program.to_str();
const auto program_ast = program.to_str(false);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("frag_main").to_str() +
R"( -> __void
@ -173,7 +173,7 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
Program program = p->program();
const auto program_ast = program.to_str();
const auto program_ast = program.to_str(false);
EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void
@ -208,7 +208,7 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function leaf -> __u32
()
@ -276,7 +276,7 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function ret_float -> __f32
()
@ -306,7 +306,7 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function mixed_params -> __void
(
@ -346,7 +346,7 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
Program program = p->program();
const auto program_ast = Demangler().Demangle(program);
const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"(
Function mixed_params -> __void
(

View File

@ -1129,7 +1129,7 @@ TEST_P(SpvParserTest_DeclUnderspecifiedHandle, Variable) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error();
const auto program = Demangler().Demangle(p->program());
const auto program = p->program().to_str();
EXPECT_THAT(program, HasSubstr(GetParam().var_decl)) << program;
}
@ -1305,7 +1305,7 @@ TEST_P(SpvParserTest_SampledImageAccessTest, Variable) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error();
const auto program = Demangler().Demangle(p->program());
const auto program = p->program().to_str();
EXPECT_THAT(program, HasSubstr(GetParam().var_decl))
<< "DECLARATIONS ARE BAD " << program;
EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin))
@ -2554,7 +2554,7 @@ TEST_P(SpvParserTest_ImageAccessTest, Variable) {
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error();
const auto program = Demangler().Demangle(p->program());
const auto program = p->program().to_str();
EXPECT_THAT(program, HasSubstr(GetParam().var_decl))
<< "DECLARATIONS ARE BAD " << program;
EXPECT_THAT(program, HasSubstr(GetParam().texture_builtin))
@ -3787,8 +3787,7 @@ TEST_P(SpvParserTest_ImageCoordsTest, MakeCoordinateOperandsForImageAccess) {
Program program = p->program();
for (auto* expr : result) {
ASSERT_NE(expr, nullptr);
result_strings.push_back(
Demangler().Demangle(program.Symbols(), expr->str(program.Sem())));
result_strings.push_back(program.str(expr));
}
EXPECT_THAT(result_strings,
::testing::ContainerEq(GetParam().expected_expressions));

View File

@ -144,7 +144,7 @@ TEST_F(SpvModuleScopeVarParserTest, AnonWorkgroupVar) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
x_52
@ -163,7 +163,7 @@ TEST_F(SpvModuleScopeVarParserTest, NamedWorkgroupVar) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
the_counter
@ -182,7 +182,7 @@ TEST_F(SpvModuleScopeVarParserTest, PrivateVar) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
my_own_private_idaho
@ -201,7 +201,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinVertexIndex) {
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -251,7 +251,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_MapsToModuleScopeVec4Var) {
EXPECT_EQ(position_info.pointer_type_id, 11u);
EXPECT_EQ(position_info.storage_class, SpvStorageClassOutput);
EXPECT_EQ(position_info.per_vertex_var_id, 1u);
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -331,7 +331,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_StorePosition) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{
Identifier[not set]{gl_Position}
@ -384,7 +384,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{
Identifier[not set]{gl_Position}
@ -415,7 +415,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{
MemberAccessor[not set]{
@ -446,7 +446,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
{
Assignment{
@ -476,7 +476,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Write1_IsErased) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_EQ(module_str, R"(Module{
Variable{
Decorations{
@ -532,7 +532,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_ReadReplaced) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_EQ(module_str, R"(Module{
Variable{
x_900
@ -599,7 +599,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_EQ(module_str, R"(Module{
Variable{
Decorations{
@ -650,7 +650,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Loose_Write1_IsErased) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_EQ(module_str, R"(Module{
Function x_500 -> __void
()
@ -694,7 +694,7 @@ TEST_F(SpvModuleScopeVarParserTest, BuiltinPointSize_Loose_ReadReplaced) {
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_EQ(module_str, R"(Module{
Variable{
x_900
@ -730,7 +730,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_EQ(module_str, R"(Module{
Function x_500 -> __void
()
@ -757,7 +757,7 @@ TEST_F(SpvModuleScopeVarParserTest,
auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty()) << p->error();
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_EQ(module_str, R"(Module{
Function x_500 -> __void
()
@ -861,7 +861,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarInitializers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_1
private
@ -918,7 +918,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarNullInitializers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_1
private
@ -967,7 +967,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarUndefInitializers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_1
private
@ -1011,7 +1011,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1034,7 +1034,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1057,7 +1057,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorBoolUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1080,7 +1080,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1103,7 +1103,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorUintUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1126,7 +1126,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1149,7 +1149,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorIntUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1172,7 +1172,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1195,7 +1195,7 @@ TEST_F(SpvModuleScopeVarParserTest, VectorFloatUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1224,7 +1224,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1260,7 +1260,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1296,7 +1296,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1333,7 +1333,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1356,7 +1356,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1379,7 +1379,7 @@ TEST_F(SpvModuleScopeVarParserTest, ArrayUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1404,7 +1404,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1433,7 +1433,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructNullInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1462,7 +1462,7 @@ TEST_F(SpvModuleScopeVarParserTest, StructUndefInitializer) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(Variable{
x_200
private
@ -1493,7 +1493,7 @@ TEST_F(SpvModuleScopeVarParserTest, LocationDecoration_Valid) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -1545,7 +1545,7 @@ TEST_F(SpvModuleScopeVarParserTest, DescriptorGroupDecoration_Valid) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -1599,7 +1599,7 @@ TEST_F(SpvModuleScopeVarParserTest, BindingDecoration_Valid) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
Decorations{
@ -1653,7 +1653,7 @@ TEST_F(SpvModuleScopeVarParserTest,
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1684,7 +1684,7 @@ TEST_F(SpvModuleScopeVarParserTest, ColMajorDecoration_Dropped) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1713,7 +1713,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration_Dropped) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1762,7 +1762,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_AllMembers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1791,7 +1791,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_NotAllMembers) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1823,7 +1823,7 @@ TEST_F(
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
S Struct{
[[block]]
@ -1847,7 +1847,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_True) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1872,7 +1872,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_False) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1897,7 +1897,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_U32) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1922,7 +1922,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_I32) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1947,7 +1947,7 @@ TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_F32) {
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
Decorations{
@ -1973,7 +1973,7 @@ TEST_F(SpvModuleScopeVarParserTest,
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
EXPECT_TRUE(p->error().empty());
const auto module_str = Demangler().Demangle(p->program());
const auto module_str = p->program().to_str();
EXPECT_THAT(module_str, HasSubstr(R"(
VariableConst{
myconst

View File

@ -41,7 +41,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonStruct) {
%s = OpTypeStruct %uint %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->program()), HasSubstr("S Struct"));
EXPECT_THAT(p->program().to_str(), HasSubstr("S Struct"));
}
TEST_F(SpvParserTest, NamedTypes_NamedStruct) {
@ -51,7 +51,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedStruct) {
%s = OpTypeStruct %uint %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->program()), HasSubstr("mystruct Struct"));
EXPECT_THAT(p->program().to_str(), HasSubstr("mystruct Struct"));
}
TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) {
@ -61,7 +61,7 @@ TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) {
%s2 = OpTypeStruct %uint %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_THAT(Demangler().Demangle(p->program()), HasSubstr(R"(S Struct{
EXPECT_THAT(p->program().to_str(), HasSubstr(R"(S Struct{
StructMember{field0: __u32}
StructMember{field1: __u32}
}
@ -82,7 +82,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArrayWithDecoration) {
%arr = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->program()),
EXPECT_THAT(p->program().to_str(),
HasSubstr("RTArr -> __array__u32_stride_8\n"));
}
@ -95,7 +95,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArray_Dup_EmitBoth) {
%arr2 = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->program()),
EXPECT_THAT(p->program().to_str(),
HasSubstr("RTArr -> __array__u32_stride_8\n RTArr_1 -> "
"__array__u32_stride_8\n"));
}
@ -108,7 +108,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedRTArray) {
%arr = OpTypeRuntimeArray %uint
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->program()),
EXPECT_THAT(p->program().to_str(),
HasSubstr("myrtarr -> __array__u32_stride_8\n"));
}
@ -122,7 +122,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedArray) {
%arr2 = OpTypeArray %uint %uint_5
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->program()),
EXPECT_THAT(p->program().to_str(),
HasSubstr("myarr -> __array__u32_5_stride_8"));
}
@ -136,7 +136,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonArray_Dup_EmitBoth) {
%arr2 = OpTypeArray %uint %uint_5
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_THAT(Demangler().Demangle(p->program()),
EXPECT_THAT(p->program().to_str(),
HasSubstr("Arr -> __array__u32_5_stride_8\n Arr_1 -> "
"__array__u32_5_stride_8"));
}

View File

@ -69,7 +69,7 @@ inline std::string ToString(const Program& program,
const ast::StatementList& stmts) {
std::ostringstream outs;
for (const auto* stmt : stmts) {
stmt->to_str(program.Sem(), outs, 0);
program.to_str(stmt, outs, 0);
}
return Demangler().Demangle(program.Symbols(), outs.str());
}
@ -82,7 +82,7 @@ inline std::string ToString(ProgramBuilder& builder,
const ast::StatementList& stmts) {
std::ostringstream outs;
for (const auto* stmt : stmts) {
stmt->to_str(builder.Sem(), outs, 0);
builder.to_str(stmt, outs, 0);
}
return Demangler().Demangle(builder.Symbols(), outs.str());
}

View File

@ -20,7 +20,6 @@
#include <utility>
#include "gtest/gtest.h"
#include "src/demangler.h"
#include "src/program_builder.h"
namespace tint {
@ -28,18 +27,7 @@ namespace type {
/// Helper class for testing
template <typename BASE>
class TestHelperBase : public BASE, public ProgramBuilder {
public:
/// Demangles the given string
/// @param s the string to demangle
/// @returns the demangled string
std::string demangle(const std::string& s) {
return demanger.Demangle(this, s);
}
/// A demangler
Demangler demanger;
};
class TestHelperBase : public BASE, public ProgramBuilder {};
using TestHelper = TestHelperBase<testing::Test>;
template <typename T>

View File

@ -289,7 +289,7 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
}
set_error(stmt->source(), "unknown statement type for type determination: " +
stmt->str(builder_->Sem()));
builder_->str(stmt));
return false;
}

View File

@ -3175,7 +3175,7 @@ TEST_P(TypeDeterminerTextureIntrinsicTest, Call) {
ident->intrinsic_signature());
ASSERT_NE(sig, nullptr);
auto got = to_str(param.function, sig);
auto got = ::tint::to_str(param.function, sig);
auto* expected = expected_texture_overload(param.overload);
EXPECT_EQ(got, expected);
}

View File

@ -360,14 +360,10 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) {
? selector->As<ast::UintLiteral>()->value()
: selector->As<ast::SintLiteral>()->value());
if (selector_set.count(v)) {
auto v_str =
selector->type()->Is<type::U32>()
? selector->As<ast::UintLiteral>()->to_str(program_->Sem())
: selector->As<ast::SintLiteral>()->to_str(program_->Sem());
add_error(case_stmt->source(), "v-0027",
"a literal value must not appear more than once in "
"the case selectors for a switch statement: '" +
v_str + "'");
program_->str(selector) + "'");
return false;
}
selector_set.emplace(v);

View File

@ -1141,7 +1141,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& pre,
return EmitUnaryOp(pre, out, u);
}
error_ = "unknown expression type: " + expr->str(program_->Sem());
error_ = "unknown expression type: " + program_->str(expr);
return false;
}
@ -2179,7 +2179,7 @@ bool GeneratorImpl::EmitStatement(std::ostream& out, ast::Statement* stmt) {
return EmitVariable(out, v->variable(), false);
}
error_ = "unknown statement type: " + stmt->str(program_->Sem());
error_ = "unknown statement type: " + program_->str(stmt);
return false;
}

View File

@ -1177,7 +1177,7 @@ bool GeneratorImpl::EmitExpression(ast::Expression* expr) {
return EmitUnaryOp(u);
}
error_ = "unknown expression type: " + expr->str(program_->Sem());
error_ = "unknown expression type: " + program_->str(expr);
return false;
}
@ -1844,7 +1844,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
return EmitVariable(v->variable(), false);
}
error_ = "unknown statement type: " + stmt->str(program_->Sem());
error_ = "unknown statement type: " + program_->str(stmt);
return false;
}
@ -2032,7 +2032,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) {
}
current_offset = offset;
} else {
error_ = "unsupported member decoration: " + deco->str(program_->Sem());
error_ = "unsupported member decoration: " + program_->str(deco);
return false;
}
}

View File

@ -533,7 +533,7 @@ uint32_t Builder::GenerateExpression(ast::Expression* expr) {
return GenerateUnaryOpExpression(u);
}
error_ = "unknown expression type: " + expr->str(program_->Sem());
error_ = "unknown expression type: " + program_->str(expr);
return 0;
}
@ -1091,7 +1091,7 @@ uint32_t Builder::GenerateAccessorExpression(ast::Expression* expr) {
}
} else {
error_ = "invalid accessor in list: " + accessor->str(program_->Sem());
error_ = "invalid accessor in list: " + program_->str(accessor);
return 0;
}
}
@ -2763,7 +2763,7 @@ bool Builder::GenerateStatement(ast::Statement* stmt) {
return GenerateVariableDeclStatement(v);
}
error_ = "Unknown statement: " + stmt->str(program_->Sem());
error_ = "Unknown statement: " + program_->str(stmt);
return false;
}

View File

@ -550,7 +550,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) {
auto* impl = str->impl();
for (auto* deco : impl->decorations()) {
out_ << "[[";
deco->to_str(program_->Sem(), out_, 0);
program_->to_str(deco, out_, 0);
out_ << "]]" << std::endl;
}
out_ << "struct " << program_->Symbols().NameFor(str->symbol()) << " {"
@ -817,7 +817,7 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
return EmitVariable(v->variable());
}
error_ = "unknown statement type: " + stmt->str(program_->Sem());
error_ = "unknown statement type: " + program_->str(stmt);
return false;
}