From e7367d6bcb9de27237ecab6de7208f4a725eda37 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 14 Oct 2014 20:28:40 +0000 Subject: Factor code into CXXRecordDecl::getTemplateInstantiationPattern() helper This moves some code from SemaType.cpp's hasVisibleDefinition() into DeclCXX.cpp so that it can be used elsewhere. I found one other instance of code trying to do the same thing, there are probably more. Search for getInstantiatedFrom() to try to find more. No functionality change. Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5783 llvm-svn: 219714 --- clang/lib/AST/DeclCXX.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'clang/lib/AST/DeclCXX.cpp') diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 37bd050c697..623cae5bf7a 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -1261,6 +1261,44 @@ CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { llvm_unreachable("Not a class template or member class specialization"); } +const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const { + // If it's a class template specialization, find the template or partial + // specialization from which it was instantiated. + if (auto *TD = dyn_cast(this)) { + auto From = TD->getInstantiatedFrom(); + if (auto *CTD = From.dyn_cast()) { + while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) { + if (NewCTD->isMemberSpecialization()) + break; + CTD = NewCTD; + } + return CTD->getTemplatedDecl(); + } + if (auto *CTPSD = + From.dyn_cast()) { + while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) { + if (NewCTPSD->isMemberSpecialization()) + break; + CTPSD = NewCTPSD; + } + return CTPSD; + } + } + + if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { + if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { + const CXXRecordDecl *RD = this; + while (auto *NewRD = RD->getInstantiatedFromMemberClass()) + RD = NewRD; + return RD; + } + } + + assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) && + "couldn't find pattern for class template instantiation"); + return nullptr; +} + CXXDestructorDecl *CXXRecordDecl::getDestructor() const { ASTContext &Context = getASTContext(); QualType ClassType = Context.getTypeDeclType(this); -- cgit v1.2.3