]> git.tdb.fi Git - libs/gl.git/commitdiff
Change the naming scheme for the interface block map
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 11:08:21 +0000 (14:08 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Apr 2021 11:08:21 +0000 (14:08 +0300)
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.

source/glsl/generate.cpp
source/glsl/resolve.cpp
source/glsl/validate.cpp
source/glsl/visitor.cpp

index 3387667283b425c4f9fdb74245b1da577c2b9d5b..4550b51c29360997e12c728208cb7c1decca0ba5 100644 (file)
@@ -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<Block *> set_block(current_block, &stage->content);
@@ -215,7 +215,7 @@ void InterfaceGenerator::visit(VariableReference &var)
        }
 
        const map<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
-       map<string, InterfaceBlock *>::const_iterator j = prev_blocks.find("_"+var.name);
+       map<string, InterfaceBlock *>::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<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
-                       map<string, InterfaceBlock *>::const_iterator i = prev_blocks.find("out"+iface.block_name);
+                       map<string, InterfaceBlock *>::const_iterator i = prev_blocks.find("out "+iface.block_name);
                        if(i!=prev_blocks.end())
                        {
                                iface.linked_block = i->second;
index 02f224d66b4453d2469a2638e0ab0453d2cd6c4a..8bfe635ee73b8d2f3c0dd1bd9dd7414313117263 100644 (file)
@@ -225,7 +225,7 @@ void VariableResolver::visit(VariableReference &var)
        if(!declaration)
        {
                const map<string, InterfaceBlock *> &blocks = stage->interface_blocks;
-               map<string, InterfaceBlock *>::const_iterator i = blocks.find("_"+var.name);
+               map<string, InterfaceBlock *>::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<string, InterfaceBlock *>::iterator i = stage->interface_blocks.find("_"+iface.name);
+       map<string, InterfaceBlock *>::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);
 }
index b313354dc9c54d56688fe7d7b32b24f8328bcbfc..6ce2ee51400df1668f769c2bc4a086cf61c376f3 100644 (file)
@@ -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<string, InterfaceBlock *>::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);
index 808bcfa52dfc3757e70ea16ba4ec1fe451b75fe8..3e480484c33dd6e12ad1ac8bad61801ba01b94c4 100644 (file)
@@ -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);