]> git.tdb.fi Git - libs/gl.git/commitdiff
Check if blocks need braces at formatting time
authorMikko Rasa <tdb@tdb.fi>
Mon, 14 Nov 2016 11:39:50 +0000 (13:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 14 Nov 2016 11:45:22 +0000 (13:45 +0200)
source/programcompiler.cpp

index 2428ab796e4756ea171cd026d2954a49b505c35b..a730f74348f072fab4edd1398835b380b4295af4 100644 (file)
@@ -245,7 +245,8 @@ void ProgramCompiler::Formatter::visit(Block &block)
                --else_if;
 
        unsigned brace_indent = indent;
-       if(block.use_braces)
+       bool use_braces = (block.use_braces || (indent && block.body.size()!=1));
+       if(use_braces)
                formatted += format("%s{\n", string(brace_indent*2, ' '));
 
        SetForScope<unsigned> set(indent, indent+!formatted.empty());
@@ -259,7 +260,7 @@ void ProgramCompiler::Formatter::visit(Block &block)
                else_if = 0;
        }
 
-       if(block.use_braces)
+       if(use_braces)
                formatted += format("\n%s}", string(brace_indent*2, ' '));
 }