From 926410d2db727c5093bda792cb8b2025d7f02cc3 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 21 Feb 2012 02:22:07 +0000 Subject: Implement name mangling for lambda expressions that occur within the initializers of data members (both static and non-static). llvm-svn: 151017 --- clang/lib/AST/ItaniumMangle.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'clang/lib/AST/ItaniumMangle.cpp') diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 93ebcc50cf2..47f50cf078e 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -1313,9 +1313,26 @@ void CXXNameMangler::mangleLocalName(const NamedDecl *ND) { } void CXXNameMangler::mangleLambda(const CXXRecordDecl *Lambda) { - // FIXME: Figure out if we're in a function body, default argument, - // or initializer for a class member. - + // If the context of a closure type is an initializer for a class member + // (static or nonstatic), it is encoded in a qualified name with a final + // of the form: + // + // := M + // + // Technically, the data-member-prefix is part of the . However, + // since a closure type will always be mangled with a prefix, it's easier + // to emit that last part of the prefix here. + if (Decl *Context = Lambda->getLambdaContextDecl()) { + if ((isa(Context) || isa(Context)) && + Context->getDeclContext()->isRecord()) { + if (const IdentifierInfo *Name + = cast(Context)->getIdentifier()) { + mangleSourceName(Name); + Out << 'M'; + } + } + } + Out << "Ul"; DeclarationName Name = getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); @@ -1392,26 +1409,27 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, bool NoFunction) { return; } - if (mangleSubstitution(cast(DC))) + const NamedDecl *ND = cast(DC); + if (mangleSubstitution(ND)) return; - + // Check if we have a template. const TemplateArgumentList *TemplateArgs = 0; - if (const TemplateDecl *TD = isTemplate(cast(DC), TemplateArgs)) { + if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { mangleTemplatePrefix(TD); TemplateParameterList *TemplateParameters = TD->getTemplateParameters(); mangleTemplateArgs(*TemplateParameters, *TemplateArgs); } - else if(NoFunction && (isa(DC) || isa(DC))) + else if(NoFunction && (isa(ND) || isa(ND))) return; - else if (const ObjCMethodDecl *Method = dyn_cast(DC)) + else if (const ObjCMethodDecl *Method = dyn_cast(ND)) mangleObjCMethodName(Method); else { - manglePrefix(getEffectiveParentContext(DC), NoFunction); - mangleUnqualifiedName(cast(DC)); + manglePrefix(getEffectiveDeclContext(ND), NoFunction); + mangleUnqualifiedName(ND); } - addSubstitution(cast(DC)); + addSubstitution(ND); } void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) { -- cgit v1.2.3