From: Nick Desaulniers Date: Wed, 25 Jul 2018 18:11:01 +0000 (+0000) Subject: [clang:sema] de-duplicate getDepthAndIndex helpers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d271415afbba1a47a2a0b81b4d7af05c9f158fa;p=clang [clang:sema] de-duplicate getDepthAndIndex helpers Summary: Continuing off of: https://reviews.llvm.org/D38382 Fixes: https://bugs.llvm.org/show_bug.cgi?id=12176 Reviewers: srhines, pirama, vsk Reviewed By: vsk Subscribers: cfe-commits, vsk, maitesin Differential Revision: https://reviews.llvm.org/D49760 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337944 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/SemaInternal.h b/include/clang/Sema/SemaInternal.h index 153270f3d0..86ab703a5b 100644 --- a/include/clang/Sema/SemaInternal.h +++ b/include/clang/Sema/SemaInternal.h @@ -101,6 +101,27 @@ inline InheritableAttr *getDLLAttr(Decl *D) { return nullptr; } +/// Retrieve the depth and index of a template parameter. +inline std::pair getDepthAndIndex(NamedDecl *ND) { + if (const auto *TTP = dyn_cast(ND)) + return std::make_pair(TTP->getDepth(), TTP->getIndex()); + + if (const auto *NTTP = dyn_cast(ND)) + return std::make_pair(NTTP->getDepth(), NTTP->getIndex()); + + const auto *TTP = cast(ND); + return std::make_pair(TTP->getDepth(), TTP->getIndex()); +} + +/// Retrieve the depth and index of an unexpanded parameter pack. +inline std::pair +getDepthAndIndex(UnexpandedParameterPack UPP) { + if (const auto *TTP = UPP.first.dyn_cast()) + return std::make_pair(TTP->getDepth(), TTP->getIndex()); + + return getDepthAndIndex(UPP.first.get()); +} + class TypoCorrectionConsumer : public VisibleDeclConsumer { typedef SmallVector TypoResultList; typedef llvm::StringMap TypoResultsMap; diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 0b41a515d9..633b2837e1 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -628,29 +628,6 @@ static bool IsPossiblyOpaquelyQualifiedType(QualType T) { } } -/// Retrieve the depth and index of a template parameter. -static std::pair -getDepthAndIndex(NamedDecl *ND) { - if (TemplateTypeParmDecl *TTP = dyn_cast(ND)) - return std::make_pair(TTP->getDepth(), TTP->getIndex()); - - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND)) - return std::make_pair(NTTP->getDepth(), NTTP->getIndex()); - - TemplateTemplateParmDecl *TTP = cast(ND); - return std::make_pair(TTP->getDepth(), TTP->getIndex()); -} - -/// Retrieve the depth and index of an unexpanded parameter pack. -static std::pair -getDepthAndIndex(UnexpandedParameterPack UPP) { - if (const TemplateTypeParmType *TTP - = UPP.first.dyn_cast()) - return std::make_pair(TTP->getDepth(), TTP->getIndex()); - - return getDepthAndIndex(UPP.first.get()); -} - /// Helper function to build a TemplateParameter when we don't /// know its type statically. static TemplateParameter makeTemplateParameter(Decl *D) { diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 3cf584344c..bc2ee42400 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -708,19 +708,6 @@ Optional Sema::isSFINAEContext() const { return None; } -/// Retrieve the depth and index of a parameter pack. -static std::pair -getDepthAndIndex(NamedDecl *ND) { - if (TemplateTypeParmDecl *TTP = dyn_cast(ND)) - return std::make_pair(TTP->getDepth(), TTP->getIndex()); - - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND)) - return std::make_pair(NTTP->getDepth(), NTTP->getIndex()); - - TemplateTemplateParmDecl *TTP = cast(ND); - return std::make_pair(TTP->getDepth(), TTP->getIndex()); -} - //===----------------------------------------------------------------------===/ // Template Instantiation for Types //===----------------------------------------------------------------------===/ diff --git a/lib/Sema/SemaTemplateVariadic.cpp b/lib/Sema/SemaTemplateVariadic.cpp index 8f7a75a165..fc16413342 100644 --- a/lib/Sema/SemaTemplateVariadic.cpp +++ b/lib/Sema/SemaTemplateVariadic.cpp @@ -26,19 +26,6 @@ using namespace clang; // Visitor that collects unexpanded parameter packs //---------------------------------------------------------------------------- -/// Retrieve the depth and index of a parameter pack. -static std::pair -getDepthAndIndex(NamedDecl *ND) { - if (TemplateTypeParmDecl *TTP = dyn_cast(ND)) - return std::make_pair(TTP->getDepth(), TTP->getIndex()); - - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(ND)) - return std::make_pair(NTTP->getDepth(), NTTP->getIndex()); - - TemplateTemplateParmDecl *TTP = cast(ND); - return std::make_pair(TTP->getDepth(), TTP->getIndex()); -} - namespace { /// A class that collects unexpanded parameter packs. class CollectUnexpandedParameterPacksVisitor :