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
64 {
65 return document->objects.at(resolvedIndex(index));
66 }
67
68 QmlIR::Object *objectAt(int index)
69 {
70 return document->objects.at(resolvedIndex(index));
71 }
72
73 int objectCount() const { return document->objects.size(); }
74 int resolvedIndex(int index) const;
75 int implicitComponentForObject(int childIndex) const;
76 QString stringAt(int idx) const;
77 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsBegin(const QmlIR::Object *object) const { return object->functionsBegin(); }
81 {
82 for (const QmlIR::Pragma *pragma: document->pragmas) {
83 if (pragma->type == QmlIR::Pragma::ListPropertyAssignBehavior)
84 return pragma->listPropertyAssignBehavior;
85 }
86 return ListPropertyAssignBehavior::Append;
87 }
88 // ---
89
91
92 QList<QQmlError> compilationErrors() const { return errors; }
93 void recordError(const QV4::CompiledData::Location &location, const QString &description);
94 void recordError(const QQmlJS::DiagnosticMessage &message);
95 void recordError(const QQmlError &e);
96
97 int registerString(const QString &str);
98 int registerConstant(QV4::ReturnedValue v);
99
100 const QV4::CompiledData::Unit *qmlUnit() const;
101
102 QUrl url() const { return typeData->finalUrl(); }
103 QQmlTypeLoader *typeLoader() const { return loader; }
104 const QQmlImports *imports() const;
105 QList<QmlIR::Object *> *qmlObjects() const;
109 QStringView newStringRef(const QString &string);
111
112 const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; }
113
114 QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const;
115
116 void addImport(const QString &module, const QString &qualifier, QTypeRevision version);
117
119 {
120 return resolvedTypes->value(id);
121 }
122
123 QV4::ResolvedTypeReference *resolvedType(QMetaType type) const
124 {
125 for (QV4::ResolvedTypeReference *ref : std::as_const(*resolvedTypes)) {
126 if (ref->type().typeId() == type)
127 return ref;
128 }
129 return nullptr;
130 }
131
132 QQmlType qmlTypeForComponent(const QString &inlineComponentName = QString()) const;
133
134private:
135 QList<QQmlError> errors;
136 QQmlTypeLoader *loader;
137 const QV4::CompiledData::DependentTypesHasher &dependencyHasher;
138 QmlIR::Document *document;
139 // index is string index of type name (use obj->inheritedTypeNameIndex)
140 QHash<int, QQmlCustomParser*> customParsers;
141
142 // index in first hash is component index, vector inside contains object indices of objects with id property
143 QQmlPropertyCacheVector m_propertyCaches;
144
145 QQmlTypeData *typeData;
146};
147
149{
150 QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
151
152 QString stringAt(int idx) const { return compiler->stringAt(idx); }
153protected:
154 void recordError(const QV4::CompiledData::Location &location, const QString &description) const
155 { compiler->recordError(location, description); }
156
158 { return compiler->resolvedType(id); }
159
161};
162
163// Resolves signal handlers. Updates the QV4::CompiledData::Binding objects to
164// set the property name to the final signal name (onTextChanged -> textChanged)
165// and sets the IsSignalExpression flag.
167{
169public:
171
173
174private:
175 bool resolveSignalHandlerExpressions(
176 const QmlIR::Object *obj, const QString &typeName,
177 const QQmlPropertyCache::ConstPtr &propertyCache,
178 QQmlPropertyResolver::RevisionCheck revisionCheck
179 = QQmlPropertyResolver::CheckRevision);
180
181 QQmlTypeLoader *typeLoader;
182 const QList<QmlIR::Object*> &qmlObjects;
183 const QQmlImports *imports;
184 const QHash<int, QQmlCustomParser*> &customParsers;
185 const QQmlPropertyCacheVector * const propertyCaches;
186};
187
188// ### This will go away when the codegen resolves all enums to constant expressions
189// and we replace the constant expression with a literal binding instead of using
190// a script.
192{
194public:
196
197 bool resolveEnumBindings();
198
199private:
200 bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject);
201 bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
202 {
203 return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject);
204 }
205 bool tryQualifiedEnumAssignment(
206 const QmlIR::Object *obj, const QQmlPropertyCache::ConstPtr &propertyCache,
207 const QQmlPropertyData *prop, QmlIR::Binding *binding);
208 int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const;
209
210
211 const QList<QmlIR::Object*> &qmlObjects;
212 const QQmlPropertyCacheVector * const propertyCaches;
213 const QQmlImports *imports;
214};
215
217{
218public:
220
222
223private:
224 void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false);
225
226 const QList<QmlIR::Object*> &qmlObjects;
227 const QHash<int, QQmlCustomParser*> &customParsers;
228};
229
230// Annotate properties bound to aliases with a flag
232{
233public:
235
237private:
238 const QList<QmlIR::Object*> &qmlObjects;
239 const QQmlPropertyCacheVector * const propertyCaches;
240};
241
243{
244public:
246
247 void scan();
248
249private:
250 const QList<QmlIR::Object*> &qmlObjects;
251 const QQmlPropertyCacheVector * const propertyCaches;
252};
253
255{
257public:
259
260 bool scanObject();
261
262private:
263 enum class ScopeDeferred { False, True };
264 bool scanObject(int objectIndex, ScopeDeferred scopeDeferred);
265
266 QList<QmlIR::Object*> *qmlObjects;
267 const QQmlPropertyCacheVector * const propertyCaches;
268 const QHash<int, QQmlCustomParser*> &customParsers;
269
270 bool _seenObjectWithId;
271};
272
273QT_END_NAMESPACE
274
275#endif // QQMLTYPECOMPILER_P_H
QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler)
QQmlCustomParserScriptIndexer(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 implicitComponentForObject(int childIndex) 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)
int resolvedIndex(int index) const
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