1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLDOMMODULEINDEX_P_H
5#define QQMLDOMMODULEINDEX_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmldomelements_p.h"
19
20QT_BEGIN_NAMESPACE
21
22namespace QQmlJS {
23namespace Dom {
24
25class QMLDOM_EXPORT ModuleScope final : public DomBase
26{
27public:
28 constexpr static DomType kindValue = DomType::ModuleScope;
29 DomType kind() const override { return kindValue; }
30
31 ModuleScope(QString uri = QString(), const Version &version = Version())
32 : uri(uri), version(version)
33 {
34 }
35
36 Path pathFromOwner() const
37 {
38 return Path::Field(s: Fields::moduleScope)
39 .key(name: version.isValid() ? QString::number(version.minorVersion) : QString());
40 }
41 Path pathFromOwner(DomItem &) const override { return pathFromOwner(); }
42 Path canonicalPath(DomItem &self) const override
43 {
44 return self.owner().canonicalPath().path(toAdd: pathFromOwner());
45 }
46 bool iterateDirectSubpaths(DomItem &self, DirectVisitor visitor) override;
47
48 QString uri;
49 Version version;
50};
51
52class QMLDOM_EXPORT ModuleIndex final : public OwningItem
53{
54 Q_DECLARE_TR_FUNCTIONS(ModuleIndex);
55
56protected:
57 std::shared_ptr<OwningItem> doCopy(DomItem &self) const override;
58
59public:
60 enum class Status { NotLoaded, Loading, Loaded };
61 constexpr static DomType kindValue = DomType::ModuleIndex;
62 DomType kind() const override { return kindValue; }
63
64 ModuleIndex(QString uri, int majorVersion, int derivedFrom = 0,
65 QDateTime lastDataUpdateAt = QDateTime::fromMSecsSinceEpoch(msecs: 0, timeZone: QTimeZone::UTC))
66 : OwningItem(derivedFrom, lastDataUpdateAt), m_uri(uri), m_majorVersion(majorVersion)
67 {
68 }
69
70 ModuleIndex(const ModuleIndex &o);
71
72 ~ModuleIndex();
73
74 std::shared_ptr<ModuleIndex> makeCopy(DomItem &self) const
75 {
76 return std::static_pointer_cast<ModuleIndex>(r: doCopy(self));
77 }
78
79 Path canonicalPath(DomItem &) const override
80 {
81 return Paths::moduleIndexPath(uri: uri(), majorVersion: majorVersion());
82 }
83
84 bool iterateDirectSubpaths(DomItem &self, DirectVisitor visitor) override;
85
86 QSet<QString> exportNames(DomItem &self) const;
87
88 QList<DomItem> exportsWithNameAndMinorVersion(DomItem &self, QString name,
89 int minorVersion) const;
90
91 QString uri() const { return m_uri; }
92 int majorVersion() const { return m_majorVersion; }
93 QList<Path> sources() const;
94
95 QList<int> minorVersions() const
96 {
97 QMutexLocker l(mutex());
98 return m_moduleScope.keys();
99 }
100 ModuleScope *ensureMinorVersion(int minorVersion);
101 void mergeWith(std::shared_ptr<ModuleIndex> o);
102 void addQmltypeFilePath(Path p)
103 {
104 QMutexLocker l(mutex());
105 if (!m_qmltypesFilesPaths.contains(t: p))
106 m_qmltypesFilesPaths.append(t: p);
107 }
108
109 QList<Path> qmldirsToLoad(DomItem &self);
110 QList<Path> qmltypesFilesPaths() const
111 {
112 QMutexLocker l(mutex());
113 return m_qmltypesFilesPaths;
114 }
115 QList<Path> qmldirPaths() const
116 {
117 QMutexLocker l(mutex());
118 return m_qmldirPaths;
119 }
120 QList<Path> directoryPaths() const
121 {
122 QMutexLocker l(mutex());
123 return m_directoryPaths;
124 }
125 QList<DomItem> autoExports(DomItem &self) const;
126
127private:
128 QString m_uri;
129 int m_majorVersion;
130
131 QList<Path> m_qmltypesFilesPaths;
132 QList<Path> m_qmldirPaths;
133 QList<Path> m_directoryPaths;
134 QMap<int, ModuleScope *> m_moduleScope;
135};
136
137} // end namespace Dom
138} // end namespace QQmlJS
139QT_END_NAMESPACE
140#endif // QQMLDOMMODULEINDEX_P_H
141

source code of qtdeclarative/src/qmldom/qqmldommoduleindex_p.h