]> granicus.if.org Git - clang/commitdiff
Add new PrintingPolicy entry to trim number of newlines. Useful for the CFG printer.
authorTed Kremenek <kremenek@apple.com>
Wed, 11 Dec 2013 23:44:02 +0000 (23:44 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 11 Dec 2013 23:44:02 +0000 (23:44 +0000)
The change isn't completely comprehensive.  This can be filled in
lazily as needed.  There is one consumer right now.

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

include/clang/AST/PrettyPrinter.h
lib/AST/StmtPrinter.cpp

index 76426991cf47b5a410f629bfe1c9dc78949ba56b..37a4df7250c06074aac72f7fb1db3b1fcb24bee2 100644 (file)
@@ -41,7 +41,8 @@ struct PrintingPolicy {
       ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
       SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
       Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
-      MSWChar(LO.MicrosoftExt && !LO.WChar) { }
+      MSWChar(LO.MicrosoftExt && !LO.WChar),
+      IncludeNewlines(true) { }
 
   /// \brief What language we're printing.
   LangOptions LangOpts;
@@ -155,6 +156,9 @@ struct PrintingPolicy {
   /// \brief When true, print the built-in wchar_t type as __wchar_t. For use in
   /// Microsoft mode when wchar_t is not available.
   unsigned MSWChar : 1;
+
+  /// \brief When true, include newlines after statements like "break", etc.
+  unsigned IncludeNewlines : 1;
 };
 
 } // end namespace clang
index 0016b25f2fa21537b45062ab6d528ede1c7881ee..abbc3d89aaa7c5d17a2007ce232e7fac566e5c0d 100644 (file)
@@ -330,7 +330,8 @@ void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) {
   PrintExpr(Node->getRangeInit());
   OS << ") {\n";
   PrintStmt(Node->getBody());
-  Indent() << "}\n";
+  Indent() << "}";
+  if (Policy.IncludeNewlines) OS << "\n";
 }
 
 void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
@@ -350,21 +351,25 @@ void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) {
 }
 
 void StmtPrinter::VisitGotoStmt(GotoStmt *Node) {
-  Indent() << "goto " << Node->getLabel()->getName() << ";\n";
+  Indent() << "goto " << Node->getLabel()->getName() << ";";
+  if (Policy.IncludeNewlines) OS << "\n";
 }
 
 void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) {
   Indent() << "goto *";
   PrintExpr(Node->getTarget());
-  OS << ";\n";
+  OS << ";";
+  if (Policy.IncludeNewlines) OS << "\n";
 }
 
 void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) {
-  Indent() << "continue;\n";
+  Indent() << "continue;";
+  if (Policy.IncludeNewlines) OS << "\n";
 }
 
 void StmtPrinter::VisitBreakStmt(BreakStmt *Node) {
-  Indent() << "break;\n";
+  Indent() << "break;";
+  if (Policy.IncludeNewlines) OS << "\n";
 }
 
 
@@ -374,7 +379,8 @@ void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
     OS << " ";
     PrintExpr(Node->getRetValue());
   }
-  OS << ";\n";
+  OS << ";";
+  if (Policy.IncludeNewlines) OS << "\n";
 }
 
 
@@ -437,7 +443,8 @@ void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) {
     VisitStringLiteral(Node->getClobberStringLiteral(i));
   }
 
-  OS << ");\n";
+  OS << ");";
+  if (Policy.IncludeNewlines) OS << "\n";
 }
 
 void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {