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