Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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,
50 const QV4::CompiledData::DependentTypesHasher &dependencyHasher);
51
52 // --- interface used by QQmlPropertyCacheCreator
56
57 // Deliberate choice of map over hash here to ensure stable generated output.
58 using IdToObjectMap = QMap<int, int>;
59
60 const QmlIR::Object *objectAt(int index) const { return document->objects.at(index); }
61 QmlIR::Object *objectAt(int index) { return document->objects.at(index); }
62 int objectCount() const { return document->objects.size(); }
63 QString stringAt(int idx) const;
64 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsBegin(const QmlIR::Object *object) const { return object->functionsBegin(); }
65 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsEnd(const QmlIR::Object *object) const { return object->functionsEnd(); }
68 {
69 for (const QmlIR::Pragma *pragma: document->pragmas) {
71 return pragma->listPropertyAssignBehavior;
72 }
73 return ListPropertyAssignBehavior::Append;
74 }
75 // ---
76
77 QQmlRefPointer<QV4::CompiledData::CompilationUnit> compile();
78
79 QList<QQmlError> compilationErrors() const { return errors; }
80 void recordError(const QV4::CompiledData::Location &location, const QString &description);
82 void recordError(const QQmlError &e);
83
84 int registerString(const QString &str);
86
87 const QV4::CompiledData::Unit *qmlUnit() const;
88
89 QUrl url() const { return typeData->finalUrl(); }
91 const QQmlImports *imports() const;
92 QVector<QmlIR::Object *> *qmlObjects() const;
96 QStringView newStringRef(const QString &string);
98
99 const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; }
100
101 QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const;
102
103 void addImport(const QString &module, const QString &qualifier, QTypeRevision version);
104
106 {
107 return resolvedTypes->value(id);
108 }
109
111 {
112 for (QV4::ResolvedTypeReference *ref : std::as_const(*resolvedTypes)) {
113 if (ref->type().typeId() == type)
114 return ref;
115 }
116 return nullptr;
117 }
118
119 QQmlType qmlTypeForComponent(const QString &inlineComponentName = QString()) const;
120
121private:
122 QList<QQmlError> errors;
124 const QV4::CompiledData::DependentTypesHasher &dependencyHasher;
125 QmlIR::Document *document;
126 // index is string index of type name (use obj->inheritedTypeNameIndex)
127 QHash<int, QQmlCustomParser*> customParsers;
128
129 // index in first hash is component index, vector inside contains object indices of objects with id property
130 QQmlPropertyCacheVector m_propertyCaches;
131
132 QQmlTypeData *typeData;
133};
134
136{
137 QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
138
139 QString stringAt(int idx) const { return compiler->stringAt(idx); }
140protected:
141 void recordError(const QV4::CompiledData::Location &location, const QString &description) const
142 { compiler->recordError(location, description); }
143
146
148};
149
150// Resolves signal handlers. Updates the QV4::CompiledData::Binding objects to
151// set the property name to the final signal name (onTextChanged -> textChanged)
152// and sets the IsSignalExpression flag.
154{
156public:
158
160
161private:
163 const QQmlPropertyCache::ConstPtr &propertyCache);
164
165 QQmlEnginePrivate *enginePrivate;
166 const QVector<QmlIR::Object*> &qmlObjects;
167 const QQmlImports *imports;
168 const QHash<int, QQmlCustomParser*> &customParsers;
169 const QSet<QString> &illegalNames;
170 const QQmlPropertyCacheVector * const propertyCaches;
171};
172
173// ### This will go away when the codegen resolves all enums to constant expressions
174// and we replace the constant expression with a literal binding instead of using
175// a script.
177{
179public:
181
182 bool resolveEnumBindings();
183
184private:
185 bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject);
186 bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
187 {
188 return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject);
189 }
190 bool tryQualifiedEnumAssignment(
191 const QmlIR::Object *obj, const QQmlPropertyCache::ConstPtr &propertyCache,
192 const QQmlPropertyData *prop, QmlIR::Binding *binding);
193 int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const;
194
195
196 const QVector<QmlIR::Object*> &qmlObjects;
197 const QQmlPropertyCacheVector * const propertyCaches;
198 const QQmlImports *imports;
199};
200
202{
203public:
205
207
208private:
209 void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false);
210
211 const QVector<QmlIR::Object*> &qmlObjects;
212 const QHash<int, QQmlCustomParser*> &customParsers;
213};
214
215// Annotate properties bound to aliases with a flag
217{
218public:
220
222private:
223 const QVector<QmlIR::Object*> &qmlObjects;
224 const QQmlPropertyCacheVector * const propertyCaches;
225};
226
228{
229public:
231
232 void scan();
233
234private:
235 const QVector<QmlIR::Object*> &qmlObjects;
236 const QQmlPropertyCacheVector * const propertyCaches;
237};
238
240{
242public:
244
245 bool scanObject();
246
247private:
248 enum class ScopeDeferred { False, True };
249 bool scanObject(int objectIndex, ScopeDeferred scopeDeferred);
250
251 QVector<QmlIR::Object*> *qmlObjects;
252 const QQmlPropertyCacheVector * const propertyCaches;
253 const QHash<int, QQmlCustomParser*> &customParsers;
254
255 bool _seenObjectWithId;
256};
257
259{
260public:
262
264
265private:
266 void mergeDefaultProperties(int objectIndex);
267
268 const QVector<QmlIR::Object*> &qmlObjects;
269 const QQmlPropertyCacheVector * const propertyCaches;
270};
271
273
274#endif // QQMLTYPECOMPILER_P_H
T value(const Key &key) const noexcept
Definition qhash.h:1054
\inmodule QtCore
Definition qmetatype.h:341
QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler)
QQmlCustomParserScriptIndexer(QQmlTypeCompiler *typeCompiler)
QUrl finalUrl() const
Returns the logical URL to be used for resolving further URLs referred to in the code.
QQmlDefaultPropertyMerger(QQmlTypeCompiler *typeCompiler)
QQmlDeferredAndCustomParserBindingScanner(QQmlTypeCompiler *typeCompiler)
QQmlEnumTypeResolver(QQmlTypeCompiler *typeCompiler)
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
The QQmlImports class encapsulates one QML document's import statements.
QQmlScriptStringScanner(QQmlTypeCompiler *typeCompiler)
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
\inmodule QtCore
Definition qurl.h:94
QString str
[2]
Combined button and popup list for selecting options.
std::function< QByteArray()> DependentTypesHasher
quint64 ReturnedValue
#define Q_DECLARE_TR_FUNCTIONS(context)
const char * typeName
GLint location
GLsizei const GLfloat * v
[13]
GLuint index
[2]
GLenum type
GLuint GLsizei const GLchar * message
GLint ref
GLhandleARB obj
[2]
QJSEngine engine
[0]
void recordError(const QV4::CompiledData::Location &location, const QString &description) const
QQmlCompilePass(QQmlTypeCompiler *typeCompiler)
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
QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlTypeData *typeData, QmlIR::Document *document, QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache, const QV4::CompiledData::DependentTypesHasher &dependencyHasher)
QList< QQmlError > compilationErrors() const
const QHash< int, QQmlCustomParser * > & customParserCache() const
QV4::CompiledData::ResolvedTypeReferenceMap * resolvedTypes
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()
QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const
ListPropertyAssignBehavior listPropertyAssignBehavior() const
int registerString(const QString &str)
const QV4::Compiler::StringTableGenerator * stringPool() const
QV4::ResolvedTypeReference * resolvedType(QMetaType type) 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)
QQmlRefPointer< QV4::CompiledData::CompilationUnit > compile()
QVector< QmlIR::Object * > * qmlObjects() const
QString stringAt(int idx) const
const QQmlImports * imports() const
SignalHandlerResolver(QQmlTypeCompiler *typeCompiler)