зеркало из https://github.com/microsoft/clang-1.git
Improve char literal pretty printing, patch by Keith Bauer!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39846 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
b02d4b4bdf
Коммит
8bf9f079f1
|
@ -292,13 +292,50 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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'; }
|
Загрузка…
Ссылка в новой задаче