[cfe-commits] r39114 - /cfe/cfe/trunk/AST/StmtPrinter.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:27:39 PDT 2007


Author: sabre
Date: Wed Jul 11 11:27:39 2007
New Revision: 39114

URL: http://llvm.org/viewvc/llvm-project?rev=39114&view=rev
Log:
pretty print strings more nicely

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=39114&r1=39113&r2=39114&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/cfe/trunk/AST/StmtPrinter.cpp Wed Jul 11 11:27:39 2007
@@ -178,7 +178,22 @@
 }
 void StmtPrinter::VisitStringExpr(StringExpr *Str) {
   if (Str->isWide()) OS << 'L';
-  OS << '"' << Str->getStrData() << '"';
+  OS << '"';
+  
+  // FIXME: this doesn't print wstrings right.
+  for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
+    switch (Str->getStrData()[i]) {
+    default: OS << Str->getStrData()[i]; break;
+    // Handle some common ones to make dumps prettier.
+    case '\\': OS << "\\\\"; break;
+    case '"': OS << "\\\""; break;
+    case '\n': OS << "\\n"; break;
+    case '\t': OS << "\\t"; break;
+    case '\a': OS << "\\a"; break;
+    case '\b': OS << "\\b"; break;
+    }
+  }
+  OS << '"';
 }
 void StmtPrinter::VisitParenExpr(ParenExpr *Node) {
   OS << "(";





More information about the cfe-commits mailing list