xref: /netbsd-src/external/apache2/llvm/dist/clang/lib/AST/Comment.cpp (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
17330f729Sjoerg //===--- Comment.cpp - Comment AST node implementation --------------------===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg 
97330f729Sjoerg #include "clang/AST/Comment.h"
107330f729Sjoerg #include "clang/AST/ASTContext.h"
117330f729Sjoerg #include "clang/AST/Decl.h"
127330f729Sjoerg #include "clang/AST/DeclObjC.h"
137330f729Sjoerg #include "clang/AST/DeclTemplate.h"
147330f729Sjoerg #include "clang/Basic/CharInfo.h"
157330f729Sjoerg #include "llvm/Support/ErrorHandling.h"
167330f729Sjoerg #include <type_traits>
177330f729Sjoerg 
187330f729Sjoerg namespace clang {
197330f729Sjoerg namespace comments {
207330f729Sjoerg 
217330f729Sjoerg // Check that no comment class has a non-trival destructor. They are allocated
227330f729Sjoerg // with a BumpPtrAllocator and therefore their destructor is not executed.
237330f729Sjoerg #define ABSTRACT_COMMENT(COMMENT)
247330f729Sjoerg #define COMMENT(CLASS, PARENT)                                                 \
257330f729Sjoerg   static_assert(std::is_trivially_destructible<CLASS>::value,                  \
267330f729Sjoerg                 #CLASS " should be trivially destructible!");
277330f729Sjoerg #include "clang/AST/CommentNodes.inc"
287330f729Sjoerg #undef COMMENT
297330f729Sjoerg #undef ABSTRACT_COMMENT
307330f729Sjoerg 
317330f729Sjoerg // DeclInfo is also allocated with a BumpPtrAllocator.
327330f729Sjoerg static_assert(std::is_trivially_destructible<DeclInfo>::value,
337330f729Sjoerg               "DeclInfo should be trivially destructible!");
347330f729Sjoerg 
getCommentKindName() const357330f729Sjoerg const char *Comment::getCommentKindName() const {
367330f729Sjoerg   switch (getCommentKind()) {
377330f729Sjoerg   case NoCommentKind: return "NoCommentKind";
387330f729Sjoerg #define ABSTRACT_COMMENT(COMMENT)
397330f729Sjoerg #define COMMENT(CLASS, PARENT) \
407330f729Sjoerg   case CLASS##Kind: \
417330f729Sjoerg     return #CLASS;
427330f729Sjoerg #include "clang/AST/CommentNodes.inc"
437330f729Sjoerg #undef COMMENT
447330f729Sjoerg #undef ABSTRACT_COMMENT
457330f729Sjoerg   }
467330f729Sjoerg   llvm_unreachable("Unknown comment kind!");
477330f729Sjoerg }
487330f729Sjoerg 
497330f729Sjoerg namespace {
507330f729Sjoerg struct good {};
517330f729Sjoerg struct bad {};
527330f729Sjoerg 
537330f729Sjoerg template <typename T>
implements_child_begin_end(Comment::child_iterator (T::*)()const)547330f729Sjoerg good implements_child_begin_end(Comment::child_iterator (T::*)() const) {
557330f729Sjoerg   return good();
567330f729Sjoerg }
577330f729Sjoerg 
587330f729Sjoerg LLVM_ATTRIBUTE_UNUSED
implements_child_begin_end(Comment::child_iterator (Comment::*)()const)597330f729Sjoerg static inline bad implements_child_begin_end(
607330f729Sjoerg                       Comment::child_iterator (Comment::*)() const) {
617330f729Sjoerg   return bad();
627330f729Sjoerg }
637330f729Sjoerg 
647330f729Sjoerg #define ASSERT_IMPLEMENTS_child_begin(function) \
657330f729Sjoerg   (void) good(implements_child_begin_end(function))
667330f729Sjoerg 
677330f729Sjoerg LLVM_ATTRIBUTE_UNUSED
CheckCommentASTNodes()687330f729Sjoerg static inline void CheckCommentASTNodes() {
697330f729Sjoerg #define ABSTRACT_COMMENT(COMMENT)
707330f729Sjoerg #define COMMENT(CLASS, PARENT) \
717330f729Sjoerg   ASSERT_IMPLEMENTS_child_begin(&CLASS::child_begin); \
727330f729Sjoerg   ASSERT_IMPLEMENTS_child_begin(&CLASS::child_end);
737330f729Sjoerg #include "clang/AST/CommentNodes.inc"
747330f729Sjoerg #undef COMMENT
757330f729Sjoerg #undef ABSTRACT_COMMENT
767330f729Sjoerg }
777330f729Sjoerg 
787330f729Sjoerg #undef ASSERT_IMPLEMENTS_child_begin
797330f729Sjoerg 
807330f729Sjoerg } // end unnamed namespace
817330f729Sjoerg 
child_begin() const827330f729Sjoerg Comment::child_iterator Comment::child_begin() const {
837330f729Sjoerg   switch (getCommentKind()) {
847330f729Sjoerg   case NoCommentKind: llvm_unreachable("comment without a kind");
857330f729Sjoerg #define ABSTRACT_COMMENT(COMMENT)
867330f729Sjoerg #define COMMENT(CLASS, PARENT) \
877330f729Sjoerg   case CLASS##Kind: \
887330f729Sjoerg     return static_cast<const CLASS *>(this)->child_begin();
897330f729Sjoerg #include "clang/AST/CommentNodes.inc"
907330f729Sjoerg #undef COMMENT
917330f729Sjoerg #undef ABSTRACT_COMMENT
927330f729Sjoerg   }
937330f729Sjoerg   llvm_unreachable("Unknown comment kind!");
947330f729Sjoerg }
957330f729Sjoerg 
child_end() const967330f729Sjoerg Comment::child_iterator Comment::child_end() const {
977330f729Sjoerg   switch (getCommentKind()) {
987330f729Sjoerg   case NoCommentKind: llvm_unreachable("comment without a kind");
997330f729Sjoerg #define ABSTRACT_COMMENT(COMMENT)
1007330f729Sjoerg #define COMMENT(CLASS, PARENT) \
1017330f729Sjoerg   case CLASS##Kind: \
1027330f729Sjoerg     return static_cast<const CLASS *>(this)->child_end();
1037330f729Sjoerg #include "clang/AST/CommentNodes.inc"
1047330f729Sjoerg #undef COMMENT
1057330f729Sjoerg #undef ABSTRACT_COMMENT
1067330f729Sjoerg   }
1077330f729Sjoerg   llvm_unreachable("Unknown comment kind!");
1087330f729Sjoerg }
1097330f729Sjoerg 
isWhitespaceNoCache() const1107330f729Sjoerg bool TextComment::isWhitespaceNoCache() const {
1117330f729Sjoerg   for (StringRef::const_iterator I = Text.begin(), E = Text.end();
1127330f729Sjoerg        I != E; ++I) {
1137330f729Sjoerg     if (!clang::isWhitespace(*I))
1147330f729Sjoerg       return false;
1157330f729Sjoerg   }
1167330f729Sjoerg   return true;
1177330f729Sjoerg }
1187330f729Sjoerg 
isWhitespaceNoCache() const1197330f729Sjoerg bool ParagraphComment::isWhitespaceNoCache() const {
1207330f729Sjoerg   for (child_iterator I = child_begin(), E = child_end(); I != E; ++I) {
1217330f729Sjoerg     if (const TextComment *TC = dyn_cast<TextComment>(*I)) {
1227330f729Sjoerg       if (!TC->isWhitespace())
1237330f729Sjoerg         return false;
1247330f729Sjoerg     } else
1257330f729Sjoerg       return false;
1267330f729Sjoerg   }
1277330f729Sjoerg   return true;
1287330f729Sjoerg }
1297330f729Sjoerg 
lookThroughTypedefOrTypeAliasLocs(TypeLoc & SrcTL)1307330f729Sjoerg static TypeLoc lookThroughTypedefOrTypeAliasLocs(TypeLoc &SrcTL) {
1317330f729Sjoerg   TypeLoc TL = SrcTL.IgnoreParens();
1327330f729Sjoerg 
1337330f729Sjoerg   // Look through attribute types.
1347330f729Sjoerg   if (AttributedTypeLoc AttributeTL = TL.getAs<AttributedTypeLoc>())
1357330f729Sjoerg     return AttributeTL.getModifiedLoc();
1367330f729Sjoerg   // Look through qualified types.
1377330f729Sjoerg   if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>())
1387330f729Sjoerg     return QualifiedTL.getUnqualifiedLoc();
1397330f729Sjoerg   // Look through pointer types.
1407330f729Sjoerg   if (PointerTypeLoc PointerTL = TL.getAs<PointerTypeLoc>())
1417330f729Sjoerg     return PointerTL.getPointeeLoc().getUnqualifiedLoc();
1427330f729Sjoerg   // Look through reference types.
1437330f729Sjoerg   if (ReferenceTypeLoc ReferenceTL = TL.getAs<ReferenceTypeLoc>())
1447330f729Sjoerg     return ReferenceTL.getPointeeLoc().getUnqualifiedLoc();
1457330f729Sjoerg   // Look through adjusted types.
1467330f729Sjoerg   if (AdjustedTypeLoc ATL = TL.getAs<AdjustedTypeLoc>())
1477330f729Sjoerg     return ATL.getOriginalLoc();
1487330f729Sjoerg   if (BlockPointerTypeLoc BlockPointerTL = TL.getAs<BlockPointerTypeLoc>())
1497330f729Sjoerg     return BlockPointerTL.getPointeeLoc().getUnqualifiedLoc();
1507330f729Sjoerg   if (MemberPointerTypeLoc MemberPointerTL = TL.getAs<MemberPointerTypeLoc>())
1517330f729Sjoerg     return MemberPointerTL.getPointeeLoc().getUnqualifiedLoc();
1527330f729Sjoerg   if (ElaboratedTypeLoc ETL = TL.getAs<ElaboratedTypeLoc>())
1537330f729Sjoerg     return ETL.getNamedTypeLoc();
1547330f729Sjoerg 
1557330f729Sjoerg   return TL;
1567330f729Sjoerg }
1577330f729Sjoerg 
getFunctionTypeLoc(TypeLoc TL,FunctionTypeLoc & ResFTL)1587330f729Sjoerg static bool getFunctionTypeLoc(TypeLoc TL, FunctionTypeLoc &ResFTL) {
1597330f729Sjoerg   TypeLoc PrevTL;
1607330f729Sjoerg   while (PrevTL != TL) {
1617330f729Sjoerg     PrevTL = TL;
1627330f729Sjoerg     TL = lookThroughTypedefOrTypeAliasLocs(TL);
1637330f729Sjoerg   }
1647330f729Sjoerg 
1657330f729Sjoerg   if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
1667330f729Sjoerg     ResFTL = FTL;
1677330f729Sjoerg     return true;
1687330f729Sjoerg   }
1697330f729Sjoerg 
1707330f729Sjoerg   if (TemplateSpecializationTypeLoc STL =
1717330f729Sjoerg           TL.getAs<TemplateSpecializationTypeLoc>()) {
1727330f729Sjoerg     // If we have a typedef to a template specialization with exactly one
1737330f729Sjoerg     // template argument of a function type, this looks like std::function,
1747330f729Sjoerg     // boost::function, or other function wrapper.  Treat these typedefs as
1757330f729Sjoerg     // functions.
1767330f729Sjoerg     if (STL.getNumArgs() != 1)
1777330f729Sjoerg       return false;
1787330f729Sjoerg     TemplateArgumentLoc MaybeFunction = STL.getArgLoc(0);
1797330f729Sjoerg     if (MaybeFunction.getArgument().getKind() != TemplateArgument::Type)
1807330f729Sjoerg       return false;
1817330f729Sjoerg     TypeSourceInfo *MaybeFunctionTSI = MaybeFunction.getTypeSourceInfo();
1827330f729Sjoerg     TypeLoc TL = MaybeFunctionTSI->getTypeLoc().getUnqualifiedLoc();
1837330f729Sjoerg     if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
1847330f729Sjoerg       ResFTL = FTL;
1857330f729Sjoerg       return true;
1867330f729Sjoerg     }
1877330f729Sjoerg   }
1887330f729Sjoerg 
1897330f729Sjoerg   return false;
1907330f729Sjoerg }
1917330f729Sjoerg 
getDirectionAsString(PassDirection D)1927330f729Sjoerg const char *ParamCommandComment::getDirectionAsString(PassDirection D) {
1937330f729Sjoerg   switch (D) {
1947330f729Sjoerg   case ParamCommandComment::In:
1957330f729Sjoerg     return "[in]";
1967330f729Sjoerg   case ParamCommandComment::Out:
1977330f729Sjoerg     return "[out]";
1987330f729Sjoerg   case ParamCommandComment::InOut:
1997330f729Sjoerg     return "[in,out]";
2007330f729Sjoerg   }
2017330f729Sjoerg   llvm_unreachable("unknown PassDirection");
2027330f729Sjoerg }
2037330f729Sjoerg 
fill()2047330f729Sjoerg void DeclInfo::fill() {
2057330f729Sjoerg   assert(!IsFilled);
2067330f729Sjoerg 
2077330f729Sjoerg   // Set defaults.
2087330f729Sjoerg   Kind = OtherKind;
2097330f729Sjoerg   TemplateKind = NotTemplate;
2107330f729Sjoerg   IsObjCMethod = false;
2117330f729Sjoerg   IsInstanceMethod = false;
2127330f729Sjoerg   IsClassMethod = false;
2137330f729Sjoerg   ParamVars = None;
2147330f729Sjoerg   TemplateParameters = nullptr;
2157330f729Sjoerg 
2167330f729Sjoerg   if (!CommentDecl) {
2177330f729Sjoerg     // If there is no declaration, the defaults is our only guess.
2187330f729Sjoerg     IsFilled = true;
2197330f729Sjoerg     return;
2207330f729Sjoerg   }
2217330f729Sjoerg   CurrentDecl = CommentDecl;
2227330f729Sjoerg 
2237330f729Sjoerg   Decl::Kind K = CommentDecl->getKind();
2247330f729Sjoerg   switch (K) {
2257330f729Sjoerg   default:
2267330f729Sjoerg     // Defaults are should be good for declarations we don't handle explicitly.
2277330f729Sjoerg     break;
2287330f729Sjoerg   case Decl::Function:
2297330f729Sjoerg   case Decl::CXXMethod:
2307330f729Sjoerg   case Decl::CXXConstructor:
2317330f729Sjoerg   case Decl::CXXDestructor:
2327330f729Sjoerg   case Decl::CXXConversion: {
2337330f729Sjoerg     const FunctionDecl *FD = cast<FunctionDecl>(CommentDecl);
2347330f729Sjoerg     Kind = FunctionKind;
2357330f729Sjoerg     ParamVars = FD->parameters();
2367330f729Sjoerg     ReturnType = FD->getReturnType();
2377330f729Sjoerg     unsigned NumLists = FD->getNumTemplateParameterLists();
2387330f729Sjoerg     if (NumLists != 0) {
2397330f729Sjoerg       TemplateKind = TemplateSpecialization;
2407330f729Sjoerg       TemplateParameters =
2417330f729Sjoerg           FD->getTemplateParameterList(NumLists - 1);
2427330f729Sjoerg     }
2437330f729Sjoerg 
2447330f729Sjoerg     if (K == Decl::CXXMethod || K == Decl::CXXConstructor ||
2457330f729Sjoerg         K == Decl::CXXDestructor || K == Decl::CXXConversion) {
2467330f729Sjoerg       const CXXMethodDecl *MD = cast<CXXMethodDecl>(CommentDecl);
2477330f729Sjoerg       IsInstanceMethod = MD->isInstance();
2487330f729Sjoerg       IsClassMethod = !IsInstanceMethod;
2497330f729Sjoerg     }
2507330f729Sjoerg     break;
2517330f729Sjoerg   }
2527330f729Sjoerg   case Decl::ObjCMethod: {
2537330f729Sjoerg     const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(CommentDecl);
2547330f729Sjoerg     Kind = FunctionKind;
2557330f729Sjoerg     ParamVars = MD->parameters();
2567330f729Sjoerg     ReturnType = MD->getReturnType();
2577330f729Sjoerg     IsObjCMethod = true;
2587330f729Sjoerg     IsInstanceMethod = MD->isInstanceMethod();
2597330f729Sjoerg     IsClassMethod = !IsInstanceMethod;
2607330f729Sjoerg     break;
2617330f729Sjoerg   }
2627330f729Sjoerg   case Decl::FunctionTemplate: {
2637330f729Sjoerg     const FunctionTemplateDecl *FTD = cast<FunctionTemplateDecl>(CommentDecl);
2647330f729Sjoerg     Kind = FunctionKind;
2657330f729Sjoerg     TemplateKind = Template;
2667330f729Sjoerg     const FunctionDecl *FD = FTD->getTemplatedDecl();
2677330f729Sjoerg     ParamVars = FD->parameters();
2687330f729Sjoerg     ReturnType = FD->getReturnType();
2697330f729Sjoerg     TemplateParameters = FTD->getTemplateParameters();
2707330f729Sjoerg     break;
2717330f729Sjoerg   }
2727330f729Sjoerg   case Decl::ClassTemplate: {
2737330f729Sjoerg     const ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(CommentDecl);
2747330f729Sjoerg     Kind = ClassKind;
2757330f729Sjoerg     TemplateKind = Template;
2767330f729Sjoerg     TemplateParameters = CTD->getTemplateParameters();
2777330f729Sjoerg     break;
2787330f729Sjoerg   }
2797330f729Sjoerg   case Decl::ClassTemplatePartialSpecialization: {
2807330f729Sjoerg     const ClassTemplatePartialSpecializationDecl *CTPSD =
2817330f729Sjoerg         cast<ClassTemplatePartialSpecializationDecl>(CommentDecl);
2827330f729Sjoerg     Kind = ClassKind;
2837330f729Sjoerg     TemplateKind = TemplatePartialSpecialization;
2847330f729Sjoerg     TemplateParameters = CTPSD->getTemplateParameters();
2857330f729Sjoerg     break;
2867330f729Sjoerg   }
2877330f729Sjoerg   case Decl::ClassTemplateSpecialization:
2887330f729Sjoerg     Kind = ClassKind;
2897330f729Sjoerg     TemplateKind = TemplateSpecialization;
2907330f729Sjoerg     break;
2917330f729Sjoerg   case Decl::Record:
2927330f729Sjoerg   case Decl::CXXRecord:
2937330f729Sjoerg     Kind = ClassKind;
2947330f729Sjoerg     break;
2957330f729Sjoerg   case Decl::Var:
2967330f729Sjoerg   case Decl::Field:
2977330f729Sjoerg   case Decl::EnumConstant:
2987330f729Sjoerg   case Decl::ObjCIvar:
2997330f729Sjoerg   case Decl::ObjCAtDefsField:
3007330f729Sjoerg   case Decl::ObjCProperty: {
3017330f729Sjoerg     const TypeSourceInfo *TSI;
3027330f729Sjoerg     if (const auto *VD = dyn_cast<DeclaratorDecl>(CommentDecl))
3037330f729Sjoerg       TSI = VD->getTypeSourceInfo();
3047330f729Sjoerg     else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(CommentDecl))
3057330f729Sjoerg       TSI = PD->getTypeSourceInfo();
3067330f729Sjoerg     else
3077330f729Sjoerg       TSI = nullptr;
3087330f729Sjoerg     if (TSI) {
3097330f729Sjoerg       TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
3107330f729Sjoerg       FunctionTypeLoc FTL;
3117330f729Sjoerg       if (getFunctionTypeLoc(TL, FTL)) {
3127330f729Sjoerg         ParamVars = FTL.getParams();
3137330f729Sjoerg         ReturnType = FTL.getReturnLoc().getType();
3147330f729Sjoerg       }
3157330f729Sjoerg     }
3167330f729Sjoerg     Kind = VariableKind;
3177330f729Sjoerg     break;
3187330f729Sjoerg   }
3197330f729Sjoerg   case Decl::Namespace:
3207330f729Sjoerg     Kind = NamespaceKind;
3217330f729Sjoerg     break;
3227330f729Sjoerg   case Decl::TypeAlias:
3237330f729Sjoerg   case Decl::Typedef: {
3247330f729Sjoerg     Kind = TypedefKind;
3257330f729Sjoerg     // If this is a typedef / using to something we consider a function, extract
3267330f729Sjoerg     // arguments and return type.
3277330f729Sjoerg     const TypeSourceInfo *TSI =
3287330f729Sjoerg         K == Decl::Typedef
3297330f729Sjoerg             ? cast<TypedefDecl>(CommentDecl)->getTypeSourceInfo()
3307330f729Sjoerg             : cast<TypeAliasDecl>(CommentDecl)->getTypeSourceInfo();
3317330f729Sjoerg     if (!TSI)
3327330f729Sjoerg       break;
3337330f729Sjoerg     TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
3347330f729Sjoerg     FunctionTypeLoc FTL;
3357330f729Sjoerg     if (getFunctionTypeLoc(TL, FTL)) {
3367330f729Sjoerg       Kind = FunctionKind;
3377330f729Sjoerg       ParamVars = FTL.getParams();
3387330f729Sjoerg       ReturnType = FTL.getReturnLoc().getType();
3397330f729Sjoerg     }
3407330f729Sjoerg     break;
3417330f729Sjoerg   }
3427330f729Sjoerg   case Decl::TypeAliasTemplate: {
3437330f729Sjoerg     const TypeAliasTemplateDecl *TAT = cast<TypeAliasTemplateDecl>(CommentDecl);
3447330f729Sjoerg     Kind = TypedefKind;
3457330f729Sjoerg     TemplateKind = Template;
3467330f729Sjoerg     TemplateParameters = TAT->getTemplateParameters();
3477330f729Sjoerg     TypeAliasDecl *TAD = TAT->getTemplatedDecl();
3487330f729Sjoerg     if (!TAD)
3497330f729Sjoerg       break;
3507330f729Sjoerg 
3517330f729Sjoerg     const TypeSourceInfo *TSI = TAD->getTypeSourceInfo();
3527330f729Sjoerg     if (!TSI)
3537330f729Sjoerg       break;
3547330f729Sjoerg     TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
3557330f729Sjoerg     FunctionTypeLoc FTL;
3567330f729Sjoerg     if (getFunctionTypeLoc(TL, FTL)) {
3577330f729Sjoerg       Kind = FunctionKind;
3587330f729Sjoerg       ParamVars = FTL.getParams();
3597330f729Sjoerg       ReturnType = FTL.getReturnLoc().getType();
3607330f729Sjoerg     }
3617330f729Sjoerg     break;
3627330f729Sjoerg   }
3637330f729Sjoerg   case Decl::Enum:
3647330f729Sjoerg     Kind = EnumKind;
3657330f729Sjoerg     break;
3667330f729Sjoerg   }
3677330f729Sjoerg 
3687330f729Sjoerg   IsFilled = true;
3697330f729Sjoerg }
3707330f729Sjoerg 
getParamName(const FullComment * FC) const3717330f729Sjoerg StringRef ParamCommandComment::getParamName(const FullComment *FC) const {
3727330f729Sjoerg   assert(isParamIndexValid());
3737330f729Sjoerg   if (isVarArgParam())
3747330f729Sjoerg     return "...";
3757330f729Sjoerg   return FC->getDeclInfo()->ParamVars[getParamIndex()]->getName();
3767330f729Sjoerg }
3777330f729Sjoerg 
getParamName(const FullComment * FC) const3787330f729Sjoerg StringRef TParamCommandComment::getParamName(const FullComment *FC) const {
3797330f729Sjoerg   assert(isPositionValid());
3807330f729Sjoerg   const TemplateParameterList *TPL = FC->getDeclInfo()->TemplateParameters;
3817330f729Sjoerg   for (unsigned i = 0, e = getDepth(); i != e; ++i) {
382*e038c9c4Sjoerg     assert(TPL && "Unknown TemplateParameterList");
3837330f729Sjoerg     if (i == e - 1)
3847330f729Sjoerg       return TPL->getParam(getIndex(i))->getName();
3857330f729Sjoerg     const NamedDecl *Param = TPL->getParam(getIndex(i));
386*e038c9c4Sjoerg     if (auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param))
3877330f729Sjoerg       TPL = TTP->getTemplateParameters();
3887330f729Sjoerg   }
3897330f729Sjoerg   return "";
3907330f729Sjoerg }
3917330f729Sjoerg 
3927330f729Sjoerg } // end namespace comments
3937330f729Sjoerg } // end namespace clang
3947330f729Sjoerg 
395