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