@@ -541,10 +541,7 @@ object FastPrettyPrinter extends FastPrettyPrinterBase with BracketPrettyPrinter
541541 case None =>
542542 nil
543543 case Some (actualBody) =>
544- braces(nest(defaultIndent,
545- lineIfSomeNonEmpty(actualBody.children) <>
546- ssep(Seq (showStmt(actualBody)), line)
547- ) <> line)
544+ showBlock(actualBody)
548545 })
549546 case Predicate (name, formalArgs, body) =>
550547 text(" predicate" ) <+> name <> nest(defaultIndent, parens(showVars(formalArgs))) <+> (body match {
@@ -634,11 +631,20 @@ object FastPrettyPrinter extends FastPrettyPrinterBase with BracketPrettyPrinter
634631 }
635632
636633 /** Show some node inside square braces (with nesting). */
637- def showBlock (stmt : Stmt ): Cont = {
638- braces(nest(defaultIndent,
639- lineIfSomeNonEmpty(stmt match {case s : Seqn => s.scopedDecls; case _ => Seq ()}, stmt.children) <>
640- showStmt(stmt)
641- ) <> line)
634+ def showBlock (stmt : Stmt ): Cont = stmt match {
635+ case Seqn (stmts, scopedDecls) =>
636+ val locals = scopedDecls.collect { case l : LocalVarDecl => l }
637+ val nonEmptyStmts = stmts.filter {
638+ case s@ Seqn (ss, sd) => ss.nonEmpty || sd.nonEmpty || s.info.comment.nonEmpty
639+ case _ => true
640+ }
641+ braces(nest(defaultIndent,
642+ lineIfSomeNonEmpty(scopedDecls, nonEmptyStmts) <>
643+ ssep((locals map (text(" var" ) <+> showVar(_))) ++ (nonEmptyStmts map show), line)) <> line)
644+ case s =>
645+ braces(nest(defaultIndent,
646+ line <> showStmt(s)
647+ ))
642648 }
643649
644650 /** Show a statement. */
@@ -662,6 +668,19 @@ object FastPrettyPrinter extends FastPrettyPrinterBase with BracketPrettyPrinter
662668 case Nil => call
663669 case _ => ssep(targets map show, char(',' ) <> space) <+> " :=" <+> call
664670 }
671+ case Seqn (stmts, scopedDecls) if scopedDecls.nonEmpty =>
672+ val locals = scopedDecls.collect {case l : LocalVarDecl => l}
673+ val nonEmptyStmts = stmts.filter{
674+ case s@ Seqn (ss, sd) => ss.nonEmpty || sd.nonEmpty || s.info.comment.nonEmpty
675+ case _ => true
676+ }
677+ if (stmts.isEmpty && locals.isEmpty)
678+ nil
679+ else {
680+ braces(nest(defaultIndent,
681+ lineIfSomeNonEmpty(scopedDecls, stmts) <>
682+ ssep((locals map (text(" var" ) <+> showVar(_))) ++ (nonEmptyStmts map show), line)) <> line)
683+ }
665684 case seqn@ Seqn (stmts, scopedDecls) =>
666685 val locals = scopedDecls.collect {case l : LocalVarDecl => l}
667686 if (stmts.isEmpty && locals.isEmpty && seqn.info.comment.isEmpty)
@@ -677,10 +696,7 @@ object FastPrettyPrinter extends FastPrettyPrinterBase with BracketPrettyPrinter
677696 nest(defaultIndent,
678697 showContracts(" invariant" , invs)
679698 ) <+> lineIfSomeNonEmpty(invs) <>
680- braces(nest(defaultIndent,
681- lineIfSomeNonEmpty(body.scopedDecls, body.children) <>
682- ssep(Seq (showStmt(body)), line)
683- ) <> line)
699+ showBlock(body)
684700 case If (cond, thn, els) =>
685701 text(" if" ) <+> parens(show(cond)) <+> showBlock(thn) <> showElse(els)
686702 case Label (name, invs) =>
0 commit comments