[cfe-commits] r40964 - /cfe/trunk/AST/StmtDumper.cpp

Chris Lattner sabre at nondot.org
Thu Aug 9 10:14:24 PDT 2007


Author: lattner
Date: Thu Aug  9 12:14:24 2007
New Revision: 40964

URL: http://llvm.org/viewvc/llvm-project?rev=40964&view=rev
Log:
dump strings with escapes and other stuff in them nicely.

Modified:
    cfe/trunk/AST/StmtDumper.cpp

Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=40964&r1=40963&r2=40964&view=diff

==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Thu Aug  9 12:14:24 2007
@@ -327,27 +327,26 @@
 void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
   DumpExpr(Str);
   // FIXME: this doesn't print wstrings right.
-  // FIXME: this doesn't print strings with \0's in them.
-  fprintf(F, " \"%s\")", Str->getStrData());
+  fprintf(F, " %s\"", Str->isWide() ? "L" : "");
 
-#if 0
-  if (Str->isWide()) OS << 'L';
-  OS << '"';
-  
   for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
-    switch (Str->getStrData()[i]) {
-    default: OS << Str->getStrData()[i]; break;
+    switch (char C = Str->getStrData()[i]) {
+    default:
+      if (isprint(C))
+        fputc(C, F); 
+      else
+        fprintf(F, "\\%03o", C);
+      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;
+    case '\\': fprintf(F, "\\\\"); break;
+    case '"':  fprintf(F, "\\\""); break;
+    case '\n': fprintf(F, "\\n"); break;
+    case '\t': fprintf(F, "\\t"); break;
+    case '\a': fprintf(F, "\\a"); break;
+    case '\b': fprintf(F, "\\b"); break;
     }
   }
-  OS << '"';
-#endif
+  fprintf(F, "\")");
 }
 void StmtDumper::VisitParenExpr(ParenExpr *Node) {
   DumpExpr(Node);





More information about the cfe-commits mailing list