Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmltypedata_p.h
Go to the documentation of this file.
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/qqmlnotifyingblob_p.h>
19#include <private/qqmlsourcecoordinate_p.h>
20#include <private/qqmltypeloader_p.h>
21#include <private/qv4executablecompilationunit_p.h>
22
24
26
27class Q_AUTOTEST_EXPORT QQmlTypeData : public QQmlNotifyingBlob
28{
29 Q_DECLARE_TR_FUNCTIONS(QQmlTypeData)
30public:
31
32 struct TypeReference
33 {
34 TypeReference() : version(QTypeRevision::zero()), needsCreation(true) {}
35
36 QV4::CompiledData::Location location;
37 QQmlType type;
38 QTypeRevision version;
39 QQmlRefPointer<QQmlTypeData> typeData;
40 bool selfReference = false;
41 QString prefix; // used by CompositeSingleton types
42 QString qualifiedName() const;
43 bool needsCreation;
44 };
45
46 struct ScriptReference
47 {
48 QV4::CompiledData::Location location;
49 QString qualifier;
50 QQmlRefPointer<QQmlScriptBlob> script;
51 };
52
53private:
54 friend class QQmlTypeLoader;
55
56public:
57 QQmlTypeData(const QUrl &, QQmlTypeLoader *);
58 ~QQmlTypeData() override;
59
60 QV4::CompiledData::CompilationUnit *compilationUnit() const;
61
62 QQmlType qmlType(const QString &inlineComponentName = QString()) const;
63 QByteArray typeClassName() const { return m_typeClassName; }
64 SourceCodeData backupSourceCode() const { return m_backupSourceCode; }
65
66protected:
67 void done() override;
68
69 void dataReceived(const SourceCodeData &) override;
70 void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) override;
71 void allDependenciesDone() override;
72
73 QString stringAt(int index) const override;
74
75private:
76 using InlineComponentData = QV4::CompiledData::InlineComponentData;
77
78 bool tryLoadFromDiskCache();
79 bool loadFromDiskCache(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit);
80 bool loadFromSource();
81 void restoreIR(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit);
82 void continueLoadFromIR();
83 bool resolveTypes();
84 QQmlError buildTypeResolutionCaches(
85 QQmlRefPointer<QQmlTypeNameCache> *typeNameCache,
86 QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache
87 ) const;
88 void compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
89 QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache,
90 const QV4::CompiledData::DependentTypesHasher &dependencyHasher);
91 QQmlError createTypeAndPropertyCaches(
92 const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
93 const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache);
94 bool resolveType(const QString &typeName, QTypeRevision &version,
95 TypeReference &ref, int lineNumber = -1, int columnNumber = -1,
96 bool reportErrors = true,
97 QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType,
98 bool *typeRecursionDetected = nullptr);
99
100 void scriptImported(
101 const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location,
102 const QString &nameSpace, const QString &qualifier) override;
103
104 SourceCodeData m_backupSourceCode; // used when cache verification fails.
105 QScopedPointer<QmlIR::Document> m_document;
106 QV4::CompiledData::TypeReferenceMap m_typeReferences;
107
108 QList<ScriptReference> m_scripts;
109
110 QSet<QString> m_namespaces;
111 QList<TypeReference> m_compositeSingletons;
112
113 // map from name index to resolved type
114 // While this could be a hash, a map is chosen here to provide a stable
115 // order, which is used to calculating a check-sum on dependent meta-objects.
116 QMap<int, TypeReference> m_resolvedTypes;
117 bool m_typesResolved:1;
118
119 // Used for self-referencing types, otherwise invalid.
120 QQmlType m_qmlType;
121 QByteArray m_typeClassName; // used for meta-object later
122
123 using CompilationUnitPtr = QQmlRefPointer<QV4::CompiledData::CompilationUnit>;
124
125 QHash<QString, InlineComponentData> m_inlineComponentData;
126
127 CompilationUnitPtr m_compiledData;
128
129 bool m_implicitImportLoaded;
130 bool loadImplicitImport();
131 bool checkScripts();
132 bool checkDependencies();
133
134 template<typename Reference>
135 void createError(const Reference &ref, const QString &message, QList<QQmlError> errors)
136 {
137 QQmlError error;
138 error.setUrl(url());
139 error.setLine(qmlConvertSourceCoordinate<quint32, int>(ref.location.line()));
140 error.setColumn(qmlConvertSourceCoordinate<quint32, int>(ref.location.column()));
141 error.setDescription(message);
142 errors.prepend(std::move(error));
143 setError(errors);
144 }
145
146 void createError(const TypeReference &type, const QString &message);
147 void createError(const ScriptReference &script, const QString &message);
148
149 bool checkCompositeSingletons();
150 void createQQmlType();
151 bool rebuildFromSource();
152};
153
154QT_END_NAMESPACE
155
156#endif // QQMLTYPEDATA_P_H
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher)