]> granicus.if.org Git - clang/commitdiff
pretty print some nodes more nicely.
authorChris Lattner <sabre@nondot.org>
Sat, 15 Sep 2007 21:49:37 +0000 (21:49 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 15 Sep 2007 21:49:37 +0000 (21:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41989 91177308-0d34-0410-b5e6-96231b3b80d8

AST/StmtPrinter.cpp

index 44a04f6230c0307159c9192f25e5bb6d4acb77d1..9e8f3e9b202bc637f52cd9e047b861e29178fbf3 100644 (file)
@@ -243,9 +243,17 @@ void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
 }
 
 void StmtPrinter::VisitDoStmt(DoStmt *Node) {
-  Indent() << "do\n";
-  PrintStmt(Node->getBody());
-  Indent() << "while ";
+  Indent() << "do ";
+  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
+    PrintRawCompoundStmt(CS);
+    OS << " ";
+  } else {
+    OS << "\n";
+    PrintStmt(Node->getBody());
+    Indent();
+  }
+  
+  OS << "while ";
   PrintExpr(Node->getCond());
   OS << ";\n";
 }
@@ -258,14 +266,25 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) {
     else
       PrintExpr(cast<Expr>(Node->getInit()));
   }
-  OS << "; ";
-  if (Node->getCond())
+  OS << ";";
+  if (Node->getCond()) {
+    OS << " ";
     PrintExpr(Node->getCond());
-  OS << "; ";
-  if (Node->getInc())
+  }
+  OS << ";";
+  if (Node->getInc()) {
+    OS << " ";
     PrintExpr(Node->getInc());
-  OS << ")\n";
-  PrintStmt(Node->getBody());
+  }
+  OS << ") ";
+  
+  if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Node->getBody())) {
+    PrintRawCompoundStmt(CS);
+    OS << "\n";
+  } else {
+    OS << "\n";
+    PrintStmt(Node->getBody());
+  }
 }
 
 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {