[cfe-commits] r126505 - /cfe/trunk/lib/AST/TemplateBase.cpp
Chandler Carruth
chandlerc at gmail.com
Fri Feb 25 12:09:14 PST 2011
Author: chandlerc
Date: Fri Feb 25 14:09:13 2011
New Revision: 126505
URL: http://llvm.org/viewvc/llvm-project?rev=126505&view=rev
Log:
Clean up some gross code in the printer here. No more string stream
silliness, and actually use the existing facilities of raw_ostream to do
escaping.
This will also hopefully fix an assert when building with signed char
(MSVC I think).
Modified:
cfe/trunk/lib/AST/TemplateBase.cpp
Modified: cfe/trunk/lib/AST/TemplateBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=126505&r1=126504&r2=126505&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TemplateBase.cpp (original)
+++ cfe/trunk/lib/AST/TemplateBase.cpp Fri Feb 25 14:09:13 2011
@@ -24,8 +24,6 @@
#include "llvm/ADT/FoldingSet.h"
#include <algorithm>
#include <cctype>
-#include <iomanip>
-#include <sstream>
using namespace clang;
@@ -42,17 +40,11 @@
if (T->isBooleanType()) {
Out << (Val->getBoolValue() ? "true" : "false");
} else if (T->isCharType()) {
- char Ch = Val->getSExtValue();
- if (std::isprint(Ch)) {
- Out << "'";
- if (Ch == '\'' || Ch == '\\')
- Out << '\\';
- Out << Ch << "'";
- } else {
- std::ostringstream Str;
- Str << std::setw(2) << std::setfill('0') << std::hex << (int)Ch;
- Out << "'\\x" << Str.str() << "'";
- }
+ const unsigned char Ch = Val->getZExtValue();
+ const std::string Str(1, Ch);
+ Out << ((Ch == '\'') ? "'\\" : "'");
+ Out.write_escaped(Str, /*UseHexEscapes=*/ true);
+ Out << "'";
} else {
Out << Val->toString(10);
}
More information about the cfe-commits
mailing list