Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmltypecompiler_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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#ifndef QQMLTYPECOMPILER_P_H
4#define QQMLTYPECOMPILER_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <qglobal.h>
18#include <qqmlerror.h>
19#include <qhash.h>
20#include <private/qqmltypeloader_p.h>
21#include <private/qqmlirbuilder_p.h>
22#include <private/qqmlpropertycachecreator_p.h>
23
25
27class QQmlError;
28class QQmlTypeData;
29class QQmlImports;
30
31namespace QmlIR {
32struct Document;
33}
34
35namespace QV4 {
36namespace CompiledData {
37struct QmlUnit;
38struct Location;
39}
40}
41
43{
45public:
47 QQmlTypeData *typeData,
48 QmlIR::Document *document,
49 const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
50 QV4::ResolvedTypeReferenceMap *resolvedTypeCache,
51 const QV4::CompiledData::DependentTypesHasher &dependencyHasher);
52
53 // --- interface used by QQmlPropertyCacheCreator
57
58 // Deliberate choice of map over hash here to ensure stable generated output.
60
61 const QmlIR::Object *objectAt(int index) const { return document->objects.at(index); }
62 QmlIR::Object *objectAt(int index) { return document->objects.at(index); }
63 int objectCount() const { return document->objects.size(); }
64 QString stringAt(int idx) const;
65 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsBegin(const QmlIR::Object *object) const { return object->functionsBegin(); }
66 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsEnd(const QmlIR::Object *object) const { return object->functionsEnd(); }
69 {
70 for (const QmlIR::Pragma *pragma: document->pragmas) {
72 return pragma->listPropertyAssignBehavior;
73 }
74 return ListPropertyAssignBehavior::Append;
75 }
76 // ---
77
79
80 QList<QQmlError> compilationErrors() const { return errors; }
81 void recordError(const QV4::CompiledData::Location &location, const QString &description);
83 void recordError(const QQmlError &e);
84
85 int registerString(const QString &str);
87
88 const QV4::CompiledData::Unit *qmlUnit() const;
89
90 QUrl url() const { return typeData->finalUrl(); }
92 const QQmlImports *imports() const;
97 QStringView newStringRef(const QString &string);
99
100 const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; }
101
102 QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const;
103
104 void addImport(const QString &module, const QString &qualifier, QTypeRevision version);
105
107 {
108 return resolvedTypes->value(id);
109 }
110
111 QQmlType qmlTypeForComponent(const QString &inlineComponentName = QString()) const;
112
113private:
114 QList<QQmlError> errors;
116 const QV4::CompiledData::DependentTypesHasher &dependencyHasher;
117 QmlIR::Document *document;
118 // index is string index of type name (use obj->inheritedTypeNameIndex)
119 QHash<int, QQmlCustomParser*> customParsers;
120
121 // index in first hash is component index, vector inside contains object indices of objects with id property
122 QQmlPropertyCacheVector m_propertyCaches;
123
125 QQmlTypeData *typeData;
126};
127
129{
130 QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
131
132 QString stringAt(int idx) const { return compiler->stringAt(idx); }
133protected:
134 void recordError(const QV4::CompiledData::Location &location, const QString &description) const
135 { compiler->recordError(location, description); }
136
138 { return compiler->resolvedType(id); }
139
141};
142
143// Resolves signal handlers. Updates the QV4::CompiledData::Binding objects to
144// set the property name to the final signal name (onTextChanged -> textChanged)
145// and sets the IsSignalExpression flag.
147{
149public:
151
153
154private:
156 const QQmlPropertyCache::ConstPtr &propertyCache);
157
158 QQmlEnginePrivate *enginePrivate;
159 const QVector<QmlIR::Object*> &qmlObjects;
160 const QQmlImports *imports;
161 const QHash<int, QQmlCustomParser*> &customParsers;
162 const QSet<QString> &illegalNames;
163 const QQmlPropertyCacheVector * const propertyCaches;
164};
165
166// ### This will go away when the codegen resolves all enums to constant expressions
167// and we replace the constant expression with a literal binding instead of using
168// a script.
170{
172public:
174
175 bool resolveEnumBindings();
176
177private:
178 bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject);
179 bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
180 {
181 return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject);
182 }
183 bool tryQualifiedEnumAssignment(
184 const QmlIR::Object *obj, const QQmlPropertyCache::ConstPtr &propertyCache,
185 const QQmlPropertyData *prop, QmlIR::Binding *binding);
186 int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const;
187
188
189 const QVector<QmlIR::Object*> &qmlObjects;
190 const QQmlPropertyCacheVector * const propertyCaches;
191 const QQmlImports *imports;
192};
193
195{
196public:
198
200
201private:
202 void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false);
203
204 const QVector<QmlIR::Object*> &qmlObjects;
205 const QHash<int, QQmlCustomParser*> &customParsers;
206};
207
208// Annotate properties bound to aliases with a flag
210{
211public:
213
215private:
216 const QVector<QmlIR::Object*> &qmlObjects;
217 const QQmlPropertyCacheVector * const propertyCaches;
218};
219
221{
222public:
224
225 void scan();
226
227private:
228 const QVector<QmlIR::Object*> &qmlObjects;
229 const QQmlPropertyCacheVector * const propertyCaches;
230};
231
233{
235public:
237
238 bool scanObject();
239
240private:
241 enum class ScopeDeferred { False, True };
242 bool scanObject(int objectIndex, ScopeDeferred scopeDeferred);
243
244 QVector<QmlIR::Object*> *qmlObjects;
245 const QQmlPropertyCacheVector * const propertyCaches;
246 const QHash<int, QQmlCustomParser*> &customParsers;
247
248 bool _seenObjectWithId;
249};
250
252{
253public:
255
257
258private:
259 void mergeDefaultProperties(int objectIndex);
260
261 const QVector<QmlIR::Object*> &qmlObjects;
262 const QQmlPropertyCacheVector * const propertyCaches;
263};
264
266
267#endif // QQMLTYPECOMPILER_P_H
\inmodule QtCore
Definition qhash.h:818
T value(const Key &key) const noexcept
Definition qhash.h:1044
Definition qlist.h:74
QUrl finalUrl() const
Returns the logical URL to be used for resolving further URLs referred to in the code.
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
The QQmlImports class encapsulates one QML document's import statements.
Definition qset.h:18
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
\inmodule QtCore
Definition qurl.h:94
QString str
[2]
double e
Combined button and popup list for selecting options.
std::function< QByteArray()> DependentTypesHasher
\qmltype Particle \inqmlmodule QtQuick.Particles
quint64 ReturnedValue
#define Q_DECLARE_TR_FUNCTIONS(context)
const char * typeName
GLint location
GLsizei const GLfloat * v
[13]
GLuint index
[2]
GLuint GLsizei const GLchar * message
GLhandleARB obj
[2]
QJSEngine engine
[0]
void recordError(const QV4::CompiledData::Location &location, const QString &description) const
QV4::ResolvedTypeReference * resolvedType(int id) const
QQmlTypeCompiler * compiler
QString stringAt(int idx) const
QQmlEnginePrivate * enginePrivate() const
const QmlIR::Object * objectAt(int index) const
int registerConstant(QV4::ReturnedValue v)
QmlIR::Object CompiledObject
QmlIR::PoolList< QmlIR::Function >::Iterator objectFunctionsBegin(const QmlIR::Object *object) const
QV4::ResolvedTypeReference * resolvedType(int id) const
QList< QQmlError > compilationErrors() const
const QHash< int, QQmlCustomParser * > & customParserCache() const
const QV4::CompiledData::Unit * qmlUnit() const
QmlIR::Object * objectAt(int index)
QQmlType qmlTypeForComponent(const QString &inlineComponentName=QString()) const
QmlIR::PoolList< QmlIR::Function >::Iterator objectFunctionsEnd(const QmlIR::Object *object) const
QQmlPropertyCacheVector * propertyCaches()
QQmlJS::MemoryPool * memoryPool()
QV4::ResolvedTypeReferenceMap * resolvedTypes
QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const
ListPropertyAssignBehavior listPropertyAssignBehavior() const
QQmlRefPointer< QV4::ExecutableCompilationUnit > compile()
int registerString(const QString &str)
const QV4::Compiler::StringTableGenerator * stringPool() const
void recordError(const QV4::CompiledData::Location &location, const QString &description)
QStringView newStringRef(const QString &string)
QmlIR::Binding CompiledBinding
void addImport(const QString &module, const QString &qualifier, QTypeRevision version)
QVector< QmlIR::Object * > * qmlObjects() const
QString stringAt(int idx) const
const QQmlImports * imports() const