From: Mikko Rasa Date: Mon, 14 Nov 2016 11:39:50 +0000 (+0200) Subject: Check if blocks need braces at formatting time X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f9b23e69b63cbbeed8eeb605c0dc491002a4c23b;p=libs%2Fgl.git Check if blocks need braces at formatting time --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 2428ab79..a730f743 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -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 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, ' ')); }