X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fsyntax.cpp;h=c94e2e27042c63a6a7f0b2c91f3d26c5b00f1e30;hb=0388083;hp=bbd364c0730d7cca157376ad34bbdbd028ec1581;hpb=911c6c4acc8218bc40d93917207f9dc32e9f2596;p=libs%2Fgl.git diff --git a/source/glsl/syntax.cpp b/source/glsl/syntax.cpp index bbd364c0..c94e2e27 100644 --- a/source/glsl/syntax.cpp +++ b/source/glsl/syntax.cpp @@ -105,12 +105,6 @@ void Literal::visit(NodeVisitor &visitor) } -void ParenthesizedExpression::visit(NodeVisitor &visitor) -{ - visitor.visit(*this); -} - - VariableReference::VariableReference(): declaration(0) { } @@ -470,6 +464,41 @@ Module::Module(): shared(Stage::SHARED) { } + +string get_unused_variable_name(const Block &block, const string &base, const string &prefix_hint) +{ + string name = base; + + bool prefixed = false; + unsigned number = 1; + unsigned size_without_number = 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; + + if(!prefixed && !prefix_hint.empty()) + { + if(name.front()!='_') + name = "_"+name; + name = prefix_hint+name; + if(name.front()!='_') + name = "_"+name; + prefixed = true; + size_without_number = name.size(); + } + else + { + name.erase(size_without_number); + name += format("_%d", number); + ++number; + } + } +} + } // namespace SL } // namespace GL } // namespace Msp