| 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 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | namespace QQmlJS { |
| 23 | namespace Dom { |
| 24 | |
| 25 | class QMLDOM_EXPORT ModuleScope final : public DomBase |
| 26 | { |
| 27 | public: |
| 28 | constexpr static DomType kindValue = DomType::ModuleScope; |
| 29 | DomType kind() const override { return kindValue; } |
| 30 | |
| 31 | ModuleScope(const QString &uri = QString(), const Version &version = Version()) |
| 32 | : uri(uri), version(version) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | Path pathFromOwner() const |
| 37 | { |
| 38 | return Path::fromField(s: Fields::moduleScope) |
| 39 | .withKey(name: version.isValid() ? QString::number(version.minorVersion) : QString()); |
| 40 | } |
| 41 | Path pathFromOwner(const DomItem &) const override { return pathFromOwner(); } |
| 42 | Path canonicalPath(const DomItem &self) const override |
| 43 | { |
| 44 | return self.owner().canonicalPath().withPath(toAdd: pathFromOwner()); |
| 45 | } |
| 46 | bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override; |
| 47 | |
| 48 | QString uri; |
| 49 | Version version; |
| 50 | }; |
| 51 | |
| 52 | class QMLDOM_EXPORT ModuleIndex final : public OwningItem |
| 53 | { |
| 54 | Q_DECLARE_TR_FUNCTIONS(ModuleIndex); |
| 55 | |
| 56 | protected: |
| 57 | std::shared_ptr<OwningItem> doCopy(const DomItem &self) const override; |
| 58 | |
| 59 | public: |
| 60 | enum class Status { NotLoaded, Loading, Loaded }; |
| 61 | constexpr static DomType kindValue = DomType::ModuleIndex; |
| 62 | DomType kind() const override { return kindValue; } |
| 63 | |
| 64 | ModuleIndex( |
| 65 | const QString &uri, int majorVersion, int derivedFrom = 0, |
| 66 | const QDateTime &lastDataUpdateAt = QDateTime::fromMSecsSinceEpoch(msecs: 0, timeZone: QTimeZone::UTC)) |
| 67 | : OwningItem(derivedFrom, lastDataUpdateAt), m_uri(uri), m_majorVersion(majorVersion) |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | ModuleIndex(const ModuleIndex &o); |
| 72 | |
| 73 | ~ModuleIndex(); |
| 74 | |
| 75 | std::shared_ptr<ModuleIndex> makeCopy(const DomItem &self) const |
| 76 | { |
| 77 | return std::static_pointer_cast<ModuleIndex>(r: doCopy(self)); |
| 78 | } |
| 79 | |
| 80 | Path canonicalPath(const DomItem &) const override |
| 81 | { |
| 82 | return Paths::moduleIndexPath(uri: uri(), majorVersion: majorVersion()); |
| 83 | } |
| 84 | |
| 85 | bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const override; |
| 86 | |
| 87 | QSet<QString> exportNames(const DomItem &self) const; |
| 88 | |
| 89 | QList<DomItem> exportsWithNameAndMinorVersion(const DomItem &self, const QString &name, |
| 90 | int minorVersion) const; |
| 91 | |
| 92 | QString uri() const { return m_uri; } |
| 93 | int majorVersion() const { return m_majorVersion; } |
| 94 | QList<Path> sources() const; |
| 95 | |
| 96 | QList<int> minorVersions() const |
| 97 | { |
| 98 | QMutexLocker l(mutex()); |
| 99 | return m_moduleScope.keys(); |
| 100 | } |
| 101 | ModuleScope *ensureMinorVersion(int minorVersion); |
| 102 | void mergeWith(const std::shared_ptr<ModuleIndex> &o); |
| 103 | void addQmltypeFilePath(const Path &p) |
| 104 | { |
| 105 | QMutexLocker l(mutex()); |
| 106 | if (!m_qmltypesFilesPaths.contains(t: p)) |
| 107 | m_qmltypesFilesPaths.append(t: p); |
| 108 | } |
| 109 | |
| 110 | QList<Path> qmldirsToLoad(const DomItem &self); |
| 111 | QList<Path> qmltypesFilesPaths() const |
| 112 | { |
| 113 | QMutexLocker l(mutex()); |
| 114 | return m_qmltypesFilesPaths; |
| 115 | } |
| 116 | QList<Path> qmldirPaths() const |
| 117 | { |
| 118 | QMutexLocker l(mutex()); |
| 119 | return m_qmldirPaths; |
| 120 | } |
| 121 | QList<Path> directoryPaths() const |
| 122 | { |
| 123 | QMutexLocker l(mutex()); |
| 124 | return m_directoryPaths; |
| 125 | } |
| 126 | QList<DomItem> autoExports(const DomItem &self) const; |
| 127 | |
| 128 | private: |
| 129 | QString m_uri; |
| 130 | int m_majorVersion; |
| 131 | |
| 132 | QList<Path> m_qmltypesFilesPaths; |
| 133 | QList<Path> m_qmldirPaths; |
| 134 | QList<Path> m_directoryPaths; |
| 135 | QMap<int, ModuleScope *> m_moduleScope; |
| 136 | }; |
| 137 | |
| 138 | } // end namespace Dom |
| 139 | } // end namespace QQmlJS |
| 140 | QT_END_NAMESPACE |
| 141 | #endif // QQMLDOMMODULEINDEX_P_H |
| 142 | |