[clang-tools-extra] [clang-doc] Add a breadcrumb navigation bar (PR #173297)
Erick Velez via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 7 13:09:58 PST 2026
================
@@ -697,10 +697,46 @@ static TemplateParamInfo convertTemplateArgToInfo(const clang::Decl *D,
return TemplateParamInfo(Str);
}
+// Check if the DeclKind is one for which we support contextual relationships.
+// There might be other ContextDecls, like blocks, that we currently don't
+// handle at all.
+static bool isSupportedContext(Decl::Kind DeclKind) {
+ switch (DeclKind) {
+ case Decl::Kind::Record:
+ case Decl::Kind::CXXRecord:
+ case Decl::Kind::ClassTemplateSpecialization:
+ case Decl::Kind::ClassTemplatePartialSpecialization:
+ case Decl::Kind::Namespace:
+ return true;
+ default:
+ return false;
+ }
+}
+
+template <typename T> static void findParent(Info &I, const T *D) {
+ assert(D && "Invalid Decl");
+
+ // Only walk up contexts if D is a record or namespace.
+ if (!isSupportedContext(D->getKind()))
+ return;
+
+ const DeclContext *ParentCtx = dyn_cast<DeclContext>(D)->getLexicalParent();
+ while (ParentCtx) {
+ if (isSupportedContext(ParentCtx->getDeclKind())) {
+ // Break when we reach the first record or namespace.
+ I.ParentUSR = getUSRForDecl(dyn_cast<Decl>(ParentCtx));
+ break;
+ }
+ ParentCtx = ParentCtx->getParent();
----------------
evelez7 wrote:
Isn't the `while` enough here for a check to return in case of `nullptr`? If the Decl is valid but for some reason parent is not, documentation could still show up somewhere for `D`.
https://github.com/llvm/llvm-project/pull/173297
More information about the cfe-commits
mailing list