X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Foutput.cpp;h=72af837958e77a712196b97cc9279258e8c08555;hp=7d502739903a6cd8708cfc758aac470cad2fa17f;hb=2989fc60f0fd98282962a0105bcba055193e2f8c;hpb=d1da983b2ddfd221ef4348d2c40736264670c2b5 diff --git a/source/glsl/output.cpp b/source/glsl/output.cpp index 7d502739..72af8379 100644 --- a/source/glsl/output.cpp +++ b/source/glsl/output.cpp @@ -82,6 +82,32 @@ void Formatter::set_source(unsigned index, unsigned line) source_line = line; } +void Formatter::visit(Block &block) +{ + unsigned brace_indent = indent; + bool use_braces = (block.use_braces || (indent && block.body.size()!=1)); + if(use_braces) + append(format("%s{\n", string(brace_indent*2, ' '))); + + SetForScope set(indent, indent+(indent>0 || use_braces)); + string spaces(indent*2, ' '); + bool first = true; + for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ++i) + { + if((*i)->source==BUILTIN_SOURCE) + continue; + if(!first) + append('\n'); + first = false; + set_source((*i)->source, (*i)->line); + append(spaces); + (*i)->visit(*this); + } + + if(use_braces) + append(format("\n%s}", string(brace_indent*2, ' '))); +} + void Formatter::visit(Literal &literal) { append(literal.token); @@ -153,32 +179,6 @@ void Formatter::visit(ExpressionStatement &expr) append(';'); } -void Formatter::visit(Block &block) -{ - unsigned brace_indent = indent; - bool use_braces = (block.use_braces || (indent && block.body.size()!=1)); - if(use_braces) - append(format("%s{\n", string(brace_indent*2, ' '))); - - SetForScope set(indent, indent+(indent>0 || use_braces)); - string spaces(indent*2, ' '); - bool first = true; - for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ++i) - { - if((*i)->source==BUILTIN_SOURCE) - continue; - if(!first) - append('\n'); - first = false; - set_source((*i)->source, (*i)->line); - append(spaces); - (*i)->visit(*this); - } - - if(use_braces) - append(format("\n%s}", string(brace_indent*2, ' '))); -} - void Formatter::visit(Import &import) { append(format("import %s;", import.module));