Program: Remove deprecated symbol methods

Fixup all usages

Bug: tint:390
Change-Id: If861b044eae006af2fd86d348de6ba62f448bc6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38549
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-26 16:57:10 +00:00
parent cf757e3a89
commit d7137d7233
50 changed files with 496 additions and 498 deletions

View File

@ -40,7 +40,7 @@ Variable* Builder::Var(const std::string& name,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(program->RegisterSymbol(name), storage, type, auto* var = create<Variable>(program->Symbols().Register(name), storage, type,
false, constructor, decorations); false, constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
@ -52,8 +52,8 @@ Variable* Builder::Var(const Source& source,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(source, program->RegisterSymbol(name), storage, auto* var = create<Variable>(source, program->Symbols().Register(name),
type, false, constructor, decorations); storage, type, false, constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
} }
@ -69,7 +69,7 @@ Variable* Builder::Const(const std::string& name,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(program->RegisterSymbol(name), storage, type, auto* var = create<Variable>(program->Symbols().Register(name), storage, type,
true, constructor, decorations); true, constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
@ -81,8 +81,8 @@ Variable* Builder::Const(const Source& source,
type::Type* type, type::Type* type,
Expression* constructor, Expression* constructor,
VariableDecorationList decorations) { VariableDecorationList decorations) {
auto* var = create<Variable>(source, program->RegisterSymbol(name), storage, auto* var = create<Variable>(source, program->Symbols().Register(name),
type, true, constructor, decorations); storage, type, true, constructor, decorations);
OnVariableBuilt(var); OnVariableBuilt(var);
return var; return var;
} }

View File

@ -166,7 +166,8 @@ class TypesBuilder {
/// @param type the alias type /// @param type the alias type
/// @returns the alias pointer /// @returns the alias pointer
type::Alias* alias(const std::string& name, type::Type* type) const { type::Alias* alias(const std::string& name, type::Type* type) const {
return program_->create<type::Alias>(program_->RegisterSymbol(name), type); return program_->create<type::Alias>(program_->Symbols().Register(name),
type);
} }
/// @return the tint AST pointer to type `T` with the given StorageClass. /// @return the tint AST pointer to type `T` with the given StorageClass.
@ -180,7 +181,8 @@ class TypesBuilder {
/// @param impl the struct implementation /// @param impl the struct implementation
/// @returns a struct pointer /// @returns a struct pointer
type::Struct* struct_(const std::string& name, ast::Struct* impl) const { type::Struct* struct_(const std::string& name, ast::Struct* impl) const {
return program_->create<type::Struct>(program_->RegisterSymbol(name), impl); return program_->create<type::Struct>(program_->Symbols().Register(name),
impl);
} }
private: private:
@ -227,20 +229,21 @@ class Builder {
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const std::string& name) { IdentifierExpression* Expr(const std::string& name) {
return create<IdentifierExpression>(program->RegisterSymbol(name)); return create<IdentifierExpression>(program->Symbols().Register(name));
} }
/// @param source the source information /// @param source the source information
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const Source& source, const std::string& name) { IdentifierExpression* Expr(const Source& source, const std::string& name) {
return create<IdentifierExpression>(source, program->RegisterSymbol(name)); return create<IdentifierExpression>(source,
program->Symbols().Register(name));
} }
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const char* name) { IdentifierExpression* Expr(const char* name) {
return create<IdentifierExpression>(program->RegisterSymbol(name)); return create<IdentifierExpression>(program->Symbols().Register(name));
} }
/// @param value the boolean value /// @param value the boolean value
@ -620,7 +623,7 @@ class Builder {
ast::StatementList body, ast::StatementList body,
ast::FunctionDecorationList decorations) { ast::FunctionDecorationList decorations) {
return program->create<ast::Function>( return program->create<ast::Function>(
source, program->RegisterSymbol(name), params, type, source, program->Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations); create<ast::BlockStatement>(body), decorations);
} }
@ -636,8 +639,8 @@ class Builder {
type::Type* type, type::Type* type,
ast::StatementList body, ast::StatementList body,
ast::FunctionDecorationList decorations) { ast::FunctionDecorationList decorations) {
return create<ast::Function>(program->RegisterSymbol(name), params, type, return create<ast::Function>(program->Symbols().Register(name), params,
create<ast::BlockStatement>(body), type, create<ast::BlockStatement>(body),
decorations); decorations);
} }
@ -649,7 +652,8 @@ class Builder {
StructMember* Member(const Source& source, StructMember* Member(const Source& source,
const std::string& name, const std::string& name,
type::Type* type) { type::Type* type) {
return program->create<StructMember>(source, program->RegisterSymbol(name), return program->create<StructMember>(source,
program->Symbols().Register(name),
type, StructMemberDecorationList{}); type, StructMemberDecorationList{});
} }
@ -658,7 +662,8 @@ class Builder {
/// @param type the struct member type /// @param type the struct member type
/// @returns the struct member pointer /// @returns the struct member pointer
StructMember* Member(const std::string& name, type::Type* type) { StructMember* Member(const std::string& name, type::Type* type) {
return program->create<StructMember>(source_, program->RegisterSymbol(name), return program->create<StructMember>(source_,
program->Symbols().Register(name),
type, StructMemberDecorationList{}); type, StructMemberDecorationList{});
} }
@ -670,8 +675,8 @@ class Builder {
StructMember* Member(const std::string& name, StructMember* Member(const std::string& name,
type::Type* type, type::Type* type,
StructMemberDecorationList decos) { StructMemberDecorationList decos) {
return program->create<StructMember>(source_, program->RegisterSymbol(name), return program->create<StructMember>(
type, decos); source_, program->Symbols().Register(name), type, decos);
} }
/// Creates a new Node owned by the Module, with the explicit Source. /// Creates a new Node owned by the Module, with the explicit Source.

View File

@ -36,7 +36,7 @@ TEST_F(FunctionTest, Creation) {
auto* f = auto* f =
Func("func", params, ty.void_, StatementList{}, FunctionDecorationList{}); Func("func", params, ty.void_, StatementList{}, FunctionDecorationList{});
EXPECT_EQ(f->symbol(), mod->RegisterSymbol("func")); EXPECT_EQ(f->symbol(), mod->Symbols().Register("func"));
ASSERT_EQ(f->params().size(), 1u); ASSERT_EQ(f->params().size(), 1u);
EXPECT_EQ(f->return_type(), ty.void_); EXPECT_EQ(f->return_type(), ty.void_);
EXPECT_EQ(f->params()[0], var); EXPECT_EQ(f->params()[0], var);
@ -151,7 +151,7 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) {
auto* f = Func("func", VariableList{}, ty.void_, StatementList{}, auto* f = Func("func", VariableList{}, ty.void_, StatementList{},
FunctionDecorationList{}); FunctionDecorationList{});
auto main_sym = mod->RegisterSymbol("main"); auto main_sym = mod->Symbols().Register("main");
f->add_ancestor_entry_point(main_sym); f->add_ancestor_entry_point(main_sym);
ASSERT_EQ(1u, f->ancestor_entry_points().size()); ASSERT_EQ(1u, f->ancestor_entry_points().size());
EXPECT_EQ(main_sym, f->ancestor_entry_points()[0]); EXPECT_EQ(main_sym, f->ancestor_entry_points()[0]);
@ -364,12 +364,12 @@ TEST_F(FunctionListTest, FindSymbol) {
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
FunctionList list; FunctionList list;
list.Add(func); list.Add(func);
EXPECT_EQ(func, list.Find(mod->RegisterSymbol("main"))); EXPECT_EQ(func, list.Find(mod->Symbols().Register("main")));
} }
TEST_F(FunctionListTest, FindSymbolMissing) { TEST_F(FunctionListTest, FindSymbolMissing) {
FunctionList list; FunctionList list;
EXPECT_EQ(nullptr, list.Find(mod->RegisterSymbol("Missing"))); EXPECT_EQ(nullptr, list.Find(mod->Symbols().Register("Missing")));
} }
TEST_F(FunctionListTest, FindSymbolStage) { TEST_F(FunctionListTest, FindSymbolStage) {
@ -384,9 +384,10 @@ TEST_F(FunctionListTest, FindSymbolStage) {
FunctionList list; FunctionList list;
list.Add(fs); list.Add(fs);
list.Add(vs); list.Add(vs);
EXPECT_EQ(fs, EXPECT_EQ(
list.Find(mod->RegisterSymbol("main"), PipelineStage::kFragment)); fs, list.Find(mod->Symbols().Register("main"), PipelineStage::kFragment));
EXPECT_EQ(vs, list.Find(mod->RegisterSymbol("main"), PipelineStage::kVertex)); EXPECT_EQ(vs,
list.Find(mod->Symbols().Register("main"), PipelineStage::kVertex));
} }
TEST_F(FunctionListTest, FindSymbolStageMissing) { TEST_F(FunctionListTest, FindSymbolStageMissing) {
@ -396,7 +397,7 @@ TEST_F(FunctionListTest, FindSymbolStageMissing) {
create<ast::StageDecoration>(PipelineStage::kFragment), create<ast::StageDecoration>(PipelineStage::kFragment),
})); }));
EXPECT_EQ(nullptr, EXPECT_EQ(nullptr,
list.Find(mod->RegisterSymbol("main"), PipelineStage::kVertex)); list.Find(mod->Symbols().Register("main"), PipelineStage::kVertex));
} }
TEST_F(FunctionListTest, HasStage) { TEST_F(FunctionListTest, HasStage) {

View File

@ -23,7 +23,7 @@ CloneContext::CloneContext(Program* to, Program const* from)
CloneContext::~CloneContext() = default; CloneContext::~CloneContext() = default;
Symbol CloneContext::Clone(const Symbol& s) const { Symbol CloneContext::Clone(const Symbol& s) const {
return dst->RegisterSymbol(src->SymbolToName(s)); return dst->Symbols().Register(src->Symbols().NameFor(s));
} }
void CloneContext::Clone() { void CloneContext::Clone() {

View File

@ -46,7 +46,7 @@ std::string Demangler::Demangle(const Program& program,
auto id = ret.substr(start_idx, len); auto id = ret.substr(start_idx, len);
Symbol sym(std::stoi(id)); Symbol sym(std::stoi(id));
auto name = program.SymbolToName(sym); auto name = program.Symbols().NameFor(sym);
ret.replace(idx, end_idx - idx, name); ret.replace(idx, end_idx - idx, name);
pos = idx + name.length(); pos = idx + name.length();

View File

@ -24,7 +24,7 @@ using DemanglerTest = testing::Test;
TEST_F(DemanglerTest, NoSymbols) { TEST_F(DemanglerTest, NoSymbols) {
Program m; Program m;
m.RegisterSymbol("sym1"); m.Symbols().Register("sym1");
Demangler d; Demangler d;
EXPECT_EQ("test str", d.Demangle(m, "test str")); EXPECT_EQ("test str", d.Demangle(m, "test str"));
@ -32,7 +32,7 @@ TEST_F(DemanglerTest, NoSymbols) {
TEST_F(DemanglerTest, Symbol) { TEST_F(DemanglerTest, Symbol) {
Program m; Program m;
m.RegisterSymbol("sym1"); m.Symbols().Register("sym1");
Demangler d; Demangler d;
EXPECT_EQ("test sym1 str", d.Demangle(m, "test tint_symbol_1 str")); EXPECT_EQ("test sym1 str", d.Demangle(m, "test tint_symbol_1 str"));
@ -40,8 +40,8 @@ TEST_F(DemanglerTest, Symbol) {
TEST_F(DemanglerTest, MultipleSymbols) { TEST_F(DemanglerTest, MultipleSymbols) {
Program m; Program m;
m.RegisterSymbol("sym1"); m.Symbols().Register("sym1");
m.RegisterSymbol("sym2"); m.Symbols().Register("sym2");
Demangler d; Demangler d;
EXPECT_EQ( EXPECT_EQ(

View File

@ -56,14 +56,14 @@ std::vector<EntryPoint> Inspector::GetEntryPoints() {
} }
EntryPoint entry_point; EntryPoint entry_point;
entry_point.name = program_.SymbolToName(func->symbol()); entry_point.name = program_.Symbols().NameFor(func->symbol());
entry_point.remapped_name = program_.SymbolToName(func->symbol()); entry_point.remapped_name = program_.Symbols().NameFor(func->symbol());
entry_point.stage = func->pipeline_stage(); entry_point.stage = func->pipeline_stage();
std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y, std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y,
entry_point.workgroup_size_z) = func->workgroup_size(); entry_point.workgroup_size_z) = func->workgroup_size();
for (auto* var : func->referenced_module_variables()) { for (auto* var : func->referenced_module_variables()) {
auto name = program_.SymbolToName(var->symbol()); auto name = program_.Symbols().NameFor(var->symbol());
if (var->HasBuiltinDecoration()) { if (var->HasBuiltinDecoration()) {
continue; continue;
} }
@ -283,7 +283,7 @@ std::vector<ResourceBinding> Inspector::GetMultisampledTextureResourceBindings(
} }
ast::Function* Inspector::FindEntryPointByName(const std::string& name) { ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
auto* func = program_.AST().Functions().Find(program_.GetSymbol(name)); auto* func = program_.AST().Functions().Find(program_.Symbols().Get(name));
if (!func) { if (!func) {
error_ += name + " was not found!"; error_ += name + " was not found!";
return nullptr; return nullptr;

View File

@ -47,18 +47,6 @@ void Program::Clone(CloneContext* ctx) const {
} }
} }
Symbol Program::RegisterSymbol(const std::string& name) {
return symbols_.Register(name);
}
Symbol Program::GetSymbol(const std::string& name) const {
return symbols_.Get(name);
}
std::string Program::SymbolToName(const Symbol sym) const {
return symbols_.NameFor(sym);
}
bool Program::IsValid() const { bool Program::IsValid() const {
return ast_->IsValid(); return ast_->IsValid();
} }

View File

@ -118,25 +118,6 @@ class Program {
return types_.Get<T>(std::forward<ARGS>(args)...); return types_.Get<T>(std::forward<ARGS>(args)...);
} }
/// Registers `name` as a symbol
/// @param name the name to register
/// @returns the symbol for the `name`. If `name` is already registered the
/// previously generated symbol will be returned.
/// [DEPRECATED]: Use Symbols().Register()
Symbol RegisterSymbol(const std::string& name);
/// Returns the symbol for `name`
/// @param name the name to lookup
/// @returns the symbol for name or symbol::kInvalid
/// [DEPRECATED]: Use Symbols().Get()
Symbol GetSymbol(const std::string& name) const;
/// Returns the `name` for `sym`
/// @param sym the symbol to retrieve the name for
/// @returns the use provided `name` for the symbol or "" if not found
/// [DEPRECATED]: Use Symbols().NameFor()
std::string SymbolToName(const Symbol sym) const;
private: private:
Program(const Program&) = delete; Program(const Program&) = delete;

View File

@ -786,7 +786,7 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
const auto& top = statements_stack_.back(); const auto& top = statements_stack_.back();
auto* cond = create<ast::IdentifierExpression>( auto* cond = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(guard_name)); Source{}, program_.Symbols().Register(guard_name));
auto* builder = AddStatementBuilder<IfStatementBuilder>(cond); auto* builder = AddStatementBuilder<IfStatementBuilder>(cond);
PushNewStatementBlock( PushNewStatementBlock(
@ -859,9 +859,10 @@ bool FunctionEmitter::Emit() {
auto& statements = statements_stack_[0].GetStatements(); auto& statements = statements_stack_[0].GetStatements();
auto* body = create<ast::BlockStatement>(Source{}, statements); auto* body = create<ast::BlockStatement>(Source{}, statements);
program_.AST().Functions().Add(create<ast::Function>( program_.AST().Functions().Add(
decl.source, program_.RegisterSymbol(decl.name), std::move(decl.params), create<ast::Function>(decl.source, program_.Symbols().Register(decl.name),
decl.return_type, body, std::move(decl.decorations))); std::move(decl.params), decl.return_type, body,
std::move(decl.decorations)));
// Maintain the invariant by repopulating the one and only element. // Maintain the invariant by repopulating the one and only element.
statements_stack_.clear(); statements_stack_.clear();
@ -2012,7 +2013,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
return TypedExpression{ return TypedExpression{
parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()), parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()),
create<ast::IdentifierExpression>(Source{}, create<ast::IdentifierExpression>(Source{},
program_.RegisterSymbol(name))}; program_.Symbols().Register(name))};
} }
if (singly_used_values_.count(id)) { if (singly_used_values_.count(id)) {
auto expr = std::move(singly_used_values_[id]); auto expr = std::move(singly_used_values_[id]);
@ -2034,7 +2035,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
auto name = namer_.Name(inst->result_id()); auto name = namer_.Name(inst->result_id());
return TypedExpression{parser_impl_.ConvertType(inst->type_id()), return TypedExpression{parser_impl_.ConvertType(inst->type_id()),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(name))}; Source{}, program_.Symbols().Register(name))};
} }
default: default:
break; break;
@ -2263,14 +2264,14 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
const std::string guard_name = block_info.flow_guard_name; const std::string guard_name = block_info.flow_guard_name;
if (!guard_name.empty()) { if (!guard_name.empty()) {
// Declare the guard variable just before the "if", initialized to true. // Declare the guard variable just before the "if", initialized to true.
auto* guard_var = auto* guard_var = create<ast::Variable>(
create<ast::Variable>(Source{}, // source Source{}, // source
program_.RegisterSymbol(guard_name), // symbol program_.Symbols().Register(guard_name), // symbol
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
parser_impl_.Bool(), // type parser_impl_.Bool(), // type
false, // is_const false, // is_const
MakeTrue(Source{}), // constructor MakeTrue(Source{}), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* guard_decl = create<ast::VariableDeclStatement>(Source{}, guard_var); auto* guard_decl = create<ast::VariableDeclStatement>(Source{}, guard_var);
AddStatement(guard_decl); AddStatement(guard_decl);
} }
@ -2672,7 +2673,7 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
return create<ast::AssignmentStatement>( return create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(flow_guard)), Source{}, program_.Symbols().Register(flow_guard)),
MakeFalse(Source{})); MakeFalse(Source{}));
} }
@ -2793,7 +2794,7 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
assert(!phi_var_name.empty()); assert(!phi_var_name.empty());
auto* var = create<ast::Variable>( auto* var = create<ast::Variable>(
Source{}, // source Source{}, // source
program_.RegisterSymbol(phi_var_name), // symbol program_.Symbols().Register(phi_var_name), // symbol
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
parser_impl_.ConvertType(def_inst->type_id()), // type parser_impl_.ConvertType(def_inst->type_id()), // type
false, // is_const false, // is_const
@ -2831,8 +2832,8 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
auto expr = MakeExpression(assignment.value); auto expr = MakeExpression(assignment.value);
AddStatement(create<ast::AssignmentStatement>( AddStatement(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, create<ast::IdentifierExpression>(
program_.RegisterSymbol(var_name)), Source{}, program_.Symbols().Register(var_name)),
expr.expr)); expr.expr));
} }
} }
@ -2870,7 +2871,7 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
AddStatement(create<ast::AssignmentStatement>( AddStatement(create<ast::AssignmentStatement>(
Source{}, Source{},
create<ast::IdentifierExpression>(Source{}, create<ast::IdentifierExpression>(Source{},
program_.RegisterSymbol(name)), program_.Symbols().Register(name)),
ast_expr.expr)); ast_expr.expr));
return true; return true;
} }
@ -3009,7 +3010,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
TypedExpression expr{ TypedExpression expr{
parser_impl_.ConvertType(inst.type_id()), parser_impl_.ConvertType(inst.type_id()),
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(def_info->phi_var))}; Source{}, program_.Symbols().Register(def_info->phi_var))};
return EmitConstDefOrWriteToHoistedVar(inst, expr); return EmitConstDefOrWriteToHoistedVar(inst, expr);
} }
@ -3072,7 +3073,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
create<ast::CallExpression>( create<ast::CallExpression>(
Source{}, Source{},
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(unary_builtin_name)), Source{}, program_.Symbols().Register(unary_builtin_name)),
std::move(params))}; std::move(params))};
} }
@ -3177,8 +3178,8 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
return {}; return {};
} }
auto* func = create<ast::IdentifierExpression>(Source{}, auto* func = create<ast::IdentifierExpression>(
program_.RegisterSymbol(name)); Source{}, program_.Symbols().Register(name));
ast::ExpressionList operands; ast::ExpressionList operands;
type::Type* first_operand_type = nullptr; type::Type* first_operand_type = nullptr;
// All parameters to GLSL.std.450 extended instructions are IDs. // All parameters to GLSL.std.450 extended instructions are IDs.
@ -3204,20 +3205,20 @@ ast::IdentifierExpression* FunctionEmitter::Swizzle(uint32_t i) {
} }
const char* names[] = {"x", "y", "z", "w"}; const char* names[] = {"x", "y", "z", "w"};
return create<ast::IdentifierExpression>( return create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(names[i & 3])); Source{}, program_.Symbols().Register(names[i & 3]));
} }
ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) { ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) {
switch (n) { switch (n) {
case 1: case 1:
return create<ast::IdentifierExpression>(Source{}, return create<ast::IdentifierExpression>(
program_.RegisterSymbol("x")); Source{}, program_.Symbols().Register("x"));
case 2: case 2:
return create<ast::IdentifierExpression>(Source{}, return create<ast::IdentifierExpression>(
program_.RegisterSymbol("xy")); Source{}, program_.Symbols().Register("xy"));
case 3: case 3:
return create<ast::IdentifierExpression>(Source{}, return create<ast::IdentifierExpression>(
program_.RegisterSymbol("xyz")); Source{}, program_.Symbols().Register("xyz"));
default: default:
break; break;
} }
@ -3312,7 +3313,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name = namer_.Name(base_id); auto name = namer_.Name(base_id);
current_expr.expr = create<ast::IdentifierExpression>( current_expr.expr = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(name)); Source{}, program_.Symbols().Register(name));
current_expr.type = parser_impl_.ConvertType(ptr_ty_id); current_expr.type = parser_impl_.ConvertType(ptr_ty_id);
} }
} }
@ -3405,7 +3406,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
auto name = auto name =
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val)); namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val));
auto* member_access = create<ast::IdentifierExpression>( auto* member_access = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(name)); Source{}, program_.Symbols().Register(name));
next_expr = create<ast::MemberAccessorExpression>( next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access); Source{}, current_expr.expr, member_access);
@ -3526,7 +3527,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
} }
auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val)); auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val));
auto* member_access = create<ast::IdentifierExpression>( auto* member_access = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(name)); Source{}, program_.Symbols().Register(name));
next_expr = create<ast::MemberAccessorExpression>( next_expr = create<ast::MemberAccessorExpression>(
Source{}, current_expr.expr, member_access); Source{}, current_expr.expr, member_access);
@ -3931,7 +3932,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
// We ignore function attributes such as Inline, DontInline, Pure, Const. // We ignore function attributes such as Inline, DontInline, Pure, Const.
auto name = namer_.Name(inst.GetSingleWordInOperand(0)); auto name = namer_.Name(inst.GetSingleWordInOperand(0));
auto* function = create<ast::IdentifierExpression>( auto* function = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(name)); Source{}, program_.Symbols().Register(name));
ast::ExpressionList params; ast::ExpressionList params;
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) { for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
@ -3960,7 +3961,7 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
ss << intrinsic; ss << intrinsic;
auto name = ss.str(); auto name = ss.str();
auto* ident = create<ast::IdentifierExpression>( auto* ident = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(name)); Source{}, program_.Symbols().Register(name));
ident->set_intrinsic(intrinsic); ident->set_intrinsic(intrinsic);
ast::ExpressionList params; ast::ExpressionList params;
@ -4003,11 +4004,12 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
params.push_back(operand2.expr); params.push_back(operand2.expr);
// The condition goes last. // The condition goes last.
params.push_back(condition.expr); params.push_back(condition.expr);
return {operand1.type, create<ast::CallExpression>( return {operand1.type,
Source{}, create<ast::CallExpression>(
create<ast::IdentifierExpression>( Source{},
Source{}, program_.RegisterSymbol("select")), create<ast::IdentifierExpression>(
std::move(params))}; Source{}, program_.Symbols().Register("select")),
std::move(params))};
} }
return {}; return {};
} }
@ -4056,7 +4058,7 @@ ast::Expression* FunctionEmitter::GetImageExpression(
} }
auto name = namer_.Name(image->result_id()); auto name = namer_.Name(image->result_id());
return create<ast::IdentifierExpression>(GetSourceForInst(inst), return create<ast::IdentifierExpression>(GetSourceForInst(inst),
program_.RegisterSymbol(name)); program_.Symbols().Register(name));
} }
ast::Expression* FunctionEmitter::GetSamplerExpression( ast::Expression* FunctionEmitter::GetSamplerExpression(
@ -4072,7 +4074,7 @@ ast::Expression* FunctionEmitter::GetSamplerExpression(
} }
auto name = namer_.Name(image->result_id()); auto name = namer_.Name(image->result_id());
return create<ast::IdentifierExpression>(GetSourceForInst(inst), return create<ast::IdentifierExpression>(GetSourceForInst(inst),
program_.RegisterSymbol(name)); program_.Symbols().Register(name));
} }
bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
@ -4259,7 +4261,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
} }
auto* ident = create<ast::IdentifierExpression>( auto* ident = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(builtin_name)); Source{}, program_.Symbols().Register(builtin_name));
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(Source{}, ident, std::move(params)); create<ast::CallExpression>(Source{}, ident, std::move(params));
@ -4567,14 +4569,14 @@ TypedExpression FunctionEmitter::MakeArrayLength(
} }
auto* member_ident = create<ast::IdentifierExpression>( auto* member_ident = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(field_name)); Source{}, program_.Symbols().Register(field_name));
auto* member_access = create<ast::MemberAccessorExpression>( auto* member_access = create<ast::MemberAccessorExpression>(
Source{}, MakeExpression(struct_ptr_id).expr, member_ident); Source{}, MakeExpression(struct_ptr_id).expr, member_ident);
// Generate the intrinsic function call. // Generate the intrinsic function call.
std::string call_ident_str = "arrayLength"; std::string call_ident_str = "arrayLength";
auto* call_ident = create<ast::IdentifierExpression>( auto* call_ident = create<ast::IdentifierExpression>(
Source{}, program_.RegisterSymbol(call_ident_str)); Source{}, program_.Symbols().Register(call_ident_str));
call_ident->set_intrinsic(ast::Intrinsic::kArrayLength); call_ident->set_intrinsic(ast::Intrinsic::kArrayLength);
ast::ExpressionList params{member_access}; ast::ExpressionList params{member_access};

View File

@ -947,7 +947,7 @@ type::Type* ParserImpl::ConvertType(
} }
const auto member_name = namer_.GetMemberName(type_id, member_index); const auto member_name = namer_.GetMemberName(type_id, member_index);
auto* ast_struct_member = create<ast::StructMember>( auto* ast_struct_member = create<ast::StructMember>(
Source{}, program_.RegisterSymbol(member_name), ast_member_ty, Source{}, program_.Symbols().Register(member_name), ast_member_ty,
std::move(ast_member_decorations)); std::move(ast_member_decorations));
ast_members.push_back(ast_struct_member); ast_members.push_back(ast_struct_member);
} }
@ -963,8 +963,8 @@ type::Type* ParserImpl::ConvertType(
namer_.SuggestSanitizedName(type_id, "S"); namer_.SuggestSanitizedName(type_id, "S");
auto name = namer_.GetName(type_id); auto name = namer_.GetName(type_id);
auto* result = auto* result = program_.create<type::Struct>(
program_.create<type::Struct>(program_.RegisterSymbol(name), ast_struct); program_.Symbols().Register(name), ast_struct);
id_to_type_[type_id] = result; id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) { if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(result); read_only_struct_types_.insert(result);
@ -1130,7 +1130,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
} }
const auto name = namer_.GetName(type_id); const auto name = namer_.GetName(type_id);
auto* ast_alias_type = program_.create<type::Alias>( auto* ast_alias_type = program_.create<type::Alias>(
program_.RegisterSymbol(name), ast_underlying_type); program_.Symbols().Register(name), ast_underlying_type);
// Record this new alias as the AST type for this SPIR-V ID. // Record this new alias as the AST type for this SPIR-V ID.
id_to_type_[type_id] = ast_alias_type; id_to_type_[type_id] = ast_alias_type;
program_.AST().AddConstructedType(ast_alias_type); program_.AST().AddConstructedType(ast_alias_type);
@ -1306,13 +1306,13 @@ ast::Variable* ParserImpl::MakeVariable(
} }
std::string name = namer_.Name(id); std::string name = namer_.Name(id);
return create<ast::Variable>(Source{}, // source return create<ast::Variable>(Source{}, // source
program_.RegisterSymbol(name), // symbol program_.Symbols().Register(name), // symbol
sc, // storage_class sc, // storage_class
type, // type type, // type
is_const, // is_const is_const, // is_const
constructor, // constructor constructor, // constructor
decorations); // decorations decorations); // decorations
} }
TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) { TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {

View File

@ -81,7 +81,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str(); const auto program_ast = p->get_program().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().GetSymbol("main").to_str() + Function )" + p->get_program().Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
@ -101,7 +101,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str(); const auto program_ast = p->get_program().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().GetSymbol("main").to_str() + Function )" + p->get_program().Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
StageDecoration{fragment} StageDecoration{fragment}
() ()
@ -121,7 +121,7 @@ OpFunctionEnd)";
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str(); const auto program_ast = p->get_program().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().GetSymbol("main").to_str() + Function )" + p->get_program().Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
StageDecoration{compute} StageDecoration{compute}
() ()
@ -143,13 +143,13 @@ OpFunctionEnd)";
ASSERT_TRUE(p->error().empty()) << p->error(); ASSERT_TRUE(p->error().empty()) << p->error();
const auto program_ast = p->get_program().to_str(); const auto program_ast = p->get_program().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().GetSymbol("frag_main").to_str() + Function )" + p->get_program().Symbols().Get("frag_main").to_str() +
R"( -> __void R"( -> __void
StageDecoration{fragment} StageDecoration{fragment}
() ()
{)")); {)"));
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().GetSymbol("comp_main").to_str() + Function )" + p->get_program().Symbols().Get("comp_main").to_str() +
R"( -> __void R"( -> __void
StageDecoration{compute} StageDecoration{compute}
() ()
@ -167,7 +167,7 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) {
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto program_ast = p->get_program().to_str(); const auto program_ast = p->get_program().to_str();
EXPECT_THAT(program_ast, HasSubstr(R"( EXPECT_THAT(program_ast, HasSubstr(R"(
Function )" + p->get_program().GetSymbol("main").to_str() + Function )" + p->get_program().Symbols().Get("main").to_str() +
R"( -> __void R"( -> __void
() ()
{)")); {)"));

View File

@ -361,7 +361,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
auto* type = str.value; auto* type = str.value;
register_constructed( register_constructed(
program_.SymbolToName(type->As<type::Struct>()->symbol()), type); program_.Symbols().NameFor(type->As<type::Struct>()->symbol()), type);
program_.AST().AddConstructedType(type); program_.AST().AddConstructedType(type);
return true; return true;
} }
@ -435,13 +435,14 @@ Maybe<ast::Variable*> ParserImpl::global_variable_decl(
constructor = expr.value; constructor = expr.value;
} }
return create<ast::Variable>(decl->source, // source return create<ast::Variable>(
program_.RegisterSymbol(decl->name), // symbol decl->source, // source
decl->storage_class, // storage_class program_.Symbols().Register(decl->name), // symbol
decl->type, // type decl->storage_class, // storage_class
false, // is_const decl->type, // type
constructor, // constructor false, // is_const
std::move(var_decos.value)); // decorations constructor, // constructor
std::move(var_decos.value)); // decorations
} }
// global_constant_decl // global_constant_decl
@ -463,13 +464,14 @@ Maybe<ast::Variable*> ParserImpl::global_constant_decl() {
if (init.errored) if (init.errored)
return Failure::kErrored; return Failure::kErrored;
return create<ast::Variable>(decl->source, // source return create<ast::Variable>(
program_.RegisterSymbol(decl->name), // symbol decl->source, // source
ast::StorageClass::kNone, // storage_class program_.Symbols().Register(decl->name), // symbol
decl->type, // type ast::StorageClass::kNone, // storage_class
true, // is_const decl->type, // type
init.value, // constructor true, // is_const
ast::VariableDecorationList{}); // decorations init.value, // constructor
ast::VariableDecorationList{}); // decorations
} }
// variable_decl // variable_decl
@ -974,7 +976,7 @@ Maybe<type::Type*> ParserImpl::type_alias() {
return add_error(peek(), "invalid type alias"); return add_error(peek(), "invalid type alias");
auto* alias = program_.create<type::Alias>( auto* alias = program_.create<type::Alias>(
program_.RegisterSymbol(name.value), type.value); program_.Symbols().Register(name.value), type.value);
register_constructed(name.value, alias); register_constructed(name.value, alias);
return alias; return alias;
@ -1227,7 +1229,7 @@ Maybe<type::Struct*> ParserImpl::struct_decl(ast::DecorationList& decos) {
return Failure::kErrored; return Failure::kErrored;
return create<type::Struct>( return create<type::Struct>(
program_.RegisterSymbol(name.value), program_.Symbols().Register(name.value),
create<ast::Struct>(source, std::move(body.value), create<ast::Struct>(source, std::move(body.value),
std::move(struct_decos.value))); std::move(struct_decos.value)));
} }
@ -1282,7 +1284,7 @@ Expect<ast::StructMember*> ParserImpl::expect_struct_member(
return Failure::kErrored; return Failure::kErrored;
return create<ast::StructMember>(decl->source, return create<ast::StructMember>(decl->source,
program_.RegisterSymbol(decl->name), program_.Symbols().Register(decl->name),
decl->type, std::move(member_decos.value)); decl->type, std::move(member_decos.value));
} }
@ -1319,7 +1321,7 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
return Failure::kErrored; return Failure::kErrored;
return create<ast::Function>( return create<ast::Function>(
header->source, program_.RegisterSymbol(header->name), header->params, header->source, program_.Symbols().Register(header->name), header->params,
header->return_type, body.value, func_decos.value); header->return_type, body.value, func_decos.value);
} }
@ -1387,14 +1389,14 @@ Expect<ast::VariableList> ParserImpl::expect_param_list() {
ast::VariableList ret; ast::VariableList ret;
for (;;) { for (;;) {
auto* var = auto* var = create<ast::Variable>(
create<ast::Variable>(decl->source, // source decl->source, // source
program_.RegisterSymbol(decl->name), // symbol program_.Symbols().Register(decl->name), // symbol
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
decl->type, // type decl->type, // type
true, // is_const true, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
// Formal parameters are treated like a const declaration where the // Formal parameters are treated like a const declaration where the
// initializer value is provided by the call's argument. The key point is // initializer value is provided by the call's argument. The key point is
// that it's not updatable after intially set. This is unlike C or GLSL // that it's not updatable after intially set. This is unlike C or GLSL
@ -1658,14 +1660,14 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
if (!constructor.matched) if (!constructor.matched)
return add_error(peek(), "missing constructor for const declaration"); return add_error(peek(), "missing constructor for const declaration");
auto* var = auto* var = create<ast::Variable>(
create<ast::Variable>(decl->source, // source decl->source, // source
program_.RegisterSymbol(decl->name), // symbol program_.Symbols().Register(decl->name), // symbol
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
decl->type, // type decl->type, // type
true, // is_const true, // is_const
constructor.value, // constructor constructor.value, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
return create<ast::VariableDeclStatement>(decl->source, var); return create<ast::VariableDeclStatement>(decl->source, var);
} }
@ -1688,8 +1690,8 @@ Maybe<ast::VariableDeclStatement*> ParserImpl::variable_stmt() {
} }
auto* var = auto* var =
create<ast::Variable>(decl->source, // source create<ast::Variable>(decl->source, // source
program_.RegisterSymbol(decl->name), // symbol program_.Symbols().Register(decl->name), // symbol
decl->storage_class, // storage_class decl->storage_class, // storage_class
decl->type, // type decl->type, // type
false, // is_const false, // is_const
@ -2088,11 +2090,11 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
return Failure::kErrored; return Failure::kErrored;
return create<ast::CallStatement>( return create<ast::CallStatement>(
Source{}, Source{}, create<ast::CallExpression>(
create<ast::CallExpression>(source, source,
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
source, program_.RegisterSymbol(name)), source, program_.Symbols().Register(name)),
std::move(params))); std::move(params)));
} }
// break_stmt // break_stmt
@ -2164,7 +2166,7 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
if (match(Token::Type::kIdentifier)) if (match(Token::Type::kIdentifier))
return create<ast::IdentifierExpression>( return create<ast::IdentifierExpression>(
t.source(), program_.RegisterSymbol(t.to_str())); t.source(), program_.Symbols().Register(t.to_str()));
auto type = type_decl(); auto type = type_decl();
if (type.errored) if (type.errored)
@ -2240,7 +2242,7 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
return postfix_expr(create<ast::MemberAccessorExpression>( return postfix_expr(create<ast::MemberAccessorExpression>(
ident.source, prefix, ident.source, prefix,
create<ast::IdentifierExpression>( create<ast::IdentifierExpression>(
ident.source, program_.RegisterSymbol(ident.value)))); ident.source, program_.Symbols().Register(ident.value))));
} }
return prefix; return prefix;

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, AndExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -42,7 +42,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
ASSERT_TRUE(e->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(e->lhs()->Is<ast::IdentifierExpression>());
auto* ident = e->lhs()->As<ast::IdentifierExpression>(); auto* ident = e->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(e->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(e->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(e->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(e->rhs()->Is<ast::ScalarConstructorExpression>());
@ -77,7 +77,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
auto* ident = mem->member()->As<ast::IdentifierExpression>(); auto* ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("d")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("d"));
ASSERT_TRUE(mem->structure()->Is<ast::ArrayAccessorExpression>()); ASSERT_TRUE(mem->structure()->Is<ast::ArrayAccessorExpression>());
auto* ary = mem->structure()->As<ast::ArrayAccessorExpression>(); auto* ary = mem->structure()->As<ast::ArrayAccessorExpression>();
@ -93,18 +93,18 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
mem = ary->array()->As<ast::MemberAccessorExpression>(); mem = ary->array()->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
ident = mem->member()->As<ast::IdentifierExpression>(); ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("c")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("c"));
ASSERT_TRUE(mem->structure()->Is<ast::MemberAccessorExpression>()); ASSERT_TRUE(mem->structure()->Is<ast::MemberAccessorExpression>());
mem = mem->structure()->As<ast::MemberAccessorExpression>(); mem = mem->structure()->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(mem->structure()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(mem->structure()->Is<ast::IdentifierExpression>());
ident = mem->structure()->As<ast::IdentifierExpression>(); ident = mem->structure()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(mem->member()->Is<ast::IdentifierExpression>());
ident = mem->member()->As<ast::IdentifierExpression>(); ident = mem->member()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("b")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("b"));
} }
TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) { TEST_F(ParserImplTest, AssignmentStmt_MissingEqual) {

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, Statement_Call) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* ident = c->func()->As<ast::IdentifierExpression>(); auto* ident = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(c->params().size(), 0u); EXPECT_EQ(c->params().size(), 0u);
} }
@ -56,7 +56,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* ident = c->func()->As<ast::IdentifierExpression>(); auto* ident = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(c->params().size(), 3u); EXPECT_EQ(c->params().size(), 3u);
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>()); EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -37,13 +37,13 @@ TEST_F(ParserImplTest, FunctionDecl) {
EXPECT_TRUE(f.matched); EXPECT_TRUE(f.matched);
ASSERT_NE(f.value, nullptr); ASSERT_NE(f.value, nullptr);
EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); EXPECT_EQ(f->symbol(), p->get_program().Symbols().Register("main"));
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>()); EXPECT_TRUE(f->return_type()->Is<type::Void>());
ASSERT_EQ(f->params().size(), 2u); ASSERT_EQ(f->params().size(), 2u);
EXPECT_EQ(f->params()[0]->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(f->params()[0]->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(f->params()[1]->symbol(), p->get_program().RegisterSymbol("b")); EXPECT_EQ(f->params()[1]->symbol(), p->get_program().Symbols().Register("b"));
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>()); EXPECT_TRUE(f->return_type()->Is<type::Void>());
@ -65,7 +65,7 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
EXPECT_TRUE(f.matched); EXPECT_TRUE(f.matched);
ASSERT_NE(f.value, nullptr); ASSERT_NE(f.value, nullptr);
EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); EXPECT_EQ(f->symbol(), p->get_program().Symbols().Register("main"));
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>()); EXPECT_TRUE(f->return_type()->Is<type::Void>());
ASSERT_EQ(f->params().size(), 0u); ASSERT_EQ(f->params().size(), 0u);
@ -103,7 +103,7 @@ fn main() -> void { return; })");
EXPECT_TRUE(f.matched); EXPECT_TRUE(f.matched);
ASSERT_NE(f.value, nullptr); ASSERT_NE(f.value, nullptr);
EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); EXPECT_EQ(f->symbol(), p->get_program().Symbols().Register("main"));
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>()); EXPECT_TRUE(f->return_type()->Is<type::Void>());
ASSERT_EQ(f->params().size(), 0u); ASSERT_EQ(f->params().size(), 0u);
@ -148,7 +148,7 @@ fn main() -> void { return; })");
EXPECT_TRUE(f.matched); EXPECT_TRUE(f.matched);
ASSERT_NE(f.value, nullptr); ASSERT_NE(f.value, nullptr);
EXPECT_EQ(f->symbol(), p->get_program().RegisterSymbol("main")); EXPECT_EQ(f->symbol(), p->get_program().Symbols().Register("main"));
ASSERT_NE(f->return_type(), nullptr); ASSERT_NE(f->return_type(), nullptr);
EXPECT_TRUE(f->return_type()->Is<type::Void>()); EXPECT_TRUE(f->return_type()->Is<type::Void>());
ASSERT_EQ(f->params().size(), 0u); ASSERT_EQ(f->params().size(), 0u);

View File

@ -33,8 +33,8 @@ TEST_F(ParserImplTest, FunctionHeader) {
EXPECT_EQ(f->name, "main"); EXPECT_EQ(f->name, "main");
ASSERT_EQ(f->params.size(), 2u); ASSERT_EQ(f->params.size(), 2u);
EXPECT_EQ(f->params[0]->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(f->params[0]->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(f->params[1]->symbol(), p->get_program().RegisterSymbol("b")); EXPECT_EQ(f->params[1]->symbol(), p->get_program().Symbols().Register("b"));
EXPECT_TRUE(f->return_type->Is<type::Void>()); EXPECT_TRUE(f->return_type->Is<type::Void>());
} }

View File

@ -33,7 +33,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
EXPECT_TRUE(e->is_const()); EXPECT_TRUE(e->is_const());
EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_NE(e->type(), nullptr); ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->Is<type::F32>()); EXPECT_TRUE(e->type()->Is<type::F32>());

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) {
ASSERT_EQ(m.AST().GlobalVariables().size(), 1u); ASSERT_EQ(m.AST().GlobalVariables().size(), 1u);
auto* v = m.AST().GlobalVariables()[0]; auto* v = m.AST().GlobalVariables()[0];
EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(v->symbol(), p->get_program().Symbols().Register("a"));
} }
TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Invalid) { TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Invalid) {
@ -64,7 +64,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalConstant) {
ASSERT_EQ(m.AST().GlobalVariables().size(), 1u); ASSERT_EQ(m.AST().GlobalVariables().size(), 1u);
auto* v = m.AST().GlobalVariables()[0]; auto* v = m.AST().GlobalVariables()[0];
EXPECT_EQ(v->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(v->symbol(), p->get_program().Symbols().Register("a"));
} }
TEST_F(ParserImplTest, GlobalDecl_GlobalConstant_Invalid) { TEST_F(ParserImplTest, GlobalDecl_GlobalConstant_Invalid) {
@ -89,7 +89,7 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
auto& m = p->get_program(); auto& m = p->get_program();
ASSERT_EQ(m.AST().ConstructedTypes().size(), 1u); ASSERT_EQ(m.AST().ConstructedTypes().size(), 1u);
ASSERT_TRUE(m.AST().ConstructedTypes()[0]->Is<type::Alias>()); ASSERT_TRUE(m.AST().ConstructedTypes()[0]->Is<type::Alias>());
EXPECT_EQ(m.SymbolToName( EXPECT_EQ(m.Symbols().NameFor(
m.AST().ConstructedTypes()[0]->As<type::Alias>()->symbol()), m.AST().ConstructedTypes()[0]->As<type::Alias>()->symbol()),
"A"); "A");
} }
@ -107,11 +107,11 @@ type B = A;)");
ASSERT_EQ(m.AST().ConstructedTypes().size(), 2u); ASSERT_EQ(m.AST().ConstructedTypes().size(), 2u);
ASSERT_TRUE(m.AST().ConstructedTypes()[0]->Is<type::Struct>()); ASSERT_TRUE(m.AST().ConstructedTypes()[0]->Is<type::Struct>());
auto* str = m.AST().ConstructedTypes()[0]->As<type::Struct>(); auto* str = m.AST().ConstructedTypes()[0]->As<type::Struct>();
EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); EXPECT_EQ(str->symbol(), p->get_program().Symbols().Register("A"));
ASSERT_TRUE(m.AST().ConstructedTypes()[1]->Is<type::Alias>()); ASSERT_TRUE(m.AST().ConstructedTypes()[1]->Is<type::Alias>());
auto* alias = m.AST().ConstructedTypes()[1]->As<type::Alias>(); auto* alias = m.AST().ConstructedTypes()[1]->As<type::Alias>();
EXPECT_EQ(alias->symbol(), p->get_program().RegisterSymbol("B")); EXPECT_EQ(alias->symbol(), p->get_program().Symbols().Register("B"));
EXPECT_EQ(alias->type(), str); EXPECT_EQ(alias->type(), str);
} }
@ -136,7 +136,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function) {
auto& m = p->get_program(); auto& m = p->get_program();
ASSERT_EQ(m.AST().Functions().size(), 1u); ASSERT_EQ(m.AST().Functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.AST().Functions()[0]->symbol()), "main"); EXPECT_EQ(m.Symbols().NameFor(m.AST().Functions()[0]->symbol()), "main");
} }
TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) { TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
@ -146,7 +146,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithDecoration) {
auto& m = p->get_program(); auto& m = p->get_program();
ASSERT_EQ(m.AST().Functions().size(), 1u); ASSERT_EQ(m.AST().Functions().size(), 1u);
EXPECT_EQ(m.SymbolToName(m.AST().Functions()[0]->symbol()), "main"); EXPECT_EQ(m.Symbols().NameFor(m.AST().Functions()[0]->symbol()), "main");
} }
TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) { TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) {
@ -169,7 +169,7 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
ASSERT_TRUE(t->Is<type::Struct>()); ASSERT_TRUE(t->Is<type::Struct>());
auto* str = t->As<type::Struct>(); auto* str = t->As<type::Struct>();
EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); EXPECT_EQ(str->symbol(), p->get_program().Symbols().Register("A"));
EXPECT_EQ(str->impl()->members().size(), 2u); EXPECT_EQ(str->impl()->members().size(), 2u);
} }
@ -188,7 +188,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
ASSERT_TRUE(t->Is<type::Struct>()); ASSERT_TRUE(t->Is<type::Struct>());
auto* str = t->As<type::Struct>(); auto* str = t->As<type::Struct>();
EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); EXPECT_EQ(str->symbol(), p->get_program().Symbols().Register("A"));
EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_FALSE(str->IsBlockDecorated()); EXPECT_FALSE(str->IsBlockDecorated());
@ -212,7 +212,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
ASSERT_TRUE(t->Is<type::Struct>()); ASSERT_TRUE(t->Is<type::Struct>());
auto* str = t->As<type::Struct>(); auto* str = t->As<type::Struct>();
EXPECT_EQ(str->symbol(), p->get_program().RegisterSymbol("A")); EXPECT_EQ(str->symbol(), p->get_program().Symbols().Register("A"));
EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_TRUE(str->IsBlockDecorated()); EXPECT_TRUE(str->IsBlockDecorated());
} }

View File

@ -36,7 +36,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
EXPECT_FALSE(e.errored); EXPECT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_TRUE(e->type()->Is<type::F32>()); EXPECT_TRUE(e->type()->Is<type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
@ -59,7 +59,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
EXPECT_FALSE(e.errored); EXPECT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_TRUE(e->type()->Is<type::F32>()); EXPECT_TRUE(e->type()->Is<type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
@ -84,7 +84,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) {
EXPECT_FALSE(e.errored); EXPECT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_NE(e->type(), nullptr); ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->Is<type::F32>()); EXPECT_TRUE(e->type()->Is<type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
@ -114,7 +114,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) {
EXPECT_FALSE(e.errored); EXPECT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
EXPECT_EQ(e->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_NE(e->type(), nullptr); ASSERT_NE(e->type(), nullptr);
EXPECT_TRUE(e->type()->Is<type::F32>()); EXPECT_TRUE(e->type()->Is<type::F32>());
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -85,7 +85,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, ParamList_Single) {
ASSERT_FALSE(e.errored); ASSERT_FALSE(e.errored);
EXPECT_EQ(e.value.size(), 1u); EXPECT_EQ(e.value.size(), 1u);
EXPECT_EQ(e.value[0]->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e.value[0]->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(e.value[0]->type(), i32); EXPECT_EQ(e.value[0]->type(), i32);
EXPECT_TRUE(e.value[0]->is_const()); EXPECT_TRUE(e.value[0]->is_const());
@ -61,7 +61,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
ASSERT_FALSE(e.errored); ASSERT_FALSE(e.errored);
EXPECT_EQ(e.value.size(), 3u); EXPECT_EQ(e.value.size(), 3u);
EXPECT_EQ(e.value[0]->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e.value[0]->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(e.value[0]->type(), i32); EXPECT_EQ(e.value[0]->type(), i32);
EXPECT_TRUE(e.value[0]->is_const()); EXPECT_TRUE(e.value[0]->is_const());
@ -70,7 +70,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
ASSERT_EQ(e.value[0]->source().range.end.line, 1u); ASSERT_EQ(e.value[0]->source().range.end.line, 1u);
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]->symbol(), p->get_program().RegisterSymbol("b")); EXPECT_EQ(e.value[1]->symbol(), p->get_program().Symbols().Register("b"));
EXPECT_EQ(e.value[1]->type(), f32); EXPECT_EQ(e.value[1]->type(), f32);
EXPECT_TRUE(e.value[1]->is_const()); EXPECT_TRUE(e.value[1]->is_const());
@ -79,7 +79,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
ASSERT_EQ(e.value[1]->source().range.end.line, 1u); ASSERT_EQ(e.value[1]->source().range.end.line, 1u);
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]->symbol(), p->get_program().RegisterSymbol("c")); EXPECT_EQ(e.value[2]->symbol(), p->get_program().Symbols().Register("c"));
EXPECT_EQ(e.value[2]->type(), vec2); EXPECT_EQ(e.value[2]->type(), vec2);
EXPECT_TRUE(e.value[2]->is_const()); EXPECT_TRUE(e.value[2]->is_const());

View File

@ -42,7 +42,7 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) {
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
auto* ident = ary->array()->As<ast::IdentifierExpression>(); auto* ident = ary->array()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());
@ -64,7 +64,7 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) {
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
auto* ident = ary->array()->As<ast::IdentifierExpression>(); auto* ident = ary->array()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(ary->idx_expr()->Is<ast::BinaryExpression>()); ASSERT_TRUE(ary->idx_expr()->Is<ast::BinaryExpression>());
} }
@ -112,7 +112,7 @@ TEST_F(ParserImplTest, PostfixExpression_Call_Empty) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* func = c->func()->As<ast::IdentifierExpression>(); auto* func = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(func->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(func->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(c->params().size(), 0u); EXPECT_EQ(c->params().size(), 0u);
} }
@ -130,7 +130,7 @@ TEST_F(ParserImplTest, PostfixExpression_Call_WithArgs) {
ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(c->func()->Is<ast::IdentifierExpression>());
auto* func = c->func()->As<ast::IdentifierExpression>(); auto* func = c->func()->As<ast::IdentifierExpression>();
EXPECT_EQ(func->symbol(), p->get_program().RegisterSymbol("test")); EXPECT_EQ(func->symbol(), p->get_program().Symbols().Register("test"));
EXPECT_EQ(c->params().size(), 3u); EXPECT_EQ(c->params().size(), 3u);
EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>()); EXPECT_TRUE(c->params()[0]->Is<ast::ConstructorExpression>());
@ -180,11 +180,11 @@ TEST_F(ParserImplTest, PostfixExpression_MemberAccessor) {
auto* m = e->As<ast::MemberAccessorExpression>(); auto* m = e->As<ast::MemberAccessorExpression>();
ASSERT_TRUE(m->structure()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(m->structure()->Is<ast::IdentifierExpression>());
EXPECT_EQ(m->structure()->As<ast::IdentifierExpression>()->symbol(), EXPECT_EQ(m->structure()->As<ast::IdentifierExpression>()->symbol(),
p->get_program().RegisterSymbol("a")); p->get_program().Symbols().Register("a"));
ASSERT_TRUE(m->member()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(m->member()->Is<ast::IdentifierExpression>());
EXPECT_EQ(m->member()->As<ast::IdentifierExpression>()->symbol(), EXPECT_EQ(m->member()->As<ast::IdentifierExpression>()->symbol(),
p->get_program().RegisterSymbol("b")); p->get_program().Symbols().Register("b"));
} }
TEST_F(ParserImplTest, PostfixExpression_MemberAccesssor_InvalidIdent) { TEST_F(ParserImplTest, PostfixExpression_MemberAccesssor_InvalidIdent) {

View File

@ -41,7 +41,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) {
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->Is<ast::IdentifierExpression>()); ASSERT_TRUE(e->Is<ast::IdentifierExpression>());
auto* ident = e->As<ast::IdentifierExpression>(); auto* ident = e->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
} }
TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) {

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -85,7 +85,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -108,7 +108,7 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());
@ -62,7 +62,7 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) {
ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(rel->lhs()->Is<ast::IdentifierExpression>());
auto* ident = rel->lhs()->As<ast::IdentifierExpression>(); auto* ident = rel->lhs()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(rel->rhs()->Is<ast::ScalarConstructorExpression>());

View File

@ -34,7 +34,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) {
ASSERT_EQ(m.value.size(), 1u); ASSERT_EQ(m.value.size(), 1u);
const auto* mem = m.value[0]; const auto* mem = m.value[0];
EXPECT_EQ(mem->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(mem->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(mem->type(), i32); EXPECT_EQ(mem->type(), i32);
EXPECT_EQ(mem->decorations().size(), 0u); EXPECT_EQ(mem->decorations().size(), 0u);
} }

View File

@ -39,12 +39,12 @@ struct S {
EXPECT_FALSE(s.errored); EXPECT_FALSE(s.errored);
EXPECT_TRUE(s.matched); EXPECT_TRUE(s.matched);
ASSERT_NE(s.value, nullptr); ASSERT_NE(s.value, nullptr);
ASSERT_EQ(s->symbol(), p->get_program().RegisterSymbol("S")); ASSERT_EQ(s->symbol(), p->get_program().Symbols().Register("S"));
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->symbol(), EXPECT_EQ(s->impl()->members()[0]->symbol(),
p->get_program().RegisterSymbol("a")); p->get_program().Symbols().Register("a"));
EXPECT_EQ(s->impl()->members()[1]->symbol(), EXPECT_EQ(s->impl()->members()[1]->symbol(),
p->get_program().RegisterSymbol("b")); p->get_program().Symbols().Register("b"));
} }
TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
@ -63,12 +63,12 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
EXPECT_FALSE(s.errored); EXPECT_FALSE(s.errored);
EXPECT_TRUE(s.matched); EXPECT_TRUE(s.matched);
ASSERT_NE(s.value, nullptr); ASSERT_NE(s.value, nullptr);
ASSERT_EQ(s->symbol(), p->get_program().RegisterSymbol("B")); ASSERT_EQ(s->symbol(), p->get_program().Symbols().Register("B"));
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->symbol(), EXPECT_EQ(s->impl()->members()[0]->symbol(),
p->get_program().RegisterSymbol("a")); p->get_program().Symbols().Register("a"));
EXPECT_EQ(s->impl()->members()[1]->symbol(), EXPECT_EQ(s->impl()->members()[1]->symbol(),
p->get_program().RegisterSymbol("b")); p->get_program().Symbols().Register("b"));
ASSERT_EQ(s->impl()->decorations().size(), 1u); ASSERT_EQ(s->impl()->decorations().size(), 1u);
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>()); EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
} }
@ -90,12 +90,12 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) {
EXPECT_FALSE(s.errored); EXPECT_FALSE(s.errored);
EXPECT_TRUE(s.matched); EXPECT_TRUE(s.matched);
ASSERT_NE(s.value, nullptr); ASSERT_NE(s.value, nullptr);
ASSERT_EQ(s->symbol(), p->get_program().RegisterSymbol("S")); ASSERT_EQ(s->symbol(), p->get_program().Symbols().Register("S"));
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->symbol(), EXPECT_EQ(s->impl()->members()[0]->symbol(),
p->get_program().RegisterSymbol("a")); p->get_program().Symbols().Register("a"));
EXPECT_EQ(s->impl()->members()[1]->symbol(), EXPECT_EQ(s->impl()->members()[1]->symbol(),
p->get_program().RegisterSymbol("b")); p->get_program().Symbols().Register("b"));
ASSERT_EQ(s->impl()->decorations().size(), 2u); ASSERT_EQ(s->impl()->decorations().size(), 2u);
EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>()); EXPECT_TRUE(s->impl()->decorations()[0]->Is<ast::StructBlockDecoration>());
EXPECT_TRUE(s->impl()->decorations()[1]->Is<ast::StructBlockDecoration>()); EXPECT_TRUE(s->impl()->decorations()[1]->Is<ast::StructBlockDecoration>());

View File

@ -39,7 +39,7 @@ TEST_F(ParserImplTest, StructMember_Parses) {
ASSERT_FALSE(m.errored); ASSERT_FALSE(m.errored);
ASSERT_NE(m.value, nullptr); ASSERT_NE(m.value, nullptr);
EXPECT_EQ(m->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(m->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(m->type(), i32); EXPECT_EQ(m->type(), i32);
EXPECT_EQ(m->decorations().size(), 0u); EXPECT_EQ(m->decorations().size(), 0u);
@ -65,7 +65,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) {
ASSERT_FALSE(m.errored); ASSERT_FALSE(m.errored);
ASSERT_NE(m.value, nullptr); ASSERT_NE(m.value, nullptr);
EXPECT_EQ(m->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(m->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(m->type(), i32); EXPECT_EQ(m->type(), i32);
EXPECT_EQ(m->decorations().size(), 1u); EXPECT_EQ(m->decorations().size(), 1u);
EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>()); EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>());
@ -96,7 +96,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) {
ASSERT_FALSE(m.errored); ASSERT_FALSE(m.errored);
ASSERT_NE(m.value, nullptr); ASSERT_NE(m.value, nullptr);
EXPECT_EQ(m->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(m->symbol(), p->get_program().Symbols().Register("a"));
EXPECT_EQ(m->type(), i32); EXPECT_EQ(m->type(), i32);
EXPECT_EQ(m->decorations().size(), 2u); EXPECT_EQ(m->decorations().size(), 2u);
EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>()); EXPECT_TRUE(m->decorations()[0]->Is<ast::StructMemberOffsetDecoration>());

View File

@ -45,7 +45,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto p = parser("type a = B"); auto p = parser("type a = B");
type::Struct str(p->get_program().RegisterSymbol("B"), {}); type::Struct str(p->get_program().Symbols().Register("B"), {});
p->register_constructed("B", &str); p->register_constructed("B", &str);
auto t = p->type_alias(); auto t = p->type_alias();
@ -55,12 +55,12 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
ASSERT_NE(t.value, nullptr); ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<type::Alias>()); ASSERT_TRUE(t->Is<type::Alias>());
auto* alias = t->As<type::Alias>(); auto* alias = t->As<type::Alias>();
EXPECT_EQ(p->get_program().SymbolToName(alias->symbol()), "a"); EXPECT_EQ(p->get_program().Symbols().NameFor(alias->symbol()), "a");
ASSERT_TRUE(alias->type()->Is<type::Struct>()); ASSERT_TRUE(alias->type()->Is<type::Struct>());
auto* s = alias->type()->As<type::Struct>(); auto* s = alias->type()->As<type::Struct>();
EXPECT_EQ(s->symbol(), p->get_program().RegisterSymbol("B")); EXPECT_EQ(s->symbol(), p->get_program().Symbols().Register("B"));
EXPECT_EQ(s->symbol(), p->get_program().RegisterSymbol("B")); EXPECT_EQ(s->symbol(), p->get_program().Symbols().Register("B"));
} }
TEST_F(ParserImplTest, TypeDecl_MissingIdent) { TEST_F(ParserImplTest, TypeDecl_MissingIdent) {

View File

@ -49,7 +49,8 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
auto& mod = p->get_program(); auto& mod = p->get_program();
auto* int_type = mod.create<type::I32>(); auto* int_type = mod.create<type::I32>();
auto* alias_type = mod.create<type::Alias>(mod.RegisterSymbol("A"), int_type); auto* alias_type =
mod.create<type::Alias>(mod.Symbols().Register("A"), int_type);
p->register_constructed("A", alias_type); p->register_constructed("A", alias_type);
@ -61,7 +62,7 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
ASSERT_TRUE(t->Is<type::Alias>()); ASSERT_TRUE(t->Is<type::Alias>());
auto* alias = t->As<type::Alias>(); auto* alias = t->As<type::Alias>();
EXPECT_EQ(p->get_program().SymbolToName(alias->symbol()), "A"); EXPECT_EQ(p->get_program().Symbols().NameFor(alias->symbol()), "A");
EXPECT_EQ(alias->type(), int_type); EXPECT_EQ(alias->type(), int_type);
} }

View File

@ -38,7 +38,7 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) {
auto* ary = e->As<ast::ArrayAccessorExpression>(); auto* ary = e->As<ast::ArrayAccessorExpression>();
ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>()); ASSERT_TRUE(ary->array()->Is<ast::IdentifierExpression>());
auto* ident = ary->array()->As<ast::IdentifierExpression>(); auto* ident = ary->array()->As<ast::IdentifierExpression>();
EXPECT_EQ(ident->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(ident->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>()); ASSERT_TRUE(ary->idx_expr()->Is<ast::ConstructorExpression>());
ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>()); ASSERT_TRUE(ary->idx_expr()->Is<ast::ScalarConstructorExpression>());

View File

@ -32,7 +32,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>()); ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
ASSERT_NE(e->variable(), nullptr); ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e->variable()->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_EQ(e->source().range.begin.line, 1u); ASSERT_EQ(e->source().range.begin.line, 1u);
ASSERT_EQ(e->source().range.begin.column, 5u); ASSERT_EQ(e->source().range.begin.column, 5u);
@ -51,7 +51,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
ASSERT_NE(e.value, nullptr); ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>()); ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
ASSERT_NE(e->variable(), nullptr); ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->symbol(), p->get_program().RegisterSymbol("a")); EXPECT_EQ(e->variable()->symbol(), p->get_program().Symbols().Register("a"));
ASSERT_EQ(e->source().range.begin.line, 1u); ASSERT_EQ(e->source().range.begin.line, 1u);
ASSERT_EQ(e->source().range.begin.column, 5u); ASSERT_EQ(e->source().range.begin.column, 5u);

View File

@ -51,12 +51,12 @@ Transform::Output EmitVertexPointSize::Run(const Program* in) {
// Declare the pointsize builtin output variable. // Declare the pointsize builtin output variable.
auto* pointsize_var = out.program.create<ast::Variable>( auto* pointsize_var = out.program.create<ast::Variable>(
Source{}, // source Source{}, // source
out.program.RegisterSymbol(kPointSizeVar), // symbol out.program.Symbols().Register(kPointSizeVar), // symbol
ast::StorageClass::kOutput, // storage_class ast::StorageClass::kOutput, // storage_class
f32, // type f32, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::VariableDecorationList{
// decorations // decorations
out.program.create<ast::BuiltinDecoration>(Source{}, out.program.create<ast::BuiltinDecoration>(Source{},
@ -68,7 +68,7 @@ Transform::Output EmitVertexPointSize::Run(const Program* in) {
auto* one = out.program.create<ast::ScalarConstructorExpression>( auto* one = out.program.create<ast::ScalarConstructorExpression>(
Source{}, out.program.create<ast::FloatLiteral>(Source{}, f32, 1.0f)); Source{}, out.program.create<ast::FloatLiteral>(Source{}, f32, 1.0f));
auto* pointsize_ident = out.program.create<ast::IdentifierExpression>( auto* pointsize_ident = out.program.create<ast::IdentifierExpression>(
Source{}, out.program.RegisterSymbol(kPointSizeVar)); Source{}, out.program.Symbols().Register(kPointSizeVar));
auto* pointsize_assign = out.program.create<ast::AssignmentStatement>( auto* pointsize_assign = out.program.create<ast::AssignmentStatement>(
Source{}, pointsize_ident, one); Source{}, pointsize_ident, one);

View File

@ -65,13 +65,13 @@ ast::Variable* clone_variable_with_new_name(CloneContext* ctx,
ast::Variable* in, ast::Variable* in,
std::string new_name) { std::string new_name) {
return ctx->dst->create<ast::Variable>( return ctx->dst->create<ast::Variable>(
ctx->Clone(in->source()), // source ctx->Clone(in->source()), // source
ctx->dst->RegisterSymbol(new_name), // symbol ctx->dst->Symbols().Register(new_name), // symbol
in->storage_class(), // storage_class in->storage_class(), // storage_class
ctx->Clone(in->type()), // type ctx->Clone(in->type()), // type
in->is_const(), // is_const in->is_const(), // is_const
ctx->Clone(in->constructor()), // constructor ctx->Clone(in->constructor()), // constructor
ctx->Clone(in->decorations())); // decorations ctx->Clone(in->decorations())); // decorations
} }
} // namespace } // namespace
@ -85,7 +85,7 @@ Transform::Output FirstIndexOffset::Run(const Program* in) {
// First do a quick check to see if the transform has already been applied. // First do a quick check to see if the transform has already been applied.
for (ast::Variable* var : in->AST().GlobalVariables()) { for (ast::Variable* var : in->AST().GlobalVariables()) {
if (auto* dec_var = var->As<ast::Variable>()) { if (auto* dec_var = var->As<ast::Variable>()) {
if (dec_var->symbol() == in->GetSymbol(kBufferName)) { if (dec_var->symbol() == in->Symbols().Get(kBufferName)) {
diag::Diagnostic err; diag::Diagnostic err;
err.message = "First index offset transform has already been applied."; err.message = "First index offset transform has already been applied.";
err.severity = diag::Severity::Error; err.severity = diag::Severity::Error;
@ -137,13 +137,13 @@ Transform::Output FirstIndexOffset::Run(const Program* in) {
has_vertex_index_ = true; has_vertex_index_ = true;
return clone_variable_with_new_name( return clone_variable_with_new_name(
ctx, var, ctx, var,
kIndexOffsetPrefix + in->SymbolToName(var->symbol())); kIndexOffsetPrefix + in->Symbols().NameFor(var->symbol()));
} else if (blt_type == ast::Builtin::kInstanceIndex) { } else if (blt_type == ast::Builtin::kInstanceIndex) {
instance_index_sym = var->symbol(); instance_index_sym = var->symbol();
has_instance_index_ = true; has_instance_index_ = true;
return clone_variable_with_new_name( return clone_variable_with_new_name(
ctx, var, ctx, var,
kIndexOffsetPrefix + in->SymbolToName(var->symbol())); kIndexOffsetPrefix + in->Symbols().NameFor(var->symbol()));
} }
} }
} }
@ -162,12 +162,12 @@ Transform::Output FirstIndexOffset::Run(const Program* in) {
func->local_referenced_builtin_variables()) { func->local_referenced_builtin_variables()) {
if (data.second->value() == ast::Builtin::kVertexIndex) { if (data.second->value() == ast::Builtin::kVertexIndex) {
statements.emplace_back(CreateFirstIndexOffset( statements.emplace_back(CreateFirstIndexOffset(
in->SymbolToName(vertex_index_sym), kFirstVertexName, in->Symbols().NameFor(vertex_index_sym), kFirstVertexName,
buffer_var, ctx->dst)); buffer_var, ctx->dst));
} else if (data.second->value() == ast::Builtin::kInstanceIndex) { } else if (data.second->value() == ast::Builtin::kInstanceIndex) {
statements.emplace_back(CreateFirstIndexOffset( statements.emplace_back(CreateFirstIndexOffset(
in->SymbolToName(instance_index_sym), kFirstInstanceName, in->Symbols().NameFor(instance_index_sym),
buffer_var, ctx->dst)); kFirstInstanceName, buffer_var, ctx->dst));
} }
} }
return CloneWithStatementsAtStart(ctx, func, statements); return CloneWithStatementsAtStart(ctx, func, statements);
@ -204,7 +204,7 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(Program* dst) {
member_dec.push_back( member_dec.push_back(
dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset)); dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(dst->create<ast::StructMember>( members.push_back(dst->create<ast::StructMember>(
Source{}, dst->RegisterSymbol(kFirstVertexName), u32_type, Source{}, dst->Symbols().Register(kFirstVertexName), u32_type,
std::move(member_dec))); std::move(member_dec)));
vertex_index_offset_ = offset; vertex_index_offset_ = offset;
offset += 4; offset += 4;
@ -215,7 +215,7 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(Program* dst) {
member_dec.push_back( member_dec.push_back(
dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset)); dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
members.push_back(dst->create<ast::StructMember>( members.push_back(dst->create<ast::StructMember>(
Source{}, dst->RegisterSymbol(kFirstInstanceName), u32_type, Source{}, dst->Symbols().Register(kFirstInstanceName), u32_type,
std::move(member_dec))); std::move(member_dec)));
instance_index_offset_ = offset; instance_index_offset_ = offset;
offset += 4; offset += 4;
@ -225,16 +225,16 @@ ast::Variable* FirstIndexOffset::AddUniformBuffer(Program* dst) {
decos.push_back(dst->create<ast::StructBlockDecoration>(Source{})); decos.push_back(dst->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = dst->create<type::Struct>( auto* struct_type = dst->create<type::Struct>(
dst->RegisterSymbol(kStructName), dst->Symbols().Register(kStructName),
dst->create<ast::Struct>(Source{}, std::move(members), std::move(decos))); dst->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
auto* idx_var = dst->create<ast::Variable>( auto* idx_var = dst->create<ast::Variable>(
Source{}, // source Source{}, // source
dst->RegisterSymbol(kBufferName), // symbol dst->Symbols().Register(kBufferName), // symbol
ast::StorageClass::kUniform, // storage_class ast::StorageClass::kUniform, // storage_class
struct_type, // type struct_type, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::VariableDecorationList{
dst->create<ast::BindingDecoration>(Source{}, binding_), dst->create<ast::BindingDecoration>(Source{}, binding_),
dst->create<ast::GroupDecoration>(Source{}, group_), dst->create<ast::GroupDecoration>(Source{}, group_),
@ -259,19 +259,19 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
auto* constructor = dst->create<ast::BinaryExpression>( auto* constructor = dst->create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kAdd, Source{}, ast::BinaryOp::kAdd,
dst->create<ast::IdentifierExpression>(Source{}, dst->create<ast::IdentifierExpression>(Source{},
dst->RegisterSymbol(lhs_name)), dst->Symbols().Register(lhs_name)),
dst->create<ast::MemberAccessorExpression>( dst->create<ast::MemberAccessorExpression>(
Source{}, buffer, Source{}, buffer,
dst->create<ast::IdentifierExpression>( dst->create<ast::IdentifierExpression>(
Source{}, dst->RegisterSymbol(field_name)))); Source{}, dst->Symbols().Register(field_name))));
auto* var = auto* var = dst->create<ast::Variable>(
dst->create<ast::Variable>(Source{}, // source Source{}, // source
dst->RegisterSymbol(original_name), // symbol dst->Symbols().Register(original_name), // symbol
ast::StorageClass::kNone, // storage_class ast::StorageClass::kNone, // storage_class
dst->create<type::U32>(), // type dst->create<type::U32>(), // type
true, // is_const true, // is_const
constructor, // constructor constructor, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
return dst->create<ast::VariableDeclStatement>(Source{}, var); return dst->create<ast::VariableDeclStatement>(Source{}, var);
} }

View File

@ -85,8 +85,8 @@ Transform::Output VertexPulling::Run(const Program* in) {
} }
// Find entry point // Find entry point
auto* func = in->AST().Functions().Find(in->GetSymbol(cfg.entry_point_name), auto* func = in->AST().Functions().Find(
ast::PipelineStage::kVertex); in->Symbols().Get(cfg.entry_point_name), ast::PipelineStage::kVertex);
if (func == nullptr) { if (func == nullptr) {
diag::Diagnostic err; diag::Diagnostic err;
err.severity = diag::Severity::Error; err.severity = diag::Severity::Error;
@ -158,7 +158,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
for (auto* d : v->decorations()) { for (auto* d : v->decorations()) {
if (auto* builtin = d->As<ast::BuiltinDecoration>()) { if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
if (builtin->value() == ast::Builtin::kVertexIndex) { if (builtin->value() == ast::Builtin::kVertexIndex) {
vertex_index_name = in->SymbolToName(v->symbol()); vertex_index_name = in->Symbols().NameFor(v->symbol());
return; return;
} }
} }
@ -169,12 +169,12 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
vertex_index_name = kDefaultVertexIndexName; vertex_index_name = kDefaultVertexIndexName;
auto* var = out->create<ast::Variable>( auto* var = out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(vertex_index_name), // symbol out->Symbols().Register(vertex_index_name), // symbol
ast::StorageClass::kInput, // storage_class ast::StorageClass::kInput, // storage_class
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::VariableDecorationList{
// decorations // decorations
out->create<ast::BuiltinDecoration>(Source{}, out->create<ast::BuiltinDecoration>(Source{},
@ -205,7 +205,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
for (auto* d : v->decorations()) { for (auto* d : v->decorations()) {
if (auto* builtin = d->As<ast::BuiltinDecoration>()) { if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
if (builtin->value() == ast::Builtin::kInstanceIndex) { if (builtin->value() == ast::Builtin::kInstanceIndex) {
instance_index_name = in->SymbolToName(v->symbol()); instance_index_name = in->Symbols().NameFor(v->symbol());
return; return;
} }
} }
@ -216,12 +216,12 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
instance_index_name = kDefaultInstanceIndexName; instance_index_name = kDefaultInstanceIndexName;
auto* var = out->create<ast::Variable>( auto* var = out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(instance_index_name), // symbol out->Symbols().Register(instance_index_name), // symbol
ast::StorageClass::kInput, // storage_class ast::StorageClass::kInput, // storage_class
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::VariableDecorationList{
// decorations // decorations
out->create<ast::BuiltinDecoration>(Source{}, out->create<ast::BuiltinDecoration>(Source{},
@ -274,26 +274,26 @@ void VertexPulling::State::AddVertexStorageBuffers() {
out->create<ast::StructMemberOffsetDecoration>(Source{}, 0u)); out->create<ast::StructMemberOffsetDecoration>(Source{}, 0u));
members.push_back(out->create<ast::StructMember>( members.push_back(out->create<ast::StructMember>(
Source{}, out->RegisterSymbol(kStructBufferName), internal_array_type, Source{}, out->Symbols().Register(kStructBufferName), internal_array_type,
std::move(member_dec))); std::move(member_dec)));
ast::StructDecorationList decos; ast::StructDecorationList decos;
decos.push_back(out->create<ast::StructBlockDecoration>(Source{})); decos.push_back(out->create<ast::StructBlockDecoration>(Source{}));
auto* struct_type = out->create<type::Struct>( auto* struct_type = out->create<type::Struct>(
out->RegisterSymbol(kStructName), out->Symbols().Register(kStructName),
out->create<ast::Struct>(Source{}, std::move(members), std::move(decos))); out->create<ast::Struct>(Source{}, std::move(members), std::move(decos)));
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) { for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
// The decorated variable with struct type // The decorated variable with struct type
std::string name = GetVertexBufferName(i); std::string name = GetVertexBufferName(i);
auto* var = out->create<ast::Variable>( auto* var = out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(name), // symbol out->Symbols().Register(name), // symbol
ast::StorageClass::kStorage, // storage_class ast::StorageClass::kStorage, // storage_class
struct_type, // type struct_type, // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{ ast::VariableDecorationList{
// decorations // decorations
out->create<ast::BindingDecoration>(Source{}, i), out->create<ast::BindingDecoration>(Source{}, i),
@ -313,13 +313,13 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
// Declare the |kPullingPosVarName| variable in the shader // Declare the |kPullingPosVarName| variable in the shader
auto* pos_declaration = out->create<ast::VariableDeclStatement>( auto* pos_declaration = out->create<ast::VariableDeclStatement>(
Source{}, out->create<ast::Variable>( Source{}, out->create<ast::Variable>(
Source{}, // source Source{}, // source
out->RegisterSymbol(kPullingPosVarName), // symbol out->Symbols().Register(kPullingPosVarName), // symbol
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
GetI32Type(), // type GetI32Type(), // type
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
// |kPullingPosVarName| refers to the byte location of the current read. We // |kPullingPosVarName| refers to the byte location of the current read. We
// declare a variable in the shader to avoid having to reuse Expression // declare a variable in the shader to avoid having to reuse Expression
@ -342,7 +342,7 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
: instance_index_name; : instance_index_name;
// Identifier to index by // Identifier to index by
auto* index_identifier = out->create<ast::IdentifierExpression>( auto* index_identifier = out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(name)); Source{}, out->Symbols().Register(name));
// An expression for the start of the read in the buffer in bytes // An expression for the start of the read in the buffer in bytes
auto* pos_value = out->create<ast::BinaryExpression>( auto* pos_value = out->create<ast::BinaryExpression>(
@ -357,11 +357,11 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
Source{}, CreatePullingPositionIdent(), pos_value); Source{}, CreatePullingPositionIdent(), pos_value);
stmts.emplace_back(set_pos_expr); stmts.emplace_back(set_pos_expr);
auto ident_name = in->SymbolToName(v->symbol()); auto ident_name = in->Symbols().NameFor(v->symbol());
stmts.emplace_back(out->create<ast::AssignmentStatement>( stmts.emplace_back(out->create<ast::AssignmentStatement>(
Source{}, Source{},
out->create<ast::IdentifierExpression>( out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(ident_name)), Source{}, out->Symbols().Register(ident_name)),
AccessByFormat(i, attribute_desc.format))); AccessByFormat(i, attribute_desc.format)));
} }
} }
@ -376,7 +376,7 @@ ast::Expression* VertexPulling::State::GenUint(uint32_t value) const {
ast::Expression* VertexPulling::State::CreatePullingPositionIdent() const { ast::Expression* VertexPulling::State::CreatePullingPositionIdent() const {
return out->create<ast::IdentifierExpression>( return out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(kPullingPosVarName)); Source{}, out->Symbols().Register(kPullingPosVarName));
} }
ast::Expression* VertexPulling::State::AccessByFormat( ast::Expression* VertexPulling::State::AccessByFormat(
@ -420,9 +420,9 @@ ast::Expression* VertexPulling::State::AccessU32(uint32_t buffer,
out->create<ast::MemberAccessorExpression>( out->create<ast::MemberAccessorExpression>(
Source{}, Source{},
out->create<ast::IdentifierExpression>( out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(vbuf_name)), Source{}, out->Symbols().Register(vbuf_name)),
out->create<ast::IdentifierExpression>( out->create<ast::IdentifierExpression>(
Source{}, out->RegisterSymbol(kStructBufferName))), Source{}, out->Symbols().Register(kStructBufferName))),
out->create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kDivide, pos, out->create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kDivide, pos,
GenUint(4))); GenUint(4)));
} }

View File

@ -407,7 +407,7 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
if (callee_func == nullptr) { if (callee_func == nullptr) {
set_error(expr->source(), set_error(expr->source(),
"unable to find called function: " + "unable to find called function: " +
program_->SymbolToName(ident->symbol())); program_->Symbols().NameFor(ident->symbol()));
return false; return false;
} }
@ -433,7 +433,7 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
auto func_sym = expr->func()->As<ast::IdentifierExpression>()->symbol(); auto func_sym = expr->func()->As<ast::IdentifierExpression>()->symbol();
set_error(expr->source(), set_error(expr->source(),
"v-0005: function must be declared before use: '" + "v-0005: function must be declared before use: '" +
program_->SymbolToName(func_sym) + "'"); program_->Symbols().NameFor(func_sym) + "'");
return false; return false;
} }
@ -519,8 +519,9 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
ast::CallExpression* expr) { ast::CallExpression* expr) {
if (ast::intrinsic::IsDerivative(ident->intrinsic())) { if (ast::intrinsic::IsDerivative(ident->intrinsic())) {
if (expr->params().size() != 1) { if (expr->params().size() != 1) {
set_error(expr->source(), "incorrect number of parameters for " + set_error(expr->source(),
program_->SymbolToName(ident->symbol())); "incorrect number of parameters for " +
program_->Symbols().NameFor(ident->symbol()));
return false; return false;
} }
@ -540,8 +541,9 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
} }
if (ast::intrinsic::IsFloatClassificationIntrinsic(ident->intrinsic())) { if (ast::intrinsic::IsFloatClassificationIntrinsic(ident->intrinsic())) {
if (expr->params().size() != 1) { if (expr->params().size() != 1) {
set_error(expr->source(), "incorrect number of parameters for " + set_error(expr->source(),
program_->SymbolToName(ident->symbol())); "incorrect number of parameters for " +
program_->Symbols().NameFor(ident->symbol()));
return false; return false;
} }
@ -561,8 +563,9 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
auto* texture_param = expr->params()[0]; auto* texture_param = expr->params()[0];
if (!texture_param->result_type()->UnwrapAll()->Is<type::Texture>()) { if (!texture_param->result_type()->UnwrapAll()->Is<type::Texture>()) {
set_error(expr->source(), "invalid first argument for " + set_error(expr->source(),
program_->SymbolToName(ident->symbol())); "invalid first argument for " +
program_->Symbols().NameFor(ident->symbol()));
return false; return false;
} }
type::Texture* texture = type::Texture* texture =
@ -674,7 +677,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (expr->params().size() != param.count) { if (expr->params().size() != param.count) {
set_error(expr->source(), set_error(expr->source(),
"incorrect number of parameters for " + "incorrect number of parameters for " +
program_->SymbolToName(ident->symbol()) + ", got " + program_->Symbols().NameFor(ident->symbol()) + ", got " +
std::to_string(expr->params().size()) + " and expected " + std::to_string(expr->params().size()) + " and expected " +
std::to_string(param.count)); std::to_string(param.count));
return false; return false;
@ -747,10 +750,10 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
} }
if (ident->intrinsic() == ast::Intrinsic::kSelect) { if (ident->intrinsic() == ast::Intrinsic::kSelect) {
if (expr->params().size() != 3) { if (expr->params().size() != 3) {
set_error(expr->source(), "incorrect number of parameters for " + set_error(expr->source(),
program_->SymbolToName(ident->symbol()) + "incorrect number of parameters for " +
" expected 3 got " + program_->Symbols().NameFor(ident->symbol()) +
std::to_string(expr->params().size())); " expected 3 got " + std::to_string(expr->params().size()));
return false; return false;
} }
@ -768,14 +771,14 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
} }
} }
if (data == nullptr) { if (data == nullptr) {
error_ = error_ = "unable to find intrinsic " +
"unable to find intrinsic " + program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return false; return false;
} }
if (expr->params().size() != data->param_count) { if (expr->params().size() != data->param_count) {
set_error(expr->source(), "incorrect number of parameters for " + set_error(expr->source(), "incorrect number of parameters for " +
program_->SymbolToName(ident->symbol()) + program_->Symbols().NameFor(ident->symbol()) +
". Expected " + ". Expected " +
std::to_string(data->param_count) + " got " + std::to_string(data->param_count) + " got " +
std::to_string(expr->params().size())); std::to_string(expr->params().size()));
@ -793,7 +796,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
!result_types.back()->is_integer_scalar_or_vector()) { !result_types.back()->is_integer_scalar_or_vector()) {
set_error(expr->source(), set_error(expr->source(),
"incorrect type for " + "incorrect type for " +
program_->SymbolToName(ident->symbol()) + ". " + program_->Symbols().NameFor(ident->symbol()) + ". " +
"Requires float or int, scalar or vector values"); "Requires float or int, scalar or vector values");
return false; return false;
} }
@ -802,7 +805,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (!result_types.back()->is_float_scalar_or_vector()) { if (!result_types.back()->is_float_scalar_or_vector()) {
set_error(expr->source(), set_error(expr->source(),
"incorrect type for " + "incorrect type for " +
program_->SymbolToName(ident->symbol()) + ". " + program_->Symbols().NameFor(ident->symbol()) + ". " +
"Requires float scalar or float vector values"); "Requires float scalar or float vector values");
return false; return false;
} }
@ -812,7 +815,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (!result_types.back()->is_integer_scalar_or_vector()) { if (!result_types.back()->is_integer_scalar_or_vector()) {
set_error(expr->source(), set_error(expr->source(),
"incorrect type for " + "incorrect type for " +
program_->SymbolToName(ident->symbol()) + ". " + program_->Symbols().NameFor(ident->symbol()) + ". " +
"Requires integer scalar or integer vector values"); "Requires integer scalar or integer vector values");
return false; return false;
} }
@ -821,7 +824,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (!result_types.back()->is_float_vector()) { if (!result_types.back()->is_float_vector()) {
set_error(expr->source(), set_error(expr->source(),
"incorrect type for " + "incorrect type for " +
program_->SymbolToName(ident->symbol()) + ". " + program_->Symbols().NameFor(ident->symbol()) + ". " +
"Requires float vector values"); "Requires float vector values");
return false; return false;
} }
@ -830,7 +833,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
data->vector_size) { data->vector_size) {
set_error(expr->source(), set_error(expr->source(),
"incorrect vector size for " + "incorrect vector size for " +
program_->SymbolToName(ident->symbol()) + ". " + program_->Symbols().NameFor(ident->symbol()) + ". " +
"Requires " + std::to_string(data->vector_size) + "Requires " + std::to_string(data->vector_size) +
" elements"); " elements");
return false; return false;
@ -840,7 +843,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
if (!result_types.back()->Is<type::Matrix>()) { if (!result_types.back()->Is<type::Matrix>()) {
set_error(expr->source(), set_error(expr->source(),
"incorrect type for " + "incorrect type for " +
program_->SymbolToName(ident->symbol()) + program_->Symbols().NameFor(ident->symbol()) +
". Requires matrix value"); ". Requires matrix value");
return false; return false;
} }
@ -851,8 +854,9 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
// Verify all the parameter types match // Verify all the parameter types match
for (size_t i = 1; i < data->param_count; ++i) { for (size_t i = 1; i < data->param_count; ++i) {
if (result_types[0] != result_types[i]) { if (result_types[0] != result_types[i]) {
set_error(expr->source(), "mismatched parameter types for " + set_error(expr->source(),
program_->SymbolToName(ident->symbol())); "mismatched parameter types for " +
program_->Symbols().NameFor(ident->symbol()));
return false; return false;
} }
} }
@ -919,14 +923,14 @@ bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) {
if (!SetIntrinsicIfNeeded(expr)) { if (!SetIntrinsicIfNeeded(expr)) {
set_error(expr->source(), set_error(expr->source(),
"v-0006: identifier must be declared before use: " + "v-0006: identifier must be declared before use: " +
program_->SymbolToName(symbol)); program_->Symbols().NameFor(symbol));
return false; return false;
} }
return true; return true;
} }
bool TypeDeterminer::SetIntrinsicIfNeeded(ast::IdentifierExpression* ident) { bool TypeDeterminer::SetIntrinsicIfNeeded(ast::IdentifierExpression* ident) {
auto name = program_->SymbolToName(ident->symbol()); auto name = program_->Symbols().NameFor(ident->symbol());
if (name == "abs") { if (name == "abs") {
ident->set_intrinsic(ast::Intrinsic::kAbs); ident->set_intrinsic(ast::Intrinsic::kAbs);
} else if (name == "acos") { } else if (name == "acos") {
@ -1099,9 +1103,9 @@ bool TypeDeterminer::DetermineMemberAccessor(
} }
if (ret == nullptr) { if (ret == nullptr) {
set_error( set_error(expr->source(), "struct member " +
expr->source(), program_->Symbols().NameFor(symbol) +
"struct member " + program_->SymbolToName(symbol) + " not found"); " not found");
return false; return false;
} }
@ -1112,7 +1116,7 @@ bool TypeDeterminer::DetermineMemberAccessor(
} else if (auto* vec = data_type->As<type::Vector>()) { } else if (auto* vec = data_type->As<type::Vector>()) {
// TODO(dsinclair): Swizzle, record into the identifier experesion // TODO(dsinclair): Swizzle, record into the identifier experesion
auto size = program_->SymbolToName(expr->member()->symbol()).size(); auto size = program_->Symbols().NameFor(expr->member()->symbol()).size();
if (size == 1) { if (size == 1) {
// A single element swizzle is just the type of the vector. // A single element swizzle is just the type of the vector.
ret = vec->type(); ret = vec->type();

View File

@ -2782,17 +2782,17 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
const auto& b_eps = func_b->ancestor_entry_points(); const auto& b_eps = func_b->ancestor_entry_points();
ASSERT_EQ(2u, b_eps.size()); ASSERT_EQ(2u, b_eps.size());
EXPECT_EQ(mod->RegisterSymbol("ep_1"), b_eps[0]); EXPECT_EQ(mod->Symbols().Register("ep_1"), b_eps[0]);
EXPECT_EQ(mod->RegisterSymbol("ep_2"), b_eps[1]); EXPECT_EQ(mod->Symbols().Register("ep_2"), b_eps[1]);
const auto& a_eps = func_a->ancestor_entry_points(); const auto& a_eps = func_a->ancestor_entry_points();
ASSERT_EQ(1u, a_eps.size()); ASSERT_EQ(1u, a_eps.size());
EXPECT_EQ(mod->RegisterSymbol("ep_1"), a_eps[0]); EXPECT_EQ(mod->Symbols().Register("ep_1"), a_eps[0]);
const auto& c_eps = func_c->ancestor_entry_points(); const auto& c_eps = func_c->ancestor_entry_points();
ASSERT_EQ(2u, c_eps.size()); ASSERT_EQ(2u, c_eps.size());
EXPECT_EQ(mod->RegisterSymbol("ep_1"), c_eps[0]); EXPECT_EQ(mod->Symbols().Register("ep_1"), c_eps[0]);
EXPECT_EQ(mod->RegisterSymbol("ep_2"), c_eps[1]); EXPECT_EQ(mod->Symbols().Register("ep_2"), c_eps[1]);
EXPECT_TRUE(ep_1->ancestor_entry_points().empty()); EXPECT_TRUE(ep_1->ancestor_entry_points().empty());
EXPECT_TRUE(ep_2->ancestor_entry_points().empty()); EXPECT_TRUE(ep_2->ancestor_entry_points().empty());

View File

@ -99,7 +99,7 @@ bool ValidatorImpl::ValidateConstructedTypes(
add_error(member->source(), "v-0031", add_error(member->source(), "v-0031",
"a struct containing a runtime-sized array " "a struct containing a runtime-sized array "
"must be in the 'storage' storage class: '" + "must be in the 'storage' storage class: '" +
program_->SymbolToName(st->symbol()) + "'"); program_->Symbols().NameFor(st->symbol()) + "'");
return false; return false;
} }
} }
@ -116,7 +116,7 @@ bool ValidatorImpl::ValidateGlobalVariables(
if (variable_stack_.has(var->symbol())) { if (variable_stack_.has(var->symbol())) {
add_error(var->source(), "v-0011", add_error(var->source(), "v-0011",
"redeclared global identifier '" + "redeclared global identifier '" +
program_->SymbolToName(var->symbol()) + "'"); program_->Symbols().NameFor(var->symbol()) + "'");
return false; return false;
} }
if (!var->is_const() && var->storage_class() == ast::StorageClass::kNone) { if (!var->is_const() && var->storage_class() == ast::StorageClass::kNone) {
@ -140,7 +140,7 @@ bool ValidatorImpl::ValidateFunctions(const ast::FunctionList& funcs) {
if (function_stack_.has(func->symbol())) { if (function_stack_.has(func->symbol())) {
add_error(func->source(), "v-0016", add_error(func->source(), "v-0016",
"function names must be unique '" + "function names must be unique '" +
program_->SymbolToName(func->symbol()) + "'"); program_->Symbols().NameFor(func->symbol()) + "'");
return false; return false;
} }
@ -163,14 +163,14 @@ bool ValidatorImpl::ValidateEntryPoint(const ast::FunctionList& funcs) {
if (!func->params().empty()) { if (!func->params().empty()) {
add_error(func->source(), "v-0023", add_error(func->source(), "v-0023",
"Entry point function must accept no parameters: '" + "Entry point function must accept no parameters: '" +
program_->SymbolToName(func->symbol()) + "'"); program_->Symbols().NameFor(func->symbol()) + "'");
return false; return false;
} }
if (!func->return_type()->Is<type::Void>()) { if (!func->return_type()->Is<type::Void>()) {
add_error(func->source(), "v-0024", add_error(func->source(), "v-0024",
"Entry point function must return void: '" + "Entry point function must return void: '" +
program_->SymbolToName(func->symbol()) + "'"); program_->Symbols().NameFor(func->symbol()) + "'");
return false; return false;
} }
auto stage_deco_count = 0; auto stage_deco_count = 0;
@ -274,8 +274,9 @@ bool ValidatorImpl::ValidateDeclStatement(
if (is_global) { if (is_global) {
error_code = "v-0013"; error_code = "v-0013";
} }
add_error(decl->source(), error_code, add_error(
"redeclared identifier '" + program_->SymbolToName(symbol) + "'"); decl->source(), error_code,
"redeclared identifier '" + program_->Symbols().NameFor(symbol) + "'");
return false; return false;
} }
// TODO(dneto): Check type compatibility of the initializer. // TODO(dneto): Check type compatibility of the initializer.
@ -415,13 +416,13 @@ bool ValidatorImpl::ValidateCallExpr(const ast::CallExpression* expr) {
if (!function_stack_.has(symbol)) { if (!function_stack_.has(symbol)) {
add_error(expr->source(), "v-0005", add_error(expr->source(), "v-0005",
"function must be declared before use: '" + "function must be declared before use: '" +
program_->SymbolToName(symbol) + "'"); program_->Symbols().NameFor(symbol) + "'");
return false; return false;
} }
if (symbol == current_function_->symbol()) { if (symbol == current_function_->symbol()) {
add_error(expr->source(), "v-0004", add_error(expr->source(), "v-0004",
"recursion is not allowed: '" + "recursion is not allowed: '" +
program_->SymbolToName(symbol) + "'"); program_->Symbols().NameFor(symbol) + "'");
return false; return false;
} }
} }
@ -447,15 +448,15 @@ bool ValidatorImpl::ValidateBadAssignmentToIdentifier(
if (var->is_const()) { if (var->is_const()) {
add_error(assign->source(), "v-0021", add_error(assign->source(), "v-0021",
"cannot re-assign a constant: '" + "cannot re-assign a constant: '" +
program_->SymbolToName(ident->symbol()) + "'"); program_->Symbols().NameFor(ident->symbol()) + "'");
return false; return false;
} }
} else { } else {
// The identifier is not defined. This should already have been caught // The identifier is not defined. This should already have been caught
// when validating the subexpression. // when validating the subexpression.
add_error( add_error(ident->source(), "v-0006",
ident->source(), "v-0006", "'" + program_->Symbols().NameFor(ident->symbol()) +
"'" + program_->SymbolToName(ident->symbol()) + "' is not declared"); "' is not declared");
return false; return false;
} }
return true; return true;
@ -525,9 +526,9 @@ bool ValidatorImpl::ValidateExpression(const ast::Expression* expr) {
bool ValidatorImpl::ValidateIdentifier(const ast::IdentifierExpression* ident) { bool ValidatorImpl::ValidateIdentifier(const ast::IdentifierExpression* ident) {
ast::Variable* var; ast::Variable* var;
if (!variable_stack_.get(ident->symbol(), &var)) { if (!variable_stack_.get(ident->symbol(), &var)) {
add_error( add_error(ident->source(), "v-0006",
ident->source(), "v-0006", "'" + program_->Symbols().NameFor(ident->symbol()) +
"'" + program_->SymbolToName(ident->symbol()) + "' is not declared"); "' is not declared");
return false; return false;
} }
return true; return true;

View File

@ -232,7 +232,8 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
// HLSL typedef is for intrinsic types only. For an alias'd struct, // HLSL typedef is for intrinsic types only. For an alias'd struct,
// generate a secondary struct with the new name. // generate a secondary struct with the new name.
if (auto* str = alias->type()->As<type::Struct>()) { if (auto* str = alias->type()->As<type::Struct>()) {
if (!EmitStructType(out, str, program_->SymbolToName(alias->symbol()))) { if (!EmitStructType(out, str,
program_->Symbols().NameFor(alias->symbol()))) {
return false; return false;
} }
return true; return true;
@ -241,10 +242,10 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
if (!EmitType(out, alias->type(), "")) { if (!EmitType(out, alias->type(), "")) {
return false; return false;
} }
out << " " << namer_.NameFor(program_->SymbolToName(alias->symbol())) << ";" out << " " << namer_.NameFor(program_->Symbols().NameFor(alias->symbol()))
<< std::endl; << ";" << std::endl;
} else if (auto* str = ty->As<type::Struct>()) { } else if (auto* str = ty->As<type::Struct>()) {
if (!EmitStructType(out, str, program_->SymbolToName(str->symbol()))) { if (!EmitStructType(out, str, program_->Symbols().NameFor(str->symbol()))) {
return false; return false;
} }
} else { } else {
@ -623,7 +624,7 @@ bool GeneratorImpl::EmitCall(std::ostream& pre,
return true; return true;
} }
auto name = program_->SymbolToName(ident->symbol()); auto name = program_->Symbols().NameFor(ident->symbol());
auto caller_sym = ident->symbol(); auto caller_sym = ident->symbol();
auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" + auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" +
caller_sym.to_str()); caller_sym.to_str());
@ -633,8 +634,8 @@ bool GeneratorImpl::EmitCall(std::ostream& pre,
auto* func = program_->AST().Functions().Find(ident->symbol()); auto* func = program_->AST().Functions().Find(ident->symbol());
if (func == nullptr) { if (func == nullptr) {
error_ = error_ = "Unable to find function: " +
"Unable to find function: " + program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return false; return false;
} }
@ -868,7 +869,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& pre,
break; break;
default: default:
error_ = "Internal compiler error: Unhandled texture intrinsic '" + error_ = "Internal compiler error: Unhandled texture intrinsic '" +
program_->SymbolToName(ident->symbol()) + "'"; program_->Symbols().NameFor(ident->symbol()) + "'";
return false; return false;
} }
@ -972,7 +973,7 @@ std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) {
case ast::Intrinsic::kMax: case ast::Intrinsic::kMax:
case ast::Intrinsic::kMin: case ast::Intrinsic::kMin:
case ast::Intrinsic::kClamp: case ast::Intrinsic::kClamp:
out = program_->SymbolToName(ident->symbol()); out = program_->Symbols().NameFor(ident->symbol());
break; break;
case ast::Intrinsic::kFaceForward: case ast::Intrinsic::kFaceForward:
out = "faceforward"; out = "faceforward";
@ -987,8 +988,8 @@ std::string GeneratorImpl::generate_builtin_name(ast::CallExpression* expr) {
out = "smoothstep"; out = "smoothstep";
break; break;
default: default:
error_ = error_ = "Unknown builtin method: " +
"Unknown builtin method: " + program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return ""; return "";
} }
@ -1168,7 +1169,7 @@ bool GeneratorImpl::EmitIdentifier(std::ostream&,
out << name << "."; out << name << ".";
} }
} }
out << namer_.NameFor(program_->SymbolToName(ident->symbol())); out << namer_.NameFor(program_->Symbols().NameFor(ident->symbol()));
return true; return true;
} }
@ -1330,12 +1331,12 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out,
auto ep_name = ep_sym.to_str(); auto ep_name = ep_sym.to_str();
// TODO(dsinclair): The SymbolToName should go away and just use // TODO(dsinclair): The SymbolToName should go away and just use
// to_str() here when the conversion is complete. // to_str() here when the conversion is complete.
name = generate_name(program_->SymbolToName(func->symbol()) + "_" + name = generate_name(program_->Symbols().NameFor(func->symbol()) + "_" +
program_->SymbolToName(ep_sym)); program_->Symbols().NameFor(ep_sym));
ep_func_name_remapped_[ep_name + "_" + func_name] = name; ep_func_name_remapped_[ep_name + "_" + func_name] = name;
} else { } else {
// TODO(dsinclair): this should be updated to a remapped name // TODO(dsinclair): this should be updated to a remapped name
name = namer_.NameFor(program_->SymbolToName(func->symbol())); name = namer_.NameFor(program_->Symbols().NameFor(func->symbol()));
} }
out << name << "("; out << name << "(";
@ -1371,12 +1372,12 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out,
} }
first = false; first = false;
if (!EmitType(out, v->type(), program_->SymbolToName(v->symbol()))) { if (!EmitType(out, v->type(), program_->Symbols().NameFor(v->symbol()))) {
return false; return false;
} }
// Array name is output as part of the type // Array name is output as part of the type
if (!v->type()->Is<type::Array>()) { if (!v->type()->Is<type::Array>()) {
out << " " << program_->SymbolToName(v->symbol()); out << " " << program_->Symbols().NameFor(v->symbol());
} }
} }
@ -1430,7 +1431,7 @@ bool GeneratorImpl::EmitEntryPointData(
auto* binding = data.second.binding; auto* binding = data.second.binding;
if (binding == nullptr) { if (binding == nullptr) {
error_ = "unable to find binding information for uniform: " + error_ = "unable to find binding information for uniform: " +
program_->SymbolToName(var->symbol()); program_->Symbols().NameFor(var->symbol());
return false; return false;
} }
// auto* set = data.second.set; // auto* set = data.second.set;
@ -1444,9 +1445,9 @@ bool GeneratorImpl::EmitEntryPointData(
auto* type = var->type()->UnwrapIfNeeded(); auto* type = var->type()->UnwrapIfNeeded();
if (auto* strct = type->As<type::Struct>()) { if (auto* strct = type->As<type::Struct>()) {
out << "ConstantBuffer<" << program_->SymbolToName(strct->symbol()) out << "ConstantBuffer<" << program_->Symbols().NameFor(strct->symbol())
<< "> " << program_->SymbolToName(var->symbol()) << " : register(b" << "> " << program_->Symbols().NameFor(var->symbol())
<< binding->value() << ");" << std::endl; << " : register(b" << binding->value() << ");" << std::endl;
} else { } else {
// TODO(dsinclair): There is outstanding spec work to require all uniform // TODO(dsinclair): There is outstanding spec work to require all uniform
// buffers to be [[block]] decorated, which means structs. This is // buffers to be [[block]] decorated, which means structs. This is
@ -1454,7 +1455,7 @@ bool GeneratorImpl::EmitEntryPointData(
// is not a block. // is not a block.
// Relevant: https://github.com/gpuweb/gpuweb/issues/1004 // Relevant: https://github.com/gpuweb/gpuweb/issues/1004
// https://github.com/gpuweb/gpuweb/issues/1008 // https://github.com/gpuweb/gpuweb/issues/1008
auto name = "cbuffer_" + program_->SymbolToName(var->symbol()); auto name = "cbuffer_" + program_->Symbols().NameFor(var->symbol());
out << "cbuffer " << name << " : register(b" << binding->value() << ") {" out << "cbuffer " << name << " : register(b" << binding->value() << ") {"
<< std::endl; << std::endl;
@ -1463,7 +1464,8 @@ bool GeneratorImpl::EmitEntryPointData(
if (!EmitType(out, type, "")) { if (!EmitType(out, type, "")) {
return false; return false;
} }
out << " " << program_->SymbolToName(var->symbol()) << ";" << std::endl; out << " " << program_->Symbols().NameFor(var->symbol()) << ";"
<< std::endl;
decrement_indent(); decrement_indent();
out << "};" << std::endl; out << "};" << std::endl;
} }
@ -1495,7 +1497,7 @@ bool GeneratorImpl::EmitEntryPointData(
if (ac->IsReadWrite()) { if (ac->IsReadWrite()) {
out << "RW"; out << "RW";
} }
out << "ByteAddressBuffer " << program_->SymbolToName(var->symbol()) out << "ByteAddressBuffer " << program_->Symbols().NameFor(var->symbol())
<< " : register(u" << binding->value() << ");" << std::endl; << " : register(u" << binding->value() << ");" << std::endl;
emitted_storagebuffer = true; emitted_storagebuffer = true;
} }
@ -1504,8 +1506,9 @@ bool GeneratorImpl::EmitEntryPointData(
} }
if (!in_variables.empty()) { if (!in_variables.empty()) {
auto in_struct_name = generate_name(program_->SymbolToName(func->symbol()) + auto in_struct_name =
"_" + kInStructNameSuffix); generate_name(program_->Symbols().NameFor(func->symbol()) + "_" +
kInStructNameSuffix);
auto in_var_name = generate_name(kTintStructInVarPrefix); auto in_var_name = generate_name(kTintStructInVarPrefix);
ep_sym_to_in_data_[func->symbol()] = {in_struct_name, in_var_name}; ep_sym_to_in_data_[func->symbol()] = {in_struct_name, in_var_name};
@ -1519,11 +1522,12 @@ bool GeneratorImpl::EmitEntryPointData(
auto* deco = data.second; auto* deco = data.second;
make_indent(out); make_indent(out);
if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(out, var->type(),
program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
out << " " << program_->SymbolToName(var->symbol()) << " : "; out << " " << program_->Symbols().NameFor(var->symbol()) << " : ";
if (auto* location = deco->As<ast::LocationDecoration>()) { if (auto* location = deco->As<ast::LocationDecoration>()) {
if (func->pipeline_stage() == ast::PipelineStage::kCompute) { if (func->pipeline_stage() == ast::PipelineStage::kCompute) {
error_ = "invalid location variable for pipeline stage"; error_ = "invalid location variable for pipeline stage";
@ -1550,8 +1554,9 @@ bool GeneratorImpl::EmitEntryPointData(
} }
if (!outvariables.empty()) { if (!outvariables.empty()) {
auto outstruct_name = generate_name(program_->SymbolToName(func->symbol()) + auto outstruct_name =
"_" + kOutStructNameSuffix); generate_name(program_->Symbols().NameFor(func->symbol()) + "_" +
kOutStructNameSuffix);
auto outvar_name = generate_name(kTintStructOutVarPrefix); auto outvar_name = generate_name(kTintStructOutVarPrefix);
ep_sym_to_out_data_[func->symbol()] = {outstruct_name, outvar_name}; ep_sym_to_out_data_[func->symbol()] = {outstruct_name, outvar_name};
@ -1564,11 +1569,12 @@ bool GeneratorImpl::EmitEntryPointData(
auto* deco = data.second; auto* deco = data.second;
make_indent(out); make_indent(out);
if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(out, var->type(),
program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
out << " " << program_->SymbolToName(var->symbol()) << " : "; out << " " << program_->Symbols().NameFor(var->symbol()) << " : ";
if (auto* location = deco->As<ast::LocationDecoration>()) { if (auto* location = deco->As<ast::LocationDecoration>()) {
auto loc = location->value(); auto loc = location->value();
@ -1651,7 +1657,8 @@ bool GeneratorImpl::EmitEntryPointFunction(std::ostream& out,
out << "void"; out << "void";
} }
// TODO(dsinclair): This should output the remapped name // TODO(dsinclair): This should output the remapped name
out << " " << namer_.NameFor(program_->SymbolToName(current_ep_sym_)) << "("; out << " " << namer_.NameFor(program_->Symbols().NameFor(current_ep_sym_))
<< "(";
auto in_data = ep_sym_to_in_data_.find(current_ep_sym_); auto in_data = ep_sym_to_in_data_.find(current_ep_sym_);
if (in_data != ep_sym_to_in_data_.end()) { if (in_data != ep_sym_to_in_data_.end()) {
@ -1799,7 +1806,7 @@ bool GeneratorImpl::EmitLoop(std::ostream& out, ast::LoopStatement* stmt) {
} }
out << pre.str(); out << pre.str();
out << program_->SymbolToName(var->symbol()) << " = "; out << program_->Symbols().NameFor(var->symbol()) << " = ";
if (var->constructor() != nullptr) { if (var->constructor() != nullptr) {
out << constructor_out.str(); out << constructor_out.str();
} else { } else {
@ -1862,7 +1869,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
// //
// This must be a single element swizzle if we've got a vector at this // This must be a single element swizzle if we've got a vector at this
// point. // point.
if (program_->SymbolToName(mem->member()->symbol()).size() != 1) { if (program_->Symbols().NameFor(mem->member()->symbol()).size() != 1) {
error_ = error_ =
"Encountered multi-element swizzle when should have only one " "Encountered multi-element swizzle when should have only one "
"level"; "level";
@ -1874,7 +1881,7 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
// f64 types. // f64 types.
out << "(4 * " out << "(4 * "
<< convert_swizzle_to_index( << convert_swizzle_to_index(
program_->SymbolToName(mem->member()->symbol())) program_->Symbols().NameFor(mem->member()->symbol()))
<< ")"; << ")";
} else { } else {
error_ = error_ =
@ -2053,7 +2060,7 @@ bool GeneratorImpl::is_storage_buffer_access(
// If the data is a multi-element swizzle then we will not load the swizzle // If the data is a multi-element swizzle then we will not load the swizzle
// portion through the Load command. // portion through the Load command.
if (data_type->Is<type::Vector>() && if (data_type->Is<type::Vector>() &&
program_->SymbolToName(expr->member()->symbol()).size() > 1) { program_->Symbols().NameFor(expr->member()->symbol()).size() > 1) {
return false; return false;
} }
@ -2205,7 +2212,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
} }
if (auto* alias = type->As<type::Alias>()) { if (auto* alias = type->As<type::Alias>()) {
out << namer_.NameFor(program_->SymbolToName(alias->symbol())); out << namer_.NameFor(program_->Symbols().NameFor(alias->symbol()));
} else if (auto* ary = type->As<type::Array>()) { } else if (auto* ary = type->As<type::Array>()) {
type::Type* base_type = ary; type::Type* base_type = ary;
std::vector<uint32_t> sizes; std::vector<uint32_t> sizes;
@ -2252,7 +2259,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
} }
out << "State"; out << "State";
} else if (auto* str = type->As<type::Struct>()) { } else if (auto* str = type->As<type::Struct>()) {
out << program_->SymbolToName(str->symbol()); out << program_->Symbols().NameFor(str->symbol());
} else if (auto* tex = type->As<type::Texture>()) { } else if (auto* tex = type->As<type::Texture>()) {
if (tex->Is<type::StorageTexture>()) { if (tex->Is<type::StorageTexture>()) {
out << "RW"; out << "RW";
@ -2336,12 +2343,13 @@ bool GeneratorImpl::EmitStructType(std::ostream& out,
// TODO(dsinclair): Handle [[offset]] annotation on structs // TODO(dsinclair): Handle [[offset]] annotation on structs
// https://bugs.chromium.org/p/tint/issues/detail?id=184 // https://bugs.chromium.org/p/tint/issues/detail?id=184
if (!EmitType(out, mem->type(), program_->SymbolToName(mem->symbol()))) { if (!EmitType(out, mem->type(),
program_->Symbols().NameFor(mem->symbol()))) {
return false; return false;
} }
// Array member name will be output with the type // Array member name will be output with the type
if (!mem->type()->Is<type::Array>()) { if (!mem->type()->Is<type::Array>()) {
out << " " << namer_.NameFor(program_->SymbolToName(mem->symbol())); out << " " << namer_.NameFor(program_->Symbols().NameFor(mem->symbol()));
} }
out << ";" << std::endl; out << ";" << std::endl;
} }
@ -2400,11 +2408,11 @@ bool GeneratorImpl::EmitVariable(std::ostream& out,
if (var->is_const()) { if (var->is_const()) {
out << "const "; out << "const ";
} }
if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(out, var->type(), program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
if (!var->type()->Is<type::Array>()) { if (!var->type()->Is<type::Array>()) {
out << " " << program_->SymbolToName(var->symbol()); out << " " << program_->Symbols().NameFor(var->symbol());
} }
out << constructor_out.str() << ";" << std::endl; out << constructor_out.str() << ";" << std::endl;
@ -2449,19 +2457,21 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out,
} }
out << "#endif" << std::endl; out << "#endif" << std::endl;
out << "static const "; out << "static const ";
if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(out, var->type(),
program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
out << " " << program_->SymbolToName(var->symbol()) out << " " << program_->Symbols().NameFor(var->symbol())
<< " = WGSL_SPEC_CONSTANT_" << const_id << ";" << std::endl; << " = WGSL_SPEC_CONSTANT_" << const_id << ";" << std::endl;
out << "#undef WGSL_SPEC_CONSTANT_" << const_id << std::endl; out << "#undef WGSL_SPEC_CONSTANT_" << const_id << std::endl;
} else { } else {
out << "static const "; out << "static const ";
if (!EmitType(out, var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(out, var->type(),
program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
if (!var->type()->Is<type::Array>()) { if (!var->type()->Is<type::Array>()) {
out << " " << program_->SymbolToName(var->symbol()); out << " " << program_->Symbols().NameFor(var->symbol());
} }
if (var->constructor() != nullptr) { if (var->constructor() != nullptr) {
@ -2476,7 +2486,7 @@ bool GeneratorImpl::EmitProgramConstVariable(std::ostream& out,
std::string GeneratorImpl::get_buffer_name(ast::Expression* expr) { std::string GeneratorImpl::get_buffer_name(ast::Expression* expr) {
for (;;) { for (;;) {
if (auto* ident = expr->As<ast::IdentifierExpression>()) { if (auto* ident = expr->As<ast::IdentifierExpression>()) {
return program_->SymbolToName(ident->symbol()); return program_->Symbols().NameFor(ident->symbol());
} else if (auto* member = expr->As<ast::MemberAccessorExpression>()) { } else if (auto* member = expr->As<ast::MemberAccessorExpression>()) {
expr = member->structure(); expr = member->structure();
} else if (auto* array = expr->As<ast::ArrayAccessorExpression>()) { } else if (auto* array = expr->As<ast::ArrayAccessorExpression>()) {

View File

@ -258,7 +258,7 @@ bool GeneratorImpl::EmitConstructedType(const type::Type* ty) {
if (!EmitType(alias->type(), "")) { if (!EmitType(alias->type(), "")) {
return false; return false;
} }
out_ << " " << namer_.NameFor(program_->SymbolToName(alias->symbol())) out_ << " " << namer_.NameFor(program_->Symbols().NameFor(alias->symbol()))
<< ";" << std::endl; << ";" << std::endl;
} else if (auto* str = ty->As<type::Struct>()) { } else if (auto* str = ty->As<type::Struct>()) {
if (!EmitStructType(str)) { if (!EmitStructType(str)) {
@ -517,7 +517,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
return true; return true;
} }
auto name = program_->SymbolToName(ident->symbol()); auto name = program_->Symbols().NameFor(ident->symbol());
auto caller_sym = ident->symbol(); auto caller_sym = ident->symbol();
auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" + auto it = ep_func_name_remapped_.find(current_ep_sym_.to_str() + "_" +
caller_sym.to_str()); caller_sym.to_str());
@ -527,8 +527,8 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
auto* func = program_->AST().Functions().Find(ident->symbol()); auto* func = program_->AST().Functions().Find(ident->symbol());
if (func == nullptr) { if (func == nullptr) {
error_ = error_ = "Unable to find function: " +
"Unable to find function: " + program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return false; return false;
} }
@ -562,7 +562,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
out_ << ", "; out_ << ", ";
} }
first = false; first = false;
out_ << program_->SymbolToName(var->symbol()); out_ << program_->Symbols().NameFor(var->symbol());
} }
for (const auto& data : func->referenced_uniform_variables()) { for (const auto& data : func->referenced_uniform_variables()) {
@ -571,7 +571,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
out_ << ", "; out_ << ", ";
} }
first = false; first = false;
out_ << program_->SymbolToName(var->symbol()); out_ << program_->Symbols().NameFor(var->symbol());
} }
for (const auto& data : func->referenced_storagebuffer_variables()) { for (const auto& data : func->referenced_storagebuffer_variables()) {
@ -580,7 +580,7 @@ bool GeneratorImpl::EmitCall(ast::CallExpression* expr) {
out_ << ", "; out_ << ", ";
} }
first = false; first = false;
out_ << program_->SymbolToName(var->symbol()); out_ << program_->Symbols().NameFor(var->symbol());
} }
const auto& params = expr->params(); const auto& params = expr->params();
@ -720,7 +720,7 @@ bool GeneratorImpl::EmitTextureCall(ast::CallExpression* expr) {
break; break;
default: default:
error_ = "Internal compiler error: Unhandled texture intrinsic '" + error_ = "Internal compiler error: Unhandled texture intrinsic '" +
program_->SymbolToName(ident->symbol()) + "'"; program_->Symbols().NameFor(ident->symbol()) + "'";
return false; return false;
} }
@ -847,7 +847,7 @@ std::string GeneratorImpl::generate_builtin_name(
case ast::Intrinsic::kTrunc: case ast::Intrinsic::kTrunc:
case ast::Intrinsic::kSign: case ast::Intrinsic::kSign:
case ast::Intrinsic::kClamp: case ast::Intrinsic::kClamp:
out += program_->SymbolToName(ident->symbol()); out += program_->Symbols().NameFor(ident->symbol());
break; break;
case ast::Intrinsic::kAbs: case ast::Intrinsic::kAbs:
if (ident->result_type()->Is<type::F32>()) { if (ident->result_type()->Is<type::F32>()) {
@ -883,8 +883,8 @@ std::string GeneratorImpl::generate_builtin_name(
out += "rsqrt"; out += "rsqrt";
break; break;
default: default:
error_ = error_ = "Unknown import method: " +
"Unknown import method: " + program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return ""; return "";
} }
return out; return out;
@ -1059,8 +1059,9 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
} }
if (!in_locations.empty()) { if (!in_locations.empty()) {
auto in_struct_name = generate_name(program_->SymbolToName(func->symbol()) + auto in_struct_name =
"_" + kInStructNameSuffix); generate_name(program_->Symbols().NameFor(func->symbol()) + "_" +
kInStructNameSuffix);
auto in_var_name = generate_name(kTintStructInVarPrefix); auto in_var_name = generate_name(kTintStructInVarPrefix);
ep_sym_to_in_data_[func->symbol()] = {in_struct_name, in_var_name}; ep_sym_to_in_data_[func->symbol()] = {in_struct_name, in_var_name};
@ -1074,11 +1075,11 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
uint32_t loc = data.second; uint32_t loc = data.second;
make_indent(); make_indent();
if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(var->type(), program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
out_ << " " << program_->SymbolToName(var->symbol()) << " [["; out_ << " " << program_->Symbols().NameFor(var->symbol()) << " [[";
if (func->pipeline_stage() == ast::PipelineStage::kVertex) { if (func->pipeline_stage() == ast::PipelineStage::kVertex) {
out_ << "attribute(" << loc << ")"; out_ << "attribute(" << loc << ")";
} else if (func->pipeline_stage() == ast::PipelineStage::kFragment) { } else if (func->pipeline_stage() == ast::PipelineStage::kFragment) {
@ -1096,8 +1097,9 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
} }
if (!out_variables.empty()) { if (!out_variables.empty()) {
auto out_struct_name = generate_name( auto out_struct_name =
program_->SymbolToName(func->symbol()) + "_" + kOutStructNameSuffix); generate_name(program_->Symbols().NameFor(func->symbol()) + "_" +
kOutStructNameSuffix);
auto out_var_name = generate_name(kTintStructOutVarPrefix); auto out_var_name = generate_name(kTintStructOutVarPrefix);
ep_sym_to_out_data_[func->symbol()] = {out_struct_name, out_var_name}; ep_sym_to_out_data_[func->symbol()] = {out_struct_name, out_var_name};
@ -1110,11 +1112,11 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
auto* deco = data.second; auto* deco = data.second;
make_indent(); make_indent();
if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(var->type(), program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
out_ << " " << program_->SymbolToName(var->symbol()) << " [["; out_ << " " << program_->Symbols().NameFor(var->symbol()) << " [[";
if (auto* location = deco->As<ast::LocationDecoration>()) { if (auto* location = deco->As<ast::LocationDecoration>()) {
auto loc = location->value(); auto loc = location->value();
@ -1272,12 +1274,12 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
auto ep_name = ep_sym.to_str(); auto ep_name = ep_sym.to_str();
// TODO(dsinclair): The SymbolToName should go away and just use // TODO(dsinclair): The SymbolToName should go away and just use
// to_str() here when the conversion is complete. // to_str() here when the conversion is complete.
name = generate_name(program_->SymbolToName(func->symbol()) + "_" + name = generate_name(program_->Symbols().NameFor(func->symbol()) + "_" +
program_->SymbolToName(ep_sym)); program_->Symbols().NameFor(ep_sym));
ep_func_name_remapped_[ep_name + "_" + func_name] = name; ep_func_name_remapped_[ep_name + "_" + func_name] = name;
} else { } else {
// TODO(dsinclair): this should be updated to a remapped name // TODO(dsinclair): this should be updated to a remapped name
name = namer_.NameFor(program_->SymbolToName(func->symbol())); name = namer_.NameFor(program_->Symbols().NameFor(func->symbol()));
} }
out_ << name << "("; out_ << name << "(";
@ -1320,7 +1322,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
if (!EmitType(var->type(), "")) { if (!EmitType(var->type(), "")) {
return false; return false;
} }
out_ << "& " << program_->SymbolToName(var->symbol()); out_ << "& " << program_->Symbols().NameFor(var->symbol());
} }
for (const auto& data : func->referenced_uniform_variables()) { for (const auto& data : func->referenced_uniform_variables()) {
@ -1335,7 +1337,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
if (!EmitType(var->type(), "")) { if (!EmitType(var->type(), "")) {
return false; return false;
} }
out_ << "& " << program_->SymbolToName(var->symbol()); out_ << "& " << program_->Symbols().NameFor(var->symbol());
} }
for (const auto& data : func->referenced_storagebuffer_variables()) { for (const auto& data : func->referenced_storagebuffer_variables()) {
@ -1358,7 +1360,7 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
if (!EmitType(ac->type(), "")) { if (!EmitType(ac->type(), "")) {
return false; return false;
} }
out_ << "& " << program_->SymbolToName(var->symbol()); out_ << "& " << program_->Symbols().NameFor(var->symbol());
} }
for (auto* v : func->params()) { for (auto* v : func->params()) {
@ -1367,12 +1369,12 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
} }
first = false; first = false;
if (!EmitType(v->type(), program_->SymbolToName(v->symbol()))) { if (!EmitType(v->type(), program_->Symbols().NameFor(v->symbol()))) {
return false; return false;
} }
// Array name is output as part of the type // Array name is output as part of the type
if (!v->type()->Is<type::Array>()) { if (!v->type()->Is<type::Array>()) {
out_ << " " << program_->SymbolToName(v->symbol()); out_ << " " << program_->Symbols().NameFor(v->symbol());
} }
} }
@ -1432,7 +1434,8 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
} else { } else {
out_ << "void"; out_ << "void";
} }
out_ << " " << namer_.NameFor(program_->SymbolToName(func->symbol())) << "("; out_ << " " << namer_.NameFor(program_->Symbols().NameFor(func->symbol()))
<< "(";
bool first = true; bool first = true;
auto in_data = ep_sym_to_in_data_.find(current_ep_sym_); auto in_data = ep_sym_to_in_data_.find(current_ep_sym_);
@ -1464,7 +1467,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
error_ = "unknown builtin"; error_ = "unknown builtin";
return false; return false;
} }
out_ << " " << program_->SymbolToName(var->symbol()) << " [[" << attr out_ << " " << program_->Symbols().NameFor(var->symbol()) << " [[" << attr
<< "]]"; << "]]";
} }
@ -1481,7 +1484,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
auto* binding = data.second.binding; auto* binding = data.second.binding;
if (binding == nullptr) { if (binding == nullptr) {
error_ = "unable to find binding information for uniform: " + error_ = "unable to find binding information for uniform: " +
program_->SymbolToName(var->symbol()); program_->Symbols().NameFor(var->symbol());
return false; return false;
} }
// auto* set = data.second.set; // auto* set = data.second.set;
@ -1492,7 +1495,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
if (!EmitType(var->type(), "")) { if (!EmitType(var->type(), "")) {
return false; return false;
} }
out_ << "& " << program_->SymbolToName(var->symbol()) << " [[buffer(" out_ << "& " << program_->Symbols().NameFor(var->symbol()) << " [[buffer("
<< binding->value() << ")]]"; << binding->value() << ")]]";
} }
@ -1522,7 +1525,7 @@ bool GeneratorImpl::EmitEntryPointFunction(ast::Function* func) {
if (!EmitType(ac->type(), "")) { if (!EmitType(ac->type(), "")) {
return false; return false;
} }
out_ << "& " << program_->SymbolToName(var->symbol()) << " [[buffer(" out_ << "& " << program_->Symbols().NameFor(var->symbol()) << " [[buffer("
<< binding->value() << ")]]"; << binding->value() << ")]]";
} }
@ -1587,7 +1590,7 @@ bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
out_ << name << "."; out_ << name << ".";
} }
} }
out_ << namer_.NameFor(program_->SymbolToName(ident->symbol())); out_ << namer_.NameFor(program_->Symbols().NameFor(ident->symbol()));
return true; return true;
} }
@ -1646,7 +1649,7 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) {
make_indent(); make_indent();
auto* var = decl->variable(); auto* var = decl->variable();
out_ << program_->SymbolToName(var->symbol()) << " = "; out_ << program_->Symbols().NameFor(var->symbol()) << " = ";
if (var->constructor() != nullptr) { if (var->constructor() != nullptr) {
if (!EmitExpression(var->constructor())) { if (!EmitExpression(var->constructor())) {
return false; return false;
@ -1877,7 +1880,7 @@ bool GeneratorImpl::EmitType(type::Type* type, const std::string& name) {
} }
if (auto* alias = type->As<type::Alias>()) { if (auto* alias = type->As<type::Alias>()) {
out_ << namer_.NameFor(program_->SymbolToName(alias->symbol())); out_ << namer_.NameFor(program_->Symbols().NameFor(alias->symbol()));
} else if (auto* ary = type->As<type::Array>()) { } else if (auto* ary = type->As<type::Array>()) {
type::Type* base_type = ary; type::Type* base_type = ary;
std::vector<uint32_t> sizes; std::vector<uint32_t> sizes;
@ -1920,7 +1923,7 @@ bool GeneratorImpl::EmitType(type::Type* type, const std::string& name) {
} else if (auto* str = type->As<type::Struct>()) { } else if (auto* str = type->As<type::Struct>()) {
// The struct type emits as just the name. The declaration would be emitted // The struct type emits as just the name. The declaration would be emitted
// as part of emitting the constructed types. // as part of emitting the constructed types.
out_ << program_->SymbolToName(str->symbol()); out_ << program_->Symbols().NameFor(str->symbol());
} else if (auto* tex = type->As<type::Texture>()) { } else if (auto* tex = type->As<type::Texture>()) {
if (tex->Is<type::DepthTexture>()) { if (tex->Is<type::DepthTexture>()) {
out_ << "depth"; out_ << "depth";
@ -2002,7 +2005,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) {
// TODO(dsinclair): Block decoration? // TODO(dsinclair): Block decoration?
// if (str->impl()->decoration() != ast::StructDecoration::kNone) { // if (str->impl()->decoration() != ast::StructDecoration::kNone) {
// } // }
out_ << "struct " << program_->SymbolToName(str->symbol()) << " {" out_ << "struct " << program_->Symbols().NameFor(str->symbol()) << " {"
<< std::endl; << std::endl;
increment_indent(); increment_indent();
@ -2026,7 +2029,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) {
} }
} }
if (!EmitType(mem->type(), program_->SymbolToName(mem->symbol()))) { if (!EmitType(mem->type(), program_->Symbols().NameFor(mem->symbol()))) {
return false; return false;
} }
auto size = calculate_alignment_size(mem->type()); auto size = calculate_alignment_size(mem->type());
@ -2038,7 +2041,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) {
// Array member name will be output with the type // Array member name will be output with the type
if (!mem->type()->Is<type::Array>()) { if (!mem->type()->Is<type::Array>()) {
out_ << " " << namer_.NameFor(program_->SymbolToName(mem->symbol())); out_ << " " << namer_.NameFor(program_->Symbols().NameFor(mem->symbol()));
} }
out_ << ";" << std::endl; out_ << ";" << std::endl;
} }
@ -2080,11 +2083,11 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var, bool skip_constructor) {
if (var->is_const()) { if (var->is_const()) {
out_ << "const "; out_ << "const ";
} }
if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(var->type(), program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
if (!var->type()->Is<type::Array>()) { if (!var->type()->Is<type::Array>()) {
out_ << " " << program_->SymbolToName(var->symbol()); out_ << " " << program_->Symbols().NameFor(var->symbol());
} }
if (!skip_constructor) { if (!skip_constructor) {
@ -2122,11 +2125,11 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) {
} }
out_ << "constant "; out_ << "constant ";
if (!EmitType(var->type(), program_->SymbolToName(var->symbol()))) { if (!EmitType(var->type(), program_->Symbols().NameFor(var->symbol()))) {
return false; return false;
} }
if (!var->type()->Is<type::Array>()) { if (!var->type()->Is<type::Array>()) {
out_ << " " << program_->SymbolToName(var->symbol()); out_ << " " << program_->Symbols().NameFor(var->symbol());
} }
if (var->HasConstantIdDecoration()) { if (var->HasConstantIdDecoration()) {

View File

@ -450,7 +450,7 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) {
OperandList operands = { OperandList operands = {
Operand::Int(stage), Operand::Int(id), Operand::Int(stage), Operand::Int(id),
Operand::String(program_->SymbolToName(func->symbol()))}; Operand::String(program_->Symbols().NameFor(func->symbol()))};
for (const auto* var : func->referenced_module_variables()) { for (const auto* var : func->referenced_module_variables()) {
// For SPIR-V 1.3 we only output Input/output variables. If we update to // For SPIR-V 1.3 we only output Input/output variables. If we update to
@ -463,7 +463,7 @@ bool Builder::GenerateEntryPoint(ast::Function* func, uint32_t id) {
uint32_t var_id; uint32_t var_id;
if (!scope_stack_.get(var->symbol(), &var_id)) { if (!scope_stack_.get(var->symbol(), &var_id)) {
error_ = "unable to find ID for global variable: " + error_ = "unable to find ID for global variable: " +
program_->SymbolToName(var->symbol()); program_->Symbols().NameFor(var->symbol());
return false; return false;
} }
@ -543,7 +543,7 @@ bool Builder::GenerateFunction(ast::Function* func) {
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(func_id), {Operand::Int(func_id),
Operand::String(program_->SymbolToName(func->symbol()))}); Operand::String(program_->Symbols().NameFor(func->symbol()))});
auto ret_id = GenerateTypeIfNeeded(func->return_type()); auto ret_id = GenerateTypeIfNeeded(func->return_type());
if (ret_id == 0) { if (ret_id == 0) {
@ -569,7 +569,7 @@ bool Builder::GenerateFunction(ast::Function* func) {
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(param_id), {Operand::Int(param_id),
Operand::String(program_->SymbolToName(param->symbol()))}); Operand::String(program_->Symbols().NameFor(param->symbol()))});
params.push_back(Instruction{spv::Op::OpFunctionParameter, params.push_back(Instruction{spv::Op::OpFunctionParameter,
{Operand::Int(param_type_id), param_op}}); {Operand::Int(param_type_id), param_op}});
@ -660,7 +660,7 @@ bool Builder::GenerateFunctionVariable(ast::Variable* var) {
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(var_id), {Operand::Int(var_id),
Operand::String(program_->SymbolToName(var->symbol()))}); Operand::String(program_->Symbols().NameFor(var->symbol()))});
// TODO(dsinclair) We could detect if the constructor is fully const and emit // TODO(dsinclair) We could detect if the constructor is fully const and emit
// an initializer value for the variable instead of doing the OpLoad. // an initializer value for the variable instead of doing the OpLoad.
@ -712,7 +712,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
} }
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(init_id), {Operand::Int(init_id),
Operand::String(program_->SymbolToName(var->symbol()))}); Operand::String(program_->Symbols().NameFor(var->symbol()))});
scope_stack_.set_global(var->symbol(), init_id); scope_stack_.set_global(var->symbol(), init_id);
spirv_id_to_variable_[init_id] = var; spirv_id_to_variable_[init_id] = var;
@ -734,7 +734,7 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
push_debug(spv::Op::OpName, push_debug(spv::Op::OpName,
{Operand::Int(var_id), {Operand::Int(var_id),
Operand::String(program_->SymbolToName(var->symbol()))}); Operand::String(program_->Symbols().NameFor(var->symbol()))});
OperandList ops = {Operand::Int(type_id), result, OperandList ops = {Operand::Int(type_id), result,
Operand::Int(ConvertStorageClass(sc))}; Operand::Int(ConvertStorageClass(sc))};
@ -915,7 +915,7 @@ bool Builder::GenerateMemberAccessor(ast::MemberAccessorExpression* expr,
} }
// TODO(dsinclair): Swizzle stuff // TODO(dsinclair): Swizzle stuff
auto swiz = program_->SymbolToName(expr->member()->symbol()); auto swiz = program_->Symbols().NameFor(expr->member()->symbol());
// Single element swizzle is either an access chain or a composite extract // Single element swizzle is either an access chain or a composite extract
if (swiz.size() == 1) { if (swiz.size() == 1) {
auto val = IndexFromName(swiz[0]); auto val = IndexFromName(swiz[0]);
@ -1123,7 +1123,7 @@ uint32_t Builder::GenerateIdentifierExpression(
} }
error_ = "unable to find variable with identifier: " + error_ = "unable to find variable with identifier: " +
program_->SymbolToName(expr->symbol()); program_->Symbols().NameFor(expr->symbol());
return 0; return 0;
} }
@ -1816,7 +1816,7 @@ uint32_t Builder::GenerateCallExpression(ast::CallExpression* expr) {
auto func_id = func_symbol_to_id_[ident->symbol()]; auto func_id = func_symbol_to_id_[ident->symbol()];
if (func_id == 0) { if (func_id == 0) {
error_ = "unable to find called function: " + error_ = "unable to find called function: " +
program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return 0; return 0;
} }
ops.push_back(Operand::Int(func_id)); ops.push_back(Operand::Int(func_id));
@ -1948,7 +1948,7 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident,
auto inst_id = auto inst_id =
intrinsic_to_glsl_method(ident->result_type(), ident->intrinsic()); intrinsic_to_glsl_method(ident->result_type(), ident->intrinsic());
if (inst_id == 0) { if (inst_id == 0) {
error_ = "unknown method " + program_->SymbolToName(ident->symbol()); error_ = "unknown method " + program_->Symbols().NameFor(ident->symbol());
return 0; return 0;
} }
@ -1960,7 +1960,7 @@ uint32_t Builder::GenerateIntrinsic(ast::IdentifierExpression* ident,
if (op == spv::Op::OpNop) { if (op == spv::Op::OpNop) {
error_ = "unable to determine operator for: " + error_ = "unable to determine operator for: " +
program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return 0; return 0;
} }
@ -2384,7 +2384,7 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident,
if (op == spv::Op::OpNop) { if (op == spv::Op::OpNop) {
error_ = "unable to determine operator for: " + error_ = "unable to determine operator for: " +
program_->SymbolToName(ident->symbol()); program_->Symbols().NameFor(ident->symbol());
return false; return false;
} }
@ -3006,7 +3006,7 @@ bool Builder::GenerateStructType(type::Struct* struct_type,
push_debug( push_debug(
spv::Op::OpName, spv::Op::OpName,
{Operand::Int(struct_id), {Operand::Int(struct_id),
Operand::String(program_->SymbolToName(struct_type->symbol()))}); Operand::String(program_->Symbols().NameFor(struct_type->symbol()))});
} }
OperandList ops; OperandList ops;
@ -3049,7 +3049,7 @@ uint32_t Builder::GenerateStructMember(uint32_t struct_id,
ast::StructMember* member) { ast::StructMember* member) {
push_debug(spv::Op::OpMemberName, push_debug(spv::Op::OpMemberName,
{Operand::Int(struct_id), Operand::Int(idx), {Operand::Int(struct_id), Operand::Int(idx),
Operand::String(program_->SymbolToName(member->symbol()))}); Operand::String(program_->Symbols().NameFor(member->symbol()))});
bool has_layout = false; bool has_layout = false;
for (auto* deco : member->decorations()) { for (auto* deco : member->decorations()) {

View File

@ -114,7 +114,7 @@ bool GeneratorImpl::Generate() {
bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage, bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
const std::string& name) { const std::string& name) {
auto* func = auto* func =
program_->AST().Functions().Find(program_->GetSymbol(name), stage); program_->AST().Functions().Find(program_->Symbols().Get(name), stage);
if (func == nullptr) { if (func == nullptr) {
error_ = "Unable to find requested entry point: " + name; error_ = "Unable to find requested entry point: " + name;
return false; return false;
@ -154,7 +154,7 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
} }
for (auto* f : program_->AST().Functions()) { for (auto* f : program_->AST().Functions()) {
if (!f->HasAncestorEntryPoint(program_->GetSymbol(name))) { if (!f->HasAncestorEntryPoint(program_->Symbols().Get(name))) {
continue; continue;
} }
@ -175,7 +175,7 @@ bool GeneratorImpl::GenerateEntryPoint(ast::PipelineStage stage,
bool GeneratorImpl::EmitConstructedType(const type::Type* ty) { bool GeneratorImpl::EmitConstructedType(const type::Type* ty) {
make_indent(); make_indent();
if (auto* alias = ty->As<type::Alias>()) { if (auto* alias = ty->As<type::Alias>()) {
out_ << "type " << program_->SymbolToName(alias->symbol()) << " = "; out_ << "type " << program_->Symbols().NameFor(alias->symbol()) << " = ";
if (!EmitType(alias->type())) { if (!EmitType(alias->type())) {
return false; return false;
} }
@ -338,7 +338,7 @@ bool GeneratorImpl::EmitLiteral(ast::Literal* lit) {
bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) { bool GeneratorImpl::EmitIdentifier(ast::IdentifierExpression* expr) {
auto* ident = expr->As<ast::IdentifierExpression>(); auto* ident = expr->As<ast::IdentifierExpression>();
out_ << program_->SymbolToName(ident->symbol()); out_ << program_->Symbols().NameFor(ident->symbol());
return true; return true;
} }
@ -361,7 +361,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
} }
make_indent(); make_indent();
out_ << "fn " << program_->SymbolToName(func->symbol()) << "("; out_ << "fn " << program_->Symbols().NameFor(func->symbol()) << "(";
bool first = true; bool first = true;
for (auto* v : func->params()) { for (auto* v : func->params()) {
@ -370,7 +370,7 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
} }
first = false; first = false;
out_ << program_->SymbolToName(v->symbol()) << " : "; out_ << program_->Symbols().NameFor(v->symbol()) << " : ";
if (!EmitType(v->type())) { if (!EmitType(v->type())) {
return false; return false;
@ -418,7 +418,7 @@ bool GeneratorImpl::EmitType(type::Type* type) {
} }
return true; return true;
} else if (auto* alias = type->As<type::Alias>()) { } else if (auto* alias = type->As<type::Alias>()) {
out_ << program_->SymbolToName(alias->symbol()); out_ << program_->Symbols().NameFor(alias->symbol());
} else if (auto* ary = type->As<type::Array>()) { } else if (auto* ary = type->As<type::Array>()) {
for (auto* deco : ary->decorations()) { for (auto* deco : ary->decorations()) {
if (auto* stride = deco->As<ast::StrideDecoration>()) { if (auto* stride = deco->As<ast::StrideDecoration>()) {
@ -462,7 +462,7 @@ bool GeneratorImpl::EmitType(type::Type* type) {
} else if (auto* str = type->As<type::Struct>()) { } else if (auto* str = type->As<type::Struct>()) {
// The struct, as a type, is just the name. We should have already emitted // The struct, as a type, is just the name. We should have already emitted
// the declaration through a call to |EmitStructType| earlier. // the declaration through a call to |EmitStructType| earlier.
out_ << program_->SymbolToName(str->symbol()); out_ << program_->Symbols().NameFor(str->symbol());
} else if (auto* texture = type->As<type::Texture>()) { } else if (auto* texture = type->As<type::Texture>()) {
out_ << "texture_"; out_ << "texture_";
if (texture->Is<type::DepthTexture>()) { if (texture->Is<type::DepthTexture>()) {
@ -550,7 +550,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) {
deco->to_str(out_, 0); deco->to_str(out_, 0);
out_ << "]]" << std::endl; out_ << "]]" << std::endl;
} }
out_ << "struct " << program_->SymbolToName(str->symbol()) << " {" out_ << "struct " << program_->Symbols().NameFor(str->symbol()) << " {"
<< std::endl; << std::endl;
increment_indent(); increment_indent();
@ -564,7 +564,7 @@ bool GeneratorImpl::EmitStructType(const type::Struct* str) {
out_ << "[[offset(" << offset->offset() << ")]]" << std::endl; out_ << "[[offset(" << offset->offset() << ")]]" << std::endl;
} }
make_indent(); make_indent();
out_ << program_->SymbolToName(mem->symbol()) << " : "; out_ << program_->Symbols().NameFor(mem->symbol()) << " : ";
if (!EmitType(mem->type())) { if (!EmitType(mem->type())) {
return false; return false;
} }
@ -594,7 +594,7 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) {
} }
} }
out_ << " " << program_->SymbolToName(var->symbol()) << " : "; out_ << " " << program_->Symbols().NameFor(var->symbol()) << " : ";
if (!EmitType(var->type())) { if (!EmitType(var->type())) {
return false; return false;
} }