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
aggregate.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 "aggregate.h"
5
6#include "config.h"
7#include "functionnode.h"
10#include "parameters.h"
11#include "typedefnode.h"
12#include "qdocdatabase.h"
14#include "qmltypenode.h"
16
17#include <QtCore/qspan.h>
18
19#include <vector>
20
21using namespace Qt::Literals::StringLiterals;
22
23QT_BEGIN_NAMESPACE
24
25/*!
26 \class Aggregate
27 */
28
29/*! \fn Aggregate::Aggregate(NodeType type, Aggregate *parent, const QString &name)
30 The constructor should never be called directly. It is only called
31 by the constructors of subclasses of Aggregate. Those constructors
32 pass the node \a type they want to create, the \a parent of the new
33 node, and its \a name.
34 */
35
36/*!
37 Recursively set all non-related members in the list of children to
38 \nullptr, after which each aggregate can safely delete all children
39 in their list. Aggregate's destructor calls this only on the root
40 namespace node.
41 */
42void Aggregate::dropNonRelatedMembers()
43{
44 for (auto &child : m_children) {
45 if (!child)
46 continue;
47 if (child->parent() != this)
48 child = nullptr;
49 else if (child->isAggregate())
50 static_cast<Aggregate*>(child)->dropNonRelatedMembers();
51 }
52}
53
54/*!
55 Destroys this Aggregate; deletes each child.
56 */
58{
59 // If this is the root, clear non-related children first
60 if (isNamespace() && name().isEmpty())
61 dropNonRelatedMembers();
62
63 m_enumChildren.clear();
64 m_nonfunctionMap.clear();
65 m_functionMap.clear();
66 qDeleteAll(m_children.begin(), m_children.end());
67 m_children.clear();
68}
69
70/*!
71 If \a genus is \c{Node::DontCare}, find the first node in
72 this node's child list that has the given \a name. If this
73 node is a QML type, be sure to also look in the children
74 of its property group nodes. Return the matching node or \c nullptr.
75
76 If \a genus is either \c{Node::CPP} or \c {Node::QML}, then
77 find all this node's children that have the given \a name,
78 and return the one that satisfies the \a genus requirement.
79 */
80Node *Aggregate::findChildNode(const QString &name, Genus genus, int findFlags) const
81{
82 if (genus == Genus::DontCare) {
83 Node *node = m_nonfunctionMap.value(name);
84 if (node)
85 return node;
86 } else {
87 const NodeList &nodes = m_nonfunctionMap.values(name);
88 for (auto *node : nodes) {
89 if (node->isInternal())
90 continue;
91 if (hasCommonGenusType(genus, node->genus())) {
92 if (findFlags & TypesOnly) {
93 if (!node->isTypedef() && !node->isClassNode()
94 && !node->isQmlType() && !node->isEnumType())
95 continue;
96 } else if (findFlags & IgnoreModules && node->isModule())
97 continue;
98 return node;
99 }
100 }
101 }
102 if (genus != Genus::DontCare && !(hasCommonGenusType(genus, this->genus())))
103 return nullptr;
104
105 if (findFlags & TypesOnly)
106 return nullptr;
107
108 auto it = m_functionMap.find(name);
109 return it != m_functionMap.end() ? (*(*it).begin()) : nullptr;
110}
111
112/*!
113 Find all the child nodes of this node that are named
114 \a name and return them in \a nodes.
115 */
116void Aggregate::findChildren(const QString &name, NodeVector &nodes) const
117{
118 nodes.clear();
119 const auto &functions = m_functionMap.value(name);
120 nodes.reserve(functions.size() + m_nonfunctionMap.count(name));
121 for (auto f : functions)
122 nodes.emplace_back(f);
123 auto [it, end] = m_nonfunctionMap.equal_range(name);
124 while (it != end) {
125 nodes.emplace_back(*it);
126 ++it;
127 }
128}
129
130/*!
131 This function searches for a child node of this Aggregate,
132 such that the child node has the spacified \a name and the
133 function \a isMatch returns true for the node. The function
134 passed must be one of the isXxx() functions in class Node
135 that tests the node type.
136 */
137Node *Aggregate::findNonfunctionChild(const QString &name, bool (Node::*isMatch)() const)
138{
139 const NodeList &nodes = m_nonfunctionMap.values(name);
140 for (auto *node : nodes) {
141 if ((node->*(isMatch))())
142 return node;
143 }
144 return nullptr;
145}
146
147/*!
148 Find a function node that is a child of this node, such that
149 the function node has the specified \a name and \a parameters.
150 If \a parameters is empty but no matching function is found
151 that has no parameters, return the first non-internal primary
152 function or overload, whether it has parameters or not.
153
154 \sa normalizeOverloads()
155 */
156FunctionNode *Aggregate::findFunctionChild(const QString &name, const Parameters &parameters)
157{
158 auto map_it = m_functionMap.find(name);
159 if (map_it == m_functionMap.end())
160 return nullptr;
161
162 // If parameters is empty (e.g., from \overload command), don't try exact matching.
163 // Instead, find the best available function based on isPrimaryOverload flag.
164 if (parameters.isEmpty()) {
165 FunctionNode *fallback = nullptr;
166 FunctionNode *lastResort = nullptr;
167 FunctionNode *deletedFallback = nullptr;
168
169 for (auto *fn : *map_it) {
170 // Primary overload takes highest priority - return immediately
171 if (fn->isPrimaryOverload() && !fn->isInternal())
172 return fn;
173
174 // Remember first non-deprecated, non-internal, non-deleted as fallback.
175 // Deleted functions shouldn't be primary link targets - users linking
176 // to ClassName() want a usable constructor, not a deleted copy ctor.
177 if (!fallback && !fn->isInternal() && !fn->isDeprecated()
178 && !fn->isDeletedAsWritten())
179 fallback = fn;
180
181 // Remember first non-internal, non-deleted as last resort
182 if (!lastResort && !fn->isInternal() && !fn->isDeletedAsWritten())
183 lastResort = fn;
184
185 // Deleted functions are valid link targets when no other option exists
186 if (!deletedFallback && !fn->isInternal())
187 deletedFallback = fn;
188 }
189
190 if (fallback)
191 return fallback;
192
193 if (lastResort)
194 return lastResort;
195
196 // Fall back to deleted functions when they're the only option
197 return deletedFallback;
198 }
199
200 // Try exact parameter match
201 auto match_it = std::find_if((*map_it).begin(), (*map_it).end(),
202 [&parameters](const FunctionNode *fn) {
203 if (fn->isInternal())
204 return false;
205 if (parameters.count() != fn->parameters().count())
206 return false;
207 for (int i = 0; i < parameters.count(); ++i)
208 if (parameters.at(i).type() != fn->parameters().at(i).type())
209 return false;
210 return true;
211 });
212
213 return (match_it != (*map_it).end()) ? *match_it : nullptr;
214}
215
216/*!
217 Returns the function node that is a child of this node, such
218 that the function described has the same name and signature
219 as the function described by the function node \a clone.
220
221 Returns \nullptr if no matching function was found.
222 */
224{
225 auto funcs_it = m_functionMap.find(clone->name());
226 if (funcs_it == m_functionMap.end())
227 return nullptr;
228
229 auto func_it = std::find_if((*funcs_it).begin(), (*funcs_it).end(),
230 [clone](const FunctionNode *fn) {
231 return compare(clone, fn) == 0;
232 });
233
234 return func_it != (*funcs_it).end() ? *func_it : nullptr;
235}
236
237
238/*!
239 \internal
240 Warn about documented, non-private children under undocumented parents, unless:
241
242 \list
243 \li The \a child's parent() doesn't match \a aggregate (indicating a related
244 non-member), to avoid duplicate warnings as the node appears under multiple
245 aggregates.
246 \li The child is private (private members don't generate output).
247 \li The child has \c Internal or \c InternalAuto status (we check the child's
248 own status, not inherited internal status from the parent).
249 \li The parent is a proxy node (automatically generated, no documentation).
250 \li The parent is a namespace node (handled separately by
251 NamespaceNode::reportDocumentedChildrenInUndocumentedNamespace()).
252 \li The parent is marked with the \c{\\dontdocument} command.
253 \li The child is marked with the \c{\\dontdocument} command.
254 \li The child has auto-generated documentation. These docs are created by QDoc,
255 not written by a human, so warning about them would be confusing.
256 \li The \c{-showinternal} command-line option is set (internal nodes generate
257 output, so the warning is not needed).
258 \li The \c{-no-linkerrors} command-line option is set (avoids false positives
259 when the aggregate is documented outside the current project).
260 \li The file path of the child declaration matches \e internalfilepatterns.
261 \endlist
262
263 \note We check \c{child->status()} directly rather than \c{child->isInternal()}
264 because \c{isInternal()} also considers the parent's status. Since the parent
265 is undocumented (and thus marked InternalAuto), \c{isInternal()} would incorrectly
266 return true for all children, suppressing the warning entirely.
267
268 \sa NamespaceNode::reportDocumentedChildrenInUndocumentedNamespace()
269*/
270static void warnAboutDocumentedChildInUndocumentedParent(const Node *aggregate, const Node *child)
271{
272 Q_ASSERT(child);
273 const auto *parent{child->parent()};
274 if (parent && parent == aggregate && !child->isPrivate()
276 && !parent->isProxyNode() && !parent->isNamespace() && !parent->isDontDocument()
277 && !parent->hasDoc()) {
278
279 if (child->isDontDocument())
280 return;
281
283 return;
284
285 auto &config = Config::instance();
286
287 if (InclusionFilter::processInternalDocs(config.createInclusionPolicy()))
288 return;
289
290 if (config.get(CONFIG_NOLINKERRORS).asBool())
291 return;
292
293 if (child->genus() == Genus::CPP && !child->declLocation().isEmpty()) {
294 if (Config::matchesInternalFilePattern(
295 child->declLocation().filePath(),
296 config.getInternalFilePatternsCompiled()))
297 return;
298 }
299
300 child->doc().location().warning(
301 "No output generated for %1 '%2' because '%3' is undocumented"_L1
302 .arg(child->nodeTypeString(),
303 child->plainFullName(),
304 child->parent()->name()));
305 }
306}
307
308/*!
309 Mark all child nodes that have no documentation as having
310 internal status. QDoc will then ignore them for documentation purposes.
311 */
313{
314 for (auto *child : std::as_const(m_children)) {
315 if (!child->hasDoc() && !child->isDontDocument()) {
316 if (!child->docMustBeGenerated()) {
317 if (child->isFunction()) {
318 if (static_cast<FunctionNode *>(child)->hasAssociatedProperties())
319 continue;
320 } else if (child->isTypedef() && child->isInAPI()) {
321 if (static_cast<TypedefNode *>(child)->hasAssociatedEnum())
322 continue;
323 }
324 child->setStatus(Status::InternalAuto);
325 }
326 } else {
327 warnAboutDocumentedChildInUndocumentedParent(this, child);
328 }
329 if (child->isAggregate()) {
330 static_cast<Aggregate *>(child)->markUndocumentedChildrenInternal();
331 }
332 }
333}
334
335/*!
336 \internal
337
338 Adds \a node to the list of related non-members of the aggregate
339 \a target, without adopting it. The node remains documented under
340 its parent, and the documentation of \a target links to it.
341
342 If \a target resolves to an aggregate in an index file, records the
343 relationship in the node's tree instead, so that it is written to the
344 index file of this module. The module that documents \a target can
345 then link to the node.
346
347 If \a node is a shared comment node, adds each node in its collective
348 instead. Does nothing if \a target resolves to the node's parent. If
349 \a target is not found, reports it.
350
351 \sa Tree::addExternalRelates()
352*/
353static void addToRelatedTarget(Node *node, const QString &target)
354{
355 auto *aggregate = QDocDatabase::qdocDB()->findRelatesNode(target.split("::"_L1));
356 if (!aggregate) {
357 Location().report(
358 "Failed to find \\relates target '%1' for %2"_L1.arg(target, node->fullName()));
359 return;
360 }
361 if (aggregate == node->parent())
362 return;
363
364 const NodeList nodes = node->isSharedCommentNode()
365 ? static_cast<SharedCommentNode *>(node)->collective()
366 : NodeList{ node };
367 if (aggregate->isIndexNode()) {
368 for (auto *n : nodes)
369 n->tree()->addExternalRelates(n, aggregate->plainFullName());
370 return;
371 }
372 auto &related = aggregate->relatedByProxy();
373 for (auto *n : nodes) {
374 if (!related.contains(n))
375 related.append(n);
376 }
377}
378
379/*!
380 Adopts each non-aggregate C++ node (function/macro, typedef, enum, variable,
381 or a shared comment node with genus Node::CPP) to the aggregate specified in
382 the node's documentation using the \\relates command.
383
384 If the target Aggregate is not found in the primary tree, creates a new
385 ProxyNode to use as the parent. If the target Aggregate is not found at all,
386 reports it.
387
388 If the node's documentation has multiple \\relates commands, the target of
389 the first one becomes the node's adoptive parent. Each of the other
390 targets lists the node as a related non-member that links to the node's
391 documentation under its adoptive parent.
392*/
394{
395 auto *database = QDocDatabase::qdocDB();
396
397 // An unresolved \relates target makes this loop create a ProxyNode parented
398 // to this aggregate. Node's constructor adds it to \c{m_children}, mutating
399 // the very list being iterated. Iterate over a \c{const} copy instead, as
400 // the new ProxyNode doesn't need relates resolution itself.
401 const NodeList children = m_children;
402 for (auto *node : children) {
403 if (node->genus() != Genus::CPP)
404 continue;
405
406 if (!node->isAggregate()) {
407 const auto &relates_args = node->doc().metaCommandArgs("relates"_L1);
408 if (relates_args.isEmpty())
409 continue;
410 // Hidden friends are marked as related non-members during
411 // initial parsing (they belong to their enclosing class).
412 // An explicit \relates directive should still relocate them
413 // when the function participates in a different class's
414 // protocol (e.g. qHashEquals as a QHash customization point).
415 // Skip only if already adopted by a different \relates target.
416 if (node->isRelatedNonmember() && node->parent() != this)
417 continue;
418
419 auto *aggregate = database->findRelatesNode(relates_args[0].first.split("::"_L1));
420 if (!aggregate)
421 Location().report("Failed to find \\relates target '%1' for %2"_L1
422 .arg(relates_args[0].first, node->fullName()));
423
424 if (!aggregate || aggregate->isIndexNode())
425 aggregate = new ProxyNode(this, relates_args[0].first);
426
427 if (node->parent() != aggregate) {
428 aggregate->adoptChild(node);
429 node->setRelatedNonmember(true);
430 }
431
432 // With multiple \relates commands, the first target is the
433 // adoptive parent. The other targets list the node as a related
434 // non-member that links to its documentation under the parent.
435 for (const auto &arg : QSpan<const ArgPair>(relates_args).sliced(1))
436 addToRelatedTarget(node, arg.first);
437 } else {
438 static_cast<Aggregate*>(node)->resolveRelates();
439 }
440 }
441}
442
443/*!
444 Sorts the lists of overloads in the function map and assigns overload
445 numbers.
446
447 For sorting, active functions take precedence over internal ones, as well
448 as ones marked as \\overload - the latter ones typically do not contain
449 full documentation, so selecting them as the \e primary function
450 would cause unnecessary warnings to be generated. However, functions
451 explicitly marked with \\overload primary take precedence over other
452 overloads and will be selected as the primary function.
453
454 Otherwise, the order is set as determined by FunctionNode::compare().
455 */
457{
458 for (auto &map_it : m_functionMap) {
459 if (map_it.size() == 1) {
460 map_it.front()->setOverloadNumber(0);
461 } else if (map_it.size() > 1) {
462 // Check for multiple primary overloads before sorting
463 std::vector<const FunctionNode*> primaryOverloads;
464 for (const auto *fn : map_it) {
465 if (!fn->isPrimaryOverload())
466 continue;
467
468 // Check if we already have a primary from a different location
469 const auto *currentLocation = &(fn->doc().location());
470 for (const auto *existingPrimary : primaryOverloads) {
471 const auto *existingLocation = &(existingPrimary->doc().location());
472
473 if (*currentLocation != *existingLocation) {
474 fn->doc().location().warning(
475 "Multiple primary overloads for '%1'. The previous primary is here: %2"_L1
476 .arg(fn->name(), existingPrimary->doc().location().toString()));
477 break;
478 }
479 }
480
481 primaryOverloads.push_back(fn);
482 }
483
484 std::sort(map_it.begin(), map_it.end(),
485 [](const FunctionNode *f1, const FunctionNode *f2) -> bool {
486 if (f1->isInternal() != f2->isInternal())
487 return f2->isInternal();
488 // Prioritize functions marked with \overload primary
489 if (f1->isPrimaryOverload() != f2->isPrimaryOverload())
490 return f1->isPrimaryOverload();
491 if (f1->isOverload() != f2->isOverload())
492 return f2->isOverload();
493 // Prioritize documented over undocumented
494 if (f1->hasDoc() != f2->hasDoc())
495 return f1->hasDoc();
496 return (compare(f1, f2) < 0);
497 });
498 // Set overload numbers only if the functions are documented.
499 // They are not visible if undocumented.
500 // Only set overload numbers within the context of the parent, to
501 // avoid renumbering from occurring if the function has been
502 // adopted by multiple parents.
503 signed short n{0};
504 for (auto *fn : map_it) {
505 if (fn->hasDoc() && fn->parent() == this)
506 fn->setOverloadNumber(n++);
507 }
508 }
509 }
510
511 for (auto *node : std::as_const(m_children)) {
512 if (node->isAggregate())
513 static_cast<Aggregate *>(node)->normalizeOverloads();
514 }
515}
516
517/*!
518 Returns a copy of the child nodes of this aggregate that are
519 not function nodes, in the order they appear in the child list.
520 Consumers that need a specific presentation order must sort
521 the result themselves.
522
523 \sa childNodes()
524 */
526{
527 NodeList result = m_children;
528 result.erase(
529 std::remove_if(result.begin(), result.end(),
530 [](const Node *node) {
531 return node->isFunction();
532 }),
533 result.end());
534 return result;
535}
536
537/*! \fn bool Aggregate::isAggregate() const
538 Returns \c true because this node is an instance of Aggregate,
539 which means it can have children.
540 */
541
542/*!
543 Finds the enum type node that has \a enumValue as one of
544 its enum values and returns a pointer to it. Returns 0 if
545 no enum type node is found that has \a enumValue as one
546 of its values.
547 */
548const EnumNode *Aggregate::findEnumNodeForValue(const QString &enumValue) const
549{
550 for (const auto *node : m_enumChildren) {
551 const auto *en = static_cast<const EnumNode *>(node);
552 if (en->hasItem(enumValue))
553 return en;
554 }
555 return nullptr;
556}
557
558/*!
559 Adds the \a child to this node's child map using \a title
560 as the key. The \a child is not added to the child list
561 again, because it is presumed to already be there. We just
562 want to be able to find the child by its \a title.
563 */
564void Aggregate::addChildByTitle(Node *child, const QString &title)
565{
566 m_nonfunctionMap.insert(title, child);
567}
568
569/*!
570 Adds the \a child to this node's child list and sets the child's
571 parent pointer to this Aggregate.
572
573 The \a child is then added to this Aggregate's searchable maps
574 and lists.
575
576 \note This function does not test the child's parent pointer
577 for null before changing it. If the child's parent pointer
578 is not null, then it is being reparented. The child becomes
579 a child of this Aggregate, but it also remains a child of
580 the Aggregate that is it's old parent. But the child will
581 only have one parent, and it will be this Aggregate. The is
582 because of the \c relates command.
583 */
585{
586 m_children.append(child);
587 child->setParent(this);
588 child->setUrl(QString());
590
591 if (child->isFunction()) {
592 m_functionMap[child->name()].emplace_back(static_cast<FunctionNode *>(child));
593 } else if (!child->name().isEmpty()) {
594 m_nonfunctionMap.insert(child->name(), child);
595 if (child->isEnumType())
596 m_enumChildren.append(child);
597 }
598}
599
600/*!
601 This Aggregate becomes the adoptive parent of \a child. The
602 \a child knows this Aggregate as its parent, but its former
603 parent continues to have pointers to the child in its child
604 list and in its searchable data structures. But the child is
605 also added to the child list and searchable data structures
606 of this Aggregate.
607
608 The child's former parent is remembered as its declaration parent,
609 so that its C++ scope keeps reflecting where it was declared
610 rather than where it is documented.
611 */
613{
614 if (child->parent() != this) {
615 m_children.append(child);
616 if (!child->declarationParent())
618 child->setParent(this);
619 if (child->isFunction()) {
620 m_functionMap[child->name()].emplace_back(static_cast<FunctionNode *>(child));
621 } else if (!child->name().isEmpty()) {
622 m_nonfunctionMap.insert(child->name(), child);
623 if (child->isEnumType())
624 m_enumChildren.append(child);
625 }
626 if (child->isSharedCommentNode()) {
627 auto *scn = static_cast<SharedCommentNode *>(child);
628 for (Node *n : scn->collective())
629 adoptChild(n);
630 }
631 }
632}
633
634/*!
635 If this node has a child that is a QML property named \a n and that
636 also matches \a attached, return a pointer to that child.
637 */
639{
641 for (auto *child : std::as_const(m_children)) {
642 if (child->nodeType() == goal) {
643 if (child->name() == n) {
644 if (attached == AnyProperties
645 || (child->isAttached() && attached == AttachedProperties)
646 || (!child->isAttached() && attached == UnattachedProperties))
647 return static_cast<QmlPropertyNode *>(child);
648 }
649 }
650 }
651 return nullptr;
652}
653
654/*!
655 Returns \c true if this aggregate has multiple function
656 overloads matching the name of \a fn.
657
658 \note Assumes \a fn is a member of this aggregate.
659*/
660bool Aggregate::hasOverloads(const FunctionNode *fn) const
661{
662 auto it = m_functionMap.find(fn->name());
663 return !(it == m_functionMap.end()) && (it.value().size() > 1);
664}
665
666/*
667 When deciding whether to include a function in the function
668 index, if the function is marked private, don't include it.
669 If the function is marked obsolete, don't include it. If the
670 function is marked internal, don't include it. Or if the
671 function is a destructor or any kind of constructor, don't
672 include it. Otherwise include it.
673 */
674static bool keep(FunctionNode *fn)
675{
677 return false;
678 return true;
679}
680
681/*!
682 Insert all functions declared in this aggregate into the
683 \a functionIndex. Call the function recursively for each
684 child that is an aggregate.
685
686 Only include functions that are in the public API and
687 that are not constructors or destructors.
688 */
690{
691 for (auto functions : m_functionMap) {
692 std::for_each(functions.begin(), functions.end(),
693 [&functionIndex](FunctionNode *fn) {
694 if (keep(fn))
695 functionIndex[fn->name()].insert(fn->parent()->fullDocumentName(), fn);
696 }
697 );
698 }
699
700 for (Node *node : std::as_const(m_children)) {
701 if (node->isAggregate() && !node->isPrivate() && !node->isDontDocument())
702 static_cast<Aggregate *>(node)->findAllFunctions(functionIndex);
703 }
704}
705
706/*!
707 For each child of this node, if the child is a namespace node,
708 insert the child into the \a namespaces multimap. If the child
709 is an aggregate, call this function recursively for that child.
710
711 When the function called with the root node of a tree, it finds
712 all the namespace nodes in that tree and inserts them into the
713 \a namespaces multimap.
714
715 The root node of a tree is a namespace, but it has no name, so
716 it is not inserted into the map. So, if this function is called
717 for each tree in the qdoc database, it finds all the namespace
718 nodes in the database.
719 */
721{
722 for (auto *node : std::as_const(m_children)) {
723 if (node->isAggregate() && !node->isPrivate()) {
724 if (node->isNamespace() && !node->name().isEmpty())
725 namespaces.insert(node->name(), node);
726 static_cast<Aggregate *>(node)->findAllNamespaces(namespaces);
727 }
728 }
729}
730
731/*!
732 Returns true if this aggregate contains at least one child
733 that is marked obsolete. Otherwise returns false.
734 */
736{
737 for (const auto *node : m_children)
738 if (!node->isPrivate() && node->isDeprecated()) {
739 if (node->isFunction() || node->isProperty() || node->isEnumType() || node->isTypedef()
740 || node->isTypeAlias() || node->isVariable() || node->isQmlProperty())
741 return true;
742 }
743 return false;
744}
745
746/*!
747 Finds all the obsolete C++ classes and QML types in this
748 aggregate and all the C++ classes and QML types with obsolete
749 members, and inserts them into maps used elsewhere for
750 generating documentation.
751 */
753{
754 for (auto *node : std::as_const(m_children)) {
755 if (!node->isPrivate()) {
756 if (node->isDeprecated()) {
757 if (node->isClassNode())
758 QDocDatabase::obsoleteClasses().insert(node->qualifyCppName(), node);
759 else if (node->isQmlType())
760 QDocDatabase::obsoleteQmlTypes().insert(node->qualifyQmlName(), node);
761 } else if (node->isClassNode()) {
762 auto *a = static_cast<Aggregate *>(node);
763 if (a->hasObsoleteMembers())
764 QDocDatabase::classesWithObsoleteMembers().insert(node->qualifyCppName(), node);
765 } else if (node->isQmlType()) {
766 auto *a = static_cast<Aggregate *>(node);
767 if (a->hasObsoleteMembers())
768 QDocDatabase::qmlTypesWithObsoleteMembers().insert(node->qualifyQmlName(),
769 node);
770 } else if (node->isAggregate()) {
771 static_cast<Aggregate *>(node)->findAllObsoleteThings();
772 }
773 }
774 }
775}
776
777/*!
778 Finds all the C++ classes, QML types, QML basic types, and examples
779 in this aggregate and inserts them into appropriate maps for later
780 use in generating documentation.
781 */
783{
784 for (auto *node : std::as_const(m_children)) {
785 if (!node->isPrivate() && !node->isInternal() && !node->isDontDocument()
786 && node->tree()->camelCaseModuleName() != QString("QDoc")) {
787 if (node->isClassNode()) {
788 QDocDatabase::cppClasses().insert(node->qualifyCppName().toLower(), node);
789 } else if (node->isQmlType()) {
790 QString name = node->name().toLower();
791 QDocDatabase::qmlTypes().insert(name, node);
792 // also add to the QML basic type map
793 if (node->isQmlBasicType())
794 QDocDatabase::qmlBasicTypes().insert(name, node);
795 } else if (node->isExample()) {
796 // use the module index title as key for the example map
797 QString title = node->tree()->indexTitle();
798 if (!QDocDatabase::examples().contains(title, node))
799 QDocDatabase::examples().insert(title, node);
800 } else if (node->isAggregate()) {
801 static_cast<Aggregate *>(node)->findAllClasses();
802 }
803 }
804 }
805}
806
807/*!
808 Find all the attribution pages in this node and insert them
809 into \a attributions.
810 */
812{
813 for (auto *node : std::as_const(m_children)) {
814 if (!node->isPrivate()) {
815 if (node->isPageNode() && static_cast<PageNode*>(node)->isAttribution())
816 attributions.insert(node->tree()->indexTitle(), node);
817 else if (node->isAggregate())
818 static_cast<Aggregate *>(node)->findAllAttributions(attributions);
819 }
820 }
821}
822
823/*!
824 Finds all the nodes in this node where a \e{since} command appeared
825 in the qdoc comment and sorts them into maps according to the kind
826 of node.
827
828 This function is used for generating the "New Classes... in x.y"
829 section on the \e{What's New in Qt x.y} page.
830 */
832{
833 for (auto *node : std::as_const(m_children)) {
834 if (node->isRelatedNonmember() && node->parent() != this)
835 continue;
836 QString sinceString = node->since();
837 // Insert a new entry into each map for each new since string found.
838 if (node->isInAPI() && !sinceString.isEmpty()) {
839 // operator[] will insert a default-constructed value into the
840 // map if key is not found, which is what we want here.
841 auto &nsmap = QDocDatabase::newSinceMaps()[sinceString];
842 auto &ncmap = QDocDatabase::newClassMaps()[sinceString];
843 auto &nqcmap = QDocDatabase::newQmlTypeMaps()[sinceString];
844
845 if (node->isFunction()) {
846 // Insert functions into the general since map.
847 auto *fn = static_cast<FunctionNode *>(node);
848 if (!fn->isDeprecated() && !fn->isSomeCtor() && !fn->isDtor())
849 nsmap.insert(fn->name(), fn);
850 } else if (node->isClassNode()) {
851 // Insert classes into the since and class maps.
852 QString name = node->qualifyWithParentName();
853 nsmap.insert(name, node);
854 ncmap.insert(name, node);
855 } else if (node->isQmlType()) {
856 // Insert QML elements into the since and element maps.
857 QString name = node->qualifyWithParentName();
858 nsmap.insert(name, node);
859 nqcmap.insert(name, node);
860 } else if (node->isQmlProperty()) {
861 // Insert QML properties into the since map.
862 nsmap.insert(node->name(), node);
863 } else if (node->isConcept()) {
864 // Insert concepts with a qualified name
865 nsmap.insert(node->qualifyWithParentName(), node);
866 } else {
867 // Insert external documents into the general since map.
868 QString name = node->qualifyWithParentName();
869 nsmap.insert(name, node);
870 }
871 }
872 // Enum values - a special case as EnumItem is not a Node subclass
873 if (node->isInAPI() && node->isEnumType()) {
874 for (const auto &val : static_cast<EnumNode *>(node)->items()) {
875 sinceString = val.since();
876 if (sinceString.isEmpty())
877 continue;
878 // Insert to enum value map
879 QDocDatabase::newEnumValueMaps()[sinceString].insert(
880 node->name() + "::" + val.name(), node);
881 // Ugly hack: Insert into general map with an empty key -
882 // we need something in there to mark the corresponding
883 // section populated. See Sections class constructor.
884 QDocDatabase::newSinceMaps()[sinceString].replace(QString(), node);
885 }
886 }
887
888 // Recursively find child nodes with since commands.
889 if (node->isAggregate())
890 static_cast<Aggregate *>(node)->findAllSince();
891 }
892}
893
894/*!
895 Resolves the inheritance information for all QML type children
896 of this aggregate.
897*/
899{
900 NodeMap previousSearches;
901 for (auto *child : std::as_const(m_children)) {
902 if (!child->isQmlType())
903 continue;
904 static_cast<QmlTypeNode *>(child)->resolveInheritance(previousSearches);
905 }
906
907 // At this point we check for cycles in the inheritance of QML types.
908 for (auto *child : std::as_const(m_children)) {
909 if (child->isQmlType())
910 static_cast<QmlTypeNode *>(child)->checkInheritance();
911 }
912}
913
914/*!
915 Returns a word representing the kind of Aggregate this node is.
916 Currently recognizes class, struct, union, and namespace.
917 If \a cap is true, the word is capitalised.
918 */
919QString Aggregate::typeWord(bool cap) const
920{
921 if (cap) {
922 switch (nodeType()) {
923 case NodeType::Class:
924 return "Class"_L1;
925 case NodeType::Struct:
926 return "Struct"_L1;
927 case NodeType::Union:
928 return "Union"_L1;
929 case NodeType::Namespace:
930 return "Namespace"_L1;
931 default:
932 break;
933 }
934 } else {
935 switch (nodeType()) {
936 case NodeType::Class:
937 return "class"_L1;
938 case NodeType::Struct:
939 return "struct"_L1;
940 case NodeType::Union:
941 return "union"_L1;
942 case NodeType::Namespace:
943 return "namespace"_L1;
944 default:
945 break;
946 }
947 }
948 return QString();
949}
950
951/*! \fn int Aggregate::count() const
952 Returns the number of children in the child list.
953 */
954
955/*! \fn const NodeList &Aggregate::childNodes() const
956 Returns a const reference to the child list.
957 */
958
959/*! \fn NodeList::ConstIterator Aggregate::constBegin() const
960 Returns a const iterator pointing at the beginning of the child list.
961 */
962
963/*! \fn NodeList::ConstIterator Aggregate::constEnd() const
964 Returns a const iterator pointing at the end of the child list.
965 */
966
967/*! \fn QmlTypeNode *Aggregate::qmlBaseNode() const
968 If this Aggregate is a QmlTypeNode, this function returns a pointer to
969 the QmlTypeNode that is its base type. Otherwise it returns \c nullptr.
970 A QmlTypeNode doesn't always have a base type, so even when this Aggregate
971 is aQmlTypeNode, the pointer returned can be \c nullptr.
972 */
973
974/*! \fn FunctionMap &Aggregate::functionMap()
975 Returns a reference to this Aggregate's function map, which
976 is a map of all the children of this Aggregate that are
977 FunctionNodes.
978 */
979
980/*! \fn void Aggregate::appendToRelatedByProxy(const NodeList &t)
981 Appends the list of node pointers to the list of elements that are
982 related to this Aggregate but are documented elsewhere.
983
984 \sa relatedByProxy()
985 */
986
987/*! \fn NodeList &Aggregate::relatedByProxy()
988 Returns a reference to a list of node pointers where each element
989 points to a node that is related to this Aggregate, but documented
990 elsewhere. The node is either in an index file for some other module,
991 or it is a related non-member adopted by another aggregate, listed
992 as one of the additional targets of the \c {\relates} command. When
993 the documentation for this Aggregate is written, it contains links to
994 these nodes.
995 */
996
997QT_END_NAMESPACE
static void warnAboutDocumentedChildInUndocumentedParent(const Node *aggregate, const Node *child)
static bool keep(FunctionNode *fn)
static void addToRelatedTarget(Node *node, const QString &target)
NodeList nonFunctionChildren() const
Returns a copy of the child nodes of this aggregate that are not function nodes, in the order they ap...
void resolveRelates()
Adopts each non-aggregate C++ node (function/macro, typedef, enum, variable, or a shared comment node...
void adoptChild(Node *child)
This Aggregate becomes the adoptive parent of child.
QString typeWord(bool cap) const
Returns a word representing the kind of Aggregate this node is.
void resolveQmlInheritance()
Resolves the inheritance information for all QML type children of this aggregate.
void addChildByTitle(Node *child, const QString &title)
Adds the child to this node's child map using title as the key.
bool hasOverloads(const FunctionNode *fn) const
Returns true if this aggregate has multiple function overloads matching the name of fn.
void findAllObsoleteThings()
Finds all the obsolete C++ classes and QML types in this aggregate and all the C++ classes and QML ty...
~Aggregate() override
Destroys this Aggregate; deletes each child.
Definition aggregate.cpp:57
void findChildren(const QString &name, NodeVector &nodes) const
Find all the child nodes of this node that are named name and return them in nodes.
bool hasObsoleteMembers() const
Returns true if this aggregate contains at least one child that is marked obsolete.
FunctionNode * findFunctionChild(const QString &name, const Parameters &parameters)
Find a function node that is a child of this node, such that the function node has the specified name...
void findAllSince()
Finds all the nodes in this node where a {since} command appeared in the qdoc comment and sorts them ...
NodeList m_children
Definition aggregate.h:90
void normalizeOverloads()
Sorts the lists of overloads in the function map and assigns overload numbers.
Node * findNonfunctionChild(const QString &name, bool(Node::*)() const)
This function searches for a child node of this Aggregate, such that the child node has the spacified...
PropertySearchType
Definition aggregate.h:25
void findAllFunctions(NodeMapMap &functionIndex)
Insert all functions declared in this aggregate into the functionIndex.
void findAllNamespaces(NodeMultiMap &namespaces)
For each child of this node, if the child is a namespace node, insert the child into the namespaces m...
void markUndocumentedChildrenInternal()
Mark all child nodes that have no documentation as having internal status.
QmlPropertyNode * hasQmlProperty(const QString &, PropertySearchType attached=AnyProperties) const
If this node has a child that is a QML property named n and that also matches attached,...
void addChild(Node *child)
Adds the child to this node's child list and sets the child's parent pointer to this Aggregate.
Node * findChildNode(const QString &name, Genus genus, int findFlags=0) const
If genus is {Node::DontCare}, find the first node in this node's child list that has the given name.
Definition aggregate.cpp:80
FunctionNode * findFunctionChild(const FunctionNode *clone)
Returns the function node that is a child of this node, such that the function described has the same...
void findAllClasses()
Finds all the C++ classes, QML types, QML basic types, and examples in this aggregate and inserts the...
void findAllAttributions(NodeMultiMap &attributions)
Find all the attribution pages in this node and insert them into attributions.
const EnumNode * findEnumNodeForValue(const QString &enumValue) const
Finds the enum type node that has enumValue as one of its enum values and returns a pointer to it.
const Location & location() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:89
bool isAutoGenerated() const
Returns true if this documentation was auto-generated by QDoc rather than written by an author.
Definition doc.cpp:249
This node is used to represent any kind of function being documented.
const Parameters & parameters() const
bool isDeprecated() const override
\reimp
bool isDtor() const
friend int compare(const FunctionNode *f1, const FunctionNode *f2)
Compares FunctionNode f1 with f2, assumed to have identical names.
bool isSomeCtor() const
static bool processInternalDocs(const InclusionPolicy &policy)
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
bool isEmpty() const
Returns true if there is no file name set yet; returns false otherwise.
Definition location.h:45
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
static QDocDatabase * qdocDB()
Creates the singleton.
Status
Specifies the status of the QQmlIncubator.
#define CONFIG_NOLINKERRORS
Definition config.h:435
NodeType
Definition genustypes.h:165
QList< Node * > NodeList
Definition node.h:45
QList< Node * > NodeVector
Definition node.h:47
QMap< QString, Node * > NodeMap
Definition node.h:48
QMap< QString, NodeMap > NodeMapMap
Definition node.h:49
QMultiMap< QString, Node * > NodeMultiMap
Definition node.h:50
@ TypesOnly
@ 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 isDontDocument() const
Returns true if this node's status is DontDocument.
Definition node.h:93
const Doc & doc() const
Returns a reference to the node's Doc data member.
Definition node.h:239
bool isPrivate() const
Returns true if this node's access is Private.
Definition node.h:113
void setIndexNodeFlag(bool isIndexNode=true)
Sets a flag in this Node that indicates the node was created for something in an index file.
Definition node.h:184
bool isNamespace() const
Returns true if the node type is Namespace.
Definition node.h:110
void setDeclarationParent(Aggregate *n)
Sets the node's declaration parent pointer to n, the aggregate in whose C++ scope the node was declar...
Definition node.h:183
bool isSharedCommentNode() const
Returns true if the node type is SharedComment.
Definition node.h:126
virtual bool isInternal() const
Returns true if the node's status is Internal, or if its parent is a class with Internal status.
Definition node.cpp:868
NodeType nodeType() const override
Returns this node's type.
Definition node.h:82
Genus genus() const override
Returns this node's Genus.
Definition node.h:85
bool isEnumType() const
Returns true if the node type is Enum.
Definition node.h:94
virtual Status status() const
Returns the node's status value.
Definition node.h:243
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
Definition node.h:211
bool isProxyNode() const
Returns true if the node type is Proxy.
Definition node.h:115
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
const Location & declLocation() const
Returns the Location where this node's declaration was seen.
Definition node.h:233
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
void setParent(Aggregate *n)
Sets the node's parent pointer to n.
Definition node.h:182
Aggregate * declarationParent() const
Returns the aggregate in whose C++ scope the node was declared, or null if the node was not adopted b...
Definition node.h:212
bool isIndexNode() const
Returns true if this node was created from something in an index file.
Definition node.h:107
A class for parsing and managing a function parameter list.
Definition main.cpp:28
bool isEmpty() const
Definition parameters.h:32
const Parameter & at(int i) const
Definition parameters.h:36
int count() const
Definition parameters.h:34