]> granicus.if.org Git - clang/commitdiff
A couple of tweaks to make -ast-print produce code that's closer to
authorEli Friedman <eli.friedman@gmail.com>
Sun, 17 May 2009 01:05:34 +0000 (01:05 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 17 May 2009 01:05:34 +0000 (01:05 +0000)
valid C code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71971 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/StmtPrinter.cpp
tools/clang-cc/ASTConsumers.cpp

index cf1a255236a2105081ccf4dc52fdfa49f0349b41..380634daf3bd491a33de7446f618f14b3fe004fe 100644 (file)
@@ -289,9 +289,9 @@ void StmtPrinter::VisitDoStmt(DoStmt *Node) {
     Indent();
   }
   
-  OS << "while ";
+  OS << "while (";
   PrintExpr(Node->getCond());
-  OS << ";\n";
+  OS << ");\n";
 }
 
 void StmtPrinter::VisitForStmt(ForStmt *Node) {
index d68b61cc3d54f41d9b4b316d5382e00231568cf1..48bf85b4dccab16a9fa5f241ef04cdb82fc10806 100644 (file)
@@ -141,19 +141,20 @@ void DeclPrinter:: PrintDecl(Decl *D) {
     if (const IdentifierInfo *II = TD->getIdentifier())
       Out << II->getName();
 
-    Out << " {\n";
-    ChangeIndent(1);
-    // FIXME: Shouldn't pass a NULL context
-    ASTContext *Context = 0;
-    for (DeclContext::decl_iterator i = TD->decls_begin(*Context);
-         i != TD->decls_end(*Context);
-         ++i)
-      PrintDecl(*i);    
-    ChangeIndent(-1);
-    Indent();
-    Out << "}";
-
-    Out << "\n";
+    if (TD->isDefinition()) {
+      Out << " {\n";
+      ChangeIndent(1);
+      // FIXME: Shouldn't pass a NULL context
+      ASTContext *Context = 0;
+      for (DeclContext::decl_iterator i = TD->decls_begin(*Context);
+           i != TD->decls_end(*Context);
+           ++i)
+        PrintDecl(*i);    
+      ChangeIndent(-1);
+      Indent();
+      Out << "}";
+    }
+    Out << ";\n";
   } else if (TemplateDecl *TempD = dyn_cast<TemplateDecl>(D)) {
     PrintTemplateDecl(TempD);
   } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {