From fd2bdf8ea9ae87ddbfed0129f07e695671ab5b13 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 4 Mar 2021 15:39:08 +0200 Subject: [PATCH] Use insert instead of [] to retain the first item with the same name --- source/glsl/generate.cpp | 14 +++++++------- source/glsl/validate.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 71b35b2c..0a469a46 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -295,7 +295,7 @@ void VariableResolver::visit(FunctionCall &call) void VariableResolver::visit(StructDeclaration &strct) { TraversingVisitor::visit(strct); - stage->types[strct.name] = &strct; + stage->types.insert(make_pair(strct.name, &strct)); } void VariableResolver::visit(VariableDeclaration &var) @@ -308,16 +308,16 @@ void VariableResolver::visit(VariableDeclaration &var) var.interface = block_interface; TraversingVisitor::visit(var); - current_block->variables[var.name] = &var; + current_block->variables.insert(make_pair(var.name, &var)); } void VariableResolver::visit(InterfaceBlock &iface) { /* Block names can't be used for any other identifiers so we can put them in the same map with instance names. */ - stage->interface_blocks[iface.name] = &iface; + stage->interface_blocks.insert(make_pair(iface.name, &iface)); if(!iface.instance_name.empty()) - stage->interface_blocks[iface.instance_name] = &iface; + stage->interface_blocks.insert(make_pair(iface.instance_name, &iface)); SetForScope set_iface(block_interface, iface.interface); TraversingVisitor::visit(iface); @@ -443,7 +443,7 @@ VariableDeclaration *InterfaceGenerator::generate_interface(VariableDeclaration } iface_target_block->body.insert(iface_insert_point, iface_var); - iface_target_block->variables[name] = iface_var; + iface_target_block->variables.insert(make_pair(name, iface_var)); return iface_var; } @@ -472,9 +472,9 @@ InterfaceBlock *InterfaceGenerator::generate_interface(InterfaceBlock &out_block } iface_target_block->body.insert(iface_insert_point, in_block); - stage->interface_blocks[in_block->name] = in_block; + stage->interface_blocks.insert(make_pair(in_block->name, in_block)); if(!in_block->instance_name.empty()) - stage->interface_blocks[in_block->instance_name] = in_block; + stage->interface_blocks.insert(make_pair(in_block->instance_name, in_block)); SetFlag set_scope(function_scope, false); SetForScope set_block(current_block, &stage->content); diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 6368c069..3d2015bd 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -51,9 +51,9 @@ void DeclarationValidator::check_definition(const string &name, Statement &state return; } - declarations[current_block][name] = &statement; + declarations[current_block].insert(make_pair(name, &statement)); if(anonymous_block) - declarations[current_block->parent][name] = &statement; + declarations[current_block->parent].insert(make_pair(name, &statement)); } void DeclarationValidator::visit(VariableDeclaration &var) -- 2.45.2