From 0030f87e9c8e2a2cf529ffebac94ebb2fc72bf44 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <qtc-committer@nokia.com>
Date: Wed, 7 Jan 2009 10:33:19 +0100
Subject: [PATCH] Improved the pretty printing of enum specifiers and if-else
 statements.

---
 shared/cplusplus/PrettyPrinter.cpp  | 22 ++++++++++++++++------
 tests/manual/cplusplus/tests/t1.cpp | 10 +++++++++-
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/shared/cplusplus/PrettyPrinter.cpp b/shared/cplusplus/PrettyPrinter.cpp
index 8a8b43bb37b..4adc69e78c3 100644
--- a/shared/cplusplus/PrettyPrinter.cpp
+++ b/shared/cplusplus/PrettyPrinter.cpp
@@ -453,11 +453,20 @@ bool PrettyPrinter::visit(EnumSpecifierAST *ast)
         out << ' ';
         accept(ast->name);
     }
+    out << ' ';
     out << '{';
-    for (EnumeratorAST *it = ast->enumerators; it; it = it->next) {
-        accept(it);
-        if (it->next)
-            out << ", ";
+    if (ast->enumerators) {
+        indent();
+        newline();
+        for (EnumeratorAST *it = ast->enumerators; it; it = it->next) {
+            accept(it);
+            if (it->next) {
+                out << ", ";
+                newline();
+            }
+        }
+        deindent();
+        newline();
     }
     out << '}';
     return false;
@@ -599,9 +608,10 @@ bool PrettyPrinter::visit(IfStatementAST *ast)
     out << '(';
     accept(ast->condition);
     out << ')';
-    if (ast->statement->asCompoundStatement())
+    if (ast->statement->asCompoundStatement()) {
+        out << ' ';
         accept(ast->statement);
-    else {
+    } else {
         indent();
         newline();
         accept(ast->statement);
diff --git a/tests/manual/cplusplus/tests/t1.cpp b/tests/manual/cplusplus/tests/t1.cpp
index 362146fc19b..75c4666d55b 100644
--- a/tests/manual/cplusplus/tests/t1.cpp
+++ b/tests/manual/cplusplus/tests/t1.cpp
@@ -2,7 +2,9 @@
 class Class {
   int a, b;
 
-  enum zoo { a, b };
+  enum zoo { a = 1, b = a + 2 + x::y<10>::value };
+
+  enum {};
 
   typedef enum { k };
 
@@ -12,5 +14,11 @@ class Class {
   void another_foo() {
     int a = static_cast<int>(1+2/3*4-5%6+(7&8));
   }
+
+  void test_if() {
+    if (a == 10) return 1;
+    else if (b == 20) return 2;
+    else if (c == 30) { x = 1; }
+  }
 };
 
-- 
GitLab