summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/TemplateBase.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-02-25 20:09:13 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-02-25 20:09:13 +0000
commit20d0fee3f4942116e516cf56cd1e2f61ef886f49 (patch)
treee08e573039538b06dd8eeae908465ecd78f1462d /clang/lib/AST/TemplateBase.cpp
parenta8d8ca4d6f700890791d5a2ba99c647e522cdd38 (diff)
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). llvm-svn: 126505
Diffstat (limited to 'clang/lib/AST/TemplateBase.cpp')
-rw-r--r--clang/lib/AST/TemplateBase.cpp18
1 files changed, 5 insertions, 13 deletions
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index 5ab5f4644c88..1764f4ab1f03 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -24,8 +24,6 @@
#include "llvm/ADT/FoldingSet.h"
#include <algorithm>
#include <cctype>
-#include <iomanip>
-#include <sstream>
using namespace clang;
@@ -42,17 +40,11 @@ static void printIntegral(const TemplateArgument &TemplArg,
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);
}