diff options
author | Reid Kleckner <reid@kleckner.net> | 2014-10-14 20:28:40 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2014-10-14 20:28:40 +0000 |
commit | e7367d6bcb9de27237ecab6de7208f4a725eda37 (patch) | |
tree | 4b92cf2eece349ccd93f0a7d534d4b0b321e23f6 /clang/lib/Sema | |
parent | dad2103801e58b559bf14164d1aebdf7f444da5b (diff) | |
download | bcm5719-llvm-e7367d6bcb9de27237ecab6de7208f4a725eda37.tar.gz bcm5719-llvm-e7367d6bcb9de27237ecab6de7208f4a725eda37.zip |
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
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 17 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 26 |
2 files changed, 4 insertions, 39 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 639e6511217..cbeebb2ac98 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1175,21 +1175,8 @@ static Module *getDefiningModule(Decl *Entity) { if (FunctionDecl *Pattern = FD->getTemplateInstantiationPattern()) Entity = Pattern; } else if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Entity)) { - // If it's a class template specialization, find the template or partial - // specialization from which it was instantiated. - if (ClassTemplateSpecializationDecl *SpecRD = - dyn_cast<ClassTemplateSpecializationDecl>(RD)) { - llvm::PointerUnion<ClassTemplateDecl*, - ClassTemplatePartialSpecializationDecl*> From = - SpecRD->getInstantiatedFrom(); - if (ClassTemplateDecl *FromTemplate = From.dyn_cast<ClassTemplateDecl*>()) - Entity = FromTemplate->getTemplatedDecl(); - else if (From) - Entity = From.get<ClassTemplatePartialSpecializationDecl*>(); - // Otherwise, it's an explicit specialization. - } else if (MemberSpecializationInfo *MSInfo = - RD->getMemberSpecializationInfo()) - Entity = getInstantiatedFrom(RD, MSInfo); + if (CXXRecordDecl *Pattern = RD->getTemplateInstantiationPattern()) + Entity = Pattern; } else if (EnumDecl *ED = dyn_cast<EnumDecl>(Entity)) { if (MemberSpecializationInfo *MSInfo = ED->getMemberSpecializationInfo()) Entity = getInstantiatedFrom(ED, MSInfo); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 31d7f73e097..3ce9489fdd2 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5085,31 +5085,9 @@ static bool hasVisibleDefinition(Sema &S, NamedDecl *D, NamedDecl **Suggested) { // If this definition was instantiated from a template, map back to the // pattern from which it was instantiated. - // - // FIXME: There must be a better place for this to live. if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { - if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) { - auto From = TD->getInstantiatedFrom(); - if (auto *CTD = From.dyn_cast<ClassTemplateDecl*>()) { - while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) { - if (NewCTD->isMemberSpecialization()) - break; - CTD = NewCTD; - } - RD = CTD->getTemplatedDecl(); - } else if (auto *CTPSD = From.dyn_cast< - ClassTemplatePartialSpecializationDecl *>()) { - while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) { - if (NewCTPSD->isMemberSpecialization()) - break; - CTPSD = NewCTPSD; - } - RD = CTPSD; - } - } else if (isTemplateInstantiation(RD->getTemplateSpecializationKind())) { - while (auto *NewRD = RD->getInstantiatedFromMemberClass()) - RD = NewRD; - } + if (auto *Pattern = RD->getTemplateInstantiationPattern()) + RD = Pattern; D = RD->getDefinition(); } else if (auto *ED = dyn_cast<EnumDecl>(D)) { while (auto *NewED = ED->getInstantiatedFromMemberEnum()) |