Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmltypeloader_p.h |
Source code | Switch to Preprocessed file |
Line | Source | Count |
---|---|---|
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 QtQml module 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 | - | |
40 | #ifndef QQMLTYPELOADER_P_H | - |
41 | #define QQMLTYPELOADER_P_H | - |
42 | - | |
43 | // | - |
44 | // W A R N I N G | - |
45 | // ------------- | - |
46 | // | - |
47 | // This file is not part of the Qt API. It exists purely as an | - |
48 | // implementation detail. This header file may change from version to | - |
49 | // version without notice, or even be removed. | - |
50 | // | - |
51 | // We mean it. | - |
52 | // | - |
53 | - | |
54 | #include <QtQml/qtqmlglobal.h> | - |
55 | #include <QtCore/qobject.h> | - |
56 | #include <QtCore/qatomic.h> | - |
57 | #include <QtCore/qfileinfo.h> | - |
58 | #include <QtCore/qcache.h> | - |
59 | #if QT_CONFIG(qml_network) | - |
60 | #include <QtNetwork/qnetworkreply.h> | - |
61 | #endif | - |
62 | #include <QtQml/qqmlerror.h> | - |
63 | #include <QtQml/qqmlengine.h> | - |
64 | #include <QtQml/qqmlfile.h> | - |
65 | #include <QtQml/qqmlabstracturlinterceptor.h> | - |
66 | - | |
67 | #include <private/qhashedstring_p.h> | - |
68 | #include <private/qqmlimport_p.h> | - |
69 | #include <private/qqmlcleanup_p.h> | - |
70 | #include <private/qqmldirparser_p.h> | - |
71 | #include <private/qflagpointer_p.h> | - |
72 | #include <private/qqmlirbuilder_p.h> | - |
73 | - | |
74 | #include <private/qv4value_p.h> | - |
75 | #include <private/qv4script_p.h> | - |
76 | - | |
77 | QT_BEGIN_NAMESPACE | - |
78 | - | |
79 | class QQmlScriptData; | - |
80 | class QQmlScriptBlob; | - |
81 | class QQmlQmldirData; | - |
82 | class QQmlTypeLoader; | - |
83 | class QQmlComponentPrivate; | - |
84 | class QQmlTypeData; | - |
85 | class QQmlTypeLoader; | - |
86 | class QQmlExtensionInterface; | - |
87 | class QQmlProfiler; | - |
88 | struct QQmlCompileError; | - |
89 | - | |
90 | namespace QmlIR { | - |
91 | struct Document; | - |
92 | } | - |
93 | - | |
94 | class Q_QML_PRIVATE_EXPORT QQmlDataBlob : public QQmlRefCount | - |
95 | { | - |
96 | public: | - |
97 | enum Status { | - |
98 | Null, // Prior to QQmlTypeLoader::load() | - |
99 | Loading, // Prior to data being received and dataReceived() being called | - |
100 | WaitingForDependencies, // While there are outstanding addDependency()s | - |
101 | ResolvingDependencies, // While resolving outstanding dependencies, to detect cycles | - |
102 | Complete, // Finished | - |
103 | Error // Error | - |
104 | }; | - |
105 | - | |
106 | enum Type { //Matched in QQmlAbstractUrlInterceptor | - |
107 | QmlFile = QQmlAbstractUrlInterceptor::QmlFile, | - |
108 | JavaScriptFile = QQmlAbstractUrlInterceptor::JavaScriptFile, | - |
109 | QmldirFile = QQmlAbstractUrlInterceptor::QmldirFile | - |
110 | }; | - |
111 | - | |
112 | QQmlDataBlob(const QUrl &, Type, QQmlTypeLoader* manager); | - |
113 | ~QQmlDataBlob() override; | - |
114 | - | |
115 | void startLoading(); | - |
116 | - | |
117 | QQmlTypeLoader *typeLoader() const { return m_typeLoader; } executed 489193 times by 142 tests: return m_typeLoader; Executed by:
| 489193 |
118 | - | |
119 | Type type() const; | - |
120 | - | |
121 | Status status() const; | - |
122 | bool isNull() const; | - |
123 | bool isLoading() const; | - |
124 | bool isWaiting() const; | - |
125 | bool isComplete() const; | - |
126 | bool isError() const; | - |
127 | bool isCompleteOrError() const; | - |
128 | - | |
129 | qreal progress() const; | - |
130 | - | |
131 | QUrl url() const; | - |
132 | QString urlString() const; | - |
133 | QUrl finalUrl() const; | - |
134 | QString finalUrlString() const; | - |
135 | - | |
136 | QList<QQmlError> errors() const; | - |
137 | - | |
138 | class SourceCodeData { | - |
139 | public: | - |
140 | QString readAll(QString *error) const; | - |
141 | QDateTime sourceTimeStamp() const; | - |
142 | bool exists() const; | - |
143 | bool isEmpty() const; | - |
144 | private: | - |
145 | friend class QQmlDataBlob; | - |
146 | friend class QQmlTypeLoader; | - |
147 | QString inlineSourceCode; | - |
148 | QFileInfo fileInfo; | - |
149 | bool hasInlineSourceCode = false; | - |
150 | }; | - |
151 | - | |
152 | protected: | - |
153 | // Can be called from within callbacks | - |
154 | void setError(const QQmlError &); | - |
155 | void setError(const QList<QQmlError> &errors); | - |
156 | void setError(const QQmlCompileError &error); | - |
157 | void setError(const QVector<QQmlCompileError> &errors); | - |
158 | void setError(const QString &description); | - |
159 | void addDependency(QQmlDataBlob *); | - |
160 | - | |
161 | // Callbacks made in load thread | - |
162 | virtual void dataReceived(const SourceCodeData &) = 0; | - |
163 | virtual void initializeFromCachedUnit(const QV4::CompiledData::Unit*) = 0; | - |
164 | virtual void done(); | - |
165 | #if QT_CONFIG(qml_network) | - |
166 | virtual void networkError(QNetworkReply::NetworkError); | - |
167 | #endif | - |
168 | virtual void dependencyError(QQmlDataBlob *); | - |
169 | virtual void dependencyComplete(QQmlDataBlob *); | - |
170 | virtual void allDependenciesDone(); | - |
171 | - | |
172 | // Callbacks made in main thread | - |
173 | virtual void downloadProgressChanged(qreal); | - |
174 | virtual void completed(); | - |
175 | - | |
176 | protected: | - |
177 | // Manager that is currently fetching data for me | - |
178 | QQmlTypeLoader *m_typeLoader; | - |
179 | - | |
180 | private: | - |
181 | friend class QQmlTypeLoader; | - |
182 | friend class QQmlTypeLoaderThread; | - |
183 | - | |
184 | void tryDone(); | - |
185 | void cancelAllWaitingFor(); | - |
186 | void notifyAllWaitingOnMe(); | - |
187 | void notifyComplete(QQmlDataBlob *); | - |
188 | - | |
189 | struct ThreadData { | - |
190 | inline ThreadData(); | - |
191 | inline QQmlDataBlob::Status status() const; | - |
192 | inline void setStatus(QQmlDataBlob::Status); | - |
193 | inline bool isAsync() const; | - |
194 | inline void setIsAsync(bool); | - |
195 | inline quint8 progress() const; | - |
196 | inline void setProgress(quint8); | - |
197 | - | |
198 | private: | - |
199 | QAtomicInt _p; | - |
200 | }; | - |
201 | ThreadData m_data; | - |
202 | - | |
203 | // m_errors should *always* be written before the status is set to Error. | - |
204 | // We use the status change as a memory fence around m_errors so that locking | - |
205 | // isn't required. Once the status is set to Error (or Complete), m_errors | - |
206 | // cannot be changed. | - |
207 | QList<QQmlError> m_errors; | - |
208 | - | |
209 | Type m_type; | - |
210 | - | |
211 | QUrl m_url; | - |
212 | QUrl m_finalUrl; | - |
213 | mutable QString m_urlString; | - |
214 | mutable QString m_finalUrlString; | - |
215 | - | |
216 | // List of QQmlDataBlob's that are waiting for me to complete. | - |
217 | QList<QQmlDataBlob *> m_waitingOnMe; | - |
218 | - | |
219 | // List of QQmlDataBlob's that I am waiting for to complete. | - |
220 | QVector<QQmlRefPointer<QQmlDataBlob>> m_waitingFor; | - |
221 | - | |
222 | int m_redirectCount:30; | - |
223 | bool m_inCallback:1; | - |
224 | bool m_isDone:1; | - |
225 | }; | - |
226 | - | |
227 | class QQmlTypeLoaderThread; | - |
228 | - | |
229 | class QQmlTypeLoaderQmldirContent | - |
230 | { | - |
231 | private: | - |
232 | friend class QQmlTypeLoader; | - |
233 | - | |
234 | void setContent(const QString &location, const QString &content); | - |
235 | void setError(const QQmlError &); | - |
236 | - | |
237 | public: | - |
238 | QQmlTypeLoaderQmldirContent(); | - |
239 | QQmlTypeLoaderQmldirContent(const QQmlTypeLoaderQmldirContent &) = default; | - |
240 | QQmlTypeLoaderQmldirContent &operator=(const QQmlTypeLoaderQmldirContent &) = default; | - |
241 | - | |
242 | bool hasContent() const { return m_hasContent; } executed 171259 times by 141 tests: return m_hasContent; Executed by:
| 171259 |
243 | bool hasError() const; | - |
244 | QList<QQmlError> errors(const QString &uri) const; | - |
245 | - | |
246 | QString typeNamespace() const; | - |
247 | - | |
248 | QQmlDirComponents components() const; | - |
249 | QQmlDirScripts scripts() const; | - |
250 | QQmlDirPlugins plugins() const; | - |
251 | - | |
252 | QString pluginLocation() const; | - |
253 | - | |
254 | bool designerSupported() const; | - |
255 | - | |
256 | private: | - |
257 | QQmlDirParser m_parser; | - |
258 | QString m_location; | - |
259 | bool m_hasContent = false; | - |
260 | }; | - |
261 | - | |
262 | class Q_QML_PRIVATE_EXPORT QQmlTypeLoader | - |
263 | { | - |
264 | Q_DECLARE_TR_FUNCTIONS(QQmlTypeLoader) | - |
265 | public: | - |
266 | enum Mode { PreferSynchronous, Asynchronous, Synchronous }; | - |
267 | - | |
268 | class Q_QML_PRIVATE_EXPORT Blob : public QQmlDataBlob | - |
269 | { | - |
270 | public: | - |
271 | Blob(const QUrl &url, QQmlDataBlob::Type type, QQmlTypeLoader *loader); | - |
272 | ~Blob() override; | - |
273 | - | |
274 | const QQmlImports &imports() const { return m_importCache; } executed 145432 times by 142 tests: return m_importCache; Executed by:
| 145432 |
275 | - | |
276 | void setCachedUnitStatus(QQmlMetaType::CachedUnitLookupError status) { m_cachedUnitStatus = status; } executed 9660 times by 128 tests: end of block Executed by:
| 9660 |
277 | - | |
278 | protected: | - |
279 | bool addImport(const QV4::CompiledData::Import *import, QList<QQmlError> *errors); | - |
280 | - | |
281 | bool fetchQmldir(const QUrl &url, const QV4::CompiledData::Import *import, int priority, QList<QQmlError> *errors); | - |
282 | bool updateQmldir(const QQmlRefPointer<QQmlQmldirData> &data, const QV4::CompiledData::Import *import, QList<QQmlError> *errors); | - |
283 | - | |
284 | private: | - |
285 | virtual bool qmldirDataAvailable(const QQmlRefPointer<QQmlQmldirData> &, QList<QQmlError> *); | - |
286 | - | |
287 | virtual void scriptImported(const QQmlRefPointer<QQmlScriptBlob> &, const QV4::CompiledData::Location &, const QString &, const QString &) {} | - |
288 | - | |
289 | void dependencyComplete(QQmlDataBlob *) override; | - |
290 | - | |
291 | protected: | - |
292 | virtual QString stringAt(int) const { return QString(); } never executed: return QString(); | 0 |
293 | - | |
294 | bool isDebugging() const; | - |
295 | - | |
296 | QQmlImports m_importCache; | - |
297 | QHash<const QV4::CompiledData::Import*, int> m_unresolvedImports; | - |
298 | QVector<QQmlRefPointer<QQmlQmldirData>> m_qmldirs; | - |
299 | QQmlMetaType::CachedUnitLookupError m_cachedUnitStatus = QQmlMetaType::CachedUnitLookupError::NoError; | - |
300 | }; | - |
301 | - | |
302 | QQmlTypeLoader(QQmlEngine *); | - |
303 | ~QQmlTypeLoader(); | - |
304 | - | |
305 | QQmlImportDatabase *importDatabase() const; | - |
306 | - | |
307 | static QUrl normalize(const QUrl &unNormalizedUrl); | - |
308 | - | |
309 | QQmlRefPointer<QQmlTypeData> getType(const QUrl &unNormalizedUrl, Mode mode = PreferSynchronous); | - |
310 | QQmlRefPointer<QQmlTypeData> getType(const QByteArray &, const QUrl &url, Mode mode = PreferSynchronous); | - |
311 | - | |
312 | QQmlRefPointer<QQmlScriptBlob> getScript(const QUrl &unNormalizedUrl); | - |
313 | QQmlRefPointer<QQmlQmldirData> getQmldir(const QUrl &); | - |
314 | - | |
315 | QString absoluteFilePath(const QString &path); | - |
316 | bool directoryExists(const QString &path); | - |
317 | - | |
318 | const QQmlTypeLoaderQmldirContent qmldirContent(const QString &filePath); | - |
319 | void setQmldirContent(const QString &filePath, const QString &content); | - |
320 | - | |
321 | void clearCache(); | - |
322 | void trimCache(); | - |
323 | - | |
324 | bool isTypeLoaded(const QUrl &url) const; | - |
325 | bool isScriptLoaded(const QUrl &url) const; | - |
326 | - | |
327 | void lock() { m_mutex.lock(); } executed 687506 times by 142 tests: end of block Executed by:
| 687506 |
328 | void unlock() { m_mutex.unlock(); } executed 687506 times by 142 tests: end of block Executed by:
| 687506 |
329 | - | |
330 | void load(QQmlDataBlob *, Mode = PreferSynchronous); | - |
331 | void loadWithStaticData(QQmlDataBlob *, const QByteArray &, Mode = PreferSynchronous); | - |
332 | void loadWithCachedUnit(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit, Mode mode = PreferSynchronous); | - |
333 | - | |
334 | QQmlEngine *engine() const; | - |
335 | void initializeEngine(QQmlExtensionInterface *, const char *); | - |
336 | void invalidate(); | - |
337 | - | |
338 | #if !QT_CONFIG(qml_debug) | - |
339 | quintptr profiler() const { return 0; } | - |
340 | void setProfiler(quintptr) {} | - |
341 | #else | - |
342 | QQmlProfiler *profiler() const { return m_profiler.data(); } executed 55623 times by 142 tests: return m_profiler.data(); Executed by:
| 55623 |
343 | void setProfiler(QQmlProfiler *profiler); | - |
344 | #endif // QT_CONFIG(qml_debug) | - |
345 | - | |
346 | - | |
347 | private: | - |
348 | friend class QQmlDataBlob; | - |
349 | friend class QQmlTypeLoaderThread; | - |
350 | #if QT_CONFIG(qml_network) | - |
351 | friend class QQmlTypeLoaderNetworkReplyProxy; | - |
352 | #endif // qml_network | - |
353 | - | |
354 | void shutdownThread(); | - |
355 | - | |
356 | void loadThread(QQmlDataBlob *); | - |
357 | void loadWithStaticDataThread(QQmlDataBlob *, const QByteArray &); | - |
358 | void loadWithCachedUnitThread(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit); | - |
359 | #if QT_CONFIG(qml_network) | - |
360 | void networkReplyFinished(QNetworkReply *); | - |
361 | void networkReplyProgress(QNetworkReply *, qint64, qint64); | - |
362 | - | |
363 | typedef QHash<QNetworkReply *, QQmlDataBlob *> NetworkReplies; | - |
364 | #endif | - |
365 | - | |
366 | void setData(QQmlDataBlob *, const QByteArray &); | - |
367 | void setData(QQmlDataBlob *, const QString &fileName); | - |
368 | void setData(QQmlDataBlob *, const QQmlDataBlob::SourceCodeData &); | - |
369 | void setCachedUnit(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit); | - |
370 | - | |
371 | template<typename T> | - |
372 | struct TypedCallback | - |
373 | { | - |
374 | TypedCallback(T *object, void (T::*func)(QQmlTypeData *)) : o(object), mf(func) {} never executed: end of block | 0 |
375 | - | |
376 | static void redirect(void *arg, QQmlTypeData *type) | - |
377 | { | - |
378 | TypedCallback<T> *self = reinterpret_cast<TypedCallback<T> *>(arg); | - |
379 | ((self->o)->*(self->mf))(type); | - |
380 | } never executed: end of block | 0 |
381 | - | |
382 | private: | - |
383 | T *o; | - |
384 | void (T::*mf)(QQmlTypeData *); | - |
385 | }; | - |
386 | - | |
387 | typedef QHash<QUrl, QQmlTypeData *> TypeCache; | - |
388 | typedef QHash<QUrl, QQmlScriptBlob *> ScriptCache; | - |
389 | typedef QHash<QUrl, QQmlQmldirData *> QmldirCache; | - |
390 | typedef QCache<QString, QCache<QString, bool> > ImportDirCache; | - |
391 | typedef QStringHash<QQmlTypeLoaderQmldirContent *> ImportQmlDirCache; | - |
392 | - | |
393 | QQmlEngine *m_engine; | - |
394 | QQmlTypeLoaderThread *m_thread; | - |
395 | QMutex &m_mutex; | - |
396 | - | |
397 | #if QT_CONFIG(qml_debug) | - |
398 | QScopedPointer<QQmlProfiler> m_profiler; | - |
399 | #endif | - |
400 | - | |
401 | #if QT_CONFIG(qml_network) | - |
402 | NetworkReplies m_networkReplies; | - |
403 | #endif | - |
404 | TypeCache m_typeCache; | - |
405 | int m_typeCacheTrimThreshold; | - |
406 | ScriptCache m_scriptCache; | - |
407 | QmldirCache m_qmldirCache; | - |
408 | ImportDirCache m_importDirCache; | - |
409 | ImportQmlDirCache m_importQmlDirCache; | - |
410 | - | |
411 | template<typename Loader> | - |
412 | void doLoad(const Loader &loader, QQmlDataBlob *blob, Mode mode); | - |
413 | void updateTypeCacheTrimThreshold(); | - |
414 | - | |
415 | friend struct PlainLoader; | - |
416 | friend struct CachedLoader; | - |
417 | friend struct StaticLoader; | - |
418 | }; | - |
419 | - | |
420 | class Q_AUTOTEST_EXPORT QQmlTypeData : public QQmlTypeLoader::Blob | - |
421 | { | - |
422 | Q_DECLARE_TR_FUNCTIONS(QQmlTypeData) | - |
423 | public: | - |
424 | struct TypeReference | - |
425 | { | - |
426 | TypeReference() : majorVersion(0), minorVersion(0), needsCreation(true) {} executed 77697 times by 142 tests: end of block Executed by:
| 77697 |
427 | - | |
428 | QV4::CompiledData::Location location; | - |
429 | QQmlType type; | - |
430 | int majorVersion; | - |
431 | int minorVersion; | - |
432 | QQmlRefPointer<QQmlTypeData> typeData; | - |
433 | QString prefix; // used by CompositeSingleton types | - |
434 | QString qualifiedName() const; | - |
435 | bool needsCreation; | - |
436 | }; | - |
437 | - | |
438 | struct ScriptReference | - |
439 | { | - |
440 | QV4::CompiledData::Location location; | - |
441 | QString qualifier; | - |
442 | QQmlRefPointer<QQmlScriptBlob> script; | - |
443 | }; | - |
444 | - | |
445 | private: | - |
446 | friend class QQmlTypeLoader; | - |
447 | - | |
448 | QQmlTypeData(const QUrl &, QQmlTypeLoader *); | - |
449 | - | |
450 | public: | - |
451 | ~QQmlTypeData() override; | - |
452 | - | |
453 | const QList<ScriptReference> &resolvedScripts() const; | - |
454 | - | |
455 | QV4::CompiledData::CompilationUnit *compilationUnit() const; | - |
456 | - | |
457 | // Used by QQmlComponent to get notifications | - |
458 | struct TypeDataCallback { | - |
459 | virtual ~TypeDataCallback(); | - |
460 | virtual void typeDataProgress(QQmlTypeData *, qreal) {} | - |
461 | virtual void typeDataReady(QQmlTypeData *) {} | - |
462 | }; | - |
463 | void registerCallback(TypeDataCallback *); | - |
464 | void unregisterCallback(TypeDataCallback *); | - |
465 | - | |
466 | protected: | - |
467 | void done() override; | - |
468 | void completed() override; | - |
469 | void dataReceived(const SourceCodeData &) override; | - |
470 | void initializeFromCachedUnit(const QV4::CompiledData::Unit *unit) override; | - |
471 | void allDependenciesDone() override; | - |
472 | void downloadProgressChanged(qreal) override; | - |
473 | - | |
474 | QString stringAt(int index) const override; | - |
475 | - | |
476 | private: | - |
477 | bool tryLoadFromDiskCache(); | - |
478 | bool loadFromSource(); | - |
479 | void restoreIR(QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit); | - |
480 | void continueLoadFromIR(); | - |
481 | void resolveTypes(); | - |
482 | QQmlCompileError buildTypeResolutionCaches( | - |
483 | QQmlRefPointer<QQmlTypeNameCache> *typeNameCache, | - |
484 | QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache | - |
485 | ) const; | - |
486 | void compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, | - |
487 | const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache, const QV4::CompiledData::DependentTypesHasher &dependencyHasher); | - |
488 | void createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, | - |
489 | const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache); | - |
490 | bool resolveType(const QString &typeName, int &majorVersion, int &minorVersion, | - |
491 | TypeReference &ref, int lineNumber = -1, int columnNumber = -1, | - |
492 | bool reportErrors = true, | - |
493 | QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType); | - |
494 | - | |
495 | void scriptImported(const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace) override; | - |
496 | - | |
497 | - | |
498 | SourceCodeData m_backupSourceCode; // used when cache verification fails. | - |
499 | QScopedPointer<QmlIR::Document> m_document; | - |
500 | QV4::CompiledData::TypeReferenceMap m_typeReferences; | - |
501 | - | |
502 | QList<ScriptReference> m_scripts; | - |
503 | - | |
504 | QSet<QString> m_namespaces; | - |
505 | QList<TypeReference> m_compositeSingletons; | - |
506 | - | |
507 | // map from name index to resolved type | - |
508 | // While this could be a hash, a map is chosen here to provide a stable | - |
509 | // order, which is used to calculating a check-sum on dependent meta-objects. | - |
510 | QMap<int, TypeReference> m_resolvedTypes; | - |
511 | bool m_typesResolved:1; | - |
512 | - | |
513 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> m_compiledData; | - |
514 | - | |
515 | QList<TypeDataCallback *> m_callbacks; | - |
516 | - | |
517 | bool m_implicitImportLoaded; | - |
518 | bool loadImplicitImport(); | - |
519 | }; | - |
520 | - | |
521 | // QQmlScriptData instances are created, uninitialized, by the loader in the | - |
522 | // load thread. The first time they are used by the VME, they are initialized which | - |
523 | // creates their v8 objects and they are referenced and added to the engine's cleanup | - |
524 | // list. During QQmlCleanup::clear() all v8 resources are destroyed, and the | - |
525 | // reference that was created is released but final deletion only occurs once all the | - |
526 | // references as released. This is all intended to ensure that the v8 resources are | - |
527 | // only created and destroyed in the main thread :) | - |
528 | class Q_AUTOTEST_EXPORT QQmlScriptData : public QQmlCleanup, public QQmlRefCount | - |
529 | { | - |
530 | private: | - |
531 | friend class QQmlTypeLoader; | - |
532 | - | |
533 | QQmlScriptData(); | - |
534 | - | |
535 | public: | - |
536 | ~QQmlScriptData() override; | - |
537 | - | |
538 | QUrl url; | - |
539 | QString urlString; | - |
540 | QQmlTypeNameCache *typeNameCache; | - |
541 | QVector<QQmlRefPointer<QQmlScriptBlob>> scripts; | - |
542 | - | |
543 | QV4::ReturnedValue scriptValueForContext(QQmlContextData *parentCtxt); | - |
544 | - | |
545 | protected: | - |
546 | void clear() override; // From QQmlCleanup | - |
547 | - | |
548 | private: | - |
549 | friend class QQmlScriptBlob; | - |
550 | - | |
551 | void initialize(QQmlEngine *); | - |
552 | - | |
553 | bool m_loaded; | - |
554 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> m_precompiledScript; | - |
555 | QV4::Script *m_program; | - |
556 | QV4::PersistentValue m_value; | - |
557 | }; | - |
558 | - | |
559 | class Q_AUTOTEST_EXPORT QQmlScriptBlob : public QQmlTypeLoader::Blob | - |
560 | { | - |
561 | private: | - |
562 | friend class QQmlTypeLoader; | - |
563 | - | |
564 | QQmlScriptBlob(const QUrl &, QQmlTypeLoader *); | - |
565 | - | |
566 | public: | - |
567 | ~QQmlScriptBlob() override; | - |
568 | - | |
569 | struct ScriptReference | - |
570 | { | - |
571 | QV4::CompiledData::Location location; | - |
572 | QString qualifier; | - |
573 | QString nameSpace; | - |
574 | QQmlRefPointer<QQmlScriptBlob> script; | - |
575 | }; | - |
576 | - | |
577 | QQmlRefPointer<QQmlScriptData> scriptData() const; | - |
578 | - | |
579 | protected: | - |
580 | void dataReceived(const SourceCodeData &) override; | - |
581 | void initializeFromCachedUnit(const QV4::CompiledData::Unit *unit) override; | - |
582 | void done() override; | - |
583 | - | |
584 | QString stringAt(int index) const override; | - |
585 | - | |
586 | private: | - |
587 | void scriptImported(const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace) override; | - |
588 | void initializeFromCompilationUnit(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit); | - |
589 | - | |
590 | QList<ScriptReference> m_scripts; | - |
591 | QQmlRefPointer<QQmlScriptData> m_scriptData; | - |
592 | }; | - |
593 | - | |
594 | class Q_AUTOTEST_EXPORT QQmlQmldirData : public QQmlTypeLoader::Blob | - |
595 | { | - |
596 | private: | - |
597 | friend class QQmlTypeLoader; | - |
598 | - | |
599 | QQmlQmldirData(const QUrl &, QQmlTypeLoader *); | - |
600 | - | |
601 | public: | - |
602 | const QString &content() const; | - |
603 | - | |
604 | const QV4::CompiledData::Import *import(QQmlTypeLoader::Blob *) const; | - |
605 | void setImport(QQmlTypeLoader::Blob *, const QV4::CompiledData::Import *); | - |
606 | - | |
607 | int priority(QQmlTypeLoader::Blob *) const; | - |
608 | void setPriority(QQmlTypeLoader::Blob *, int); | - |
609 | - | |
610 | protected: | - |
611 | void dataReceived(const SourceCodeData &) override; | - |
612 | void initializeFromCachedUnit(const QV4::CompiledData::Unit *) override; | - |
613 | - | |
614 | private: | - |
615 | QString m_content; | - |
616 | QHash<QQmlTypeLoader::Blob *, const QV4::CompiledData::Import *> m_imports; | - |
617 | QHash<QQmlTypeLoader::Blob *, int> m_priorities; | - |
618 | }; | - |
619 | - | |
620 | - | |
621 | QT_END_NAMESPACE | - |
622 | - | |
623 | #endif // QQMLTYPELOADER_P_H | - |
Source code | Switch to Preprocessed file |