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;
33class QTypeRevision;
34
35namespace QmlIR {
36struct Document;
37}
38
39namespace QV4 {
40namespace CompiledData {
41struct QmlUnit;
42struct Location;
43}
44}
45
47{
49public:
55
56 // --- interface used by QQmlPropertyCacheCreator
60
61 // Deliberate choice of map over hash here to ensure stable generated output.
62 using IdToObjectMap = QMap<int, int>;
63
64 const QmlIR::Object *objectAt(int index) const
65 {
66 return document->objects.at(resolvedIndex(index));
67 }
68
69 QmlIR::Object *objectAt(int index)
70 {
71 return document->objects.at(resolvedIndex(index));
72 }
73
74 int objectCount() const { return document->objects.size(); }
75 int resolvedIndex(int index) const;
76 int implicitComponentForObject(int childIndex) const;
77 QString stringAt(int idx) const;
78 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsBegin(const QmlIR::Object *object) const { return object->functionsBegin(); }
82 {
83 for (const QmlIR::Pragma *pragma: document->pragmas) {
84 if (pragma->type == QmlIR::Pragma::ListPropertyAssignBehavior)
85 return pragma->listPropertyAssignBehavior;
86 }
87 return ListPropertyAssignBehavior::Append;
88 }
89 // ---
90
92
93 QList<QQmlError> compilationErrors() const { return errors; }
94 void recordError(const QV4::CompiledData::Location &location, const QString &description);
95 void recordError(const QQmlJS::DiagnosticMessage &message);
96 void recordError(const QQmlError &e);
97
98 int registerString(const QString &str);
99 int registerConstant(QV4::ReturnedValue v);
100
101 const QV4::CompiledData::Unit *qmlUnit() const;
102
103 QUrl url() const { return typeData->finalUrl(); }
104 QQmlTypeLoader *typeLoader() const { return loader; }
105 const QQmlImports *imports() const;
106 QList<QmlIR::Object *> *qmlObjects() const;
110 QStringView newStringRef(const QString &string);
112
113 const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; }
114
115 QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const;
116
117 void addImport(const QString &module, const QString &qualifier, QTypeRevision version);
118
120 {
121 return resolvedTypes->value(id);
122 }
123
124 QV4::ResolvedTypeReference *resolvedType(QMetaType type) const
125 {
126 for (QV4::ResolvedTypeReference *ref : std::as_const(*resolvedTypes)) {
127 if (ref->type().typeId() == type)
128 return ref;
129 }
130 return nullptr;
131 }
132
133 QQmlType qmlTypeForComponent(const QString &inlineComponentName = QString()) const;
134
135private:
136 QList<QQmlError> errors;
137 QQmlTypeLoader *loader;
138 const QV4::CompiledData::DependentTypesHasher &dependencyHasher;
139 QmlIR::Document *document;
140 // index is string index of type name (use obj->inheritedTypeNameIndex)
141 QHash<int, QQmlCustomParser*> customParsers;
142
143 // index in first hash is component index, vector inside contains object indices of objects with id property
144 QQmlPropertyCacheVector m_propertyCaches;
145
146 QQmlTypeData *typeData;
147};
148
150{
151 QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
152
153 QString stringAt(int idx) const { return compiler->stringAt(idx); }
154protected:
155 void recordError(const QV4::CompiledData::Location &location, const QString &description) const
156 { compiler->recordError(location, description); }
157
159 { return compiler->resolvedType(id); }
160
162};
163
164// Resolves signal handlers. Updates the QV4::CompiledData::Binding objects to
165// set the property name to the final signal name (onTextChanged -> textChanged)
166// and sets the IsSignalExpression flag.
168{
170public:
172
174
175private:
176 bool resolveSignalHandlerExpressions(
177 const QmlIR::Object *obj, const QString &typeName,
178 const QQmlPropertyCache::ConstPtr &propertyCache,
179 QQmlPropertyResolver::RevisionCheck revisionCheck
180 = QQmlPropertyResolver::CheckRevision);
181
182 QQmlTypeLoader *typeLoader;
183 const QList<QmlIR::Object*> &qmlObjects;
184 const QQmlImports *imports;
185 const QHash<int, QQmlCustomParser*> &customParsers;
186 const QQmlPropertyCacheVector * const propertyCaches;
187};
188
189// ### This will go away when the codegen resolves all enums to constant expressions
190// and we replace the constant expression with a literal binding instead of using
191// a script.
193{
195public:
197
198 bool resolveEnumBindings();
199
200private:
201 bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject);
202 bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
203 {
204 return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject);
205 }
206 bool tryQualifiedEnumAssignment(
207 const QmlIR::Object *obj, const QQmlPropertyCache::ConstPtr &propertyCache,
208 const QQmlPropertyData *prop, QmlIR::Binding *binding);
209 int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const;
210
211
212 const QList<QmlIR::Object*> &qmlObjects;
213 const QQmlPropertyCacheVector * const propertyCaches;
214 const QQmlImports *imports;
215};
216
218{
219public:
221
223
224private:
225 void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false);
226
227 const QList<QmlIR::Object*> &qmlObjects;
228 const QHash<int, QQmlCustomParser*> &customParsers;
229};
230
231// Annotate properties bound to aliases with a flag
233{
234public:
236
238private:
239 const QList<QmlIR::Object*> &qmlObjects;
240 const QQmlPropertyCacheVector * const propertyCaches;
241};
242
244{
245public:
247
248 void scan();
249
250private:
251 const QList<QmlIR::Object*> &qmlObjects;
252 const QQmlPropertyCacheVector * const propertyCaches;
253};
254
256{
258public:
260
261 bool scanObject();
262
263private:
264 enum class ScopeDeferred { False, True };
265 bool scanObject(int objectIndex, ScopeDeferred scopeDeferred);
266
267 QList<QmlIR::Object*> *qmlObjects;
268 const QQmlPropertyCacheVector * const propertyCaches;
269 const QHash<int, QQmlCustomParser*> &customParsers;
270
271 bool _seenObjectWithId;
272};
273
274QT_END_NAMESPACE
275
276#endif // QQMLTYPECOMPILER_P_H
QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler)
QQmlCustomParserScriptIndexer(QQmlTypeCompiler *typeCompiler)
friend class QQmlEnginePrivate
QQmlScriptStringScanner(QQmlTypeCompiler *typeCompiler)
\inmodule QtCore
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