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
generator.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include "generator.h"
5
6#include "access.h"
7#include "aggregate.h"
8#include "classnode.h"
9#include "codemarker.h"
10#include "codeparser.h"
11#include "collectionnode.h"
13#include "config.h"
14#include "doc.h"
15#include "editdistance.h"
16#include "enumnode.h"
17#include "examplenode.h"
18#include "functionnode.h"
21#include "inode.h"
22#include "locationplan.h"
23#include "node.h"
25#include "openedlist.h"
28#include "propertynode.h"
29#include "qdocdatabase.h"
30#include "qmltypenode.h"
32#include "quoter.h"
34#include "tokenizer.h"
35#include "typedefnode.h"
36#include "utilities.h"
37#include "textutils.h"
38
39#include <QtCore/qdebug.h>
40#include <QtCore/qdir.h>
41#include <QtCore/qregularexpression.h>
42
43#ifndef QT_BOOTSTRAPPED
44# include "QtCore/qurl.h"
45#endif
46
47#include <string>
48#include <utility>
49
50using namespace std::literals::string_literals;
51
52QT_BEGIN_NAMESPACE
53
54using namespace Qt::StringLiterals;
55
56Generator *Generator::s_currentGenerator;
57QMap<QString, QMap<QString, QString>> Generator::s_fmtLeftMaps;
58QMap<QString, QMap<QString, QString>> Generator::s_fmtRightMaps;
59QList<Generator *> Generator::s_generators;
60QString Generator::s_outDir;
61QString Generator::s_imagesOutDir;
62QString Generator::s_outSubdir;
63QStringList Generator::s_outFileNames;
64QList<const PageNode *> Generator::s_generatedPages;
65QStringList Generator::s_exampleImageFileNames;
66QSet<QString> Generator::s_trademarks;
67QSet<QString> Generator::s_outputFormats;
68QHash<QString, QString> Generator::s_outputPrefixes;
69QHash<QString, QString> Generator::s_outputSuffixes;
70QString Generator::s_project;
71bool Generator::s_noLinkErrors = false;
72bool Generator::s_autolinkErrors = false;
74bool Generator::s_useOutputSubdirs = true;
75QmlTypeNode *Generator::s_qmlTypeContext = nullptr;
76
77static QRegularExpression tag("</?@[^>]*>");
78static QLatin1String amp("&amp;");
79static QLatin1String gt("&gt;");
80static QLatin1String lt("&lt;");
81static QLatin1String quot("&quot;");
82
83/*!
84 Returns the set of template parameter names inherited from the parent
85 scope chain of \a node. This includes template parameters from enclosing
86 class templates, which are visible but not required to be documented
87 in nested classes or member functions.
88*/
90{
91 QSet<QString> names;
92 for (const Node *p = node->parent(); p; p = p->parent()) {
94 names.unite(p->templateDecl()->parameterNames());
95 }
96 return names;
97}
98
99/*!
100 \enum ValidationContext
101 Selects warning message wording based on documentation context.
102
103 \value FunctionDoc Warns "No such parameter" (function docs may reference
104 both function parameters and template parameters).
105 \value TemplateDoc Warns "No such template parameter" (template class/alias
106 docs reference only template parameters).
107*/
109
110/*!
111 Warns about documented parameter names in \a node that don't exist in
112 \a allowedNames. Uses \a context to select appropriate wording.
113*/
115 const QSet<QString> &documentedNames,
116 const QSet<QString> &allowedNames,
117 ValidationContext context)
118{
119 for (const auto &name : documentedNames) {
120 if (!allowedNames.contains(name) && CodeParser::isWorthWarningAbout(node->doc())) {
121 const auto message = (context == ValidationContext::TemplateDoc)
122 ? "No such template parameter '%1' in %2"_L1
123 : "No such parameter '%1' in %2"_L1;
124 node->doc().location().warning(message.arg(name, node->plainFullName()),
125 suggestName(name, allowedNames));
126 }
127 }
128}
129
130/*!
131 Constructs the generator base class. Prepends the newly
132 constructed generator to the list of output generators.
133 Sets a pointer to the QDoc database singleton, which is
134 available to the generator subclasses.
135 */
137 : file_resolver{file_resolver}
138{
140 s_generators.prepend(this);
141}
142
143/*!
144 Destroys the generator after removing it from the list of
145 output generators.
146 */
148{
149 s_generators.removeAll(this);
150}
151
152void Generator::appendFullName(Text &text, const Node *apparentNode, const Node *relative,
153 const Node *actualNode)
154{
155 if (actualNode == nullptr)
156 actualNode = apparentNode;
157
158 addNodeLink(text, actualNode, apparentNode->plainFullName(relative));
159}
160
161void Generator::appendFullName(Text &text, const Node *apparentNode, const QString &fullName,
162 const Node *actualNode)
163{
164 if (actualNode == nullptr)
165 actualNode = apparentNode;
166
167 addNodeLink(text, actualNode, fullName);
168}
169
170/*!
171 Append the signature for the function named in \a node to
172 \a text, so that is a link to the documentation for that
173 function.
174 */
175void Generator::appendSignature(Text &text, const Node *node)
176{
177 addNodeLink(text, node, node->signature(Node::SignaturePlain));
178}
179
180/*!
181 Generate a bullet list of function signatures. The function
182 nodes are in \a nodes. It uses the \a relative node and the
183 \a marker for the generation.
184 */
185void Generator::signatureList(const NodeList &nodes, const Node *relative, CodeMarker *marker)
186{
187 Text text;
188 int count = 0;
189 text << Atom(Atom::ListLeft, QString("bullet"));
190 for (const auto &node : nodes) {
191 text << Atom(Atom::ListItemNumber, QString::number(++count));
192 text << Atom(Atom::ListItemLeft, QString("bullet"));
193 appendSignature(text, node);
194 text << Atom(Atom::ListItemRight, QString("bullet"));
195 }
196 text << Atom(Atom::ListRight, QString("bullet"));
197 generateText(text, relative, marker);
198}
199
200int Generator::appendSortedNames(Text &text, const ClassNode *cn, const QList<RelatedClass> &rc)
201{
202 QMap<QString, Text> classMap;
203 for (const auto &relatedClass : rc) {
204 ClassNode *rcn = relatedClass.m_node;
205 if (rcn && rcn->isInAPI()) {
206 Text className;
207 appendFullName(className, rcn, cn);
208 classMap[className.toString().toLower()] = className;
209 }
210 }
211
212 int index = 0;
213 const QStringList classNames = classMap.keys();
214 for (const auto &className : classNames) {
215 text << classMap[className];
216 text << TextUtils::comma(index++, classNames.size());
217 }
218 return index;
219}
220
221int Generator::appendSortedQmlNames(Text &text, const Node *base, const QStringList &knownTypes,
222 const NodeList &subs)
223{
224 QMap<QString, Text> classMap;
225
226 QStringList typeNames(knownTypes);
227 for (const auto sub : subs)
228 typeNames << sub->name();
229
230 for (const auto sub : subs) {
231 Text full_name;
232 appendFullName(full_name, sub, base);
233 // Disambiguate with '(<QML module name>)' if there are clashing type names
234 if (typeNames.count(sub->name()) > 1)
235 full_name << Atom(Atom::String, " (%1)"_L1.arg(sub->logicalModuleName()));
236 classMap[full_name.toString().toLower()] = full_name;
237 }
238
239 int index = 0;
240 const auto &names = classMap.keys();
241 for (const auto &name : names)
242 text << classMap[name] << TextUtils::comma(index++, names.size());
243 return index;
244}
245
246/*!
247 Creates the file named \a fileName in the output directory
248 and returns a QFile pointing to this file. In particular,
249 this method deals with errors when opening the file:
250 the returned QFile is always valid and can be written to.
251
252 If \a fileName is the canonical file name of \a node, the node is
253 recorded as one for which a page was generated; see generatedPages().
254
255 \sa beginSubPage()
256 */
257QFile *Generator::openSubPageFile(const PageNode *node, const QString &fileName)
258{
259 // Skip generating a warning for license attribution pages, as their source
260 // is generated by qtattributionsscanner and may potentially include duplicates.
261 // NOTE: Depending on the value of the `QtParts` field in qt_attribution.json files,
262 // qtattributionsscanner may not use the \attribution QDoc command for the page
263 // (by design). Therefore, check also filename.
264 if (s_outFileNames.contains(fileName) && !node->isAttribution() && !fileName.contains("-attribution-"_L1))
265 node->location().warning("Already generated %1 for this project"_L1.arg(fileName));
266
267 QString path = outputDir() + QLatin1Char('/') + fileName;
268
269 const auto &outPath = s_redirectDocumentationToDevNull ? QStringLiteral("/dev/null") : path;
270 auto outFile = new QFile(outPath);
271
272 if (!s_redirectDocumentationToDevNull && outFile->exists()) {
273 const QString warningText {"Output file already exists, overwriting %1"_L1.arg(outFile->fileName())};
274 if (qEnvironmentVariableIsSet("QDOC_ALL_OVERWRITES_ARE_WARNINGS"))
275 node->location().warning(warningText);
276 else
277 qCDebug(lcQdoc) << qUtf8Printable(warningText);
278 }
279
280 if (!outFile->open(QFile::WriteOnly | QFile::Text)) {
281 node->location().fatal(
282 QStringLiteral("Cannot open output file '%1'").arg(outFile->fileName()));
283 }
284
285 qCDebug(lcQdoc, "Writing: %s", qPrintable(path));
286 s_outFileNames << fileName;
287 // A page written under a name other than the node's canonical file name is an
288 // auxiliary one - an `All members` or `Obsolete members` list, or a listing of
289 // a file included in an example. Such pages are reachable from the node's own
290 // page, and are never listed on their own.
291 if (fileName == this->fileName(node))
292 s_generatedPages << node;
293 s_trademarks.clear();
294 return outFile;
295}
296
297/*!
298 Creates the file named \a fileName in the output directory.
299 Attaches a QTextStream to the created file, which is written
300 to using out().
301
302 The associated page \a node is used for error reporting.
303
304 \sa openSubPageFile()
305 */
306void Generator::beginSubPage(const PageNode *node, const QString &fileName)
307{
308 QFile *outFile = openSubPageFile(node, fileName);
309 auto *out = new QTextStream(outFile);
310 outStreamStack.push(out);
311}
312
313/*!
314 Flush the text stream associated with the subpage, and
315 then pop it off the text stream stack and delete it.
316 This terminates output of the subpage.
317 */
319{
320 outStreamStack.top()->flush();
321 delete outStreamStack.top()->device();
322 delete outStreamStack.pop();
323}
324
325QString Generator::fileBase(const Node *node) const
326{
327 if (!node->isPageNode() && !node->isCollectionNode())
328 node = node->parent();
329
330 if (node->hasFileNameBase())
331 return node->fileNameBase();
332
333 QString result = Utilities::computeFileBase(
334 node, s_project,
335 [](const Node *n) { return outputPrefix(n); },
336 [](const Node *n) { return outputSuffix(n); });
337
338 const_cast<Node *>(node)->setFileNameBase(result);
339 return result;
340}
341
342/*!
343 Constructs an href link from an example file name, which
344 is a \a path to the example file. If \a fileExt is empty
345 (default value), retrieve the file extension from
346 the generator.
347 */
348QString Generator::linkForExampleFile(const QString &path, const QString &fileExt) const
349{
350 return Utilities::linkForExampleFile(path, s_project, fileExt.isEmpty() ? fileExtension() : fileExt);
351}
352
353/*!
354 Helper function to construct a title for a file or image page
355 included in an example.
356*/
357QString Generator::exampleFileTitle(const ExampleNode *relative, const QString &fileName)
358{
359 return Utilities::exampleFileTitle(relative->files(), relative->images(), fileName);
360}
361
362/*!
363 If the \a node has a URL, return the URL as the file name.
364 Otherwise, construct the file name from the fileBase() and
365 either the provided \a extension or fileExtension(), and
366 return the constructed name.
367 */
368QString Generator::fileName(const Node *node, const QString &extension) const
369{
370 if (!node->url().isEmpty())
371 return node->url();
372
373 // Special case for simple page nodes (\page commands) with explicit
374 // non-.html extensions. Use the normalized fileBase() but preserve
375 // user specified extension
376 if (node->isTextPageNode() && !node->isCollectionNode() && extension.isNull()) {
377 QFileInfo originalName(node->name());
378 QString suffix = originalName.suffix();
379 if (!suffix.isEmpty() && suffix != "html") {
380 // User specified a non-.html extension - use normalized base + original extension
381 QString name = fileBase(node);
382 return name + QLatin1Char('.') + suffix;
383 }
384 }
385
386 QString name = fileBase(node) + QLatin1Char('.');
387 return name + (extension.isNull() ? fileExtension() : extension);
388}
389
390/*!
391 Clean the given \a ref to be used as an HTML anchor or an \c xml:id.
392 If \a xmlCompliant is set to \c true, a stricter process is used, as XML
393 is more rigorous in what it accepts. Otherwise, if \a xmlCompliant is set to
394 \c false, the basic HTML transformations are applied.
395
396 More specifically, only XML NCNames are allowed
397 (https://www.w3.org/TR/REC-xml-names/#NT-NCName).
398 */
399QString Generator::cleanRef(const QString &ref, bool xmlCompliant)
400{
401 return TextUtils::cleanAnchorRef(ref, xmlCompliant ? TextUtils::AnchorSyntax::Xml
403}
404
406{
407 return s_fmtLeftMaps[format()];
408}
409
411{
412 return s_fmtRightMaps[format()];
413}
414
415/*!
416 Returns the full document location of \a node: its page file name and,
417 for a member, the anchor fragment within that page. The rules live in
418 LocationPlan::resolveDocumentLocation() so that exchange metadata planned
419 before rendering and the legacy generators agree on every location; this
420 generator only supplies its file base and extension.
421 */
422QString Generator::fullDocumentLocation(const Node *node) const
423{
425 node, [this](const Node *n) { return fileBase(n); }, fileExtension());
426}
427
428/*!
429 Generates text for a "see also" list for the given \a node and \a marker
430 if a list has been defined.
431
432 Check for links to the node containing the \sa command, looking for empty
433 ref fields to ensure that a link is referring to the node itself and not
434 a different section of a larger document.
435*/
436void Generator::generateAlsoList(const Node *node, CodeMarker *marker)
437{
438 QList<Text> alsoList = node->doc().alsoList();
439 supplementAlsoList(node, alsoList);
440
441 if (!alsoList.isEmpty()) {
442 Text text;
443 text << Atom::ParaLeft << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) << "See also "
445
446 QSet<QString> used;
447 QList<Text> items;
448 for (const auto &also : std::as_const(alsoList)) {
449 // Every item starts with a link atom.
450 const Atom *atom = also.firstAtom();
451 QString link = atom->string();
452 if (!used.contains(link)) {
453 items.append(also);
454 used.insert(link);
455
456 QString ref;
457 if (m_qdb->findNodeForAtom(atom, node, ref) == node && ref.isEmpty())
458 node->doc().location().warning("Redundant link to self in \\sa command for %1"_L1.arg(node->name()));
459 }
460 }
461
462 int i = 0;
463 for (const auto &also : std::as_const(items))
464 text << also << TextUtils::separator(i++, items.size());
465
466 text << Atom::ParaRight;
467 generateText(text, node, marker);
468 }
469}
470
471const Atom *Generator::generateAtomList(const Atom *atom, const Node *relative, CodeMarker *marker,
472 bool generate, int &numAtoms)
473{
474 while (atom != nullptr) {
475 if (atom->type() == Atom::FormatIf) {
476 int numAtoms0 = numAtoms;
477 bool rightFormat = canHandleFormat(atom->string());
478 atom = generateAtomList(atom->next(), relative, marker, generate && rightFormat,
479 numAtoms);
480 if (atom == nullptr)
481 return nullptr;
482
483 if (atom->type() == Atom::FormatElse) {
484 ++numAtoms;
485 atom = generateAtomList(atom->next(), relative, marker, generate && !rightFormat,
486 numAtoms);
487 if (atom == nullptr)
488 return nullptr;
489 }
490
491 if (atom->type() == Atom::FormatEndif) {
492 if (generate && numAtoms0 == numAtoms) {
493 relative->location().warning(QStringLiteral("Output format %1 not handled %2")
494 .arg(format(), outFileName()));
495 Atom unhandledFormatAtom(Atom::UnhandledFormat, format());
496 generateAtomList(&unhandledFormatAtom, relative, marker, generate, numAtoms);
497 }
498 atom = atom->next();
499 }
500 } else if (atom->type() == Atom::FormatElse || atom->type() == Atom::FormatEndif) {
501 return atom;
502 } else {
503 int n = 1;
504 if (generate) {
505 n += generateAtom(atom, relative, marker);
506 numAtoms += n;
507 }
508 while (n-- > 0)
509 atom = atom->next();
510 }
511 }
512 return nullptr;
513}
514
515
516/*!
517 Generate the body of the documentation from the qdoc comment
518 found with the entity represented by the \a node.
519 */
520void Generator::generateBody(const Node *node, CodeMarker *marker)
521{
522 const FunctionNode *fn = node->isFunction() ? static_cast<const FunctionNode *>(node) : nullptr;
523 if (!node->hasDoc()) {
524 /*
525 Test for special function, like a destructor or copy constructor,
526 that has no documentation.
527 */
528 if (fn) {
529 if (fn->isDtor()) {
530 Text text;
531 text << "Destroys the instance of ";
532 text << fn->parent()->name() << ".";
533 if (fn->isVirtual())
534 text << " The destructor is virtual.";
535 out() << "<p>";
536 generateText(text, node, marker);
537 out() << "</p>";
538 } else if (fn->isCtor()) {
539 Text text;
540 text << "Default-constructs an instance of "
541 << fn->parent()->name() << ".";
542 out() << "<p>";
543 generateText(text, node, marker);
544 out() << "</p>";
545 } else if (fn->isCCtor()) {
546 Text text;
547 text << "Copy-constructs an instance of "
548 << fn->parent()->name() << ".";
549 out() << "<p>";
550 generateText(text, node, marker);
551 out() << "</p>";
552 } else if (fn->isMCtor()) {
553 Text text;
554 text << "Move-constructs an instance of "
555 << fn->parent()->name() << ".";
556 out() << "<p>";
557 generateText(text, node, marker);
558 out() << "</p>";
559 } else if (fn->isCAssign()) {
560 Text text;
561 text << "Copy-assigns "
564 << " to this " << fn->parent()->name() << " instance.";
565 out() << "<p>";
566 generateText(text, node, marker);
567 out() << "</p>";
568 } else if (fn->isMAssign()) {
569 Text text;
570 text << "Move-assigns "
573 << " to this " << fn->parent()->name() << " instance.";
574 out() << "<p>";
575 generateText(text, node, marker);
576 out() << "</p>";
577 } else if (!node->isWrapper() && !node->isMarkedReimp()) {
578 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
579 const NodeContext context = node->createContext();
580 if (!fn->isIgnored() && InclusionFilter::requiresDocumentation(policy, context)) // undocumented functions added by Q_OBJECT
581 node->location().warning(
582 QStringLiteral("No documentation for %1 '%2'")
583 .arg(fn->kindString(), node->plainSignature()));
584 }
585 } else if (!node->isWrapper() && !node->isMarkedReimp()) {
586 // Don't require documentation of things defined in Q_GADGET
587 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
588 const NodeContext context = node->createContext();
589 if (node->name() != QLatin1String("QtGadgetHelper") && InclusionFilter::requiresDocumentation(policy, context))
590 node->location().warning(
591 QStringLiteral("No documentation for '%1'").arg(node->plainSignature()));
592 }
593 } else if (!node->isSharingComment()) {
594 // Reimplements clause and type alias info precede body text
595 if (fn && !fn->overridesThis().isEmpty())
596 generateReimplementsClause(fn, marker);
597 else if (node->isProperty()) {
598 if (static_cast<const PropertyNode *>(node)->propertyType() != PropertyNode::PropertyType::StandardProperty)
600 }
601
602 if (!generateText(node->doc().body(), node, marker)) {
603 if (node->isMarkedReimp())
604 return;
605 }
606
607 if (fn) {
608 if (fn->isQmlSignal())
612 if (fn->isInvokable())
616 if (fn->hasOverloads() && fn->doc().hasOverloadCommand()
617 && !fn->isSignal() && !fn->isSlot())
619 }
620
621 // Generate warnings
622 if (node->isEnumType()) {
623 const auto *enume = static_cast<const EnumNode *>(node);
624
625 QSet<QString> definedItems;
626 const QList<EnumItem> &items = enume->items();
627 for (const auto &item : items)
628 definedItems.insert(item.name());
629
630 const auto &documentedItemList = enume->doc().enumItemNames();
631 QSet<QString> documentedItems(documentedItemList.cbegin(), documentedItemList.cend());
632 const QSet<QString> allItems = definedItems + documentedItems;
633 if (allItems.size() > definedItems.size()
634 || allItems.size() > documentedItems.size()) {
635 for (const auto &it : allItems) {
636 if (!definedItems.contains(it)) {
637 node->doc().location().warning(
638 QStringLiteral("No such enum item '%1' in %2")
639 .arg(it, node->plainFullName()),
640 QStringLiteral("Maybe you meant '%1'?")
641 .arg(suggestName(it, definedItems, documentedItems)));
642 } else if (!documentedItems.contains(it)) {
643 node->doc().location().warning(
644 QStringLiteral("Undocumented enum item '%1' in %2")
645 .arg(it, node->plainFullName()));
646 }
647 }
648 }
649 } else if (fn) {
650 // Build name environment with visibility vs. responsibility distinction:
651 // - requiredNames: names that must be documented (function params + API-significant template params)
652 // - allowedNames: all names that can be referenced (includes type template params + inherited)
653 //
654 // For functions, type template parameters (typename T) are not required because
655 // they typically serve to type function parameters - documenting the function
656 // parameter implicitly covers the template parameter's role. Only non-type and
657 // template-template parameters are required as they carry independent meaning.
658 const QSet<QString> requiredFunctionParams = fn->parameters().getNames();
659 const QSet<QString> requiredTemplateParams = fn->templateDecl()
660 ? fn->templateDecl()->requiredParameterNamesForFunctions()
661 : QSet<QString>{};
662 const QSet<QString> requiredNames = requiredFunctionParams + requiredTemplateParams;
663
664 // All template parameters (including type params and inherited from parent chain)
665 // are allowed to be referenced without "no such parameter" warnings
666 const QSet<QString> ownTemplateParams = fn->templateDecl()
667 ? fn->templateDecl()->parameterNames()
668 : QSet<QString>{};
669 const QSet<QString> allowedNames = requiredNames + ownTemplateParams
670 + inheritedTemplateParamNames(fn);
671
672 const QSet<QString> documentedNames = fn->doc().parameterNames();
673
674 // Warn about missing required parameters
675 for (const auto &name : requiredNames) {
676 if (!documentedNames.contains(name)) {
677 if (fn->isActive() || fn->isPreliminary()) {
678 // Require no parameter documentation for overrides and overloads,
679 // and only require it for non-overloaded constructors.
680 if (!fn->isMarkedReimp() && !fn->isOverload()
681 && !(fn->isSomeCtor() && fn->hasOverloads())) {
682 // Use appropriate wording based on parameter type
683 const bool isTemplateParam = requiredTemplateParams.contains(name);
684 fn->doc().location().warning(
685 "Undocumented %1 '%2' in %3"_L1
686 .arg(isTemplateParam ? "template parameter"_L1
687 : "parameter"_L1,
688 name, node->plainFullName()));
689 }
690 }
691 }
692 }
693
694 warnAboutUnknownDocumentedParams(fn, documentedNames, allowedNames,
696 /*
697 This return value check should be implemented
698 for all functions with a return type.
699 mws 13/12/2018
700 */
702 && !fn->isOverload()) {
703 if (!fn->doc().body().contains("return"))
704 node->doc().location().warning(
705 QStringLiteral("Undocumented return value "
706 "(hint: use 'return' or 'returns' in the text"));
707 }
708 } else if (node->isQmlProperty()) {
709 if (auto *qpn = static_cast<const QmlPropertyNode *>(node); !qpn->validateDataType())
710 qpn->doc().location().warning("Invalid QML property type: %1"_L1.arg(qpn->dataType()));
711 } else if (node->templateDecl()) {
712 // Template classes, type aliases, and other non-function template declarations
713 // Use the same visibility vs. responsibility model as functions:
714 // - requiredNames: template params declared on this node (must be documented)
715 // - allowedNames: required + inherited from parent chain (can be referenced)
716 const QSet<QString> requiredNames = node->templateDecl()->parameterNames();
717 const QSet<QString> allowedNames = requiredNames + inheritedTemplateParamNames(node);
718 const QSet<QString> documentedNames = node->doc().parameterNames();
719
720 if (node->isActive() || node->isPreliminary()) {
721 for (const auto &name : requiredNames) {
722 if (!documentedNames.contains(name) && CodeParser::isWorthWarningAbout(node->doc())) {
723 node->doc().location().warning(
724 "Undocumented template parameter '%1' in %2"_L1
725 .arg(name, node->plainFullName()));
726 }
727 }
728 }
729
730 warnAboutUnknownDocumentedParams(node, documentedNames, allowedNames,
732 }
733 }
735 generateRequiredLinks(node, marker);
736}
737
738/*!
739 Generates either a link to the project folder for example \a node, or a list
740 of links files/images if 'url.examples config' variable is not defined.
741
742 Does nothing for non-example nodes.
743*/
745{
746 if (!node->isExample())
747 return;
748
749 const auto *en = static_cast<const ExampleNode *>(node);
750 QString exampleUrl{Config::instance().get(CONFIG_URL + Config::dot + CONFIG_EXAMPLES).asString()};
751
752 if (exampleUrl.isEmpty()) {
753 if (!en->noAutoList()) {
754 generateFileList(en, marker, false); // files
755 generateFileList(en, marker, true); // images
756 }
757 } else {
758 generateLinkToExample(en, marker, exampleUrl);
759 }
760}
761
762/*!
763 Generates an external link to the project folder for example \a node.
764 The path to the example replaces a placeholder '\1' character if
765 one is found in the \a baseUrl string. If no such placeholder is found,
766 the path is appended to \a baseUrl, after a '/' character if \a baseUrl did
767 not already end in one.
768*/
770 const QString &baseUrl)
771{
772 QString exampleUrl(baseUrl);
773 QString link;
774#ifndef QT_BOOTSTRAPPED
775 link = QUrl(exampleUrl).host();
776#endif
777 if (!link.isEmpty())
778 link.prepend(" @ ");
779 link.prepend("Example project");
780
781 const QLatin1Char separator('/');
782 const QLatin1Char placeholder('\1');
783 if (!exampleUrl.contains(placeholder)) {
784 if (!exampleUrl.endsWith(separator))
785 exampleUrl += separator;
786 exampleUrl += placeholder;
787 }
788
789 // Construct a path to the example; <install path>/<example name>
790 QString pathRoot;
791 QStringMultiMap *metaTagMap = en->doc().metaTagMap();
792 if (metaTagMap)
793 pathRoot = metaTagMap->value(QLatin1String("installpath"));
794 if (pathRoot.isEmpty())
795 pathRoot = Config::instance().get(CONFIG_EXAMPLESINSTALLPATH).asString();
796 QStringList path = QStringList() << pathRoot << en->name();
797 path.removeAll(QString());
798
799 Text text;
800 text << Atom::ParaLeft
801 << Atom(Atom::Link, exampleUrl.replace(placeholder, path.join(separator)))
804
805 generateText(text, nullptr, marker);
806}
807
808void Generator::addImageToCopy(const ExampleNode *en, const ResolvedFile& resolved_file)
809{
810 // TODO: [uncentralized-output-directory-structure]
811 const QString prefix("/images/used-in-examples");
812
813 // TODO: Generators probably should not need to keep track of which files were generated.
814 // Understand if we really need this information and where it should
815 // belong, considering that it should be part of whichever system
816 // would actually store the file itself.
817 s_exampleImageFileNames << prefix.mid(1) + "/" + resolved_file.get_query();
818
819 const OutputDirectory outDir =
820 OutputDirectory::ensure(s_outDir, en->location());
821 const OutputDirectory imagesUsedInExamplesDir =
822 outDir.ensureSubdir(prefix.mid(1), en->location());
823
824 const QFileInfo fi{resolved_file.get_query()};
825 const QString relativePath = fi.path();
826 // QFileInfo::path() can return "." for files with no directory component
827 const bool hasSubdir = !relativePath.isEmpty() && relativePath != "."_L1;
828 const OutputDirectory imgOutDir =
829 hasSubdir ? imagesUsedInExamplesDir.ensureSubdir(relativePath, en->location())
830 : imagesUsedInExamplesDir;
831
832 const QString fileName = fi.fileName();
833 Config::copyFile(en->location(), resolved_file.get_path(), fileName, imgOutDir.path());
834}
835
836// TODO: [multi-purpose-function-with-flag][generate-file-list]
837// Avoid the use of a boolean flag to dispatch to the correct
838// implementation trough branching.
839// We always have to process both images and files, such that we
840// should consider to remove the branching altogheter, performing both
841// operations in a single call.
842// Otherwise, if this turns out to be infeasible, complex or
843// possibly-confusing, consider extracting the processing code outside
844// the function and provide two higer-level dispathing functions for
845// files and images.
846
847/*!
848 This function is called when the documentation for an example is
849 being formatted. It outputs a list of files for the example, which
850 can be the example's source files or the list of images used by the
851 example. The images are copied into a subtree of
852 \c{...doc/html/images/used-in-examples/...}
853*/
854void Generator::generateFileList(const ExampleNode *en, CodeMarker *marker, bool images)
855{
856 Text text;
858 QString tag;
859 QStringList paths;
861
862 if (images) {
863 paths = en->images();
864 tag = "Images:";
865 atomType = Atom::ExampleImageLink;
866 } else { // files
867 paths = en->files();
868 tag = "Files:";
869 }
870 std::sort(paths.begin(), paths.end(), Generator::comparePaths);
871
872 text << Atom::ParaLeft << tag << Atom::ParaRight;
873 text << Atom(Atom::ListLeft, openedList.styleString());
874
875 for (const auto &path : std::as_const(paths)) {
876 auto maybe_resolved_file{file_resolver.resolve(path)};
877 if (!maybe_resolved_file) {
878 // TODO: [uncentralized-admonition][failed-resolve-file]
879 QString details = std::transform_reduce(
880 file_resolver.get_search_directories().cbegin(),
881 file_resolver.get_search_directories().cend(),
882 u"Searched directories:"_s,
883 std::plus(),
884 [](const DirectoryPath &directory_path) -> QString { return u' ' + directory_path.value(); }
885 );
886
887 en->location().warning(u"(Generator)Cannot find file to quote from: %1"_s.arg(path), details);
888
889 continue;
890 }
891
892 const auto &file{*maybe_resolved_file};
893 if (images)
894 addImageToCopy(en, file);
895 else
896 generateExampleFilePage(en, file, marker);
897
898 openedList.next();
899 text << Atom(Atom::ListItemNumber, openedList.numberString())
900 << Atom(Atom::ListItemLeft, openedList.styleString()) << Atom::ParaLeft
901 << Atom(atomType, file.get_query()) << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << file.get_query()
902 << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) << Atom::ParaRight
903 << Atom(Atom::ListItemRight, openedList.styleString());
904 }
905 text << Atom(Atom::ListRight, openedList.styleString());
906 if (!paths.isEmpty())
907 generateText(text, en, marker);
908}
909
910/*!
911 Recursive writing of HTML files from the root \a node.
912 */
914{
915 if (!node->url().isNull())
916 return;
917 if (node->isIndexNode())
918 return;
919 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
920 const NodeContext context = node->createContext();
921 if (!InclusionFilter::isIncluded(policy, context))
922 return;
923 if (node->isExternalPage())
924 return;
925
926 /*
927 Obtain a code marker for the source file.
928 */
929 CodeMarker *marker = CodeMarker::markerForFileName(node->location().filePath());
930
931 if (node->parent() != nullptr && node->isPageNode()) {
932 PageNode *pageNode = static_cast<PageNode *>(node);
933 if (pageNode->isCollectionNode()) {
934 /*
935 A collection node collects: groups, C++ modules, or QML
936 modules. Testing for a CollectionNode must be done
937 before testing for a TextPageNode because a
938 CollectionNode is a PageNode at this point.
939
940 Don't output an HTML page for the collection node unless
941 the \group, \module, or \qmlmodule command was actually
942 seen by qdoc in the qdoc comment for the node.
943
944 A key prerequisite in this case is the call to
945 mergeCollections(cn). We must determine whether this
946 group, module or QML module has members in other
947 modules. We know at this point that cn's members list
948 contains only members in the current module. Therefore,
949 before outputting the page for cn, we must search for
950 members of cn in the other modules and add them to the
951 members list.
952 */
953 auto *cn = static_cast<CollectionNode *>(node);
954 if (cn->wasSeen()) {
955 m_qdb->mergeCollections(cn);
956 beginSubPage(pageNode, fileName(node));
959 } else if (cn->isGenericCollection()) {
960 // Currently used only for the module's related orphans page
961 // but can be generalized for other kinds of collections if
962 // other use cases pop up.
963 QString name = cn->name().toLower();
964 name.replace(QChar(' '), QString("-"));
965 QString filename =
966 cn->tree()->physicalModuleName() + "-" + name + "." + fileExtension();
967 beginSubPage(pageNode, filename);
970 }
971 } else if (node->isTextPageNode()) {
972 beginSubPage(pageNode, fileName(node));
973 generatePageNode(pageNode, marker);
975 } else if (node->isAggregate()) {
976 if ((node->isClassNode() || node->isHeader() || node->isNamespace())
977 && node->docMustBeGenerated()) {
978 beginSubPage(pageNode, fileName(node));
979 generateCppReferencePage(static_cast<Aggregate *>(node), marker);
981 } else if (node->isQmlType()) {
982 beginSubPage(pageNode, fileName(node));
983 auto *qcn = static_cast<QmlTypeNode *>(node);
984 generateQmlTypePage(qcn, marker);
986 } else if (node->isProxyNode()) {
987 beginSubPage(pageNode, fileName(node));
988 generateProxyPage(static_cast<Aggregate *>(node), marker);
990 }
991 }
992 }
993
994 if (node->isAggregate()) {
995 auto *aggregate = static_cast<Aggregate *>(node);
996 const NodeList &children = aggregate->childNodes();
997 for (auto *child : children) {
998 if (child->isPageNode()) {
999 generateDocumentation(child);
1000 } else if (!node->parent() && child->isInAPI() && !child->isRelatedNonmember()
1001 && !child->doc().isAutoGenerated()) {
1002 // Warn if there are documented non-page-generating nodes in the root namespace
1003 child->location().warning(u"No documentation generated for %1 '%2' in global scope."_s
1004 .arg(NodeText::nodeTypeDescription(child), child->name()),
1005 u"Maybe you forgot to use the '\\relates' command?"_s);
1006 child->setStatus(Status::DontDocument);
1007 } else if (child->isQmlModule() && !child->wasSeen()) {
1008 // An undocumented QML module that was constructed as a placeholder
1009 auto *qmlModule = static_cast<CollectionNode *>(child);
1010 for (const auto *member : qmlModule->members()) {
1011 member->location().warning(
1012 u"Undocumented QML module '%1' referred by type '%2' or its members"_s
1013 .arg(qmlModule->name(), member->name()),
1014 u"Maybe you forgot to document '\\qmlmodule %1'?"_s
1015 .arg(qmlModule->name()));
1016 }
1017 } else if (child->isQmlType() && !child->hasDoc()) {
1018 // A placeholder QML type with incorrect module identifier
1019 auto *qmlType = static_cast<QmlTypeNode *>(child);
1020 if (auto qmid = qmlType->logicalModuleName(); !qmid.isEmpty())
1021 qmlType->location().warning(u"No such type '%1' in QML module '%2'"_s
1022 .arg(qmlType->name(), qmid));
1023 }
1024 }
1025 }
1026}
1027
1028void Generator::generateReimplementsClause(const FunctionNode *fn, CodeMarker *marker)
1029{
1030 if (fn->overridesThis().isEmpty() || !fn->parent()->isClassNode())
1031 return;
1032
1033 auto *cn = static_cast<ClassNode *>(fn->parent());
1034 const FunctionNode *overrides = cn->findOverriddenFunction(fn);
1035 if (overrides && !overrides->isPrivate() && !overrides->parent()->isPrivate()) {
1036 if (overrides->hasDoc()) {
1037 Text text;
1038 text << Atom::ParaLeft << "Reimplements: ";
1039 QString fullName =
1040 overrides->parent()->name()
1041 + "::" + overrides->signature(Node::SignaturePlain);
1042 appendFullName(text, overrides->parent(), fullName, overrides);
1043 text << "." << Atom::ParaRight;
1044 generateText(text, fn, marker);
1045 } else {
1046 fn->doc().location().warning(
1047 QStringLiteral("Illegal \\reimp; no documented virtual function for %1")
1048 .arg(overrides->plainSignature()));
1049 }
1050 return;
1051 }
1052 const PropertyNode *sameName = cn->findOverriddenProperty(fn);
1053 if (sameName && sameName->hasDoc()) {
1054 Text text;
1055 text << Atom::ParaLeft << "Reimplements an access function for property: ";
1056 QString fullName = sameName->parent()->name() + "::" + sameName->name();
1057 appendFullName(text, sameName->parent(), fullName, sameName);
1058 text << "." << Atom::ParaRight;
1059 generateText(text, fn, marker);
1060 }
1061}
1062
1063QString Generator::formatSince(const Node *node)
1064{
1065 QStringList since = node->since().split(QLatin1Char(' '));
1066
1067 // If there is only one argument, assume it is the product version number.
1068 if (since.size() == 1) {
1069 const QString productName = Config::instance().get(CONFIG_PRODUCTNAME).asString();
1070 return productName.isEmpty() ? node->since() : productName + " " + since[0];
1071 }
1072
1073 // Otherwise, use the original <project> <version> string.
1074 return node->since();
1075}
1076
1077/*!
1078 \internal
1079 Returns a string representing status information of a \a node.
1080
1081 If a status description is returned, it is one of:
1082 \list
1083 \li Custom status set explicitly in node's documentation using
1084 \c {\meta {status} {<description>}},
1085 \li 'Deprecated [since <version>]' (\\deprecated [<version>]),
1086 \li 'Until <version>',
1087 \li 'Preliminary' or the value of config variable `preliminary'
1088 (\\preliminary), or
1089 \li The description adopted from associated module's state:
1090 \c {\modulestate {<description>}}.
1091 \endlist
1092
1093 Otherwise, returns \c std::nullopt.
1094*/
1095std::optional<QString> formatStatus(const Node *node, QDocDatabase *qdb)
1096{
1097 QString status;
1098
1099 if (const auto metaMap = node->doc().metaTagMap(); metaMap) {
1100 status = metaMap->value("status");
1101 if (!status.isEmpty())
1102 return {status};
1103 }
1104 const auto &since = node->deprecatedSince();
1105 if (node->status() == Status::Deprecated) {
1106 status = u"Deprecated"_s;
1107 if (!since.isEmpty())
1108 status += " since %1"_L1.arg(since);
1109 } else if (!since.isEmpty()) {
1110 status = "Until %1"_L1.arg(since);
1111 } else if (node->status() == Status::Preliminary) {
1112 status = Config::instance().get(CONFIG_PRELIMINARY).asString();
1113 } else if (const auto collection = qdb->getModuleNode(node); collection) {
1114 status = collection->state();
1115 }
1116
1117 return status.isEmpty() ? std::nullopt : std::optional(status);
1118}
1119
1120void Generator::generateSince(const Node *node, CodeMarker *marker)
1121{
1122 if (node->since().isEmpty())
1123 return;
1124
1125 const auto *shared = node->isSharedCommentNode()
1126 ? static_cast<const SharedCommentNode *>(node) : nullptr;
1127 const bool plural = shared && shared->collective().size() > 1;
1128 const Node *described = plural ? shared->collective().first() : node;
1129 const auto number = plural ? NodeText::GrammaticalNumber::Plural
1131
1132 Text text;
1133 text << Atom::ParaLeft
1134 << (plural ? "These "_L1 : "This "_L1)
1135 << NodeText::nodeTypeDescription(described, number)
1136 << (plural ? " were "_L1 : " was "_L1)
1137 << "introduced in " << formatSince(node) << "." << Atom::ParaRight;
1138
1139 generateText(text, node, marker);
1140}
1141
1142void Generator::generateNoexceptNote(const Node *node, CodeMarker *marker)
1143{
1144 std::vector<const Node *> nodes;
1145 if (node->isSharedCommentNode()) {
1146 const auto &collective = static_cast<const SharedCommentNode *>(node)->collective();
1147 nodes.assign(collective.begin(), collective.end());
1148 } else {
1149 nodes.push_back(node);
1150 }
1151
1152 std::size_t position = 0;
1153 for (const Node *member : nodes) {
1154 ++position;
1155 if (!member->isFunction(Genus::CPP))
1156 continue;
1157
1158 const auto &noexceptExpr = static_cast<const FunctionNode *>(member)->getNoexcept();
1159 if (!noexceptExpr || noexceptExpr->isEmpty())
1160 continue;
1161
1162 QString subject;
1163 if (nodes.size() > 1)
1164 subject = " ("_L1 + QString::number(position) + ")"_L1;
1165 else
1166 subject = "This "_L1 + NodeText::nodeTypeDescription(member);
1167
1168 Text text;
1169 text << Atom::NoteLeft << subject
1170 << " is noexcept when "
1171 << Atom(Atom::C, marker->markedUpCode(*noexceptExpr, nullptr, Location()))
1172 << " is " << Atom(Atom::C, "true") << "." << Atom::NoteRight;
1173 generateText(text, member, marker);
1174 }
1175}
1176
1177void Generator::generateStatus(const Node *node, CodeMarker *marker)
1178{
1179 Text text;
1180
1181 // A property group is one documented entity; other shared comments
1182 // with several members describe each of them.
1183 const auto *shared = node->isSharedCommentNode()
1184 ? static_cast<const SharedCommentNode *>(node) : nullptr;
1185 const bool plural = shared && !shared->isPropertyGroup() && shared->collective().size() > 1;
1186 const QString subject = plural
1187 ? "These "_L1 + NodeText::nodeTypeDescription(shared->collective().first(), NodeText::GrammaticalNumber::Plural) + " are"_L1
1188 : "This "_L1 + NodeText::nodeTypeDescription(node) + " is"_L1;
1189
1190 switch (node->status()) {
1191 case Status::Active:
1192 // Output the module 'state' description if set.
1193 if (node->isModule() || node->isQmlModule()) {
1194 const QString &state = static_cast<const CollectionNode*>(node)->state();
1195 if (!state.isEmpty()) {
1196 text << Atom::ParaLeft << "This " << NodeText::nodeTypeDescription(node) << " is in "
1198 << Atom(Atom::FormattingRight, ATOM_FORMATTING_ITALIC) << " state."
1199 << Atom::ParaRight;
1200 break;
1201 }
1202 }
1203 if (const auto &version = node->deprecatedSince(); !version.isEmpty()) {
1204 text << Atom::ParaLeft << subject
1205 << " scheduled for deprecation in version "
1206 << version << ".";
1207 if (const Text reason = node->doc().deprecationText(); !reason.isEmpty())
1208 text << " " << reason;
1209 text << Atom::ParaRight;
1210 }
1211 break;
1212 case Status::Preliminary: {
1213 auto description = Config::instance()
1214 .get(CONFIG_PRELIMINARY + Config::dot + CONFIG_DESCRIPTION)
1215 .asString();
1216 description.replace('\1'_L1, NodeText::nodeTypeDescription(node));
1218 << description
1220 } break;
1221 case Status::Deprecated:
1222 text << Atom::ParaLeft;
1223 if (node->isAggregate())
1225 text << subject << " deprecated";
1226 if (const QString &version = node->deprecatedSince(); !version.isEmpty()) {
1227 text << " since ";
1228 if (node->isQmlNode() && !node->logicalModuleName().isEmpty())
1229 text << node->logicalModuleName() << " ";
1230 text << version;
1231 }
1232
1233 text << ". We strongly advise against using " << (plural ? "them" : "it")
1234 << " in new code.";
1235 if (node->isAggregate())
1237 if (const Text reason = node->doc().deprecationText(); !reason.isEmpty())
1238 text << " " << reason;
1239 text << Atom::ParaRight;
1240 break;
1241 case Status::Internal:
1243 if (node->isPageNode())
1245 << "Part of developer documentation for internal use."
1247 break;
1248 default:
1249 break;
1250 }
1251 generateText(text, node, marker);
1252}
1253
1254/*!
1255 Generates an addendum note of type \a type for \a node, using \a marker
1256 as the code marker.
1257*/
1258void Generator::generateAddendum(const Node *node, Addendum type, CodeMarker *marker,
1259 AdmonitionPrefix prefix)
1260{
1261 Q_ASSERT(node && !node->name().isEmpty());
1262 Text text;
1263 text << Atom(Atom::DivLeft,
1264 "class=\"admonition %1\""_L1.arg(prefix == AdmonitionPrefix::Note ? u"note"_s : u"auto"_s));
1265 text << Atom::ParaLeft;
1266
1267 switch (prefix) {
1269 break;
1272 << "Note: " << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD);
1273 break;
1274 }
1275 }
1276
1277 switch (type) {
1278 case Invokable:
1279 text << "This function can be invoked via the meta-object system and from QML. See "
1280 << Atom(Atom::AutoLink, "Q_INVOKABLE")
1283 break;
1284 case PrivateSignal:
1285 text << "This is a private signal. It can be used in signal connections "
1286 "but cannot be emitted by the user.";
1287 break;
1288 case QmlSignalHandler:
1289 {
1290 QString handler(node->name());
1291 qsizetype prefixLocation = handler.lastIndexOf('.', -2) + 1;
1292 handler[prefixLocation] = handler[prefixLocation].toTitleCase();
1293 handler.insert(prefixLocation, QLatin1String("on"));
1294 text << "The corresponding handler is "
1297 break;
1298 }
1300 {
1301 if (!node->isFunction())
1302 return;
1303 const auto *fn = static_cast<const FunctionNode *>(node);
1304 auto nodes = fn->associatedProperties();
1305 if (nodes.isEmpty())
1306 return;
1307 std::sort(nodes.begin(), nodes.end(), Node::nodeNameLessThan);
1308
1309 // Group properties by their role for more concise output
1310 QMap<PropertyNode::FunctionRole, QList<const PropertyNode *>> roleGroups;
1311 for (const auto *n : std::as_const(nodes)) {
1312 const auto *pn = static_cast<const PropertyNode *>(n);
1313 if (pn->isInAPI()) {
1314 PropertyNode::FunctionRole role = pn->role(fn);
1315 roleGroups[role].append(pn);
1316 }
1317 }
1318
1319 if (roleGroups.isEmpty())
1320 return;
1321
1322 // Generate text for each role group in an explicit order
1323 static constexpr PropertyNode::FunctionRole roleOrder[] = {
1329 };
1330 for (auto role : roleOrder) {
1331 const auto it = roleGroups.constFind(role);
1332 if (it == roleGroups.cend())
1333 continue;
1334
1335 const auto &properties = it.value();
1336
1337 QString msg;
1338 switch (role) {
1340 msg = u"Getter function"_s;
1341 break;
1343 msg = u"Setter function"_s;
1344 break;
1346 msg = u"Resetter function"_s;
1347 break;
1349 msg = u"Notifier signal"_s;
1350 break;
1352 msg = u"Bindable function"_s;
1353 break;
1354 default:
1355 continue;
1356 }
1357
1358 if (properties.size() == 1) {
1359 const auto *pn = properties.first();
1360 text << msg << u" for property "_s << Atom(Atom::Link, pn->name())
1361 << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << pn->name()
1362 << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) << u". "_s;
1363 } else {
1364 text << msg << u" for properties "_s;
1365 for (qsizetype i = 0; i < properties.size(); ++i) {
1366 const auto *pn = properties.at(i);
1367 text << Atom(Atom::Link, pn->name())
1368 << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << pn->name()
1370 << TextUtils::separator(i, properties.size());
1371 }
1372 text << u" "_s;
1373 }
1374 }
1375 break;
1376 }
1377 case BindableProperty:
1378 {
1379 text << "This property supports "
1380 << Atom(Atom::Link, "QProperty")
1381 << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << "QProperty"
1383 text << " bindings.";
1384 break;
1385 }
1386 case OverloadNote:
1387 {
1388 const auto *func = static_cast<const FunctionNode *>(node);
1389
1390 // Primary overloads should not display any overload note text
1391 if (func->isPrimaryOverload())
1392 return;
1393
1394 if (func->isSignal() || func->isSlot()) {
1395 QString functionType = func->isSignal() ? "signal" : "slot";
1396 const QString &configKey = func->isSignal() ? "overloadedsignalstarget" : "overloadedslotstarget";
1397 const QString &defaultTarget = func->isSignal() ? "connecting-overloaded-signals" : "connecting-overloaded-slots";
1398 const QString &linkTarget = Config::instance().get(configKey).asString(defaultTarget);
1399
1400 text << "This " << functionType << " is overloaded. ";
1401
1402 QString snippet = generateOverloadSnippet(func);
1403 if (!snippet.isEmpty()) {
1404 text << "To connect to this " << functionType << ":\n\n"
1405 << Atom(Atom::Code, snippet) << "\n";
1406 }
1407
1408 if (!linkTarget.isEmpty()) {
1409 text << "For more examples and approaches, see "
1410 << Atom(Atom::Link, linkTarget)
1412 << "connecting to overloaded " << functionType << "s"
1414 }
1415 } else {
1416 const auto &args = node->doc().overloadList();
1417 if (args.first().first.isEmpty()) {
1418 text << "This is an overloaded function.";
1419 } else {
1420 QString target = args.first().first;
1421 // If the target is not fully qualified and we have a parent class context,
1422 // attempt to qualify it to improve link resolution
1423 if (!target.contains("::")) {
1424 const auto *parent = node->parent();
1425 if (parent && (parent->isClassNode() || parent->isNamespace()))
1426 target = parent->name() + "::" + target;
1427 }
1428 text << "This function overloads " << Atom(Atom::AutoLink, target) << ".";
1429 }
1430 }
1431 break;
1432 }
1433 default:
1434 return;
1435 }
1436
1437 text << Atom::ParaRight
1438 << Atom::DivRight;
1439 generateText(text, node, marker);
1440}
1441
1442/*!
1443 Generate the documentation for \a relative. i.e. \a relative
1444 is the node that represents the entity where a qdoc comment
1445 was found, and \a text represents the qdoc comment.
1446 */
1447bool Generator::generateText(const Text &text, const Node *relative, CodeMarker *marker)
1448{
1449 bool result = false;
1450 if (text.firstAtom() != nullptr) {
1451 int numAtoms = 0;
1453 generateAtomList(text.firstAtom(), relative, marker, true, numAtoms);
1454 result = true;
1455 }
1456 return result;
1457}
1458
1459/*
1460 The node is an aggregate, typically a class node, which has
1461 a threadsafeness level. This function checks all the children
1462 of the node to see if they are exceptions to the node's
1463 threadsafeness. If there are any exceptions, the exceptions
1464 are added to the appropriate set (reentrant, threadsafe, and
1465 nonreentrant, and true is returned. If there are no exceptions,
1466 the three node lists remain empty and false is returned.
1467 */
1468bool Generator::hasExceptions(const Node *node, NodeList &reentrant, NodeList &threadsafe,
1469 NodeList &nonreentrant)
1470{
1471 bool result = false;
1473 const NodeList &children = static_cast<const Aggregate *>(node)->childNodes();
1474 for (auto child : children) {
1475 if (!child->isDeprecated()) {
1476 switch (child->threadSafeness()) {
1477 case Node::Reentrant:
1478 reentrant.append(child);
1479 if (ts == Node::ThreadSafe)
1480 result = true;
1481 break;
1482 case Node::ThreadSafe:
1483 threadsafe.append(child);
1484 if (ts == Node::Reentrant)
1485 result = true;
1486 break;
1487 case Node::NonReentrant:
1488 nonreentrant.append(child);
1489 result = true;
1490 break;
1491 default:
1492 break;
1493 }
1494 }
1495 }
1496 return result;
1497}
1498
1499/*!
1500 Returns \c true if a trademark symbol should be appended to the
1501 output as determined by \a atom. Trademarks are tracked via the
1502 use of the \\tm formatting command.
1503
1504 Returns true if:
1505
1506 \list
1507 \li \a atom is of type Atom::FormattingRight containing
1508 ATOM_FORMATTING_TRADEMARK, and
1509 \li The trademarked string is the first appearance on the
1510 current sub-page.
1511 \endlist
1512*/
1514{
1516 return false;
1517 if (atom->string() != ATOM_FORMATTING_TRADEMARK)
1518 return false;
1519
1520 if (atom->count() > 1) {
1521 if (s_trademarks.contains(atom->string(1)))
1522 return false;
1523 s_trademarks << atom->string(1);
1524 }
1525
1526 return true;
1527}
1528
1529static void startNote(Text &text)
1530{
1532 << "Note:" << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) << " ";
1533}
1534
1535/*!
1536 Generates text that explains how threadsafe and/or reentrant
1537 \a node is.
1538 */
1540{
1541 Text text, rlink, tlink;
1542 NodeList reentrant;
1543 NodeList threadsafe;
1544 NodeList nonreentrant;
1546 bool exceptions = false;
1547
1548 rlink << Atom(Atom::Link, "reentrant") << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK)
1549 << "reentrant" << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK);
1550
1551 tlink << Atom(Atom::Link, "thread-safe") << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK)
1552 << "thread-safe" << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK);
1553
1554 switch (ts) {
1556 break;
1557 case Node::NonReentrant:
1559 << "Warning:" << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) << " This "
1560 << NodeText::nodeTypeDescription(node) << " is not " << rlink << "." << Atom::ParaRight;
1561 break;
1562 case Node::Reentrant:
1563 case Node::ThreadSafe:
1564 startNote(text);
1565 if (node->isAggregate()) {
1566 exceptions = hasExceptions(node, reentrant, threadsafe, nonreentrant);
1567 text << "All functions in this " << NodeText::nodeTypeDescription(node) << " are ";
1568 if (ts == Node::ThreadSafe)
1569 text << tlink;
1570 else
1571 text << rlink;
1572
1573 if (!exceptions || (ts == Node::Reentrant && !threadsafe.isEmpty()))
1574 text << ".";
1575 else
1576 text << " with the following exceptions:";
1577 } else {
1578 text << "This " << NodeText::nodeTypeDescription(node) << " is ";
1579 if (ts == Node::ThreadSafe)
1580 text << tlink;
1581 else
1582 text << rlink;
1583 text << ".";
1584 }
1585 text << Atom::ParaRight;
1586 break;
1587 default:
1588 break;
1589 }
1590 generateText(text, node, marker);
1591
1592 if (exceptions) {
1593 text.clear();
1594 if (ts == Node::Reentrant) {
1595 if (!nonreentrant.isEmpty()) {
1596 startNote(text);
1597 text << "These functions are not " << rlink << ":" << Atom::ParaRight;
1598 signatureList(nonreentrant, node, marker);
1599 }
1600 if (!threadsafe.isEmpty()) {
1601 text.clear();
1602 startNote(text);
1603 text << "These functions are also " << tlink << ":" << Atom::ParaRight;
1604 generateText(text, node, marker);
1605 signatureList(threadsafe, node, marker);
1606 }
1607 } else { // thread-safe
1608 if (!reentrant.isEmpty()) {
1609 startNote(text);
1610 text << "These functions are only " << rlink << ":" << Atom::ParaRight;
1611 signatureList(reentrant, node, marker);
1612 }
1613 if (!nonreentrant.isEmpty()) {
1614 text.clear();
1615 startNote(text);
1616 text << "These functions are not " << rlink << ":" << Atom::ParaRight;
1617 signatureList(nonreentrant, node, marker);
1618 }
1619 }
1620 }
1621}
1622
1623/*!
1624 \internal
1625
1626 Generates text that describes the comparison category of \a node.
1627 The CodeMarker \a marker is passed along to generateText().
1628 */
1630{
1631 auto category{node->comparisonCategory()};
1632 if (category == ComparisonCategory::None)
1633 return false;
1634
1635 Text text;
1636 text << Atom::ParaLeft << "%1 is "_L1.arg(node->plainFullName())
1637 << Atom(Atom::FormattingLeft, ATOM_FORMATTING_ITALIC)
1638 << QString::fromStdString(comparisonCategoryAsString(category))
1639 << ((category == ComparisonCategory::Equality) ? "-"_L1 : "ly "_L1)
1640 << Atom(Atom::String, "comparable"_L1)
1641 << Atom(Atom::FormattingRight, ATOM_FORMATTING_ITALIC)
1642 << "."_L1 << Atom::ParaRight;
1643 generateText(text, node, marker);
1644 return true;
1645}
1646
1647/*!
1648 Generates a table of comparison categories for \a node, combining both
1649 self-comparison (from \\compares) and comparisons with other types
1650 (from \\compareswith).
1651
1652 If the node has a comparison category set via \\compares, it appears
1653 as the first row in the table. Subsequent rows come from \\compareswith
1654 entries.
1655
1656 The Description column is only included if at least one \\compareswith
1657 entry has descriptive content.
1658
1659 Returns \c true if text was generated, \c false otherwise.
1660 */
1662{
1663 Q_ASSERT(node);
1664
1665 const auto selfCategory = node->comparisonCategory();
1666 const auto *map = node->doc().comparesWithMap();
1667
1668 const bool hasSelfComparison = (selfCategory != ComparisonCategory::None);
1669 const bool hasComparesWithEntries = (map && !map->isEmpty());
1670
1671 if (!hasSelfComparison && !hasComparesWithEntries)
1672 return false;
1673
1674 bool hasDescriptions = false;
1675 if (hasComparesWithEntries) {
1676 for (const auto &description : *map) {
1677 if (description.firstAtom()->next() != description.lastAtom()) {
1678 hasDescriptions = true;
1679 break;
1680 }
1681 }
1682 }
1683
1684 Text text;
1685
1686 text << Atom::ParaLeft
1687 << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD)
1688 << "%1 Comparisons"_L1.arg(node->plainFullName())
1689 << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD)
1690 << Atom::ParaRight;
1691
1692 text << Atom(Atom::TableLeft, "generic"_L1);
1693
1694 text << Atom::TableHeaderLeft
1695 << Atom::TableItemLeft << "Category"_L1 << Atom::TableItemRight
1696 << Atom::TableItemLeft << "Comparable Types"_L1 << Atom::TableItemRight;
1697 if (hasDescriptions)
1698 text << Atom::TableItemLeft << "Description"_L1 << Atom::TableItemRight;
1699 text << Atom::TableHeaderRight;
1700
1701 // First row: self-comparison from \compares
1702 if (hasSelfComparison) {
1703 const QString &category = QString::fromStdString(comparisonCategoryAsString(selfCategory));
1704
1705 text << Atom::TableRowLeft;
1706 text << Atom::TableItemLeft << category << Atom::TableItemRight;
1707 text << Atom::TableItemLeft
1708 << Atom(Atom::String, node->plainFullName()) << Atom::TableItemRight;
1709 if (hasDescriptions)
1711 text << Atom::TableRowRight;
1712 }
1713
1714 // Subsequent rows: \compareswith entries
1715 if (hasComparesWithEntries) {
1716 for (auto [key, description] : map->asKeyValueRange()) {
1717 const QString &category = QString::fromStdString(comparisonCategoryAsString(key));
1718
1719 text << Atom::TableRowLeft;
1720
1721 text << Atom::TableItemLeft << category << Atom::TableItemRight;
1722
1723 text << Atom::TableItemLeft;
1724 const QStringList types{description.firstAtom()->string().split(';'_L1)};
1725 for (const auto &name : types)
1726 text << Atom(Atom::AutoLink, name)
1727 << TextUtils::separator(types.indexOf(name), types.size());
1728 text << Atom::TableItemRight;
1729
1730 if (hasDescriptions) {
1731 text << Atom::TableItemLeft;
1732 if (description.firstAtom()->next() != description.lastAtom())
1733 text << Text::subText(description.firstAtom()->next(), description.lastAtom());
1734 text << Atom::TableItemRight;
1735 }
1736
1737 text << Atom::TableRowRight;
1738 }
1739 }
1740
1741 text << Atom::TableRight;
1742
1743 generateText(text, node, nullptr);
1744 return !text.isEmpty();
1745}
1746
1747/*!
1748 Traverses the database recursively to generate all the documentation.
1749 */
1751{
1752 s_currentGenerator = this;
1754}
1755
1756Generator *Generator::generatorForFormat(const QString &format)
1757{
1758 // First, check the OutputProducerRegistry for producers.
1759 // This supports both Generator-based producers (which register themselves)
1760 // and future non-Generator OutputProducer implementations.
1761 if (auto *producer = OutputProducerRegistry::instance().producerForFormat(format)) {
1762 // TODO: All registered producers are Generators, but this will
1763 // change as we migrate to OutputProducer-based implementations.
1764 if (auto *gen = dynamic_cast<Generator *>(producer))
1765 return gen;
1766 }
1767
1768 // Fallback: Check the legacy s_generators list for unregistered generators.
1769 // This should not normally be reached, but provides backward compatibility.
1770 for (const auto &generator : std::as_const(s_generators)) {
1771 if (generator->format() == format)
1772 return generator;
1773 }
1774 return nullptr;
1775}
1776
1777QString Generator::indent(int level, const QString &markedCode)
1778{
1779 if (level == 0)
1780 return markedCode;
1781
1782 QString t;
1783 int column = 0;
1784
1785 int i = 0;
1786 while (i < markedCode.size()) {
1787 if (markedCode.at(i) == QLatin1Char('\n')) {
1788 column = 0;
1789 } else {
1790 if (column == 0) {
1791 for (int j = 0; j < level; j++)
1792 t += QLatin1Char(' ');
1793 }
1794 column++;
1795 }
1796 t += markedCode.at(i++);
1797 }
1798 return t;
1799}
1800
1802{
1803 Config &config = Config::instance();
1804 s_outputFormats = config.getOutputFormats();
1806
1807 for (auto &g : s_generators) {
1808 if (s_outputFormats.contains(g->format())) {
1809 s_currentGenerator = g;
1810 OutputProducerRegistry::instance().registerProducer(g);
1811 g->initializeGenerator();
1812 }
1813 }
1814
1815 const auto &configFormatting = config.subVars(CONFIG_FORMATTING);
1816 for (const auto &n : configFormatting) {
1817 QString formattingDotName = CONFIG_FORMATTING + Config::dot + n;
1818 const auto &formattingDotNames = config.subVars(formattingDotName);
1819 for (const auto &f : formattingDotNames) {
1820 const auto &configVar = config.get(formattingDotName + Config::dot + f);
1821 QString def{configVar.asString()};
1822 if (!def.isEmpty()) {
1823 int numParams = Config::numParams(def);
1824 int numOccs = def.count("\1");
1825 if (numParams != 1) {
1826 configVar.location().warning(QStringLiteral("Formatting '%1' must "
1827 "have exactly one "
1828 "parameter (found %2)")
1829 .arg(n, numParams));
1830 } else if (numOccs > 1) {
1831 configVar.location().fatal(QStringLiteral("Formatting '%1' must "
1832 "contain exactly one "
1833 "occurrence of '\\1' "
1834 "(found %2)")
1835 .arg(n, numOccs));
1836 } else {
1837 int paramPos = def.indexOf("\1");
1838 s_fmtLeftMaps[f].insert(n, def.left(paramPos));
1839 s_fmtRightMaps[f].insert(n, def.mid(paramPos + 1));
1840 }
1841 }
1842 }
1843 }
1844
1845 s_project = config.get(CONFIG_PROJECT).asString();
1846 s_outDir = config.getOutputDir();
1847 s_outSubdir = s_outDir.mid(s_outDir.lastIndexOf('/') + 1);
1848
1849 s_outputPrefixes.clear();
1850 QStringList items{config.get(CONFIG_OUTPUTPREFIXES).asStringList()};
1851 if (!items.isEmpty()) {
1852 for (const auto &prefix : items)
1853 s_outputPrefixes[prefix] =
1854 config.get(CONFIG_OUTPUTPREFIXES + Config::dot + prefix).asString();
1855 }
1856 if (!items.contains(u"QML"_s))
1857 s_outputPrefixes[u"QML"_s] = u"qml-"_s;
1858
1859 s_outputSuffixes.clear();
1860 for (const auto &suffix : config.get(CONFIG_OUTPUTSUFFIXES).asStringList())
1861 s_outputSuffixes[suffix] = config.get(CONFIG_OUTPUTSUFFIXES
1862 + Config::dot + suffix).asString();
1863
1864 s_noLinkErrors = config.get(CONFIG_NOLINKERRORS).asBool();
1865 s_autolinkErrors = config.get(CONFIG_AUTOLINKERRORS).asBool();
1866}
1867
1868/*!
1869 Creates template-specific subdirs (e.g. /styles and /scripts for HTML)
1870 and copies the files to them.
1871 */
1872void Generator::copyTemplateFiles(const QString &configVar, const QString &subDir)
1873{
1874 // TODO: [resolving-files-unlinked-to-doc]
1875 // This is another case of resolving files, albeit it doesn't use Doc::resolveFile.
1876 // While it may be left out of a first iteration of the file
1877 // resolution logic, it should later be integrated into it.
1878 // This should come naturally when the output directory logic is
1879 // extracted and copying a file should require a validated
1880 // intermediate format.
1881 // Do note that what is done here is a bit different from the
1882 // resolve file routine that is done for other user-given paths.
1883 // Thas is, the paths will always be absolute and not relative as
1884 // they are resolved from the configuration.
1885 // Ideally, this could be solved in the configuration already,
1886 // together with the other configuration resolution processes that
1887 // do not abide by the same constraints that, for example, snippet
1888 // resolution uses.
1889 Config &config = Config::instance();
1890 QStringList files = config.getCanonicalPathList(configVar, Config::Validate);
1891 const auto &loc = config.get(configVar).location();
1892 if (!files.isEmpty()) {
1893 // TODO: [uncentralized-output-directory-structure]
1894 // OutputDirectory provides the centralized system for managing output
1895 // directory structure in Generator base class methods. However, the
1896 // format-specific generators (HtmlGenerator, DocBookGenerator,
1897 // WebXMLGenerator) still manually construct image paths using string
1898 // concatenation and direct Config::copyFile() calls. These should be
1899 // refactored to use OutputDirectory for consistency and security.
1900
1901 const OutputDirectory outDir =
1902 OutputDirectory::ensure(s_outDir, loc);
1903
1904 const OutputDirectory templateDir =
1905 outDir.ensureSubdir(subDir, loc);
1906
1907 for (const auto &file : files) {
1908 if (!file.isEmpty()) {
1909 const QFileInfo fi(file);
1910 Config::copyFile(loc, fi.absoluteFilePath(), fi.fileName(), templateDir.path());
1911 }
1912 }
1913 }
1914}
1915
1916/*!
1917 Reads format-specific variables from config, sets output
1918 (sub)directories, creates them on the filesystem and copies the
1919 template-specific files.
1920 */
1922{
1923 Config &config = Config::instance();
1924 s_outFileNames.clear();
1925 s_generatedPages.clear();
1926 s_exampleImageFileNames.clear();
1927 s_useOutputSubdirs = true;
1928 if (config.get(format() + Config::dot + "nosubdirs").asBool())
1930
1931 if (s_outputFormats.isEmpty())
1932 return;
1934 return;
1935
1936 s_outDir = config.getOutputDir(format());
1937 if (s_outDir.isEmpty()) {
1938 Location().fatal(QStringLiteral("No output directory specified in "
1939 "configuration file or on the command line"));
1940 } else {
1941 s_outSubdir = s_outDir.mid(s_outDir.lastIndexOf('/') + 1);
1942 }
1943
1944 // Ensure output directory exists before proceeding
1945 const OutputDirectory outputDir =
1946 OutputDirectory::ensure(s_outDir, Location());
1947
1948 // Check if the directory is empty when required
1950 if (!outputDir.toQDir().isEmpty())
1951 Location().error("Output directory '%1' exists but is not empty"_L1.arg(s_outDir));
1952 }
1953
1954 // Output directory exists, which is enough for prepare phase.
1955 if (config.preparing())
1956 return;
1957
1958 auto imagesDir = config.get(CONFIG_IMAGESOUTPUTDIR).asString(u"images"_s);
1959 // Ensure images subdirectory exists
1960 [[maybe_unused]] const OutputDirectory imagesOutputDir =
1961 outputDir.ensureSubdir(imagesDir, Location());
1962 s_imagesOutDir = std::move(imagesDir);
1963
1964 copyTemplateFiles(format() + Config::dot + CONFIG_STYLESHEETS, "style");
1965 copyTemplateFiles(format() + Config::dot + CONFIG_SCRIPTS, "scripts");
1966 copyTemplateFiles(format() + Config::dot + CONFIG_EXTRAIMAGES, "images");
1967
1968 // Use a format-specific .quotinginformation if defined, otherwise a global value
1969 if (config.subVars(format()).contains(CONFIG_QUOTINGINFORMATION))
1970 m_quoting = config.get(format() + Config::dot + CONFIG_QUOTINGINFORMATION).asBool();
1971 else
1973}
1974
1975/*!
1976 No-op base implementation. Subclasses may override to perform
1977 generator-specific initialization.
1978 */
1980{
1981 // Default implementation does nothing
1982}
1983
1984bool Generator::matchAhead(const Atom *atom, Atom::AtomType expectedAtomType)
1985{
1986 return atom->next() && atom->next()->type() == expectedAtomType;
1987}
1988
1989/*!
1990 Used for writing to the current output stream. Returns a
1991 reference to the current output stream, which is then used
1992 with the \c {<<} operator for writing.
1993 */
1994QTextStream &Generator::out()
1995{
1996 return *outStreamStack.top();
1997}
1998
2000{
2001 return QFileInfo(static_cast<QFile *>(out().device())->fileName()).fileName();
2002}
2003
2004QString Generator::outputPrefix(const Node *node)
2005{
2006 // Omit prefix for module pages
2007 if (node->isPageNode() && !node->isCollectionNode()) {
2008 switch (node->genus()) {
2009 case Genus::QML:
2010 return s_outputPrefixes[u"QML"_s];
2011 case Genus::CPP:
2012 return s_outputPrefixes[u"CPP"_s];
2013 default:
2014 break;
2015 }
2016 }
2017 return QString();
2018}
2019
2020QString Generator::outputSuffix(const Node *node)
2021{
2022 if (node->isPageNode()) {
2023 switch (node->genus()) {
2024 case Genus::QML:
2025 return s_outputSuffixes[u"QML"_s];
2026 case Genus::CPP:
2027 return s_outputSuffixes[u"CPP"_s];
2028 default:
2029 break;
2030 }
2031 }
2032
2033 return QString();
2034}
2035
2036bool Generator::parseArg(const QString &src, const QString &tag, int *pos, int n,
2037 QStringView *contents, QStringView *par1)
2038{
2039#define SKIP_CHAR(c)
2040 if (i >= n || src[i] != c)
2041 return false;
2042 ++i;
2043
2044#define SKIP_SPACE
2045 while (i < n && src[i] == ' ')
2046 ++i;
2047
2048 qsizetype i = *pos;
2049 qsizetype j {};
2050
2051 // assume "<@" has been parsed outside
2052 // SKIP_CHAR('<');
2053 // SKIP_CHAR('@');
2054
2055 if (tag != QStringView(src).mid(i, tag.size())) {
2056 return false;
2057 }
2058
2059 // skip tag
2060 i += tag.size();
2061
2062 // parse stuff like: linkTag("(<@link node=\"([^\"]+)\">).*(</@link>)");
2063 if (par1) {
2064 SKIP_SPACE;
2065 // read parameter name
2066 j = i;
2067 while (i < n && src[i].isLetter())
2068 ++i;
2069 if (src[i] == '=') {
2070 SKIP_CHAR('=');
2071 SKIP_CHAR('"');
2072 // skip parameter name
2073 j = i;
2074 while (i < n && src[i] != '"')
2075 ++i;
2076 *par1 = QStringView(src).mid(j, i - j);
2077 SKIP_CHAR('"');
2078 SKIP_SPACE;
2079 }
2080 }
2081 SKIP_SPACE;
2082 SKIP_CHAR('>');
2083
2084 // find contents up to closing "</@tag>
2085 j = i;
2086 for (; true; ++i) {
2087 if (i + 4 + tag.size() > n)
2088 return false;
2089 if (src[i] != '<')
2090 continue;
2091 if (src[i + 1] != '/')
2092 continue;
2093 if (src[i + 2] != '@')
2094 continue;
2095 if (tag != QStringView(src).mid(i + 3, tag.size()))
2096 continue;
2097 if (src[i + 3 + tag.size()] != '>')
2098 continue;
2099 break;
2100 }
2101
2102 *contents = QStringView(src).mid(j, i - j);
2103
2104 i += tag.size() + 4;
2105
2106 *pos = i;
2107 return true;
2108#undef SKIP_CHAR
2109#undef SKIP_SPACE
2110}
2111
2112QString Generator::plainCode(const QString &markedCode)
2113{
2114 QString t = markedCode;
2115 t.replace(tag, QString());
2116 t.replace(quot, QLatin1String("\""));
2117 t.replace(gt, QLatin1String(">"));
2118 t.replace(lt, QLatin1String("<"));
2119 t.replace(amp, QLatin1String("&"));
2120 return t;
2121}
2122
2123int Generator::skipAtoms(const Atom *atom, Atom::AtomType type) const
2124{
2125 int skipAhead = 0;
2126 atom = atom->next();
2127 while (atom && atom->type() != type) {
2128 skipAhead++;
2129 atom = atom->next();
2130 }
2131 return skipAhead;
2132}
2133
2134/*!
2135 Resets the variables used during text output.
2136 */
2138{
2139 m_inLink = false;
2140 m_inContents = false;
2141 m_inSectionHeading = false;
2142 m_inTableHeader = false;
2143 m_numTableRows = 0;
2145 m_link.clear();
2146 m_sectionNumber.clear();
2147}
2148
2149void Generator::supplementAlsoList(const Node *node, QList<Text> &alsoList)
2150{
2151 if (node->isFunction() && !node->isMacro()) {
2152 const auto fn = static_cast<const FunctionNode *>(node);
2153 if (fn->overloadNumber() == 0) {
2154 QString alternateName;
2155 const FunctionNode *alternateFunc = nullptr;
2156
2157 if (fn->name().startsWith("set") && fn->name().size() >= 4) {
2158 alternateName = fn->name()[3].toLower();
2159 alternateName += fn->name().mid(4);
2160 alternateFunc = fn->parent()->findFunctionChild(alternateName, QString());
2161
2162 if (!alternateFunc) {
2163 alternateName = "is" + fn->name().mid(3);
2164 alternateFunc = fn->parent()->findFunctionChild(alternateName, QString());
2165 if (!alternateFunc) {
2166 alternateName = "has" + fn->name().mid(3);
2167 alternateFunc = fn->parent()->findFunctionChild(alternateName, QString());
2168 }
2169 }
2170 } else if (!fn->name().isEmpty()) {
2171 alternateName = "set";
2172 alternateName += fn->name()[0].toUpper();
2173 alternateName += fn->name().mid(1);
2174 alternateFunc = fn->parent()->findFunctionChild(alternateName, QString());
2175 }
2176
2177 if (alternateFunc && alternateFunc->access() != Access::Private) {
2178 int i;
2179 for (i = 0; i < alsoList.size(); ++i) {
2180 if (alsoList.at(i).toString().contains(alternateName))
2181 break;
2182 }
2183
2184 if (i == alsoList.size()) {
2185 if (alternateFunc->isDeprecated() && !fn->isDeprecated())
2186 return;
2187 alternateName += "()";
2188
2189 Text also;
2190 also << Atom(Atom::Link, alternateName)
2191 << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) << alternateName
2193 alsoList.prepend(also);
2194 }
2195 }
2196 }
2197 }
2198}
2199
2201{
2202 const NativeEnum *nativeEnum{nullptr};
2203 if (auto *ne_if = dynamic_cast<const NativeEnumInterface *>(node))
2204 nativeEnum = ne_if->nativeEnum();
2205 else
2206 return;
2207
2208 if (!nativeEnum->enumNode())
2209 return;
2210
2211 // Retrieve atoms from C++ enum \value list
2212 const auto body{nativeEnum->enumNode()->doc().body()};
2213 const auto *start{body.firstAtom()};
2214 Text text;
2215
2216 while ((start = start->find(Atom::ListLeft, ATOM_LIST_VALUE))) {
2217 const auto end = start->find(Atom::ListRight, ATOM_LIST_VALUE);
2218 // Skip subsequent ListLeft atoms, collating multiple lists into one
2219 text << body.subText(text.isEmpty() ? start : start->next(), end);
2220 start = end;
2221 }
2222 if (text.isEmpty())
2223 return;
2224
2225 text << Atom(Atom::ListRight, ATOM_LIST_VALUE);
2226 if (marker)
2227 generateText(text, node, marker);
2228 else
2229 generateText(text, node);
2230}
2231
2233{
2234 for (const auto &generator : std::as_const(s_generators)) {
2235 if (s_outputFormats.contains(generator->format())) {
2236 OutputProducerRegistry::instance().unregisterProducer(generator);
2237 generator->terminateGenerator();
2238 }
2239 }
2240
2241 // REMARK: Generators currently, due to recent changes and the
2242 // transitive nature of the current codebase, receive some of
2243 // their dependencies in the constructor and some of them in their
2244 // initialize-terminate lifetime.
2245 // This means that generators need to be constructed and
2246 // destructed between usages such that if multiple usages are
2247 // required, the generators present in the list will have been
2248 // destroyed by then such that accessing them would be an error.
2249 // The current codebase calls initialize and the correspective
2250 // terminate with the same scope as the lifetime of the
2251 // generators.
2252 // Then, clearing the list ensures that, if another generator
2253 // execution is needed, the stale generators will not be removed
2254 // as to be replaced by newly constructed ones.
2255 // Do note that it is not clear that this will happen for any call
2256 // in Qt's documentation and this should work only because of the
2257 // form of the current codebase and the scoping of the
2258 // initialize-terminate calls. As such, this should be considered
2259 // a patchwork that may or may not be doing anything and that may
2260 // break due to changes in other parts of the codebase.
2261 //
2262 // This is still to be considered temporary as the whole
2263 // initialize-terminate idiom must be removed from the codebase.
2264 s_generators.clear();
2265
2266 s_fmtLeftMaps.clear();
2267 s_fmtRightMaps.clear();
2268 s_outDir.clear();
2269 s_imagesOutDir.clear();
2270}
2271
2273
2274/*!
2275 Trims trailing whitespace off the \a string and returns
2276 the trimmed string.
2277 */
2278QString Generator::trimmedTrailing(const QString &string, const QString &prefix,
2279 const QString &suffix)
2280{
2281 QString trimmed = string;
2282 while (trimmed.size() > 0 && trimmed[trimmed.size() - 1].isSpace())
2283 trimmed.truncate(trimmed.size() - 1);
2284
2285 trimmed.append(suffix);
2286 trimmed.prepend(prefix);
2287 return trimmed;
2288}
2289
2290void Generator::unknownAtom(const Atom *atom)
2291{
2292 Location::internalError(QStringLiteral("unknown atom type '%1' in %2 generator")
2293 .arg(atom->typeString(), format()));
2294}
2295
2296/*!
2297 * Generate the CMake requisite for the node \a cn, i.e. the the find_package and target_link_libraries
2298 * calls to use it.
2299 *
2300 * If only cmakepackage is set it will look like
2301 *
2302 * \badcode
2303 * find_package(Foo REQUIRED)
2304 * target_link_libraries(mytarget PRIVATE Foo:Foo)
2305 * \endcode
2306 *
2307 * If no cmakepackage is set Qt6 is assumed.
2308 *
2309 * If cmakecomponent is set it will look like
2310 *
2311 * \badcode
2312 * find_package(Qt6 REQUIRED COMPONENTS Bar)
2313 * target_link_libraries(mytarget PRIVATE Qt6::Bar)
2314 * \endcode
2315 *
2316 * If cmaketargetitem is set the item in target_link_libraries will be set accordingly
2317 *
2318 * \badcode
2319 * find_package(Qt6 REQUIRED COMPONENTS Bar)
2320 * target_link_libraries(mytarget PRIVATE My::Target)
2321 * \endcode
2322 *
2323 * Returns a pair consisting of the find package line and link libraries line.
2324 *
2325 * If no sensible requisite can be created (i.e. both cmakecomponent and cmakepackage are unset)
2326 * \c std::nullopt is returned.
2327 */
2328std::optional<std::pair<QString, QString>> Generator::cmakeRequisite(const CollectionNode *cn)
2329{
2330 if (!cn || (cn->cmakeComponent().isEmpty() && cn->cmakePackage().isEmpty())) {
2331 return {};
2332 }
2333
2334 const QString package =
2335 cn->cmakePackage().isEmpty() ? "Qt" + QString::number(QT_VERSION_MAJOR) : cn->cmakePackage();
2336
2337 QString findPackageText;
2338 if (cn->cmakeComponent().isEmpty()) {
2339 findPackageText = "find_package(" + package + " REQUIRED)";
2340 } else {
2341 findPackageText = "find_package(" + package + " REQUIRED COMPONENTS " + cn->cmakeComponent() + ")";
2342 }
2343
2344 QString targetText;
2345 if (cn->cmakeTargetItem().isEmpty()) {
2346 if (cn->cmakeComponent().isEmpty()) {
2347 targetText = package + "::" + package;
2348 } else {
2349 targetText = package + "::" + cn->cmakeComponent();
2350 }
2351 } else {
2352 targetText = cn->cmakeTargetItem();
2353 }
2354
2355 const QString targetLinkLibrariesText = "target_link_libraries(mytarget PRIVATE " + targetText + ")";
2356 const QStringList cmakeInfo { findPackageText, targetLinkLibrariesText };
2357
2358 return std::make_pair(findPackageText, targetLinkLibrariesText);
2359}
2360
2361/*!
2362 \brief Adds a formatted link to the specified \a text stream.
2363
2364 This function creates a sequence of Atom objects that together form a link
2365 and appends them to the \a text. The \a nodeRef parameter specifies the
2366 target of the link (typically obtained via stringForNode()), and \a linkText
2367 specifies the visible text for the link.
2368
2369 \sa Atom, stringForNode()
2370*/
2371void Generator::addNodeLink(Text &text, const QString &nodeRef, const QString &linkText) {
2372 text << Atom(Atom::LinkNode, nodeRef)
2374 << Atom(Atom::String, linkText)
2376}
2377
2378/*!
2379 \overload
2380
2381 This convenience overload automatically obtains the node reference string
2382 using stringForNode(). If \a linkText is empty, the node's name is used as
2383 the link text; otherwise, the specified \a linkText is used.
2384
2385 \sa stringForNode()
2386*/
2387void Generator::addNodeLink(Text &text, const INode *node, const QString &linkText) {
2388 addNodeLink(
2389 text,
2390 Utilities::stringForNode(node),
2391 linkText.isEmpty() ? node->name() : linkText
2392 );
2393}
2394
2395/*!
2396 Generates a contextual code snippet for connecting to an overloaded signal or
2397 slot. Returns an empty string if the function is not a signal or slot.
2398
2399 For signals, the snippet shows the signal in the second argument position of
2400 connect(). For slots, the snippet shows the slot in the fourth argument
2401 position (receiver side).
2402*/
2404{
2405 if (!func || (!func->isSignal() && !func->isSlot()))
2406 return QString();
2407
2408 QString className = func->parent()->name();
2409 QString functionName = func->name();
2410 QString typeList = func->parameters().generateTypeList();
2411 QString typeAndNameList = func->parameters().generateTypeAndNameList();
2412 QString nameList = func->parameters().generateNameList();
2413 QString objectName = generateObjectName(className);
2414
2415 QString snippet;
2416
2417 if (func->isSignal()) {
2418 snippet = QString(
2419 "// Connect using qOverload:\n"
2420 "connect(%1, qOverload<%2>(&%3::%4),\n"
2421 " receiver, &ReceiverClass::slot);\n\n"
2422 "// Or using a lambda:\n"
2423 "connect(%1, qOverload<%2>(&%3::%4),\n"
2424 " this, [](%5) { /* handle %4 */ });")
2425 .arg(objectName, typeList, className, functionName, typeAndNameList);
2426 } else {
2427 snippet = QString(
2428 "// Connect using qOverload:\n"
2429 "connect(sender, &SenderClass::signal,\n"
2430 " %1, qOverload<%2>(&%3::%4));\n\n"
2431 "// Or using a lambda as wrapper:\n"
2432 "connect(sender, &SenderClass::signal,\n"
2433 " %1, [receiver = %1](%5) { receiver->%4(%6); });")
2434 .arg(objectName, typeList, className, functionName, typeAndNameList, nameList);
2435 }
2436
2437 return snippet;
2438}
2439
2440/*!
2441 Generates an appropriate object name for code snippets based on the class name.
2442 Converts class names like "QComboBox" to "comboBox".
2443*/
2444QString Generator::generateObjectName(const QString &className)
2445{
2446 QString name = className;
2447
2448 if (name.startsWith('Q') && name.length() > 1)
2449 name.remove(0, 1);
2450
2451 if (!name.isEmpty())
2452 name[0] = name[0].toLower();
2453
2454 return name;
2455}
2456
2457QT_END_NAMESPACE
#define ATOM_FORMATTING_TELETYPE
Definition atom.h:206
#define ATOM_FORMATTING_BOLD
Definition atom.h:197
#define ATOM_FORMATTING_TRADEMARK
Definition atom.h:207
#define ATOM_LIST_VALUE
Definition atom.h:213
#define ATOM_FORMATTING_ITALIC
Definition atom.h:199
#define ATOM_FORMATTING_LINK
Definition atom.h:200
#define ATOM_FORMATTING_PARAMETER
Definition atom.h:202
The Atom class is the fundamental unit for representing documents internally.
Definition atom.h:19
AtomType type() const
Return the type of this atom.
Definition atom.h:146
AtomType
\value AnnotatedList \value AutoLink \value BaseName \value BriefLeft \value BriefRight \value C \val...
Definition atom.h:21
@ TableRight
Definition atom.h:99
@ DivRight
Definition atom.h:44
@ TableHeaderRight
Definition atom.h:101
@ FormatElse
Definition atom.h:49
@ TableRowRight
Definition atom.h:103
@ TableRowLeft
Definition atom.h:102
@ TableItemRight
Definition atom.h:105
@ Code
Definition atom.h:31
@ String
Definition atom.h:97
@ ListLeft
Definition atom.h:67
@ ExampleFileLink
Definition atom.h:45
@ ListRight
Definition atom.h:73
@ ParaRight
Definition atom.h:80
@ FormattingLeft
Definition atom.h:52
@ FormattingRight
Definition atom.h:53
@ Link
Definition atom.h:65
@ FormatEndif
Definition atom.h:50
@ ExampleImageLink
Definition atom.h:46
@ AutoLink
Definition atom.h:23
@ LinkNode
Definition atom.h:66
@ TableItemLeft
Definition atom.h:104
@ ParaLeft
Definition atom.h:79
@ FormatIf
Definition atom.h:51
const Atom * next() const
Return the next atom in the atom list.
Definition atom.h:143
The ClassNode represents a C++ class.
Definition classnode.h:23
A class for holding the members of a collection of doc pages.
const Location & location() const
Definition config.h:55
bool asBool() const
Returns this config variable as a boolean.
Definition config.cpp:317
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition config.h:95
@ Validate
Definition config.h:114
bool preparing() const
Definition config.h:201
bool generating() const
Definition config.h:202
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 deprecationText() const
Definition doc.cpp:131
QStringMultiMap * metaTagMap() const
Definition doc.cpp:347
Encapsulate the logic that QDoc uses to find files whose path is provided by the user and that are re...
This node is used to represent any kind of function being documented.
bool isPrivateSignal() const
QString kindString() const
Returns a string representing the kind of function this Function node represents, which depends on th...
const Parameters & parameters() const
bool isMAssign() const
bool isVirtual() const
bool isCAssign() const
const QString & overridesThis() const
bool isInvokable() const
bool isDeprecated() const override
\reimp
bool hasOverloads() const
Returns true if this function has overloads.
bool returnsBool() const
bool isMarkedReimp() const override
Returns true if the FunctionNode is marked as a reimplemented function.
bool isDtor() const
bool isSignal() const
bool isQmlSignal() const
bool isOverload() const
bool isIgnored() const
In some cases, it is ok for a public function to be not documented.
bool isCCtor() const
bool isMCtor() const
bool isCtor() const
bool hasAssociatedProperties() const
bool isSlot() const
bool m_quoting
Definition generator.h:234
void appendSignature(Text &text, const Node *node)
Append the signature for the function named in node to text, so that is a link to the documentation f...
virtual void generateCollectionNode(CollectionNode *, CodeMarker *)
Definition generator.h:111
virtual void generateProxyPage(Aggregate *, CodeMarker *)
Definition generator.h:108
virtual void generateCppReferencePage(Aggregate *, CodeMarker *)
Definition generator.h:107
bool generateComparisonCategory(const Node *node, CodeMarker *marker=nullptr)
QMap< QString, QString > & formattingRightMap()
FileResolver & file_resolver
Definition generator.h:226
virtual bool generateText(const Text &text, const Node *relative)
Definition generator.h:115
virtual void initializeFormat()
Reads format-specific variables from config, sets output (sub)directories, creates them on the filesy...
virtual void generateDocumentation(Node *node)
Recursive writing of HTML files from the root node.
static void initialize()
const Atom * generateAtomList(const Atom *atom, const Node *relative, CodeMarker *marker, bool generate, int &numGeneratedAtoms)
void generateStatus(const Node *node, CodeMarker *marker)
virtual void generateAlsoList(const Node *node, CodeMarker *marker)
Generates text for a "see also" list for the given node and marker if a list has been defined.
void appendFullName(Text &text, const Node *apparentNode, const Node *relative, const Node *actualNode=nullptr)
virtual void generateFileList(const ExampleNode *en, CodeMarker *marker, bool images)
This function is called when the documentation for an example is being formatted.
void generateThreadSafeness(const Node *node, CodeMarker *marker)
Generates text that explains how threadsafe and/or reentrant node is.
static void terminate()
Generator(FileResolver &file_resolver)
Constructs the generator base class.
QString fullDocumentLocation(const Node *node) const
Returns the full document location of node: its page file name and, for a member, the anchor fragment...
QDocDatabase * m_qdb
Definition generator.h:228
bool m_inContents
Definition generator.h:230
static bool useOutputSubdirs()
Definition generator.h:91
void generateNoexceptNote(const Node *node, CodeMarker *marker)
void unknownAtom(const Atom *atom)
QString generateObjectName(const QString &className)
Generates an appropriate object name for code snippets based on the class name.
virtual bool generateText(const Text &text, const Node *relative, CodeMarker *marker)
Generate the documentation for relative.
int appendSortedQmlNames(Text &text, const Node *base, const QStringList &knownTypes, const QList< Node * > &subs)
void generateLinkToExample(const ExampleNode *en, CodeMarker *marker, const QString &exampleUrl)
Generates an external link to the project folder for example node.
virtual void terminateGenerator()
QString generateOverloadSnippet(const FunctionNode *func)
Generates a contextual code snippet for connecting to an overloaded signal or slot.
static bool matchAhead(const Atom *atom, Atom::AtomType expectedAtomType)
bool m_inLink
Definition generator.h:229
void addImageToCopy(const ExampleNode *en, const ResolvedFile &resolved_file)
virtual void generateDocs()
Traverses the database recursively to generate all the documentation.
bool m_inTableHeader
Definition generator.h:232
static bool appendTrademark(const Atom *atom)
Returns true if a trademark symbol should be appended to the output as determined by atom.
bool m_inSectionHeading
Definition generator.h:231
void generateEnumValuesForQmlReference(const Node *node, CodeMarker *marker)
virtual int skipAtoms(const Atom *atom, Atom::AtomType type) const
int m_numTableRows
Definition generator.h:235
bool m_threeColumnEnumValueTable
Definition generator.h:233
QString linkForExampleFile(const QString &path, const QString &fileExt=QString()) const
Constructs an href link from an example file name, which is a path to the example file.
virtual void generateQmlTypePage(QmlTypeNode *, CodeMarker *)
Definition generator.h:109
void signatureList(const QList< Node * > &nodes, const Node *relative, CodeMarker *marker)
Generate a bullet list of function signatures.
void appendFullName(Text &text, const Node *apparentNode, const QString &fullName, const Node *actualNode)
QTextStream & out()
static bool s_redirectDocumentationToDevNull
Definition generator.h:225
virtual void generateBody(const Node *node, CodeMarker *marker)
Generate the body of the documentation from the qdoc comment found with the entity represented by the...
QFile * openSubPageFile(const PageNode *node, const QString &fileName)
Creates the file named fileName in the output directory and returns a QFile pointing to this file.
void beginSubPage(const PageNode *node, const QString &fileName)
Creates the file named fileName in the output directory.
QString outFileName()
virtual void generatePageNode(PageNode *, CodeMarker *)
Definition generator.h:110
virtual ~Generator()
Destroys the generator after removing it from the list of output generators.
void generateSince(const Node *node, CodeMarker *marker)
QMap< QString, QString > & formattingLeftMap()
int appendSortedNames(Text &text, const ClassNode *classe, const QList< RelatedClass > &classes)
void endSubPage()
Flush the text stream associated with the subpage, and then pop it off the text stream stack and dele...
virtual void generateAddendum(const Node *node, Addendum type, CodeMarker *marker)
Definition generator.h:144
QString indent(int level, const QString &markedCode)
QString fileName(const Node *node, const QString &extension=QString()) const
If the node has a URL, return the URL as the file name.
virtual void generateAddendum(const Node *node, Addendum type, CodeMarker *marker, AdmonitionPrefix prefix)
static void resetUseOutputSubdirs()
Definition generator.h:90
@ AssociatedProperties
Definition generator.h:47
@ PrivateSignal
Definition generator.h:45
@ QmlSignalHandler
Definition generator.h:46
@ BindableProperty
Definition generator.h:48
@ OverloadNote
Definition generator.h:49
bool generateComparisonTable(const Node *node)
Generates a table of comparison categories for node, combining both self-comparison (from \compares) ...
bool parseArg(const QString &src, const QString &tag, int *pos, int n, QStringView *contents, QStringView *par1=nullptr)
virtual void generateGenericCollectionPage(CollectionNode *, CodeMarker *)
Definition generator.h:112
virtual QString fileBase(const Node *node) const
virtual void initializeGenerator()
No-op base implementation.
void initializeTextOutput()
Resets the variables used during text output.
void generateRequiredLinks(const Node *node, CodeMarker *marker)
Generates either a link to the project folder for example node, or a list of links files/images if 'u...
Definition inode.h:20
static bool isIncluded(const InclusionPolicy &policy, const NodeContext &context)
static bool requiresDocumentation(const InclusionPolicy &policy, const NodeContext &context)
\variable PublicationLocation::path
static QString resolveDocumentLocation(const Node *node, const FileBase &fileBase, const QString &fileExtension)
Resolves the full document location of node from the caller's fileBase and fileExtension: the page fi...
The Location class provides a way to mark a location in a file.
Definition location.h:20
Location()
Constructs an empty location.
Definition location.cpp:50
Interface implemented by Node subclasses that can refer to a C++ enum.
Definition nativeenum.h:28
virtual const NativeEnum * nativeEnum() const =0
Encapsulates information about native (C++) enum values.
Definition nativeenum.h:14
const EnumNode * enumNode() const
Definition nativeenum.h:19
QString styleString() const
OpenedList(ListStyle style)
Represents an output directory that has been verified to exist.
const QString & path() const noexcept
Singleton registry for discovering output producers by format.
OutputProducer * producerForFormat(const QString &format) const
Returns the producer registered for format, or nullptr if none.
static OutputProducerRegistry & instance()
Returns the singleton registry instance.
A PageNode is a Node that generates a documentation page.
Definition pagenode.h:19
bool isAttribution() const
Definition pagenode.h:51
This class describes one instance of using the Q_PROPERTY macro.
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
static QDocDatabase * qdocDB()
Creates the singleton.
NamespaceNode * primaryTreeRoot()
Returns a pointer to the root node of the primary tree.
const CollectionNode * getModuleNode(const Node *relative)
Returns the collection node representing the module that relative node belongs to,...
Status
Specifies the status of the QQmlIncubator.
Definition text.h:12
const Atom * firstAtom() const
Definition text.h:33
bool isEmpty() const
Definition text.h:30
void clear()
Definition text.cpp:250
#define SKIP_CHAR()
#define CONFIG_REDIRECTDOCUMENTATIONTODEVNULL
Definition config.h:447
#define CONFIG_AUTOLINKERRORS
Definition config.h:384
#define CONFIG_EXTRAIMAGES
Definition config.h:403
#define CONFIG_EXAMPLES
Definition config.h:399
#define CONFIG_URL
Definition config.h:468
#define CONFIG_OUTPUTSUFFIXES
Definition config.h:439
#define CONFIG_OUTPUTPREFIXES
Definition config.h:438
#define CONFIG_PRELIMINARY
Definition config.h:442
#define CONFIG_NOLINKERRORS
Definition config.h:435
#define CONFIG_DESCRIPTION
Definition config.h:394
#define CONFIG_PROJECT
Definition config.h:444
#define CONFIG_EXAMPLESINSTALLPATH
Definition config.h:400
#define CONFIG_PRODUCTNAME
Definition config.h:443
#define CONFIG_QUOTINGINFORMATION
Definition config.h:450
#define CONFIG_STYLESHEETS
Definition config.h:460
#define CONFIG_IMAGESOUTPUTDIR
Definition config.h:417
#define CONFIG_FORMATTING
Definition config.h:405
#define CONFIG_SCRIPTS
Definition config.h:452
QMultiMap< QString, QString > QStringMultiMap
Definition doc.h:29
Provides human-readable descriptions of QDoc nodes.
QString nodeTypeDescription(const Node *node, GrammaticalNumber number=GrammaticalNumber::Singular)
Pure string helpers with no dependencies on QDoc driver types.
Definition textutils.h:11
This namespace holds QDoc-internal utility methods.
Definition utilities.h:21
QList< Node * > NodeList
Definition node.h:45
static QLatin1String gt("&gt;")
#define SKIP_SPACE
static void startNote(Text &text)
ValidationContext
Selects warning message wording based on documentation context.
static QLatin1String amp("&amp;")
static QLatin1String quot("&quot;")
static void warnAboutUnknownDocumentedParams(const Node *node, const QSet< QString > &documentedNames, const QSet< QString > &allowedNames, ValidationContext context)
Warns about documented parameter names in node that don't exist in allowedNames.
static QLatin1String lt("&lt;")
static QSet< QString > inheritedTemplateParamNames(const Node *node)
Returns the set of template parameter names inherited from the parent scope chain of node.
Definition generator.cpp:89
static QRegularExpression tag("</?@[^>]*>")
std::optional< QString > formatStatus(const Node *node, QDocDatabase *qdb)
@ Deprecated
Definition status.h:12
@ Active
Definition status.h:14
@ Preliminary
Definition status.h:13
@ InternalAuto
Definition status.h:16
@ Internal
Definition status.h:15
The Node class is the base class for all the nodes in QDoc's parse tree.
bool isExternalPage() const
Returns true if the node type is ExternalPage.
Definition node.h:100
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
virtual bool docMustBeGenerated() const
This function is called to perform a test to decide if the node must have documentation generated.
Definition node.h:198
virtual bool isWrapper() const
Returns true if the node is a class node or a QML type node that is marked as being a wrapper class o...
Definition node.cpp:989
bool isPrivate() const
Returns true if this node's access is Private.
Definition node.h:113
bool isActive() const
Returns true if this node's status is Active.
Definition node.h:89
bool isNamespace() const
Returns true if the node type is Namespace.
Definition node.h:110
ComparisonCategory comparisonCategory() const
Definition node.h:187
bool hasFileNameBase() const
Returns true if the node's file name base has been set.
Definition node.h:169
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
Definition node.h:123
bool isSharedCommentNode() const
Returns true if the node type is SharedComment.
Definition node.h:126
bool isHeader() const
Returns true if the node type is HeaderFile.
Definition node.h:106
Genus genus() const override
Returns this node's Genus.
Definition node.h:85
virtual bool isPageNode() const
Returns true if this node represents something that generates a documentation page.
Definition node.h:150
virtual bool isMacro() const
returns true if either FunctionNode::isMacroWithParams() or FunctionNode::isMacroWithoutParams() retu...
Definition node.h:149
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
virtual bool isTextPageNode() const
Returns true if the node is a PageNode but not an Aggregate.
Definition node.h:155
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
const Location & location() const
If this node's definition location is empty, this function returns this node's declaration location.
Definition node.h:235
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
virtual bool isMarkedReimp() const
Returns true if the FunctionNode is marked as a reimplemented function.
Definition node.h:152
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
bool isSharingComment() const
This function returns true if the node is sharing a comment with other nodes.
Definition node.h:250
bool hasDoc() const
Returns true if this node is documented, or it represents a documented node read from the index ('had...
Definition node.cpp:942
bool isPreliminary() const
Returns true if this node's status is Preliminary.
Definition node.h:112
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
@ SignaturePlain
Definition node.h:66
bool isExample() const
Returns true if the node type is Example.
Definition node.h:99
bool isIndexNode() const
Returns true if this node was created from something in an index file.
Definition node.h:107
bool isQmlProperty() const
Returns true if the node type is QmlProperty.
Definition node.h:122
Represents a file that is reachable by QDoc based on its current configuration.