diff options
Diffstat (limited to 'src/qml/qml/qqmltypeloader_p.h')
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 95 |
1 files changed, 40 insertions, 55 deletions
diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 51228eacc7..53cf4234e1 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -51,9 +51,12 @@ // We mean it. // +#include <QtQml/qtqmlglobal.h> #include <QtCore/qobject.h> #include <QtCore/qatomic.h> +#if QT_CONFIG(qml_network) #include <QtNetwork/qnetworkreply.h> +#endif #include <QtQml/qqmlerror.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlfile.h> @@ -75,11 +78,11 @@ class QQmlScriptData; class QQmlScriptBlob; class QQmlQmldirData; class QQmlTypeLoader; -class QQmlCompiledData; class QQmlComponentPrivate; class QQmlTypeData; class QQmlTypeLoader; class QQmlExtensionInterface; +struct QQmlCompileError; namespace QmlIR { struct Document; @@ -129,34 +132,32 @@ public: class Data { public: - inline const char *data() const; - inline int size() const; - - inline QByteArray asByteArray() const; - - inline bool isFile() const; - inline QQmlFile *asFile() const; - + QByteArray readAll(QString *error, qint64 *sourceTimeStamp = 0) const; private: friend class QQmlDataBlob; friend class QQmlTypeLoader; inline Data(); Data(const Data &); Data &operator=(const Data &); - QBiPointer<const QByteArray, QQmlFile> d; + QBiPointer<const QByteArray, const QString> d; }; protected: // Can be called from within callbacks void setError(const QQmlError &); void setError(const QList<QQmlError> &errors); + void setError(const QQmlCompileError &error); + void setError(const QVector<QQmlCompileError> &errors); + void setError(const QString &description); void addDependency(QQmlDataBlob *); // Callbacks made in load thread virtual void dataReceived(const Data &) = 0; virtual void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit*) = 0; virtual void done(); +#if QT_CONFIG(qml_network) virtual void networkError(QNetworkReply::NetworkError); +#endif virtual void dependencyError(QQmlDataBlob *); virtual void dependencyComplete(QQmlDataBlob *); virtual void allDependenciesDone(); @@ -233,7 +234,6 @@ public: protected: bool addImport(const QV4::CompiledData::Import *import, QList<QQmlError> *errors); - bool addPragma(const QmlIR::Pragma &pragma, QList<QQmlError> *errors); bool fetchQmldir(const QUrl &url, const QV4::CompiledData::Import *import, int priority, QList<QQmlError> *errors); bool updateQmldir(QQmlQmldirData *data, const QV4::CompiledData::Import *import, QList<QQmlError> *errors); @@ -249,8 +249,9 @@ public: protected: virtual QString stringAt(int) const { return QString(); } + bool isDebugging() const; + QQmlImports m_importCache; - bool m_isSingleton; QHash<const QV4::CompiledData::Import*, int> m_unresolvedImports; QList<QQmlQmldirData *> m_qmldirs; }; @@ -320,20 +321,24 @@ public: private: friend class QQmlDataBlob; friend class QQmlTypeLoaderThread; +#if QT_CONFIG(qml_network) friend class QQmlTypeLoaderNetworkReplyProxy; +#endif // qml_network void shutdownThread(); void loadThread(QQmlDataBlob *); void loadWithStaticDataThread(QQmlDataBlob *, const QByteArray &); void loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit); +#if QT_CONFIG(qml_network) void networkReplyFinished(QNetworkReply *); void networkReplyProgress(QNetworkReply *, qint64, qint64); typedef QHash<QNetworkReply *, QQmlDataBlob *> NetworkReplies; +#endif void setData(QQmlDataBlob *, const QByteArray &); - void setData(QQmlDataBlob *, QQmlFile *); + void setData(QQmlDataBlob *, const QString &fileName); void setData(QQmlDataBlob *, const QQmlDataBlob::Data &); void setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit); @@ -362,7 +367,9 @@ private: QQmlEngine *m_engine; QQmlTypeLoaderThread *m_thread; +#if QT_CONFIG(qml_network) NetworkReplies m_networkReplies; +#endif TypeCache m_typeCache; int m_typeCacheTrimThreshold; ScriptCache m_scriptCache; @@ -381,6 +388,7 @@ private: class Q_AUTOTEST_EXPORT QQmlTypeData : public QQmlTypeLoader::Blob { + Q_DECLARE_TR_FUNCTIONS(QQmlTypeData) public: struct TypeReference { @@ -412,13 +420,9 @@ private: public: ~QQmlTypeData(); - const QHash<int, TypeReference> &resolvedTypeRefs() const { return m_resolvedTypes; } - const QList<ScriptReference> &resolvedScripts() const; - const QSet<QString> &namespaces() const; - const QList<TypeReference> &compositeSingletons() const; - QQmlCompiledData *compiledData() const; + QV4::CompiledData::CompilationUnit *compilationUnit() const; // Used by QQmlComponent to get notifications struct TypeDataCallback { @@ -440,14 +444,27 @@ protected: virtual QString stringAt(int index) const; private: + bool tryLoadFromDiskCache(); + bool loadFromSource(); void continueLoadFromIR(); void resolveTypes(); - void compile(); + QQmlCompileError buildTypeResolutionCaches( + QQmlRefPointer<QQmlTypeNameCache> *importCache, + QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache + ) const; + void compile(const QQmlRefPointer<QQmlTypeNameCache> &importCache, + const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache); + void createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeNameCache> &importCache, + const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache); bool resolveType(const QString &typeName, int &majorVersion, int &minorVersion, TypeReference &ref); virtual void scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace); + + qint64 m_sourceTimeStamp = 0; + QByteArray m_backupSourceCode; // used when cache verification fails. QScopedPointer<QmlIR::Document> m_document; + QV4::CompiledData::TypeReferenceMap m_typeReferences; QList<ScriptReference> m_scripts; @@ -455,14 +472,15 @@ private: QList<TypeReference> m_compositeSingletons; // map from name index to resolved type - QHash<int, TypeReference> m_resolvedTypes; + // While this could be a hash, a map is chosen here to provide a stable + // order, which is used to calculating a check-sum on dependent meta-objects. + QMap<int, TypeReference> m_resolvedTypes; bool m_typesResolved:1; - QQmlCompiledData *m_compiledData; + QQmlRefPointer<QV4::CompiledData::CompilationUnit> m_compiledData; QList<TypeDataCallback *> m_callbacks; - QV4::CompiledData::Import *m_implicitImport; bool m_implicitImportLoaded; bool loadImplicitImport(); }; @@ -572,40 +590,7 @@ QQmlDataBlob::Data::Data() { } -const char *QQmlDataBlob::Data::data() const -{ - Q_ASSERT(!d.isNull()); - - if (d.isT1()) return d.asT1()->constData(); - else return d.asT2()->data(); -} - -int QQmlDataBlob::Data::size() const -{ - Q_ASSERT(!d.isNull()); - - if (d.isT1()) return d.asT1()->size(); - else return d.asT2()->size(); -} - -bool QQmlDataBlob::Data::isFile() const -{ - return d.isT2(); -} -QByteArray QQmlDataBlob::Data::asByteArray() const -{ - Q_ASSERT(!d.isNull()); - - if (d.isT1()) return *d.asT1(); - else return d.asT2()->dataByteArray(); -} - -QQmlFile *QQmlDataBlob::Data::asFile() const -{ - if (d.isT2()) return d.asT2(); - else return 0; -} QT_END_NAMESPACE |