From f63d56a13b381115c340afee17982e7fcb50cf60 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <qtc-committer@nokia.com> Date: Wed, 7 Jan 2009 10:42:43 +0100 Subject: [PATCH] Nicer pretty printing of while statements. --- shared/cplusplus/PrettyPrinter.cpp | 11 ++++++++++- tests/manual/cplusplus/tests/t1.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/shared/cplusplus/PrettyPrinter.cpp b/shared/cplusplus/PrettyPrinter.cpp index d7570127e32..6fcd06de380 100644 --- a/shared/cplusplus/PrettyPrinter.cpp +++ b/shared/cplusplus/PrettyPrinter.cpp @@ -1229,7 +1229,16 @@ bool PrettyPrinter::visit(WhileStatementAST *ast) out << '('; accept(ast->condition); out << ')'; - accept(ast->statement); + out << ' '; + if (ast->statement && ast->statement->asCompoundStatement()) + accept(ast->statement); + else { + indent(); + newline(); + accept(ast->statement); + deindent(); + newline(); + } return false; } diff --git a/tests/manual/cplusplus/tests/t1.cpp b/tests/manual/cplusplus/tests/t1.cpp index 186d9fbea7c..0151673c70b 100644 --- a/tests/manual/cplusplus/tests/t1.cpp +++ b/tests/manual/cplusplus/tests/t1.cpp @@ -20,6 +20,16 @@ class Class { else if (b == 20) return 2; else if (c == 30) { x = 1; } } + + void test_while() { + while (int a = 1) { + exit(); + } + + while (x==1) do_something_here(); + + while (x==2) if(a==1) c(); else if (a==2) c(); else c3(); + } }; class Derived: public Class { -- GitLab