summaryrefslogtreecommitdiffstats
path: root/src/qdoc/qdocdatabase.h
blob: 1ff3aff15ed540e84c2845ceb25e34f46c7495fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QDOCDATABASE_H
#define QDOCDATABASE_H

#include "config.h"
#include "text.h"
#include "tree.h"

#include <QtCore/qdebug.h>
#include <QtCore/qmap.h>
#include <QtCore/qstring.h>

QT_BEGIN_NAMESPACE

typedef QMap<Text, const Node *> TextToNodeMap;

class Atom;
class Generator;
class QDocDatabase;

enum FindFlag {
    SearchBaseClasses = 0x1,
    SearchEnumValues = 0x2,
    TypesOnly = 0x4,
    IgnoreModules = 0x8
};

class QDocForest
{
private:
    friend class QDocDatabase;
    QDocForest(QDocDatabase *qdb)
        : qdb_(qdb), primaryTree_(nullptr), currentIndex_(0) { }
    ~QDocForest();

    NamespaceNode *firstRoot();
    NamespaceNode *nextRoot();
    Tree *firstTree();
    Tree *nextTree();
    Tree *primaryTree() { return primaryTree_; }
    Tree *findTree(const QString &t) { return forest_.value(t); }
    QStringList keys() {
        return forest_.keys();
    }
    NamespaceNode *primaryTreeRoot() { return (primaryTree_ ? primaryTree_->root() : nullptr); }
    bool isEmpty() { return searchOrder().isEmpty(); }
    bool done() { return (currentIndex_ >= searchOrder().size()); }
    const QVector<Tree *> &searchOrder();
    const QVector<Tree *> &indexSearchOrder();
    void setSearchOrder(const QStringList &t);
    bool isLoaded(const QString &fn) {
        for (const auto *tree : searchOrder()) {
            if (fn == tree->indexFileName())
                return true;
        }
        return false;
    }

    const Node *findNode(const QStringList &path,
                         const Node *relative,
                         int findFlags,
                         Node::Genus genus) {
        for (const auto *tree : searchOrder()) {
            const Node *n = tree->findNode(path, relative, findFlags, genus);
            if (n)
                return n;
            relative = nullptr;
        }
        return nullptr;
    }

    Node *findNodeByNameAndType(const QStringList &path, bool (Node::*isMatch) () const) {
        for (const auto *tree : searchOrder()) {
            Node *n = tree->findNodeByNameAndType(path, isMatch);
            if (n)
                return n;
        }
        return nullptr;
    }

    ClassNode *findClassNode(const QStringList &path) {
        for (const auto *tree : searchOrder()) {
            ClassNode *n = tree->findClassNode(path);
            if (n)
                return n;
        }
        return nullptr;
    }

    Node *findNodeForInclude(const QStringList &path) {
        for (const auto *tree : searchOrder()) {
            Node *n = tree->findNodeForInclude(path);
            if (n)
                return n;
        }
        return nullptr;
    }

    const FunctionNode *findFunctionNode(const QStringList &path,
                                         const Parameters &parameters,
                                         const Node *relative,
                                         Node::Genus genus);
    const Node *findNodeForTarget(QStringList &targetPath,
                                  const Node *relative,
                                  Node::Genus genus,
                                  QString &ref);

    const Node *findTypeNode(const QStringList &path, const Node *relative, Node::Genus genus)
    {
        int flags = SearchBaseClasses | SearchEnumValues | TypesOnly;
        if (relative && genus == Node::DontCare && relative->genus() != Node::DOC)
            genus = relative->genus();
        for (const auto *tree : searchOrder()) {
            const Node *n = tree->findNode(path, relative, flags, genus);
            if (n)
                return n;
            relative = nullptr;
        }
        return nullptr;
    }

    const PageNode *findPageNodeByTitle(const QString &title)
    {
        for (const auto *tree : searchOrder()) {
            const PageNode *n = tree->findPageNodeByTitle(title);
            if (n)
                return n;
        }
        return nullptr;
    }

    const CollectionNode *getCollectionNode(const QString &name, Node::NodeType type)
    {
        for (auto *tree : searchOrder()) {
            const CollectionNode *cn = tree->getCollection(name, type);
            if (cn)
                return cn;
        }
        return nullptr;
    }

    QmlTypeNode *lookupQmlType(const QString &name)
    {
        for (const auto *tree : searchOrder()) {
            QmlTypeNode *qcn = tree->lookupQmlType(name);
            if (qcn)
                return qcn;
        }
        return nullptr;
    }

    Aggregate *lookupQmlBasicType(const QString &name)
    {
        for (const auto *tree : searchOrder()) {
            Aggregate *a = tree->lookupQmlBasicType(name);
            if (a)
                return a;
        }
        return nullptr;
    }
    void clearSearchOrder() { searchOrder_.clear(); }
    void clearLinkCounts()
    {
        for (auto *tree : searchOrder())
            tree->clearLinkCount();
    }
    void printLinkCounts(const QString &project);
    QString getLinkCounts(QStringList &strings, QVector<int> &counts);
    void newPrimaryTree(const QString &module);
    void setPrimaryTree(const QString &t);
    NamespaceNode *newIndexTree(const QString &module);

private:
    QDocDatabase *qdb_;
    Tree *primaryTree_;
    int currentIndex_;
    QMap<QString, Tree *> forest_;
    QVector<Tree *> searchOrder_;
    QVector<Tree *> indexSearchOrder_;
    QVector<QString> moduleNames_;
};

class QDocDatabase
{
    Q_DECLARE_TR_FUNCTIONS(QDoc::QDocDatabase)

public:
    static QDocDatabase *qdocDB();
    static void destroyQdocDB();
    ~QDocDatabase();

    Tree *findTree(const QString &t) { return forest_.findTree(t); }

    const CNMap &groups() { return primaryTree()->groups(); }
    const CNMap &modules() { return primaryTree()->modules(); }
    const CNMap &qmlModules() { return primaryTree()->qmlModules(); }
    const CNMap &jsModules() { return primaryTree()->jsModules(); }

    CollectionNode *addGroup(const QString &name) { return primaryTree()->addGroup(name); }
    CollectionNode *addModule(const QString &name) { return primaryTree()->addModule(name); }
    CollectionNode *addQmlModule(const QString &name) { return primaryTree()->addQmlModule(name); }
    CollectionNode *addJsModule(const QString &name) { return primaryTree()->addJsModule(name); }

    CollectionNode *addToGroup(const QString &name, Node *node) {
        return primaryTree()->addToGroup(name, node);
    }
    CollectionNode *addToModule(const QString &name, Node *node) {
        return primaryTree()->addToModule(name, node);
    }
    CollectionNode *addToQmlModule(const QString &name, Node *node) {
        return primaryTree()->addToQmlModule(name, node);
    }
    CollectionNode *addToJsModule(const QString &name, Node *node) {
        return primaryTree()->addToJsModule(name, node);
    }

    void addExampleNode(ExampleNode *n) { primaryTree()->addExampleNode(n); }
    ExampleNodeMap &exampleNodeMap() { return primaryTree()->exampleNodeMap(); }

    QmlTypeNode *findQmlType(const QString &name);
    QmlTypeNode *findQmlType(const QString &qmid, const QString &name);
    QmlTypeNode *findQmlType(const ImportRec& import, const QString &name);
    Aggregate *findQmlBasicType(const QString &qmid, const QString &name);

    static NodeMultiMap &obsoleteClasses() { return obsoleteClasses_; }
    static NodeMultiMap &obsoleteQmlTypes() { return obsoleteQmlTypes_; }
    static NodeMultiMap &classesWithObsoleteMembers() { return classesWithObsoleteMembers_; }
    static NodeMultiMap &qmlTypesWithObsoleteMembers() { return qmlTypesWithObsoleteMembers_; }
    static NodeMultiMap &cppClasses() { return cppClasses_; }
    static NodeMultiMap &qmlBasicTypes() { return qmlBasicTypes_; }
    static NodeMultiMap &qmlTypes() { return qmlTypes_; }
    static NodeMultiMap &examples() { return examples_; }
    static NodeMapMap &newClassMaps() { return newClassMaps_; }
    static NodeMapMap &newQmlTypeMaps() { return newQmlTypeMaps_; }
    static NodeMultiMapMap &newSinceMaps() { return newSinceMaps_; }

private:
    void findAllClasses(Aggregate *node) { node->findAllClasses(); }
    void findAllFunctions(Aggregate *node) { node->findAllFunctions(functionIndex_); }
    void findAllAttributions(Aggregate *node) { node->findAllAttributions(attributions_); }
    void findAllLegaleseTexts(Aggregate *node);
    void findAllObsoleteThings(Aggregate *node) { node->findAllObsoleteThings(); }
    void findAllSince(Aggregate *node) { node->findAllSince(); }

public:
    /*******************************************************************
     special collection access functions
    ********************************************************************/
    NodeMultiMap &getCppClasses();
    NodeMultiMap &getObsoleteClasses();
    NodeMultiMap &getClassesWithObsoleteMembers();
    NodeMultiMap &getObsoleteQmlTypes();
    NodeMultiMap &getQmlTypesWithObsoleteMembers();
    NodeMultiMap &getNamespaces();
    NodeMultiMap &getQmlBasicTypes();
    NodeMultiMap &getQmlTypes();
    NodeMultiMap &getExamples();
    NodeMultiMap &getAttributions();
    NodeMapMap &getFunctionIndex();
    TextToNodeMap &getLegaleseTexts();
    const NodeMap &getClassMap(const QString &key);
    const NodeMap &getQmlTypeMap(const QString &key);
    const NodeMap &getSinceMap(const QString &key);

    /*******************************************************************
      Many of these will be either eliminated or replaced.
    ********************************************************************/
    void resolveStuff();
    void insertTarget(const QString &name,
                      const QString &title,
                      TargetRec::TargetType type,
                      Node *node,
                      int priority) {
        primaryTree()->insertTarget(name, title, type, node, priority);
    }

    /*******************************************************************
      The functions declared below are called for the current tree only.
    ********************************************************************/
    Aggregate *findRelatesNode(const QStringList &path) { return primaryTree()->findRelatesNode(path); }
    Node *findNodeInOpenNamespace(QStringList &path, bool (Node::*) () const);
    /*******************************************************************/

    /*****************************************************************************
      This function can handle parameters enclosed in '[' ']' (domanin and genus).
    ******************************************************************************/
    const Node *findNodeForAtom(const Atom *atom, const Node *relative, QString &ref);
    /*******************************************************************/

    /*******************************************************************
      The functions declared below are called for all trees.
    ********************************************************************/
    ClassNode *findClassNode(const QStringList &path) { return forest_.findClassNode(path); }
    Node *findNodeForInclude(const QStringList &path) { return forest_.findNodeForInclude(path); }
    const FunctionNode *findFunctionNode(const QString &target, const Node *relative, Node::Genus genus);
    const Node *findTypeNode(const QString &type, const Node *relative, Node::Genus genus);
    const Node *findNodeForTarget(const QString &target, const Node *relative);
    const PageNode *findPageNodeByTitle(const QString &title) {
        return forest_.findPageNodeByTitle(title);
    }
    Node *findNodeByNameAndType(const QStringList &path, bool (Node::*isMatch) () const) {
        return forest_.findNodeByNameAndType(path, isMatch);
    }
    const CollectionNode *getCollectionNode(const QString &name, Node::NodeType type) {
        return forest_.getCollectionNode(name, type);
    }
    FunctionNode *findFunctionNodeForTag(QString tag) { return primaryTree()->findFunctionNodeForTag(tag); }
    FunctionNode *findMacroNode(const QString &t) { return primaryTree()->findMacroNode(t); }

private:
    const Node *findNodeForTarget(QStringList &targetPath,
                                  const Node *relative,
                                  Node::Genus genus,
                                  QString &ref) {
        return forest_.findNodeForTarget(targetPath, relative, genus, ref);
    }
    const FunctionNode *findFunctionNode(const QStringList &path,
                                         const Parameters &parameters,
                                         const Node *relative,
                                         Node::Genus genus) {
        return forest_.findFunctionNode(path, parameters, relative, genus);
    }

    /*******************************************************************/
public:
    void addPropertyFunction(PropertyNode *property,
                             const QString &funcName,
                             PropertyNode::FunctionRole funcRole) {
        primaryTree()->addPropertyFunction(property, funcName, funcRole);
    }

    void setVersion(const QString &v) { version_ = v; }
    QString version() const { return version_; }

    void generateTagFile(const QString &name, Generator *g);
    void readIndexes(const QStringList &indexFiles);
    void generateIndex(const QString &fileName, const QString &url, const QString &title, Generator *g);

    void clearOpenNamespaces() { openNamespaces_.clear(); }
    void insertOpenNamespace(const QString &path) { openNamespaces_.insert(path); }
    void setShowInternal(bool value) { showInternal_ = value; }
    void setSingleExec(bool value) { singleExec_ = value; }
    void processForest();

    // Try to make this function private.
    QDocForest& forest() { return forest_; }
    NamespaceNode *primaryTreeRoot() { return forest_.primaryTreeRoot(); }
    void newPrimaryTree(const QString &module) { forest_.newPrimaryTree(module); }
    void setPrimaryTree(const QString &t) { forest_.setPrimaryTree(t); }
    NamespaceNode *newIndexTree(const QString &module) { return forest_.newIndexTree(module); }
    const QVector<Tree *> &searchOrder() { return forest_.searchOrder(); }
    void setLocalSearch() { forest_.searchOrder_ = QVector<Tree *>(1, primaryTree()); }
    void setSearchOrder(const QVector<Tree *> &searchOrder) { forest_.searchOrder_ = searchOrder; }
    void setSearchOrder(QStringList &t) { forest_.setSearchOrder(t); }
    void mergeCollections(Node::NodeType type, CNMap &cnm, const Node *relative);
    void mergeCollections(CollectionNode *c);
    void clearSearchOrder() { forest_.clearSearchOrder(); }
    void incrementLinkCount(const Node *t) { t->tree()->incrementLinkCount(); }
    void clearLinkCounts() { forest_.clearLinkCounts(); }
    void printLinkCounts(const QString &t) { forest_.printLinkCounts(t); }
    QString getLinkCounts(QStringList &strings, QVector<int> &counts) {
        return forest_.getLinkCounts(strings, counts);
    }
    QString getNewLinkTarget(const Node *locNode,
                             const Node *t,
                             const QString &fileName,
                             QString &text,
                             bool broken = false) {
        return primaryTree()->getNewLinkTarget(locNode, t, fileName, text, broken);
    }
    TargetList* getTargetList(const QString &t) { return primaryTree()->getTargetList(t); }
    QStringList getTargetListKeys() { return primaryTree()->getTargetListKeys(); }
    QStringList keys() { return forest_.keys(); }
    void resolveNamespaces();
    void resolveProxies();
    void resolveBaseClasses();

private:
    friend class Tree;

    const Node *findNode(const QStringList &path,
                         const Node *relative,
                         int findFlags,
                         Node::Genus genus) {
        return forest_.findNode(path, relative, findFlags, genus);
    }
    void processForest(void (QDocDatabase::*) (Aggregate*));
    bool isLoaded(const QString &t) { return forest_.isLoaded(t); }
    static void initializeDB();

private:
    QDocDatabase();
    QDocDatabase(QDocDatabase const &) : showInternal_(false), forest_(this) { }
    QDocDatabase& operator=(QDocDatabase const &);

public:
    static bool debug;
    Tree *primaryTree() { return forest_.primaryTree(); }

private:
    static QDocDatabase *qdocDB_;
    static NodeMap typeNodeMap_;
    static NodeMultiMap obsoleteClasses_;
    static NodeMultiMap classesWithObsoleteMembers_;
    static NodeMultiMap obsoleteQmlTypes_;
    static NodeMultiMap qmlTypesWithObsoleteMembers_;
    static NodeMultiMap cppClasses_;
    static NodeMultiMap qmlBasicTypes_;
    static NodeMultiMap qmlTypes_;
    static NodeMultiMap examples_;
    static NodeMapMap newClassMaps_;
    static NodeMapMap newQmlTypeMaps_;
    static NodeMultiMapMap newSinceMaps_;

    bool showInternal_;
    bool singleExec_;
    QString version_;
    QDocForest forest_;

    NodeMultiMap namespaceIndex_;
    NodeMultiMap attributions_;
    NodeMapMap functionIndex_;
    TextToNodeMap legaleseTexts_;
    QSet<QString> openNamespaces_;
};

QT_END_NAMESPACE

#endif