]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/syntax.cpp
Adjust naming of generated variables
[libs/gl.git] / source / glsl / syntax.cpp
index bbd364c0730d7cca157376ad34bbdbd028ec1581..e7a3990e5c1478b3fcdf8e5727226b05ba688582 100644 (file)
@@ -105,12 +105,6 @@ void Literal::visit(NodeVisitor &visitor)
 }
 
 
-void ParenthesizedExpression::visit(NodeVisitor &visitor)
-{
-       visitor.visit(*this);
-}
-
-
 VariableReference::VariableReference():
        declaration(0)
 { }
@@ -470,6 +464,27 @@ Module::Module():
        shared(Stage::SHARED)
 { }
 
+
+string get_unused_variable_name(const Block &block, const string &base)
+{
+       string name = base;
+
+       unsigned number = 1;
+       unsigned base_size = name.size();
+       while(1)
+       {
+               bool unused = true;
+               for(const Block *b=█ (unused && b); b=b->parent)
+                       unused = !b->variables.count(name);
+               if(unused)
+                       return name;
+
+               name.erase(base_size);
+               name += format("_%d", number);
+               ++number;
+       }
+}
+
 } // namespace SL
 } // namespace GL
 } // namespace Msp