]> git.tdb.fi Git - libs/gl.git/commitdiff
Use insert instead of [] to retain the first item with the same name
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 13:39:08 +0000 (15:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 15:46:41 +0000 (17:46 +0200)
source/glsl/generate.cpp
source/glsl/validate.cpp

index 71b35b2c59f3ef8217db37d32b93123da763d047..0a469a46e1dd79b07ad73b82d594e41c11fd5749 100644 (file)
@@ -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<string> 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<Block *> set_block(current_block, &stage->content);
index 6368c069244629217b32f04bb78987d3784f39b7..3d2015bde3ffaae7b1d086d5be502b430c3cc5ed 100644 (file)
@@ -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)