Index: lib/Sema/DepthAndIndex.h =================================================================== --- lib/Sema/DepthAndIndex.h +++ lib/Sema/DepthAndIndex.h @@ -0,0 +1,44 @@ +//===- DepthAndIndex.h - Static declaration of the getDepthAndIndex function -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +//===----------------------------------------------------------------------===// +// +// This file defines getDepthAndIndex function. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_SEMA_DEPTHANDINDEX_H +#define LLVM_CLANG_LIB_SEMA_DEPTHANDINDEX_H + +#include "clang/AST/DeclTemplate.h" +#include "clang/Sema/DeclSpec.h" +#include "clang/Sema/Template.h" + +/// Retrieve the depth and index of a template parameter. +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. +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()); +} + +#endif // LLVM_CLANG_LIB_SEMA_DEPTHANDINDEX_H \ No newline at end of file Index: lib/Sema/SemaTemplateDeduction.cpp =================================================================== --- lib/Sema/SemaTemplateDeduction.cpp +++ lib/Sema/SemaTemplateDeduction.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===/ #include "clang/Sema/TemplateDeduction.h" +#include "DepthAndIndex.h" #include "TreeTransform.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTLambda.h" @@ -579,29 +580,6 @@ } } -/// \brief 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()); -} - -/// \brief 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()); -} - /// \brief Helper function to build a TemplateParameter when we don't /// know its type statically. static TemplateParameter makeTemplateParameter(Decl *D) { Index: lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiate.cpp +++ lib/Sema/SemaTemplateInstantiate.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===/ #include "clang/Sema/SemaInternal.h" +#include "DepthAndIndex.h" #include "TreeTransform.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" @@ -693,19 +694,6 @@ return None; } -/// \brief 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 //===----------------------------------------------------------------------===/ Index: lib/Sema/SemaTemplateVariadic.cpp =================================================================== --- lib/Sema/SemaTemplateVariadic.cpp +++ lib/Sema/SemaTemplateVariadic.cpp @@ -10,6 +10,7 @@ //===----------------------------------------------------------------------===/ #include "clang/Sema/Sema.h" +#include "DepthAndIndex.h" #include "TypeLocBuilder.h" #include "clang/AST/Expr.h" #include "clang/AST/RecursiveASTVisitor.h" @@ -26,19 +27,6 @@ // Visitor that collects unexpanded parameter packs //---------------------------------------------------------------------------- -/// \brief 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 { /// \brief A class that collects unexpanded parameter packs. class CollectUnexpandedParameterPacksVisitor :