From: Ted Kremenek Date: Wed, 11 Dec 2013 23:44:02 +0000 (+0000) Subject: Add new PrintingPolicy entry to trim number of newlines. Useful for the CFG printer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b9a904f1f0471aa9132bc1a0dcf6980a0ce50d26;p=clang Add new PrintingPolicy entry to trim number of newlines. Useful for the CFG printer. 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 --- diff --git a/include/clang/AST/PrettyPrinter.h b/include/clang/AST/PrettyPrinter.h index 76426991cf..37a4df7250 100644 --- a/include/clang/AST/PrettyPrinter.h +++ b/include/clang/AST/PrettyPrinter.h @@ -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 diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 0016b25f2f..abbc3d89aa 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -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) {