From: Mikko Rasa Date: Mon, 5 Apr 2021 11:08:21 +0000 (+0300) Subject: Change the naming scheme for the interface block map X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3773733011653d67e47768cf031e95f8f68cf714;p=libs%2Fgl.git Change the naming scheme for the interface block map Adding a space in the keys for block name makes it impossible for them to conflict with identifiers and allows instance names to be used directly. --- diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 33876672..4550b51c 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -134,7 +134,7 @@ VariableDeclaration *InterfaceGenerator::generate_interface(VariableDeclaration InterfaceBlock *InterfaceGenerator::generate_interface(InterfaceBlock &out_block) { - if(stage->interface_blocks.count("in"+out_block.block_name)) + if(stage->interface_blocks.count("in "+out_block.block_name)) return 0; InterfaceBlock *in_block = new InterfaceBlock; @@ -160,9 +160,9 @@ InterfaceBlock *InterfaceGenerator::generate_interface(InterfaceBlock &out_block } iface_target_block->body.insert(iface_insert_point, in_block); - stage->interface_blocks.insert(make_pair("in"+in_block->block_name, in_block)); + stage->interface_blocks.insert(make_pair("in "+in_block->block_name, in_block)); if(!in_block->instance_name.empty()) - stage->interface_blocks.insert(make_pair("_"+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); @@ -215,7 +215,7 @@ void InterfaceGenerator::visit(VariableReference &var) } const map &prev_blocks = stage->previous->interface_blocks; - map::const_iterator j = prev_blocks.find("_"+var.name); + map::const_iterator j = prev_blocks.find(var.name); if(j!=prev_blocks.end() && j->second->interface=="out") { generate_interface(*j->second); @@ -291,7 +291,7 @@ void InterfaceGenerator::visit(InterfaceBlock &iface) if(!iface.linked_block && stage->previous) { const map &prev_blocks = stage->previous->interface_blocks; - map::const_iterator i = prev_blocks.find("out"+iface.block_name); + map::const_iterator i = prev_blocks.find("out "+iface.block_name); if(i!=prev_blocks.end()) { iface.linked_block = i->second; diff --git a/source/glsl/resolve.cpp b/source/glsl/resolve.cpp index 02f224d6..8bfe635e 100644 --- a/source/glsl/resolve.cpp +++ b/source/glsl/resolve.cpp @@ -225,7 +225,7 @@ void VariableResolver::visit(VariableReference &var) if(!declaration) { const map &blocks = stage->interface_blocks; - map::const_iterator i = blocks.find("_"+var.name); + map::const_iterator i = blocks.find(var.name); if(i!=blocks.end()) { /* The name refers to an interface block with an instance name rather @@ -259,7 +259,7 @@ void VariableResolver::visit(VariableReference &var) void VariableResolver::visit(InterfaceBlockReference &iface) { - map::iterator i = stage->interface_blocks.find("_"+iface.name); + map::iterator i = stage->interface_blocks.find(iface.name); InterfaceBlock *declaration = (i!=stage->interface_blocks.end() ? i->second : 0); r_any_resolved |= (declaration!=iface.declaration); iface.declaration = declaration; @@ -430,9 +430,9 @@ void VariableResolver::visit(InterfaceBlock &iface) { /* Block names can be reused in different interfaces. Prefix the name with the first character of the interface to avoid conflicts. */ - stage->interface_blocks.insert(make_pair(iface.interface+iface.block_name, &iface)); + stage->interface_blocks.insert(make_pair(format("%s %s", iface.interface, iface.block_name), &iface)); if(!iface.instance_name.empty()) - stage->interface_blocks.insert(make_pair("_"+iface.instance_name, &iface)); + stage->interface_blocks.insert(make_pair(iface.instance_name, &iface)); TraversingVisitor::visit(iface); } diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index b313354d..6ce2ee51 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -353,7 +353,7 @@ void IdentifierValidator::visit(VariableDeclaration &var) void IdentifierValidator::visit(InterfaceBlock &iface) { - string key = iface.interface+iface.block_name; + string key = format("%s %s", iface.interface, iface.block_name); map::const_iterator i = interface_blocks.find(key); if(i!=interface_blocks.end()) multiple_definition(format("interface block '%s %s'", iface.interface, iface.block_name), iface, *i->second); diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index 808bcfa5..3e480484 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -193,9 +193,9 @@ void NodeRemover::visit(InterfaceBlock &iface) { if(to_remove->count(&iface)) { - remove_from_map(stage->interface_blocks, iface.interface+iface.block_name, iface); + remove_from_map(stage->interface_blocks, format("%s %s", iface.interface, iface.block_name), iface); if(!iface.instance_name.empty()) - remove_from_map(stage->interface_blocks, "_"+iface.instance_name, iface); + remove_from_map(stage->interface_blocks, iface.instance_name, iface); } SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface)); TraversingVisitor::visit(iface);