OpenCoverage

qqmltypecompiler_p.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/compiler/qqmltypecompiler_p.h
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the tools applications of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39#ifndef QQMLTYPECOMPILER_P_H-
40#define QQMLTYPECOMPILER_P_H-
41-
42//-
43// W A R N I N G-
44// --------------
45//-
46// This file is not part of the Qt API. It exists purely as an-
47// implementation detail. This header file may change from version to-
48// version without notice, or even be removed.-
49//-
50// We mean it.-
51//-
52-
53#include <qglobal.h>-
54#include <qqmlerror.h>-
55#include <qhash.h>-
56#include <private/qqmltypeloader_p.h>-
57#include <private/qqmlirbuilder_p.h>-
58#include <private/qqmlpropertycachecreator_p.h>-
59-
60QT_BEGIN_NAMESPACE-
61-
62class QQmlEnginePrivate;-
63class QQmlError;-
64class QQmlTypeData;-
65class QQmlImports;-
66-
67namespace QmlIR {-
68struct Document;-
69}-
70-
71namespace QV4 {-
72namespace CompiledData {-
73struct QmlUnit;-
74struct Location;-
75}-
76}-
77-
78struct QQmlTypeCompiler-
79{-
80 Q_DECLARE_TR_FUNCTIONS(QQmlTypeCompiler)-
81public:-
82 QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlTypeData *typeData, QmlIR::Document *document, const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache,-
83 const QV4::CompiledData::DependentTypesHasher &dependencyHasher);-
84-
85 // --- interface used by QQmlPropertyCacheCreator-
86 typedef QmlIR::Object CompiledObject;-
87 const QmlIR::Object *objectAt(int index) const { return document->objects.at(index); }
executed 71753 times by 141 tests: return document->objects.at(index);
Executed by:
  • tst_bindingdependencyapi
  • tst_drawingmodes
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • ...
71753
88 int objectCount() const { return document->objects.count(); }
executed 48461 times by 141 tests: return document->objects.count();
Executed by:
  • tst_bindingdependencyapi
  • tst_drawingmodes
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • ...
48461
89 QString stringAt(int idx) const;-
90 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsBegin(const QmlIR::Object *object) const { return object->functionsBegin(); }
executed 4594 times by 101 tests: return object->functionsBegin();
Executed by:
  • tst_bindingdependencyapi
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • tst_qqmlitemmodels
  • tst_qqmllistmodel
  • ...
4594
91 QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsEnd(const QmlIR::Object *object) const { return object->functionsEnd(); }
executed 4594 times by 101 tests: return object->functionsEnd();
Executed by:
  • tst_bindingdependencyapi
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • tst_qqmlitemmodels
  • tst_qqmllistmodel
  • ...
4594
92 QV4::CompiledData::ResolvedTypeReferenceMap resolvedTypes;-
93 // ----
94-
95 QQmlRefPointer<QV4::CompiledData::CompilationUnit> compile();-
96-
97 QList<QQmlError> compilationErrors() const { return errors; }
executed 8 times by 2 tests: return errors;
Executed by:
  • tst_qqmlecmascript
  • tst_qqmlpropertymap
8
98 void recordError(QQmlError error);-
99 void recordError(const QV4::CompiledData::Location &location, const QString &description);-
100 void recordError(const QQmlCompileError &error);-
101-
102 int registerString(const QString &str);-
103-
104 const QV4::CompiledData::Unit *qmlUnit() const;-
105-
106 QUrl url() const { return typeData->finalUrl(); }
executed 3835 times by 95 tests: return typeData->finalUrl();
Executed by:
  • tst_bindingdependencyapi
  • tst_examples
  • tst_flickableinterop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • tst_qqmlitemmodels
  • tst_qqmllistmodel
  • tst_qqmllistmodelworkerscript
  • ...
3835
107 QQmlEnginePrivate *enginePrivate() const { return engine; }
executed 146726 times by 141 tests: return engine;
Executed by:
  • tst_bindingdependencyapi
  • tst_drawingmodes
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • ...
146726
108 const QQmlImports *imports() const;-
109 QVector<QmlIR::Object *> *qmlObjects() const;-
110 void setPropertyCaches(QQmlPropertyCacheVector &&caches);-
111 const QQmlPropertyCacheVector *propertyCaches() const;-
112 QQmlPropertyCacheVector &&takePropertyCaches();-
113 void setComponentRoots(const QVector<quint32> &roots) { m_componentRoots = roots; }
executed 48455 times by 141 tests: end of block
Executed by:
  • tst_bindingdependencyapi
  • tst_drawingmodes
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • ...
48455
114 const QVector<quint32> &componentRoots() const { return m_componentRoots; }
executed 48431 times by 140 tests: return m_componentRoots;
Executed by:
  • tst_bindingdependencyapi
  • tst_drawingmodes
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • tst_qqmlitemmodels
  • ...
48431
115 QQmlJS::MemoryPool *memoryPool();-
116 QStringRef newStringRef(const QString &string);-
117 const QV4::Compiler::StringTableGenerator *stringPool() const;-
118 void setBindingPropertyDataPerObject(const QVector<QV4::CompiledData::BindingPropertyData> &propertyData);-
119-
120 const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; }
executed 193800 times by 141 tests: return customParsers;
Executed by:
  • tst_bindingdependencyapi
  • tst_drawingmodes
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • ...
193800
121-
122 QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const;-
123-
124 void addImport(const QString &module, const QString &qualifier, int majorVersion, int minorVersion);-
125-
126private:-
127 QList<QQmlError> errors;-
128 QQmlEnginePrivate *engine;-
129 QQmlTypeData *typeData;-
130 const QV4::CompiledData::DependentTypesHasher &dependencyHasher;-
131 QQmlRefPointer<QQmlTypeNameCache> typeNameCache;-
132 QmlIR::Document *document;-
133 // index is string index of type name (use obj->inheritedTypeNameIndex)-
134 QHash<int, QQmlCustomParser*> customParsers;-
135-
136 // index in first hash is component index, vector inside contains object indices of objects with id property-
137 QVector<quint32> m_componentRoots;-
138 QQmlPropertyCacheVector m_propertyCaches;-
139};-
140-
141struct QQmlCompilePass-
142{-
143 QQmlCompilePass(QQmlTypeCompiler *typeCompiler);-
144-
145 QString stringAt(int idx) const { return compiler->stringAt(idx); }
executed 628669 times by 141 tests: return compiler->stringAt(idx);
Executed by:
  • tst_bindingdependencyapi
  • tst_drawingmodes
  • tst_examples
  • tst_flickableinterop
  • tst_multipointtoucharea_interop
  • tst_parserstress
  • tst_qjsengine
  • tst_qmlcachegen
  • tst_qmldiskcache
  • tst_qqmlapplicationengine
  • tst_qqmlbinding
  • tst_qqmlcomponent
  • tst_qqmlconnections
  • tst_qqmlconsole
  • tst_qqmlcontext
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmlenginecleanup
  • tst_qqmlenginedebugservice
  • tst_qqmlexpression
  • tst_qqmlfileselector
  • tst_qqmlimport
  • tst_qqmlincubator
  • tst_qqmlinfo
  • tst_qqmlinstantiator
  • ...
628669
146protected:-
147 void recordError(const QV4::CompiledData::Location &location, const QString &description) const-
148 { compiler->recordError(location, description); }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qqmlecmascript
4
149 void recordError(const QQmlCompileError &error)-
150 { compiler->recordError(error); }
never executed: end of block
0
151-
152 QQmlTypeCompiler *compiler;-
153};-
154-
155// "Converts" signal expressions to full-fleged function declarations with-
156// parameters taken from the signal declarations-
157// It also updates the QV4::CompiledData::Binding objects to set the property name-
158// to the final signal name (onTextChanged -> textChanged) and sets the IsSignalExpression flag.-
159struct SignalHandlerConverter : public QQmlCompilePass-
160{-
161 Q_DECLARE_TR_FUNCTIONS(SignalHandlerConverter)-
162public:-
163 SignalHandlerConverter(QQmlTypeCompiler *typeCompiler);-
164-
165 bool convertSignalHandlerExpressionsToFunctionDeclarations();-
166-
167private:-
168 bool convertSignalHandlerExpressionsToFunctionDeclarations(const QmlIR::Object *obj, const QString &typeName, QQmlPropertyCache *propertyCache);-
169-
170 QQmlEnginePrivate *enginePrivate;-
171 const QVector<QmlIR::Object*> &qmlObjects;-
172 const QQmlImports *imports;-
173 const QHash<int, QQmlCustomParser*> &customParsers;-
174 const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypes;-
175 const QSet<QString> &illegalNames;-
176 const QQmlPropertyCacheVector * const propertyCaches;-
177};-
178-
179// ### This will go away when the codegen resolves all enums to constant expressions-
180// and we replace the constant expression with a literal binding instead of using-
181// a script.-
182class QQmlEnumTypeResolver : public QQmlCompilePass-
183{-
184 Q_DECLARE_TR_FUNCTIONS(QQmlEnumTypeResolver)-
185public:-
186 QQmlEnumTypeResolver(QQmlTypeCompiler *typeCompiler);-
187-
188 bool resolveEnumBindings();-
189-
190private:-
191 bool assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &enumName, int enumValue, bool isQtObject);-
192 bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)-
193 {-
194 return assignEnumToBinding(binding, QStringRef(&enumName), enumValue, isQtObject);
never executed: return assignEnumToBinding(binding, QStringRef(&enumName), enumValue, isQtObject);
0
195 }-
196 bool tryQualifiedEnumAssignment(const QmlIR::Object *obj, const QQmlPropertyCache *propertyCache,-
197 const QQmlPropertyData *prop,-
198 QmlIR::Binding *binding);-
199 int evaluateEnum(const QString &scope, const QStringRef &enumName, const QStringRef &enumValue, bool *ok) const;-
200-
201-
202 const QVector<QmlIR::Object*> &qmlObjects;-
203 const QQmlPropertyCacheVector * const propertyCaches;-
204 const QQmlImports *imports;-
205 QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypes;-
206};-
207-
208class QQmlCustomParserScriptIndexer: public QQmlCompilePass-
209{-
210public:-
211 QQmlCustomParserScriptIndexer(QQmlTypeCompiler *typeCompiler);-
212-
213 void annotateBindingsWithScriptStrings();-
214-
215private:-
216 void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false);-
217-
218 const QVector<QmlIR::Object*> &qmlObjects;-
219 const QHash<int, QQmlCustomParser*> &customParsers;-
220};-
221-
222// Annotate properties bound to aliases with a flag-
223class QQmlAliasAnnotator : public QQmlCompilePass-
224{-
225public:-
226 QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler);-
227-
228 void annotateBindingsToAliases();-
229private:-
230 const QVector<QmlIR::Object*> &qmlObjects;-
231 const QQmlPropertyCacheVector * const propertyCaches;-
232};-
233-
234class QQmlScriptStringScanner : public QQmlCompilePass-
235{-
236public:-
237 QQmlScriptStringScanner(QQmlTypeCompiler *typeCompiler);-
238-
239 void scan();-
240-
241private:-
242 const QVector<QmlIR::Object*> &qmlObjects;-
243 const QQmlPropertyCacheVector * const propertyCaches;-
244};-
245-
246class QQmlComponentAndAliasResolver : public QQmlCompilePass-
247{-
248 Q_DECLARE_TR_FUNCTIONS(QQmlAnonymousComponentResolver)-
249public:-
250 QQmlComponentAndAliasResolver(QQmlTypeCompiler *typeCompiler);-
251-
252 bool resolve();-
253-
254protected:-
255 void findAndRegisterImplicitComponents(const QmlIR::Object *obj, QQmlPropertyCache *propertyCache);-
256 bool collectIdsAndAliases(int objectIndex);-
257 bool resolveAliases(int componentIndex);-
258 void propertyDataForAlias(QmlIR::Alias *alias, int *type, quint32 *propertyFlags);-
259-
260 enum AliasResolutionResult {-
261 NoAliasResolved,-
262 SomeAliasesResolved,-
263 AllAliasesResolved-
264 };-
265-
266 AliasResolutionResult resolveAliasesInObject(int objectIndex, QQmlCompileError *error);-
267-
268 QQmlEnginePrivate *enginePrivate;-
269 QQmlJS::MemoryPool *pool;-
270-
271 QVector<QmlIR::Object*> *qmlObjects;-
272-
273 // indices of the objects that are actually Component {}-
274 QVector<quint32> componentRoots;-
275-
276 // Deliberate choice of map over hash here to ensure stable generated output.-
277 QMap<int, int> _idToObjectIndex;-
278 QVector<int> _objectsWithAliases;-
279-
280 QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypes;-
281 QQmlPropertyCacheVector propertyCaches;-
282};-
283-
284class QQmlDeferredAndCustomParserBindingScanner : public QQmlCompilePass-
285{-
286public:-
287 QQmlDeferredAndCustomParserBindingScanner(QQmlTypeCompiler *typeCompiler);-
288-
289 bool scanObject();-
290-
291private:-
292 bool scanObject(int objectIndex);-
293-
294 QVector<QmlIR::Object*> *qmlObjects;-
295 const QQmlPropertyCacheVector * const propertyCaches;-
296 const QHash<int, QQmlCustomParser*> &customParsers;-
297-
298 bool _seenObjectWithId;-
299};-
300-
301// ### merge with QtQml::JSCodeGen and operate directly on object->functionsAndExpressions once old compiler is gone.-
302class QQmlJSCodeGenerator : public QQmlCompilePass-
303{-
304public:-
305 QQmlJSCodeGenerator(QQmlTypeCompiler *typeCompiler, QmlIR::JSCodeGen *v4CodeGen);-
306-
307 bool generateCodeForComponents();-
308-
309private:-
310 bool compileComponent(int componentRoot);-
311 bool compileJavaScriptCodeInObjectsRecursively(int objectIndex, int scopeObjectIndex);-
312-
313 const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypes;-
314 const QHash<int, QQmlCustomParser*> &customParsers;-
315 const QVector<QmlIR::Object*> &qmlObjects;-
316 const QQmlPropertyCacheVector * const propertyCaches;-
317 QmlIR::JSCodeGen * const v4CodeGen;-
318};-
319-
320class QQmlDefaultPropertyMerger : public QQmlCompilePass-
321{-
322public:-
323 QQmlDefaultPropertyMerger(QQmlTypeCompiler *typeCompiler);-
324-
325 void mergeDefaultProperties();-
326-
327private:-
328 void mergeDefaultProperties(int objectIndex);-
329-
330 const QVector<QmlIR::Object*> &qmlObjects;-
331 const QQmlPropertyCacheVector * const propertyCaches;-
332};-
333-
334QT_END_NAMESPACE-
335-
336#endif // QQMLTYPECOMPILER_P_H-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0