Remove `SymbolTable::NameFor`

This CL removes the `NameFor` method from SymbolTable and accesses the
symbols name directly.

Change-Id: Ic4ad6eecfa78efb946d97aeaecf2d784af2e6f16
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127301
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2023-04-18 19:38:25 +00:00 committed by Dawn LUCI CQ
parent b353ebe752
commit d026e13f48
183 changed files with 700 additions and 874 deletions

View File

@ -24,8 +24,8 @@ using AstAliasTest = TestHelper;
TEST_F(AstAliasTest, Create) { TEST_F(AstAliasTest, Create) {
auto u32 = ty.u32(); auto u32 = ty.u32();
auto* a = Alias("a_type", u32); auto* a = Alias("a_type", u32);
CheckIdentifier(Symbols(), a->name, "a_type"); CheckIdentifier(a->name, "a_type");
CheckIdentifier(Symbols(), a->type, "u32"); CheckIdentifier(a->type, "u32");
} }
} // namespace } // namespace

View File

@ -25,7 +25,7 @@ using BitcastExpressionTest = TestHelper;
TEST_F(BitcastExpressionTest, Create) { TEST_F(BitcastExpressionTest, Create) {
auto* expr = Expr("expr"); auto* expr = Expr("expr");
auto* exp = Bitcast(ty.f32(), expr); auto* exp = Bitcast(ty.f32(), expr);
CheckIdentifier(Symbols(), exp->type, "f32"); CheckIdentifier(exp->type, "f32");
ASSERT_EQ(exp->expr, expr); ASSERT_EQ(exp->expr, expr);
} }

View File

@ -24,7 +24,7 @@ using BuiltinAttributeTest = TestHelper;
TEST_F(BuiltinAttributeTest, Creation) { TEST_F(BuiltinAttributeTest, Creation) {
auto* d = Builtin(builtin::BuiltinValue::kFragDepth); auto* d = Builtin(builtin::BuiltinValue::kFragDepth);
CheckIdentifier(Symbols(), d->builtin, "frag_depth"); CheckIdentifier(d->builtin, "frag_depth");
} }
TEST_F(BuiltinAttributeTest, Assert_Null_Builtin) { TEST_F(BuiltinAttributeTest, Assert_Null_Builtin) {

View File

@ -29,7 +29,7 @@ TEST_F(DiagnosticDirectiveTest, Creation) {
EXPECT_EQ(diag->source.range.end.line, 10u); EXPECT_EQ(diag->source.range.end.line, 10u);
EXPECT_EQ(diag->source.range.end.column, 15u); EXPECT_EQ(diag->source.range.end.column, 15u);
EXPECT_EQ(diag->control.severity, builtin::DiagnosticSeverity::kWarning); EXPECT_EQ(diag->control.severity, builtin::DiagnosticSeverity::kWarning);
CheckIdentifier(Symbols(), diag->control.rule_name, "foo"); CheckIdentifier(diag->control.rule_name, "foo");
} }
} // namespace } // namespace

View File

@ -33,7 +33,7 @@ TEST_F(FunctionTest, Creation_i32ReturnType) {
auto* f = Func("func", params, i32, utils::Empty); auto* f = Func("func", params, i32, utils::Empty);
EXPECT_EQ(f->name->symbol, Symbols().Get("func")); EXPECT_EQ(f->name->symbol, Symbols().Get("func"));
ASSERT_EQ(f->params.Length(), 1u); ASSERT_EQ(f->params.Length(), 1u);
CheckIdentifier(Symbols(), f->return_type, "i32"); CheckIdentifier(f->return_type, "i32");
EXPECT_EQ(f->params[0], var); EXPECT_EQ(f->params[0], var);
} }

View File

@ -27,8 +27,8 @@ using InterpolateAttributeTest = TestHelper;
TEST_F(InterpolateAttributeTest, Creation) { TEST_F(InterpolateAttributeTest, Creation) {
auto* d = auto* d =
Interpolate(builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kCenter); Interpolate(builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kCenter);
CheckIdentifier(Symbols(), d->type, "linear"); CheckIdentifier(d->type, "linear");
CheckIdentifier(Symbols(), d->sampling, "center"); CheckIdentifier(d->sampling, "center");
} }
} // namespace } // namespace

View File

@ -125,12 +125,9 @@ TEST_F(ModuleTest, CloneOrder) {
ASSERT_TRUE(decls[2]->Is<ast::Alias>()); ASSERT_TRUE(decls[2]->Is<ast::Alias>());
ASSERT_TRUE(decls[4]->Is<ast::Alias>()); ASSERT_TRUE(decls[4]->Is<ast::Alias>());
ASSERT_EQ(cloned.Symbols().NameFor(decls[0]->As<ast::Alias>()->name->symbol), ASSERT_EQ(decls[0]->As<ast::Alias>()->name->symbol.Name(), "inserted_before_F");
"inserted_before_F"); ASSERT_EQ(decls[2]->As<ast::Alias>()->name->symbol.Name(), "inserted_before_A");
ASSERT_EQ(cloned.Symbols().NameFor(decls[2]->As<ast::Alias>()->name->symbol), ASSERT_EQ(decls[4]->As<ast::Alias>()->name->symbol.Name(), "inserted_before_V");
"inserted_before_A");
ASSERT_EQ(cloned.Symbols().NameFor(decls[4]->As<ast::Alias>()->name->symbol),
"inserted_before_V");
} }
TEST_F(ModuleTest, Directives) { TEST_F(ModuleTest, Directives) {

View File

@ -23,8 +23,8 @@ using StructMemberTest = TestHelper;
TEST_F(StructMemberTest, Creation) { TEST_F(StructMemberTest, Creation) {
auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)}); auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)});
CheckIdentifier(Symbols(), st->name, "a"); CheckIdentifier(st->name, "a");
CheckIdentifier(Symbols(), st->type, "i32"); CheckIdentifier(st->type, "i32");
EXPECT_EQ(st->attributes.Length(), 1u); EXPECT_EQ(st->attributes.Length(), 1u);
EXPECT_TRUE(st->attributes[0]->Is<StructMemberSizeAttribute>()); EXPECT_TRUE(st->attributes[0]->Is<StructMemberSizeAttribute>());
EXPECT_EQ(st->source.range.begin.line, 0u); EXPECT_EQ(st->source.range.begin.line, 0u);
@ -36,8 +36,8 @@ TEST_F(StructMemberTest, Creation) {
TEST_F(StructMemberTest, CreationWithSource) { TEST_F(StructMemberTest, CreationWithSource) {
auto* st = Member(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a", auto* st = Member(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a",
ty.i32()); ty.i32());
CheckIdentifier(Symbols(), st->name, "a"); CheckIdentifier(st->name, "a");
CheckIdentifier(Symbols(), st->type, "i32"); CheckIdentifier(st->type, "i32");
EXPECT_EQ(st->attributes.Length(), 0u); EXPECT_EQ(st->attributes.Length(), 0u);
EXPECT_EQ(st->source.range.begin.line, 27u); EXPECT_EQ(st->source.range.begin.line, 27u);
EXPECT_EQ(st->source.range.begin.column, 4u); EXPECT_EQ(st->source.range.begin.column, 4u);

View File

@ -72,25 +72,21 @@ struct IsTemplatedIdentifierMatcher<TemplatedIdentifierMatcher<ARGS...>> {
}; };
/// A testing utility for checking that an Identifier matches the expected values. /// A testing utility for checking that an Identifier matches the expected values.
/// @param symbols the symbol table
/// @param got the identifier /// @param got the identifier
/// @param expected the expected identifier name /// @param expected the expected identifier name
template <typename... ARGS> template <typename... ARGS>
void CheckIdentifier(const SymbolTable& symbols, const Identifier* got, std::string_view expected) { void CheckIdentifier(const Identifier* got, std::string_view expected) {
EXPECT_FALSE(got->Is<TemplatedIdentifier>()); EXPECT_FALSE(got->Is<TemplatedIdentifier>());
EXPECT_EQ(symbols.NameFor(got->symbol), expected); EXPECT_EQ(got->symbol.Name(), expected);
} }
/// A testing utility for checking that an Identifier matches the expected name and template /// A testing utility for checking that an Identifier matches the expected name and template
/// arguments. /// arguments.
/// @param symbols the symbol table
/// @param ident the identifier /// @param ident the identifier
/// @param expected the expected identifier name and arguments /// @param expected the expected identifier name and arguments
template <typename... ARGS> template <typename... ARGS>
void CheckIdentifier(const SymbolTable& symbols, void CheckIdentifier(const Identifier* ident, const TemplatedIdentifierMatcher<ARGS...>& expected) {
const Identifier* ident, EXPECT_EQ(ident->symbol.Name(), expected.name);
const TemplatedIdentifierMatcher<ARGS...>& expected) {
EXPECT_EQ(symbols.NameFor(ident->symbol), expected.name);
ASSERT_TRUE(ident->Is<TemplatedIdentifier>()); ASSERT_TRUE(ident->Is<TemplatedIdentifier>());
auto* got = ident->As<TemplatedIdentifier>(); auto* got = ident->As<TemplatedIdentifier>();
ASSERT_EQ(got->arguments.Length(), std::tuple_size_v<decltype(expected.args)>); ASSERT_EQ(got->arguments.Length(), std::tuple_size_v<decltype(expected.args)>);
@ -102,12 +98,12 @@ void CheckIdentifier(const SymbolTable& symbols,
using T = std::decay_t<decltype(expected_arg)>; using T = std::decay_t<decltype(expected_arg)>;
if constexpr (traits::IsStringLike<T>) { if constexpr (traits::IsStringLike<T>) {
ASSERT_TRUE(got_arg->Is<IdentifierExpression>()); ASSERT_TRUE(got_arg->Is<IdentifierExpression>());
CheckIdentifier(symbols, got_arg->As<IdentifierExpression>()->identifier, expected_arg); CheckIdentifier(got_arg->As<IdentifierExpression>()->identifier, expected_arg);
} else if constexpr (IsTemplatedIdentifierMatcher<T>::value) { } else if constexpr (IsTemplatedIdentifierMatcher<T>::value) {
ASSERT_TRUE(got_arg->Is<IdentifierExpression>()); ASSERT_TRUE(got_arg->Is<IdentifierExpression>());
auto* got_ident = got_arg->As<IdentifierExpression>()->identifier; auto* got_ident = got_arg->As<IdentifierExpression>()->identifier;
ASSERT_TRUE(got_ident->Is<TemplatedIdentifier>()); ASSERT_TRUE(got_ident->Is<TemplatedIdentifier>());
CheckIdentifier(symbols, got_ident->As<TemplatedIdentifier>(), expected_arg); CheckIdentifier(got_ident->As<TemplatedIdentifier>(), expected_arg);
} else if constexpr (std::is_same_v<T, bool>) { } else if constexpr (std::is_same_v<T, bool>) {
ASSERT_TRUE(got_arg->Is<BoolLiteralExpression>()); ASSERT_TRUE(got_arg->Is<BoolLiteralExpression>());
EXPECT_EQ(got_arg->As<BoolLiteralExpression>()->value, expected_arg); EXPECT_EQ(got_arg->As<BoolLiteralExpression>()->value, expected_arg);
@ -149,30 +145,24 @@ void CheckIdentifier(const SymbolTable& symbols,
} }
/// A testing utility for checking that an IdentifierExpression matches the expected values. /// A testing utility for checking that an IdentifierExpression matches the expected values.
/// @param symbols the symbol table
/// @param expr the IdentifierExpression /// @param expr the IdentifierExpression
/// @param expected the expected identifier name /// @param expected the expected identifier name
template <typename... ARGS> template <typename... ARGS>
void CheckIdentifier(const SymbolTable& symbols, void CheckIdentifier(const Expression* expr, std::string_view expected) {
const Expression* expr,
std::string_view expected) {
auto* expr_ident = expr->As<IdentifierExpression>(); auto* expr_ident = expr->As<IdentifierExpression>();
ASSERT_NE(expr_ident, nullptr) << "expression is not a IdentifierExpression"; ASSERT_NE(expr_ident, nullptr) << "expression is not a IdentifierExpression";
CheckIdentifier(symbols, expr_ident->identifier, expected); CheckIdentifier(expr_ident->identifier, expected);
} }
/// A testing utility for checking that an IdentifierExpression matches the expected name and /// A testing utility for checking that an IdentifierExpression matches the expected name and
/// template arguments. /// template arguments.
/// @param symbols the symbol table
/// @param expr the IdentifierExpression /// @param expr the IdentifierExpression
/// @param expected the expected identifier name and arguments /// @param expected the expected identifier name and arguments
template <typename... ARGS> template <typename... ARGS>
void CheckIdentifier(const SymbolTable& symbols, void CheckIdentifier(const Expression* expr, const TemplatedIdentifierMatcher<ARGS...>& expected) {
const Expression* expr,
const TemplatedIdentifierMatcher<ARGS...>& expected) {
auto* expr_ident = expr->As<IdentifierExpression>(); auto* expr_ident = expr->As<IdentifierExpression>();
ASSERT_NE(expr_ident, nullptr) << "expression is not a IdentifierExpression"; ASSERT_NE(expr_ident, nullptr) << "expression is not a IdentifierExpression";
CheckIdentifier(symbols, expr_ident->identifier, expected); CheckIdentifier(expr_ident->identifier, expected);
} }
} // namespace tint::ast } // namespace tint::ast

View File

@ -21,21 +21,21 @@ using namespace tint::number_suffixes; // NOLINT
using AstCheckIdentifierTest = TestHelper; using AstCheckIdentifierTest = TestHelper;
TEST_F(AstCheckIdentifierTest, NonTemplated) { TEST_F(AstCheckIdentifierTest, NonTemplated) {
CheckIdentifier(Symbols(), Ident("abc"), "abc"); CheckIdentifier(Ident("abc"), "abc");
} }
TEST_F(AstCheckIdentifierTest, TemplatedScalars) { TEST_F(AstCheckIdentifierTest, TemplatedScalars) {
CheckIdentifier(Symbols(), Ident("abc", 1_i, 2_u, 3_f, 4_h, 5_a, 6._a, true), // CheckIdentifier(Ident("abc", 1_i, 2_u, 3_f, 4_h, 5_a, 6._a, true), //
Template("abc", 1_i, 2_u, 3_f, 4_h, 5_a, 6._a, true)); Template("abc", 1_i, 2_u, 3_f, 4_h, 5_a, 6._a, true));
} }
TEST_F(AstCheckIdentifierTest, TemplatedIdentifiers) { TEST_F(AstCheckIdentifierTest, TemplatedIdentifiers) {
CheckIdentifier(Symbols(), Ident("abc", "one", "two", "three"), // CheckIdentifier(Ident("abc", "one", "two", "three"), //
Template("abc", "one", "two", "three")); Template("abc", "one", "two", "three"));
} }
TEST_F(AstCheckIdentifierTest, NestedTemplate) { TEST_F(AstCheckIdentifierTest, NestedTemplate) {
CheckIdentifier(Symbols(), Ident("abc", "pre", Ident("nested", 42_a), "post"), // CheckIdentifier(Ident("abc", "pre", Ident("nested", 42_a), "post"), //
Template("abc", "pre", Template("nested", 42_a), "post")); Template("abc", "pre", Template("nested", 42_a), "post"));
} }

View File

@ -28,10 +28,10 @@ using VariableTest = TestHelper;
TEST_F(VariableTest, Creation) { TEST_F(VariableTest, Creation) {
auto* v = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction); auto* v = Var("my_var", ty.i32(), builtin::AddressSpace::kFunction);
CheckIdentifier(Symbols(), v->name, "my_var"); CheckIdentifier(v->name, "my_var");
CheckIdentifier(Symbols(), v->declared_address_space, "function"); CheckIdentifier(v->declared_address_space, "function");
EXPECT_EQ(v->declared_access, nullptr); EXPECT_EQ(v->declared_access, nullptr);
CheckIdentifier(Symbols(), v->type, "i32"); CheckIdentifier(v->type, "i32");
EXPECT_EQ(v->source.range.begin.line, 0u); EXPECT_EQ(v->source.range.begin.line, 0u);
EXPECT_EQ(v->source.range.begin.column, 0u); EXPECT_EQ(v->source.range.begin.column, 0u);
EXPECT_EQ(v->source.range.end.line, 0u); EXPECT_EQ(v->source.range.end.line, 0u);
@ -42,9 +42,9 @@ TEST_F(VariableTest, CreationWithSource) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i", auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i",
ty.f32(), builtin::AddressSpace::kPrivate, utils::Empty); ty.f32(), builtin::AddressSpace::kPrivate, utils::Empty);
CheckIdentifier(Symbols(), v->name, "i"); CheckIdentifier(v->name, "i");
CheckIdentifier(Symbols(), v->declared_address_space, "private"); CheckIdentifier(v->declared_address_space, "private");
CheckIdentifier(Symbols(), v->type, "f32"); CheckIdentifier(v->type, "f32");
EXPECT_EQ(v->source.range.begin.line, 27u); EXPECT_EQ(v->source.range.begin.line, 27u);
EXPECT_EQ(v->source.range.begin.column, 4u); EXPECT_EQ(v->source.range.begin.column, 4u);
EXPECT_EQ(v->source.range.end.line, 27u); EXPECT_EQ(v->source.range.end.line, 27u);
@ -55,9 +55,9 @@ TEST_F(VariableTest, CreationEmpty) {
auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var", auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var",
ty.i32(), builtin::AddressSpace::kWorkgroup, utils::Empty); ty.i32(), builtin::AddressSpace::kWorkgroup, utils::Empty);
CheckIdentifier(Symbols(), v->name, "a_var"); CheckIdentifier(v->name, "a_var");
CheckIdentifier(Symbols(), v->declared_address_space, "workgroup"); CheckIdentifier(v->declared_address_space, "workgroup");
CheckIdentifier(Symbols(), v->type, "i32"); CheckIdentifier(v->type, "i32");
EXPECT_EQ(v->source.range.begin.line, 27u); EXPECT_EQ(v->source.range.begin.line, 27u);
EXPECT_EQ(v->source.range.begin.column, 4u); EXPECT_EQ(v->source.range.begin.column, 4u);
EXPECT_EQ(v->source.range.end.line, 27u); EXPECT_EQ(v->source.range.end.line, 27u);

View File

@ -73,7 +73,7 @@ TEST_F(WorkgroupAttributeTest, Creation_WithIdentifier) {
auto* z_ident = As<IdentifierExpression>(values[2]); auto* z_ident = As<IdentifierExpression>(values[2]);
ASSERT_TRUE(z_ident); ASSERT_TRUE(z_ident);
EXPECT_EQ(Symbols().NameFor(z_ident->identifier->symbol), "depth"); EXPECT_EQ(z_ident->identifier->symbol.Name(), "depth");
} }
} // namespace } // namespace

View File

@ -49,7 +49,7 @@ Symbol CloneContext::Clone(Symbol s) {
if (symbol_transform_) { if (symbol_transform_) {
return symbol_transform_(s); return symbol_transform_(s);
} }
return dst->Symbols().New(src->Symbols().NameFor(s)); return dst->Symbols().New(s.Name());
}); });
} }

View File

@ -183,10 +183,8 @@ TEST_F(CloneContextNodeTest, CloneWithReplaceAll_Cloneable) {
CloneContext ctx(&cloned, &original); CloneContext ctx(&cloned, &original);
ctx.ReplaceAll([&](const Replaceable* in) { ctx.ReplaceAll([&](const Replaceable* in) {
auto out_name = auto out_name = cloned.Symbols().Register("replacement:" + in->name.Name());
cloned.Symbols().Register("replacement:" + original.Symbols().NameFor(in->name)); auto b_name = cloned.Symbols().Register("replacement-child:" + in->name.Name());
auto b_name =
cloned.Symbols().Register("replacement-child:" + original.Symbols().NameFor(in->name));
auto* out = alloc.Create<Replacement>(out_name); auto* out = alloc.Create<Replacement>(out_name);
out->b = alloc.Create<Node>(b_name); out->b = alloc.Create<Node>(b_name);
out->c = ctx.Clone(in->a); out->c = ctx.Clone(in->a);
@ -276,7 +274,7 @@ TEST_F(CloneContextNodeTest, CloneWithReplaceAll_Symbols) {
ProgramBuilder cloned; ProgramBuilder cloned;
auto* cloned_root = CloneContext(&cloned, &original, false) auto* cloned_root = CloneContext(&cloned, &original, false)
.ReplaceAll([&](Symbol sym) { .ReplaceAll([&](Symbol sym) {
auto in = original.Symbols().NameFor(sym); auto in = sym.Name();
auto out = "transformed<" + in + ">"; auto out = "transformed<" + in + ">";
return cloned.Symbols().New(out); return cloned.Symbols().New(out);
}) })
@ -1173,9 +1171,9 @@ TEST_F(CloneContextTest, CloneNewUnnamedSymbols) {
Symbol old_a = builder.Symbols().New(); Symbol old_a = builder.Symbols().New();
Symbol old_b = builder.Symbols().New(); Symbol old_b = builder.Symbols().New();
Symbol old_c = builder.Symbols().New(); Symbol old_c = builder.Symbols().New();
EXPECT_EQ(builder.Symbols().NameFor(old_a), "tint_symbol"); EXPECT_EQ(old_a.Name(), "tint_symbol");
EXPECT_EQ(builder.Symbols().NameFor(old_b), "tint_symbol_1"); EXPECT_EQ(old_b.Name(), "tint_symbol_1");
EXPECT_EQ(builder.Symbols().NameFor(old_c), "tint_symbol_2"); EXPECT_EQ(old_c.Name(), "tint_symbol_2");
Program original(std::move(builder)); Program original(std::move(builder));
@ -1188,12 +1186,12 @@ TEST_F(CloneContextTest, CloneNewUnnamedSymbols) {
Symbol new_z = cloned.Symbols().New(); Symbol new_z = cloned.Symbols().New();
Symbol new_c = ctx.Clone(old_c); Symbol new_c = ctx.Clone(old_c);
EXPECT_EQ(cloned.Symbols().NameFor(new_x), "tint_symbol"); EXPECT_EQ(new_x.Name(), "tint_symbol");
EXPECT_EQ(cloned.Symbols().NameFor(new_a), "tint_symbol_1"); EXPECT_EQ(new_a.Name(), "tint_symbol_1");
EXPECT_EQ(cloned.Symbols().NameFor(new_y), "tint_symbol_2"); EXPECT_EQ(new_y.Name(), "tint_symbol_2");
EXPECT_EQ(cloned.Symbols().NameFor(new_b), "tint_symbol_1_1"); EXPECT_EQ(new_b.Name(), "tint_symbol_1_1");
EXPECT_EQ(cloned.Symbols().NameFor(new_z), "tint_symbol_3"); EXPECT_EQ(new_z.Name(), "tint_symbol_3");
EXPECT_EQ(cloned.Symbols().NameFor(new_c), "tint_symbol_2_1"); EXPECT_EQ(new_c.Name(), "tint_symbol_2_1");
} }
TEST_F(CloneContextTest, CloneNewSymbols) { TEST_F(CloneContextTest, CloneNewSymbols) {
@ -1201,9 +1199,9 @@ TEST_F(CloneContextTest, CloneNewSymbols) {
Symbol old_a = builder.Symbols().New("a"); Symbol old_a = builder.Symbols().New("a");
Symbol old_b = builder.Symbols().New("b"); Symbol old_b = builder.Symbols().New("b");
Symbol old_c = builder.Symbols().New("c"); Symbol old_c = builder.Symbols().New("c");
EXPECT_EQ(builder.Symbols().NameFor(old_a), "a"); EXPECT_EQ(old_a.Name(), "a");
EXPECT_EQ(builder.Symbols().NameFor(old_b), "b"); EXPECT_EQ(old_b.Name(), "b");
EXPECT_EQ(builder.Symbols().NameFor(old_c), "c"); EXPECT_EQ(old_c.Name(), "c");
Program original(std::move(builder)); Program original(std::move(builder));
@ -1216,12 +1214,12 @@ TEST_F(CloneContextTest, CloneNewSymbols) {
Symbol new_z = cloned.Symbols().New("c"); Symbol new_z = cloned.Symbols().New("c");
Symbol new_c = ctx.Clone(old_c); Symbol new_c = ctx.Clone(old_c);
EXPECT_EQ(cloned.Symbols().NameFor(new_x), "a"); EXPECT_EQ(new_x.Name(), "a");
EXPECT_EQ(cloned.Symbols().NameFor(new_a), "a_1"); EXPECT_EQ(new_a.Name(), "a_1");
EXPECT_EQ(cloned.Symbols().NameFor(new_y), "b"); EXPECT_EQ(new_y.Name(), "b");
EXPECT_EQ(cloned.Symbols().NameFor(new_b), "b_1"); EXPECT_EQ(new_b.Name(), "b_1");
EXPECT_EQ(cloned.Symbols().NameFor(new_z), "c"); EXPECT_EQ(new_z.Name(), "c");
EXPECT_EQ(cloned.Symbols().NameFor(new_c), "c_1"); EXPECT_EQ(new_c.Name(), "c_1");
} }
TEST_F(CloneContextTest, CloneNewSymbols_AfterCloneSymbols) { TEST_F(CloneContextTest, CloneNewSymbols_AfterCloneSymbols) {
@ -1229,9 +1227,9 @@ TEST_F(CloneContextTest, CloneNewSymbols_AfterCloneSymbols) {
Symbol old_a = builder.Symbols().New("a"); Symbol old_a = builder.Symbols().New("a");
Symbol old_b = builder.Symbols().New("b"); Symbol old_b = builder.Symbols().New("b");
Symbol old_c = builder.Symbols().New("c"); Symbol old_c = builder.Symbols().New("c");
EXPECT_EQ(builder.Symbols().NameFor(old_a), "a"); EXPECT_EQ(old_a.Name(), "a");
EXPECT_EQ(builder.Symbols().NameFor(old_b), "b"); EXPECT_EQ(old_b.Name(), "b");
EXPECT_EQ(builder.Symbols().NameFor(old_c), "c"); EXPECT_EQ(old_c.Name(), "c");
Program original(std::move(builder)); Program original(std::move(builder));
@ -1244,12 +1242,12 @@ TEST_F(CloneContextTest, CloneNewSymbols_AfterCloneSymbols) {
Symbol new_z = cloned.Symbols().New("c"); Symbol new_z = cloned.Symbols().New("c");
Symbol new_c = ctx.Clone(old_c); Symbol new_c = ctx.Clone(old_c);
EXPECT_EQ(cloned.Symbols().NameFor(new_x), "a_1"); EXPECT_EQ(new_x.Name(), "a_1");
EXPECT_EQ(cloned.Symbols().NameFor(new_a), "a"); EXPECT_EQ(new_a.Name(), "a");
EXPECT_EQ(cloned.Symbols().NameFor(new_y), "b_1"); EXPECT_EQ(new_y.Name(), "b_1");
EXPECT_EQ(cloned.Symbols().NameFor(new_b), "b"); EXPECT_EQ(new_b.Name(), "b");
EXPECT_EQ(cloned.Symbols().NameFor(new_z), "c_1"); EXPECT_EQ(new_z.Name(), "c_1");
EXPECT_EQ(cloned.Symbols().NameFor(new_c), "c"); EXPECT_EQ(new_c.Name(), "c");
} }
TEST_F(CloneContextTest, ProgramIDs) { TEST_F(CloneContextTest, ProgramIDs) {

View File

@ -237,7 +237,7 @@ void EmitJson(const tint::Program* program) {
std::cout << std::endl; std::cout << std::endl;
std::cout << "{" << std::endl; std::cout << "{" << std::endl;
std::cout << "\"name\": \"" << s->FriendlyName(program->Symbols()) << "\"," << std::endl; std::cout << "\"name\": \"" << s->FriendlyName() << "\"," << std::endl;
std::cout << "\"align\": " << s->Align() << "," << std::endl; std::cout << "\"align\": " << s->Align() << "," << std::endl;
std::cout << "\"size\": " << s->Size() << "," << std::endl; std::cout << "\"size\": " << s->Size() << "," << std::endl;
std::cout << "\"members\": ["; std::cout << "\"members\": [";
@ -265,8 +265,7 @@ void EmitJson(const tint::Program* program) {
} }
std::cout << "{" << std::endl; std::cout << "{" << std::endl;
std::cout << "\"name\": \"" << program->Symbols().NameFor(m->Name()) << "\"," std::cout << "\"name\": \"" << m->Name().Name() << "\"," << std::endl;
<< std::endl;
std::cout << "\"offset\": " << m->Offset() << "," << std::endl; std::cout << "\"offset\": " << m->Offset() << "," << std::endl;
std::cout << "\"align\": " << m->Align() << "," << std::endl; std::cout << "\"align\": " << m->Align() << "," << std::endl;
std::cout << "\"size\": " << m->Size() << std::endl; std::cout << "\"size\": " << m->Size() << std::endl;
@ -307,7 +306,7 @@ void EmitText(const tint::Program* program) {
continue; continue;
} }
const auto* s = ty->As<tint::type::Struct>(); const auto* s = ty->As<tint::type::Struct>();
std::cout << s->Layout(program->Symbols()) << std::endl << std::endl; std::cout << s->Layout() << std::endl << std::endl;
} }
} }
} }

View File

@ -133,8 +133,8 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) {
auto* sem = program_->Sem().Get(func); auto* sem = program_->Sem().Get(func);
entry_point.name = program_->Symbols().NameFor(func->name->symbol); entry_point.name = func->name->symbol.Name();
entry_point.remapped_name = program_->Symbols().NameFor(func->name->symbol); entry_point.remapped_name = func->name->symbol.Name();
switch (func->PipelineStage()) { switch (func->PipelineStage()) {
case ast::PipelineStage::kCompute: { case ast::PipelineStage::kCompute: {
@ -163,9 +163,9 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) {
} }
for (auto* param : sem->Parameters()) { for (auto* param : sem->Parameters()) {
AddEntryPointInOutVariables(program_->Symbols().NameFor(param->Declaration()->name->symbol), AddEntryPointInOutVariables(param->Declaration()->name->symbol.Name(), param->Type(),
param->Type(), param->Declaration()->attributes, param->Declaration()->attributes, param->Location(),
param->Location(), entry_point.input_variables); entry_point.input_variables);
entry_point.input_position_used |= ContainsBuiltin( entry_point.input_position_used |= ContainsBuiltin(
builtin::BuiltinValue::kPosition, param->Type(), param->Declaration()->attributes); builtin::BuiltinValue::kPosition, param->Type(), param->Declaration()->attributes);
@ -192,7 +192,7 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) {
for (auto* var : sem->TransitivelyReferencedGlobals()) { for (auto* var : sem->TransitivelyReferencedGlobals()) {
auto* decl = var->Declaration(); auto* decl = var->Declaration();
auto name = program_->Symbols().NameFor(decl->name->symbol); auto name = decl->name->symbol.Name();
auto* global = var->As<sem::GlobalVariable>(); auto* global = var->As<sem::GlobalVariable>();
if (global && global->Declaration()->Is<ast::Override>()) { if (global && global->Declaration()->Is<ast::Override>()) {
@ -295,7 +295,7 @@ std::map<std::string, OverrideId> Inspector::GetNamedOverrideIds() {
for (auto* var : program_->AST().GlobalVariables()) { for (auto* var : program_->AST().GlobalVariables()) {
auto* global = program_->Sem().Get<sem::GlobalVariable>(var); auto* global = program_->Sem().Get<sem::GlobalVariable>(var);
if (global && global->Declaration()->Is<ast::Override>()) { if (global && global->Declaration()->Is<ast::Override>()) {
auto name = program_->Symbols().NameFor(var->name->symbol); auto name = var->name->symbol.Name();
result[name] = global->OverrideId(); result[name] = global->OverrideId();
} }
} }
@ -619,9 +619,9 @@ void Inspector::AddEntryPointInOutVariables(std::string name,
if (auto* struct_ty = unwrapped_type->As<sem::Struct>()) { if (auto* struct_ty = unwrapped_type->As<sem::Struct>()) {
// Recurse into members. // Recurse into members.
for (auto* member : struct_ty->Members()) { for (auto* member : struct_ty->Members()) {
AddEntryPointInOutVariables(name + "." + program_->Symbols().NameFor(member->Name()), AddEntryPointInOutVariables(name + "." + member->Name().Name(), member->Type(),
member->Type(), member->Declaration()->attributes, member->Declaration()->attributes, member->Location(),
member->Location(), variables); variables);
} }
return; return;
} }
@ -838,8 +838,8 @@ void Inspector::GenerateSamplerTargets() {
auto sampler_binding_point = globals[1]->BindingPoint(); auto sampler_binding_point = globals[1]->BindingPoint();
for (auto* entry_point : entry_points) { for (auto* entry_point : entry_points) {
const auto& ep_name = program_->Symbols().NameFor( const auto& ep_name =
entry_point->Declaration()->name->symbol); entry_point->Declaration()->name->symbol.Name();
(*sampler_targets_)[ep_name].Add( (*sampler_targets_)[ep_name].Add(
{sampler_binding_point, texture_binding_point}); {sampler_binding_point, texture_binding_point});
} }

View File

@ -83,7 +83,7 @@ bool InspectorBuilder::ContainsName(utils::VectorRef<StageVariable> vec, const s
} }
std::string InspectorBuilder::StructMemberName(size_t idx, ast::Type type) { std::string InspectorBuilder::StructMemberName(size_t idx, ast::Type type) {
return std::to_string(idx) + Symbols().NameFor(type->identifier->symbol); return std::to_string(idx) + type->identifier->symbol.Name();
} }
const ast::Struct* InspectorBuilder::MakeStructType(const std::string& name, const ast::Struct* InspectorBuilder::MakeStructType(const std::string& name,

View File

@ -29,9 +29,9 @@ Binary::Binary(Kind kind, Value* result, Value* lhs, Value* rhs)
Binary::~Binary() = default; Binary::~Binary() = default;
utils::StringStream& Binary::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& Binary::ToString(utils::StringStream& out) const {
Result()->ToString(out, st) << " = "; Result()->ToString(out) << " = ";
lhs_->ToString(out, st) << " "; lhs_->ToString(out) << " ";
switch (GetKind()) { switch (GetKind()) {
case Binary::Kind::kAdd: case Binary::Kind::kAdd:
@ -90,7 +90,7 @@ utils::StringStream& Binary::ToString(utils::StringStream& out, const SymbolTabl
break; break;
} }
out << " "; out << " ";
rhs_->ToString(out, st); rhs_->ToString(out);
return out; return out;
} }

View File

@ -76,9 +76,8 @@ class Binary : public Castable<Binary, Instruction> {
/// Write the instruction to the given stream /// Write the instruction to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
private: private:
Kind kind_; Kind kind_;

View File

@ -47,7 +47,7 @@ TEST_F(IR_InstructionTest, CreateAnd) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 & 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 & 2");
} }
@ -74,7 +74,7 @@ TEST_F(IR_InstructionTest, CreateOr) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 | 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 | 2");
} }
@ -101,7 +101,7 @@ TEST_F(IR_InstructionTest, CreateXor) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 ^ 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 ^ 2");
} }
@ -128,7 +128,7 @@ TEST_F(IR_InstructionTest, CreateLogicalAnd) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 && 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 && 2");
} }
@ -155,7 +155,7 @@ TEST_F(IR_InstructionTest, CreateLogicalOr) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 || 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 || 2");
} }
@ -182,7 +182,7 @@ TEST_F(IR_InstructionTest, CreateEqual) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 == 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 == 2");
} }
@ -209,7 +209,7 @@ TEST_F(IR_InstructionTest, CreateNotEqual) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 != 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 != 2");
} }
@ -236,7 +236,7 @@ TEST_F(IR_InstructionTest, CreateLessThan) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 < 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 < 2");
} }
@ -263,7 +263,7 @@ TEST_F(IR_InstructionTest, CreateGreaterThan) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 > 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 > 2");
} }
@ -290,7 +290,7 @@ TEST_F(IR_InstructionTest, CreateLessThanEqual) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 <= 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 <= 2");
} }
@ -317,7 +317,7 @@ TEST_F(IR_InstructionTest, CreateGreaterThanEqual) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (bool) = 4 >= 2"); EXPECT_EQ(str.str(), "%42 (bool) = 4 >= 2");
} }
@ -344,7 +344,7 @@ TEST_F(IR_InstructionTest, CreateShiftLeft) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 << 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 << 2");
} }
@ -371,7 +371,7 @@ TEST_F(IR_InstructionTest, CreateShiftRight) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 >> 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 >> 2");
} }
@ -398,7 +398,7 @@ TEST_F(IR_InstructionTest, CreateAdd) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 + 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 + 2");
} }
@ -425,7 +425,7 @@ TEST_F(IR_InstructionTest, CreateSubtract) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 - 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 - 2");
} }
@ -452,7 +452,7 @@ TEST_F(IR_InstructionTest, CreateMultiply) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 * 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 * 2");
} }
@ -479,7 +479,7 @@ TEST_F(IR_InstructionTest, CreateDivide) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 / 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 / 2");
} }
@ -506,7 +506,7 @@ TEST_F(IR_InstructionTest, CreateModulo) {
EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(2_i, rhs->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = 4 % 2"); EXPECT_EQ(str.str(), "%42 (i32) = 4 % 2");
} }

View File

@ -26,10 +26,10 @@ Bitcast::Bitcast(Value* result, Value* val) : Base(result), val_(val) {
Bitcast::~Bitcast() = default; Bitcast::~Bitcast() = default;
utils::StringStream& Bitcast::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& Bitcast::ToString(utils::StringStream& out) const {
Result()->ToString(out, st); Result()->ToString(out);
out << " = bitcast("; out << " = bitcast(";
val_->ToString(out, st); val_->ToString(out);
out << ")"; out << ")";
return out; return out;
} }

View File

@ -42,9 +42,8 @@ class Bitcast : public Castable<Bitcast, Instruction> {
/// Write the instruction to the given stream /// Write the instruction to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
private: private:
Value* val_ = nullptr; Value* val_ = nullptr;

View File

@ -40,7 +40,7 @@ TEST_F(IR_InstructionTest, Bitcast) {
EXPECT_EQ(4_i, val->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(4_i, val->As<constant::Scalar<i32>>()->ValueAs<i32>());
utils::StringStream str; utils::StringStream str;
instr->ToString(str, b.builder.ir.symbols); instr->ToString(str);
EXPECT_EQ(str.str(), "%42 (i32) = bitcast(4)"); EXPECT_EQ(str.str(), "%42 (i32) = bitcast(4)");
} }

View File

@ -146,7 +146,7 @@ FlowNode* BuilderImpl::FindEnclosingControl(ControlFlags flags) {
} }
Symbol BuilderImpl::CloneSymbol(Symbol sym) const { Symbol BuilderImpl::CloneSymbol(Symbol sym) const {
return clone_ctx_.type_ctx.dst.st->Register(clone_ctx_.type_ctx.src.st->NameFor(sym)); return clone_ctx_.type_ctx.dst.st->Register(sym.Name());
} }
ResultType BuilderImpl::Build() { ResultType BuilderImpl::Build() {

View File

@ -25,10 +25,10 @@ Builtin::Builtin(Value* result, builtin::Function func, utils::VectorRef<Value*>
Builtin::~Builtin() = default; Builtin::~Builtin() = default;
utils::StringStream& Builtin::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& Builtin::ToString(utils::StringStream& out) const {
Result()->ToString(out, st); Result()->ToString(out);
out << " = " << builtin::str(func_) << "("; out << " = " << builtin::str(func_) << "(";
EmitArgs(out, st); EmitArgs(out);
out << ")"; out << ")";
return out; return out;
} }

View File

@ -44,9 +44,8 @@ class Builtin : public Castable<Builtin, Call> {
/// Write the instruction to the given stream /// Write the instruction to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
private: private:
const builtin::Function func_; const builtin::Function func_;

View File

@ -26,14 +26,14 @@ Call::Call(Value* result, utils::VectorRef<Value*> args) : Base(result), args_(a
Call::~Call() = default; Call::~Call() = default;
void Call::EmitArgs(utils::StringStream& out, const SymbolTable& st) const { void Call::EmitArgs(utils::StringStream& out) const {
bool first = true; bool first = true;
for (const auto* arg : args_) { for (const auto* arg : args_) {
if (!first) { if (!first) {
out << ", "; out << ", ";
} }
first = false; first = false;
arg->ToString(out, st); arg->ToString(out);
} }
} }

View File

@ -42,8 +42,7 @@ class Call : public Castable<Call, Instruction> {
/// Writes the call arguments to the given stream. /// Writes the call arguments to the given stream.
/// @param out the output stream /// @param out the output stream
/// @param st the symbol table void EmitArgs(utils::StringStream& out) const;
void EmitArgs(utils::StringStream& out, const SymbolTable& st) const;
private: private:
utils::Vector<Value*, 1> args_; utils::Vector<Value*, 1> args_;

View File

@ -29,7 +29,7 @@ Constant::Constant(const constant::Value* val) : value(val) {}
Constant::~Constant() = default; Constant::~Constant() = default;
utils::StringStream& Constant::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& Constant::ToString(utils::StringStream& out) const {
std::function<void(const constant::Value*)> emit = [&](const constant::Value* c) { std::function<void(const constant::Value*)> emit = [&](const constant::Value* c) {
Switch( Switch(
c, c,
@ -43,12 +43,12 @@ utils::StringStream& Constant::ToString(utils::StringStream& out, const SymbolTa
out << (scalar->ValueAs<bool>() ? "true" : "false"); out << (scalar->ValueAs<bool>() ? "true" : "false");
}, },
[&](const constant::Splat* splat) { [&](const constant::Splat* splat) {
out << splat->Type()->FriendlyName(st) << "("; out << splat->Type()->FriendlyName() << "(";
emit(splat->Index(0)); emit(splat->Index(0));
out << ")"; out << ")";
}, },
[&](const constant::Composite* composite) { [&](const constant::Composite* composite) {
out << composite->Type()->FriendlyName(st) << "("; out << composite->Type()->FriendlyName() << "(";
for (const auto* elem : composite->elements) { for (const auto* elem : composite->elements) {
if (elem != composite->elements[0]) { if (elem != composite->elements[0]) {
out << ", "; out << ", ";

View File

@ -35,9 +35,8 @@ class Constant : public Castable<Constant, Value> {
/// Write the constant to the given stream /// Write the constant to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
/// The constants value /// The constants value
const constant::Value* const value; const constant::Value* const value;

View File

@ -31,7 +31,7 @@ TEST_F(IR_ConstantTest, f32) {
auto* c = b.builder.Constant(1.2_f); auto* c = b.builder.Constant(1.2_f);
EXPECT_EQ(1.2_f, c->value->As<constant::Scalar<f32>>()->ValueAs<f32>()); EXPECT_EQ(1.2_f, c->value->As<constant::Scalar<f32>>()->ValueAs<f32>());
c->ToString(str, b.builder.ir.symbols); c->ToString(str);
EXPECT_EQ("1.20000004768371582031", str.str()); EXPECT_EQ("1.20000004768371582031", str.str());
EXPECT_TRUE(c->value->Is<constant::Scalar<f32>>()); EXPECT_TRUE(c->value->Is<constant::Scalar<f32>>());
@ -49,7 +49,7 @@ TEST_F(IR_ConstantTest, f16) {
auto* c = b.builder.Constant(1.1_h); auto* c = b.builder.Constant(1.1_h);
EXPECT_EQ(1.1_h, c->value->As<constant::Scalar<f16>>()->ValueAs<f16>()); EXPECT_EQ(1.1_h, c->value->As<constant::Scalar<f16>>()->ValueAs<f16>());
c->ToString(str, b.builder.ir.symbols); c->ToString(str);
EXPECT_EQ("1.099609375", str.str()); EXPECT_EQ("1.099609375", str.str());
EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>()); EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>());
@ -67,7 +67,7 @@ TEST_F(IR_ConstantTest, i32) {
auto* c = b.builder.Constant(1_i); auto* c = b.builder.Constant(1_i);
EXPECT_EQ(1_i, c->value->As<constant::Scalar<i32>>()->ValueAs<i32>()); EXPECT_EQ(1_i, c->value->As<constant::Scalar<i32>>()->ValueAs<i32>());
c->ToString(str, b.builder.ir.symbols); c->ToString(str);
EXPECT_EQ("1", str.str()); EXPECT_EQ("1", str.str());
EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>()); EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>());
@ -85,7 +85,7 @@ TEST_F(IR_ConstantTest, u32) {
auto* c = b.builder.Constant(2_u); auto* c = b.builder.Constant(2_u);
EXPECT_EQ(2_u, c->value->As<constant::Scalar<u32>>()->ValueAs<u32>()); EXPECT_EQ(2_u, c->value->As<constant::Scalar<u32>>()->ValueAs<u32>());
c->ToString(str, b.builder.ir.symbols); c->ToString(str);
EXPECT_EQ("2", str.str()); EXPECT_EQ("2", str.str());
EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>()); EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>());
@ -104,7 +104,7 @@ TEST_F(IR_ConstantTest, bool) {
auto* c = b.builder.Constant(false); auto* c = b.builder.Constant(false);
EXPECT_FALSE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>()); EXPECT_FALSE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>());
c->ToString(str, b.builder.ir.symbols); c->ToString(str);
EXPECT_EQ("false", str.str()); EXPECT_EQ("false", str.str());
} }
@ -113,7 +113,7 @@ TEST_F(IR_ConstantTest, bool) {
auto c = b.builder.Constant(true); auto c = b.builder.Constant(true);
EXPECT_TRUE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>()); EXPECT_TRUE(c->value->As<constant::Scalar<bool>>()->ValueAs<bool>());
c->ToString(str, b.builder.ir.symbols); c->ToString(str);
EXPECT_EQ("true", str.str()); EXPECT_EQ("true", str.str());
EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>()); EXPECT_FALSE(c->value->Is<constant::Scalar<f32>>());

View File

@ -23,12 +23,12 @@ Construct::Construct(Value* result, utils::VectorRef<Value*> args) : Base(result
Construct::~Construct() = default; Construct::~Construct() = default;
utils::StringStream& Construct::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& Construct::ToString(utils::StringStream& out) const {
Result()->ToString(out, st); Result()->ToString(out);
out << " = construct(" << Result()->Type()->FriendlyName(st); out << " = construct(" << Result()->Type()->FriendlyName();
if (!Args().IsEmpty()) { if (!Args().IsEmpty()) {
out << ", "; out << ", ";
EmitArgs(out, st); EmitArgs(out);
} }
out << ")"; out << ")";
return out; return out;

View File

@ -39,9 +39,8 @@ class Construct : public Castable<Construct, Call> {
/// Write the instruction to the given stream /// Write the instruction to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
}; };
} // namespace tint::ir } // namespace tint::ir

View File

@ -24,11 +24,11 @@ Convert::Convert(Value* result, const type::Type* from, utils::VectorRef<Value*>
Convert::~Convert() = default; Convert::~Convert() = default;
utils::StringStream& Convert::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& Convert::ToString(utils::StringStream& out) const {
Result()->ToString(out, st); Result()->ToString(out);
out << " = convert(" << Result()->Type()->FriendlyName(st) << ", " << from_->FriendlyName(st) out << " = convert(" << Result()->Type()->FriendlyName() << ", " << from_->FriendlyName()
<< ", "; << ", ";
EmitArgs(out, st); EmitArgs(out);
out << ")"; out << ")";
return out; return out;
} }

View File

@ -45,9 +45,8 @@ class Convert : public Castable<Convert, Call> {
/// Write the instruction to the given stream /// Write the instruction to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
private: private:
const type::Type* from_ = nullptr; const type::Type* from_ = nullptr;

View File

@ -145,7 +145,7 @@ std::string Debug::AsDotGraph(const Module* mod) {
for (const auto* func : mod->functions) { for (const auto* func : mod->functions) {
// Cluster each function to label and draw a box around it. // Cluster each function to label and draw a box around it.
out << "subgraph cluster_" << name_for(func) << " {" << std::endl; out << "subgraph cluster_" << name_for(func) << " {" << std::endl;
out << R"(label=")" << mod->symbols.NameFor(func->name) << R"(")" << std::endl; out << R"(label=")" << func->name.Name() << R"(")" << std::endl;
out << name_for(func->start_target) << R"( [label="start"])" << std::endl; out << name_for(func->start_target) << R"( [label="start"])" << std::endl;
out << name_for(func->end_target) << R"( [label="end"])" << std::endl; out << name_for(func->end_target) << R"( [label="end"])" << std::endl;
Graph(func->start_target); Graph(func->start_target);

View File

@ -64,7 +64,7 @@ utils::StringStream& Disassembler::Indent() {
void Disassembler::EmitBlockInstructions(const Block* b) { void Disassembler::EmitBlockInstructions(const Block* b) {
for (const auto* instr : b->instructions) { for (const auto* instr : b->instructions) {
Indent(); Indent();
instr->ToString(out_, mod_.symbols) << std::endl; instr->ToString(out_) << std::endl;
} }
} }
@ -89,8 +89,7 @@ void Disassembler::Walk(const FlowNode* node) {
tint::Switch( tint::Switch(
node, node,
[&](const ir::Function* f) { [&](const ir::Function* f) {
Indent() << "%bb" << GetIdForNode(f) << " = Function " << mod_.symbols.NameFor(f->name) Indent() << "%bb" << GetIdForNode(f) << " = Function " << f->name.Name() << std::endl;
<< std::endl;
{ {
ScopedIndent func_indent(&indent_size_); ScopedIndent func_indent(&indent_size_);
@ -120,7 +119,7 @@ void Disassembler::Walk(const FlowNode* node) {
if (v != b->branch.args.Front()) { if (v != b->branch.args.Front()) {
out_ << ", "; out_ << ", ";
} }
v->ToString(out_, mod_.symbols); v->ToString(out_);
} }
out_ << ")" << std::endl; out_ << ")" << std::endl;
@ -132,7 +131,7 @@ void Disassembler::Walk(const FlowNode* node) {
}, },
[&](const ir::Switch* s) { [&](const ir::Switch* s) {
Indent() << "%bb" << GetIdForNode(s) << " = Switch ("; Indent() << "%bb" << GetIdForNode(s) << " = Switch (";
s->condition->ToString(out_, mod_.symbols); s->condition->ToString(out_);
out_ << ")" << std::endl; out_ << ")" << std::endl;
{ {
@ -148,7 +147,7 @@ void Disassembler::Walk(const FlowNode* node) {
if (selector.IsDefault()) { if (selector.IsDefault()) {
out_ << "default"; out_ << "default";
} else { } else {
selector.val->ToString(out_, mod_.symbols); selector.val->ToString(out_);
} }
} }
out_ << std::endl; out_ << std::endl;
@ -161,7 +160,7 @@ void Disassembler::Walk(const FlowNode* node) {
}, },
[&](const ir::If* i) { [&](const ir::If* i) {
Indent() << "%bb" << GetIdForNode(i) << " = if ("; Indent() << "%bb" << GetIdForNode(i) << " = if (";
i->condition->ToString(out_, mod_.symbols); i->condition->ToString(out_);
out_ << ")" << std::endl; out_ << ")" << std::endl;
{ {

View File

@ -38,10 +38,8 @@ class Instruction : public Castable<Instruction> {
/// Write the instruction to the given stream /// Write the instruction to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
virtual utils::StringStream& ToString(utils::StringStream& out, virtual utils::StringStream& ToString(utils::StringStream& out) const = 0;
const SymbolTable& st) const = 0;
protected: protected:
/// Constructor /// Constructor

View File

@ -24,8 +24,8 @@ Temp::Temp(const type::Type* type, Id id) : type_(type), id_(id) {}
Temp::~Temp() = default; Temp::~Temp() = default;
utils::StringStream& Temp::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& Temp::ToString(utils::StringStream& out) const {
out << "%" << std::to_string(AsId()) << " (" << type_->FriendlyName(st) << ")"; out << "%" << std::to_string(AsId()) << " (" << type_->FriendlyName() << ")";
return out; return out;
} }

View File

@ -49,9 +49,8 @@ class Temp : public Castable<Temp, Value> {
/// Write the temp to the given stream /// Write the temp to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
private: private:
const type::Type* type_ = nullptr; const type::Type* type_ = nullptr;

View File

@ -32,7 +32,7 @@ TEST_F(IR_TempTest, id) {
auto* val = b.builder.Temp(b.builder.ir.types.Get<type::I32>()); auto* val = b.builder.Temp(b.builder.ir.types.Get<type::I32>());
EXPECT_EQ(4u, val->AsId()); EXPECT_EQ(4u, val->AsId());
val->ToString(str, b.builder.ir.symbols); val->ToString(str);
EXPECT_EQ("%4 (i32)", str.str()); EXPECT_EQ("%4 (i32)", str.str());
} }

View File

@ -24,11 +24,11 @@ UserCall::UserCall(Value* result, Symbol name, utils::VectorRef<Value*> args)
UserCall::~UserCall() = default; UserCall::~UserCall() = default;
utils::StringStream& UserCall::ToString(utils::StringStream& out, const SymbolTable& st) const { utils::StringStream& UserCall::ToString(utils::StringStream& out) const {
Result()->ToString(out, st); Result()->ToString(out);
out << " = call("; out << " = call(";
out << st.NameFor(name_) << ", "; out << name_.Name() << ", ";
EmitArgs(out, st); EmitArgs(out);
out << ")"; out << ")";
return out; return out;
} }

View File

@ -43,9 +43,8 @@ class UserCall : public Castable<UserCall, Call> {
/// Write the instruction to the given stream /// Write the instruction to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
utils::StringStream& ToString(utils::StringStream& out, const SymbolTable& st) const override; utils::StringStream& ToString(utils::StringStream& out) const override;
private: private:
Symbol name_{}; Symbol name_{};

View File

@ -53,10 +53,8 @@ class Value : public Castable<Value> {
/// Write the value to the given stream /// Write the value to the given stream
/// @param out the stream to write to /// @param out the stream to write to
/// @param st the symbol table
/// @returns the stream /// @returns the stream
virtual utils::StringStream& ToString(utils::StringStream& out, virtual utils::StringStream& ToString(utils::StringStream& out) const = 0;
const SymbolTable& st) const = 0;
protected: protected:
/// Constructor /// Constructor

View File

@ -136,11 +136,11 @@ const type::Type* Program::TypeOf(const ast::TypeDecl* type_decl) const {
std::string Program::FriendlyName(ast::Type type) const { std::string Program::FriendlyName(ast::Type type) const {
TINT_ASSERT_PROGRAM_IDS_EQUAL(Program, type, ID()); TINT_ASSERT_PROGRAM_IDS_EQUAL(Program, type, ID());
return type ? Symbols().NameFor(type->identifier->symbol) : "<null>"; return type ? type->identifier->symbol.Name() : "<null>";
} }
std::string Program::FriendlyName(const type::Type* type) const { std::string Program::FriendlyName(const type::Type* type) const {
return type ? type->FriendlyName(Symbols()) : "<null>"; return type ? type->FriendlyName() : "<null>";
} }
std::string Program::FriendlyName(std::nullptr_t) const { std::string Program::FriendlyName(std::nullptr_t) const {

View File

@ -115,11 +115,11 @@ const type::Type* ProgramBuilder::TypeOf(const ast::TypeDecl* type_decl) const {
std::string ProgramBuilder::FriendlyName(ast::Type type) const { std::string ProgramBuilder::FriendlyName(ast::Type type) const {
TINT_ASSERT_PROGRAM_IDS_EQUAL(ProgramBuilder, type, ID()); TINT_ASSERT_PROGRAM_IDS_EQUAL(ProgramBuilder, type, ID());
return type.expr ? Symbols().NameFor(type->identifier->symbol) : "<null>"; return type.expr ? type->identifier->symbol.Name() : "<null>";
} }
std::string ProgramBuilder::FriendlyName(const type::Type* type) const { std::string ProgramBuilder::FriendlyName(const type::Type* type) const {
return type ? type->FriendlyName(Symbols()) : "<null>"; return type ? type->FriendlyName() : "<null>";
} }
std::string ProgramBuilder::FriendlyName(std::nullptr_t) const { std::string ProgramBuilder::FriendlyName(std::nullptr_t) const {

View File

@ -75,7 +75,7 @@ std::string ToString(const Program& program, const ast::Node* node) {
} }
return writer.result(); return writer.result();
}, },
[&](const ast::Identifier* ident) { return program.Symbols().NameFor(ident->symbol); }, [&](const ast::Identifier* ident) { return ident->symbol.Name(); },
[&](Default) { [&](Default) {
return "<unhandled AST node type " + std::string(node->TypeInfo().name) + ">"; return "<unhandled AST node type " + std::string(node->TypeInfo().name) + ">";
}); });

View File

@ -35,7 +35,7 @@ TEST_F(ParserImplTest, Statement_Call) {
ASSERT_TRUE(e->Is<ast::CallStatement>()); ASSERT_TRUE(e->Is<ast::CallStatement>());
auto* c = e->As<ast::CallStatement>()->expr; auto* c = e->As<ast::CallStatement>()->expr;
ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); ast::CheckIdentifier(c->target, "a");
EXPECT_EQ(c->args.Length(), 0u); EXPECT_EQ(c->args.Length(), 0u);
} }
@ -51,7 +51,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
ASSERT_TRUE(e->Is<ast::CallStatement>()); ASSERT_TRUE(e->Is<ast::CallStatement>());
auto* c = e->As<ast::CallStatement>()->expr; auto* c = e->As<ast::CallStatement>()->expr;
ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); ast::CheckIdentifier(c->target, "a");
EXPECT_EQ(c->args.Length(), 3u); EXPECT_EQ(c->args.Length(), 3u);
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>()); EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>());
@ -70,7 +70,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) {
ASSERT_TRUE(e->Is<ast::CallStatement>()); ASSERT_TRUE(e->Is<ast::CallStatement>());
auto* c = e->As<ast::CallStatement>()->expr; auto* c = e->As<ast::CallStatement>()->expr;
ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); ast::CheckIdentifier(c->target, "a");
EXPECT_EQ(c->args.Length(), 2u); EXPECT_EQ(c->args.Length(), 2u);
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>()); EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>());

View File

@ -30,7 +30,7 @@ TEST_F(ParserImplTest, DiagnosticAttribute_Valid) {
EXPECT_EQ(d->control.severity, builtin::DiagnosticSeverity::kOff); EXPECT_EQ(d->control.severity, builtin::DiagnosticSeverity::kOff);
auto* r = d->control.rule_name; auto* r = d->control.rule_name;
ASSERT_NE(r, nullptr); ASSERT_NE(r, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); ast::CheckIdentifier(r, "foo");
} }
} // namespace } // namespace

View File

@ -33,7 +33,7 @@ TEST_P(DiagnosticControlParserTest, DiagnosticControl_Valid) {
auto* r = e->rule_name; auto* r = e->rule_name;
ASSERT_NE(r, nullptr); ASSERT_NE(r, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); ast::CheckIdentifier(r, "foo");
} }
INSTANTIATE_TEST_SUITE_P(DiagnosticControlParserTest, INSTANTIATE_TEST_SUITE_P(DiagnosticControlParserTest,
DiagnosticControlParserTest, DiagnosticControlParserTest,
@ -52,7 +52,7 @@ TEST_F(ParserImplTest, DiagnosticControl_Valid_TrailingComma) {
auto* r = e->rule_name; auto* r = e->rule_name;
ASSERT_NE(r, nullptr); ASSERT_NE(r, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); ast::CheckIdentifier(r, "foo");
} }
TEST_F(ParserImplTest, DiagnosticControl_MissingOpenParen) { TEST_F(ParserImplTest, DiagnosticControl_MissingOpenParen) {

View File

@ -33,7 +33,7 @@ TEST_F(ParserImplTest, DiagnosticDirective_Valid) {
auto* r = directive->control.rule_name; auto* r = directive->control.rule_name;
ASSERT_NE(r, nullptr); ASSERT_NE(r, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); ast::CheckIdentifier(r, "foo");
} }
TEST_F(ParserImplTest, DiagnosticDirective_MissingSemicolon) { TEST_F(ParserImplTest, DiagnosticDirective_MissingSemicolon) {

View File

@ -311,7 +311,7 @@ TEST_F(ParserImplTest, Attribute_Workgroup_WithIdent) {
ast::IntLiteralExpression::Suffix::kNone); ast::IntLiteralExpression::Suffix::kNone);
ASSERT_NE(values[1], nullptr); ASSERT_NE(values[1], nullptr);
ast::CheckIdentifier(p->builder().Symbols(), values[1], "height"); ast::CheckIdentifier(values[1], "height");
ASSERT_EQ(values[2], nullptr); ASSERT_EQ(values[2], nullptr);
} }

View File

@ -241,7 +241,7 @@ TEST_F(ParserImplTest, FunctionDecl_ReturnTypeAttributeList) {
EXPECT_EQ(f->name->symbol, p->builder().Symbols().Get("main")); EXPECT_EQ(f->name->symbol, p->builder().Symbols().Get("main"));
ASSERT_NE(f->return_type, nullptr); ASSERT_NE(f->return_type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), f->return_type, "f32"); ast::CheckIdentifier(f->return_type, "f32");
ASSERT_EQ(f->params.Length(), 0u); ASSERT_EQ(f->params.Length(), 0u);

View File

@ -53,7 +53,7 @@ TEST_F(ParserImplTest, FunctionHeader_AttributeReturnType) {
EXPECT_EQ(f->name, "main"); EXPECT_EQ(f->name, "main");
EXPECT_EQ(f->params.Length(), 0u); EXPECT_EQ(f->params.Length(), 0u);
ast::CheckIdentifier(p->builder().Symbols(), f->return_type, "f32"); ast::CheckIdentifier(f->return_type, "f32");
ASSERT_EQ(f->return_type_attributes.Length(), 1u); ASSERT_EQ(f->return_type_attributes.Length(), 1u);
auto* loc = f->return_type_attributes[0]->As<ast::LocationAttribute>(); auto* loc = f->return_type_attributes[0]->As<ast::LocationAttribute>();
@ -72,7 +72,7 @@ TEST_F(ParserImplTest, FunctionHeader_InvariantReturnType) {
EXPECT_EQ(f->name, "main"); EXPECT_EQ(f->name, "main");
EXPECT_EQ(f->params.Length(), 0u); EXPECT_EQ(f->params.Length(), 0u);
ast::CheckIdentifier(p->builder().Symbols(), f->return_type, "f32"); ast::CheckIdentifier(f->return_type, "f32");
ASSERT_EQ(f->return_type_attributes.Length(), 1u); ASSERT_EQ(f->return_type_attributes.Length(), 1u);
EXPECT_TRUE(f->return_type_attributes[0]->Is<ast::InvariantAttribute>()); EXPECT_TRUE(f->return_type_attributes[0]->Is<ast::InvariantAttribute>());
} }

View File

@ -45,7 +45,7 @@ TEST_F(ParserImplTest, GlobalConstDecl) {
EXPECT_EQ(c->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(c->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(c->type, nullptr); ASSERT_NE(c->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), c->type, "f32"); ast::CheckIdentifier(c->type, "f32");
EXPECT_EQ(c->source.range.begin.line, 1u); EXPECT_EQ(c->source.range.begin.line, 1u);
EXPECT_EQ(c->source.range.begin.column, 7u); EXPECT_EQ(c->source.range.begin.column, 7u);
@ -121,7 +121,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId) {
EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(override->type, nullptr); ASSERT_NE(override->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), override->type, "f32"); ast::CheckIdentifier(override->type, "f32");
EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.line, 1u);
EXPECT_EQ(override->source.range.begin.column, 17u); EXPECT_EQ(override->source.range.begin.column, 17u);
@ -151,7 +151,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId_TrailingComma) {
EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(override->type, nullptr); ASSERT_NE(override->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), override->type, "f32"); ast::CheckIdentifier(override->type, "f32");
EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.line, 1u);
EXPECT_EQ(override->source.range.begin.column, 18u); EXPECT_EQ(override->source.range.begin.column, 18u);
@ -181,7 +181,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithoutId) {
EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(override->type, nullptr); ASSERT_NE(override->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), override->type, "f32"); ast::CheckIdentifier(override->type, "f32");
EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.line, 1u);
EXPECT_EQ(override->source.range.begin.column, 10u); EXPECT_EQ(override->source.range.begin.column, 10u);

View File

@ -34,7 +34,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) {
auto* v = program.AST().GlobalVariables()[0]; auto* v = program.AST().GlobalVariables()[0];
EXPECT_EQ(v->name->symbol, program.Symbols().Get("a")); EXPECT_EQ(v->name->symbol, program.Symbols().Get("a"));
ast::CheckIdentifier(program.Symbols(), v->type, ast::Template("vec2", "i32")); ast::CheckIdentifier(v->type, ast::Template("vec2", "i32"));
} }
TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Inferred) { TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Inferred) {
@ -107,8 +107,7 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().TypeDecls().Length(), 1u); ASSERT_EQ(program.AST().TypeDecls().Length(), 1u);
ASSERT_TRUE(program.AST().TypeDecls()[0]->Is<ast::Alias>()); ASSERT_TRUE(program.AST().TypeDecls()[0]->Is<ast::Alias>());
ast::CheckIdentifier(program.Symbols(), program.AST().TypeDecls()[0]->As<ast::Alias>()->name, ast::CheckIdentifier(program.AST().TypeDecls()[0]->As<ast::Alias>()->name, "A");
"A");
} }
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) { TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) {
@ -129,7 +128,7 @@ alias B = A;)");
ASSERT_TRUE(program.AST().TypeDecls()[1]->Is<ast::Alias>()); ASSERT_TRUE(program.AST().TypeDecls()[1]->Is<ast::Alias>());
auto* alias = program.AST().TypeDecls()[1]->As<ast::Alias>(); auto* alias = program.AST().TypeDecls()[1]->As<ast::Alias>();
EXPECT_EQ(alias->name->symbol, program.Symbols().Get("B")); EXPECT_EQ(alias->name->symbol, program.Symbols().Get("B"));
ast::CheckIdentifier(program.Symbols(), alias->type, "A"); ast::CheckIdentifier(alias->type, "A");
} }
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_MissingSemicolon) { TEST_F(ParserImplTest, GlobalDecl_TypeAlias_MissingSemicolon) {
@ -146,7 +145,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function) {
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().Functions().Length(), 1u); ASSERT_EQ(program.AST().Functions().Length(), 1u);
ast::CheckIdentifier(program.Symbols(), program.AST().Functions()[0]->name, "main"); ast::CheckIdentifier(program.AST().Functions()[0]->name, "main");
} }
TEST_F(ParserImplTest, GlobalDecl_Function_WithAttribute) { TEST_F(ParserImplTest, GlobalDecl_Function_WithAttribute) {
@ -156,7 +155,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithAttribute) {
auto program = p->program(); auto program = p->program();
ASSERT_EQ(program.AST().Functions().Length(), 1u); ASSERT_EQ(program.AST().Functions().Length(), 1u);
ast::CheckIdentifier(program.Symbols(), program.AST().Functions()[0]->name, "main"); ast::CheckIdentifier(program.AST().Functions()[0]->name, "main");
} }
TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) { TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) {

View File

@ -30,9 +30,9 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) {
auto* var = e.value->As<ast::Var>(); auto* var = e.value->As<ast::Var>();
ASSERT_NE(var, nullptr); ASSERT_NE(var, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); ast::CheckIdentifier(var->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); ast::CheckIdentifier(var->type, "f32");
ast::CheckIdentifier(p->builder().Symbols(), var->declared_address_space, "private"); ast::CheckIdentifier(var->declared_address_space, "private");
EXPECT_EQ(var->source.range.begin.line, 1u); EXPECT_EQ(var->source.range.begin.line, 1u);
EXPECT_EQ(var->source.range.begin.column, 14u); EXPECT_EQ(var->source.range.begin.column, 14u);
@ -54,9 +54,9 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) {
auto* var = e.value->As<ast::Var>(); auto* var = e.value->As<ast::Var>();
ASSERT_NE(var, nullptr); ASSERT_NE(var, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); ast::CheckIdentifier(var->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); ast::CheckIdentifier(var->type, "f32");
ast::CheckIdentifier(p->builder().Symbols(), var->declared_address_space, "private"); ast::CheckIdentifier(var->declared_address_space, "private");
EXPECT_EQ(var->source.range.begin.line, 1u); EXPECT_EQ(var->source.range.begin.line, 1u);
EXPECT_EQ(var->source.range.begin.column, 14u); EXPECT_EQ(var->source.range.begin.column, 14u);
@ -79,9 +79,9 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute) {
auto* var = e.value->As<ast::Var>(); auto* var = e.value->As<ast::Var>();
ASSERT_NE(var, nullptr); ASSERT_NE(var, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); ast::CheckIdentifier(var->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); ast::CheckIdentifier(var->type, "f32");
ast::CheckIdentifier(p->builder().Symbols(), var->declared_address_space, "uniform"); ast::CheckIdentifier(var->declared_address_space, "uniform");
EXPECT_EQ(var->source.range.begin.line, 1u); EXPECT_EQ(var->source.range.begin.line, 1u);
EXPECT_EQ(var->source.range.begin.column, 36u); EXPECT_EQ(var->source.range.begin.column, 36u);
@ -109,9 +109,9 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute_MulitpleGroups) {
auto* var = e.value->As<ast::Var>(); auto* var = e.value->As<ast::Var>();
ASSERT_NE(var, nullptr); ASSERT_NE(var, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); ast::CheckIdentifier(var->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); ast::CheckIdentifier(var->type, "f32");
ast::CheckIdentifier(p->builder().Symbols(), var->declared_address_space, "uniform"); ast::CheckIdentifier(var->declared_address_space, "uniform");
EXPECT_EQ(var->source.range.begin.line, 1u); EXPECT_EQ(var->source.range.begin.line, 1u);
EXPECT_EQ(var->source.range.begin.column, 36u); EXPECT_EQ(var->source.range.begin.column, 36u);

View File

@ -27,7 +27,7 @@ TEST_F(ParserImplTest, ParamList_Single) {
EXPECT_EQ(e.value.Length(), 1u); EXPECT_EQ(e.value.Length(), 1u);
EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a"));
ast::CheckIdentifier(p->builder().Symbols(), e.value[0]->type, "i32"); ast::CheckIdentifier(e.value[0]->type, "i32");
EXPECT_TRUE(e.value[0]->Is<ast::Parameter>()); EXPECT_TRUE(e.value[0]->Is<ast::Parameter>());
ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u);
@ -45,7 +45,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
EXPECT_EQ(e.value.Length(), 3u); EXPECT_EQ(e.value.Length(), 3u);
EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a"));
ast::CheckIdentifier(p->builder().Symbols(), e.value[0]->type, "i32"); ast::CheckIdentifier(e.value[0]->type, "i32");
EXPECT_TRUE(e.value[0]->Is<ast::Parameter>()); EXPECT_TRUE(e.value[0]->Is<ast::Parameter>());
ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u);
@ -54,7 +54,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
ASSERT_EQ(e.value[0]->source.range.end.column, 2u); ASSERT_EQ(e.value[0]->source.range.end.column, 2u);
EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("b")); EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("b"));
ast::CheckIdentifier(p->builder().Symbols(), e.value[1]->type, "f32"); ast::CheckIdentifier(e.value[1]->type, "f32");
EXPECT_TRUE(e.value[1]->Is<ast::Parameter>()); EXPECT_TRUE(e.value[1]->Is<ast::Parameter>());
ASSERT_EQ(e.value[1]->source.range.begin.line, 1u); ASSERT_EQ(e.value[1]->source.range.begin.line, 1u);
@ -63,7 +63,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
ASSERT_EQ(e.value[1]->source.range.end.column, 11u); ASSERT_EQ(e.value[1]->source.range.end.column, 11u);
EXPECT_EQ(e.value[2]->name->symbol, p->builder().Symbols().Get("c")); EXPECT_EQ(e.value[2]->name->symbol, p->builder().Symbols().Get("c"));
ast::CheckIdentifier(p->builder().Symbols(), e.value[2]->type, ast::Template("vec2", "f32")); ast::CheckIdentifier(e.value[2]->type, ast::Template("vec2", "f32"));
EXPECT_TRUE(e.value[2]->Is<ast::Parameter>()); EXPECT_TRUE(e.value[2]->Is<ast::Parameter>());
ASSERT_EQ(e.value[2]->source.range.begin.line, 1u); ASSERT_EQ(e.value[2]->source.range.begin.line, 1u);
@ -97,13 +97,12 @@ TEST_F(ParserImplTest, ParamList_Attributes) {
ASSERT_EQ(e.value.Length(), 2u); ASSERT_EQ(e.value.Length(), 2u);
EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("coord")); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("coord"));
ast::CheckIdentifier(p->builder().Symbols(), e.value[0]->type, ast::Template("vec4", "f32")); ast::CheckIdentifier(e.value[0]->type, ast::Template("vec4", "f32"));
EXPECT_TRUE(e.value[0]->Is<ast::Parameter>()); EXPECT_TRUE(e.value[0]->Is<ast::Parameter>());
auto attrs_0 = e.value[0]->attributes; auto attrs_0 = e.value[0]->attributes;
ASSERT_EQ(attrs_0.Length(), 1u); ASSERT_EQ(attrs_0.Length(), 1u);
EXPECT_TRUE(attrs_0[0]->Is<ast::BuiltinAttribute>()); EXPECT_TRUE(attrs_0[0]->Is<ast::BuiltinAttribute>());
ast::CheckIdentifier(p->builder().Symbols(), attrs_0[0]->As<ast::BuiltinAttribute>()->builtin, ast::CheckIdentifier(attrs_0[0]->As<ast::BuiltinAttribute>()->builtin, "position");
"position");
ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u);
ASSERT_EQ(e.value[0]->source.range.begin.column, 20u); ASSERT_EQ(e.value[0]->source.range.begin.column, 20u);
@ -111,7 +110,7 @@ TEST_F(ParserImplTest, ParamList_Attributes) {
ASSERT_EQ(e.value[0]->source.range.end.column, 25u); ASSERT_EQ(e.value[0]->source.range.end.column, 25u);
EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("loc1")); EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("loc1"));
ast::CheckIdentifier(p->builder().Symbols(), e.value[1]->type, "f32"); ast::CheckIdentifier(e.value[1]->type, "f32");
EXPECT_TRUE(e.value[1]->Is<ast::Parameter>()); EXPECT_TRUE(e.value[1]->Is<ast::Parameter>());
auto attrs_1 = e.value[1]->attributes; auto attrs_1 = e.value[1]->attributes;
ASSERT_EQ(attrs_1.Length(), 1u); ASSERT_EQ(attrs_1.Length(), 1u);

View File

@ -27,7 +27,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) {
EXPECT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->Is<ast::IdentifierExpression>()); ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
ast::CheckIdentifier(p->builder().Symbols(), e.value, "a"); ast::CheckIdentifier(e.value, "a");
} }
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {
@ -116,7 +116,7 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructInitializer_Empty) {
auto* call = e->As<ast::CallExpression>(); auto* call = e->As<ast::CallExpression>();
ASSERT_NE(call->target, nullptr); ASSERT_NE(call->target, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), call->target, "S"); ast::CheckIdentifier(call->target, "S");
ASSERT_EQ(call->args.Length(), 0u); ASSERT_EQ(call->args.Length(), 0u);
} }
@ -140,7 +140,7 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructInitializer_NotEmpty) {
auto* call = e->As<ast::CallExpression>(); auto* call = e->As<ast::CallExpression>();
ASSERT_NE(call->target, nullptr); ASSERT_NE(call->target, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), call->target, "S"); ast::CheckIdentifier(call->target, "S");
ASSERT_EQ(call->args.Length(), 2u); ASSERT_EQ(call->args.Length(), 2u);
@ -215,7 +215,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
ASSERT_TRUE(e->Is<ast::CallExpression>()); ASSERT_TRUE(e->Is<ast::CallExpression>());
auto* call = e->As<ast::CallExpression>(); auto* call = e->As<ast::CallExpression>();
ast::CheckIdentifier(p->builder().Symbols(), call->target, "f32"); ast::CheckIdentifier(call->target, "f32");
ASSERT_EQ(call->args.Length(), 1u); ASSERT_EQ(call->args.Length(), 1u);
ASSERT_TRUE(call->args[0]->Is<ast::IntLiteralExpression>()); ASSERT_TRUE(call->args[0]->Is<ast::IntLiteralExpression>());
@ -233,7 +233,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
auto* c = e->As<ast::BitcastExpression>(); auto* c = e->As<ast::BitcastExpression>();
ast::CheckIdentifier(p->builder().Symbols(), c->type, "f32"); ast::CheckIdentifier(c->type, "f32");
ASSERT_TRUE(c->expr->Is<ast::IntLiteralExpression>()); ASSERT_TRUE(c->expr->Is<ast::IntLiteralExpression>());
} }

View File

@ -98,7 +98,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_Empty) {
ASSERT_TRUE(e->Is<ast::CallExpression>()); ASSERT_TRUE(e->Is<ast::CallExpression>());
auto* c = e->As<ast::CallExpression>(); auto* c = e->As<ast::CallExpression>();
ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); ast::CheckIdentifier(c->target, "a");
EXPECT_EQ(c->args.Length(), 0u); EXPECT_EQ(c->args.Length(), 0u);
} }
@ -114,7 +114,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) {
ASSERT_TRUE(e->Is<ast::CallExpression>()); ASSERT_TRUE(e->Is<ast::CallExpression>());
auto* c = e->As<ast::CallExpression>(); auto* c = e->As<ast::CallExpression>();
ast::CheckIdentifier(p->builder().Symbols(), c->target, "test"); ast::CheckIdentifier(c->target, "test");
EXPECT_EQ(c->args.Length(), 3u); EXPECT_EQ(c->args.Length(), 3u);
EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>()); EXPECT_TRUE(c->args[0]->Is<ast::IntLiteralExpression>());

View File

@ -30,7 +30,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) {
const auto* mem = m.value[0]; const auto* mem = m.value[0];
EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a")); EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a"));
ast::CheckIdentifier(p->builder().Symbols(), mem->type, "i32"); ast::CheckIdentifier(mem->type, "i32");
EXPECT_EQ(mem->attributes.Length(), 0u); EXPECT_EQ(mem->attributes.Length(), 0u);
} }
@ -46,7 +46,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses_TrailingComma) {
const auto* mem = m.value[0]; const auto* mem = m.value[0];
EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a")); EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a"));
ast::CheckIdentifier(p->builder().Symbols(), mem->type, "i32"); ast::CheckIdentifier(mem->type, "i32");
EXPECT_EQ(mem->attributes.Length(), 0u); EXPECT_EQ(mem->attributes.Length(), 0u);
} }

View File

@ -26,8 +26,8 @@ TEST_F(ParserImplTest, StructMember_Parses) {
ASSERT_FALSE(m.errored); ASSERT_FALSE(m.errored);
ASSERT_NE(m.value, nullptr); ASSERT_NE(m.value, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); ast::CheckIdentifier(m->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); ast::CheckIdentifier(m->type, "i32");
EXPECT_EQ(m->attributes.Length(), 0u); EXPECT_EQ(m->attributes.Length(), 0u);
EXPECT_EQ(m->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); EXPECT_EQ(m->source.range, (Source::Range{{1u, 1u}, {1u, 2u}}));
@ -42,8 +42,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithAlignAttribute) {
ASSERT_FALSE(m.errored); ASSERT_FALSE(m.errored);
ASSERT_NE(m.value, nullptr); ASSERT_NE(m.value, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); ast::CheckIdentifier(m->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); ast::CheckIdentifier(m->type, "i32");
EXPECT_EQ(m->attributes.Length(), 1u); EXPECT_EQ(m->attributes.Length(), 1u);
EXPECT_TRUE(m->attributes[0]->Is<ast::StructMemberAlignAttribute>()); EXPECT_TRUE(m->attributes[0]->Is<ast::StructMemberAlignAttribute>());
@ -65,8 +65,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithSizeAttribute) {
ASSERT_FALSE(m.errored); ASSERT_FALSE(m.errored);
ASSERT_NE(m.value, nullptr); ASSERT_NE(m.value, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); ast::CheckIdentifier(m->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); ast::CheckIdentifier(m->type, "i32");
EXPECT_EQ(m->attributes.Length(), 1u); EXPECT_EQ(m->attributes.Length(), 1u);
ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>()); ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>());
auto* s = m->attributes[0]->As<ast::StructMemberSizeAttribute>(); auto* s = m->attributes[0]->As<ast::StructMemberSizeAttribute>();
@ -87,8 +87,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleattributes) {
ASSERT_FALSE(m.errored); ASSERT_FALSE(m.errored);
ASSERT_NE(m.value, nullptr); ASSERT_NE(m.value, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); ast::CheckIdentifier(m->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); ast::CheckIdentifier(m->type, "i32");
EXPECT_EQ(m->attributes.Length(), 2u); EXPECT_EQ(m->attributes.Length(), 2u);
ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>()); ASSERT_TRUE(m->attributes[0]->Is<ast::StructMemberSizeAttribute>());
auto* size_attr = m->attributes[0]->As<ast::StructMemberSizeAttribute>(); auto* size_attr = m->attributes[0]->As<ast::StructMemberSizeAttribute>();

View File

@ -28,7 +28,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<ast::Alias>()); ASSERT_TRUE(t->Is<ast::Alias>());
auto* alias = t->As<ast::Alias>(); auto* alias = t->As<ast::Alias>();
ast::CheckIdentifier(p->builder().Symbols(), alias->type, "i32"); ast::CheckIdentifier(alias->type, "i32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}}));
} }
@ -42,8 +42,8 @@ TEST_F(ParserImplTest, TypeDecl_Parses_Ident) {
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t.value->Is<ast::Alias>()); ASSERT_TRUE(t.value->Is<ast::Alias>());
auto* alias = t.value->As<ast::Alias>(); auto* alias = t.value->As<ast::Alias>();
ast::CheckIdentifier(p->builder().Symbols(), alias->name, "a"); ast::CheckIdentifier(alias->name, "a");
ast::CheckIdentifier(p->builder().Symbols(), alias->type, "B"); ast::CheckIdentifier(alias->type, "B");
EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 12u}})); EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 12u}}));
} }
@ -61,8 +61,8 @@ TEST_F(ParserImplTest, TypeDecl_Unicode_Parses_Ident) {
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t.value->Is<ast::Alias>()); ASSERT_TRUE(t.value->Is<ast::Alias>());
auto* alias = t.value->As<ast::Alias>(); auto* alias = t.value->As<ast::Alias>();
ast::CheckIdentifier(p->builder().Symbols(), alias->name, ident); ast::CheckIdentifier(alias->name, ident);
ast::CheckIdentifier(p->builder().Symbols(), alias->type, "i32"); ast::CheckIdentifier(alias->type, "i32");
EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 38u}})); EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 38u}}));
} }

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ast::CheckIdentifier(p->builder().Symbols(), t.value, "A"); ast::CheckIdentifier(t.value, "A");
EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 2u}}));
} }
@ -49,7 +49,7 @@ TEST_F(ParserImplTest, TypeDecl_Bool) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ast::CheckIdentifier(p->builder().Symbols(), t.value, "bool"); ast::CheckIdentifier(t.value, "bool");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}}));
} }
@ -60,7 +60,7 @@ TEST_F(ParserImplTest, TypeDecl_F16) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ast::CheckIdentifier(p->builder().Symbols(), t.value, "f16"); ast::CheckIdentifier(t.value, "f16");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
} }
@ -71,7 +71,7 @@ TEST_F(ParserImplTest, TypeDecl_F32) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ast::CheckIdentifier(p->builder().Symbols(), t.value, "f32"); ast::CheckIdentifier(t.value, "f32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
} }
@ -82,7 +82,7 @@ TEST_F(ParserImplTest, TypeDecl_I32) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ast::CheckIdentifier(p->builder().Symbols(), t.value, "i32"); ast::CheckIdentifier(t.value, "i32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
} }
@ -93,7 +93,7 @@ TEST_F(ParserImplTest, TypeDecl_U32) {
EXPECT_TRUE(t.matched); EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ast::CheckIdentifier(p->builder().Symbols(), t.value, "u32"); ast::CheckIdentifier(t.value, "u32");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}}));
} }
@ -117,8 +117,7 @@ TEST_P(VecTest, Parse) {
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::CheckIdentifier(t.value, ast::Template("vec" + std::to_string(params.count), "f32"));
ast::Template("vec" + std::to_string(params.count), "f32"));
EXPECT_EQ(t.value->source.range, params.range); EXPECT_EQ(t.value->source.range, params.range);
} }
INSTANTIATE_TEST_SUITE_P(ParserImplTest, INSTANTIATE_TEST_SUITE_P(ParserImplTest,
@ -153,7 +152,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("ptr", "function", "f32")); ast::CheckIdentifier(t.value, ast::Template("ptr", "function", "f32"));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}}));
} }
@ -165,8 +164,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_WithAccess) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::CheckIdentifier(t.value, ast::Template("ptr", "function", "f32", "read"));
ast::Template("ptr", "function", "f32", "read"));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}}));
} }
@ -178,8 +176,7 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::CheckIdentifier(t.value, ast::Template("ptr", "function", ast::Template("vec2", "f32")));
ast::Template("ptr", "function", ast::Template("vec2", "f32")));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25}}));
} }
@ -232,7 +229,7 @@ TEST_F(ParserImplTest, TypeDecl_Atomic) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("atomic", "f32")); ast::CheckIdentifier(t.value, ast::Template("atomic", "f32"));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}}));
} }
@ -244,8 +241,7 @@ TEST_F(ParserImplTest, TypeDecl_Atomic_ToVec) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::CheckIdentifier(t.value, ast::Template("atomic", ast::Template("vec2", "f32")));
ast::Template("atomic", ast::Template("vec2", "f32")));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}}));
} }
@ -267,7 +263,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_AbstractIntLiteralSize) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_a)); ast::CheckIdentifier(t.value, ast::Template("array", "f32", 5_a));
} }
TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) { TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) {
@ -278,7 +274,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_i)); ast::CheckIdentifier(t.value, ast::Template("array", "f32", 5_i));
} }
TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) { TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) {
@ -289,7 +285,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_u)); ast::CheckIdentifier(t.value, ast::Template("array", "f32", 5_u));
} }
TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) { TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) {
@ -300,7 +296,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", "size")); ast::CheckIdentifier(t.value, ast::Template("array", "f32", "size"));
} }
TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) { TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) {
@ -311,17 +307,15 @@ TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
auto name_for = [&](const Symbol& sym) { return p->builder().Symbols().NameFor(sym); };
auto* arr = t->expr->identifier->As<ast::TemplatedIdentifier>(); auto* arr = t->expr->identifier->As<ast::TemplatedIdentifier>();
EXPECT_EQ(name_for(arr->symbol), "array"); EXPECT_EQ(arr->symbol.Name(), "array");
EXPECT_TRUE(arr->attributes.IsEmpty()); EXPECT_TRUE(arr->attributes.IsEmpty());
ASSERT_EQ(arr->arguments.Length(), 2u); ASSERT_EQ(arr->arguments.Length(), 2u);
auto* ty = As<ast::IdentifierExpression>(arr->arguments[0]); auto* ty = As<ast::IdentifierExpression>(arr->arguments[0]);
ASSERT_NE(ty, nullptr); ASSERT_NE(ty, nullptr);
EXPECT_EQ(name_for(ty->identifier->symbol), "f32"); EXPECT_EQ(ty->identifier->symbol.Name(), "f32");
auto* count = As<ast::BinaryExpression>(arr->arguments[1]); auto* count = As<ast::BinaryExpression>(arr->arguments[1]);
ASSERT_NE(count, nullptr); ASSERT_NE(count, nullptr);
@ -329,7 +323,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) {
auto* count_lhs = As<ast::IdentifierExpression>(count->lhs); auto* count_lhs = As<ast::IdentifierExpression>(count->lhs);
ASSERT_NE(count_lhs, nullptr); ASSERT_NE(count_lhs, nullptr);
EXPECT_EQ(name_for(count_lhs->identifier->symbol), "size"); EXPECT_EQ(count_lhs->identifier->symbol.Name(), "size");
auto* count_rhs = As<ast::IntLiteralExpression>(count->rhs); auto* count_rhs = As<ast::IntLiteralExpression>(count->rhs);
ASSERT_NE(count_rhs, nullptr); ASSERT_NE(count_rhs, nullptr);
@ -344,7 +338,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "u32")); ast::CheckIdentifier(t.value, ast::Template("array", "u32"));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}}));
} }
@ -356,8 +350,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) {
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::CheckIdentifier(t.value, ast::Template("array", ast::Template("vec4", "u32")));
ast::Template("array", ast::Template("vec4", "u32")));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}}));
} }
@ -406,7 +399,7 @@ TEST_P(MatrixTest, Parse) {
std::string expected_name = std::string expected_name =
"mat" + std::to_string(GetParam().columns) + "x" + std::to_string(GetParam().rows); "mat" + std::to_string(GetParam().columns) + "x" + std::to_string(GetParam().rows);
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template(expected_name, "f32")); ast::CheckIdentifier(t.value, ast::Template(expected_name, "f32"));
EXPECT_EQ(t.value->source.range, params.range); EXPECT_EQ(t.value->source.range, params.range);
} }
INSTANTIATE_TEST_SUITE_P(ParserImplTest, INSTANTIATE_TEST_SUITE_P(ParserImplTest,
@ -453,7 +446,7 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) {
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ast::CheckIdentifier(p->builder().Symbols(), t.value, "sampler"); ast::CheckIdentifier(t.value, "sampler");
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}}));
} }
@ -465,7 +458,7 @@ TEST_F(ParserImplTest, TypeDecl_Texture) {
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_cube", "f32")); ast::CheckIdentifier(t.value, ast::Template("texture_cube", "f32"));
EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}}));
} }

View File

@ -39,8 +39,7 @@ TEST_F(ParserImplTest, AttributeList_Parses) {
EXPECT_EQ(exp->value, 4u); EXPECT_EQ(exp->value, 4u);
ASSERT_TRUE(attr_1->Is<ast::BuiltinAttribute>()); ASSERT_TRUE(attr_1->Is<ast::BuiltinAttribute>());
ast::CheckIdentifier(p->builder().Symbols(), attr_1->As<ast::BuiltinAttribute>()->builtin, ast::CheckIdentifier(attr_1->As<ast::BuiltinAttribute>()->builtin, "position");
"position");
} }
TEST_F(ParserImplTest, AttributeList_Invalid) { TEST_F(ParserImplTest, AttributeList_Invalid) {

View File

@ -233,7 +233,7 @@ TEST_P(BuiltinTest, Attribute_Builtin) {
ASSERT_TRUE(var_attr->Is<ast::BuiltinAttribute>()); ASSERT_TRUE(var_attr->Is<ast::BuiltinAttribute>());
auto* builtin = var_attr->As<ast::BuiltinAttribute>(); auto* builtin = var_attr->As<ast::BuiltinAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), builtin->builtin, str); ast::CheckIdentifier(builtin->builtin, str);
} }
TEST_P(BuiltinTest, Attribute_Builtin_TrailingComma) { TEST_P(BuiltinTest, Attribute_Builtin_TrailingComma) {
auto str = utils::ToString(GetParam()); auto str = utils::ToString(GetParam());
@ -249,7 +249,7 @@ TEST_P(BuiltinTest, Attribute_Builtin_TrailingComma) {
ASSERT_TRUE(var_attr->Is<ast::BuiltinAttribute>()); ASSERT_TRUE(var_attr->Is<ast::BuiltinAttribute>());
auto* builtin = var_attr->As<ast::BuiltinAttribute>(); auto* builtin = var_attr->As<ast::BuiltinAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), builtin->builtin, str); ast::CheckIdentifier(builtin->builtin, str);
} }
INSTANTIATE_TEST_SUITE_P(ParserImplTest, INSTANTIATE_TEST_SUITE_P(ParserImplTest,
BuiltinTest, BuiltinTest,
@ -308,7 +308,7 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Flat) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>()); ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>(); auto* interp = var_attr->As<ast::InterpolateAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), interp->type, "flat"); ast::CheckIdentifier(interp->type, "flat");
EXPECT_EQ(interp->sampling, nullptr); EXPECT_EQ(interp->sampling, nullptr);
} }
@ -324,7 +324,7 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Single_TrailingComma) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>()); ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>(); auto* interp = var_attr->As<ast::InterpolateAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), interp->type, "flat"); ast::CheckIdentifier(interp->type, "flat");
EXPECT_EQ(interp->sampling, nullptr); EXPECT_EQ(interp->sampling, nullptr);
} }
@ -350,8 +350,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Center) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>()); ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>(); auto* interp = var_attr->As<ast::InterpolateAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), interp->type, "perspective"); ast::CheckIdentifier(interp->type, "perspective");
ast::CheckIdentifier(p->builder().Symbols(), interp->sampling, "center"); ast::CheckIdentifier(interp->sampling, "center");
} }
TEST_F(ParserImplTest, Attribute_Interpolate_Double_TrailingComma) { TEST_F(ParserImplTest, Attribute_Interpolate_Double_TrailingComma) {
@ -366,8 +366,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Double_TrailingComma) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>()); ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>(); auto* interp = var_attr->As<ast::InterpolateAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), interp->type, "perspective"); ast::CheckIdentifier(interp->type, "perspective");
ast::CheckIdentifier(p->builder().Symbols(), interp->sampling, "center"); ast::CheckIdentifier(interp->sampling, "center");
} }
TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Centroid) { TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Centroid) {
@ -382,8 +382,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Centroid) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>()); ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>(); auto* interp = var_attr->As<ast::InterpolateAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), interp->type, "perspective"); ast::CheckIdentifier(interp->type, "perspective");
ast::CheckIdentifier(p->builder().Symbols(), interp->sampling, "centroid"); ast::CheckIdentifier(interp->sampling, "centroid");
} }
TEST_F(ParserImplTest, Attribute_Interpolate_Linear_Sample) { TEST_F(ParserImplTest, Attribute_Interpolate_Linear_Sample) {
@ -398,8 +398,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Linear_Sample) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>()); ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>(); auto* interp = var_attr->As<ast::InterpolateAttribute>();
ast::CheckIdentifier(p->builder().Symbols(), interp->type, "linear"); ast::CheckIdentifier(interp->type, "linear");
ast::CheckIdentifier(p->builder().Symbols(), interp->sampling, "sample"); ast::CheckIdentifier(interp->sampling, "sample");
} }
TEST_F(ParserImplTest, Attribute_Interpolate_MissingLeftParen) { TEST_F(ParserImplTest, Attribute_Interpolate_MissingLeftParen) {

View File

@ -26,7 +26,7 @@ TEST_F(ParserImplTest, VariableDecl_Parses) {
EXPECT_EQ(v->name, "my_var"); EXPECT_EQ(v->name, "my_var");
EXPECT_NE(v->type, nullptr); EXPECT_NE(v->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); ast::CheckIdentifier(v->type, "f32");
EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 11u}})); EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 11u}}));
EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 14u}, {1u, 17u}})); EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 14u}, {1u, 17u}}));
@ -46,7 +46,7 @@ TEST_F(ParserImplTest, VariableDecl_Unicode_Parses) {
EXPECT_EQ(v->name, ident); EXPECT_EQ(v->name, ident);
EXPECT_NE(v->type, nullptr); EXPECT_NE(v->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); ast::CheckIdentifier(v->type, "f32");
EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 48u}})); EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 48u}}));
EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 51u}, {1u, 54u}})); EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 51u}, {1u, 54u}}));
@ -83,8 +83,8 @@ TEST_F(ParserImplTest, VariableDecl_WithAddressSpace) {
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
EXPECT_EQ(v->name, "my_var"); EXPECT_EQ(v->name, "my_var");
ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); ast::CheckIdentifier(v->type, "f32");
ast::CheckIdentifier(p->builder().Symbols(), v->address_space, "private"); ast::CheckIdentifier(v->address_space, "private");
EXPECT_EQ(v->source.range.begin.line, 1u); EXPECT_EQ(v->source.range.begin.line, 1u);
EXPECT_EQ(v->source.range.begin.column, 14u); EXPECT_EQ(v->source.range.begin.column, 14u);
@ -100,8 +100,8 @@ TEST_F(ParserImplTest, VariableDecl_WithPushConstant) {
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
EXPECT_EQ(v->name, "my_var"); EXPECT_EQ(v->name, "my_var");
ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); ast::CheckIdentifier(v->type, "f32");
ast::CheckIdentifier(p->builder().Symbols(), v->address_space, "push_constant"); ast::CheckIdentifier(v->address_space, "push_constant");
} }
} // namespace } // namespace

View File

@ -25,7 +25,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses) {
ASSERT_FALSE(decl.errored); ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var"); ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr); ASSERT_NE(decl->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), decl->type, "f32"); ast::CheckIdentifier(decl->type, "f32");
EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}})); EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}}));
EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}})); EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}}));
@ -38,7 +38,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses_AllowInferredType) {
ASSERT_FALSE(decl.errored); ASSERT_FALSE(decl.errored);
ASSERT_EQ(decl->name, "my_var"); ASSERT_EQ(decl->name, "my_var");
ASSERT_NE(decl->type, nullptr); ASSERT_NE(decl->type, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), decl->type, "f32"); ast::CheckIdentifier(decl->type, "f32");
EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}})); EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}}));
EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}})); EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}}));

View File

@ -39,13 +39,12 @@ TEST_P(VariableQualifierTest, ParsesAddressSpace) {
EXPECT_FALSE(sc.errored); EXPECT_FALSE(sc.errored);
EXPECT_TRUE(sc.matched); EXPECT_TRUE(sc.matched);
if (params.address_space != builtin::AddressSpace::kUndefined) { if (params.address_space != builtin::AddressSpace::kUndefined) {
ast::CheckIdentifier(p->builder().Symbols(), sc->address_space, ast::CheckIdentifier(sc->address_space, utils::ToString(params.address_space));
utils::ToString(params.address_space));
} else { } else {
EXPECT_EQ(sc->address_space, nullptr); EXPECT_EQ(sc->address_space, nullptr);
} }
if (params.access != builtin::Access::kUndefined) { if (params.access != builtin::Access::kUndefined) {
ast::CheckIdentifier(p->builder().Symbols(), sc->access, utils::ToString(params.access)); ast::CheckIdentifier(sc->access, utils::ToString(params.access));
} else { } else {
EXPECT_EQ(sc->access, nullptr); EXPECT_EQ(sc->access, nullptr);
} }

View File

@ -81,7 +81,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) {
ASSERT_NE(e->variable->initializer, nullptr); ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>(); auto* call = e->variable->initializer->As<ast::CallExpression>();
ASSERT_NE(call, nullptr); ASSERT_NE(call, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("array", "i32")); ast::CheckIdentifier(call->target, ast::Template("array", "i32"));
} }
TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) { TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) {
@ -98,7 +98,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) {
ASSERT_NE(e->variable->initializer, nullptr); ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>(); auto* call = e->variable->initializer->As<ast::CallExpression>();
ASSERT_NE(call, nullptr); ASSERT_NE(call, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("array", "i32")); ast::CheckIdentifier(call->target, ast::Template("array", "i32"));
} }
TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) { TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) {
@ -114,7 +114,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) {
ASSERT_NE(e->variable->initializer, nullptr); ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>(); auto* call = e->variable->initializer->As<ast::CallExpression>();
ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("vec2", "i32")); ast::CheckIdentifier(call->target, ast::Template("vec2", "i32"));
} }
TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) { TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) {
@ -131,7 +131,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) {
ASSERT_NE(e->variable->initializer, nullptr); ASSERT_NE(e->variable->initializer, nullptr);
auto* call = e->variable->initializer->As<ast::CallExpression>(); auto* call = e->variable->initializer->As<ast::CallExpression>();
ASSERT_NE(call, nullptr); ASSERT_NE(call, nullptr);
ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("vec2", "i32")); ast::CheckIdentifier(call->target, ast::Template("vec2", "i32"));
} }
TEST_F(ParserImplTest, VariableStmt_Let) { TEST_F(ParserImplTest, VariableStmt_Let) {
@ -168,11 +168,11 @@ TEST_F(ParserImplTest, VariableStmt_Let_ComplexExpression) {
ASSERT_TRUE(expr->lhs->Is<ast::IdentifierExpression>()); ASSERT_TRUE(expr->lhs->Is<ast::IdentifierExpression>());
auto* ident_expr = expr->lhs->As<ast::IdentifierExpression>(); auto* ident_expr = expr->lhs->As<ast::IdentifierExpression>();
ast::CheckIdentifier(p->builder().Symbols(), ident_expr->identifier, "collide"); ast::CheckIdentifier(ident_expr->identifier, "collide");
ASSERT_TRUE(expr->rhs->Is<ast::IdentifierExpression>()); ASSERT_TRUE(expr->rhs->Is<ast::IdentifierExpression>());
ident_expr = expr->rhs->As<ast::IdentifierExpression>(); ident_expr = expr->rhs->As<ast::IdentifierExpression>();
ast::CheckIdentifier(p->builder().Symbols(), ident_expr->identifier, "collide_1"); ast::CheckIdentifier(ident_expr->identifier, "collide_1");
} }
TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) { TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) {

View File

@ -115,8 +115,7 @@ TEST_P(ResolverBitcastValidationTestInvalidSrcTy, Test) {
auto* cast = Bitcast(dst.ast(*this), Expr(Source{{12, 34}}, "src")); auto* cast = Bitcast(dst.ast(*this), Expr(Source{{12, 34}}, "src"));
WrapInFunction(Let("src", src.expr(*this, 0)), cast); WrapInFunction(Let("src", src.expr(*this, 0)), cast);
auto expected = auto expected = "12:34 error: '" + src.sem(*this)->FriendlyName() + "' cannot be bitcast";
"12:34 error: '" + src.sem(*this)->FriendlyName(Symbols()) + "' cannot be bitcast";
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), expected); EXPECT_EQ(r()->error(), expected);
@ -150,8 +149,7 @@ TEST_P(ResolverBitcastValidationTestInvalidDstTy, Test) {
Alias("T", dst.ast(*this)); Alias("T", dst.ast(*this));
WrapInFunction(Bitcast(ty(Source{{12, 34}}, "T"), src.expr(*this, 0))); WrapInFunction(Bitcast(ty(Source{{12, 34}}, "T"), src.expr(*this, 0)));
auto expected = auto expected = "12:34 error: cannot bitcast to '" + dst.sem(*this)->FriendlyName() + "'";
"12:34 error: cannot bitcast to '" + dst.sem(*this)->FriendlyName(Symbols()) + "'";
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), expected); EXPECT_EQ(r()->error(), expected);
@ -183,8 +181,8 @@ TEST_P(ResolverBitcastValidationTestIncompatible, Test) {
WrapInFunction(Bitcast(Source{{12, 34}}, dst.ast(*this), src.expr(*this, 0))); WrapInFunction(Bitcast(Source{{12, 34}}, dst.ast(*this), src.expr(*this, 0)));
auto expected = "12:34 error: cannot bitcast from '" + src.sem(*this)->FriendlyName(Symbols()) + auto expected = "12:34 error: cannot bitcast from '" + src.sem(*this)->FriendlyName() +
"' to '" + dst.sem(*this)->FriendlyName(Symbols()) + "'"; "' to '" + dst.sem(*this)->FriendlyName() + "'";
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), expected); EXPECT_EQ(r()->error(), expected);

View File

@ -2120,7 +2120,7 @@ class ResolverBuiltinTest_TextureOperation : public ResolverTestWithParam<Textur
} }
void add_call_param(std::string name, ast::Type type, ExpressionList* call_params) { void add_call_param(std::string name, ast::Type type, ExpressionList* call_params) {
std::string type_name = Symbols().NameFor(type->identifier->symbol); std::string type_name = type->identifier->symbol.Name();
if (utils::HasPrefix(type_name, "texture") || utils::HasPrefix(type_name, "sampler")) { if (utils::HasPrefix(type_name, "texture") || utils::HasPrefix(type_name, "sampler")) {
GlobalVar(name, type, Binding(0_a), Group(0_a)); GlobalVar(name, type, Binding(0_a), Group(0_a));
} else { } else {

View File

@ -61,7 +61,6 @@
#include "src/tint/scope_stack.h" #include "src/tint/scope_stack.h"
#include "src/tint/sem/builtin.h" #include "src/tint/sem/builtin.h"
#include "src/tint/switch.h" #include "src/tint/switch.h"
#include "src/tint/symbol_table.h"
#include "src/tint/utils/block_allocator.h" #include "src/tint/utils/block_allocator.h"
#include "src/tint/utils/compiler_macros.h" #include "src/tint/utils/compiler_macros.h"
#include "src/tint/utils/defer.h" #include "src/tint/utils/defer.h"
@ -143,19 +142,16 @@ void AddNote(diag::List& diagnostics, const std::string& msg, const Source& sour
class DependencyScanner { class DependencyScanner {
public: public:
/// Constructor /// Constructor
/// @param syms the program symbol table
/// @param globals_by_name map of global symbol to Global pointer /// @param globals_by_name map of global symbol to Global pointer
/// @param diagnostics diagnostic messages, appended with any errors found /// @param diagnostics diagnostic messages, appended with any errors found
/// @param graph the dependency graph to populate with resolved symbols /// @param graph the dependency graph to populate with resolved symbols
/// @param edges the map of globals-to-global dependency edges, which will /// @param edges the map of globals-to-global dependency edges, which will
/// be populated by calls to Scan() /// be populated by calls to Scan()
DependencyScanner(const SymbolTable& syms, DependencyScanner(const GlobalMap& globals_by_name,
const GlobalMap& globals_by_name,
diag::List& diagnostics, diag::List& diagnostics,
DependencyGraph& graph, DependencyGraph& graph,
DependencyEdges& edges) DependencyEdges& edges)
: symbols_(syms), : globals_(globals_by_name),
globals_(globals_by_name),
diagnostics_(diagnostics), diagnostics_(diagnostics),
graph_(graph), graph_(graph),
dependency_edges_(edges) { dependency_edges_(edges) {
@ -331,7 +327,7 @@ class DependencyScanner {
void Declare(Symbol symbol, const ast::Node* node) { void Declare(Symbol symbol, const ast::Node* node) {
auto* old = scope_stack_.Set(symbol, node); auto* old = scope_stack_.Set(symbol, node);
if (old != nullptr && node != old) { if (old != nullptr && node != old) {
auto name = symbols_.NameFor(symbol); auto name = symbol.Name();
AddError(diagnostics_, "redeclaration of '" + name + "'", node->source); AddError(diagnostics_, "redeclaration of '" + name + "'", node->source);
AddNote(diagnostics_, "'" + name + "' previously declared here", old->source); AddNote(diagnostics_, "'" + name + "' previously declared here", old->source);
} }
@ -440,7 +436,7 @@ class DependencyScanner {
void AddDependency(const ast::Identifier* from, Symbol to) { void AddDependency(const ast::Identifier* from, Symbol to) {
auto* resolved = scope_stack_.Get(to); auto* resolved = scope_stack_.Get(to);
if (!resolved) { if (!resolved) {
auto s = symbols_.NameFor(to); auto s = to.Name();
if (auto builtin_fn = builtin::ParseFunction(s); if (auto builtin_fn = builtin::ParseFunction(s);
builtin_fn != builtin::Function::kNone) { builtin_fn != builtin::Function::kNone) {
graph_.resolved_identifiers.Add(from, ResolvedIdentifier(builtin_fn)); graph_.resolved_identifiers.Add(from, ResolvedIdentifier(builtin_fn));
@ -496,7 +492,6 @@ class DependencyScanner {
} }
using VariableMap = utils::Hashmap<Symbol, const ast::Variable*, 32>; using VariableMap = utils::Hashmap<Symbol, const ast::Variable*, 32>;
const SymbolTable& symbols_;
const GlobalMap& globals_; const GlobalMap& globals_;
diag::List& diagnostics_; diag::List& diagnostics_;
DependencyGraph& graph_; DependencyGraph& graph_;
@ -510,8 +505,8 @@ class DependencyScanner {
struct DependencyAnalysis { struct DependencyAnalysis {
public: public:
/// Constructor /// Constructor
DependencyAnalysis(const SymbolTable& symbols, diag::List& diagnostics, DependencyGraph& graph) DependencyAnalysis(diag::List& diagnostics, DependencyGraph& graph)
: symbols_(symbols), diagnostics_(diagnostics), graph_(graph) {} : diagnostics_(diagnostics), graph_(graph) {}
/// Performs global dependency analysis on the module, emitting any errors to /// Performs global dependency analysis on the module, emitting any errors to
/// #diagnostics. /// #diagnostics.
@ -562,7 +557,7 @@ struct DependencyAnalysis {
/// @returns the name of the global declaration node /// @returns the name of the global declaration node
/// @note will raise an ICE if the node is not a type, function or variable /// @note will raise an ICE if the node is not a type, function or variable
/// declaration /// declaration
std::string NameOf(const ast::Node* node) const { return symbols_.NameFor(SymbolOf(node)); } std::string NameOf(const ast::Node* node) const { return SymbolOf(node).Name(); }
/// @param node the ast::Node of the global declaration /// @param node the ast::Node of the global declaration
/// @returns a string representation of the global declaration kind /// @returns a string representation of the global declaration kind
@ -597,7 +592,7 @@ struct DependencyAnalysis {
/// Walks the global declarations, determining the dependencies of each global /// Walks the global declarations, determining the dependencies of each global
/// and adding these to each global's Global::deps field. /// and adding these to each global's Global::deps field.
void DetermineDependencies() { void DetermineDependencies() {
DependencyScanner scanner(symbols_, globals_, diagnostics_, graph_, dependency_edges_); DependencyScanner scanner(globals_, diagnostics_, graph_, dependency_edges_);
for (auto* global : declaration_order_) { for (auto* global : declaration_order_) {
scanner.Scan(global); scanner.Scan(global);
} }
@ -762,7 +757,7 @@ struct DependencyAnalysis {
for (auto* node : sorted_) { for (auto* node : sorted_) {
auto symbol = SymbolOf(node); auto symbol = SymbolOf(node);
auto* global = *globals_.Find(symbol); auto* global = *globals_.Find(symbol);
printf("%s depends on:\n", symbols_.NameFor(symbol).c_str()); printf("%s depends on:\n", symbol.Name().c_str());
for (auto* dep : global->deps) { for (auto* dep : global->deps) {
printf(" %s\n", NameOf(dep->node).c_str()); printf(" %s\n", NameOf(dep->node).c_str());
} }
@ -770,9 +765,6 @@ struct DependencyAnalysis {
printf("=========================\n"); printf("=========================\n");
} }
/// Program symbols
const SymbolTable& symbols_;
/// Program diagnostics /// Program diagnostics
diag::List& diagnostics_; diag::List& diagnostics_;
@ -802,37 +794,36 @@ DependencyGraph::DependencyGraph(DependencyGraph&&) = default;
DependencyGraph::~DependencyGraph() = default; DependencyGraph::~DependencyGraph() = default;
bool DependencyGraph::Build(const ast::Module& module, bool DependencyGraph::Build(const ast::Module& module,
const SymbolTable& symbols,
diag::List& diagnostics, diag::List& diagnostics,
DependencyGraph& output) { DependencyGraph& output) {
DependencyAnalysis da{symbols, diagnostics, output}; DependencyAnalysis da{diagnostics, output};
return da.Run(module); return da.Run(module);
} }
std::string ResolvedIdentifier::String(const SymbolTable& symbols, diag::List& diagnostics) const { std::string ResolvedIdentifier::String(diag::List& diagnostics) const {
if (auto* node = Node()) { if (auto* node = Node()) {
return Switch( return Switch(
node, node,
[&](const ast::TypeDecl* n) { // [&](const ast::TypeDecl* n) { //
return "type '" + symbols.NameFor(n->name->symbol) + "'"; return "type '" + n->name->symbol.Name() + "'";
}, },
[&](const ast::Var* n) { // [&](const ast::Var* n) { //
return "var '" + symbols.NameFor(n->name->symbol) + "'"; return "var '" + n->name->symbol.Name() + "'";
}, },
[&](const ast::Let* n) { // [&](const ast::Let* n) { //
return "let '" + symbols.NameFor(n->name->symbol) + "'"; return "let '" + n->name->symbol.Name() + "'";
}, },
[&](const ast::Const* n) { // [&](const ast::Const* n) { //
return "const '" + symbols.NameFor(n->name->symbol) + "'"; return "const '" + n->name->symbol.Name() + "'";
}, },
[&](const ast::Override* n) { // [&](const ast::Override* n) { //
return "override '" + symbols.NameFor(n->name->symbol) + "'"; return "override '" + n->name->symbol.Name() + "'";
}, },
[&](const ast::Function* n) { // [&](const ast::Function* n) { //
return "function '" + symbols.NameFor(n->name->symbol) + "'"; return "function '" + n->name->symbol.Name() + "'";
}, },
[&](const ast::Parameter* n) { // [&](const ast::Parameter* n) { //
return "parameter '" + symbols.NameFor(n->name->symbol) + "'"; return "parameter '" + n->name->symbol.Name() + "'";
}, },
[&](Default) { [&](Default) {
TINT_UNREACHABLE(Resolver, diagnostics) TINT_UNREACHABLE(Resolver, diagnostics)

View File

@ -27,7 +27,6 @@
#include "src/tint/builtin/interpolation_type.h" #include "src/tint/builtin/interpolation_type.h"
#include "src/tint/builtin/texel_format.h" #include "src/tint/builtin/texel_format.h"
#include "src/tint/diagnostic/diagnostic.h" #include "src/tint/diagnostic/diagnostic.h"
#include "src/tint/symbol_table.h"
#include "src/tint/utils/hashmap.h" #include "src/tint/utils/hashmap.h"
namespace tint::resolver { namespace tint::resolver {
@ -164,10 +163,9 @@ class ResolvedIdentifier {
return !(*this == other); return !(*this == other);
} }
/// @param symbols the program's symbol table
/// @param diagnostics diagnostics used to report ICEs /// @param diagnostics diagnostics used to report ICEs
/// @return a description of the resolved symbol /// @return a description of the resolved symbol
std::string String(const SymbolTable& symbols, diag::List& diagnostics) const; std::string String(diag::List& diagnostics) const;
private: private:
std::variant<UnresolvedIdentifier, std::variant<UnresolvedIdentifier,
@ -196,14 +194,10 @@ struct DependencyGraph {
/// Build() performs symbol resolution and dependency analysis on `module`, /// Build() performs symbol resolution and dependency analysis on `module`,
/// populating `output` with the resulting dependency graph. /// populating `output` with the resulting dependency graph.
/// @param module the AST module to analyse /// @param module the AST module to analyse
/// @param symbols the symbol table
/// @param diagnostics the diagnostic list to populate with errors / warnings /// @param diagnostics the diagnostic list to populate with errors / warnings
/// @param output the resulting DependencyGraph /// @param output the resulting DependencyGraph
/// @returns true on success, false on error /// @returns true on success, false on error
static bool Build(const ast::Module& module, static bool Build(const ast::Module& module, diag::List& diagnostics, DependencyGraph& output);
const SymbolTable& symbols,
diag::List& diagnostics,
DependencyGraph& output);
/// All globals in dependency-sorted order. /// All globals in dependency-sorted order.
utils::Vector<const ast::Node*, 32> ordered_globals; utils::Vector<const ast::Node*, 32> ordered_globals;

View File

@ -35,8 +35,7 @@ class ResolverDependencyGraphTestWithParam : public ResolverTestWithParam<T> {
public: public:
DependencyGraph Build(std::string expected_error = "") { DependencyGraph Build(std::string expected_error = "") {
DependencyGraph graph; DependencyGraph graph;
auto result = auto result = DependencyGraph::Build(this->AST(), this->Diagnostics(), graph);
DependencyGraph::Build(this->AST(), this->Symbols(), this->Diagnostics(), graph);
if (expected_error.empty()) { if (expected_error.empty()) {
EXPECT_TRUE(result) << this->Diagnostics().str(); EXPECT_TRUE(result) << this->Diagnostics().str();
} else { } else {
@ -1194,7 +1193,7 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinFunc, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->BuiltinFunction(), builtin) << resolved->String(Symbols(), Diagnostics()); EXPECT_EQ(resolved->BuiltinFunction(), builtin) << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
@ -1234,7 +1233,7 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinType, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->BuiltinType(), builtin::ParseBuiltin(name)) EXPECT_EQ(resolved->BuiltinType(), builtin::ParseBuiltin(name))
<< resolved->String(Symbols(), Diagnostics()); << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
@ -1273,8 +1272,7 @@ TEST_P(ResolverDependencyGraphResolveToAccess, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->Access(), builtin::ParseAccess(name)) EXPECT_EQ(resolved->Access(), builtin::ParseAccess(name)) << resolved->String(Diagnostics());
<< resolved->String(Symbols(), Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
@ -1314,7 +1312,7 @@ TEST_P(ResolverDependencyGraphResolveToAddressSpace, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->AddressSpace(), builtin::ParseAddressSpace(name)) EXPECT_EQ(resolved->AddressSpace(), builtin::ParseAddressSpace(name))
<< resolved->String(Symbols(), Diagnostics()); << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
@ -1354,7 +1352,7 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinValue, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->BuiltinValue(), builtin::ParseBuiltinValue(name)) EXPECT_EQ(resolved->BuiltinValue(), builtin::ParseBuiltinValue(name))
<< resolved->String(Symbols(), Diagnostics()); << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
@ -1394,7 +1392,7 @@ TEST_P(ResolverDependencyGraphResolveToInterpolationSampling, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->InterpolationSampling(), builtin::ParseInterpolationSampling(name)) EXPECT_EQ(resolved->InterpolationSampling(), builtin::ParseInterpolationSampling(name))
<< resolved->String(Symbols(), Diagnostics()); << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
@ -1434,7 +1432,7 @@ TEST_P(ResolverDependencyGraphResolveToInterpolationType, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->InterpolationType(), builtin::ParseInterpolationType(name)) EXPECT_EQ(resolved->InterpolationType(), builtin::ParseInterpolationType(name))
<< resolved->String(Symbols(), Diagnostics()); << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -1477,7 +1475,7 @@ TEST_P(ResolverDependencyGraphResolveToTexelFormat, Resolve) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->TexelFormat(), builtin::ParseTexelFormat(name)) EXPECT_EQ(resolved->TexelFormat(), builtin::ParseTexelFormat(name))
<< resolved->String(Symbols(), Diagnostics()); << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Types, INSTANTIATE_TEST_SUITE_P(Types,
@ -1558,7 +1556,7 @@ TEST_P(ResolverDependencyGraphShadowKindTest, ShadowedByGlobalVar) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->Node(), decl) << resolved->String(Symbols(), Diagnostics()); EXPECT_EQ(resolved->Node(), decl) << resolved->String(Diagnostics());
} }
TEST_P(ResolverDependencyGraphShadowKindTest, ShadowedByStruct) { TEST_P(ResolverDependencyGraphShadowKindTest, ShadowedByStruct) {
@ -1575,7 +1573,7 @@ TEST_P(ResolverDependencyGraphShadowKindTest, ShadowedByStruct) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->Node(), decl) << resolved->String(Symbols(), Diagnostics()); EXPECT_EQ(resolved->Node(), decl) << resolved->String(Diagnostics());
} }
TEST_P(ResolverDependencyGraphShadowKindTest, ShadowedByFunc) { TEST_P(ResolverDependencyGraphShadowKindTest, ShadowedByFunc) {
@ -1590,7 +1588,7 @@ TEST_P(ResolverDependencyGraphShadowKindTest, ShadowedByFunc) {
auto resolved = Build().resolved_identifiers.Get(ident); auto resolved = Build().resolved_identifiers.Get(ident);
ASSERT_TRUE(resolved); ASSERT_TRUE(resolved);
EXPECT_EQ(resolved->Node(), decl) << resolved->String(Symbols(), Diagnostics()); EXPECT_EQ(resolved->Node(), decl) << resolved->String(Diagnostics());
} }
INSTANTIATE_TEST_SUITE_P(Access, INSTANTIATE_TEST_SUITE_P(Access,

View File

@ -65,7 +65,7 @@ class Any final : public Castable<Any, type::Type> {
// Stub implementations for type::Type conformance. // Stub implementations for type::Type conformance.
bool Equals(const type::UniqueNode&) const override { return false; } bool Equals(const type::UniqueNode&) const override { return false; }
std::string FriendlyName(const SymbolTable&) const override { return "<any>"; } std::string FriendlyName() const override { return "<any>"; }
type::Type* Clone(type::CloneContext&) const override { return nullptr; } type::Type* Clone(type::CloneContext&) const override { return nullptr; }
}; };
@ -977,11 +977,9 @@ const sem::Struct* build_frexp_result_vec(MatchState& state, Number& n, const ty
} }
const sem::Struct* build_atomic_compare_exchange_result(MatchState& state, const type::Type* ty) { const sem::Struct* build_atomic_compare_exchange_result(MatchState& state, const type::Type* ty) {
return build_struct( return build_struct(state.builder, "__atomic_compare_exchange_result" + ty->FriendlyName(),
state.builder, {{"old_value", const_cast<type::Type*>(ty)},
"__atomic_compare_exchange_result" + ty->FriendlyName(state.builder.Symbols()), {"exchanged", state.builder.create<type::Bool>()}});
{{"old_value", const_cast<type::Type*>(ty)},
{"exchanged", state.builder.create<type::Bool>()}});
} }
/// ParameterInfo describes a parameter /// ParameterInfo describes a parameter
@ -1230,14 +1228,13 @@ class Impl : public IntrinsicTable {
/// @return a string representing a call to a builtin with the given argument /// @return a string representing a call to a builtin with the given argument
/// types. /// types.
std::string CallSignature(ProgramBuilder& builder, std::string CallSignature(const char* intrinsic_name,
const char* intrinsic_name,
utils::VectorRef<const type::Type*> args, utils::VectorRef<const type::Type*> args,
const type::Type* template_arg = nullptr) { const type::Type* template_arg = nullptr) {
utils::StringStream ss; utils::StringStream ss;
ss << intrinsic_name; ss << intrinsic_name;
if (template_arg) { if (template_arg) {
ss << "<" << template_arg->FriendlyName(builder.Symbols()) << ">"; ss << "<" << template_arg->FriendlyName() << ">";
} }
ss << "("; ss << "(";
{ {
@ -1247,7 +1244,7 @@ std::string CallSignature(ProgramBuilder& builder,
ss << ", "; ss << ", ";
} }
first = false; first = false;
ss << arg->UnwrapRef()->FriendlyName(builder.Symbols()); ss << arg->UnwrapRef()->FriendlyName();
} }
} }
ss << ")"; ss << ")";
@ -1274,7 +1271,7 @@ Impl::Builtin Impl::Lookup(builtin::Function builtin_type,
// Generates an error when no overloads match the provided arguments // Generates an error when no overloads match the provided arguments
auto on_no_match = [&](utils::VectorRef<Candidate> candidates) { auto on_no_match = [&](utils::VectorRef<Candidate> candidates) {
utils::StringStream ss; utils::StringStream ss;
ss << "no matching call to " << CallSignature(builder, intrinsic_name, args) << std::endl; ss << "no matching call to " << CallSignature(intrinsic_name, args) << std::endl;
if (!candidates.IsEmpty()) { if (!candidates.IsEmpty()) {
ss << std::endl ss << std::endl
<< candidates.Length() << " candidate function" << candidates.Length() << " candidate function"
@ -1343,7 +1340,7 @@ IntrinsicTable::UnaryOperator Impl::Lookup(ast::UnaryOp op,
// Generates an error when no overloads match the provided arguments // Generates an error when no overloads match the provided arguments
auto on_no_match = [&, name = intrinsic_name](utils::VectorRef<Candidate> candidates) { auto on_no_match = [&, name = intrinsic_name](utils::VectorRef<Candidate> candidates) {
utils::StringStream ss; utils::StringStream ss;
ss << "no matching overload for " << CallSignature(builder, name, args) << std::endl; ss << "no matching overload for " << CallSignature(name, args) << std::endl;
if (!candidates.IsEmpty()) { if (!candidates.IsEmpty()) {
ss << std::endl ss << std::endl
<< candidates.Length() << " candidate operator" << candidates.Length() << " candidate operator"
@ -1421,7 +1418,7 @@ IntrinsicTable::BinaryOperator Impl::Lookup(ast::BinaryOp op,
// Generates an error when no overloads match the provided arguments // Generates an error when no overloads match the provided arguments
auto on_no_match = [&, name = intrinsic_name](utils::VectorRef<Candidate> candidates) { auto on_no_match = [&, name = intrinsic_name](utils::VectorRef<Candidate> candidates) {
utils::StringStream ss; utils::StringStream ss;
ss << "no matching overload for " << CallSignature(builder, name, args) << std::endl; ss << "no matching overload for " << CallSignature(name, args) << std::endl;
if (!candidates.IsEmpty()) { if (!candidates.IsEmpty()) {
ss << std::endl ss << std::endl
<< candidates.Length() << " candidate operator" << candidates.Length() << " candidate operator"
@ -1456,7 +1453,7 @@ IntrinsicTable::CtorOrConv Impl::Lookup(CtorConvIntrinsic type,
// Generates an error when no overloads match the provided arguments // Generates an error when no overloads match the provided arguments
auto on_no_match = [&](utils::VectorRef<Candidate> candidates) { auto on_no_match = [&](utils::VectorRef<Candidate> candidates) {
utils::StringStream ss; utils::StringStream ss;
ss << "no matching constructor for " << CallSignature(builder, name, args, template_arg) ss << "no matching constructor for " << CallSignature(name, args, template_arg)
<< std::endl; << std::endl;
Candidates ctor, conv; Candidates ctor, conv;
for (auto candidate : candidates) { for (auto candidate : candidates) {
@ -1871,7 +1868,7 @@ void Impl::ErrAmbiguousOverload(const char* intrinsic_name,
ss << "ambiguous overload while attempting to match " << intrinsic_name; ss << "ambiguous overload while attempting to match " << intrinsic_name;
for (size_t i = 0; i < std::numeric_limits<size_t>::max(); i++) { for (size_t i = 0; i < std::numeric_limits<size_t>::max(); i++) {
if (auto* ty = templates.Type(i)) { if (auto* ty = templates.Type(i)) {
ss << ((i == 0) ? "<" : ", ") << ty->FriendlyName(builder.Symbols()); ss << ((i == 0) ? "<" : ", ") << ty->FriendlyName();
} else { } else {
if (i > 0) { if (i > 0) {
ss << ">"; ss << ">";
@ -1886,7 +1883,7 @@ void Impl::ErrAmbiguousOverload(const char* intrinsic_name,
ss << ", "; ss << ", ";
} }
first = false; first = false;
ss << arg->FriendlyName(builder.Symbols()); ss << arg->FriendlyName();
} }
ss << "):\n"; ss << "):\n";
for (auto& candidate : candidates) { for (auto& candidate : candidates) {

View File

@ -128,8 +128,7 @@ bool Resolver::Resolve() {
// Pre-allocate the marked bitset with the total number of AST nodes. // Pre-allocate the marked bitset with the total number of AST nodes.
marked_.Resize(builder_->ASTNodes().Count()); marked_.Resize(builder_->ASTNodes().Count());
if (!DependencyGraph::Build(builder_->AST(), builder_->Symbols(), diagnostics_, if (!DependencyGraph::Build(builder_->AST(), diagnostics_, dependencies_)) {
dependencies_)) {
return false; return false;
} }
@ -266,8 +265,7 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) {
if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined, if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined,
const_cast<type::Type*>(ty), v->source)) { const_cast<type::Type*>(ty), v->source)) {
AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->name->symbol), AddNote("while instantiating 'let' " + v->name->symbol.Name(), v->source);
v->source);
return nullptr; return nullptr;
} }
@ -329,8 +327,7 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined, if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined,
const_cast<type::Type*>(ty), v->source)) { const_cast<type::Type*>(ty), v->source)) {
AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->name->symbol), AddNote("while instantiating 'override' " + v->name->symbol.Name(), v->source);
v->source);
return nullptr; return nullptr;
} }
@ -423,8 +420,7 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined, if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined,
const_cast<type::Type*>(ty), c->source)) { const_cast<type::Type*>(ty), c->source)) {
AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->name->symbol), AddNote("while instantiating 'const' " + c->name->symbol.Name(), c->source);
c->source);
return nullptr; return nullptr;
} }
@ -524,8 +520,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {
if (!ApplyAddressSpaceUsageToType(address_space, var_ty, if (!ApplyAddressSpaceUsageToType(address_space, var_ty,
var->type ? var->type->source : var->source)) { var->type ? var->type->source : var->source)) {
AddNote("while instantiating 'var' " + builder_->Symbols().NameFor(var->name->symbol), AddNote("while instantiating 'var' " + var->name->symbol.Name(), var->source);
var->source);
return nullptr; return nullptr;
} }
@ -611,8 +606,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
Mark(param->name); Mark(param->name);
auto add_note = [&] { auto add_note = [&] {
AddNote("while instantiating parameter " + builder_->Symbols().NameFor(param->name->symbol), AddNote("while instantiating parameter " + param->name->symbol.Name(), param->source);
param->source);
}; };
for (auto* attr : param->attributes) { for (auto* attr : param->attributes) {
@ -879,7 +873,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) {
{ // Check the parameter name is unique for the function { // Check the parameter name is unique for the function
if (auto added = parameter_names.Add(param->name->symbol, param->source); !added) { if (auto added = parameter_names.Add(param->name->symbol, param->source); !added) {
auto name = builder_->Symbols().NameFor(param->name->symbol); auto name = param->name->symbol.Name();
AddError("redefinition of parameter '" + name + "'", param->source); AddError("redefinition of parameter '" + name + "'", param->source);
AddNote("previous definition is here", *added.value); AddNote("previous definition is here", *added.value);
return nullptr; return nullptr;
@ -944,8 +938,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) {
if (auto* str = return_type->As<sem::Struct>()) { if (auto* str = return_type->As<sem::Struct>()) {
if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined, str, decl->source)) { if (!ApplyAddressSpaceUsageToType(builtin::AddressSpace::kUndefined, str, decl->source)) {
AddNote("while instantiating return type for " + AddNote("while instantiating return type for " + decl->name->symbol.Name(),
builder_->Symbols().NameFor(decl->name->symbol),
decl->source); decl->source);
return nullptr; return nullptr;
} }
@ -1577,7 +1570,7 @@ bool Resolver::AliasAnalysis(const sem::Call* call) {
break; break;
case Alias::ModuleScope: { case Alias::ModuleScope: {
auto* func = var.expr->Stmt()->Function(); auto* func = var.expr->Stmt()->Function();
auto func_name = builder_->Symbols().NameFor(func->Declaration()->name->symbol); auto func_name = func->Declaration()->name->symbol.Name();
AddNote( AddNote(
"aliases with module-scope variable " + var.access + " in '" + func_name + "'", "aliases with module-scope variable " + var.access + " in '" + func_name + "'",
var.expr->Declaration()->source); var.expr->Declaration()->source);
@ -2147,8 +2140,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
auto resolved = dependencies_.resolved_identifiers.Get(ident); auto resolved = dependencies_.resolved_identifiers.Get(ident);
if (!resolved) { if (!resolved) {
TINT_ICE(Resolver, diagnostics_) TINT_ICE(Resolver, diagnostics_)
<< "identifier '" << builder_->Symbols().NameFor(ident->symbol) << "identifier '" << ident->symbol.Name() << "' was not resolved";
<< "' was not resolved";
return nullptr; return nullptr;
} }
@ -2355,27 +2347,27 @@ type::Type* Resolver::BuiltinType(builtin::Builtin builtin_ty, const ast::Identi
auto* tmpl_ident = ident->As<ast::TemplatedIdentifier>(); auto* tmpl_ident = ident->As<ast::TemplatedIdentifier>();
if (!tmpl_ident) { if (!tmpl_ident) {
if (TINT_UNLIKELY(min_args != 0)) { if (TINT_UNLIKELY(min_args != 0)) {
AddError("expected '<' for '" + b.Symbols().NameFor(ident->symbol) + "'", AddError("expected '<' for '" + ident->symbol.Name() + "'",
Source{ident->source.range.end}); Source{ident->source.range.end});
} }
return nullptr; return nullptr;
} }
if (min_args == max_args) { if (min_args == max_args) {
if (TINT_UNLIKELY(tmpl_ident->arguments.Length() != min_args)) { if (TINT_UNLIKELY(tmpl_ident->arguments.Length() != min_args)) {
AddError("'" + b.Symbols().NameFor(ident->symbol) + "' requires " + AddError("'" + ident->symbol.Name() + "' requires " + std::to_string(min_args) +
std::to_string(min_args) + " template arguments", " template arguments",
ident->source); ident->source);
return nullptr; return nullptr;
} }
} else { } else {
if (TINT_UNLIKELY(tmpl_ident->arguments.Length() < min_args)) { if (TINT_UNLIKELY(tmpl_ident->arguments.Length() < min_args)) {
AddError("'" + b.Symbols().NameFor(ident->symbol) + "' requires at least " + AddError("'" + ident->symbol.Name() + "' requires at least " +
std::to_string(min_args) + " template arguments", std::to_string(min_args) + " template arguments",
ident->source); ident->source);
return nullptr; return nullptr;
} }
if (TINT_UNLIKELY(tmpl_ident->arguments.Length() > max_args)) { if (TINT_UNLIKELY(tmpl_ident->arguments.Length() > max_args)) {
AddError("'" + b.Symbols().NameFor(ident->symbol) + "' requires at most " + AddError("'" + ident->symbol.Name() + "' requires at most " +
std::to_string(max_args) + " template arguments", std::to_string(max_args) + " template arguments",
ident->source); ident->source);
return nullptr; return nullptr;
@ -2752,7 +2744,7 @@ type::Type* Resolver::BuiltinType(builtin::Builtin builtin_ty, const ast::Identi
break; break;
} }
auto name = builder_->Symbols().NameFor(ident->symbol); auto name = ident->symbol.Name();
TINT_ICE(Resolver, diagnostics_) << ident->source << " unhandled builtin type '" << name << "'"; TINT_ICE(Resolver, diagnostics_) << ident->source << " unhandled builtin type '" << name << "'";
return nullptr; return nullptr;
} }
@ -2940,7 +2932,7 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
auto resolved = dependencies_.resolved_identifiers.Get(ident); auto resolved = dependencies_.resolved_identifiers.Get(ident);
if (!resolved) { if (!resolved) {
TINT_ICE(Resolver, diagnostics_) TINT_ICE(Resolver, diagnostics_)
<< "identifier '" << builder_->Symbols().NameFor(ident->symbol) << "' was not resolved"; << "identifier '" << ident->symbol.Name() << "' was not resolved";
return nullptr; return nullptr;
} }
@ -2968,12 +2960,11 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
if (auto decl = loop_block->Decls().Find(symbol)) { if (auto decl = loop_block->Decls().Find(symbol)) {
if (decl->order >= loop_block->NumDeclsAtFirstContinue()) { if (decl->order >= loop_block->NumDeclsAtFirstContinue()) {
AddError("continue statement bypasses declaration of '" + AddError("continue statement bypasses declaration of '" +
builder_->Symbols().NameFor(symbol) + "'", symbol.Name() + "'",
loop_block->FirstContinue()->source); loop_block->FirstContinue()->source);
AddNote("identifier '" + builder_->Symbols().NameFor(symbol) + AddNote("identifier '" + symbol.Name() + "' declared here",
"' declared here",
decl->variable->Declaration()->source); decl->variable->Declaration()->source);
AddNote("identifier '" + builder_->Symbols().NameFor(symbol) + AddNote("identifier '" + symbol.Name() +
"' referenced in continuing block here", "' referenced in continuing block here",
expr->source); expr->source);
return nullptr; return nullptr;
@ -3011,7 +3002,7 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
// Note: The spec is currently vague around the rules here. See // Note: The spec is currently vague around the rules here. See
// https://github.com/gpuweb/gpuweb/issues/3081. Remove this comment when // https://github.com/gpuweb/gpuweb/issues/3081. Remove this comment when
// resolved. // resolved.
std::string desc = "var '" + builder_->Symbols().NameFor(symbol) + "' "; std::string desc = "var '" + symbol.Name() + "' ";
AddError(desc + "cannot be referenced at module-scope", expr->source); AddError(desc + "cannot be referenced at module-scope", expr->source);
AddNote(desc + "declared here", variable->Declaration()->source); AddNote(desc + "declared here", variable->Declaration()->source);
return nullptr; return nullptr;
@ -3116,7 +3107,7 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) {
} }
TINT_UNREACHABLE(Resolver, diagnostics_) TINT_UNREACHABLE(Resolver, diagnostics_)
<< "unhandled resolved identifier: " << resolved->String(builder_->Symbols(), diagnostics_); << "unhandled resolved identifier: " << resolved->String(diagnostics_);
return nullptr; return nullptr;
} }
@ -3151,8 +3142,7 @@ sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpressi
} }
if (member == nullptr) { if (member == nullptr) {
AddError("struct member " + builder_->Symbols().NameFor(symbol) + " not found", AddError("struct member " + symbol.Name() + " not found", expr->source);
expr->source);
return nullptr; return nullptr;
} }
@ -3173,7 +3163,7 @@ sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpressi
}, },
[&](const type::Vector* vec) -> sem::ValueExpression* { [&](const type::Vector* vec) -> sem::ValueExpression* {
std::string s = builder_->Symbols().NameFor(expr->member->symbol); std::string s = expr->member->symbol.Name();
auto size = s.size(); auto size = s.size();
utils::Vector<uint32_t, 4> swizzle; utils::Vector<uint32_t, 4> swizzle;
swizzle.Reserve(s.size()); swizzle.Reserve(s.size());
@ -3474,7 +3464,7 @@ bool Resolver::InternalAttribute(const ast::InternalAttribute* attr) {
bool Resolver::DiagnosticControl(const ast::DiagnosticControl& control) { bool Resolver::DiagnosticControl(const ast::DiagnosticControl& control) {
Mark(control.rule_name); Mark(control.rule_name);
auto rule_name = builder_->Symbols().NameFor(control.rule_name->symbol); auto rule_name = control.rule_name->symbol.Name();
auto rule = builtin::ParseDiagnosticRule(rule_name); auto rule = builtin::ParseDiagnosticRule(rule_name);
if (rule != builtin::DiagnosticRule::kUndefined) { if (rule != builtin::DiagnosticRule::kUndefined) {
validator_.DiagnosticFilters().Set(rule, control.severity); validator_.DiagnosticFilters().Set(rule, control.severity);
@ -3646,7 +3636,7 @@ type::Type* Resolver::Alias(const ast::Alias* alias) {
sem::Struct* Resolver::Structure(const ast::Struct* str) { sem::Struct* Resolver::Structure(const ast::Struct* str) {
auto struct_name = [&] { // auto struct_name = [&] { //
return builder_->Symbols().NameFor(str->name->symbol); return str->name->symbol.Name();
}; };
if (validator_.IsValidationEnabled(str->attributes, if (validator_.IsValidationEnabled(str->attributes,
@ -3687,8 +3677,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
Mark(member); Mark(member);
Mark(member->name); Mark(member->name);
if (auto added = member_map.Add(member->name->symbol, member); !added) { if (auto added = member_map.Add(member->name->symbol, member); !added) {
AddError("redefinition of '" + builder_->Symbols().NameFor(member->name->symbol) + "'", AddError("redefinition of '" + member->name->symbol.Name() + "'", member->source);
member->source);
AddNote("previous definition is here", (*added.value)->source); AddNote("previous definition is here", (*added.value)->source);
return nullptr; return nullptr;
} }
@ -4230,7 +4219,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(builtin::AddressSpace address_space,
address_space, const_cast<type::Type*>(member->Type()), decl->type->source)) { address_space, const_cast<type::Type*>(member->Type()), decl->type->source)) {
utils::StringStream err; utils::StringStream err;
err << "while analyzing structure member " << sem_.TypeNameOf(str) << "." err << "while analyzing structure member " << sem_.TypeNameOf(str) << "."
<< builder_->Symbols().NameFor(member->Name()); << member->Name().Name();
AddNote(err.str(), member->Source()); AddNote(err.str(), member->Source());
return false; return false;
} }
@ -4369,9 +4358,9 @@ void Resolver::ApplyDiagnosticSeverities(NODE* node) {
bool Resolver::CheckNotTemplated(const char* use, const ast::Identifier* ident) { bool Resolver::CheckNotTemplated(const char* use, const ast::Identifier* ident) {
if (TINT_UNLIKELY(ident->Is<ast::TemplatedIdentifier>())) { if (TINT_UNLIKELY(ident->Is<ast::TemplatedIdentifier>())) {
AddError(std::string(use) + " '" + builder_->Symbols().NameFor(ident->symbol) + AddError(
"' does not take template arguments", std::string(use) + " '" + ident->symbol.Name() + "' does not take template arguments",
ident->source); ident->source);
if (auto resolved = dependencies_.resolved_identifiers.Get(ident)) { if (auto resolved = dependencies_.resolved_identifiers.Get(ident)) {
if (auto* ast_node = resolved->Node()) { if (auto* ast_node = resolved->Node()) {
sem_.NoteDeclarationSource(ast_node); sem_.NoteDeclarationSource(ast_node);
@ -4385,9 +4374,7 @@ bool Resolver::CheckNotTemplated(const char* use, const ast::Identifier* ident)
void Resolver::ErrorMismatchedResolvedIdentifier(const Source& source, void Resolver::ErrorMismatchedResolvedIdentifier(const Source& source,
const ResolvedIdentifier& resolved, const ResolvedIdentifier& resolved,
std::string_view wanted) { std::string_view wanted) {
AddError("cannot use " + resolved.String(builder_->Symbols(), diagnostics_) + " as " + AddError("cannot use " + resolved.String(diagnostics_) + " as " + std::string(wanted), source);
std::string(wanted),
source);
sem_.NoteDeclarationSource(resolved.Node()); sem_.NoteDeclarationSource(resolved.Node());
} }

View File

@ -112,12 +112,12 @@ class TestHelper : public ProgramBuilder {
/// @param type a type /// @param type a type
/// @returns the name for `type` that closely resembles how it would be /// @returns the name for `type` that closely resembles how it would be
/// declared in WGSL. /// declared in WGSL.
std::string FriendlyName(ast::Type type) { return Symbols().NameFor(type->identifier->symbol); } std::string FriendlyName(ast::Type type) { return type->identifier->symbol.Name(); }
/// @param type a type /// @param type a type
/// @returns the name for `type` that closely resembles how it would be /// @returns the name for `type` that closely resembles how it would be
/// declared in WGSL. /// declared in WGSL.
std::string FriendlyName(const type::Type* type) { return type->FriendlyName(Symbols()); } std::string FriendlyName(const type::Type* type) { return type->FriendlyName(); }
private: private:
std::unique_ptr<Resolver> resolver_; std::unique_ptr<Resolver> resolver_;

View File

@ -32,7 +32,7 @@ std::string SemHelper::TypeNameOf(const type::Type* ty) const {
} }
std::string SemHelper::RawTypeNameOf(const type::Type* ty) const { std::string SemHelper::RawTypeNameOf(const type::Type* ty) const {
return ty->FriendlyName(builder_->Symbols()); return ty->FriendlyName();
} }
type::Type* SemHelper::TypeOf(const ast::Expression* expr) const { type::Type* SemHelper::TypeOf(const ast::Expression* expr) const {
@ -45,7 +45,7 @@ std::string SemHelper::Describe(const sem::Expression* expr) const {
expr, // expr, //
[&](const sem::VariableUser* var_expr) { [&](const sem::VariableUser* var_expr) {
auto* variable = var_expr->Variable()->Declaration(); auto* variable = var_expr->Variable()->Declaration();
auto name = builder_->Symbols().NameFor(variable->name->symbol); auto name = variable->name->symbol.Name();
auto* kind = Switch( auto* kind = Switch(
variable, // variable, //
[&](const ast::Var*) { return "var"; }, // [&](const ast::Var*) { return "var"; }, //
@ -57,16 +57,16 @@ std::string SemHelper::Describe(const sem::Expression* expr) const {
return std::string(kind) + " '" + name + "'"; return std::string(kind) + " '" + name + "'";
}, },
[&](const sem::ValueExpression* val_expr) { [&](const sem::ValueExpression* val_expr) {
auto type = val_expr->Type()->FriendlyName(builder_->Symbols()); auto type = val_expr->Type()->FriendlyName();
return "value expression of type '" + type + "'"; return "value expression of type '" + type + "'";
}, },
[&](const sem::TypeExpression* ty_expr) { [&](const sem::TypeExpression* ty_expr) {
auto name = ty_expr->Type()->FriendlyName(builder_->Symbols()); auto name = ty_expr->Type()->FriendlyName();
return "type '" + name + "'"; return "type '" + name + "'";
}, },
[&](const sem::FunctionExpression* fn_expr) { [&](const sem::FunctionExpression* fn_expr) {
auto* fn = fn_expr->Function()->Declaration(); auto* fn = fn_expr->Function()->Declaration();
auto name = builder_->Symbols().NameFor(fn->name->symbol); auto name = fn->name->symbol.Name();
return "function '" + name + "'"; return "function '" + name + "'";
}, },
[&](const sem::BuiltinEnumExpression<builtin::Access>* access) { [&](const sem::BuiltinEnumExpression<builtin::Access>* access) {
@ -128,37 +128,28 @@ void SemHelper::NoteDeclarationSource(const ast::Node* node) const {
Switch( Switch(
node, node,
[&](const ast::Struct* n) { [&](const ast::Struct* n) {
AddNote("struct '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", AddNote("struct '" + n->name->symbol.Name() + "' declared here", n->source);
n->source);
}, },
[&](const ast::Alias* n) { [&](const ast::Alias* n) {
AddNote("alias '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", AddNote("alias '" + n->name->symbol.Name() + "' declared here", n->source);
n->source);
}, },
[&](const ast::Var* n) { [&](const ast::Var* n) {
AddNote("var '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", AddNote("var '" + n->name->symbol.Name() + "' declared here", n->source);
n->source);
}, },
[&](const ast::Let* n) { [&](const ast::Let* n) {
AddNote("let '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", AddNote("let '" + n->name->symbol.Name() + "' declared here", n->source);
n->source);
}, },
[&](const ast::Override* n) { [&](const ast::Override* n) {
AddNote("override '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", AddNote("override '" + n->name->symbol.Name() + "' declared here", n->source);
n->source);
}, },
[&](const ast::Const* n) { [&](const ast::Const* n) {
AddNote("const '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", AddNote("const '" + n->name->symbol.Name() + "' declared here", n->source);
n->source);
}, },
[&](const ast::Parameter* n) { [&](const ast::Parameter* n) {
AddNote( AddNote("parameter '" + n->name->symbol.Name() + "' declared here", n->source);
"parameter '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here",
n->source);
}, },
[&](const ast::Function* n) { [&](const ast::Function* n) {
AddNote("function '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", AddNote("function '" + n->name->symbol.Name() + "' declared here", n->source);
n->source);
}); });
} }

View File

@ -178,7 +178,7 @@ struct FunctionInfo {
/// @param func the AST function /// @param func the AST function
/// @param builder the program builder /// @param builder the program builder
FunctionInfo(const ast::Function* func, const ProgramBuilder* builder) { FunctionInfo(const ast::Function* func, const ProgramBuilder* builder) {
name = builder->Symbols().NameFor(func->name->symbol); name = func->name->symbol.Name();
callsite_tag = {CallSiteTag::CallSiteNoRestriction}; callsite_tag = {CallSiteTag::CallSiteNoRestriction};
function_tag = NoRestriction; function_tag = NoRestriction;
@ -196,7 +196,7 @@ struct FunctionInfo {
parameters.Resize(func->params.Length()); parameters.Resize(func->params.Length());
for (size_t i = 0; i < func->params.Length(); i++) { for (size_t i = 0; i < func->params.Length(); i++) {
auto* param = func->params[i]; auto* param = func->params[i];
auto param_name = builder->Symbols().NameFor(param->name->symbol); auto param_name = param->name->symbol.Name();
auto* sem = builder->Sem().Get<sem::Parameter>(param); auto* sem = builder->Sem().Get<sem::Parameter>(param);
parameters[i].sem = sem; parameters[i].sem = sem;
@ -397,14 +397,12 @@ class UniformityGraph {
/// @param expr the expression to get the symbol name of /// @param expr the expression to get the symbol name of
/// @returns the symbol name /// @returns the symbol name
inline std::string NameFor(const ast::IdentifierExpression* expr) { inline std::string NameFor(const ast::IdentifierExpression* expr) {
return builder_->Symbols().NameFor(expr->identifier->symbol); return expr->identifier->symbol.Name();
} }
/// @param var the variable to get the name of /// @param var the variable to get the name of
/// @returns the name of the variable @p var /// @returns the name of the variable @p var
inline std::string NameFor(const ast::Variable* var) { inline std::string NameFor(const ast::Variable* var) { return var->name->symbol.Name(); }
return builder_->Symbols().NameFor(var->name->symbol);
}
/// @param var the variable to get the name of /// @param var the variable to get the name of
/// @returns the name of the variable @p var /// @returns the name of the variable @p var
@ -413,7 +411,7 @@ class UniformityGraph {
/// @param fn the function to get the name of /// @param fn the function to get the name of
/// @returns the name of the function @p fn /// @returns the name of the function @p fn
inline std::string NameFor(const sem::Function* fn) { inline std::string NameFor(const sem::Function* fn) {
return builder_->Symbols().NameFor(fn->Declaration()->name->symbol); return fn->Declaration()->name->symbol.Name();
} }
/// Process a function. /// Process a function.

View File

@ -413,9 +413,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
return required_align; return required_align;
}; };
auto member_name_of = [this](const sem::StructMember* sm) { auto member_name_of = [](const sem::StructMember* sm) { return sm->Name().Name(); };
return symbols_.NameFor(sm->Name());
};
// Only validate the [type + address space] once // Only validate the [type + address space] once
if (!valid_type_storage_layouts_.Add(TypeAndAddressSpace{store_ty, address_space})) { if (!valid_type_storage_layouts_.Add(TypeAndAddressSpace{store_ty, address_space})) {
@ -427,7 +425,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
} }
auto note_usage = [&] { auto note_usage = [&] {
AddNote("'" + store_ty->FriendlyName(symbols_) + "' used in address space '" + AddNote("'" + store_ty->FriendlyName() + "' used in address space '" +
utils::ToString(address_space) + "' here", utils::ToString(address_space) + "' here",
source); source);
}; };
@ -447,7 +445,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
// Recurse into the member type. // Recurse into the member type.
if (!AddressSpaceLayout(m->Type(), address_space, m->Declaration()->type->source)) { if (!AddressSpaceLayout(m->Type(), address_space, m->Declaration()->type->source)) {
AddNote("see layout of struct:\n" + str->Layout(symbols_), str->Source()); AddNote("see layout of struct:\n" + str->Layout(), str->Source());
note_usage(); note_usage();
return false; return false;
} }
@ -457,18 +455,18 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
!enabled_extensions_.Contains( !enabled_extensions_.Contains(
builtin::Extension::kChromiumInternalRelaxedUniformLayout)) { builtin::Extension::kChromiumInternalRelaxedUniformLayout)) {
AddError("the offset of a struct member of type '" + AddError("the offset of a struct member of type '" +
m->Type()->UnwrapRef()->FriendlyName(symbols_) + m->Type()->UnwrapRef()->FriendlyName() + "' in address space '" +
"' in address space '" + utils::ToString(address_space) + utils::ToString(address_space) + "' must be a multiple of " +
"' must be a multiple of " + std::to_string(required_align) + std::to_string(required_align) + " bytes, but '" + member_name_of(m) +
" bytes, but '" + member_name_of(m) + "' is currently at offset " + "' is currently at offset " + std::to_string(m->Offset()) +
std::to_string(m->Offset()) + ". Consider setting @align(" + ". Consider setting @align(" + std::to_string(required_align) +
std::to_string(required_align) + ") on this member", ") on this member",
m->Source()); m->Source());
AddNote("see layout of struct:\n" + str->Layout(symbols_), str->Source()); AddNote("see layout of struct:\n" + str->Layout(), str->Source());
if (auto* member_str = m->Type()->As<sem::Struct>()) { if (auto* member_str = m->Type()->As<sem::Struct>()) {
AddNote("and layout of struct member:\n" + member_str->Layout(symbols_), AddNote("and layout of struct member:\n" + member_str->Layout(),
member_str->Source()); member_str->Source());
} }
@ -493,11 +491,10 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
"'. Consider setting @align(16) on this member", "'. Consider setting @align(16) on this member",
m->Source()); m->Source());
AddNote("see layout of struct:\n" + str->Layout(symbols_), str->Source()); AddNote("see layout of struct:\n" + str->Layout(), str->Source());
auto* prev_member_str = prev_member->Type()->As<sem::Struct>(); auto* prev_member_str = prev_member->Type()->As<sem::Struct>();
AddNote("and layout of previous member struct:\n" + AddNote("and layout of previous member struct:\n" + prev_member_str->Layout(),
prev_member_str->Layout(symbols_),
prev_member_str->Source()); prev_member_str->Source());
note_usage(); note_usage();
return false; return false;
@ -540,7 +537,7 @@ bool Validator::AddressSpaceLayout(const type::Type* store_ty,
AddError( AddError(
"uniform storage requires that array elements are aligned to 16 bytes, but " "uniform storage requires that array elements are aligned to 16 bytes, but "
"array element of type '" + "array element of type '" +
arr->ElemType()->FriendlyName(symbols_) + "' has a stride of " + arr->ElemType()->FriendlyName() + "' has a stride of " +
std::to_string(arr->Stride()) + " bytes. " + hint, std::to_string(arr->Stride()) + " bytes. " + hint,
source); source);
return false; return false;
@ -1070,7 +1067,7 @@ bool Validator::Function(const sem::Function* func, ast::PipelineStage stage) co
} else if (TINT_UNLIKELY(IsValidationEnabled( } else if (TINT_UNLIKELY(IsValidationEnabled(
decl->attributes, ast::DisabledValidation::kFunctionHasNoBody))) { decl->attributes, ast::DisabledValidation::kFunctionHasNoBody))) {
TINT_ICE(Resolver, diagnostics_) TINT_ICE(Resolver, diagnostics_)
<< "Function " << symbols_.NameFor(decl->name->symbol) << " has no body"; << "Function " << decl->name->symbol.Name() << " has no body";
} }
for (auto* attr : decl->return_type_attributes) { for (auto* attr : decl->return_type_attributes) {
@ -1102,7 +1099,7 @@ bool Validator::Function(const sem::Function* func, ast::PipelineStage stage) co
// a function behavior is always one of {}, or {Next}. // a function behavior is always one of {}, or {Next}.
if (TINT_UNLIKELY(func->Behaviors() != sem::Behaviors{} && if (TINT_UNLIKELY(func->Behaviors() != sem::Behaviors{} &&
func->Behaviors() != sem::Behavior::kNext)) { func->Behaviors() != sem::Behavior::kNext)) {
auto name = symbols_.NameFor(decl->name->symbol); auto name = decl->name->symbol.Name();
TINT_ICE(Resolver, diagnostics_) TINT_ICE(Resolver, diagnostics_)
<< "function '" << name << "' behaviors are: " << func->Behaviors(); << "function '" << name << "' behaviors are: " << func->Behaviors();
} }
@ -1284,8 +1281,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
member->Declaration()->attributes, member->Type(), member->Source(), member->Declaration()->attributes, member->Type(), member->Source(),
param_or_ret, param_or_ret,
/*is_struct_member*/ true, member->Location())) { /*is_struct_member*/ true, member->Location())) {
AddNote("while analyzing entry point '" + AddNote("while analyzing entry point '" + decl->name->symbol.Name() + "'",
symbols_.NameFor(decl->name->symbol) + "'",
decl->source); decl->source);
return false; return false;
} }
@ -1364,7 +1360,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
// Bindings must not alias within a shader stage: two different variables in the // Bindings must not alias within a shader stage: two different variables in the
// resource interface of a given shader must not have the same group and binding values, // resource interface of a given shader must not have the same group and binding values,
// when considered as a pair of values. // when considered as a pair of values.
auto func_name = symbols_.NameFor(decl->name->symbol); auto func_name = decl->name->symbol.Name();
AddError( AddError(
"entry point '" + func_name + "entry point '" + func_name +
"' references multiple variables that use the same resource binding @group(" + "' references multiple variables that use the same resource binding @group(" +
@ -1505,8 +1501,7 @@ bool Validator::Call(const sem::Call* call, sem::Statement* current_statement) c
call->Target(), // call->Target(), //
[&](const sem::Function* fn) { [&](const sem::Function* fn) {
AddError("ignoring return value of function '" + AddError("ignoring return value of function '" +
symbols_.NameFor(fn->Declaration()->name->symbol) + fn->Declaration()->name->symbol.Name() + "' annotated with @must_use",
"' annotated with @must_use",
call->Declaration()->source); call->Declaration()->source);
sem_.NoteDeclarationSource(fn->Declaration()); sem_.NoteDeclarationSource(fn->Declaration());
}, },
@ -1741,7 +1736,7 @@ bool Validator::FunctionCall(const sem::Call* call, sem::Statement* current_stat
auto* decl = call->Declaration(); auto* decl = call->Declaration();
auto* target = call->Target()->As<sem::Function>(); auto* target = call->Target()->As<sem::Function>();
auto sym = target->Declaration()->name->symbol; auto sym = target->Declaration()->name->symbol;
auto name = symbols_.NameFor(sym); auto name = sym.Name();
if (!current_statement) { // Function call at module-scope. if (!current_statement) { // Function call at module-scope.
AddError("functions cannot be called at module-scope", decl->source); AddError("functions cannot be called at module-scope", decl->source);
@ -1928,13 +1923,12 @@ bool Validator::PipelineStages(utils::VectorRef<sem::Function*> entry_points) co
auto backtrace = [&](const sem::Function* func, const sem::Function* entry_point) { auto backtrace = [&](const sem::Function* func, const sem::Function* entry_point) {
if (func != entry_point) { if (func != entry_point) {
TraverseCallChain(diagnostics_, entry_point, func, [&](const sem::Function* f) { TraverseCallChain(diagnostics_, entry_point, func, [&](const sem::Function* f) {
AddNote( AddNote("called by function '" + f->Declaration()->name->symbol.Name() + "'",
"called by function '" + symbols_.NameFor(f->Declaration()->name->symbol) + "'", f->Declaration()->source);
f->Declaration()->source);
}); });
AddNote("called by entry point '" + AddNote(
symbols_.NameFor(entry_point->Declaration()->name->symbol) + "'", "called by entry point '" + entry_point->Declaration()->name->symbol.Name() + "'",
entry_point->Declaration()->source); entry_point->Declaration()->source);
} }
}; };
@ -2040,33 +2034,33 @@ bool Validator::PushConstants(utils::VectorRef<sem::Function*> entry_points) con
continue; continue;
} }
AddError("entry point '" + symbols_.NameFor(ep->Declaration()->name->symbol) + AddError("entry point '" + ep->Declaration()->name->symbol.Name() +
"' uses two different 'push_constant' variables.", "' uses two different 'push_constant' variables.",
ep->Declaration()->source); ep->Declaration()->source);
AddNote("first 'push_constant' variable declaration is here", AddNote("first 'push_constant' variable declaration is here",
var->Declaration()->source); var->Declaration()->source);
if (func != ep) { if (func != ep) {
TraverseCallChain(diagnostics_, ep, func, [&](const sem::Function* f) { TraverseCallChain(diagnostics_, ep, func, [&](const sem::Function* f) {
AddNote("called by function '" + AddNote(
symbols_.NameFor(f->Declaration()->name->symbol) + "'", "called by function '" + f->Declaration()->name->symbol.Name() + "'",
f->Declaration()->source); f->Declaration()->source);
}); });
AddNote("called by entry point '" + AddNote(
symbols_.NameFor(ep->Declaration()->name->symbol) + "'", "called by entry point '" + ep->Declaration()->name->symbol.Name() + "'",
ep->Declaration()->source); ep->Declaration()->source);
} }
AddNote("second 'push_constant' variable declaration is here", AddNote("second 'push_constant' variable declaration is here",
push_constant_var->Declaration()->source); push_constant_var->Declaration()->source);
if (push_constant_func != ep) { if (push_constant_func != ep) {
TraverseCallChain( TraverseCallChain(diagnostics_, ep, push_constant_func,
diagnostics_, ep, push_constant_func, [&](const sem::Function* f) { [&](const sem::Function* f) {
AddNote("called by function '" + AddNote("called by function '" +
symbols_.NameFor(f->Declaration()->name->symbol) + "'", f->Declaration()->name->symbol.Name() + "'",
f->Declaration()->source); f->Declaration()->source);
}); });
AddNote("called by entry point '" + AddNote(
symbols_.NameFor(ep->Declaration()->name->symbol) + "'", "called by entry point '" + ep->Declaration()->name->symbol.Name() + "'",
ep->Declaration()->source); ep->Declaration()->source);
} }
return false; return false;
} }
@ -2484,7 +2478,7 @@ bool Validator::IncrementDecrementStatement(const ast::IncrementDecrementStateme
[&](const ast::Override*) { return "cannot modify 'override'"; }); [&](const ast::Override*) { return "cannot modify 'override'"; });
if (err) { if (err) {
AddError(err, lhs->source); AddError(err, lhs->source);
AddNote("'" + symbols_.NameFor(v->name->symbol) + "' is declared here:", v->source); AddNote("'" + v->name->symbol.Name() + "' is declared here:", v->source);
return false; return false;
} }
} }
@ -2544,7 +2538,7 @@ bool Validator::DiagnosticControls(utils::VectorRef<const ast::DiagnosticControl
} }
{ {
utils::StringStream ss; utils::StringStream ss;
ss << "severity of '" << symbols_.NameFor(dc->rule_name->symbol) << "' set to '" ss << "severity of '" << dc->rule_name->symbol.Name() << "' set to '"
<< dc->severity << "' here"; << dc->severity << "' here";
AddNote(ss.str(), (*diag_added.value)->rule_name->source); AddNote(ss.str(), (*diag_added.value)->rule_name->source);
} }
@ -2589,7 +2583,7 @@ void Validator::RaiseArrayWithOverrideCountError(const Source& source) const {
std::string Validator::VectorPretty(uint32_t size, const type::Type* element_type) const { std::string Validator::VectorPretty(uint32_t size, const type::Type* element_type) const {
type::Vector vec_type(element_type, size); type::Vector vec_type(element_type, size);
return vec_type.FriendlyName(symbols_); return vec_type.FriendlyName();
} }
bool Validator::CheckTypeAccessAddressSpace( bool Validator::CheckTypeAccessAddressSpace(

View File

@ -33,8 +33,8 @@ bool NamedOverrideArrayCount::Equals(const UniqueNode& other) const {
return false; return false;
} }
std::string NamedOverrideArrayCount::FriendlyName(const SymbolTable& symbols) const { std::string NamedOverrideArrayCount::FriendlyName() const {
return symbols.NameFor(variable->Declaration()->name->symbol); return variable->Declaration()->name->symbol.Name();
} }
type::ArrayCount* NamedOverrideArrayCount::Clone(type::CloneContext&) const { type::ArrayCount* NamedOverrideArrayCount::Clone(type::CloneContext&) const {
@ -53,7 +53,7 @@ bool UnnamedOverrideArrayCount::Equals(const UniqueNode& other) const {
return false; return false;
} }
std::string UnnamedOverrideArrayCount::FriendlyName(const SymbolTable&) const { std::string UnnamedOverrideArrayCount::FriendlyName() const {
return "[unnamed override-expression]"; return "[unnamed override-expression]";
} }

View File

@ -40,9 +40,8 @@ class NamedOverrideArrayCount final : public Castable<NamedOverrideArrayCount, t
/// @returns true if this array count is equal @p other /// @returns true if this array count is equal @p other
bool Equals(const type::UniqueNode& other) const override; bool Equals(const type::UniqueNode& other) const override;
/// @param symbols the symbol table
/// @returns the friendly name for this array count /// @returns the friendly name for this array count
std::string FriendlyName(const SymbolTable& symbols) const override; std::string FriendlyName() const override;
/// @param ctx the clone context /// @param ctx the clone context
/// @returns a clone of this type /// @returns a clone of this type
@ -70,9 +69,8 @@ class UnnamedOverrideArrayCount final
/// @returns true if this array count is equal @p other /// @returns true if this array count is equal @p other
bool Equals(const type::UniqueNode& other) const override; bool Equals(const type::UniqueNode& other) const override;
/// @param symbols the symbol table
/// @returns the friendly name for this array count /// @returns the friendly name for this array count
std::string FriendlyName(const SymbolTable& symbols) const override; std::string FriendlyName() const override;
/// @param ctx the clone context /// @param ctx the clone context
/// @returns a clone of this type /// @returns a clone of this type

View File

@ -52,7 +52,7 @@ TEST_F(SemStructTest, FriendlyName) {
auto* impl = create<ast::Struct>(Ident(name), utils::Empty, utils::Empty); auto* impl = create<ast::Struct>(Ident(name), utils::Empty, utils::Empty);
auto* s = create<sem::Struct>(impl, impl->source, impl->name->symbol, utils::Empty, auto* s = create<sem::Struct>(impl, impl->source, impl->name->symbol, utils::Empty,
4u /* align */, 4u /* size */, 4u /* size_no_padding */); 4u /* align */, 4u /* size */, 4u /* size_no_padding */);
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct"); EXPECT_EQ(s->FriendlyName(), "my_struct");
} }
} // namespace } // namespace

View File

@ -56,11 +56,6 @@ Symbol SymbolTable::Get(const std::string& name) const {
return it ? *it : Symbol(); return it ? *it : Symbol();
} }
std::string SymbolTable::NameFor(const Symbol symbol) const {
TINT_ASSERT_PROGRAM_IDS_EQUAL(Symbol, program_id_, symbol);
return symbol.Name();
}
Symbol SymbolTable::New(std::string prefix /* = "" */) { Symbol SymbolTable::New(std::string prefix /* = "" */) {
if (prefix.empty()) { if (prefix.empty()) {
prefix = "tint_symbol"; prefix = "tint_symbol";

View File

@ -63,11 +63,6 @@ class SymbolTable {
/// @returns the symbol for the name or Symbol() if not found. /// @returns the symbol for the name or Symbol() if not found.
Symbol Get(const std::string& name) const; Symbol Get(const std::string& name) const;
/// Returns the name for the given symbol
/// @param symbol the symbol to retrieve the name for
/// @returns the symbol name or "" if not found
std::string NameFor(const Symbol symbol) const;
/// Returns a new unique symbol with the given name, possibly suffixed with a /// Returns a new unique symbol with the given name, possibly suffixed with a
/// unique number. /// unique number.
/// @param name the symbol name /// @param name the symbol name

View File

@ -36,19 +36,6 @@ TEST_F(SymbolTableTest, DeduplicatesNames) {
EXPECT_EQ(Symbol(1, program_id, "name"), s.Register("name")); EXPECT_EQ(Symbol(1, program_id, "name"), s.Register("name"));
} }
TEST_F(SymbolTableTest, ReturnsNameForSymbol) {
auto program_id = ProgramID::New();
SymbolTable s{program_id};
auto sym = s.Register("name");
EXPECT_EQ("name", s.NameFor(sym));
}
TEST_F(SymbolTableTest, ReturnsBlankForMissingSymbol) {
auto program_id = ProgramID::New();
SymbolTable s{program_id};
EXPECT_EQ("$2", s.NameFor(Symbol(2, program_id, "$2")));
}
TEST_F(SymbolTableTest, AssertsForBlankString) { TEST_F(SymbolTableTest, AssertsForBlankString) {
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
{ {

View File

@ -70,7 +70,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src,
auto* wrapper = wrapper_structs.GetOrCreate(ty, [&] { auto* wrapper = wrapper_structs.GetOrCreate(ty, [&] {
auto* block = b.ASTNodes().Create<BlockAttribute>(b.ID(), b.AllocateNodeID()); auto* block = b.ASTNodes().Create<BlockAttribute>(b.ID(), b.AllocateNodeID());
auto wrapper_name = src->Symbols().NameFor(global->name->symbol) + "_block"; auto wrapper_name = global->name->symbol.Name() + "_block";
auto* ret = b.create<ast::Struct>( auto* ret = b.create<ast::Struct>(
b.Ident(b.Symbols().New(wrapper_name)), b.Ident(b.Symbols().New(wrapper_name)),
utils::Vector{b.Member(kMemberName, CreateASTTypeFor(ctx, ty))}, utils::Vector{b.Member(kMemberName, CreateASTTypeFor(ctx, ty))},

View File

@ -351,7 +351,7 @@ struct CanonicalizeEntryPointIO::State {
} }
} }
auto name = ctx.src->Symbols().NameFor(param->Declaration()->name->symbol); auto name = param->Declaration()->name->symbol.Name();
auto* input_expr = AddInput(name, param->Type(), param->Location(), std::move(attributes)); auto* input_expr = AddInput(name, param->Type(), param->Location(), std::move(attributes));
inner_call_parameters.Push(input_expr); inner_call_parameters.Push(input_expr);
} }
@ -376,7 +376,7 @@ struct CanonicalizeEntryPointIO::State {
continue; continue;
} }
auto name = ctx.src->Symbols().NameFor(member->Name()); auto name = member->Name().Name();
auto attributes = auto attributes =
CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate); CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate);
@ -405,7 +405,7 @@ struct CanonicalizeEntryPointIO::State {
continue; continue;
} }
auto name = ctx.src->Symbols().NameFor(member->Name()); auto name = member->Name().Name();
auto attributes = auto attributes =
CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate); CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate);
@ -530,7 +530,7 @@ struct CanonicalizeEntryPointIO::State {
} else { } else {
name = ctx.dst->Symbols().Register(outval.name); name = ctx.dst->Symbols().Register(outval.name);
} }
member_names.insert(ctx.dst->Symbols().NameFor(name)); member_names.insert(name.Name());
wrapper_struct_output_members.Push({ wrapper_struct_output_members.Push({
ctx.dst->Member(name, outval.type, std::move(outval.attributes)), ctx.dst->Member(name, outval.type, std::move(outval.attributes)),
@ -598,7 +598,7 @@ struct CanonicalizeEntryPointIO::State {
} else { } else {
// Add a suffix to the function name, as the wrapper function will take // Add a suffix to the function name, as the wrapper function will take
// the original entry point name. // the original entry point name.
auto ep_name = ctx.src->Symbols().NameFor(func_ast->name->symbol); auto ep_name = func_ast->name->symbol.Name();
inner_name = ctx.dst->Symbols().New(ep_name + "_inner"); inner_name = ctx.dst->Symbols().New(ep_name + "_inner");
} }

View File

@ -127,7 +127,7 @@ struct ClampFragDepth::State {
auto helper = io_structs_clamp_helpers.GetOrCreate(struct_ty, [&] { auto helper = io_structs_clamp_helpers.GetOrCreate(struct_ty, [&] {
auto return_ty = fn->return_type; auto return_ty = fn->return_type;
auto fn_sym = auto fn_sym =
b.Symbols().New("clamp_frag_depth_" + sym.NameFor(struct_ty->name->symbol)); b.Symbols().New("clamp_frag_depth_" + struct_ty->name->symbol.Name());
utils::Vector<const ast::Expression*, 8u> initializer_args; utils::Vector<const ast::Expression*, 8u> initializer_args;
for (auto* member : struct_ty->members) { for (auto* member : struct_ty->members) {

View File

@ -183,11 +183,9 @@ struct CombineSamplers::State {
for (auto pair : fn->TextureSamplerPairs()) { for (auto pair : fn->TextureSamplerPairs()) {
const sem::Variable* texture_var = pair.first; const sem::Variable* texture_var = pair.first;
const sem::Variable* sampler_var = pair.second; const sem::Variable* sampler_var = pair.second;
std::string name = std::string name = texture_var->Declaration()->name->symbol.Name();
ctx.src->Symbols().NameFor(texture_var->Declaration()->name->symbol);
if (sampler_var) { if (sampler_var) {
name += "_" + ctx.src->Symbols().NameFor( name += "_" + sampler_var->Declaration()->name->symbol.Name();
sampler_var->Declaration()->name->symbol);
} }
if (IsGlobal(pair)) { if (IsGlobal(pair)) {
// Both texture and sampler are global; add a new global variable // Both texture and sampler are global; add a new global variable

View File

@ -468,7 +468,7 @@ struct DecomposeMemoryAccess::State {
return utils::GetOrCreate(load_funcs, LoadStoreKey{el_ty, buffer}, [&] { return utils::GetOrCreate(load_funcs, LoadStoreKey{el_ty, buffer}, [&] {
utils::Vector params{b.Param("offset", b.ty.u32())}; utils::Vector params{b.Param("offset", b.ty.u32())};
auto name = b.Symbols().New(ctx.dst->Symbols().NameFor(buffer) + "_load"); auto name = b.Symbols().New(buffer.Name() + "_load");
if (auto* intrinsic = IntrinsicLoadFor(ctx.dst, el_ty, address_space, buffer)) { if (auto* intrinsic = IntrinsicLoadFor(ctx.dst, el_ty, address_space, buffer)) {
auto el_ast_ty = CreateASTTypeFor(ctx, el_ty); auto el_ast_ty = CreateASTTypeFor(ctx, el_ty);
@ -551,7 +551,7 @@ struct DecomposeMemoryAccess::State {
b.Param("value", CreateASTTypeFor(ctx, el_ty)), b.Param("value", CreateASTTypeFor(ctx, el_ty)),
}; };
auto name = b.Symbols().New(ctx.dst->Symbols().NameFor(buffer) + "_store"); auto name = b.Symbols().New(buffer.Name() + "_store");
if (auto* intrinsic = IntrinsicStoreFor(ctx.dst, el_ty, buffer)) { if (auto* intrinsic = IntrinsicStoreFor(ctx.dst, el_ty, buffer)) {
b.Func(name, params, b.ty.void_(), nullptr, b.Func(name, params, b.ty.void_(), nullptr,
@ -677,7 +677,7 @@ struct DecomposeMemoryAccess::State {
ret_ty = CreateASTTypeFor(ctx, intrinsic->ReturnType()); ret_ty = CreateASTTypeFor(ctx, intrinsic->ReturnType());
} }
auto name = b.Symbols().New(ctx.dst->Symbols().NameFor(buffer) + intrinsic->str()); auto name = b.Symbols().New(buffer.Name() + intrinsic->str());
b.Func(name, std::move(params), ret_ty, nullptr, b.Func(name, std::move(params), ret_ty, nullptr,
utils::Vector{ utils::Vector{
atomic, atomic,

View File

@ -689,7 +689,7 @@ struct DirectVariableAccess::State {
// This is derived from the original function name and the pointer parameter // This is derived from the original function name and the pointer parameter
// chains. // chains.
utils::StringStream ss; utils::StringStream ss;
ss << ctx.src->Symbols().NameFor(target->Declaration()->name->symbol); ss << target->Declaration()->name->symbol.Name();
for (auto* param : target->Parameters()) { for (auto* param : target->Parameters()) {
if (auto indices = target_signature.Find(param)) { if (auto indices = target_signature.Find(param)) {
ss << "_" << AccessShapeName(*indices); ss << "_" << AccessShapeName(*indices);
@ -1086,7 +1086,7 @@ struct DirectVariableAccess::State {
if (IsPrivateOrFunction(shape.root.address_space)) { if (IsPrivateOrFunction(shape.root.address_space)) {
ss << "F"; ss << "F";
} else { } else {
ss << ctx.src->Symbols().NameFor(shape.root.variable->Declaration()->name->symbol); ss << shape.root.variable->Declaration()->name->symbol.Name();
} }
for (auto& op : shape.ops) { for (auto& op : shape.ops) {
@ -1100,7 +1100,7 @@ struct DirectVariableAccess::State {
auto* member = std::get_if<Symbol>(&op); auto* member = std::get_if<Symbol>(&op);
if (TINT_LIKELY(member)) { if (TINT_LIKELY(member)) {
ss << sym.NameFor(*member); ss << member->Name();
continue; continue;
} }
@ -1160,7 +1160,7 @@ struct DirectVariableAccess::State {
/// @returns a new Symbol starting with @p symbol concatenated with @p suffix, and possibly an /// @returns a new Symbol starting with @p symbol concatenated with @p suffix, and possibly an
/// underscore and number, if the symbol is already taken. /// underscore and number, if the symbol is already taken.
Symbol UniqueSymbolWithSuffix(Symbol symbol, const std::string& suffix) { Symbol UniqueSymbolWithSuffix(Symbol symbol, const std::string& suffix) {
auto str = ctx.src->Symbols().NameFor(symbol) + suffix; auto str = symbol.Name() + suffix;
return unique_symbols.GetOrCreate(str, [&] { return b.Symbols().New(str); }); return unique_symbols.GetOrCreate(str, [&] { return b.Symbols().New(str); });
} }

View File

@ -120,7 +120,7 @@ struct PackedVec3::State {
// type, to avoid changing the array element stride. // type, to avoid changing the array element stride.
return b.ty(packed_vec3_wrapper_struct_names.GetOrCreate(vec, [&]() { return b.ty(packed_vec3_wrapper_struct_names.GetOrCreate(vec, [&]() {
auto name = b.Symbols().New( auto name = b.Symbols().New(
"tint_packed_vec3_" + vec->type()->FriendlyName(src->Symbols()) + "tint_packed_vec3_" + vec->type()->FriendlyName() +
(array_element ? "_array_element" : "_struct_member")); (array_element ? "_array_element" : "_struct_member"));
auto* member = auto* member =
b.Member(kStructMemberName, MakePackedVec3(vec), b.Member(kStructMemberName, MakePackedVec3(vec),
@ -191,9 +191,8 @@ struct PackedVec3::State {
} }
} }
// Create the new structure. // Create the new structure.
auto struct_name = b.Symbols().New( auto struct_name = b.Symbols().New(str->Declaration()->name->symbol.Name() +
src->Symbols().NameFor(str->Declaration()->name->symbol) + "_tint_packed_vec3");
"_tint_packed_vec3");
b.Structure(struct_name, std::move(members)); b.Structure(struct_name, std::move(members));
return struct_name; return struct_name;
}); });

View File

@ -71,7 +71,7 @@ Transform::ApplyResult PadStructs::Apply(const Program* src, const DataMap&, Dat
bool has_runtime_sized_array = false; bool has_runtime_sized_array = false;
utils::Vector<const ast::StructMember*, 8> new_members; utils::Vector<const ast::StructMember*, 8> new_members;
for (auto* mem : str->Members()) { for (auto* mem : str->Members()) {
auto name = src->Symbols().NameFor(mem->Name()); auto name = mem->Name().Name();
if (offset < mem->Offset()) { if (offset < mem->Offset()) {
CreatePadding(&new_members, &padding_members, ctx.dst, mem->Offset() - offset); CreatePadding(&new_members, &padding_members, ctx.dst, mem->Offset() - offset);

View File

@ -165,7 +165,7 @@ struct PreservePadding::State {
return call_helper([&]() { return call_helper([&]() {
utils::Vector<const ast::Statement*, 8> body; utils::Vector<const ast::Statement*, 8> body;
for (auto member : str->Members()) { for (auto member : str->Members()) {
auto name = sym.NameFor(member->Declaration()->name->symbol); auto name = member->Declaration()->name->symbol.Name();
body.Push(MakeAssignment(member->Type(), body.Push(MakeAssignment(member->Type(),
b.MemberAccessor(b.Deref(kDestParamName), name), b.MemberAccessor(b.Deref(kDestParamName), name),
b.MemberAccessor(kValueParamName, name))); b.MemberAccessor(kValueParamName, name)));

View File

@ -1332,7 +1332,7 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
if (target == Target::kAll) { if (target == Target::kAll) {
return true; return true;
} }
auto name = src->Symbols().NameFor(symbol); auto name = symbol.Name();
if (!text::utf8::IsASCII(name)) { if (!text::utf8::IsASCII(name)) {
// name is non-ascii. All of the backend keywords are ascii, so rename if we're not // name is non-ascii. All of the backend keywords are ascii, so rename if we're not
// preserving unicode symbols. // preserving unicode symbols.
@ -1388,7 +1388,7 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
Data::Remappings out; Data::Remappings out;
for (auto it : remappings) { for (auto it : remappings) {
out[ctx.src->Symbols().NameFor(it.key)] = ctx.dst->Symbols().NameFor(it.value); out[it.key.Name()] = it.value.Name();
} }
outputs.Add<Data>(std::move(out)); outputs.Add<Data>(std::move(out));

View File

@ -264,8 +264,7 @@ struct Robustness::State {
auto* sem_param = sem.Get(param); auto* sem_param = sem.Get(param);
if (auto* ptr = sem_param->Type()->As<type::Pointer>()) { if (auto* ptr = sem_param->Type()->As<type::Pointer>()) {
if (ActionFor(ptr->AddressSpace()) == Action::kPredicate) { if (ActionFor(ptr->AddressSpace()) == Action::kPredicate) {
auto name = b.Symbols().New(src->Symbols().NameFor(param->name->symbol) + auto name = b.Symbols().New(param->name->symbol.Name() + "_predicate");
"_predicate");
ctx.InsertAfter(fn->params, param, b.Param(name, b.ty.bool_())); ctx.InsertAfter(fn->params, param, b.Param(name, b.ty.bool_()));
// Associate the pointer parameter expressions with the predicate. // Associate the pointer parameter expressions with the predicate.

View File

@ -166,8 +166,7 @@ struct SimplifyPointers::State {
// We have a sub-expression that needs to be saved. // We have a sub-expression that needs to be saved.
// Create a new variable // Create a new variable
auto saved_name = ctx.dst->Symbols().New( auto saved_name = ctx.dst->Symbols().New(
ctx.src->Symbols().NameFor(var->Declaration()->name->symbol) + var->Declaration()->name->symbol.Name() + "_save");
"_save");
auto* decl = auto* decl =
ctx.dst->Decl(ctx.dst->Let(saved_name, ctx.Clone(idx_expr))); ctx.dst->Decl(ctx.dst->Let(saved_name, ctx.Clone(idx_expr)));
saved.Push(decl); saved.Push(decl);

View File

@ -50,7 +50,7 @@ Transform::ApplyResult SingleEntryPoint::Apply(const Program* src,
if (!f->IsEntryPoint()) { if (!f->IsEntryPoint()) {
continue; continue;
} }
if (src->Symbols().NameFor(f->name->symbol) == cfg->entry_point_name) { if (f->name->symbol.Name() == cfg->entry_point_name) {
entry_point = f; entry_point = f;
break; break;
} }

Some files were not shown because too many files have changed in this diff Show More