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