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#ifndef TREE_H
5#define TREE_H
6
7#include "examplenode.h"
8#include "namespacenode.h"
9#include "node.h"
10#include "propertynode.h"
11#include "proxynode.h"
12#include "qmltypenode.h"
13
14#include <QtCore/qstack.h>
15
16#include <utility>
17
18QT_BEGIN_NAMESPACE
19
20class CollectionNode;
21class FunctionNode;
22class QDocDatabase;
23
24struct TargetRec
25{
26public:
27 enum TargetType { Unknown, Target, Keyword, Contents, Class, Function, Page, Subtitle };
28
29 TargetRec(QString name, TargetRec::TargetType type, Node *node, int priority)
30 : m_node(node), m_ref(std::move(name)), m_type(type), m_priority(priority)
31 {
32 // Discard the dedicated ref for keywords - they always
33 // link to the top of the QDoc comment they appear in
34 if (type == Keyword)
35 m_ref.clear();
36 }
37
38 [[nodiscard]] bool isEmpty() const { return m_ref.isEmpty(); }
39 [[nodiscard]] Node::Genus genus() const { return (m_node ? m_node->genus() : Node::DontCare); }
40
41 Node *m_node { nullptr };
42 QString m_ref {};
43 TargetType m_type {};
44 int m_priority {};
45};
46
47typedef QMultiMap<QString, TargetRec *> TargetMap;
48typedef QMultiMap<QString, PageNode *> PageNodeMultiMap;
49typedef QMap<QString, QmlTypeNode *> QmlTypeMap;
50typedef QMultiMap<QString, const ExampleNode *> ExampleNodeMap;
51
52class Tree
53{
54 friend class QDocForest;
55 friend class QDocDatabase;
56
57private: // Note the constructor and destructor are private.
58 typedef QMap<PropertyNode::FunctionRole, QString> RoleMap;
59 typedef QMap<PropertyNode *, RoleMap> PropertyMap;
60
61 Tree(const QString &camelCaseModuleName, QDocDatabase *qdb);
62 ~Tree();
63
64public: // Of necessity, a few public functions remain.
65 [[nodiscard]] const QString &camelCaseModuleName() const { return m_camelCaseModuleName; }
66 [[nodiscard]] const QString &physicalModuleName() const { return m_physicalModuleName; }
67 [[nodiscard]] const QString &indexFileName() const { return m_indexFileName; }
68 [[nodiscard]] const QString &indexTitle() const { return m_indexTitle; }
69 void setIndexTitle(const QString &t) { m_indexTitle = t; }
70 NodeList &proxies() { return m_proxies; }
71 void appendProxy(ProxyNode *t) { m_proxies.append(t); }
72 void addToDontDocumentMap(QString &arg);
73 void markDontDocumentNodes();
74
75private: // The rest of the class is private.
76 Aggregate *findAggregate(const QString &name);
77 [[nodiscard]] Node *findNodeForInclude(const QStringList &path) const;
78 ClassNode *findClassNode(const QStringList &path, const Node *start = nullptr) const;
79 [[nodiscard]] NamespaceNode *findNamespaceNode(const QStringList &path) const;
80 const FunctionNode *findFunctionNode(const QStringList &path, const Parameters &parameters,
81 const Node *relative, Node::Genus genus) const;
82 Node *findNodeRecursive(const QStringList &path, int pathIndex, const Node *start,
83 bool (Node::*)() const) const;
84 const Node *findNodeForTarget(const QStringList &path, const QString &target, const Node *node,
85 int flags, Node::Genus genus, QString &ref,
86 TargetRec::TargetType *targetType = nullptr) const;
87 const Node *matchPathAndTarget(const QStringList &path, int idx, const QString &target,
88 const Node *node, int flags, Node::Genus genus,
89 QString &ref) const;
90
91 const Node *findNode(const QStringList &path, const Node *relative, int flags,
92 Node::Genus genus) const;
93
94 [[nodiscard]] Node *findNodeByNameAndType(const QStringList &path,
95 bool (Node::*isMatch)() const) const;
96 Aggregate *findRelatesNode(const QStringList &path);
97 const Node *findEnumNode(const Node *node, const Node *aggregate, const QStringList &path, int offset) const;
98 QString getRef(const QString &target, const Node *node) const;
99 void insertTarget(const QString &name, const QString &title, TargetRec::TargetType type,
100 Node *node, int priority);
101 void resolveTargets(Aggregate *root);
102 const TargetRec *findUnambiguousTarget(const QString &target, Node::Genus genus) const;
103 [[nodiscard]] const PageNode *findPageNodeByTitle(const QString &title) const;
104
105 void addPropertyFunction(PropertyNode *property, const QString &funcName,
106 PropertyNode::FunctionRole funcRole);
107 void resolveBaseClasses(Aggregate *n);
108 void resolvePropertyOverriddenFromPtrs(Aggregate *n);
109 void resolveProperties();
110 void resolveCppToQmlLinks();
111 void resolveSince(Aggregate &aggregate);
112 void resolveEnumValueSince(EnumNode &en);
113 void removePrivateAndInternalBases(NamespaceNode *rootNode);
114 NamespaceNode *root() { return &m_root; }
115 [[nodiscard]] const NamespaceNode *root() const { return &m_root; }
116
117 ClassList allBaseClasses(const ClassNode *classe) const;
118 QString refForAtom(const Atom *atom);
119
120 CNMap *getCollectionMap(Node::NodeType type);
121 [[nodiscard]] const CNMap &groups() const { return m_groups; }
122 [[nodiscard]] const CNMap &modules() const { return m_modules; }
123 [[nodiscard]] const CNMap &qmlModules() const { return m_qmlModules; }
124
125 CollectionNode *getCollection(const QString &name, Node::NodeType type);
126 CollectionNode *findCollection(const QString &name, Node::NodeType type);
127
128 CollectionNode *findGroup(const QString &name) { return findCollection(name, type: Node::Group); }
129 CollectionNode *findModule(const QString &name) { return findCollection(name, type: Node::Module); }
130 CollectionNode *findQmlModule(const QString &name)
131 {
132 return findCollection(name, type: Node::QmlModule);
133 }
134
135 CollectionNode *addGroup(const QString &name) { return findGroup(name); }
136 CollectionNode *addModule(const QString &name) { return findModule(name); }
137 CollectionNode *addQmlModule(const QString &name) { return findQmlModule(name); }
138
139 CollectionNode *addToGroup(const QString &name, Node *node);
140 CollectionNode *addToModule(const QString &name, Node *node);
141 CollectionNode *addToQmlModule(const QString &name, Node *node);
142
143 [[nodiscard]] QmlTypeNode *lookupQmlType(const QString &name) const
144 {
145 return m_qmlTypeMap.value(key: name);
146 }
147 void insertQmlType(const QString &key, QmlTypeNode *n);
148 void addExampleNode(ExampleNode *n) { m_exampleNodeMap.insert(key: n->title(), value: n); }
149 ExampleNodeMap &exampleNodeMap() { return m_exampleNodeMap; }
150 void setIndexFileName(const QString &t) { m_indexFileName = t; }
151
152 FunctionNode *findFunctionNodeForTag(const QString &tag, Aggregate *parent = nullptr);
153 FunctionNode *findMacroNode(const QString &t, const Aggregate *parent = nullptr);
154
155private:
156 QString m_camelCaseModuleName {};
157 QString m_physicalModuleName {};
158 QString m_indexFileName {};
159 QString m_indexTitle {};
160 QDocDatabase *m_qdb { nullptr };
161 NamespaceNode m_root;
162 PropertyMap m_unresolvedPropertyMap {};
163 PageNodeMultiMap m_pageNodesByTitle {};
164 TargetMap m_nodesByTargetRef {};
165 TargetMap m_nodesByTargetTitle {};
166 CNMap m_groups {};
167 CNMap m_modules {};
168 CNMap m_qmlModules {};
169 QmlTypeMap m_qmlTypeMap {};
170 ExampleNodeMap m_exampleNodeMap {};
171 NodeList m_proxies {};
172 NodeMap m_dontDocumentMap {};
173};
174
175QT_END_NAMESPACE
176
177#endif
178

source code of qttools/src/qdoc/qdoc/tree.h