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
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/qqmlpropertyresolver_p.h>
23#include <private/qqmlpropertycachecreator_p.h>
24
26
28class QQmlError;
29class QQmlTypeData;
30class QQmlImports;
31
32namespace QmlIR {
33struct Document;
34}
35
36namespace QV4 {
37namespace CompiledData {
38struct QmlUnit;
39struct Location;
40}
41}
42
44{
46public:
52
53 // --- interface used by QQmlPropertyCacheCreator
57
58 // Deliberate choice of map over hash here to ensure stable generated output.
59 using IdToObjectMap = QMap<int, int>;
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(); }
69 {
70 for (const QmlIR::Pragma *pragma: document->pragmas) {
71 if (pragma->type == QmlIR::Pragma::ListPropertyAssignBehavior)
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);
82 void recordError(const QQmlJS::DiagnosticMessage &message);
83 void recordError(const QQmlError &e);
84
85 int registerString(const QString &str);
86 int registerConstant(QV4::ReturnedValue v);
87
88 const QV4::CompiledData::Unit *qmlUnit() const;
89
90 QUrl url() const { return typeData->finalUrl(); }
91 QQmlTypeLoader *typeLoader() const { return loader; }
92 const QQmlImports *imports() const;
93 QVector<QmlIR::Object *> *qmlObjects() 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 QV4::ResolvedTypeReference *resolvedType(QMetaType type) const
112 {
113 for (QV4::ResolvedTypeReference *ref : std::as_const(*resolvedTypes)) {
114 if (ref->type().typeId() == type)
115 return ref;
116 }
117 return nullptr;
118 }
119
120 QQmlType qmlTypeForComponent(const QString &inlineComponentName = QString()) const;
121
122private:
123 QList<QQmlError> errors;
124 QQmlTypeLoader *loader;
125 const QV4::CompiledData::DependentTypesHasher &dependencyHasher;
126 QmlIR::Document *document;
127 // index is string index of type name (use obj->inheritedTypeNameIndex)
128 QHash<int, QQmlCustomParser*> customParsers;
129
130 // index in first hash is component index, vector inside contains object indices of objects with id property
131 QQmlPropertyCacheVector m_propertyCaches;
132
133 QQmlTypeData *typeData;
134};
135
137{
138 QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
139
140 QString stringAt(int idx) const { return compiler->stringAt(idx); }
141protected:
142 void recordError(const QV4::CompiledData::Location &location, const QString &description) const
143 { compiler->recordError(location, description); }
144
146 { return compiler->resolvedType(id); }
147
149};
150
151// Resolves signal handlers. Updates the QV4::CompiledData::Binding objects to
152// set the property name to the final signal name (onTextChanged -> textChanged)
153// and sets the IsSignalExpression flag.
155{
157public:
159
161
162private:
163 bool resolveSignalHandlerExpressions(
164 const QmlIR::Object *obj, const QString &typeName,
165 const QQmlPropertyCache::ConstPtr &propertyCache,
166 QQmlPropertyResolver::RevisionCheck revisionCheck
167 = QQmlPropertyResolver::CheckRevision);
168
169 QQmlTypeLoader *typeLoader;
170 const QVector<QmlIR::Object*> &qmlObjects;
171 const QQmlImports *imports;
172 const QHash<int, QQmlCustomParser*> &customParsers;
173 const QQmlPropertyCacheVector * const propertyCaches;
174};
175
176// ### This will go away when the codegen resolves all enums to constant expressions
177// and we replace the constant expression with a literal binding instead of using
178// a script.
180{
182public:
184
185 bool resolveEnumBindings();
186
187private:
188 bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject);
189 bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
190 {
191 return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject);
192 }
193 bool tryQualifiedEnumAssignment(
194 const QmlIR::Object *obj, const QQmlPropertyCache::ConstPtr &propertyCache,
195 const QQmlPropertyData *prop, QmlIR::Binding *binding);
196 int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const;
197
198
199 const QVector<QmlIR::Object*> &qmlObjects;
200 const QQmlPropertyCacheVector * const propertyCaches;
201 const QQmlImports *imports;
202};
203
205{
206public:
208
210
211private:
212 void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false);
213
214 const QVector<QmlIR::Object*> &qmlObjects;
215 const QHash<int, QQmlCustomParser*> &customParsers;
216};
217
218// Annotate properties bound to aliases with a flag
220{
221public:
223
225private:
226 const QVector<QmlIR::Object*> &qmlObjects;
227 const QQmlPropertyCacheVector * const propertyCaches;
228};
229
231{
232public:
234
235 void scan();
236
237private:
238 const QVector<QmlIR::Object*> &qmlObjects;
239 const QQmlPropertyCacheVector * const propertyCaches;
240};
241
243{
245public:
247
248 bool scanObject();
249
250private:
251 enum class ScopeDeferred { False, True };
252 bool scanObject(int objectIndex, ScopeDeferred scopeDeferred);
253
254 QVector<QmlIR::Object*> *qmlObjects;
255 const QQmlPropertyCacheVector * const propertyCaches;
256 const QHash<int, QQmlCustomParser*> &customParsers;
257
258 bool _seenObjectWithId;
259};
260
262{
263public:
265
267
268private:
269 void mergeDefaultProperties(int objectIndex);
270
271 const QVector<QmlIR::Object*> &qmlObjects;
272 const QQmlPropertyCacheVector * const propertyCaches;
273};
274
275QT_END_NAMESPACE
276
277#endif // QQMLTYPECOMPILER_P_H
QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler)
QQmlCustomParserScriptIndexer(QQmlTypeCompiler *typeCompiler)
QQmlDefaultPropertyMerger(QQmlTypeCompiler *typeCompiler)
friend class QQmlEnginePrivate
QQmlScriptStringScanner(QQmlTypeCompiler *typeCompiler)
Definition qjsvalue.h:23
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#define COMPILE_EXCEPTION(location, desc)
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
const QmlIR::Object * objectAt(int index) const
int registerConstant(QV4::ReturnedValue v)
QmlIR::Object CompiledObject
void recordError(const QQmlJS::DiagnosticMessage &message)
QQmlTypeLoader * typeLoader() 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
QQmlPropertyCacheVector * propertyCaches()
QQmlJS::MemoryPool * memoryPool()
void recordError(const QQmlError &e)
QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const
ListPropertyAssignBehavior listPropertyAssignBehavior() const
const QQmlPropertyCacheVector * propertyCaches() const
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)
QQmlRefPointer< QV4::CompiledData::CompilationUnit > compile()
QVector< QmlIR::Object * > * qmlObjects() const
QString stringAt(int idx) const
const QQmlImports * imports() const