Handle mangling of TemplateSpecializationType.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82189 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index aaa771b..d0edb02 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -69,12 +69,18 @@
void mangleFunctionEncoding(const FunctionDecl *FD);
void mangleName(const NamedDecl *ND);
+ void mangleName(const TemplateDecl *TD,
+ const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs);
void mangleUnqualifiedName(const NamedDecl *ND);
void mangleUnscopedName(const NamedDecl *ND);
- void mangleUnscopedTemplateName(const FunctionDecl *ND);
+ void mangleUnscopedTemplateName(const NamedDecl *ND);
void mangleSourceName(const IdentifierInfo *II);
void mangleLocalName(const NamedDecl *ND);
void mangleNestedName(const NamedDecl *ND);
+ void mangleNestedName(const TemplateDecl *TD,
+ const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs);
void manglePrefix(const DeclContext *DC);
void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
void mangleCVQualifiers(unsigned Quals);
@@ -93,6 +99,8 @@
void mangleCXXCtorType(CXXCtorType T);
void mangleCXXDtorType(CXXDtorType T);
+ void mangleTemplateArgs(const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs);
void mangleTemplateArgumentList(const TemplateArgumentList &L);
void mangleTemplateArgument(const TemplateArgument &A);
};
@@ -268,6 +276,24 @@
mangleNestedName(ND);
}
+void CXXNameMangler::mangleName(const TemplateDecl *TD,
+ const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs) {
+ const DeclContext *DC = TD->getDeclContext();
+ while (isa<LinkageSpecDecl>(DC)) {
+ assert(cast<LinkageSpecDecl>(DC)->getLanguage() ==
+ LinkageSpecDecl::lang_cxx && "Unexpected linkage decl!");
+ DC = DC->getParent();
+ }
+
+ if (DC->isTranslationUnit() || isStdNamespace(DC)) {
+ mangleUnscopedTemplateName(cast<NamedDecl>(TD->getTemplatedDecl()));
+ mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
+ } else {
+ mangleNestedName(TD, TemplateArgs, NumTemplateArgs);
+ }
+}
+
void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) {
// <unscoped-name> ::= <unqualified-name>
// ::= St <unqualified-name> # ::std::
@@ -277,14 +303,14 @@
mangleUnqualifiedName(ND);
}
-void CXXNameMangler::mangleUnscopedTemplateName(const FunctionDecl *FD) {
+void CXXNameMangler::mangleUnscopedTemplateName(const NamedDecl *ND) {
// <unscoped-template-name> ::= <unscoped-name>
// ::= <substitution>
- if (mangleSubstitution(FD))
+ if (mangleSubstitution(ND))
return;
- mangleUnscopedName(FD);
- addSubstitution(FD);
+ mangleUnscopedName(ND);
+ addSubstitution(ND);
}
void CXXNameMangler::mangleCalloffset(int64_t nv, int64_t v) {
@@ -419,6 +445,17 @@
Out << 'E';
}
+void CXXNameMangler::mangleNestedName(const TemplateDecl *TD,
+ const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs) {
+ Out << 'N';
+ manglePrefix(TD->getDeclContext());
+ mangleUnqualifiedName(TD->getTemplatedDecl());
+
+ mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
+ Out << 'E';
+}
+
void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
// <local-name> := Z <function encoding> E <entity name> [<discriminator>]
// := Z <function encoding> E s [<discriminator>]
@@ -827,8 +864,10 @@
}
void CXXNameMangler::mangleType(const TemplateSpecializationType *T) {
- // TSTs are never canonical unless they're dependent.
- assert(false && "can't mangle dependent template specializations yet");
+ TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
+ assert(TD && "FIXME: Support dependent template names!");
+
+ mangleName(TD, T->getArgs(), T->getNumArgs());
}
void CXXNameMangler::mangleType(const TypenameType *T) {
@@ -896,6 +935,18 @@
Out << "E";
}
+void CXXNameMangler::mangleTemplateArgs(const TemplateArgument *TemplateArgs,
+ unsigned NumTemplateArgs) {
+ // <template-args> ::= I <template-arg>+ E
+ Out << "I";
+
+ for (unsigned i = 0; i != NumTemplateArgs; ++i) {
+ mangleTemplateArgument(TemplateArgs[i]);
+ }
+
+ Out << "E";
+}
+
void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) {
// <template-arg> ::= <type> # type or template
// ::= X <expression> E # expression