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
node.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 "node.h"
5
6#include "aggregate.h"
7#include "codemarker.h"
8#include "config.h"
9#include "enumnode.h"
10#include "functionnode.h"
11#include "generator.h"
13#include "nodecontext.h"
14#include "qdocdatabase.h"
15#include "qmltypenode.h"
17#include "relatedclass.h"
19#include "tokenizer.h"
20#include "tree.h"
21
22#include <QtCore/quuid.h>
23#include <QtCore/qversionnumber.h>
24
25#include <utility>
26
28
29using namespace Qt::StringLiterals;
30
31/*!
32 \class Node
33 \brief The Node class is the base class for all the nodes in QDoc's parse tree.
34
35 Class Node is the base class of all the node subclasses. There is a subclass of Node
36 for each type of entity that QDoc can document. The types of entities that QDoc can
37 document are listed in the enum type NodeType.
38
39 After ClangCodeParser has parsed all the header files to build its precompiled header,
40 it then visits the clang Abstract Syntax Tree (AST). For each node in the AST that it
41 determines is in the public API and must be documented, it creates an instance of one
42 of the Node subclasses and adds it to the QDoc Tree.
43
44 Each instance of a sublass of Node has a parent pointer to link it into the Tree. The
45 parent pointer is obtained by calling \l {parent()}, which returns a pointer to an
46 instance of the Node subclass, Aggregate, which is never instantiated directly, but
47 as the base class for certain subclasses of Node that can have children. For example,
48 ClassNode and QmlTypeNode can have children, so they both inherit Aggregate, while
49 PropertyNode and QmlPropertyNode can not have children, so they both inherit Node.
50
51 \sa Aggregate, ClassNode, PropertyNode
52 */
53
54/*!
55 Returns \c true if the node \a n1 is less than node \a n2. The
56 comparison is performed by comparing properties of the nodes
57 in order of increasing complexity.
58 */
59bool Node::nodeNameLessThan(const Node *n1, const Node *n2)
60{
61#define LT_RETURN_IF_NOT_EQUAL(a, b)
62 if ((a) != (b))
63 return (a) < (b);
64
65 if (n1->isPageNode() && n2->isPageNode()) {
66 LT_RETURN_IF_NOT_EQUAL(n1->fullName(), n2->fullName());
67 LT_RETURN_IF_NOT_EQUAL(n1->fullTitle(), n2->fullTitle());
68 }
69
70 if (n1->isFunction() && n2->isFunction()) {
71 const auto *f1 = static_cast<const FunctionNode *>(n1);
72 const auto *f2 = static_cast<const FunctionNode *>(n2);
73
76 f2->signature(Node::SignatureReturnType));
77 }
78
80 LT_RETURN_IF_NOT_EQUAL(n1->name(), n2->name());
81 LT_RETURN_IF_NOT_EQUAL(n1->logicalModuleName(), n2->logicalModuleName());
83 LT_RETURN_IF_NOT_EQUAL(n1->location().filePath(), n2->location().filePath());
84
85 return false;
86}
87
88
89/*!
90 Returns \c true if node \a n1 is less than node \a n2 when comparing
91 the sort keys, defined with
92
93 \badcode
94 \meta sortkey {<value>}
95 \endcode
96
97 in the respective nodes' documentation. If the two sort keys are equal,
98 falls back to nodeNameLessThan(). If \a n1 defines a sort key and \a n2
99 does not, then n1 < n2.
100
101*/
102bool Node::nodeSortKeyOrNameLessThan(const Node *n1, const Node *n2)
103{
104 const QString default_sortkey{QChar{QChar::LastValidCodePoint}};
105 const auto *n1_metamap{n1->doc().metaTagMap()};
106 const auto *n2_metamap{n2->doc().metaTagMap()};
107 if (auto cmp = QString::compare(
108 n1_metamap ? n1_metamap->value(u"sortkey"_s, default_sortkey) : default_sortkey,
109 n2_metamap ? n2_metamap->value(u"sortkey"_s, default_sortkey) : default_sortkey); cmp != 0) {
110 return cmp < 0;
111 }
112 return nodeNameLessThan(n1, n2);
113}
114
115
117{
118 NodeContext context;
119 context.type = nodeType();
120 context.isPrivate = isPrivate();
121 context.isInternal = isInternal();
123
124 return context;
125}
126
127
128/*!
129 \internal
130 \fn setComparisonCategory(const ComparisonCategory category)
131
132 Sets the comparison category of this node to \a category.
133
134 \sa ComparisonCategory, comparisonCategory()
135 */
136
137/*!
138 \internal
139 \fn ComparisonCategory comparisonCategory()
140
141 Returns the comparison category of this node.
142
143 \sa ComparisonCategory, setComparisonCategory()
144 */
145
146/*!
147 \enum Access
148
149 An unsigned char value that indicates the C++ access level.
150
151 \value Public The element has public access.
152 \value Protected The element has protected access.
153 \value Private The element has private access.
154*/
155
156/*!
157 \enum Node::Status
158
159 An unsigned char that specifies the status of the documentation element in
160 the documentation set.
161
162 \value Deprecated The element has been deprecated.
163 \value Preliminary The element is new; the documentation is preliminary.
164 \value Active The element is current.
165 \value Internal The element is for internal use only, not to be published.
166 \value DontDocument The element is not to be documented.
167*/
168
169/*!
170 \enum Node::ThreadSafeness
171
172 An unsigned char that specifies the degree of thread-safeness of the element.
173
174 \value UnspecifiedSafeness The thread-safeness is not specified.
175 \value NonReentrant The element is not reentrant.
176 \value Reentrant The element is reentrant.
177 \value ThreadSafe The element is threadsafe.
178*/
179
180/*!
181 \enum Node::LinkType
182
183 An unsigned char value that probably should be moved out of the Node base class.
184
185 \value StartLink
186 \value NextLink
187 \value PreviousLink
188 \value ContentsLink
189 */
190
191/*!
192 \enum Node::FlagValue
193
194 A value used in PropertyNode and QmlPropertyNode that can be -1, 0, or +1.
195 Properties and QML properties have flags, which can be 0 or 1, false or true,
196 or not set. FlagValueDefault is the not set value. In other words, if a flag
197 is set to FlagValueDefault, the meaning is the flag has not been set.
198
199 \value FlagValueDefault -1 Not set.
200 \value FlagValueFalse 0 False.
201 \value FlagValueTrue 1 True.
202*/
203
204/*!
205 \fn Node::~Node()
206
207 The default destructor is virtual so any subclass of Node can be
208 deleted by deleting a pointer to Node.
209 */
210
211/*! \fn bool Node::isActive() const
212 Returns true if this node's status is \c Active.
213 */
214
215/*! \fn bool Node::isClass() const
216 Returns true if the node type is \c Class.
217 */
218
219/*! \fn bool Node::isCppNode() const
220 Returns true if this node's Genus value is \c CPP.
221 */
222
223/*! \fn bool Node::isDeprecated() const
224 Returns true if this node's status is \c Deprecated.
225 */
226
227/*! \fn bool Node::isDontDocument() const
228 Returns true if this node's status is \c DontDocument.
229 */
230
231/*! \fn bool Node::isEnumType() const
232 Returns true if the node type is \c Enum.
233 */
234
235/*! \fn bool Node::isExample() const
236 Returns true if the node type is \c Example.
237 */
238
239/*! \fn bool Node::isExternalPage() const
240 Returns true if the node type is \c ExternalPage.
241 */
242
243/*! \fn bool Node::isFunction(Genus g = DontCare) const
244 Returns true if this is a FunctionNode and its Genus is set to \a g.
245 */
246
247/*! \fn bool Node::isGroup() const
248 Returns true if the node type is \c Group.
249 */
250
251/*! \fn bool Node::isHeader() const
252 Returns true if the node type is \c HeaderFile.
253 */
254
255/*! \fn bool Node::isIndexNode() const
256 Returns true if this node was created from something in an index file.
257 */
258
259/*! \fn bool Node::isModule() const
260 Returns true if the node type is \c Module.
261 */
262
263/*! \fn bool Node::isNamespace() const
264 Returns true if the node type is \c Namespace.
265 */
266
267/*! \fn bool Node::isPage() const
268 Returns true if the node type is \c Page.
269 */
270
271/*! \fn bool Node::isPreliminary() const
272 Returns true if this node's status is \c Preliminary.
273 */
274
275/*! \fn bool Node::isPrivate() const
276 Returns true if this node's access is \c Private.
277 */
278
279/*! \fn bool Node::isProperty() const
280 Returns true if the node type is \c Property.
281 */
282
283/*! \fn bool Node::isProxyNode() const
284 Returns true if the node type is \c Proxy.
285 */
287/*! \fn bool Node::isPublic() const
288 Returns true if this node's access is \c Public.
289 */
290
291/*! \fn bool Node::isProtected() const
292 Returns true if this node's access is \c Protected.
293 */
294
295/*! \fn bool Node::isQmlBasicType() const
296 Returns true if the node type is \c QmlBasicType.
297 */
298
299/*! \fn bool Node::isQmlModule() const
300 Returns true if the node type is \c QmlModule.
301 */
302
303/*! \fn bool Node::isQmlNode() const
304 Returns true if this node's Genus value is \c QML.
305 */
306
307/*! \fn bool Node::isQmlProperty() const
308 Returns true if the node type is \c QmlProperty.
309 */
310
311/*! \fn bool Node::isQmlType() const
312 Returns true if the node type is \c QmlType or \c QmlValueType.
313 */
314
315/*! \fn bool Node::isRelatedNonmember() const
316 Returns true if this is a related nonmember of something.
317 */
318
319/*! \fn bool Node::isStruct() const
320 Returns true if the node type is \c Struct.
321 */
322
323/*! \fn bool Node::isSharedCommentNode() const
324 Returns true if the node type is \c SharedComment.
325 */
326
327/*! \fn bool Node::isTypeAlias() const
328 Returns true if the node type is \c Typedef.
329 */
330
331/*! \fn bool Node::isTypedef() const
332 Returns true if the node type is \c Typedef.
333 */
334
335/*! \fn bool Node::isUnion() const
336 Returns true if the node type is \c Union.
337 */
338
339/*! \fn bool Node::isVariable() const
340 Returns true if the node type is \c Variable.
341 */
342
343/*! \fn bool Node::isGenericCollection() const
344 Returns true if the node type is \c Collection.
345 */
346
347/*! \fn bool Node::isAbstract() const
348 Returns true if the ClassNode or QmlTypeNode is marked abstract.
349*/
350
351/*! \fn bool Node::isAggregate() const
352 Returns true if this node is an aggregate, which means it
353 inherits Aggregate and can therefore have children.
354*/
355
356/*! \fn bool Node::isFirstClassAggregate() const
357 Returns true if this Node is an Aggregate but not a ProxyNode.
358*/
359
360/*! \fn bool Node::isAlias() const
361 Returns true if this QML property is marked as an alias.
362*/
363
364/*! \fn bool Node::isAttached() const
365 Returns true if the QML property or QML method node is marked as attached.
366*/
367
368/*! \fn bool Node::isClassNode() const
369 Returns true if this is an instance of ClassNode.
370*/
371
372/*! \fn bool Node::isCollectionNode() const
373 Returns true if this is an instance of CollectionNode.
374*/
375
376/*! \fn bool Node::isDefault() const
377 Returns true if the QML property node is marked as default.
378*/
379
380/*! \fn bool Node::isMacro() const
381 returns true if either FunctionNode::isMacroWithParams() or
382 FunctionNode::isMacroWithoutParams() returns true.
383*/
384
385/*! \fn bool Node::isPageNode() const
386 Returns true if this node represents something that generates a documentation
387 page. In other words, if this Node's subclass inherits PageNode, then this
388 function will return \e true.
389*/
390
391/*! \fn bool Node::isRelatableType() const
392 Returns true if this node is something you can relate things to with
393 the \e relates command. NamespaceNode, ClassNode, HeaderNode, and
394 ProxyNode are relatable types.
395*/
396
397/*! \fn bool Node::isMarkedReimp() const
398 Returns true if the FunctionNode is marked as a reimplemented function.
399 That means it is virtual in the base class and it is reimplemented in
400 the subclass.
401*/
402
403/*! \fn bool Node::isPropertyGroup() const
404 Returns true if the node is a SharedCommentNode for documenting
405 multiple C++ properties or multiple QML properties.
406*/
407
408/*! \fn bool Node::isStatic() const
409 Returns true if the FunctionNode represents a static function.
410*/
411
412/*! \fn bool Node::isTextPageNode() const
413 Returns true if the node is a PageNode but not an Aggregate.
414*/
415
416/*!
417 Returns this node's name member. Appends "()" to the returned
418 name if this node is a function node, but not if it is a macro
419 because macro names normally appear without parentheses.
420 */
422{
423 if (isFunction() && !isMacro())
424 return m_name + QLatin1String("()");
425 return m_name;
426}
427
428/*!
429 Constructs and returns the node's fully qualified name by
430 recursively ascending the parent links and prepending each
431 parent name + "::". Breaks out when reaching a HeaderNode,
432 or when the parent pointer is \a relative. Typically, calls
433 to this function pass \c nullptr for \a relative.
434 */
435QString Node::plainFullName(const Node *relative) const
436{
437 if (m_name.isEmpty())
438 return QLatin1String("global");
439 if (isHeader())
440 return plainName();
441
442 QStringList parts;
443 const Node *node = this;
444 while (node && !node->isHeader()) {
445 parts.prepend(node->plainName());
446 if (node->parent() == relative || node->parent()->name().isEmpty())
447 break;
448 node = node->parent();
449 }
450 return parts.join(QLatin1String("::"));
451}
452
453/*!
454 Constructs and returns the node's fully qualified signature
455 by recursively ascending the parent links and prepending each
456 parent name + "::" to the plain signature. The return type is
457 not included.
458 */
460{
461 if (m_name.isEmpty())
462 return QLatin1String("global");
463
464 QString fullName;
465 const Node *node = this;
466 while (node) {
467 fullName.prepend(node->signature(Node::SignaturePlain));
468 if (node->parent()->name().isEmpty())
469 break;
470 fullName.prepend(QLatin1String("::"));
471 node = node->parent();
472 }
473 return fullName;
474}
475
476/*!
477 Constructs and returns this node's full name. The full name is
478 often just the title(). When it is not the title, it is the
479 plainFullName().
480 */
481QString Node::fullName(const Node *relative) const
482{
483 if ((isTextPageNode() || isGroup()) && !title().isEmpty())
484 return title();
485 return plainFullName(relative);
486}
487
488/*!
489 Sets this Node's Doc to \a doc. If \a replace is false and
490 this Node already has a Doc, and if this doc is not marked
491 with the \\reimp command, a warning is reported that the
492 existing Doc is being overridden, and it reports where the
493 previous Doc was found. If \a replace is true, the Doc is
494 replaced silently.
495 */
496void Node::setDoc(const Doc &doc, bool replace)
497{
498 if (!m_doc.isEmpty() && !replace && !doc.isMarkedReimp()) {
499 doc.location().warning(QStringLiteral("Overrides a previous doc"),
500 QStringLiteral("from here: %1").arg(m_doc.location().toString()));
501 }
502 m_doc = doc;
503}
504
505/*!
506 Sets the node's status to \a t.
507
508 \sa Status
509*/
511{
512 m_status = t;
513
514 // Set non-null, empty URL to nodes that are ignored as
515 // link targets
516 switch (t) {
517 case Internal: {
518 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
520 break;
521 Q_FALLTHROUGH();
522 }
523 case DontDocument:
524 m_url = QStringLiteral("");
525 break;
526 default:
527 break;
528 }
529}
530
531/*!
532 Construct a node with the given \a type and having the
533 given \a parent and \a name. The new node is added to the
534 parent's child list.
535 */
536Node::Node(NodeType type, Aggregate *parent, QString name)
537 : m_nodeType(type),
538 m_indexNodeFlag(false),
539 m_relatedNonmember(false),
540 m_hadDoc(false),
541 m_parent(parent),
543{
544 if (m_parent)
545 m_parent->addChild(this);
546
548}
549
550/*!
551 Determines the appropriate Genus value for the NodeType
552 value \a t and returns that Genus value. Note that this
553 function is called in the Node() constructor. It always
554 returns Node::CPP when \a t is Node::Function, which
555 means the FunctionNode() constructor must determine its
556 own Genus value separately, because class FunctionNode
557 is a subclass of Node.
558 */
560{
561 switch (t) {
562 case NodeType::Enum:
563 case NodeType::Class:
564 case NodeType::Struct:
565 case NodeType::Union:
566 case NodeType::Module:
574 return Genus::CPP;
580 return Genus::QML;
581 case NodeType::Page:
582 case NodeType::Group:
585 return Genus::DOC;
588 case NodeType::Proxy:
589 default:
590 return Genus::DontCare;
591 }
592}
593
594/*! \fn QString Node::url() const
595 Returns the node's URL, which is the url of the documentation page
596 created for the node or the url of an external page if the node is
597 an ExternalPageNode. The url is used for generating a link to the
598 page the node represents.
599
600 \sa Node::setUrl()
601 */
602
603/*! \fn void Node::setUrl(const QString &url)
604 Sets the node's URL to \a url, which is the url to the page that the
605 node represents. This function is only called when an index file is
606 read. In other words, a node's url is set when qdoc decides where its
607 page will be and what its name will be, which happens when qdoc writes
608 the index file for the module being documented.
609
610 \sa QDocIndexFiles
611 */
612
613/*!
614 Returns this node's type as a string for use as an
615 attribute value in XML or HTML.
616 */
618{
619 if (isFunction()) {
620 const auto *fn = static_cast<const FunctionNode *>(this);
621 return fn->kindString();
622 }
623 return nodeTypeString(nodeType());
624}
625
626/*!
627 Returns the node type \a t as a string for use as an
628 attribute value in XML or HTML.
629 */
630QString Node::nodeTypeString(NodeType t)
631{
632 switch (t) {
634 return QLatin1String("namespace");
635 case NodeType::Class:
636 return QLatin1String("class");
637 case NodeType::Struct:
638 return QLatin1String("struct");
639 case NodeType::Union:
640 return QLatin1String("union");
642 return QLatin1String("header");
643 case NodeType::Page:
644 return QLatin1String("page");
645 case NodeType::Enum:
646 return QLatin1String("enum");
648 return QLatin1String("example");
650 return QLatin1String("external page");
653 return QLatin1String("typedef");
655 return QLatin1String("function");
657 return QLatin1String("property");
658 case NodeType::Proxy:
659 return QLatin1String("proxy");
661 return QLatin1String("variable");
662 case NodeType::Group:
663 return QLatin1String("group");
664 case NodeType::Module:
665 return QLatin1String("module");
666
668 return QLatin1String("QML type");
670 return QLatin1String("QML value type");
672 return QLatin1String("QML module");
674 return QLatin1String("QML property");
675
677 return QLatin1String("shared comment");
679 return QLatin1String("collection");
680 default:
681 break;
682 }
683 return QString();
684}
685
686/*! Converts the boolean value \a b to an enum representation
687 of the boolean type, which includes an enum value for the
688 \e {default value} of the item, i.e. true, false, or default.
689 */
691{
692 return b ? FlagValueTrue : FlagValueFalse;
693}
694
695/*!
696 Converts the enum \a fv back to a boolean value.
697 If \a fv is neither the true enum value nor the
698 false enum value, the boolean value returned is
699 \a defaultValue.
700 */
701bool Node::fromFlagValue(FlagValue fv, bool defaultValue)
702{
703 switch (fv) {
704 case FlagValueTrue:
705 return true;
706 case FlagValueFalse:
707 return false;
708 default:
709 return defaultValue;
710 }
711}
712
713/*!
714 This function creates a pair that describes a link.
715 The pair is composed from \a link and \a desc. The
716 \a linkType is the map index the pair is filed under.
717 */
718void Node::setLink(LinkType linkType, const QString &link, const QString &desc)
719{
720 std::pair<QString, QString> linkPair;
721 linkPair.first = std::move(link);
722 linkPair.second = std::move(desc);
723 m_linkMap[linkType] = std::move(linkPair);
724}
725
726/*!
727 Sets the information about the project and version a node was introduced
728 in, unless the version is lower than the 'ignoresince.<project>'
729 configuration variable.
730 */
731void Node::setSince(const QString &since)
732{
733 QStringList parts = since.split(QLatin1Char(' '));
734 QString project;
735 if (parts.size() > 1)
736 project = Config::dot + parts.first();
737
738 QVersionNumber cutoff =
739 QVersionNumber::fromString(Config::instance().get(CONFIG_IGNORESINCE + project).asString())
740 .normalized();
741
742 if (!cutoff.isNull() && QVersionNumber::fromString(parts.last()).normalized() < cutoff)
743 return;
744
745 m_since = parts.join(QLatin1Char(' '));
746}
747
748/*!
749 Extract a class name from the type \a string and return it.
750 */
751QString Node::extractClassName(const QString &string) const
752{
753 QString result;
754 for (int i = 0; i <= string.size(); ++i) {
755 QChar ch;
756 if (i != string.size())
757 ch = string.at(i);
758
759 QChar lower = ch.toLower();
760 if ((lower >= QLatin1Char('a') && lower <= QLatin1Char('z')) || ch.digitValue() >= 0
761 || ch == QLatin1Char('_') || ch == QLatin1Char(':')) {
762 result += ch;
763 } else if (!result.isEmpty()) {
764 if (result != QLatin1String("const"))
765 return result;
766 result.clear();
767 }
768 }
769 return result;
770}
771
772/*!
773 Returns the thread safeness value for whatever this node
774 represents. But if this node has a parent and the thread
775 safeness value of the parent is the same as the thread
776 safeness value of this node, what is returned is the
777 value \c{UnspecifiedSafeness}. Why?
778 */
780{
781 if (m_parent && m_safeness == m_parent->inheritedThreadSafeness())
782 return UnspecifiedSafeness;
783 return m_safeness;
784}
785
786/*!
787 If this node has a parent, the parent's thread safeness
788 value is returned. Otherwise, this node's thread safeness
789 value is returned. Why?
790 */
792{
793 if (m_parent && m_safeness == UnspecifiedSafeness)
794 return m_parent->inheritedThreadSafeness();
795 return m_safeness;
796}
797
798/*!
799 Returns \c true if the node's status is \c Internal, or if
800 its parent is a class with \c Internal status.
801 */
802bool Node::isInternal() const
803{
804 if (status() == Internal)
805 return true;
807}
808
809/*! \fn void Node::markInternal()
810 Sets the node's access to Private and its status to Internal.
811 */
812
813/*!
814 Returns a pointer to the root of the Tree this node is in.
815 */
816Aggregate *Node::root() const
817{
818 if (parent() == nullptr)
819 return (this->isAggregate() ? static_cast<Aggregate *>(const_cast<Node *>(this)) : nullptr);
820 Aggregate *t = parent();
821 while (t->parent() != nullptr)
822 t = t->parent();
823 return t;
824}
825
826/*!
827 Returns a pointer to the Tree this node is in.
828 */
829Tree *Node::tree() const
830{
831 return root()->tree();
832}
833
834/*!
835 Sets the node's declaration location, its definition
836 location, or both, depending on the suffix of the file
837 name from the file path in location \a t.
838 */
839void Node::setLocation(const Location &t)
840{
841 QString suffix = t.fileSuffix();
842 if (suffix == "h")
843 m_declLocation = t;
844 else if (suffix == "cpp")
845 m_defLocation = t;
846 else {
847 m_declLocation = t;
848 m_defLocation = t;
849 }
850}
851
852/*!
853 Returns \c true if this node is documented, or it represents
854 a documented node read from the index ('had doc'), or this
855 node is sharing a non-empty doc with other nodes.
856
857 \sa Doc
858 */
859bool Node::hasDoc() const
860{
861 if (m_hadDoc)
862 return true;
863
864 if (!m_doc.isEmpty())
865 return true;
866
867 return (m_sharedCommentNode && m_sharedCommentNode->hasDoc());
868}
869
870/*!
871 Returns the CPP node's qualified name by prepending the
872 namespaces name + "::" if there isw a namespace.
873 */
875{
876 if (m_parent && m_parent->isNamespace() && !m_parent->name().isEmpty())
877 return m_parent->name() + "::" + m_name;
878 return m_name;
879}
880
881/*!
882 Return the name of this node qualified with the parent name
883 and "::" if there is a parent name.
884 */
886{
887 if (m_parent && !m_parent->name().isEmpty())
888 return m_parent->name() + "::" + m_name;
889 return m_name;
890}
891
892/*!
893 Returns the QML node's qualified name by prepending the logical
894 module name.
895 */
897{
898 return logicalModuleName() + "::" + m_name;
899}
900
901/*!
902 Returns \c true if the node is a class node or a QML type node
903 that is marked as being a wrapper class or wrapper QML type,
904 or if it is a member of a wrapper class or type.
905 */
906bool Node::isWrapper() const
907{
908 return m_parent != nullptr && m_parent->isWrapper();
909}
910
911/*!
912 Construct the full document name for this node and return it.
913 */
915{
916 QStringList pieces;
917 const Node *n = this;
918
919 do {
920 if (!n->name().isEmpty())
921 pieces.insert(0, n->name());
922
923 if (n->isQmlType() && !n->logicalModuleName().isEmpty()) {
924 pieces.insert(0, n->logicalModuleName());
925 break;
926 }
927
929 break;
930
931 // Examine the parent if the node is a member
933 break;
934
935 n = n->parent();
936 } while (true);
937
938 // Create a name based on the type of the ancestor node.
939 QString concatenator = "::";
940 if (n->isQmlType())
941 concatenator = QLatin1Char('.');
942
944 concatenator = QLatin1Char('#');
945
946 return pieces.join(concatenator);
947}
948
949/*!
950 Sets the Node status to Node::Deprecated, unless \a sinceVersion represents
951 a future version.
952
953 Stores \a sinceVersion representing the version in which the deprecation
954 took (or will take) place.
955
956 Fetches the current version from the config ('version' variable) as a
957 string, and compared to \a sinceVersion. If both string represent a valid
958 version and \a sinceVersion is greater than the currect version, do not
959 mark the node as deprecated; leave it active.
960*/
961void Node::setDeprecated(const QString &sinceVersion)
962{
963
964 if (!m_deprecatedSince.isEmpty())
965 qCWarning(lcQdoc) << QStringLiteral(
966 "Setting deprecated since version for %1 to %2 even though it "
967 "was already set to %3. This is very unexpected.")
968 .arg(this->m_name, sinceVersion, this->m_deprecatedSince);
969 m_deprecatedSince = sinceVersion;
970
971 if (!sinceVersion.isEmpty()) {
972 QVersionNumber since = QVersionNumber::fromString(sinceVersion).normalized();
973 QVersionNumber current = QVersionNumber::fromString(
974 Config::instance().get(CONFIG_VERSION).asString())
975 .normalized();
976 if (!current.isNull() && !since.isNull()) {
977 if (current < since)
978 return;
979 }
980 }
982}
983
984/*! \fn Node *Node::clone(Aggregate *parent)
985
986 When reimplemented in a subclass, this function creates a
987 clone of this node on the heap and makes the clone a child
988 of \a parent. A pointer to the clone is returned.
989
990 Here in the base class, this function does nothing and returns
991 nullptr.
992 */
993
994/*! \fn NodeType Node::nodeType() const
995 Returns this node's type.
996
997 \sa NodeType
998*/
999
1000/*! \fn Genus Node::genus() const
1001 Returns this node's Genus.
1002
1003 \sa Genus
1004*/
1005
1006/*! void Node::setGenus(Genus t)
1007 Sets this node's Genus to \a t.
1008*/
1009
1010/*! \fn QString Node::signature(Node::SignatureOptions options) const
1011
1012 Specific parts of the signature are included according to flags in
1013 \a options.
1014
1015 If this node is not a FunctionNode, this function returns plainName().
1016
1017 \sa FunctionNode::signature()
1018*/
1019
1020/*! \fn const QString &Node::fileNameBase() const
1021 Returns the node's file name base string, which is built once, when
1022 Generator::fileBase() is called and stored in the Node.
1023*/
1024
1025/*! \fn bool Node::hasFileNameBase() const
1026 Returns true if the node's file name base has been set.
1027
1028 \sa Node::fileNameBase()
1029*/
1030
1031/*! \fn void Node::setFileNameBase(const QString &t)
1032 Sets the node's file name base to \a t. Only called by
1033 Generator::fileBase().
1034*/
1035
1036/*! \fn void Node::setAccess(Access t)
1037 Sets the node's access type to \a t.
1038
1039 \sa Access
1040*/
1041
1042/*! \fn void Node::setThreadSafeness(ThreadSafeness t)
1043 Sets the node's thread safeness to \a t.
1044
1045 \sa ThreadSafeness
1046*/
1047
1048/*! \fn void Node::setPhysicalModuleName(const QString &name)
1049 Sets the node's physical module \a name.
1050*/
1051
1052/*! \fn void Node::setReconstitutedBrief(const QString &t)
1053 When reading an index file, this function is called with the
1054 reconstituted brief clause \a t to set the node's brief clause.
1055 I think this is needed for linking to something in the brief clause.
1056*/
1057
1058/*! \fn void Node::setParent(Aggregate *n)
1059 Sets the node's parent pointer to \a n. Such a thing
1060 is not lightly done. All the calls to this function
1061 are in other member functions of Node subclasses. See
1062 the code in the subclass implementations to understand
1063 when this function can be called safely and why it is called.
1064*/
1065
1066/*! \fn void Node::setIndexNodeFlag(bool isIndexNode = true)
1067 Sets a flag in this Node that indicates the node was created
1068 for something in an index file. This is important to know
1069 because an index node is not to be documented in the current
1070 module. When the index flag is set, it means the Node
1071 represents something in another module, and it will be
1072 documented in that module's documentation.
1073*/
1074
1075/*! \fn void Node::setRelatedNonmember(bool b)
1076 Sets a flag in the node indicating whether this node is a related nonmember
1077 of something. This function is called when the \c relates command is seen.
1078 */
1079
1080/*! \fn void Node::addMember(Node *node)
1081 In a CollectionNode, this function adds \a node to the collection
1082 node's members list. It does nothing if this node is not a CollectionNode.
1083 */
1084
1085/*! \fn bool Node::hasNamespaces() const
1086 Returns \c true if this is a CollectionNode and its members list
1087 contains namespace nodes. Otherwise it returns \c false.
1088 */
1089
1090/*! \fn bool Node::hasClasses() const
1091 Returns \c true if this is a CollectionNode and its members list
1092 contains class nodes. Otherwise it returns \c false.
1093 */
1094
1095/*! \fn void Node::setAbstract(bool b)
1096 If this node is a ClassNode or a QmlTypeNode, the node's abstract flag
1097 data member is set to \a b.
1098 */
1099
1100/*! \fn void Node::setWrapper()
1101 If this node is a ClassNode or a QmlTypeNode, the node's wrapper flag
1102 data member is set to \c true.
1103 */
1104
1105/*! \fn void Node::setDataType(const QString &dataType)
1106 If this node is a PropertyNode or a QmlPropertyNode, its
1107 data type data member is set to \a dataType. Otherwise,
1108 this function does nothing.
1109 */
1110
1111/*! \fn bool Node::wasSeen() const
1112 Returns the \c seen flag data member of this node if it is a NamespaceNode
1113 or a CollectionNode. Otherwise it returns \c false. If \c true is returned,
1114 it means that the location where the namespace or collection is to be
1115 documented has been found.
1116 */
1117
1118/*! \fn void appendGroupName(const QString &t)
1119 If this node is a PageNode, the group name \a t is appended to the node's
1120 list of group names. It is not clear to me what this list of group names
1121 is used for, but it is written to the index file, and it is used in the
1122 navigation bar.
1123 */
1124
1125/*! \fn QString Node::element() const
1126 If this node is a QmlPropertyNode or a FunctionNode, this function
1127 returns the name of the parent node. Otherwise it returns an empty
1128 string.
1129 */
1130
1131/*! \fn bool Node::docMustBeGenerated() const
1132 This function is called to perform a test to decide if the node must have
1133 documentation generated. In the Node base class, it always returns \c false.
1134
1135 In the ProxyNode class it always returns \c true. There aren't many proxy
1136 nodes, but when one appears, it must generate documentation. In the overrides
1137 in NamespaceNode and ClassNode, a meaningful test is performed to decide if
1138 documentation must be generated.
1139 */
1140
1141/*! \fn QString Node::title() const
1142 Returns a string that can be used to print a title in the documentation for
1143 whatever this Node is. In the Node base class, the node's name() is returned.
1144 In a PageNode, the function returns the title data member. In a HeaderNode,
1145 if the title() is empty, the name() is returned.
1146 */
1147
1148/*! \fn QString Node::subtitle() const { return QString(); }
1149 Returns a string that can be used to print a subtitle in the documentation for
1150 whatever this Node is. In the Node base class, the empty string is returned.
1151 In a PageNode, the function returns the subtitle data member. In a HeaderNode,
1152 the subtitle data member is returned.
1153 */
1154
1155/*! \fn QString Node::fullTitle() const
1156 Returns a string that can be used as the full title for the documentation of
1157 this node. In this base class, the name() is returned. In a PageNode, title()
1158 is returned. In a HeaderNode, if the title() is empty, the name() is returned.
1159 If the title() is not empty then name-title is returned. In a CollectionNode,
1160 the title() is returned.
1161 */
1162
1163/*! \fn bool Node::setTitle(const QString &title)
1164 Sets the node's \a title, which is used for the title of
1165 the documentation page, if one is generated for this node.
1166 Returns \c true if the title is set. In this base class,
1167 there is no title string stored, so in the base class,
1168 nothing happens and \c false is returned. The override in
1169 the PageNode class is where the title is set.
1170 */
1171
1172/*! \fn bool Node::setSubtitle(const QString &subtitle)
1173 Sets the node's \a subtitle, which is used for the subtitle
1174 of the documentation page, if one is generated for this node.
1175 Returns \c true if the subtitle is set. In this base class,
1176 there is no subtitle string stored, so in the base class,
1177 nothing happens and \c false is returned. The override in
1178 the PageNode and HeaderNode classes is where the subtitle is
1179 set.
1180 */
1181
1182/*! \fn void Node::markDefault()
1183 If this node is a QmlPropertyNode, it is marked as the default property.
1184 Otherwise the function does nothing.
1185 */
1186
1187/*! \fn void Node::markReadOnly(bool flag)
1188 If this node is a QmlPropertyNode, then the property's read-only
1189 flag is set to \a flag.
1190 */
1191
1192/*! \fn Aggregate *Node::parent() const
1193 Returns the node's parent pointer.
1194*/
1195
1196/*! \fn const QString &Node::name() const
1197 Returns the node's name data member.
1198*/
1199
1200/*! \fn void Node::setQtVariable(const QString &v)
1201 If this node is a CollectionNode, its QT variable is set to \a v.
1202 Otherwise the function does nothing. I don't know what the QT variable
1203 is used for.
1204 */
1205
1206/*! \fn QString Node::qtVariable() const
1207 If this node is a CollectionNode, its QT variable is returned.
1208 Otherwise an empty string is returned. I don't know what the QT
1209 variable is used for.
1210 */
1211
1212/*! \fn bool Node::hasTag(const QString &t) const
1213 If this node is a FunctionNode, the function returns \c true if
1214 the function has the tag \a t. Otherwise the function returns
1215 \c false. I don't know what the tag is used for.
1216 */
1217
1218/*! \fn const QMap<LinkType, std::pair<QString, QString> > &Node::links() const
1219 Returns a reference to this node's link map. The link map should
1220 probably be moved to the PageNode, because it contains links to the
1221 start page, next page, previous page, and contents page, and these
1222 are only used in PageNode, I think.
1223 */
1224
1225/*! \fn Access Node::access() const
1226 Returns the node's Access setting, which can be \c Public,
1227 \c Protected, or \c Private.
1228 */
1229
1230/*! \fn const Location& Node::declLocation() const
1231 Returns the Location where this node's declaration was seen.
1232 Normally the declaration location is in an \e include file.
1233 The declaration location is used in qdoc error/warning messages
1234 about the declaration.
1235 */
1236
1237/*! \fn const Location& Node::defLocation() const
1238 Returns the Location where this node's dedefinition was seen.
1239 Normally the definition location is in a \e .cpp file.
1240 The definition location is used in qdoc error/warning messages
1241 when the error is discovered at the location of the definition,
1242 although the way to correct the problem often requires changing
1243 the declaration.
1244 */
1245
1246/*! \fn const Location& Node::location() const
1247 If this node's definition location is empty, this function
1248 returns this node's declaration location. Otherwise it
1249 returns the definition location.
1250
1251 \sa Location
1252 */
1253
1254/*! \fn const Doc &Node::doc() const
1255 Returns a reference to the node's Doc data member.
1256
1257 \sa Doc
1258 */
1259
1260/*! \fn Status Node::status() const
1261 Returns the node's status value.
1262
1263 \sa Status
1264 */
1265
1266/*! \fn QString Node::since() const
1267 Returns the node's since string, which can be empty.
1268 */
1269
1270/*! \fn QString Node::templateStuff() const
1271 Returns the node's template parameters string, if this node
1272 represents a templated element.
1273 */
1274
1275/*! \fn bool Node::isSharingComment() const
1276 This function returns \c true if the node is sharing a comment
1277 with other nodes. For example, multiple functions can be documented
1278 with a single qdoc comment by listing the \c {\\fn} signatures for
1279 all the functions in the single qdoc comment.
1280 */
1281
1282/*! \fn QString Node::qmlTypeName() const
1283 If this is a QmlPropertyNode or a FunctionNode representing a QML
1284 method, this function returns the qmlTypeName() of
1285 the parent() node. Otherwise it returns the name data member.
1286 */
1287
1288/*! \fn QString Node::qmlFullBaseName() const
1289 If this is a QmlTypeNode, this function returns the QML full
1290 base name. Otherwise it returns an empty string.
1291 */
1292
1293/*! \fn QString Node::logicalModuleName() const
1294 If this is a CollectionNode, this function returns the logical
1295 module name. Otherwise it returns an empty string.
1296 */
1297
1298/*! \fn QString Node::logicalModuleVersion() const
1299 If this is a CollectionNode, this function returns the logical
1300 module version number. Otherwise it returns an empty string.
1301 */
1302
1303/*! \fn QString Node::logicalModuleIdentifier() const
1304 If this is a CollectionNode, this function returns the logical
1305 module identifier. Otherwise it returns an empty string.
1306 */
1307
1308/*! \fn void Node::setLogicalModuleInfo(const QString &arg)
1309 If this node is a CollectionNode, this function splits \a arg
1310 on the blank character to get a logical module name and version
1311 number. If the version number is present, it splits the version
1312 number on the '.' character to get a major version number and a
1313 minor version number. If the version number is present, both the
1314 major and minor version numbers should be there, but the minor
1315 version number is not absolutely necessary.
1316
1317 The strings are stored in the appropriate data members for use
1318 when the QML module page is generated.
1319 */
1320
1321/*! \fn void Node::setLogicalModuleInfo(const QStringList &info)
1322 If this node is a CollectionNode, this function accepts the
1323 logical module \a info as a string list. If the logical module
1324 info contains the version number, it splits the version number
1325 on the '.' character to get the major and minor version numbers.
1326 Both major and minor version numbers should be provided, but
1327 the minor version number is not strictly necessary.
1328
1329 The strings are stored in the appropriate data members for use
1330 when the QML module page is generated. This overload
1331 of the function is called when qdoc is reading an index file.
1332 */
1333
1334/*! \fn CollectionNode *Node::logicalModule() const
1335 If this is a QmlTypeNode, a pointer to its QML module is returned,
1336 which is a pointer to a CollectionNode. Otherwise the \c nullptr
1337 is returned.
1338 */
1339
1340/*! \fn void Node::setQmlModule(CollectionNode *t)
1341 If this is a QmlTypeNode, this function sets the QML type's QML module
1342 pointer to the CollectionNode \a t. Otherwise the function does nothing.
1343 */
1344
1345/*! \fn ClassNode *Node::classNode()
1346 If this is a QmlTypeNode, this function returns the pointer to
1347 the C++ ClassNode that this QML type represents. Otherwise the
1348 \c nullptr is returned.
1349 */
1350
1351/*! \fn void Node::setClassNode(ClassNode *cn)
1352 If this is a QmlTypeNode, this function sets the C++ class node
1353 to \a cn. The C++ ClassNode is the C++ implementation of the QML
1354 type.
1355 */
1356
1357/*! \fn NodeType Node::goal(const QString &t)
1358 When a square-bracket parameter is used in a qdoc command, this
1359 function might be called to convert the text string \a t obtained
1360 from inside the square brackets to be a Goal value, which is returned.
1361
1362 \sa Goal
1363 */
1364
1365QT_END_NAMESPACE
void addChild(Node *child)
Adds the child to this node's child list and sets the child's parent pointer to this Aggregate.
Definition doc.h:31
const Location & location() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:90
Doc & operator=(const Doc &doc)
Definition doc.cpp:75
bool isMarkedReimp() const
Returns true if the set of metacommands used in the doc comment contains {reimp}.
Definition doc.cpp:228
QStringMultiMap * metaTagMap() const
Definition doc.cpp:300
bool isEmpty() const
Definition doc.cpp:110
This node is used to represent any kind of function being documented.
bool isConst() const
static bool processInternalDocs(const InclusionPolicy &policy)
The Location class provides a way to mark a location in a file.
Definition location.h:20
This class constructs and maintains a tree of instances of the subclasses of Node.
Definition tree.h:57
#define CONFIG_VERSION
Definition config.h:427
#define CONFIG_IGNORESINCE
Definition config.h:378
NodeType
Definition genustypes.h:150
@ SharedComment
Definition genustypes.h:173
#define LT_RETURN_IF_NOT_EQUAL(a, b)
bool isInternal
Definition nodecontext.h:18
bool isPureVirtual
Definition nodecontext.h:19
NodeType type
Definition nodecontext.h:16
The Node class is the base class for all the nodes in QDoc's parse tree.
virtual QString plainName() const
Returns this node's name member.
Definition node.cpp:421
const Doc & doc() const
Returns a reference to the node's Doc data member.
Definition node.h:242
void setGenus(Genus t)
Definition node.h:93
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:906
bool isPrivate() const
Returns true if this node's access is Private.
Definition node.h:118
virtual bool isAbstract() const
Returns true if the ClassNode or QmlTypeNode is marked abstract.
Definition node.h:142
QString nodeTypeString() const
Returns this node's type as a string for use as an attribute value in XML or HTML.
Definition node.cpp:617
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
Definition node.h:128
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:802
bool isHeader() const
Returns true if the node type is HeaderFile.
Definition node.h:112
NodeType nodeType() const override
Returns this node's type.
Definition node.h:89
virtual bool isPageNode() const
Returns true if this node represents something that generates a documentation page.
Definition node.h:155
virtual Status status() const
Returns the node's status value.
Definition node.h:249
virtual bool isTextPageNode() const
Returns true if the node is a PageNode but not an Aggregate.
Definition node.h:160
Aggregate * parent() const
Returns the node's parent pointer.
Definition node.h:215
static bool fromFlagValue(FlagValue fv, bool defaultValue)
Converts the enum fv back to a boolean value.
Definition node.cpp:701
void setLocation(const Location &t)
Sets the node's declaration location, its definition location, or both, depending on the suffix of th...
Definition node.cpp:839
QString plainFullName(const Node *relative=nullptr) const
Constructs and returns the node's fully qualified name by recursively ascending the parent links and ...
Definition node.cpp:435
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:143
FlagValue
A value used in PropertyNode and QmlPropertyNode that can be -1, 0, or +1.
Definition node.h:82
@ FlagValueTrue
Definition node.h:82
@ FlagValueFalse
Definition node.h:82
QString qualifyQmlName()
Returns the QML node's qualified name by prepending the logical module name.
Definition node.cpp:896
static bool nodeNameLessThan(const Node *first, const Node *second)
Returns true if the node n1 is less than node n2.
Definition node.cpp:59
QString qualifyCppName()
Returns the CPP node's qualified name by prepending the namespaces name + "::" if there isw a namespa...
Definition node.cpp:874
ThreadSafeness inheritedThreadSafeness() const
If this node has a parent, the parent's thread safeness value is returned.
Definition node.cpp:791
const Location & location() const
If this node's definition location is empty, this function returns this node's declaration location.
Definition node.h:238
Access access() const
Returns the node's Access setting, which can be Public, Protected, or Private.
Definition node.h:235
bool isFunction(Genus g=Genus::DontCare) const
Returns true if this is a FunctionNode and its Genus is set to g.
Definition node.h:107
ThreadSafeness threadSafeness() const
Returns the thread safeness value for whatever this node represents.
Definition node.cpp:779
Aggregate * root() const
QString fullDocumentName() const
Construct the full document name for this node and return it.
Definition node.cpp:914
virtual Tree * tree() const
Returns a pointer to the Tree this node is in.
Definition node.cpp:829
NodeContext createContext() const
Definition node.cpp:116
void setDoc(const Doc &doc, bool replace=false)
Sets this Node's Doc to doc.
Definition node.cpp:496
Node(NodeType type, Aggregate *parent, QString name)
Construct a node with the given type and having the given parent and name.
Definition node.cpp:536
ThreadSafeness
An unsigned char that specifies the degree of thread-safeness of the element.
Definition node.h:65
@ UnspecifiedSafeness
Definition node.h:66
QString fullName(const Node *relative) const
Constructs and returns this node's full name.
Definition node.cpp:481
virtual bool isPureVirtual() const
Definition node.h:123
bool hasDoc() const
Returns true if this node is documented, or it represents a documented node read from the index ('had...
Definition node.cpp:859
static Genus getGenus(NodeType t)
Determines the appropriate Genus value for the NodeType value t and returns that Genus value.
Definition node.cpp:559
static FlagValue toFlagValue(bool b)
Converts the boolean value b to an enum representation of the boolean type, which includes an enum va...
Definition node.cpp:690
bool isRelatedNonmember() const
Returns true if this is a related nonmember of something.
Definition node.h:129
void setSince(const QString &since)
Sets the information about the project and version a node was introduced in, unless the version is lo...
Definition node.cpp:731
void setStatus(Status t)
Sets the node's status to t.
Definition node.cpp:510
QString extractClassName(const QString &string) const
Extract a class name from the type string and return it.
Definition node.cpp:751
void setDeprecated(const QString &sinceVersion)
Sets the Node status to Node::Deprecated, unless sinceVersion represents a future version.
Definition node.cpp:961
static bool nodeSortKeyOrNameLessThan(const Node *n1, const Node *n2)
Returns true if node n1 is less than node n2 when comparing the sort keys, defined with.
Definition node.cpp:102
Status
An unsigned char that specifies the status of the documentation element in the documentation set.
Definition node.h:57
@ Internal
Definition node.h:61
@ Deprecated
Definition node.h:58
@ SignatureReturnType
Definition node.h:75
@ SignaturePlain
Definition node.h:73
QString qualifyWithParentName()
Return the name of this node qualified with the parent name and "::" if there is a parent name.
Definition node.cpp:885
QString plainSignature() const
Constructs and returns the node's fully qualified signature by recursively ascending the parent links...
Definition node.cpp:459