aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmldom/qqmldommoduleindex_p.h
blob: f2b2731624f15b34ec80afee949874f1648f2583 (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
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQMLDOMMODULEINDEX_P_H
#define QQMLDOMMODULEINDEX_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qqmldomelements_p.h"

QT_BEGIN_NAMESPACE

namespace QQmlJS {
namespace Dom {

class QMLDOM_EXPORT ModuleScope final : public DomBase
{
public:
    constexpr static DomType kindValue = DomType::ModuleScope;
    DomType kind() const override { return kindValue; }

    ModuleScope(const QString &uri = QString(), const Version &version = Version())
        : uri(uri), version(version)
    {
    }

    Path pathFromOwner() const
    {
        return Path::Field(Fields::moduleScope)
                .key(version.isValid() ? QString::number(version.minorVersion) : QString());
    }
    Path pathFromOwner(const DomItem &) const override { return pathFromOwner(); }
    Path canonicalPath(const DomItem &self) const override
    {
        return self.owner().canonicalPath().path(pathFromOwner());
    }
    bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override;

    QString uri;
    Version version;
};

class QMLDOM_EXPORT ModuleIndex final : public OwningItem
{
    Q_DECLARE_TR_FUNCTIONS(ModuleIndex);

protected:
    std::shared_ptr<OwningItem> doCopy(const DomItem &self) const override;

public:
    enum class Status { NotLoaded, Loading, Loaded };
    constexpr static DomType kindValue = DomType::ModuleIndex;
    DomType kind() const override { return kindValue; }

    ModuleIndex(
            const QString &uri, int majorVersion, int derivedFrom = 0,
            const QDateTime &lastDataUpdateAt = QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC))
        : OwningItem(derivedFrom, lastDataUpdateAt), m_uri(uri), m_majorVersion(majorVersion)
    {
    }

    ModuleIndex(const ModuleIndex &o);

    ~ModuleIndex();

    std::shared_ptr<ModuleIndex> makeCopy(const DomItem &self) const
    {
        return std::static_pointer_cast<ModuleIndex>(doCopy(self));
    }

    Path canonicalPath(const DomItem &) const override
    {
        return Paths::moduleIndexPath(uri(), majorVersion());
    }

    bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override;

    QSet<QString> exportNames(const DomItem &self) const;

    QList<DomItem> exportsWithNameAndMinorVersion(const DomItem &self, const QString &name,
                                                  int minorVersion) const;

    QString uri() const { return m_uri; }
    int majorVersion() const { return m_majorVersion; }
    QList<Path> sources() const;

    QList<int> minorVersions() const
    {
        QMutexLocker l(mutex());
        return m_moduleScope.keys();
    }
    ModuleScope *ensureMinorVersion(int minorVersion);
    void mergeWith(const std::shared_ptr<ModuleIndex> &o);
    void addQmltypeFilePath(const Path &p)
    {
        QMutexLocker l(mutex());
        if (!m_qmltypesFilesPaths.contains(p))
            m_qmltypesFilesPaths.append(p);
    }

    QList<Path> qmldirsToLoad(const DomItem &self);
    QList<Path> qmltypesFilesPaths() const
    {
        QMutexLocker l(mutex());
        return m_qmltypesFilesPaths;
    }
    QList<Path> qmldirPaths() const
    {
        QMutexLocker l(mutex());
        return m_qmldirPaths;
    }
    QList<Path> directoryPaths() const
    {
        QMutexLocker l(mutex());
        return m_directoryPaths;
    }
    QList<DomItem> autoExports(const DomItem &self) const;

private:
    QString m_uri;
    int m_majorVersion;

    QList<Path> m_qmltypesFilesPaths;
    QList<Path> m_qmldirPaths;
    QList<Path> m_directoryPaths;
    QMap<int, ModuleScope *> m_moduleScope;
};

} // end namespace Dom
} // end namespace QQmlJS
QT_END_NAMESPACE
#endif // QQMLDOMMODULEINDEX_P_H