[cfe-commits] r39468 - /cfe/cfe/trunk/AST/StmtPrinter.cpp
clattner at cs.uiuc.edu
clattner at cs.uiuc.edu
Wed Jul 11 09:44:44 PDT 2007
Author: clattner
Date: Wed Jul 11 11:44:44 2007
New Revision: 39468
URL: http://llvm.org/viewvc/llvm-project?rev=39468&view=rev
Log:
Pretty print labels and case stmts better. This leads to output like this:
void foo() {
abc:
def:
hij:
case 1:
case 1:
goto abc
baz:
goto def
}
instead of:
void foo() {
abc:
def:
hij:
case 1:
case 1:
goto abc
baz:
goto def
}
Modified:
cfe/cfe/trunk/AST/StmtPrinter.cpp
Modified: cfe/cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/StmtPrinter.cpp?rev=39468&r1=39467&r2=39468&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:44:44 2007
@@ -49,8 +49,8 @@
public:
StmtPrinter(std::ostream &os) : OS(os), IndentLevel(0) {}
- void PrintStmt(Stmt *S) {
- ++IndentLevel;
+ void PrintStmt(Stmt *S, int SubIndent = 1) {
+ IndentLevel += SubIndent;
if (S && isExpr(S)) {
// If this is an expr used in a stmt context, indent and newline it.
Indent();
@@ -61,7 +61,7 @@
} else {
Indent() << ";\n";
}
- --IndentLevel;
+ IndentLevel -= SubIndent;
}
void PrintExpr(Expr *E) {
@@ -71,8 +71,8 @@
OS << "<null expr>";
}
- std::ostream &Indent() const {
- for (unsigned i = 0, e = IndentLevel; i != e; ++i)
+ std::ostream &Indent(int Delta = 0) const {
+ for (unsigned i = 0, e = IndentLevel+Delta; i != e; ++i)
OS << " ";
return OS;
}
@@ -103,7 +103,7 @@
}
void StmtPrinter::VisitCaseStmt(CaseStmt *Node) {
- Indent() << "case ";
+ Indent(-1) << "case ";
PrintExpr(Node->getLHS());
if (Node->getRHS()) {
OS << " ... ";
@@ -111,20 +111,17 @@
}
OS << ":\n";
- // FIXME: This recursively indents consequtive cases.
- PrintStmt(Node->getSubStmt());
+ PrintStmt(Node->getSubStmt(), 0);
}
void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) {
- Indent() << "default:\n";
- // FIXME: This recursively indents consequtive cases.
- PrintStmt(Node->getSubStmt());
+ Indent(-1) << "default:\n";
+ PrintStmt(Node->getSubStmt(), 0);
}
void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
- Indent() << Node->getLabel()->getName() << ":\n";
- // FIXME: This recursively indents consequtive cases.
- PrintStmt(Node->getSubStmt());
+ Indent(-1) << Node->getLabel()->getName() << ":\n";
+ PrintStmt(Node->getSubStmt(), 0);
}
void StmtPrinter::VisitIfStmt(IfStmt *If) {
More information about the cfe-commits
mailing list