[cfe-commits] r39846 - in /cfe/trunk: AST/StmtPrinter.cpp test/Parser/char-literal-printing.c
Chris Lattner
sabre at nondot.org
Fri Jul 13 16:58:20 PDT 2007
Author: lattner
Date: Fri Jul 13 18:58:20 2007
New Revision: 39846
URL: http://llvm.org/viewvc/llvm-project?rev=39846&view=rev
Log:
Improve char literal pretty printing, patch by Keith Bauer!
Added:
cfe/trunk/test/Parser/char-literal-printing.c
Modified:
cfe/trunk/AST/StmtPrinter.cpp
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=39846&r1=39845&r2=39846&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Fri Jul 13 18:58:20 2007
@@ -292,13 +292,50 @@
}
void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) {
+ // FIXME should print an L for wchar_t constants
unsigned value = Node->getValue();
- if (isprint(value)) {
- OS << "'" << (char)value << "'";
- } else {
- // FIXME something to indicate this is a character literal?
- OS << std::hex << std::setiosflags(std::ios_base::showbase) << value
- << std::dec << std::resetiosflags(std::ios_base::showbase);
+ switch (value) {
+ case '\\':
+ OS << "'\\\\'";
+ break;
+ case '\'':
+ OS << "'\\''";
+ break;
+ case '\a':
+ // TODO: K&R: the meaning of '\\a' is different in traditional C
+ OS << "'\\a'";
+ break;
+ case '\b':
+ OS << "'\\b'";
+ break;
+ // Nonstandard escape sequence.
+ /*case '\e':
+ OS << "'\\e'";
+ break;*/
+ case '\f':
+ OS << "'\\f'";
+ break;
+ case '\n':
+ OS << "'\\n'";
+ break;
+ case '\r':
+ OS << "'\\r'";
+ break;
+ case '\t':
+ OS << "'\\t'";
+ break;
+ case '\v':
+ OS << "'\\v'";
+ break;
+ default:
+ if (isprint(value) && value < 256) {
+ OS << "'" << (char)value << "'";
+ } else if (value < 256) {
+ OS << "'\\x" << std::hex << value << std::dec << "'";
+ } else {
+ // FIXME what to really do here?
+ OS << value;
+ }
}
}
Added: cfe/trunk/test/Parser/char-literal-printing.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/char-literal-printing.c?rev=39846&view=auto
==============================================================================
--- cfe/trunk/test/Parser/char-literal-printing.c (added)
+++ cfe/trunk/test/Parser/char-literal-printing.c Fri Jul 13 18:58:20 2007
@@ -0,0 +1,31 @@
+// RUN: clang -parse-ast-print %s 2>&1 | clang -parse-ast-print
+
+#include <stddef.h>
+
+char test1(void) { return '\\'; }
+wchar_t test2(void) { return L'\\'; }
+char test3(void) { return '\''; }
+wchar_t test4(void) { return L'\''; }
+char test5(void) { return '\a'; }
+wchar_t test6(void) { return L'\a'; }
+char test7(void) { return '\b'; }
+wchar_t test8(void) { return L'\b'; }
+char test9(void) { return '\e'; }
+wchar_t test10(void) { return L'\e'; }
+char test11(void) { return '\f'; }
+wchar_t test12(void) { return L'\f'; }
+char test13(void) { return '\n'; }
+wchar_t test14(void) { return L'\n'; }
+char test15(void) { return '\r'; }
+wchar_t test16(void) { return L'\r'; }
+char test17(void) { return '\t'; }
+wchar_t test18(void) { return L'\t'; }
+char test19(void) { return '\v'; }
+wchar_t test20(void) { return L'\v'; }
+
+char test21(void) { return 'c'; }
+wchar_t test22(void) { return L'c'; }
+char test23(void) { return '\x3'; }
+wchar_t test24(void) { return L'\x3'; }
+
+wchar_t test25(void) { return L'\x333'; }
More information about the cfe-commits
mailing list