aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplate.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-12-20 16:52:59 +0000
committerDouglas Gregor <dgregor@apple.com>2010-12-20 16:52:59 +0000
commit87dd697dcc8ecb64df73ae64d61b8c80ff0c157c (patch)
tree0222a2df7114ce46f1829744c97ebd08a5b736ad /lib/Sema/SemaTemplate.cpp
parenta9150cdac3d666671fce74cac621d68cc0ade17d (diff)
Clean up the handling of template argument packs, especially in the
area of printing template arguments. The functionality changes here are limited to cases of variadic templates that aren't yet enabled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122250 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r--lib/Sema/SemaTemplate.cpp83
1 files changed, 12 insertions, 71 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 36bb76fdb3..9704495c79 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -5937,91 +5937,32 @@ std::string
Sema::getTemplateArgumentBindingsText(const TemplateParameterList *Params,
const TemplateArgument *Args,
unsigned NumArgs) {
- std::string Result;
+ llvm::SmallString<128> Str;
+ llvm::raw_svector_ostream Out(Str);
if (!Params || Params->size() == 0 || NumArgs == 0)
- return Result;
+ return std::string();
for (unsigned I = 0, N = Params->size(); I != N; ++I) {
if (I >= NumArgs)
break;
if (I == 0)
- Result += "[with ";
+ Out << "[with ";
else
- Result += ", ";
+ Out << ", ";
if (const IdentifierInfo *Id = Params->getParam(I)->getIdentifier()) {
- Result += Id->getName();
+ Out << Id->getName();
} else {
- Result += '$';
- Result += llvm::utostr(I);
+ Out << '$' << I;
}
- Result += " = ";
-
- switch (Args[I].getKind()) {
- case TemplateArgument::Null:
- Result += "<no value>";
- break;
-
- case TemplateArgument::Type: {
- std::string TypeStr;
- Args[I].getAsType().getAsStringInternal(TypeStr,
- Context.PrintingPolicy);
- Result += TypeStr;
- break;
- }
-
- case TemplateArgument::Declaration: {
- bool Unnamed = true;
- if (NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Args[I].getAsDecl())) {
- if (ND->getDeclName()) {
- Unnamed = false;
- Result += ND->getNameAsString();
- }
- }
-
- if (Unnamed) {
- Result += "<anonymous>";
- }
- break;
- }
-
- case TemplateArgument::Template: {
- std::string Str;
- llvm::raw_string_ostream OS(Str);
- Args[I].getAsTemplate().print(OS, Context.PrintingPolicy);
- Result += OS.str();
- break;
- }
-
- case TemplateArgument::Integral: {
- Result += Args[I].getAsIntegral()->toString(10);
- break;
- }
-
- case TemplateArgument::Expression: {
- // FIXME: This is non-optimal, since we're regurgitating the
- // expression we were given.
- std::string Str;
- {
- llvm::raw_string_ostream OS(Str);
- Args[I].getAsExpr()->printPretty(OS, Context, 0,
- Context.PrintingPolicy);
- }
- Result += Str;
- break;
- }
-
- case TemplateArgument::Pack:
- // FIXME: Format template argument packs
- Result += "<template argument pack>";
- break;
- }
+ Out << " = ";
+ Args[I].print(Context.PrintingPolicy, Out);
}
-
- Result += ']';
- return Result;
+
+ Out << ']';
+ return Out.str();
}