Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
nodeextractor.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6#include "aggregate.h"
7#include "atom.h"
8#include "classnode.h"
9#include "codemarker.h"
10#include "collectionnode.h"
12#include "config.h"
13#include "doc.h"
14#include "enumnode.h"
15#include "functionnode.h"
16#include "generator.h"
17#include "hrefresolver.h"
19#include "namespacenode.h"
21#include "ir/contentbuilder.h"
22#include "ir/signaturespan.h"
23#include "pagenode.h"
24#include "parameters.h"
25#include "propertynode.h"
27#include "qdocdatabase.h"
28#include "qmltypenode.h"
29#include "sections.h"
32#include "text.h"
33#include "tree.h"
34#include "typedefnode.h"
35#include "utilities.h"
36#include "textutils.h"
37#include "variablenode.h"
38
39#include "location.h"
40
41#include <QHash>
42#include <QRegularExpression>
43#include <QSet>
44
45#include <deque>
46#include <optional>
47
48QT_BEGIN_NAMESPACE
49
50using namespace Qt::Literals;
51
53{
54 const Location &loc = node->doc().location();
55 return [loc](QtMsgType type, const QString &message) {
56 switch (type) {
57 case QtWarningMsg:
58 loc.warning(message);
59 break;
60 default:
61 loc.warning(message);
62 break;
63 }
64 };
65}
66
67static QString resolveHref(const HrefResolver *resolver, const Node *target, const Node *relative)
68{
69 if (!resolver)
70 return target->url();
71 auto result = resolver->hrefForNode(target, relative);
72 if (const auto *href = std::get_if<QString>(&result))
73 return *href;
74 return {};
75}
76
77namespace {
78
79struct DeprecationData
80{
81 QString deprecatedSince;
82 QString typeNoun;
83 QString deprecatedSinceQualified;
84};
85
86QList<IR::ContentBlock> extractDeprecationNote(const Node *node)
87{
88 const Text reason = node->doc().deprecationText();
89 if (reason.isEmpty())
90 return {};
91 Text paragraph;
92 paragraph << Atom::ParaLeft << reason << Atom::ParaRight;
93 IR::ContentBuilder builder(IR::BriefHandling::Skip, 0, diagnosticHandlerFor(node));
94 return builder.build(paragraph.firstAtom());
95}
96
97/*!
98 \internal
99
100 Returns the deprecation sentence data for \a node if the node is
101 deprecated or active with a nonempty deprecation version. Otherwise,
102 returns \c{std::nullopt}.
103
104 The result contains the type noun and the plain deprecation version.
105 For a QML node with a logical module name, \c{deprecatedSinceQualified}
106 prefixes the nonempty version with the module name. For other nodes,
107 it contains the plain version. Deprecated sentences use this qualified
108 version; scheduled sentences use the plain \c{deprecatedSince} version.
109
110 A deprecated node without a version still returns sentence data with
111 a type noun and two empty version strings.
112*/
113std::optional<DeprecationData> extractDeprecationData(const Node *node)
114{
115 const auto status = node->status();
116 const auto &version = node->deprecatedSince();
117 if (status != Status::Deprecated && (status != Status::Active || version.isEmpty()))
118 return std::nullopt;
119
120 DeprecationData data{version, NodeText::nodeTypeDescription(node), version};
121 if (!version.isEmpty() && node->isQmlNode() && !node->logicalModuleName().isEmpty())
122 data.deprecatedSinceQualified = node->logicalModuleName() + ' '_L1 + version;
123 return data;
124}
125
126// Locate a documented \concept node by name. Walks the QDocDatabase search
127// order so cross-module references resolve through dependency index trees.
128// The relative node is reserved for relative-node-aware scoping in a future
129// revision; today the lookup is global.
130const Node *findConceptNodeForRelative(const Node *relative, const QString &name)
131{
132 Q_UNUSED(relative);
134 if (!qdb)
135 return nullptr;
136 return qdb->findConceptNode(name);
137}
138
139// Tokenize a requires-clause text against a list of documented concept
140// names, emitting a Text/Link/Text/... span sequence into \a out. Mirrors
141// the Text+ExternalRef+Text span pattern used for external references, but
142// uses SpanRole::Link with an HrefResolver-resolved href instead of an
143// external cppreference URL. Used by both the template-head requires
144// clause site (inside buildTemplateDeclSpans) and the trailing requires
145// site (inside buildCppSynopsisSpans).
146//
147// Concept names are matched longest first, so a fully-qualified
148// "ns::Integral" wins against a bare "Integral" when both occur in the
149// same requires clause text. Each matched spelling maps back to its
150// fully-qualified name for lookup, so source text that spells a concept
151// either qualified or unqualified resolves to the same concept page.
152//
153// When no concept name appears in the text, the whole clause is emitted as
154// a single Text span. Concept identifiers are alphanumeric and underscore
155// per the C++ grammar, but the alternation is built through
156// QRegularExpression::escape() for defense in depth.
157void appendRequiresSpansWithLinks(QList<IR::SignatureSpan> &out,
158 const QString &requiresText,
159 const QStringList &conceptNames,
160 const HrefResolver *hrefResolver,
161 const Node *relative)
162{
163 auto emitFallback = [&out, &requiresText]() {
164 IR::SignatureSpan req;
166 req.text = " requires "_L1 + requiresText;
167 out.append(req);
168 };
169
170 if (conceptNames.isEmpty() || requiresText.isEmpty()) {
171 emitFallback();
172 return;
173 }
174
175 QStringList sorted = conceptNames;
176 std::sort(sorted.begin(), sorted.end(),
177 [](const QString &a, const QString &b) { return a.size() > b.size(); });
178
179 // Build a single alternation regex matching any concept name (longest
180 // first) anchored at word boundaries, so longer names take priority and
181 // overlapping matches don't double-emit. Each matched spelling — the
182 // fully-qualified name or its unqualified tail — maps back to the
183 // fully-qualified name the lookup needs.
184 QHash<QString, QString> targetForDisplay;
185 QStringList escapedAlternatives;
186 escapedAlternatives.reserve(sorted.size() * 2);
187 for (const QString &name : sorted) {
188 if (!targetForDisplay.contains(name)) {
189 targetForDisplay.insert(name, name);
190 escapedAlternatives.append(QRegularExpression::escape(name));
191 }
192 const QString tail = name.section("::"_L1, -1);
193 if (tail != name && !targetForDisplay.contains(tail)) {
194 targetForDisplay.insert(tail, name);
195 escapedAlternatives.append(QRegularExpression::escape(tail));
196 }
197 }
198 const QRegularExpression conceptRegex(
199 u"\\b("_s + escapedAlternatives.join(u"|"_s) + u")\\b"_s);
200 if (!conceptRegex.isValid()) {
201 emitFallback();
202 return;
203 }
204
205 auto it = conceptRegex.globalMatch(requiresText);
206 if (!it.hasNext()) {
207 emitFallback();
208 return;
209 }
210
211 // At least one concept matches: emit the " requires " lead-in, then
212 // alternate plain-text runs with concept spans.
213 IR::SignatureSpan lead;
215 lead.text = " requires "_L1;
216 out.append(lead);
217
218 qsizetype pos = 0;
219 while (it.hasNext()) {
220 const auto match = it.next();
221 if (match.capturedStart() > pos) {
222 IR::SignatureSpan textSpan;
223 textSpan.role = IR::SpanRole::Text;
224 textSpan.text = requiresText.mid(pos, match.capturedStart() - pos);
225 out.append(textSpan);
226 }
227 const QString matched = match.captured(1);
228 const QString target = targetForDisplay.value(matched, matched);
229 const Node *cn = findConceptNodeForRelative(relative, target);
230 const QString href = cn ? resolveHref(hrefResolver, cn, relative) : QString();
231
232 IR::SignatureSpan span;
233 span.text = matched;
234 if (href.isEmpty()) {
235 // An undocumented concept, or one whose page can't be located,
236 // renders as plain text rather than a dangling link.
238 } else {
240 span.href = href;
241 }
242 out.append(span);
243 pos = match.capturedEnd();
244 }
245 if (pos < requiresText.size()) {
246 IR::SignatureSpan tail;
248 tail.text = requiresText.mid(pos);
249 out.append(tail);
250 }
251}
252
253} // namespace
254
255namespace NodeExtractor {
256
257/*!
258 \internal
259 \typealias NodeExtractor::SemanticOrigins
260
261 Page-local, never serialized: for each emitted detail section, one entry
262 per emitted member in the same order, pointing at the node on which that
263 member's detail documentation was authored. For a regular member the
264 origin is the member itself; for a member of a SharedCommentNode group it
265 is the SharedCommentNode, because the copied body and see-also text was
266 authored in that comment. A member without an anchorId maps to nullptr,
267 which the link resolver treats as "resolve in page context".
268
269 The list is paired with the extracted detail-section and member order
270 rather than keyed by anchorId: emitted anchors are not unique, so two
271 members (such as a QML type's regular and attached signal of the same
272 name) can share one anchorId. The pairing travels beside the IR values,
273 not inside them.
274*/
275
276/*!
277 \internal
278 Extract page-level metadata from a PageNode into a value-type struct.
279
280 This function reads classification, identity, brief, and body fields
281 from the given PageNode and returns them as an IR::PageMetadata value.
282 Body content is populated via ContentBuilder, which transforms the
283 atom chain into structured content blocks. Format-conditional atoms
284 are skipped unconditionally since the template generator builds a
285 format-agnostic IR.
286
287 For aggregate pages (classes, QML types, namespaces), member listings
288 are extracted via the Sections infrastructure and stored as frozen
289 SectionIR values.
290
291 The caller (TemplateGenerator) invokes this before passing the
292 result to IR::Builder, ensuring Builder never includes PageNode
293 or other Node subclass headers.
294
295 \a origins, when non-null, is populated alongside detail extraction
296 with a page-local origin paired with each emitted detail member, in
297 section and member order, for the template post-processing that
298 resolves links in the authored member context.
299*/
300IR::PageMetadata extractPageMetadata(const PageNode *pn, const HrefResolver *hrefResolver,
301 SemanticOrigins *origins)
302{
303 Q_ASSERT_X(pn, "NodeExtractor::extractPageMetadata",
304 "PageNode pointer must be non-null");
305 IR::PageMetadata pm;
306
307 pm.nodeType = pn->nodeType();
308 pm.genus = pn->genus();
309 pm.status = pn->status();
310 pm.access = pn->access();
311
312 if (pn->isQmlType()) {
313 const auto *qcn = static_cast<const QmlTypeNode *>(pn);
314 QString suffix = qcn->isQmlBasicType() ? " QML Value Type"_L1 : " QML Type"_L1;
315 pm.title = pn->name() + suffix;
316 pm.fullTitle = pm.title;
317 } else if (pn->isClassNode() || pn->isNamespace() || pn->isHeader()) {
318 // plainFullName() produces qualified names for nested aggregates
319 // (e.g. "Outer::Inner"), matching the legacy generator behavior.
320 // For top-level types and headers the result is the same as name().
321 const auto *aggregate = static_cast<const Aggregate *>(pn);
322 pm.fullTitle = aggregate->plainFullName();
323 pm.title = pm.fullTitle;
324 } else {
325 pm.title = pn->title();
326 pm.fullTitle = pn->fullTitle();
327 }
328
329 pm.url = hrefResolver->fileName(pn);
330 const QString baseUrl = Config::instance().get(CONFIG_URL).asString();
331 if (!baseUrl.isEmpty() && !pm.url.isEmpty() && !pm.url.contains("://"_L1)) {
332 pm.url = baseUrl
333 + (baseUrl.endsWith(u'/') ? QString{} : QStringLiteral("/"))
334 + pm.url;
335 }
336 pm.since = pn->since();
337 pm.deprecatedSince = pn->deprecatedSince();
338 if (const auto deprecation = extractDeprecationData(pn)) {
339 pm.typeNoun = deprecation->typeNoun;
340 pm.deprecatedSinceQualified = deprecation->deprecatedSinceQualified;
341 pm.deprecationNote = extractDeprecationNote(pn);
342 }
343 pm.brief = pn->doc().briefText().toString();
344
345 const Text &bodyText = pn->doc().body();
346 if (const Atom *firstAtom = bodyText.firstAtom()) {
347 // Offset section heading levels to account for page structure.
348 // QDoc's \section1 maps to level 1, but pages already use <h1>
349 // for the title. The legacy generators apply a node-type-dependent
350 // offset; we replicate the same mapping here.
351 const int headingOffset = [&] {
352 switch (pn->nodeType()) {
354 case NodeType::Class:
355 case NodeType::Struct:
356 case NodeType::Union:
357 case NodeType::Module:
358 return 2;
362 case NodeType::Page:
363 case NodeType::Group:
364 return 1;
365 default:
366 return 3;
367 }
368 }();
369 IR::ContentBuilder contentBuilder(IR::BriefHandling::Skip, headingOffset,
370 diagnosticHandlerFor(pn));
371 pm.body = contentBuilder.build(firstAtom);
372 }
373
374 if (pn->isAggregate()) {
375 const auto *aggregate = static_cast<const Aggregate *>(pn);
376 pm.summarySections = extractSummarySections(aggregate, hrefResolver);
377 pm.detailSections = extractDetailSections(aggregate, hrefResolver, origins);
378 }
379
380 if (pn->isQmlType()) {
381 const auto *qcn = static_cast<const QmlTypeNode *>(pn);
382 pm.qmlTypeData = extractQmlTypeData(qcn, hrefResolver);
383 }
384
385 if (pn->isCollectionNode()) {
386 const auto *cn = static_cast<const CollectionNode *>(pn);
387 pm.collectionData = extractCollectionData(cn, hrefResolver);
388 }
389
390 if (pn->isClassNode() || pn->isNamespace() || pn->isHeader()) {
391 const auto *aggregate = static_cast<const Aggregate *>(pn);
392 pm.cppReferenceData = extractCppReferenceData(aggregate, hrefResolver);
393 }
394
395 pm.navigationData = extractNavigationData(pn, hrefResolver);
396
397 return pm;
398}
399
400/*!
401 \internal
402 Extract QML type metadata from a QmlTypeNode.
403
404 Populates import statement, inheritance chain, inherited-by list,
405 native C++ type link, and singleton/value-type flags. InclusionFilter
406 is applied to match the legacy generator's visibility filtering.
407
408 hasObsoleteMembers reports whether any section holds deprecated
409 members, the same check the legacy QML generator applies before
410 generating its obsolete sub-page. The check walks the section
411 distribution rather than only direct children so members inherited
412 from an abstract base type count as well.
413*/
414IR::QmlTypeData extractQmlTypeData(const QmlTypeNode *qcn, const HrefResolver *hrefResolver)
415{
416 IR::QmlTypeData data;
417 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
418
419 if (!qcn->logicalModuleName().isEmpty()) {
420 bool includeImport = true;
421 const CollectionNode *collection = qcn->logicalModule();
422 if (collection) {
423 const NodeContext context = collection->createContext();
424 includeImport = InclusionFilter::isIncluded(policy, context);
425 }
426 if (includeImport) {
427 QStringList parts = QStringList()
428 << "import"_L1 << qcn->logicalModuleName() << qcn->logicalModuleVersion();
429 data.importStatement = parts.join(' '_L1).trimmed();
430 }
431 }
432
435
436 QmlTypeNode *base = qcn->qmlBaseNode();
437 while (base) {
438 const NodeContext context = base->createContext();
439 if (InclusionFilter::isIncluded(policy, context))
440 break;
441 base = base->qmlBaseNode();
442 }
443
444 NodeList subs;
445 QmlTypeNode::subclasses(qcn, subs, true);
446
447 if (base) {
448 IR::QmlTypeData::InheritsInfo inheritsInfo;
449 inheritsInfo.name = base->name();
450 inheritsInfo.href = resolveHref(hrefResolver, base, qcn);
451 const CollectionNode *baseModule = base->logicalModule();
452 if (baseModule) {
453 const NodeContext moduleContext = baseModule->createContext();
454 if (InclusionFilter::isIncluded(policy, moduleContext))
455 inheritsInfo.moduleName = base->logicalModuleName();
456 }
457 data.inherits = inheritsInfo;
458 }
459
460 if (!subs.isEmpty()) {
461 QList<IR::QmlTypeData::InheritedByEntry> filteredSubs;
462 for (const auto *sub : std::as_const(subs)) {
463 const NodeContext context = sub->createContext();
464 if (InclusionFilter::isIncluded(policy, context))
465 filteredSubs.append({sub->name(), resolveHref(hrefResolver, sub, qcn)});
466 }
467 std::sort(filteredSubs.begin(), filteredSubs.end(),
468 [](const IR::QmlTypeData::InheritedByEntry &a,
469 const IR::QmlTypeData::InheritedByEntry &b) {
470 return a.name < b.name;
471 });
472 data.inheritedBy = filteredSubs;
473 }
474
475 ClassNode *cn = qcn->classNode();
476 if (cn && cn->isQmlNativeType()) {
477 const NodeContext context = cn->createContext();
478 if (InclusionFilter::isIncluded(policy, context))
479 data.nativeType = IR::QmlTypeData::NativeTypeInfo{cn->name(), resolveHref(hrefResolver, cn, qcn)};
480 }
481
482 SectionPtrVector obsoleteSummary;
483 SectionPtrVector obsoleteDetail;
484 Sections sections(qcn);
485 data.hasObsoleteMembers = sections.hasObsoleteMembers(&obsoleteSummary, &obsoleteDetail);
486
487 return data;
488}
489
490/*!
491 \internal
492 Extract collection metadata from a CollectionNode.
493
494 Populates module identity, CMake/qmake build variables, technology
495 preview state, and pre-sorted member listings. For C++ modules,
496 members are categorized into separate namespace and class lists.
497 For groups and QML modules, a single flat member list is produced.
498
499 All member lists are filtered through InclusionFilter (excluding
500 internal entries) and exclude deprecated nodes, then sorted
501 alphabetically by name (case-insensitive).
502*/
503IR::CollectionData extractCollectionData(const CollectionNode *cn, const HrefResolver *hrefResolver)
504{
505 IR::CollectionData data;
506
507 data.logicalModuleName = cn->logicalModuleName();
508 data.logicalModuleVersion = cn->logicalModuleVersion();
509 data.qtVariable = cn->qtVariable();
510
511 // CMake metadata synthesis. Documenters can declare CMake info
512 // through several command shapes (\cmakepackage, \cmakecomponent,
513 // \cmaketargetitem and the Qt-specific \qtcmakepackage and
514 // \qtcmaketargetitem) that populate different combinations of
515 // the package, component and target fields on the CollectionNode.
516 // Synthesize the package as Qt<major-version> when only a
517 // component is declared, so module pages render coherent
518 // find_package snippets for both the generic and Qt-flavored
519 // command families. The target_link_libraries line is
520 // synthesized only when a component is also available — a bare
521 // package name does not imply a target named package::package,
522 // so packages without a component leave the target empty and
523 // the template suppresses the target_link_libraries clause.
524 // When no field is set, leave the data fields empty so the
525 // template suppresses the CMake row entirely.
526 const QString rawCmakePackage = cn->cmakePackage();
527 const QString rawCmakeComponent = cn->cmakeComponent();
528 const QString rawCmakeTargetItem = cn->cmakeTargetItem();
529 if (!rawCmakePackage.isEmpty() || !rawCmakeComponent.isEmpty()) {
530 const QString package = rawCmakePackage.isEmpty()
531 ? "Qt"_L1 + QString::number(QT_VERSION_MAJOR)
532 : rawCmakePackage;
533 data.cmakePackage = package;
534 data.cmakeComponent = rawCmakeComponent;
535 if (!rawCmakeTargetItem.isEmpty())
536 data.cmakeTargetItem = rawCmakeTargetItem;
537 else if (!rawCmakeComponent.isEmpty())
538 data.cmakeTargetItem = package + "::"_L1 + rawCmakeComponent;
539 }
540
541 data.state = cn->state();
542
543 data.isModule = cn->isModule();
544 data.isQmlModule = cn->isQmlModule();
545 data.isGroup = cn->isGroup();
546 data.isConcept = cn->isConcept();
547 data.noAutoList = cn->noAutoList();
548
549 if (cn->noAutoList())
550 return data;
551
552 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
553
554 auto makeMemberEntry = [hrefResolver, cn](const Node *node) -> IR::CollectionData::MemberEntry {
555 return { node->name(), resolveHref(hrefResolver, node, cn), node->doc().briefText().toString() };
556 };
557
558 auto sortEntries = [](QList<IR::CollectionData::MemberEntry> &entries) {
559 std::sort(entries.begin(), entries.end(),
560 [](const IR::CollectionData::MemberEntry &a,
561 const IR::CollectionData::MemberEntry &b) {
562 return a.name.compare(b.name, Qt::CaseInsensitive) < 0;
563 });
564 };
565
566 if (cn->isModule()) {
568 for (auto *node : nsMap.values()) {
569 const NodeContext context = node->createContext();
570 if (InclusionFilter::isIncluded(policy, context) && !node->isDeprecated())
571 data.namespaces.append(makeMemberEntry(node));
572 }
573 sortEntries(data.namespaces);
574
575 const NodeMap classMap = cn->getMembers([](const Node *n) { return n->isClassNode(); });
576 for (auto *node : classMap.values()) {
577 const NodeContext context = node->createContext();
578 if (InclusionFilter::isIncluded(policy, context) && !node->isDeprecated())
579 data.classes.append(makeMemberEntry(node));
580 }
581 sortEntries(data.classes);
582 } else {
583 for (const auto *node : cn->members()) {
584 if (!node->isInAPI())
585 continue;
586 const NodeContext context = node->createContext();
587 if (InclusionFilter::isIncluded(policy, context) && !node->isDeprecated())
588 data.members.append(makeMemberEntry(node));
589 }
590 sortEntries(data.members);
591 }
592
593 return data;
594}
595
597 const HrefResolver *hrefResolver,
598 const Node *relative);
599
600/*!
601 \internal
602 Extract C++ reference page metadata from a class, namespace, or header.
603
604 Reads requisite table fields (header include, build-system snippets,
605 status), inheritance hierarchies, template declarations, comparison
606 operators, thread-safeness, and group associations. The result is a
607 value-type struct that captures everything the template generator needs
608 to render the requisites table and secondary sections without touching
609 the Node tree at render time.
610
611 All three aggregate page types (ClassNode, NamespaceNode, HeaderNode)
612 are handled, with ClassNode-specific sections gated on isClassNode().
613*/
614IR::CppReferenceData extractCppReferenceData(const Aggregate *aggregate, const HrefResolver *hrefResolver)
615{
616 IR::CppReferenceData data;
618
619 data.isNamespace = aggregate->isNamespace();
620 data.isHeader = aggregate->isHeader();
621 data.isInnerClass = aggregate->parent() && aggregate->parent()->isClassNode();
622 data.typeWord = aggregate->typeWord(false);
624
625 auto ancestors = aggregate->plainFullName().split("::"_L1);
626 ancestors.pop_back();
627 data.ancestorNames = ancestors;
628
629 if (aggregate->includeFile())
630 data.headerInclude = *aggregate->includeFile();
631
632 if (!aggregate->physicalModuleName().isEmpty()) {
633 const CollectionNode *cn =
634 qdb->getCollectionNode(aggregate->physicalModuleName(), NodeType::Module);
635 if (cn && (!cn->cmakeComponent().isEmpty() || !cn->cmakePackage().isEmpty())) {
636 const QString package = cn->cmakePackage().isEmpty()
637 ? "Qt"_L1 + QString::number(QT_VERSION_MAJOR)
638 : cn->cmakePackage();
639 QString findPkg;
640 if (cn->cmakeComponent().isEmpty())
641 findPkg = "find_package("_L1 + package + " REQUIRED)"_L1;
642 else
643 findPkg = "find_package("_L1 + package + " REQUIRED COMPONENTS "_L1
644 + cn->cmakeComponent() + ")"_L1;
645
646 QString target;
647 if (!cn->cmakeTargetItem().isEmpty()) {
648 target = cn->cmakeTargetItem();
649 } else if (cn->cmakeComponent().isEmpty()) {
650 target = package + "::"_L1 + package;
651 } else {
652 target = package + "::"_L1 + cn->cmakeComponent();
653 }
654
655 data.cmakeFindPackage = findPkg;
656 data.cmakeTargetLinkLibraries =
657 "target_link_libraries(mytarget PRIVATE "_L1 + target + ")"_L1;
658 }
659 if (cn && !cn->qtVariable().isEmpty())
660 data.qmakeVariable = "QT += "_L1 + cn->qtVariable();
661 }
662
663 auto statusOpt = formatStatus(aggregate, qdb);
664 if (statusOpt) {
665 data.statusText = *statusOpt;
666 if (aggregate->status() == Status::Deprecated)
667 data.statusCssClass = "deprecated"_L1;
668 else if (!aggregate->deprecatedSince().isEmpty())
669 data.statusCssClass = "pending-deprecation"_L1;
670 else if (aggregate->status() == Status::Preliminary)
671 data.statusCssClass = "preliminary"_L1;
672 else
673 data.statusCssClass = "status"_L1;
674 }
675
676 if (aggregate->isClassNode()) {
677 auto *classNode = const_cast<ClassNode *>(static_cast<const ClassNode *>(aggregate));
678
679 if (classNode->isQmlNativeType()) {
680 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
681 const NodeContext context = classNode->createContext();
682 if (InclusionFilter::isIncluded(policy, context)) {
683 QList<QmlTypeNode *> nativeTypes{classNode->qmlNativeTypes().cbegin(),
684 classNode->qmlNativeTypes().cend()};
685 if (!nativeTypes.isEmpty()) {
686 std::sort(nativeTypes.begin(), nativeTypes.end(), Node::nodeNameLessThan);
687 data.qmlNativeType = IR::CppReferenceData::QmlNativeTypeLink{
688 nativeTypes.first()->name(),
689 resolveHref(hrefResolver, nativeTypes.first(), aggregate)
690 };
691 }
692 }
693 }
694
695 const auto *metaTags = classNode->doc().metaTagMap();
696 if (metaTags && metaTags->contains(u"qdoc-suppress-inheritance"_s))
697 data.suppressInheritance = true;
698
699 if (!data.suppressInheritance) {
700 const auto &baseClasses = classNode->baseClasses();
701 for (const auto &bc : baseClasses) {
702 if (bc.m_node) {
703 data.baseClasses.append({
704 bc.m_node->plainFullName(),
705 resolveHref(hrefResolver, bc.m_node, aggregate),
706 bc.m_access
707 });
708 }
709 }
710
711 const auto &derivedClasses = classNode->derivedClasses();
712 for (const auto &dc : derivedClasses) {
713 if (dc.m_node) {
714 data.derivedClasses.append({
715 dc.m_node->plainFullName(),
716 resolveHref(hrefResolver, dc.m_node, aggregate)
717 });
718 }
719 }
720 std::sort(data.derivedClasses.begin(), data.derivedClasses.end(),
723 return a.name.compare(b.name, Qt::CaseInsensitive) < 0;
724 });
725 }
726 }
727
728 if (aggregate->templateDecl()) {
729 const auto &templateDecl = *aggregate->templateDecl();
730 data.templateDeclSpans = buildTemplateDeclSpans(&templateDecl, hrefResolver, aggregate);
731 data.referencedConcepts.reserve(int(templateDecl.referenced_concepts.size()));
732 for (const auto &s : templateDecl.referenced_concepts)
733 data.referencedConcepts.append(QString::fromStdString(s));
734 }
735
736 const auto selfCategory = aggregate->comparisonCategory();
737 if (selfCategory != ComparisonCategory::None)
738 data.selfComparisonCategory = QString::fromStdString(comparisonCategoryAsString(selfCategory));
739
740 const auto *comparesMap = aggregate->doc().comparesWithMap();
741 if (comparesMap && !comparesMap->isEmpty()) {
742 for (auto [key, description] : comparesMap->asKeyValueRange()) {
743 IR::CppReferenceData::ComparisonEntry entry;
744 entry.category = QString::fromStdString(comparisonCategoryAsString(key));
745
746 const QStringList types{description.firstAtom()->string().split(';'_L1)};
747 entry.comparableTypes = types;
748
749 if (description.firstAtom()->next() != description.lastAtom()) {
750 Text descText = Text::subText(description.firstAtom()->next(),
751 description.lastAtom());
752 entry.description = descText.toString();
753 }
754 data.comparisonEntries.append(entry);
755 }
756 }
757
758 Node::ThreadSafeness ts = aggregate->threadSafeness();
759 if (ts != Node::UnspecifiedSafeness) {
761 switch (ts) {
763 tsInfo.level = "non-reentrant"_L1;
764 break;
765 case Node::Reentrant:
766 tsInfo.level = "reentrant"_L1;
767 break;
768 case Node::ThreadSafe:
769 tsInfo.level = "thread-safe"_L1;
770 break;
771 default:
772 break;
773 }
774
775 NodeList reentrant, threadsafe, nonreentrant;
776 bool hasExceptions = false;
777 for (const auto *child : aggregate->childNodes()) {
778 if (!child->isDeprecated()) {
779 switch (child->threadSafeness()) {
780 case Node::Reentrant:
781 reentrant.append(const_cast<Node *>(child));
782 if (ts == Node::ThreadSafe) hasExceptions = true;
783 break;
784 case Node::ThreadSafe:
785 threadsafe.append(const_cast<Node *>(child));
786 if (ts == Node::Reentrant) hasExceptions = true;
787 break;
788 case Node::NonReentrant:
789 nonreentrant.append(const_cast<Node *>(child));
790 hasExceptions = true;
791 break;
792 default:
793 break;
794 }
795 }
796 }
797 if (hasExceptions) {
798 for (const auto *node : std::as_const(reentrant)) {
799 tsInfo.reentrantExceptions.append({
800 node->plainFullName(),
801 resolveHref(hrefResolver, node, aggregate)
802 });
803 }
804 for (const auto *node : std::as_const(threadsafe)) {
805 tsInfo.threadSafeExceptions.append({
806 node->plainFullName(),
807 resolveHref(hrefResolver, node, aggregate)
808 });
809 }
810 for (const auto *node : std::as_const(nonreentrant)) {
811 tsInfo.nonReentrantExceptions.append({
812 node->plainFullName(),
813 resolveHref(hrefResolver, node, aggregate)
814 });
815 }
816 }
817 data.threadSafety = std::move(tsInfo);
818 }
819
820 const QStringList &groupNames = aggregate->groupNames();
821 if (!groupNames.isEmpty()) {
822 const auto &groupMap = qdb->groups();
823 for (const auto &groupName : groupNames) {
824 auto it = groupMap.find(groupName);
825 if (it == groupMap.end() || !*it)
826 continue;
827 CollectionNode *group = *it;
828 // TODO: mergeCollections() mutates the node tree during
829 // extraction, violating the principle that the new pipeline
830 // reads without side effects. Replace with an eager merge
831 // pass that runs before generation begins.
832 qdb->mergeCollections(group);
833 if (group->wasSeen()) {
834 data.groups.append({
835 group->fullTitle(),
836 resolveHref(hrefResolver, group, aggregate)
837 });
838 }
839 }
840 }
841
842 if (aggregate->isNamespace()) {
843 const auto *ns = static_cast<const NamespaceNode *>(aggregate);
844 if (!ns->hasDoc() && ns->docNode()) {
845 data.isPartialNamespace = true;
846 data.fullNamespaceHref = resolveHref(hrefResolver, ns->docNode(), aggregate);
847 data.fullNamespaceModuleName = ns->docNode()->tree()->camelCaseModuleName();
848 }
849 }
850
851 return data;
852}
853
854/*!
855 \internal
856 Build categorized summary sections for an aggregate node.
857
858 Delegates to the Sections class for member distribution, then extracts
859 results into frozen SectionIR values. The section variant (C++ class,
860 QML type, or generic) is chosen based on the aggregate's node type.
861*/
862QList<IR::SectionIR> extractSummarySections(const Aggregate *aggregate, const HrefResolver *hrefResolver)
863{
864 Sections sections(aggregate);
865
866 const auto &sv = sections.summarySections();
867
868 QList<IR::SectionIR> result;
869 for (const auto &section : sv) {
870 if (section.isEmpty())
871 continue;
872
873 IR::SectionIR irSection;
874 irSection.title = section.title();
875 irSection.id = TextUtils::asAsciiPrintable(section.title());
876 irSection.singular = section.singular();
877 irSection.plural = section.plural();
878
879 // SharedCommentNode groups several declarations under one doc comment.
880 // Expand them into individual MemberIR entries so each function appears
881 // in the member table. This means the IR member count may exceed the
882 // Section::members() count.
883 for (const auto *member : section.members()) {
884 if (member->isSharedCommentNode()) {
885 const auto *scn = static_cast<const SharedCommentNode *>(member);
886 for (const auto *child : scn->collective()) {
887 IR::MemberIR irMember = extractMemberIR(child, hrefResolver, aggregate);
888 irMember.href = "#"_L1 + hrefResolver->anchorForNode(child);
889 irSection.members.append(irMember);
890 }
891 } else {
892 IR::MemberIR irMember = extractMemberIR(member, hrefResolver, aggregate);
893 irMember.href = "#"_L1 + hrefResolver->anchorForNode(member);
894 irSection.members.append(irMember);
895 }
896 }
897
898 for (const auto *reimpl : section.reimplementedMembers())
899 irSection.reimplementedMembers.append(extractMemberIR(reimpl, hrefResolver, aggregate));
900
901 for (const auto &[base, count] : section.inheritedMembers()) {
902 IR::InheritedMembersIR inherited;
903 inherited.className = base->plainFullName();
904 inherited.count = count;
905 inherited.href = resolveHref(hrefResolver, base, aggregate);
906 irSection.inheritedMembers.append(inherited);
907 }
908
909 result.append(irSection);
910 }
911 return result;
912}
913
914/*!
915 \internal
916 Build categorized detail sections for an aggregate node.
917
918 Iterates Sections::detailsSections() and extracts full member
919 documentation including body content, anchor IDs, and metadata.
920 SharedCommentNode groups share a single documentation body across
921 their children; the body and see-also list are stored once on the
922 section's shared detail group, which references its members
923 positionally and carries the group's own anchor when it has one
924 (named QML property groups do), while each child keeps its own
925 anchorId, synopsis, and per-member fields with an empty body and
926 see-also list. Because one page fragment may own only one
927 destination, a group anchor that collides with a member anchor or
928 with an earlier group's anchor on the same page is dropped.
929
930 \a kind selects current or obsolete members. Both selections retain
931 shared detail groups and their semantic origins.
932
933 \a origins, when non-null, receives one entry per emitted detail
934 member, paired with the member order of each emitted section: the
935 node the member's detail documentation was authored on — the member
936 itself, or the SharedCommentNode for copied shared text. A member
937 without an anchorId maps to nullptr; its content resolves in page
938 context. Emitted anchors are not unique (a QML type's regular and
939 attached signal of the same name share one), so the pairing is
940 positional rather than keyed by anchorId.
941*/
942QList<IR::SectionIR> extractDetailSections(const Aggregate *aggregate, const HrefResolver *hrefResolver,
943 SemanticOrigins *origins, DetailSectionKind kind)
944{
945 Sections sections(aggregate);
946 const auto &sv = sections.detailsSections();
947
948 QList<IR::SectionIR> result;
949 for (const auto &section : sv) {
950 const auto &members = kind == DetailSectionKind::Obsolete
951 ? section.obsoleteMembers() : section.members();
952 if (members.isEmpty())
953 continue;
954
955 IR::SectionIR irSection;
956 irSection.title = section.title();
957 irSection.id = TextUtils::asAsciiPrintable(section.title());
958 irSection.singular = section.singular();
959 irSection.plural = section.plural();
960
961 // Paired with irSection.members: the node each member's detail
962 // documentation was authored on (nullptr without an anchor).
963 QList<const Node *> sectionOrigins;
964
965 for (const auto *member : members) {
966 if (member->isSharedCommentNode()) {
967 const auto *scn = static_cast<const SharedCommentNode *>(member);
968
969 // The body and see-also list are authored on the shared
970 // comment, not on any one child, so they are stored once
971 // on the group, which the templates render after the
972 // group's last member.
973 IR::SharedDetailGroup group;
974 group.firstIndex = static_cast<int>(irSection.members.size());
975 group.count = static_cast<int>(scn->collective().size());
976 group.status = scn->status();
977 group.isPlural = !scn->isPropertyGroup() && group.count > 1;
978 // A named QML property group is itself a link target, so
979 // the group carries its own anchor (such as "font-prop")
980 // beside its children's. Anonymous shared comments have
981 // none; anchorForNode returns an empty string for them.
982 group.anchorId = hrefResolver->anchorForNode(scn);
983 if (const auto deprecation = extractDeprecationData(scn)) {
984 group.deprecatedSince = deprecation->deprecatedSince;
985 group.deprecatedSinceQualified = deprecation->deprecatedSinceQualified;
986 const Node *described = group.isPlural ? scn->collective().first() : scn;
987 const auto number = group.isPlural ? NodeText::GrammaticalNumber::Plural
988 : NodeText::GrammaticalNumber::Singular;
989 group.typeNoun = NodeText::nodeTypeDescription(described, number);
990 group.deprecationNote = extractDeprecationNote(scn);
991 }
992
993 const Text &bodyText = scn->doc().body();
994 if (const Atom *firstAtom = bodyText.firstAtom()) {
995 IR::ContentBuilder contentBuilder(IR::BriefHandling::Include, 0,
996 diagnosticHandlerFor(scn));
997 group.body = contentBuilder.build(firstAtom);
998 }
999
1000 const QList<Text> &alsoTexts = scn->doc().alsoList();
1001 for (const Text &alsoText : alsoTexts) {
1002 if (const Atom *firstAtom = alsoText.firstAtom()) {
1003 IR::ContentBuilder contentBuilder(IR::BriefHandling::Include, 0,
1004 diagnosticHandlerFor(scn));
1005 group.alsoList.append(contentBuilder.build(firstAtom));
1006 }
1007 }
1008
1009 for (const auto *child : scn->collective()) {
1010 IR::MemberIR irMember = extractMemberIR(child, hrefResolver, aggregate, MemberExtractionLevel::Detail);
1011 // The child shares the group's comment; its body,
1012 // deprecation note, and see-also list belong to the group,
1013 // which renders them once, so the member carries only
1014 // the group's index.
1015 irMember.body.clear();
1016 irMember.deprecationNote.clear();
1017 irMember.alsoList.clear();
1018 irMember.sharedGroup = static_cast<int>(irSection.sharedGroups.size());
1019 // The shared text was authored in the shared comment,
1020 // not on the child; resolve it in that context.
1021 sectionOrigins.append(irMember.anchorId.isEmpty() ? nullptr : scn);
1022 irSection.members.append(irMember);
1023 }
1024 irSection.sharedGroups.append(group);
1025 } else {
1026 IR::MemberIR irMember = extractMemberIR(member, hrefResolver, aggregate, MemberExtractionLevel::Detail);
1027 sectionOrigins.append(irMember.anchorId.isEmpty() ? nullptr : member);
1028 irSection.members.append(irMember);
1029 }
1030 }
1031
1032 if (origins)
1033 origins->append(std::move(sectionOrigins));
1034 result.append(irSection);
1035 }
1036
1037 // A named QML property group emits its own anchor (such as
1038 // "font-prop") beside its children's, but one page fragment may
1039 // own only one destination. An ordinary member documented on the
1040 // page keeps the anchor it already owns, and a group rendered
1041 // earlier keeps it over a later group with the same anchor, so a
1042 // colliding group anchor is dropped rather than duplicated.
1043 QSet<QString> ownedAnchors;
1044 for (const auto &section : result)
1045 for (const auto &member : section.members)
1046 if (!member.anchorId.isEmpty())
1047 ownedAnchors.insert(member.anchorId);
1048
1049 for (auto &section : result)
1050 for (auto &group : section.sharedGroups) {
1051 if (group.anchorId.isEmpty())
1052 continue;
1053 if (ownedAnchors.contains(group.anchorId))
1054 group.anchorId.clear();
1055 else
1056 ownedAnchors.insert(group.anchorId);
1057 }
1058
1059 return result;
1060}
1061
1063{
1064 switch (ts) {
1065 case Node::Reentrant:
1066 return "reentrant"_L1;
1067 case Node::ThreadSafe:
1068 return "thread-safe"_L1;
1069 default:
1070 return {};
1071 }
1072}
1073
1074/*!
1075 \internal
1076 Replace the text of each constant in the value tables of \a blocks with
1077 the value qualified to the enum's declaration scope, so that the
1078 template generators display the same constant names as the HTML, WebXML,
1079 and DocBook generators. Value tables of non-enum nodes, such as
1080 enumeration properties, keep their authored spelling.
1081*/
1082static void qualifyEnumValueTerms(const EnumNode *en, QList<IR::ContentBlock> &blocks)
1083{
1084 for (auto &block : blocks) {
1085 if (block.type == IR::BlockType::DefinitionList
1086 && block.attributes.value(QLatin1String("listType"))
1087 == QLatin1String(ATOM_LIST_VALUE)) {
1088 for (auto &entry : block.children) {
1089 if (entry.type != IR::BlockType::DefinitionTerm || entry.inlineContent.isEmpty())
1090 continue;
1091 QString raw;
1092 for (const IR::InlineContent &content : entry.inlineContent)
1093 raw += content.plainText();
1094 const QString qualified = en->qualifiedValueName(raw);
1095 if (qualified != raw) {
1096 IR::InlineContent text;
1097 text.type = IR::InlineType::Text;
1098 text.text = qualified;
1099 entry.inlineContent = { text };
1100 }
1101 }
1102 }
1103 qualifyEnumValueTerms(en, block.children);
1104 }
1105}
1106
1107/*!
1108 \internal
1109 Build a MemberIR from a single Node.
1110
1111 Extracts identity, classification, and type-specific data from the node.
1112 FunctionNode provides signatures, parameters, and overload metadata.
1113 EnumNode provides scoped/unscoped signature and enum value listings.
1114 PropertyNode provides a qualified data type signature.
1115
1116 When \a level is MemberExtractionLevel::Detail, also populates
1117 detail documentation fields: anchorId, synopsis, since,
1118 threadSafety, comparisonCategory, noexcept metadata, body (via
1119 ContentBuilder), and alsoList.
1120*/
1121IR::MemberIR extractMemberIR(const Node *node, const HrefResolver *hrefResolver, const Node *relative, MemberExtractionLevel level)
1122{
1123 const bool includeDetail = (level == MemberExtractionLevel::Detail);
1124 IR::MemberIR member;
1125
1126 member.name = node->name();
1127 member.fullName = node->plainFullName();
1128 member.href = resolveHref(hrefResolver, node, relative);
1129 member.brief = node->doc().briefText().toString();
1130
1131 member.nodeType = node->nodeType();
1132 member.access = node->access();
1133 member.status = node->status();
1134 if (const auto deprecation = extractDeprecationData(node)) {
1135 member.deprecatedSince = deprecation->deprecatedSince;
1136 member.typeNoun = deprecation->typeNoun;
1137 member.deprecatedSinceQualified = deprecation->deprecatedSinceQualified;
1138 }
1139
1140 if (node->isFunction()) {
1141 const auto *fn = static_cast<const FunctionNode *>(node);
1142 member.signature = fn->signature(
1144 member.isStatic = fn->isStatic();
1145 member.isConst = fn->isConst();
1146 member.isVirtual = !fn->isNonvirtual();
1147 member.isSignal = fn->isSignal();
1148 member.isSlot = fn->isSlot();
1149 member.overloadNumber = fn->overloadNumber();
1150 member.isPrimaryOverload = fn->isPrimaryOverload();
1151
1152 const Parameters &params = fn->parameters();
1153 for (int i = 0; i < params.count(); ++i) {
1154 IR::ParameterIR param;
1155 param.type = params.at(i).type();
1156 param.name = params.at(i).name();
1157 param.defaultValue = params.at(i).defaultValue();
1158 member.parameters.append(param);
1159 }
1160 } else if (node->isEnumType()) {
1161 const auto *en = static_cast<const EnumNode *>(node);
1162 member.signature = en->isScoped()
1163 ? "enum class %1"_L1.arg(en->name())
1164 : "enum %1"_L1.arg(en->name());
1165
1166 for (const auto &item : en->items()) {
1167 IR::EnumValueIR ev;
1168 ev.name = item.name();
1169 ev.value = item.value();
1170 ev.since = item.since();
1171 member.enumValues.append(ev);
1172 }
1173 } else if (node->isQmlProperty()) {
1174 const auto *qpn = static_cast<const QmlPropertyNode *>(node);
1175 member.signature = qpn->name() + " : "_L1 + qpn->dataType();
1176 member.dataType = qpn->dataType();
1177 member.isAttached = qpn->isAttached();
1178 member.isDefault = qpn->isDefault();
1179 member.isReadOnly = qpn->isReadOnly();
1180 member.isRequired = qpn->isRequired();
1181 } else if (node->isProperty()) {
1182 const auto *pn = static_cast<const PropertyNode *>(node);
1183 member.signature = pn->name() + " : "_L1 + pn->qualifiedDataType();
1184 } else if (node->isTypedef()) {
1185 const auto *td = static_cast<const TypedefNode *>(node);
1186 member.signature = td->associatedEnum()
1187 ? "flags "_L1 + td->name()
1188 : td->name();
1189 } else if (node->nodeType() == NodeType::Variable) {
1190 const auto *vn = static_cast<const VariableNode *>(node);
1191 member.signature = vn->leftType() + vn->name() + vn->rightType();
1192 } else {
1193 member.signature = node->name();
1194 }
1195
1196 if (includeDetail) {
1197 if (!member.typeNoun.isEmpty())
1198 member.deprecationNote = extractDeprecationNote(node);
1199 member.anchorId = hrefResolver->anchorForNode(node);
1200 member.synopsis = member.signature;
1201 member.since = node->since();
1202 member.threadSafety = threadSafenessString(node->threadSafeness());
1203
1205 if (!catStr.empty())
1206 member.comparisonCategory = QString::fromStdString(catStr);
1207
1208 if (node->isFunction()) {
1209 const auto *fn = static_cast<const FunctionNode *>(node);
1210 const auto &noexcept_ = fn->getNoexcept();
1211 if (noexcept_) {
1212 member.isNoexcept = true;
1213 member.noexceptNote = *noexcept_;
1214 }
1215 }
1216
1217 const Text &bodyText = node->doc().body();
1218 if (const Atom *firstAtom = bodyText.firstAtom()) {
1219 IR::ContentBuilder contentBuilder(IR::BriefHandling::Include, 0,
1220 diagnosticHandlerFor(node));
1221 member.body = contentBuilder.build(firstAtom);
1222 if (node->isEnumType())
1223 qualifyEnumValueTerms(static_cast<const EnumNode *>(node), member.body);
1224 }
1225
1226 const QList<Text> &alsoTexts = node->doc().alsoList();
1227 for (const Text &alsoText : alsoTexts) {
1228 if (const Atom *firstAtom = alsoText.firstAtom()) {
1229 IR::ContentBuilder contentBuilder(IR::BriefHandling::Include, 0,
1230 diagnosticHandlerFor(node));
1231 QList<IR::ContentBlock> blocks = contentBuilder.build(firstAtom);
1232 member.alsoList.append(blocks);
1233 }
1234 }
1235 }
1236
1237 Section::Style spanStyle = includeDetail ? Section::Details : Section::Summary;
1238 member.signatureSpans = buildSignatureSpans(node, hrefResolver, relative, spanStyle);
1239
1240 return member;
1241}
1242
1243static QList<IR::SignatureSpan> buildTypeSpans(const QString &typeString)
1244{
1245 QList<IR::SignatureSpan> spans;
1246 QString pendingWord;
1247
1248 for (int i = 0; i <= typeString.size(); ++i) {
1249 QChar ch;
1250 if (i != typeString.size())
1251 ch = typeString.at(i);
1252
1253 QChar lower = ch.toLower();
1254 if ((lower >= 'a'_L1 && lower <= 'z'_L1) || ch.digitValue() >= 0
1255 || ch == '_'_L1 || ch == ':'_L1) {
1256 pendingWord += ch;
1257 } else {
1258 if (!pendingWord.isEmpty()) {
1259 bool isProbablyType = (pendingWord != "const"_L1);
1260 IR::SignatureSpan span;
1261 span.role = isProbablyType ? IR::SpanRole::Type : IR::SpanRole::Text;
1262 span.text = pendingWord;
1263 spans.append(span);
1264 }
1265 pendingWord.clear();
1266
1267 if (!ch.isNull()) {
1268 IR::SignatureSpan span;
1270 span.text = QString(ch);
1271 spans.append(span);
1272 }
1273 }
1274 }
1275 return spans;
1276}
1277
1279{
1280 QString extraStr = CodeMarker::extraSynopsis(node, style);
1281 if (extraStr.isEmpty())
1282 return {};
1283
1284 // extraSynopsis may contain <@extref target="...">text</@extref> tags for
1285 // cppreference links. Parse those into ExternalRef spans; everything else
1286 // becomes Extra spans.
1287 static const QRegularExpression extrefRegex(
1288 u"<@extref target=\"([^\"]+)\">([^<]+)</@extref>"_s);
1289
1290 QList<IR::SignatureSpan> spans;
1291 IR::SignatureSpan wrapper;
1292 wrapper.role = IR::SpanRole::Extra;
1293
1294 qsizetype pos = 0;
1295 auto it = extrefRegex.globalMatch(extraStr);
1296 while (it.hasNext()) {
1297 auto match = it.next();
1298 if (match.capturedStart() > pos) {
1299 IR::SignatureSpan textSpan;
1300 textSpan.role = IR::SpanRole::Text;
1301 textSpan.text = extraStr.mid(pos, match.capturedStart() - pos);
1302 wrapper.children.append(textSpan);
1303 }
1304 IR::SignatureSpan ref;
1306 ref.text = match.captured(2);
1307 ref.href = "https://en.cppreference.com/w/cpp/language/"_L1 + match.captured(1);
1308 wrapper.children.append(ref);
1309 pos = match.capturedEnd();
1310 }
1311 if (pos < extraStr.size()) {
1312 IR::SignatureSpan textSpan;
1313 textSpan.role = IR::SpanRole::Text;
1314 textSpan.text = extraStr.mid(pos);
1315 wrapper.children.append(textSpan);
1316 }
1317
1318 if (wrapper.children.isEmpty()) {
1319 wrapper.text = extraStr;
1320 }
1321 spans.append(wrapper);
1322 return spans;
1323}
1324
1326 const HrefResolver *hrefResolver,
1327 const Node *relative)
1328{
1329 if (!templateDecl)
1330 return {};
1331
1332 IR::SignatureSpan declSpan;
1334 declSpan.text = "template"_L1;
1335
1336 IR::SignatureSpan open;
1338 open.text = " <"_L1;
1339 declSpan.children.append(open);
1340
1341 bool first = true;
1342 for (const auto &param : templateDecl->parameters) {
1343 if (param.sfinae_constraint)
1344 continue;
1345 if (!first) {
1346 IR::SignatureSpan comma;
1347 comma.role = IR::SpanRole::Text;
1348 comma.text = ", "_L1;
1349 declSpan.children.append(comma);
1350 }
1351
1352 switch (param.kind) {
1353 case RelaxedTemplateParameter::Kind::TypeTemplateParameter: {
1354 if (param.concept_name) {
1355 const QString fq = QString::fromStdString(*param.concept_name);
1356 const QString unqualified = fq.section("::"_L1, -1);
1357 // Resolve by the fully-qualified name the concept is registered
1358 // under; render the unqualified spelling the author wrote.
1359 const Node *conceptNode = findConceptNodeForRelative(relative, fq);
1360 IR::SignatureSpan link;
1361 link.role = IR::SpanRole::Link;
1362 link.text = unqualified;
1363 link.href = resolveHref(hrefResolver, conceptNode, relative);
1364 declSpan.children.append(link);
1365 } else {
1366 IR::SignatureSpan kw;
1367 kw.role = IR::SpanRole::Text;
1368 kw.text = "typename"_L1;
1369 declSpan.children.append(kw);
1370 }
1371 break;
1372 }
1373 case RelaxedTemplateParameter::Kind::TemplateTemplateParameter: {
1374 IR::SignatureSpan kw;
1375 kw.role = IR::SpanRole::Text;
1376 kw.text = "typename"_L1;
1377 declSpan.children.append(kw);
1378 break;
1379 }
1380 case RelaxedTemplateParameter::Kind::NonTypeTemplateParameter: {
1381 if (!param.valued_declaration.type.empty()) {
1382 auto typeSpans = buildTypeSpans(QString::fromStdString(param.valued_declaration.type));
1383 declSpan.children.append(typeSpans);
1384 }
1385 break;
1386 }
1387 }
1388
1389 if (param.is_parameter_pack) {
1390 IR::SignatureSpan dots;
1391 dots.role = IR::SpanRole::Text;
1392 dots.text = "..."_L1;
1393 declSpan.children.append(dots);
1394 }
1395
1396 if (!param.valued_declaration.name.empty()) {
1397 IR::SignatureSpan space;
1398 space.role = IR::SpanRole::Text;
1399 space.text = " "_L1;
1400 declSpan.children.append(space);
1401
1402 IR::SignatureSpan nameSpan;
1403 nameSpan.role = IR::SpanRole::Parameter;
1404 nameSpan.text = QString::fromStdString(param.valued_declaration.name);
1405 declSpan.children.append(nameSpan);
1406 }
1407
1408 if (!param.valued_declaration.initializer.empty()) {
1409 IR::SignatureSpan eq;
1410 eq.role = IR::SpanRole::Text;
1411 eq.text = " = "_L1;
1412 declSpan.children.append(eq);
1413
1414 if (param.kind == RelaxedTemplateParameter::Kind::TypeTemplateParameter
1415 || param.kind == RelaxedTemplateParameter::Kind::TemplateTemplateParameter) {
1416 auto typeSpans = buildTypeSpans(QString::fromStdString(param.valued_declaration.initializer));
1417 declSpan.children.append(typeSpans);
1418 } else {
1419 IR::SignatureSpan val;
1420 val.role = IR::SpanRole::Text;
1421 val.text = QString::fromStdString(param.valued_declaration.initializer);
1422 declSpan.children.append(val);
1423 }
1424 }
1425
1426 first = false;
1427 }
1428
1429 IR::SignatureSpan close;
1431 close.text = ">"_L1;
1432 declSpan.children.append(close);
1433
1434 if (templateDecl->requires_clause && !templateDecl->requires_clause->empty()) {
1435 const QString reqText = QString::fromStdString(*templateDecl->requires_clause);
1436 QStringList conceptNames;
1437 conceptNames.reserve(int(templateDecl->referenced_concepts.size()));
1438 for (const auto &s : templateDecl->referenced_concepts)
1439 conceptNames.append(QString::fromStdString(s));
1440 appendRequiresSpansWithLinks(declSpan.children, reqText, conceptNames,
1441 hrefResolver, relative);
1442 }
1443
1444 return { declSpan };
1445}
1446
1448 const HrefResolver *hrefResolver,
1449 const Node *relative,
1450 Section::Style style)
1451{
1452 QList<IR::SignatureSpan> spans;
1453
1454 auto appendText = [&spans](const QString &text) {
1455 IR::SignatureSpan span;
1457 span.text = text;
1458 spans.append(span);
1459 };
1460
1461 auto appendName = [&spans, node, hrefResolver, relative](const QString &name) {
1462 IR::SignatureSpan span;
1464 span.text = name;
1465 span.href = resolveHref(hrefResolver, node, relative);
1466 spans.append(span);
1467 };
1468
1469 auto appendTypeSpans = [&spans](const QString &type, bool trailingSpace) {
1470 auto typeSpans = buildTypeSpans(type);
1471 spans.append(typeSpans);
1472 if (trailingSpace && !type.isEmpty()
1473 && !type.endsWith('*'_L1) && !type.endsWith('&'_L1)) {
1474 IR::SignatureSpan space;
1476 space.text = " "_L1;
1477 spans.append(space);
1478 }
1479 };
1480
1481 // Extra qualifiers go first (prepended in CppCodeMarker)
1482 if (style != Section::AllMembers) {
1483 auto extras = buildExtraSpans(node, style);
1484 if (!extras.isEmpty()) {
1485 spans.append(extras);
1486 appendText(" "_L1);
1487 }
1488 }
1489
1490 // Name with parent prefix for Details style
1491 QString nameText = node->name();
1492 bool linkName = (style != Section::Details);
1493
1494 if (style == Section::Details) {
1496 && !node->parent()->name().isEmpty()
1497 && !node->parent()->isHeader() && !node->isProperty() && !node->isQmlNode()) {
1498 nameText = node->parent()->name() + "::"_L1 + nameText;
1499 }
1500 }
1501
1502 switch (node->nodeType()) {
1504 case NodeType::Class:
1505 case NodeType::Struct:
1506 case NodeType::Union:
1507 appendText(Node::nodeTypeString(node->nodeType()) + " "_L1);
1508 if (linkName) {
1509 appendName(nameText);
1510 } else {
1511 IR::SignatureSpan span;
1513 span.text = nameText;
1514 spans.append(span);
1515 }
1516 break;
1517 case NodeType::Function: {
1518 const auto *func = static_cast<const FunctionNode *>(node);
1519
1520 if (style == Section::Details) {
1521 if (auto templateDecl = node->templateDecl()) {
1522 auto tmplSpans = buildTemplateDeclSpans(&*templateDecl, hrefResolver, relative);
1523 spans.append(tmplSpans);
1524 appendText(" "_L1);
1525 }
1526 }
1527
1528 if (style == Section::Summary || style == Section::Accessors) {
1529 if (!func->isNonvirtual())
1530 appendText("virtual "_L1);
1531 }
1532
1533 if (style != Section::AllMembers && !func->returnType().isEmpty())
1534 appendTypeSpans(func->returnTypeString(), true);
1535
1536 if (linkName) {
1537 appendName(nameText);
1538 } else {
1539 IR::SignatureSpan span;
1541 span.text = nameText;
1542 spans.append(span);
1543 }
1544
1545 if (!func->isMacroWithoutParams()) {
1546 appendText("("_L1);
1547 if (!func->parameters().isEmpty()) {
1548 const Parameters &parameters = func->parameters();
1549 for (int i = 0; i < parameters.count(); ++i) {
1550 if (i > 0)
1551 appendText(", "_L1);
1552 const Parameter &param = parameters.at(i);
1553 QString pName = param.name();
1554 QString type = param.type();
1555 QString value = param.defaultValue();
1556 qsizetype insertPos = param.nameInsertionPoint();
1557 if (insertPos >= 0 && style != Section::AllMembers && !pName.isEmpty()) {
1558 appendTypeSpans(type.left(insertPos), false);
1559 IR::SignatureSpan paramSpan;
1560 paramSpan.role = IR::SpanRole::Parameter;
1561 paramSpan.text = pName;
1562 spans.append(paramSpan);
1563 appendTypeSpans(type.mid(insertPos), false);
1564 } else {
1565 bool trailingSpace = style != Section::AllMembers && !pName.isEmpty();
1566 appendTypeSpans(type, trailingSpace);
1567 if (style != Section::AllMembers && !pName.isEmpty()) {
1568 IR::SignatureSpan paramSpan;
1569 paramSpan.role = IR::SpanRole::Parameter;
1570 paramSpan.text = pName;
1571 spans.append(paramSpan);
1572 }
1573 }
1574 if (style != Section::AllMembers && !value.isEmpty())
1575 appendText(" = "_L1 + value);
1576 }
1577 }
1578 appendText(")"_L1);
1579 }
1580
1581 if (func->isConst())
1582 appendText(" const"_L1);
1583
1584 if (style == Section::Summary || style == Section::Accessors) {
1585 if (func->isFinal())
1586 appendText(" final"_L1);
1587 if (func->isOverride())
1588 appendText(" override"_L1);
1589 if (func->isPureVirtual())
1590 appendText(" = 0"_L1);
1591 if (func->isRef())
1592 appendText(" &"_L1);
1593 else if (func->isRefRef())
1594 appendText(" &&"_L1);
1595 } else if (style == Section::AllMembers) {
1596 if (!func->returnType().isEmpty() && func->returnType() != "void"_L1) {
1597 appendText(" : "_L1);
1598 appendTypeSpans(func->returnTypeString(), false);
1599 }
1600 } else {
1601 if (func->isRef())
1602 appendText(" &"_L1);
1603 else if (func->isRefRef())
1604 appendText(" &&"_L1);
1605 if (const auto &req = func->trailingRequiresClause(); req && !req->isEmpty())
1606 appendRequiresSpansWithLinks(spans, *req, func->referencedConcepts(),
1607 hrefResolver, relative);
1608 }
1609 break;
1610 }
1611 case NodeType::Enum: {
1612 const auto *enume = static_cast<const EnumNode *>(node);
1613 appendText("enum"_L1);
1614 if (enume->isScoped())
1615 appendText(" class"_L1);
1616 if (!enume->isAnonymous()) {
1617 appendText(" "_L1);
1618 if (linkName) {
1619 appendName(nameText);
1620 } else {
1621 IR::SignatureSpan span;
1623 span.text = nameText;
1624 spans.append(span);
1625 }
1626 }
1627 if (style == Section::Summary) {
1628 appendText(" { "_L1);
1629 const int MaxEnumValues = 6;
1630 QStringList documentedItems = enume->doc().enumItemNames();
1631 if (documentedItems.isEmpty()) {
1632 const auto &enumItems = enume->items();
1633 for (const auto &item : enumItems)
1634 documentedItems << item.name();
1635 }
1636 const QStringList omitItems = enume->doc().omitEnumItemNames();
1637 for (const auto &item : omitItems)
1638 documentedItems.removeAll(item);
1639
1640 if (documentedItems.size() > MaxEnumValues) {
1641 const QString last = documentedItems.last();
1642 documentedItems = documentedItems.mid(0, MaxEnumValues - 1);
1643 documentedItems += "..."_L1;
1644 documentedItems += last;
1645 }
1646 appendText(documentedItems.join(", "_L1));
1647 if (!documentedItems.isEmpty())
1648 appendText(" "_L1);
1649 appendText("}"_L1);
1650 }
1651 break;
1652 }
1653 case NodeType::TypeAlias: {
1654 if (style == Section::Details) {
1655 if (auto templateDecl = node->templateDecl()) {
1656 auto tmplSpans = buildTemplateDeclSpans(&*templateDecl, hrefResolver, relative);
1657 spans.append(tmplSpans);
1658 appendText(" "_L1);
1659 }
1660 }
1661 if (linkName) {
1662 appendName(nameText);
1663 } else {
1664 IR::SignatureSpan span;
1666 span.text = nameText;
1667 spans.append(span);
1668 }
1669 break;
1670 }
1671 case NodeType::Typedef: {
1672 if (static_cast<const TypedefNode *>(node)->associatedEnum())
1673 appendText("flags "_L1);
1674 if (linkName) {
1675 appendName(nameText);
1676 } else {
1677 IR::SignatureSpan span;
1679 span.text = nameText;
1680 spans.append(span);
1681 }
1682 break;
1683 }
1684 case NodeType::Property: {
1685 const auto *property = static_cast<const PropertyNode *>(node);
1686 if (linkName) {
1687 appendName(nameText);
1688 } else {
1689 IR::SignatureSpan span;
1691 span.text = nameText;
1692 spans.append(span);
1693 }
1694 appendText(" : "_L1);
1695 appendTypeSpans(property->qualifiedDataType(), false);
1696 break;
1697 }
1698 case NodeType::QmlProperty: {
1699 const auto *property = static_cast<const QmlPropertyNode *>(node);
1700 if (linkName) {
1701 appendName(nameText);
1702 } else {
1703 IR::SignatureSpan span;
1705 span.text = nameText;
1706 spans.append(span);
1707 }
1708 appendText(" : "_L1);
1709 appendTypeSpans(property->dataType(), false);
1710 break;
1711 }
1712 case NodeType::Variable: {
1713 const auto *variable = static_cast<const VariableNode *>(node);
1714 if (style == Section::AllMembers) {
1715 if (linkName) {
1716 appendName(nameText);
1717 } else {
1718 IR::SignatureSpan span;
1720 span.text = nameText;
1721 spans.append(span);
1722 }
1723 appendText(" : "_L1);
1724 appendTypeSpans(variable->dataType(), false);
1725 } else {
1726 appendTypeSpans(variable->leftType(), true);
1727 if (linkName) {
1728 appendName(nameText);
1729 } else {
1730 IR::SignatureSpan span;
1732 span.text = nameText;
1733 spans.append(span);
1734 }
1735 appendText(variable->rightType());
1736 }
1737 break;
1738 }
1739 default:
1740 if (linkName) {
1741 appendName(nameText);
1742 } else {
1743 IR::SignatureSpan span;
1745 span.text = nameText;
1746 spans.append(span);
1747 }
1748 break;
1749 }
1750
1751 return spans;
1752}
1753
1754/*!
1755 \internal
1756 Build the signature spans for a QML member.
1757
1758 \a relative is the rendered documentation owner: the QML type whose
1759 page the signature appears on. Inherited members resolve their name
1760 link against that owner rather than the declaring type, because an
1761 internal base type generates no page of its own.
1762*/
1764 const HrefResolver *hrefResolver,
1765 const Node *relative)
1766{
1767 QList<IR::SignatureSpan> spans;
1768
1769 auto appendText = [&spans](const QString &text) {
1770 IR::SignatureSpan span;
1772 span.text = text;
1773 spans.append(span);
1774 };
1775
1776 auto appendTypeSpans = [&spans](const QString &type, bool trailingSpace) {
1777 auto typeSpans = buildTypeSpans(type);
1778 spans.append(typeSpans);
1779 if (trailingSpace && !type.isEmpty()
1780 && !type.endsWith('*'_L1) && !type.endsWith('&'_L1)) {
1781 IR::SignatureSpan space;
1783 space.text = " "_L1;
1784 spans.append(space);
1785 }
1786 };
1787
1788 IR::SignatureSpan nameSpan;
1789 nameSpan.role = IR::SpanRole::Name;
1790 nameSpan.text = node->name();
1791 nameSpan.href = resolveHref(hrefResolver, node, relative);
1792
1793 if (node->isQmlProperty()) {
1794 const auto *pn = static_cast<const QmlPropertyNode *>(node);
1795 spans.append(nameSpan);
1796 appendText(" : "_L1);
1797 appendTypeSpans(pn->dataType(), false);
1798 } else if (node->isFunction(Genus::QML)) {
1799 const auto *func = static_cast<const FunctionNode *>(node);
1800 if (!func->returnType().isEmpty())
1801 appendTypeSpans(func->returnTypeString(), true);
1802 spans.append(nameSpan);
1803 appendText("("_L1);
1804 if (!func->parameters().isEmpty()) {
1805 const Parameters &parameters = func->parameters();
1806 for (int i = 0; i < parameters.count(); ++i) {
1807 if (i > 0)
1808 appendText(", "_L1);
1809 QString pName = parameters.at(i).name();
1810 QString type = parameters.at(i).type();
1811 if (!pName.isEmpty()) {
1812 appendTypeSpans(type, true);
1813 IR::SignatureSpan paramSpan;
1814 paramSpan.role = IR::SpanRole::Parameter;
1815 paramSpan.text = pName;
1816 spans.append(paramSpan);
1817 } else {
1818 IR::SignatureSpan paramSpan;
1819 paramSpan.role = IR::SpanRole::Parameter;
1820 paramSpan.text = type;
1821 spans.append(paramSpan);
1822 }
1823 }
1824 }
1825 appendText(")"_L1);
1826 } else {
1827 spans.append(nameSpan);
1828 }
1829
1830 auto extras = buildExtraSpans(node, Section::Summary);
1831 if (!extras.isEmpty()) {
1832 appendText(" "_L1);
1833 spans.append(extras);
1834 }
1835
1836 return spans;
1837}
1838
1839static QString plainTextFromSpans(const QList<IR::SignatureSpan> &spans)
1840{
1841 QString result;
1842 for (const auto &span : spans)
1843 result += span.plainText();
1844 return result;
1845}
1846
1847/*!
1848 \internal
1849 Build structured signature spans from Node data.
1850
1851 This function produces a QList of SignatureSpan values that carry
1852 semantic roles (Type, Name, Parameter, Extra, and so on) for each
1853 element of a member's synopsis. It parallels what CppCodeMarker's
1854 markedUpSynopsis() and markedUpQmlItem() produce as tagged strings,
1855 but outputs structured IR spans instead.
1856
1857 The \a style parameter controls level of detail: Summary includes
1858 virtual/override qualifiers, Details adds template declarations and
1859 parent prefixes, AllMembers uses a condensed format.
1860*/
1862 const HrefResolver *hrefResolver,
1863 const Node *relative,
1864 Section::Style style)
1865{
1866 if (node->isQmlNode() && !node->isEnumType())
1867 return buildQmlItemSpans(node, hrefResolver, relative);
1868 return buildCppSynopsisSpans(node, hrefResolver, relative, style);
1869}
1870
1871/*!
1872 \internal
1873 Extract a grouped all-members listing for a QML type.
1874
1875 Constructs a Sections object from the QmlTypeNode, extracts
1876 allMembersSection().classNodesList() to group members by
1877 originating QML type, and builds AllMemberEntry items with
1878 QML-specific hints and property group nesting.
1879*/
1880static IR::AllMembersIR extractQmlAllMembersIR(const QmlTypeNode *qcn, const HrefResolver *hrefResolver)
1881{
1882 IR::AllMembersIR result;
1883 result.typeName = qcn->name();
1884 result.typeHref = resolveHref(hrefResolver, qcn, qcn);
1885 result.isQmlType = true;
1886
1887 Sections sections(qcn);
1888 ClassNodesList &groupedMembers = sections.allMembersSection().classNodesList();
1889 if (groupedMembers.isEmpty())
1890 return result;
1891
1892 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
1893
1894 std::function<IR::AllMemberEntry(Node *)> buildEntry = [&](Node *node) -> IR::AllMemberEntry {
1895 IR::AllMemberEntry entry;
1896 entry.signatureSpans = buildQmlItemSpans(node, hrefResolver, qcn);
1897 entry.signature = plainTextFromSpans(entry.signatureSpans);
1898 entry.href = resolveHref(hrefResolver, node, qcn);
1899
1900 if (node->isQmlProperty()) {
1901 auto *qpn = static_cast<QmlPropertyNode *>(node);
1902 QStringList qmlHints = qpn->hints();
1903 if (qpn->isAttached() && !qmlHints.contains("attached"_L1))
1904 qmlHints << "attached"_L1;
1905 for (const auto &h : std::as_const(qmlHints))
1906 entry.hints.append(h);
1907 } else if (node->isAttached()) {
1908 entry.hints.append("attached"_L1);
1909 }
1910
1911 if (node->isPropertyGroup()) {
1912 entry.isPropertyGroup = true;
1913 const auto *scn = static_cast<SharedCommentNode *>(node);
1914 for (auto *child : scn->collective()) {
1915 const NodeContext childContext = child->createContext();
1916 if (!InclusionFilter::isIncluded(policy, childContext))
1917 continue;
1918 entry.children.append(buildEntry(child));
1919 }
1920 }
1921
1922 return entry;
1923 };
1924
1925 auto isVisible = [&policy](Node *node) {
1926 const NodeContext context = node->createContext();
1927 return InclusionFilter::isIncluded(policy, context)
1928 && !(node->isSharingComment() && node->sharedCommentNode()->isPropertyGroup());
1929 };
1930
1931 for (const auto &[originType, nodes] : groupedMembers) {
1932 Q_ASSERT(originType);
1933 if (nodes.isEmpty())
1934 continue;
1935
1936 IR::MemberGroup group;
1937 if (originType != qcn) {
1938 group.typeName = originType->name();
1939 group.typeHref = resolveHref(hrefResolver, originType, qcn);
1940 }
1941
1942 for (auto *node : nodes) {
1943 if (isVisible(node))
1944 group.members.append(buildEntry(node));
1945 }
1946
1947 result.memberGroups.append(group);
1948 }
1949
1950 return result;
1951}
1952
1953/*!
1954 \internal
1955 Extract a flat all-members listing for a C++ class or namespace.
1956
1957 Constructs a Sections object from the aggregate, extracts
1958 allMembersSection().members(), builds AllMemberEntry for each
1959 visible member, and returns an AllMembersIR with isQmlType=false.
1960*/
1961static IR::AllMembersIR extractCppAllMembersIR(const Aggregate *aggregate, const HrefResolver *hrefResolver)
1962{
1963 IR::AllMembersIR result;
1964 result.typeName = aggregate->plainFullName();
1965 result.typeHref = resolveHref(hrefResolver, aggregate, aggregate);
1966 result.isQmlType = false;
1967
1968 Sections sections(aggregate);
1969 const Section &allMembers = sections.allMembersSection();
1970 if (allMembers.isEmpty())
1971 return result;
1972
1973 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
1974
1975 for (const auto *node : allMembers.members()) {
1976 if (node->name().isEmpty())
1977 continue;
1978 const NodeContext context = node->createContext();
1979 if (!InclusionFilter::isIncluded(policy, context))
1980 continue;
1981 if (node->isFunction()
1982 && static_cast<const FunctionNode *>(node)->isIgnored())
1983 continue;
1984
1985 IR::AllMemberEntry entry;
1986 entry.signatureSpans = buildSignatureSpans(node, hrefResolver, aggregate, Section::AllMembers);
1987 entry.signature = plainTextFromSpans(entry.signatureSpans);
1988 entry.href = resolveHref(hrefResolver, node, aggregate);
1989 result.members.append(entry);
1990 }
1991
1992 return result;
1993}
1994
1995/*!
1996 \internal
1997 Extract all-members IR for a page node.
1998
1999 Dispatches to the QML or C++ extraction function based on the page
2000 type. Returns std::nullopt for page types that don't have member
2001 listing pages (generic pages, QML basic types) or when the listing
2002 would be empty.
2003*/
2004std::optional<IR::AllMembersIR> extractAllMembersIR(const PageNode *pn, const HrefResolver *hrefResolver)
2005{
2006 if (pn->isQmlType()) {
2007 const auto *qcn = static_cast<const QmlTypeNode *>(pn);
2008 if (qcn->isQmlBasicType())
2009 return std::nullopt;
2010 auto result = extractQmlAllMembersIR(qcn, hrefResolver);
2011 bool hasMember = false;
2012 for (const auto &group : std::as_const(result.memberGroups)) {
2013 if (!group.members.isEmpty()) {
2014 hasMember = true;
2015 break;
2016 }
2017 }
2018 if (!hasMember)
2019 return std::nullopt;
2020 return result;
2021 }
2022
2023 if (pn->isAggregate() && (pn->isClassNode() || pn->isNamespace())) {
2024 const auto *aggregate = static_cast<const Aggregate *>(pn);
2025 auto result = extractCppAllMembersIR(aggregate, hrefResolver);
2026 if (result.members.isEmpty())
2027 return std::nullopt;
2028 return result;
2029 }
2030
2031 return std::nullopt;
2032}
2033
2034/*!
2035 \internal
2036 Extract navigation metadata from a PageNode.
2037
2038 Reads navigation configuration values (homepage, landingpage,
2039 cppclassespage, qmltypespage) and the node's position in the
2040 documentation tree to produce a breadcrumb chain, sequential
2041 links (previous/next/start), and the configured TOC depth.
2042
2043 The breadcrumb chain follows page-type-specific logic ported
2044 from HtmlGenerator::generateNavigationBar(): static chain
2045 entries for API reference pages (class, QML type), a
2046 navigationParent() walk for generic pages with a 16-item
2047 circular reference cutoff, and a fallback to the first group
2048 page when no navigation parent exists.
2049
2050 Sequential links come from the node's pre-populated link map,
2051 set by QDocDatabase::updateNavigation() before generation runs.
2052*/
2053IR::NavigationData extractNavigationData(const PageNode *pn, const HrefResolver *hrefResolver)
2054{
2055 IR::NavigationData nav;
2056 const Config &config = Config::instance();
2058
2059 const QString navDot = CONFIG_NAVIGATION + Config::dot;
2060 const QString homepage = config.get(navDot + CONFIG_HOMEPAGE).asString();
2061 const QString hometitle = config.get(navDot + CONFIG_HOMETITLE).asString(homepage);
2062 const QString landingpage = config.get(navDot + CONFIG_LANDINGPAGE).asString();
2063 const QString landingtitle = config.get(navDot + CONFIG_LANDINGTITLE).asString(landingpage);
2064 const QString cppclassespage = config.get(navDot + CONFIG_CPPCLASSESPAGE).asString();
2065 const QString cppclassestitle = config.get(navDot + CONFIG_CPPCLASSESTITLE).asString("C++ Classes"_L1);
2066 const QString qmltypespage = config.get(navDot + CONFIG_QMLTYPESPAGE).asString();
2067 const QString qmltypestitle = config.get(navDot + CONFIG_QMLTYPESTITLE).asString("QML Types"_L1);
2068
2069 const QString pageTitle = pn->title();
2070 using CrumbState = IR::NavigationData::CrumbState;
2071
2072 auto resolveCrumb = [&](const QString &targetName)
2073 -> std::pair<QString, CrumbState> {
2074 const Node *target = qdb->findNodeForTarget(targetName, pn);
2075 if (!target)
2076 return {{}, CrumbState::Unresolved};
2077 if (target == pn)
2078 return {{}, CrumbState::Current};
2079 return {resolveHref(hrefResolver, target, pn), CrumbState::Link};
2080 };
2081
2082 if (!homepage.isEmpty()) {
2083 auto [href, state] = resolveCrumb(homepage);
2084 if (state == CrumbState::Current)
2085 return nav;
2086 nav.breadcrumbs.append({hometitle, std::move(href), state});
2087 }
2088
2089 if (!landingpage.isEmpty()) {
2090 auto [href, state] = resolveCrumb(landingpage);
2091 if (state != CrumbState::Current)
2092 nav.breadcrumbs.append({landingtitle, std::move(href), state});
2093 }
2094
2095 if (pn->isClassNode()) {
2096 const bool hasClassesCrumb = !cppclassespage.isEmpty() && !cppclassestitle.isEmpty();
2097 if (hasClassesCrumb) {
2098 auto [href, state] = resolveCrumb(cppclassespage);
2099 nav.breadcrumbs.append({cppclassestitle, std::move(href), state});
2100 }
2101
2102 const auto *moduleNode = qdb->getModuleNode(pn);
2103 QString moduleState;
2104 if (moduleNode && !moduleNode->state().isEmpty())
2105 moduleState = QStringLiteral(" (%1)").arg(moduleNode->state());
2106
2107 if (!pn->physicalModuleName().isEmpty() && moduleNode
2108 && (!moduleState.isEmpty() || moduleNode->title() != cppclassespage)) {
2109 const QString moduleText = hasClassesCrumb || moduleNode->title().isEmpty()
2110 ? moduleNode->name() : moduleNode->title();
2111 nav.breadcrumbs.append({moduleText + moduleState,
2112 resolveHref(hrefResolver, moduleNode, pn),
2113 CrumbState::Link});
2114 }
2115 nav.breadcrumbs.append({pn->name(), {}, CrumbState::Current});
2116 } else if (pn->isQmlType()) {
2117 const bool hasTypesCrumb = !qmltypespage.isEmpty() && !qmltypestitle.isEmpty();
2118 if (hasTypesCrumb) {
2119 auto [href, state] = resolveCrumb(qmltypespage);
2120 nav.breadcrumbs.append({qmltypestitle, std::move(href), state});
2121 }
2122
2123 const auto *moduleNode = qdb->getModuleNode(pn);
2124 QString moduleState;
2125 if (moduleNode && !moduleNode->state().isEmpty())
2126 moduleState = QStringLiteral(" (%1)").arg(moduleNode->state());
2127
2128 if (moduleNode
2129 && (!moduleState.isEmpty() || moduleNode->title() != qmltypespage)) {
2130 const QString moduleText = hasTypesCrumb || moduleNode->title().isEmpty()
2131 ? moduleNode->name() : moduleNode->title();
2132 nav.breadcrumbs.append({moduleText + moduleState,
2133 resolveHref(hrefResolver, moduleNode, pn),
2134 CrumbState::Link});
2135 }
2136 nav.breadcrumbs.append({pn->name(), {}, CrumbState::Current});
2137 } else {
2138 auto currentNode = pn;
2139 std::deque<const Node *> navNodes;
2140 qsizetype navItems = 0;
2141 while (currentNode->navigationParent() && ++navItems < 16) {
2142 if (std::find(navNodes.cbegin(), navNodes.cend(),
2143 currentNode->navigationParent()) == navNodes.cend())
2144 navNodes.push_front(currentNode->navigationParent());
2145 currentNode = currentNode->navigationParent();
2146 }
2147 if (navNodes.empty()) {
2148 const QStringList groups = pn->groupNames();
2149 for (const auto &groupName : groups) {
2150 const auto *groupNode = qdb->findNodeByNameAndType(
2151 QStringList{groupName}, &Node::isGroup);
2152 if (groupNode && !groupNode->title().isEmpty()) {
2153 navNodes.push_front(groupNode);
2154 break;
2155 }
2156 }
2157 }
2158 for (const auto *navNode : navNodes) {
2159 if (navNode->isPageNode())
2160 nav.breadcrumbs.append({navNode->title(),
2161 resolveHref(hrefResolver, navNode, pn),
2162 CrumbState::Link});
2163 }
2164 if (!nav.breadcrumbs.isEmpty())
2165 nav.breadcrumbs.append({pageTitle, {}, CrumbState::Current});
2166 }
2167
2168 const auto &linkMap = pn->links();
2169 if (linkMap.contains(Node::PreviousLink)) {
2170 const auto &linkPair = linkMap[Node::PreviousLink];
2171 const Node *target = qdb->findNodeForTarget(linkPair.first, pn);
2172 QString href;
2173 QString title;
2174 if (target && target != pn) {
2175 href = resolveHref(hrefResolver, target, pn);
2176 title = (linkPair.first == linkPair.second && !target->title().isEmpty())
2177 ? target->title() : linkPair.second;
2178 } else {
2179 href = linkPair.first;
2180 title = linkPair.second;
2181 }
2182 nav.previousLink = IR::NavigationData::LinkEntry{title, href};
2183 }
2184 if (linkMap.contains(Node::NextLink)) {
2185 const auto &linkPair = linkMap[Node::NextLink];
2186 const Node *target = qdb->findNodeForTarget(linkPair.first, pn);
2187 QString href;
2188 QString title;
2189 if (target && target != pn) {
2190 href = resolveHref(hrefResolver, target, pn);
2191 title = (linkPair.first == linkPair.second && !target->title().isEmpty())
2192 ? target->title() : linkPair.second;
2193 } else {
2194 href = linkPair.first;
2195 title = linkPair.second;
2196 }
2197 nav.nextLink = IR::NavigationData::LinkEntry{title, href};
2198 }
2199 if (linkMap.contains(Node::StartLink)) {
2200 const auto &linkPair = linkMap[Node::StartLink];
2201 const Node *target = qdb->findNodeForTarget(linkPair.first, pn);
2202 QString href;
2203 QString title;
2204 if (target && target != pn) {
2205 href = resolveHref(hrefResolver, target, pn);
2206 title = (linkPair.first == linkPair.second && !target->title().isEmpty())
2207 ? target->title() : linkPair.second;
2208 } else {
2209 href = linkPair.first;
2210 title = linkPair.second;
2211 }
2212 nav.startLink = IR::NavigationData::LinkEntry{title, href};
2213 }
2214
2215 const QString formatDot = "HTML"_L1 + Config::dot;
2216 nav.tocDepth = config.get(formatDot + "tocdepth"_L1).asInt();
2217
2218 return nav;
2219}
2220
2221} // namespace NodeExtractor
2222
2223QT_END_NAMESPACE
#define ATOM_LIST_VALUE
Definition atom.h:213
bool hasObsoleteMembers() const
Returns true if this aggregate contains at least one child that is marked obsolete.
The Atom class is the fundamental unit for representing documents internally.
Definition atom.h:19
@ ParaRight
Definition atom.h:80
@ ParaLeft
Definition atom.h:79
The ClassNode represents a C++ class.
Definition classnode.h:23
bool isQmlNativeType()
Definition classnode.h:54
A class for holding the members of a collection of doc pages.
NodeMap getMembers(NodeType type) const
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition config.h:95
const Location & location() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:89
const Text & body() const
Definition doc.cpp:114
Text briefText(bool inclusive=false) const
Definition doc.cpp:126
Text deprecationText() const
Definition doc.cpp:131
Converts Atom chains to QList<IR::ContentBlock> trees.
static bool isIncluded(const InclusionPolicy &policy, const NodeContext &context)
The Location class provides a way to mark a location in a file.
Definition location.h:20
A PageNode is a Node that generates a documentation page.
Definition pagenode.h:19
const PageNode * navigationParent() const
Definition pagenode.h:47
bool noAutoList() const
Returns the value of the no auto-list flag.
Definition pagenode.h:42
The Parameter class describes one function parameter.
Definition parameter.h:14
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
static QDocDatabase * qdocDB()
Creates the singleton.
const CollectionNode * getModuleNode(const Node *relative)
Returns the collection node representing the module that relative node belongs to,...
const CNMap & groups()
Returns a const reference to the collection of all group nodes in the primary tree.
Status
Specifies the status of the QQmlIncubator.
ClassNode * classNode() const override
If this is a QmlTypeNode, this function returns the pointer to the C++ ClassNode that this QML type r...
Definition qmltypenode.h:27
static void subclasses(const Node *base, NodeList &subs, bool recurse=false)
Loads the list subs with the nodes of all the subclasses of base.
bool isSingleton() const
Definition qmltypenode.h:31
QmlTypeNode * qmlBaseNode() const override
If this Aggregate is a QmlTypeNode, this function returns a pointer to the QmlTypeNode that is its ba...
Definition qmltypenode.h:54
CollectionNode * logicalModule() const override
If this is a QmlTypeNode, a pointer to its QML module is returned, which is a pointer to a Collection...
Definition qmltypenode.h:47
A class for containing the elements of one documentation section.
Definition sections.h:17
ClassNodesList & classNodesList()
Definition sections.h:52
@ Summary
Definition sections.h:19
@ Details
Definition sections.h:19
@ Accessors
Definition sections.h:19
@ AllMembers
Definition sections.h:19
bool isEmpty() const
Definition sections.h:35
A class for creating vectors of collections for documentation.
Definition sections.h:80
SectionVector & summarySections()
Definition sections.h:151
Sections(const Aggregate *aggregate)
This constructor builds the section vectors based on the type of the aggregate node.
Definition sections.cpp:372
bool hasObsoleteMembers(SectionPtrVector *summary_spv, SectionPtrVector *details_spv) const
Returns true if any sections in this object contain obsolete members.
Definition sections.cpp:967
SectionVector & detailsSections()
Definition sections.h:152
Section & allMembersSection()
Definition sections.h:153
Definition text.h:12
const Atom * firstAtom() const
Definition text.h:33
bool isEmpty() const
Definition text.h:30
Atom * firstAtom()
Definition text.h:21
static std::string comparisonCategoryAsString(ComparisonCategory category)
#define CONFIG_CPPCLASSESTITLE
Definition config.h:391
#define CONFIG_HOMETITLE
Definition config.h:411
#define CONFIG_HOMEPAGE
Definition config.h:410
#define CONFIG_URL
Definition config.h:468
#define CONFIG_QMLTYPESPAGE
Definition config.h:474
#define CONFIG_CPPCLASSESPAGE
Definition config.h:390
#define CONFIG_NAVIGATION
Definition config.h:434
#define CONFIG_LANDINGPAGE
Definition config.h:423
#define CONFIG_LANDINGTITLE
Definition config.h:424
#define CONFIG_QMLTYPESTITLE
Definition config.h:475
NodeType
Definition genustypes.h:165
Definition builder.cpp:14
static QList< IR::SignatureSpan > buildTemplateDeclSpans(const RelaxedTemplateDeclaration *templateDecl, const HrefResolver *hrefResolver, const Node *relative)
static void qualifyEnumValueTerms(const EnumNode *en, QList< IR::ContentBlock > &blocks)
static QList< IR::SignatureSpan > buildTypeSpans(const QString &typeString)
IR::PageMetadata extractPageMetadata(const PageNode *pn, const HrefResolver *hrefResolver, SemanticOrigins *origins)
QList< IR::SignatureSpan > buildSignatureSpans(const Node *node, const HrefResolver *hrefResolver, const Node *relative, Section::Style style)
IR::CollectionData extractCollectionData(const CollectionNode *cn, const HrefResolver *hrefResolver)
IR::MemberIR extractMemberIR(const Node *node, const HrefResolver *hrefResolver, const Node *relative, MemberExtractionLevel level)
std::optional< IR::AllMembersIR > extractAllMembersIR(const PageNode *pn, const HrefResolver *hrefResolver)
QList< IR::SectionIR > extractSummarySections(const Aggregate *aggregate, const HrefResolver *hrefResolver)
QList< IR::SectionIR > extractDetailSections(const Aggregate *aggregate, const HrefResolver *hrefResolver, SemanticOrigins *origins, DetailSectionKind kind)
static QString plainTextFromSpans(const QList< IR::SignatureSpan > &spans)
static IR::AllMembersIR extractQmlAllMembersIR(const QmlTypeNode *qcn, const HrefResolver *hrefResolver)
IR::QmlTypeData extractQmlTypeData(const QmlTypeNode *qcn, const HrefResolver *hrefResolver)
static QList< IR::SignatureSpan > buildQmlItemSpans(const Node *node, const HrefResolver *hrefResolver, const Node *relative)
static QList< IR::SignatureSpan > buildCppSynopsisSpans(const Node *node, const HrefResolver *hrefResolver, const Node *relative, Section::Style style)
static QString threadSafenessString(Node::ThreadSafeness ts)
IR::CppReferenceData extractCppReferenceData(const Aggregate *aggregate, const HrefResolver *hrefResolver)
static IR::AllMembersIR extractCppAllMembersIR(const Aggregate *aggregate, const HrefResolver *hrefResolver)
IR::NavigationData extractNavigationData(const PageNode *pn, const HrefResolver *hrefResolver)
static QList< IR::SignatureSpan > buildExtraSpans(const Node *node, Section::Style style)
QList< Node * > NodeList
Definition node.h:45
QMap< QString, Node * > NodeMap
Definition node.h:48
static QString resolveHref(const HrefResolver *resolver, const Node *target, const Node *relative)
static IR::DiagnosticHandler diagnosticHandlerFor(const Node *node)
MemberExtractionLevel
QList< const Section * > SectionPtrVector
Definition sections.h:77
QList< ClassNodes > ClassNodesList
Definition sections.h:14
@ Deprecated
Definition status.h:12
@ Active
Definition status.h:14
@ Preliminary
Definition status.h:13
A single entry in an all-members listing page.
Definition member.h:129
Intermediate representation of the all-members listing page.
Definition member.h:146
Intermediate representation of a single documentable member.
Definition member.h:54
bool isPrimaryOverload
Definition member.h:72
bool isConst
Definition member.h:77
int overloadNumber
Definition member.h:71
bool isAttached
Definition member.h:83
bool isDefault
Definition member.h:84
bool isSlot
Definition member.h:80
bool isRequired
Definition member.h:86
bool isStatic
Definition member.h:76
bool isNoexcept
Definition member.h:96
bool isSignal
Definition member.h:79
Access access
Definition member.h:62
NodeType nodeType
Definition member.h:61
bool isReadOnly
Definition member.h:85
bool isVirtual
Definition member.h:78
Status status
Definition member.h:63
Intermediate representation of a function parameter.
Definition member.h:21
Represents a single span within a structured signature.
The Node class is the base class for all the nodes in QDoc's parse tree.
const Doc & doc() const
Returns a reference to the node's Doc data member.
Definition node.h:239
bool isQmlNode() const
Returns true if this node's Genus value is QML.
Definition node.h:121
bool isGroup() const
Returns true if the node type is Group.
Definition node.h:105
bool isNamespace() const
Returns true if the node type is Namespace.
Definition node.h:110
bool isTypedef() const
Returns true if the node type is Typedef.
Definition node.h:128
bool isQmlBasicType() const
Returns true if the node type is QmlBasicType.
Definition node.h:119
ComparisonCategory comparisonCategory() const
Definition node.h:187
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
Definition node.h:123
bool isHeader() const
Returns true if the node type is HeaderFile.
Definition node.h:106
NodeType nodeType() const override
Returns this node's type.
Definition node.h:82
Genus genus() const override
Returns this node's Genus.
Definition node.h:85
bool isEnumType() const
Returns true if the node type is Enum.
Definition node.h:94
virtual Status status() const
Returns the node's status value.
Definition node.h:243
bool isConcept() const
Definition node.h:109
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
Definition node.h:211
virtual bool isAggregate() const
Returns true if this node is an aggregate, which means it inherits Aggregate and can therefore have c...
Definition node.h:138
static bool nodeNameLessThan(const Node *first, const Node *second)
Returns true if the node n1 is less than node n2.
Definition node.cpp:111
bool isProxyNode() const
Returns true if the node type is Proxy.
Definition node.h:115
const std::optional< RelaxedTemplateDeclaration > & templateDecl() const
Definition node.h:247
Access access() const
Returns the node's Access setting, which can be Public, Protected, or Private.
Definition node.h:232
bool isFunction(Genus g=Genus::DontCare) const
Returns true if this is a FunctionNode and its Genus is set to g.
Definition node.h:101
ThreadSafeness threadSafeness() const
Returns the thread safeness value for whatever this node represents.
Definition node.cpp:845
bool isProperty() const
Returns true if the node type is Property.
Definition node.h:114
NodeContext createContext() const
Definition node.cpp:175
bool isModule() const
Returns true if the node type is Module.
Definition node.h:108
ThreadSafeness
An unsigned char that specifies the degree of thread-safeness of the element.
Definition node.h:58
@ ThreadSafe
Definition node.h:62
@ NonReentrant
Definition node.h:60
@ UnspecifiedSafeness
Definition node.h:59
@ Reentrant
Definition node.h:61
@ NextLink
Definition node.h:73
@ StartLink
Definition node.h:73
@ PreviousLink
Definition node.h:73
bool isRelatedNonmember() const
Returns true if this is a related nonmember of something.
Definition node.h:124
virtual bool isClassNode() const
Returns true if this is an instance of ClassNode.
Definition node.h:145
virtual bool isCollectionNode() const
Returns true if this is an instance of CollectionNode.
Definition node.h:146
bool isQmlModule() const
Returns true if the node type is QmlModule.
Definition node.h:120
@ SignatureReturnType
Definition node.h:68
@ SignatureDefaultValues
Definition node.h:67
bool isQmlProperty() const
Returns true if the node type is QmlProperty.
Definition node.h:122
A class for parsing and managing a function parameter list.
Definition main.cpp:28
const Parameter & at(int i) const
Definition parameters.h:36
int count() const
Definition parameters.h:34