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 restoreIR(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit);
84 void continueLoadFromIR();
85 bool resolveTypes();
86 QQmlError buildTypeResolutionCaches(
87 QQmlRefPointer<QQmlTypeNameCache> *typeNameCache,
88 QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache
89 ) const;
90 void compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
91 QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache,
92 const QV4::CompiledData::DependentTypesHasher &dependencyHasher);
93 QQmlError createTypeAndPropertyCaches(
94 const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
95 const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache);
96 bool resolveType(const QString &typeName, QTypeRevision &version,
97 TypeReference &ref, int lineNumber = -1, int columnNumber = -1,
98 bool reportErrors = true,
99 QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType,
100 bool *typeRecursionDetected = nullptr);
101
102 void scriptImported(
103 const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location,
104 const QString &nameSpace, const QString &qualifier) override;
105
106 SourceCodeData m_backupSourceCode; // used when cache verification fails.
107 QScopedPointer<QmlIR::Document> m_document;
108 QV4::CompiledData::TypeReferenceMap m_typeReferences;
109
110 QList<ScriptReference> m_scripts;
111
112 QSet<QString> m_namespaces;
113 QList<TypeReference> m_compositeSingletons;
114
115 // map from name index to resolved type
116 // While this could be a hash, a map is chosen here to provide a stable
117 // order, which is used to calculating a check-sum on dependent meta-objects.
118 QMap<int, TypeReference> m_resolvedTypes;
119 bool m_typesResolved:1;
120
121 // Used for self-referencing types, otherwise invalid.
122 QQmlType m_qmlType;
123 QByteArray m_typeClassName; // used for meta-object later
124
125 using CompilationUnitPtr = QQmlRefPointer<QV4::CompiledData::CompilationUnit>;
126
127 QHash<QString, InlineComponentData> m_inlineComponentData;
128
129 CompilationUnitPtr m_compiledData;
130
131 bool m_implicitImportLoaded;
132 bool loadImplicitImport();
133 bool checkScripts();
134 bool checkDependencies();
135
136 template<typename Reference>
137 void createError(const Reference &ref, const QString &message, QList<QQmlError> errors)
138 {
139 QQmlError error;
140 error.setUrl(url());
141 error.setLine(qmlConvertSourceCoordinate<quint32, int>(ref.location.line()));
142 error.setColumn(qmlConvertSourceCoordinate<quint32, int>(ref.location.column()));
143 error.setDescription(message);
144 errors.prepend(std::move(error));
145 setError(errors);
146 }
147
148 void createError(const TypeReference &type, const QString &message);
149 void createError(const ScriptReference &script, const QString &message);
150
151 bool checkCompositeSingletons();
152 void createQQmlType();
153 bool rebuildFromSource();
154};
155
156QT_END_NAMESPACE
157
158#endif // QQMLTYPEDATA_P_H
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)