Pretty print if/else/elseif chains nicer, like this:

void printutf8(unsigned int X) {
  if (X <= 127)
    printf("%c", (char)X);
  else if (X <= 2047)
    printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
  else if (X <= 65535)
    printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
  else
    printf("UNKNOWN %d\n", X);

instead of:

  if (X <= 127)
    printf("%c", (char)X);
  else
    if (X <= 2047)
      printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
    else
      if (X <= 65535)
        printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
      else
        printf("UNKNOWN %d\n", X);

llvm-svn: 39648
This commit is contained in:
Chris Lattner 2007-06-11 22:26:23 +00:00
parent d4a20ad752
commit c0a38dd38f
1 changed files with 13 additions and 4 deletions

View File

@ -48,7 +48,8 @@ namespace {
void PrintRawCompoundStmt(CompoundStmt *S);
void PrintRawDecl(Decl *D);
void PrintRawIfStmt(IfStmt *If);
void PrintExpr(Expr *E) {
if (E)
E->visit(*this);
@ -159,8 +160,8 @@ void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
PrintStmt(Node->getSubStmt(), 0);
}
void StmtPrinter::VisitIfStmt(IfStmt *If) {
Indent() << "if ";
void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
OS << "if ";
PrintExpr(If->getCond());
if (CompoundStmt *CS = dyn_cast<CompoundStmt>(If->getThen())) {
@ -172,7 +173,7 @@ void StmtPrinter::VisitIfStmt(IfStmt *If) {
PrintStmt(If->getThen());
if (If->getElse()) Indent();
}
if (Stmt *Else = If->getElse()) {
OS << "else";
@ -180,6 +181,9 @@ void StmtPrinter::VisitIfStmt(IfStmt *If) {
OS << ' ';
PrintRawCompoundStmt(CS);
OS << '\n';
} else if (IfStmt *ElseIf = dyn_cast<IfStmt>(Else)) {
OS << ' ';
PrintRawIfStmt(ElseIf);
} else {
OS << '\n';
PrintStmt(If->getElse());
@ -187,6 +191,11 @@ void StmtPrinter::VisitIfStmt(IfStmt *If) {
}
}
void StmtPrinter::VisitIfStmt(IfStmt *If) {
Indent();
PrintRawIfStmt(If);
}
void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
Indent() << "switch (";
PrintExpr(Node->getCond());