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 <string>
#include <unordered_set> #include <unordered_set>
#include "src/demangler.h"
#include "src/reader/wgsl/parser_impl.h" #include "src/reader/wgsl/parser_impl.h"
#include "src/writer/wgsl/generator.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()); tint::Program dst(src.Clone());
// Expect the demangled AST printed with to_str() to match // Expect the demangled AST printed with to_str() to match
tint::Demangler d; ASSERT_EQ(src.to_str(), dst.to_str());
ASSERT_EQ(d.Demangle(src), d.Demangle(dst));
// Check that none of the AST nodes or type pointers in dst are found in src // Check that none of the AST nodes or type pointers in dst are found in src
std::unordered_set<tint::ast::Node*> src_nodes; 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) { if (options.dump_ast) {
auto ast_str = program->to_str(); std::cout << std::endl << program->to_str(options.demangle) << std::endl;
if (options.demangle) {
ast_str = tint::Demangler().Demangle(program->Symbols(), ast_str);
}
std::cout << std::endl << ast_str << std::endl;
} }
if (options.parse_only) { if (options.parse_only) {
return 1; return 1;

View File

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

View File

@ -92,13 +92,10 @@ TEST_F(ArrayAccessorExpressionTest, ToStr) {
auto* idx = Expr("idx"); auto* idx = Expr("idx");
auto* exp = create<ArrayAccessorExpression>(ary, idx); auto* exp = create<ArrayAccessorExpression>(ary, idx);
std::ostringstream out; EXPECT_EQ(str(exp), R"(ArrayAccessor[not set]{
exp->to_str(Sem(), out, 2); Identifier[not set]{ary}
Identifier[not set]{idx}
EXPECT_EQ(demangle(out.str()), 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* rhs = Expr("rhs");
auto* stmt = create<AssignmentStatement>(lhs, rhs); auto* stmt = create<AssignmentStatement>(lhs, rhs);
std::ostringstream out; EXPECT_EQ(str(stmt), R"(Assignment{
stmt->to_str(Sem(), out, 2); Identifier[not set]{lhs}
Identifier[not set]{rhs}
EXPECT_EQ(demangle(out.str()), 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* rhs = Expr("rhs");
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs); auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
std::ostringstream out; EXPECT_EQ(str(r), R"(Binary[not set]{
r->to_str(Sem(), out, 2); Identifier[not set]{lhs}
EXPECT_EQ(demangle(out.str()), R"( Binary[not set]{ equal
Identifier[not set]{lhs} Identifier[not set]{rhs}
equal }
Identifier[not set]{rhs}
}
)"); )");
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -57,13 +57,11 @@ TEST_F(CallStatementTest, ToStr) {
auto* c = create<CallStatement>( auto* c = create<CallStatement>(
create<CallExpression>(Expr("func"), ExpressionList{})); create<CallExpression>(Expr("func"), ExpressionList{}));
std::ostringstream out; EXPECT_EQ(str(c), R"(Call[not set]{
c->to_str(Sem(), out, 2); Identifier[not set]{func}
EXPECT_EQ(demangle(out.str()), 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); auto* c = create<CaseStatement>(CaseSelectorList{b}, body);
std::ostringstream out; EXPECT_EQ(str(c), R"(Case -2{
c->to_str(Sem(), out, 2); Discard{}
EXPECT_EQ(out.str(), R"( Case -2{ }
Discard{}
}
)"); )");
} }
@ -151,11 +149,9 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
}); });
auto* c = create<CaseStatement>(CaseSelectorList{b}, body); auto* c = create<CaseStatement>(CaseSelectorList{b}, body);
std::ostringstream out; EXPECT_EQ(str(c), R"(Case 2{
c->to_str(Sem(), out, 2); Discard{}
EXPECT_EQ(out.str(), R"( Case 2{ }
Discard{}
}
)"); )");
} }
@ -169,11 +165,9 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
}); });
auto* c = create<CaseStatement>(b, body); auto* c = create<CaseStatement>(b, body);
std::ostringstream out; EXPECT_EQ(str(c), R"(Case 1, 2{
c->to_str(Sem(), out, 2); Discard{}
EXPECT_EQ(out.str(), R"( Case 1, 2{ }
Discard{}
}
)"); )");
} }
@ -183,11 +177,9 @@ TEST_F(CaseStatementTest, ToStr_WithoutSelectors) {
}); });
auto* c = create<CaseStatement>(CaseSelectorList{}, body); auto* c = create<CaseStatement>(CaseSelectorList{}, body);
std::ostringstream out; EXPECT_EQ(str(c), R"(Default{
c->to_str(Sem(), out, 2); Discard{}
EXPECT_EQ(out.str(), R"( Default{ }
Discard{}
}
)"); )");
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,6 @@
#include <utility> #include <utility>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/demangler.h"
#include "src/program_builder.h" #include "src/program_builder.h"
namespace tint { namespace tint {
@ -28,18 +27,7 @@ namespace ast {
/// Helper class for testing /// Helper class for testing
template <typename BASE> template <typename BASE>
class TestHelperBase : public BASE, public ProgramBuilder { 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;
};
using TestHelper = TestHelperBase<testing::Test>; using TestHelper = TestHelperBase<testing::Test>;
template <typename T> template <typename T>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,7 +19,6 @@
namespace tint { namespace tint {
class Program;
class SymbolTable; class SymbolTable;
/// Helper to demangle strings and replace symbols with original names /// Helper to demangle strings and replace symbols with original names
@ -36,12 +35,6 @@ class Demangler {
/// @returns the string with any symbol replacements performed. /// @returns the string with any symbol replacements performed.
std::string Demangle(const SymbolTable& symbols, std::string Demangle(const SymbolTable& symbols,
const std::string& str) const; 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 } // namespace tint

View File

@ -19,6 +19,7 @@
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/clone_context.h" #include "src/clone_context.h"
#include "src/demangler.h"
#include "src/program_builder.h" #include "src/program_builder.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
@ -98,9 +99,17 @@ bool Program::IsValid() const {
return is_valid_; return is_valid_;
} }
std::string Program::to_str() const { std::string Program::to_str(bool demangle) const {
AssertNotMoved(); 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 { void Program::AssertNotMoved() const {

View File

@ -105,8 +105,27 @@ class Program {
/// information /// information
bool IsValid() const; bool IsValid() const;
/// @param demangle whether to automatically demangle the symbols in the
/// returned string
/// @returns a string describing this program. /// @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: private:
Program(const Program&) = delete; Program(const Program&) = delete;

View File

@ -19,6 +19,7 @@
#include <sstream> #include <sstream>
#include "src/clone_context.h" #include "src/clone_context.h"
#include "src/demangler.h"
#include "src/type/struct_type.h" #include "src/type/struct_type.h"
namespace tint { namespace tint {
@ -54,6 +55,10 @@ bool ProgramBuilder::IsValid() const {
return !diagnostics_.contains_errors() && ast_->IsValid(); 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() { void ProgramBuilder::MarkAsMoved() {
AssertNotMoved(); AssertNotMoved();
moved_ = true; moved_ = true;

View File

@ -150,6 +150,12 @@ class ProgramBuilder {
return symbols_; 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 /// @returns a reference to the program's diagnostics
diag::List& Diagnostics() { diag::List& Diagnostics() {
AssertNotMoved(); AssertNotMoved();
@ -175,6 +181,20 @@ class ProgramBuilder {
/// information /// information
bool IsValid() const; 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 /// creates a new ast::Node owned by the Module. When the Module is
/// destructed, the ast::Node will also be destructed. /// destructed, the ast::Node will also be destructed.
/// @param source the Source of the node /// @param source the Source of the node

View File

@ -46,7 +46,7 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
OpFunctionEnd OpFunctionEnd
)")); )"));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error(); 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{ const char* expect = R"(Module{
Function tint_symbol_1 -> __void Function tint_symbol_1 -> __void
() ()
@ -217,7 +217,7 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
)")); )"));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
EXPECT_TRUE(p->error().empty()); 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{ EXPECT_THAT(program_ast_str, HasSubstr(R"(Module{
Function x_50 -> __u32 Function x_50 -> __u32
( (

View File

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

View File

@ -800,7 +800,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) {
auto p = parser(test::Assemble(assembly)); auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions())
<< assembly << p->error(); << 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"( EXPECT_THAT(module_str, HasSubstr(R"(
RTArr -> __array__u32_stride_4 RTArr -> __array__u32_stride_4
S Struct{ S Struct{

View File

@ -328,14 +328,12 @@ TEST_P(SpvParserSwizzleTest, Sample) {
Program program(p->program()); Program program(p->program());
EXPECT_TRUE(fe.success()); EXPECT_TRUE(fe.success());
ASSERT_NE(result, nullptr); ASSERT_NE(result, nullptr);
std::ostringstream ss; auto got = program.str(result);
result->to_str(program.Sem(), ss, 0); EXPECT_EQ(got, GetParam().expected_expr);
auto str = Demangler().Demangle(program.Symbols(), ss.str());
EXPECT_THAT(str, Eq(GetParam().expected_expr));
} else { } else {
EXPECT_EQ(result, nullptr); EXPECT_EQ(result, nullptr);
EXPECT_FALSE(fe.success()); 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; auto* type = expr.type;
if (!type) { if (!type) {
Fail() << "internal error: unmapped type for: " Fail() << "internal error: unmapped type for: " << builder_.str(expr.expr)
<< expr.expr->str(builder_.Sem()) << "\n"; << "\n";
return {}; return {};
} }
if (requires_unsigned) { if (requires_unsigned) {

View File

@ -566,10 +566,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
EXPECT_TRUE(type->Is<type::Struct>()); EXPECT_TRUE(type->Is<type::Struct>());
Program program = p->program(); Program program = p->program();
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
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{
StructMember{field0: __u32} StructMember{field0: __u32}
StructMember{field1: __f32} StructMember{field1: __f32}
} }
@ -590,10 +587,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
EXPECT_TRUE(type->Is<type::Struct>()); EXPECT_TRUE(type->Is<type::Struct>());
Program program = p->program(); Program program = p->program();
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
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{
[[block]] [[block]]
StructMember{field0: __u32} StructMember{field0: __u32}
} }
@ -618,10 +612,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
EXPECT_TRUE(type->Is<type::Struct>()); EXPECT_TRUE(type->Is<type::Struct>());
Program program = p->program(); Program program = p->program();
EXPECT_THAT(program.str(type->As<type::Struct>()->impl()), Eq(R"(Struct{
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{
StructMember{[[ offset 0 ]] field0: __f32} StructMember{[[ offset 0 ]] field0: __f32}
StructMember{[[ offset 8 ]] field1: __vec_2__f32} StructMember{[[ offset 8 ]] field1: __vec_2__f32}
StructMember{[[ offset 16 ]] field2: __mat_2_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->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
Program program = p->program(); 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{"))); EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
} }
@ -67,7 +67,7 @@ TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) {
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
Program program = p->program(); 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{"))); EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
} }
@ -83,7 +83,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program(); 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"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() + Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
@ -104,7 +104,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program(); 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"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() + Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
@ -125,7 +125,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program(); 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"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() + Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
@ -148,7 +148,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->BuildAndParseInternalModule()); ASSERT_TRUE(p->BuildAndParseInternalModule());
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
Program program = p->program(); 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"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("frag_main").to_str() + Function )" + program.Symbols().Get("frag_main").to_str() +
R"( -> __void R"( -> __void
@ -173,7 +173,7 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) {
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
Program program = p->program(); 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"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + program.Symbols().Get("main").to_str() + Function )" + program.Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
@ -208,7 +208,7 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
Program program = p->program(); Program program = p->program();
const auto program_ast = Demangler().Demangle(program); const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function leaf -> __u32 Function leaf -> __u32
() ()
@ -276,7 +276,7 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) {
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
Program program = p->program(); Program program = p->program();
const auto program_ast = Demangler().Demangle(program); const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function ret_float -> __f32 Function ret_float -> __f32
() ()
@ -306,7 +306,7 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
Program program = p->program(); Program program = p->program();
const auto program_ast = Demangler().Demangle(program); const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function mixed_params -> __void Function mixed_params -> __void
( (
@ -346,7 +346,7 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
Program program = p->program(); Program program = p->program();
const auto program_ast = Demangler().Demangle(program); const auto program_ast = program.to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function mixed_params -> __void Function mixed_params -> __void
( (

View File

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

View File

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

View File

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

View File

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

View File

@ -20,7 +20,6 @@
#include <utility> #include <utility>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/demangler.h"
#include "src/program_builder.h" #include "src/program_builder.h"
namespace tint { namespace tint {
@ -28,18 +27,7 @@ namespace type {
/// Helper class for testing /// Helper class for testing
template <typename BASE> template <typename BASE>
class TestHelperBase : public BASE, public ProgramBuilder { 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;
};
using TestHelper = TestHelperBase<testing::Test>; using TestHelper = TestHelperBase<testing::Test>;
template <typename T> 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: " + set_error(stmt->source(), "unknown statement type for type determination: " +
stmt->str(builder_->Sem())); builder_->str(stmt));
return false; return false;
} }

View File

@ -3175,7 +3175,7 @@ TEST_P(TypeDeterminerTextureIntrinsicTest, Call) {
ident->intrinsic_signature()); ident->intrinsic_signature());
ASSERT_NE(sig, nullptr); 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); auto* expected = expected_texture_overload(param.overload);
EXPECT_EQ(got, expected); 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::UintLiteral>()->value()
: selector->As<ast::SintLiteral>()->value()); : selector->As<ast::SintLiteral>()->value());
if (selector_set.count(v)) { 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", add_error(case_stmt->source(), "v-0027",
"a literal value must not appear more than once in " "a literal value must not appear more than once in "
"the case selectors for a switch statement: '" + "the case selectors for a switch statement: '" +
v_str + "'"); program_->str(selector) + "'");
return false; return false;
} }
selector_set.emplace(v); selector_set.emplace(v);

View File

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

View File

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

View File

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

View File

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