1 | // Copyright (C) 2019 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 QQMLTYPEDATA_P_H |
5 | #define QQMLTYPEDATA_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 <private/qqmltypeloader_p.h> |
19 | #include <private/qv4executablecompilationunit_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class Q_AUTOTEST_EXPORT QQmlTypeData : public QQmlTypeLoader::Blob |
24 | { |
25 | Q_DECLARE_TR_FUNCTIONS(QQmlTypeData) |
26 | public: |
27 | struct TypeReference |
28 | { |
29 | TypeReference() : version(QTypeRevision::zero()), needsCreation(true) {} |
30 | |
31 | QV4::CompiledData::Location location; |
32 | QQmlType type; |
33 | QTypeRevision version; |
34 | QQmlRefPointer<QQmlTypeData> typeData; |
35 | bool selfReference = false; |
36 | QString prefix; // used by CompositeSingleton types |
37 | QString qualifiedName() const; |
38 | bool needsCreation; |
39 | }; |
40 | |
41 | struct ScriptReference |
42 | { |
43 | QV4::CompiledData::Location location; |
44 | QString qualifier; |
45 | QQmlRefPointer<QQmlScriptBlob> script; |
46 | }; |
47 | |
48 | private: |
49 | friend class QQmlTypeLoader; |
50 | |
51 | QQmlTypeData(const QUrl &, QQmlTypeLoader *); |
52 | template<typename Container> |
53 | void setCompileUnit(const Container &container); |
54 | |
55 | public: |
56 | ~QQmlTypeData() override; |
57 | |
58 | const QList<ScriptReference> &resolvedScripts() const; |
59 | |
60 | QV4::ExecutableCompilationUnit *compilationUnit() const; |
61 | |
62 | // Used by QQmlComponent to get notifications |
63 | struct TypeDataCallback { |
64 | virtual ~TypeDataCallback(); |
65 | virtual void typeDataProgress(QQmlTypeData *, qreal) {} |
66 | virtual void typeDataReady(QQmlTypeData *) {} |
67 | }; |
68 | void registerCallback(TypeDataCallback *); |
69 | void unregisterCallback(TypeDataCallback *); |
70 | |
71 | CompositeMetaTypeIds typeIds(const QString &inlineComponentName = QString()) const; |
72 | QByteArray typeClassName() const { return m_typeClassName; } |
73 | SourceCodeData backupSourceCode() const { return m_backupSourceCode; } |
74 | |
75 | protected: |
76 | void done() override; |
77 | void completed() override; |
78 | void dataReceived(const SourceCodeData &) override; |
79 | void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) override; |
80 | void allDependenciesDone() override; |
81 | void downloadProgressChanged(qreal) override; |
82 | |
83 | QString stringAt(int index) const override; |
84 | |
85 | private: |
86 | bool tryLoadFromDiskCache(); |
87 | bool loadFromSource(); |
88 | void restoreIR(QV4::CompiledData::CompilationUnit &&unit); |
89 | void continueLoadFromIR(); |
90 | void resolveTypes(); |
91 | QQmlError buildTypeResolutionCaches( |
92 | QQmlRefPointer<QQmlTypeNameCache> *typeNameCache, |
93 | QV4::ResolvedTypeReferenceMap *resolvedTypeCache |
94 | ) const; |
95 | void compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, |
96 | QV4::ResolvedTypeReferenceMap *resolvedTypeCache, |
97 | const QV4::CompiledData::DependentTypesHasher &dependencyHasher); |
98 | QQmlError createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, |
99 | const QV4::ResolvedTypeReferenceMap &resolvedTypeCache); |
100 | bool resolveType(const QString &typeName, QTypeRevision &version, |
101 | TypeReference &ref, int lineNumber = -1, int columnNumber = -1, |
102 | bool reportErrors = true, |
103 | QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType, |
104 | bool *typeRecursionDetected = nullptr); |
105 | |
106 | void scriptImported( |
107 | const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location, |
108 | const QString &nameSpace, const QString &qualifier) override; |
109 | |
110 | SourceCodeData m_backupSourceCode; // used when cache verification fails. |
111 | QScopedPointer<QmlIR::Document> m_document; |
112 | QV4::CompiledData::TypeReferenceMap m_typeReferences; |
113 | |
114 | QList<ScriptReference> m_scripts; |
115 | |
116 | QSet<QString> m_namespaces; |
117 | QList<TypeReference> m_compositeSingletons; |
118 | |
119 | // map from name index to resolved type |
120 | // While this could be a hash, a map is chosen here to provide a stable |
121 | // order, which is used to calculating a check-sum on dependent meta-objects. |
122 | QMap<int, TypeReference> m_resolvedTypes; |
123 | bool m_typesResolved:1; |
124 | |
125 | // Used for self-referencing types, otherwise -1. |
126 | CompositeMetaTypeIds m_typeIds; |
127 | QByteArray m_typeClassName; // used for meta-object later |
128 | |
129 | using ExecutableCompilationUnitPtr = QQmlRefPointer<QV4::ExecutableCompilationUnit>; |
130 | |
131 | QHash<QString, InlineComponentData> m_inlineComponentData; |
132 | |
133 | ExecutableCompilationUnitPtr m_compiledData; |
134 | |
135 | QList<TypeDataCallback *> m_callbacks; |
136 | |
137 | bool m_implicitImportLoaded; |
138 | bool loadImplicitImport(); |
139 | }; |
140 | |
141 | QT_END_NAMESPACE |
142 | |
143 | #endif // QQMLTYPEDATA_P_H |
144 | |