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// Qt-Security score:significant
4
5#ifndef QQMLTYPECOMPILER_P_H
6#define QQMLTYPECOMPILER_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 <qglobal.h>
20#include <qqmlerror.h>
21#include <qhash.h>
22#include <private/qqmltypeloader_p.h>
23#include <private/qqmlirbuilder_p.h>
24#include <private/qqmlpropertyresolver_p.h>
25#include <private/qqmlpropertycachecreator_p.h>
26
28
30class QQmlError;
31class QQmlTypeData;
32class QQmlImports;
33
34namespace QmlIR {
35struct Document;
36}
37
38namespace QV4 {
39namespace CompiledData {
40struct QmlUnit;
41struct Location;
42}
43}
44
46{
48public:
54
55 // --- interface used by QQmlPropertyCacheCreator
59
60 // Deliberate choice of map over hash here to ensure stable generated output.
61 using IdToObjectMap = QMap<int, int>;
62
63 const QmlIR::Object *objectAt(int index) const { return document->objects.at(index); }
64 QmlIR::Object *objectAt(int index) { return document->objects.at(index); }
65 int objectCount() const { return document->objects.size(); }
66 QString stringAt(int idx) const;
67 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsBegin(const QmlIR::Object *object) const { return object->functionsBegin(); }
71 {
72 for (const QmlIR::Pragma *pragma: document->pragmas) {
73 if (pragma->type == QmlIR::Pragma::ListPropertyAssignBehavior)
74 return pragma->listPropertyAssignBehavior;
75 }
76 return ListPropertyAssignBehavior::Append;
77 }
78 // ---
79
81
82 QList<QQmlError> compilationErrors() const { return errors; }
83 void recordError(const QV4::CompiledData::Location &location, const QString &description);
84 void recordError(const QQmlJS::DiagnosticMessage &message);
85 void recordError(const QQmlError &e);
86
87 int registerString(const QString &str);
88 int registerConstant(QV4::ReturnedValue v);
89
90 const QV4::CompiledData::Unit *qmlUnit() const;
91
92 QUrl url() const { return typeData->finalUrl(); }
93 QQmlTypeLoader *typeLoader() const { return loader; }
94 const QQmlImports *imports() const;
95 QList<QmlIR::Object *> *qmlObjects() const;
99 QStringView newStringRef(const QString &string);
101
102 const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; }
103
104 QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const;
105
106 void addImport(const QString &module, const QString &qualifier, QTypeRevision version);
107
109 {
110 return resolvedTypes->value(id);
111 }
112
113 QV4::ResolvedTypeReference *resolvedType(QMetaType type) const
114 {
115 for (QV4::ResolvedTypeReference *ref : std::as_const(*resolvedTypes)) {
116 if (ref->type().typeId() == type)
117 return ref;
118 }
119 return nullptr;
120 }
121
122 QQmlType qmlTypeForComponent(const QString &inlineComponentName = QString()) const;
123
124private:
125 QList<QQmlError> errors;
126 QQmlTypeLoader *loader;
127 const QV4::CompiledData::DependentTypesHasher &dependencyHasher;
128 QmlIR::Document *document;
129 // index is string index of type name (use obj->inheritedTypeNameIndex)
130 QHash<int, QQmlCustomParser*> customParsers;
131
132 // index in first hash is component index, vector inside contains object indices of objects with id property
133 QQmlPropertyCacheVector m_propertyCaches;
134
135 QQmlTypeData *typeData;
136};
137
139{
140 QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
141
142 QString stringAt(int idx) const { return compiler->stringAt(idx); }
143protected:
144 void recordError(const QV4::CompiledData::Location &location, const QString &description) const
145 { compiler->recordError(location, description); }
146
148 { return compiler->resolvedType(id); }
149
151};
152
153// Resolves signal handlers. Updates the QV4::CompiledData::Binding objects to
154// set the property name to the final signal name (onTextChanged -> textChanged)
155// and sets the IsSignalExpression flag.
157{
159public:
161
163
164private:
165 bool resolveSignalHandlerExpressions(
166 const QmlIR::Object *obj, const QString &typeName,
167 const QQmlPropertyCache::ConstPtr &propertyCache,
168 QQmlPropertyResolver::RevisionCheck revisionCheck
169 = QQmlPropertyResolver::CheckRevision);
170
171 QQmlTypeLoader *typeLoader;
172 const QList<QmlIR::Object*> &qmlObjects;
173 const QQmlImports *imports;
174 const QHash<int, QQmlCustomParser*> &customParsers;
175 const QQmlPropertyCacheVector * const propertyCaches;
176};
177
178// ### This will go away when the codegen resolves all enums to constant expressions
179// and we replace the constant expression with a literal binding instead of using
180// a script.
182{
184public:
186
187 bool resolveEnumBindings();
188
189private:
190 bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject);
191 bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
192 {
193 return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject);
194 }
195 bool tryQualifiedEnumAssignment(
196 const QmlIR::Object *obj, const QQmlPropertyCache::ConstPtr &propertyCache,
197 const QQmlPropertyData *prop, QmlIR::Binding *binding);
198 int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const;
199
200
201 const QList<QmlIR::Object*> &qmlObjects;
202 const QQmlPropertyCacheVector * const propertyCaches;
203 const QQmlImports *imports;
204};
205
207{
208public:
210
212
213private:
214 void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false);
215
216 const QList<QmlIR::Object*> &qmlObjects;
217 const QHash<int, QQmlCustomParser*> &customParsers;
218};
219
220// Annotate properties bound to aliases with a flag
222{
223public:
225
227private:
228 const QList<QmlIR::Object*> &qmlObjects;
229 const QQmlPropertyCacheVector * const propertyCaches;
230};
231
233{
234public:
236
237 void scan();
238
239private:
240 const QList<QmlIR::Object*> &qmlObjects;
241 const QQmlPropertyCacheVector * const propertyCaches;
242};
243
245{
247public:
249
250 bool scanObject();
251
252private:
253 enum class ScopeDeferred { False, True };
254 bool scanObject(int objectIndex, ScopeDeferred scopeDeferred);
255
256 QList<QmlIR::Object*> *qmlObjects;
257 const QQmlPropertyCacheVector * const propertyCaches;
258 const QHash<int, QQmlCustomParser*> &customParsers;
259
260 bool _seenObjectWithId;
261};
262
264{
265public:
267
269
270private:
271 void mergeDefaultProperties(int objectIndex);
272
273 const QList<QmlIR::Object*> &qmlObjects;
274 const QQmlPropertyCacheVector * const propertyCaches;
275};
276
277QT_END_NAMESPACE
278
279#endif // QQMLTYPECOMPILER_P_H
QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler)
QQmlCustomParserScriptIndexer(QQmlTypeCompiler *typeCompiler)
QQmlDefaultPropertyMerger(QQmlTypeCompiler *typeCompiler)
friend class QQmlEnginePrivate
QQmlScriptStringScanner(QQmlTypeCompiler *typeCompiler)
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#define COMPILE_EXCEPTION(location, desc)
static bool resolveDeepAlias(QQmlTypeCompiler *compiler, const QmlIR::Object *targetObject, QStringView property, QStringView subProperty, QQmlPropertyIndex &propIdx, QMetaType targetPropertyType, const QQmlPropertyCacheVector *propertyCaches, const QMap< int, int > &idToObjectIndex)
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
QList< QmlIR::Object * > * qmlObjects() 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()
QString stringAt(int idx) const
const QQmlImports * imports() const