diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-07 15:59:24 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-10 10:26:39 +0100 |
commit | b681bd3e4ad20eb558da68ba1a2e2dfddfab9cf1 (patch) | |
tree | b2ff2bdc1ec91fb332c405466e9a6e29d7d40c3c /src/qml/qml | |
parent | c96a5432f9d34925c55753d592842a3bf7172cf2 (diff) |
[new compiler] Cleanups
Tie QQmlCompilePass and QQmlTypeCompiler together, so that we can eliminate
the battery of parameters to the individual compiler phases.
Change-Id: If2b6cf8416e6c2253c8f054048d1fd5ae12282b6
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 80 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator_p.h | 44 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 2 |
3 files changed, 49 insertions, 77 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 0c363b4dbb..1067a8dd0a 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -71,28 +71,18 @@ struct ActiveOCRestorer }; } -QQmlCompilePass::QQmlCompilePass(const QUrl &url, const QV4::CompiledData::QmlUnit *unit) - : url(url) - , jsUnit(&unit->header) +QQmlCompilePass::QQmlCompilePass(QQmlTypeCompiler *typeCompiler) + : compiler(typeCompiler) { } -QQmlCompilePass::QQmlCompilePass(const QUrl &url, const QStringList &stringTable) - : url(url) - , jsUnit(0) - , stringTable(stringTable) -{ - -} - void QQmlCompilePass::recordError(const QV4::CompiledData::Location &location, const QString &description) { QQmlError error; - error.setUrl(url); error.setLine(location.line); error.setColumn(location.column); error.setDescription(description); - errors << error; + compiler->recordError(error); } #define COMPILE_EXCEPTION(token, desc) \ @@ -103,12 +93,11 @@ void QQmlCompilePass::recordError(const QV4::CompiledData::Location &location, c static QAtomicInt classIndexCounter(0); -QQmlPropertyCacheCreator::QQmlPropertyCacheCreator(QQmlEnginePrivate *enginePrivate, const QStringList &stringTable, const QUrl &url, const QQmlImports *imports, - QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes) - : QQmlCompilePass(url, stringTable) - , enginePrivate(enginePrivate) - , imports(imports) - , resolvedTypes(resolvedTypes) +QQmlPropertyCacheCreator::QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler) + : QQmlCompilePass(typeCompiler) + , enginePrivate(typeCompiler->enginePrivate()) + , imports(typeCompiler->imports()) + , resolvedTypes(typeCompiler->resolvedTypes()) { } @@ -477,8 +466,8 @@ static void removeBindingOnProperty(QObject *o, int index) } QmlObjectCreator::QmlObjectCreator(QQmlContextData *parentContext, QQmlCompiledData *compiledData) - : QQmlCompilePass(compiledData->url, compiledData->qmlUnit) - , componentAttached(0) + : componentAttached(0) + , url(compiledData->url) , engine(parentContext->engine) , qmlUnit(compiledData->qmlUnit) , jsUnit(compiledData->compilationUnit) @@ -1241,6 +1230,16 @@ void QmlObjectCreator::setupFunctions() } } +void QmlObjectCreator::recordError(const QV4::CompiledData::Location &location, const QString &description) +{ + QQmlError error; + error.setUrl(url); + error.setLine(location.line); + error.setColumn(location.column); + error.setDescription(description); + errors << error; +} + QObject *QmlObjectCreator::createInstance(int index, QObject *parent) { ActiveOCRestorer ocRestorer(this, QQmlEnginePrivate::get(engine)); @@ -1469,21 +1468,17 @@ bool QmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPoi } -QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(const QUrl &url, const QStringList &stringTable, const QList<QmlObject *> &qmlObjects, int indexOfRootObject, - const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes, - const QList<QQmlPropertyCache *> &propertyCaches, QList<QByteArray> *vmeMetaObjectData, - QHash<int, int> *objectIndexToIdForRoot, - QHash<int, QHash<int, int> > *objectIndexToIdPerComponent) - : QQmlCompilePass(url, stringTable) - , qmlObjects(qmlObjects) - , indexOfRootObject(indexOfRootObject) +QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(QQmlTypeCompiler *typeCompiler) + : QQmlCompilePass(typeCompiler) + , qmlObjects(*typeCompiler->qmlObjects()) + , indexOfRootObject(typeCompiler->rootObjectIndex()) , _componentIndex(-1) , _objectIndexToIdInScope(0) - , resolvedTypes(resolvedTypes) - , propertyCaches(propertyCaches) - , vmeMetaObjectData(vmeMetaObjectData) - , objectIndexToIdForRoot(objectIndexToIdForRoot) - , objectIndexToIdPerComponent(objectIndexToIdPerComponent) + , resolvedTypes(*typeCompiler->resolvedTypes()) + , propertyCaches(typeCompiler->propertyCaches()) + , vmeMetaObjectData(typeCompiler->vmeMetaObjects()) + , objectIndexToIdForRoot(typeCompiler->objectIndexToIdForRoot()) + , objectIndexToIdPerComponent(typeCompiler->objectIndexToIdPerComponent()) { } @@ -1745,16 +1740,13 @@ bool QQmlComponentAndAliasResolver::resolveAliases() } -QQmlPropertyValidator::QQmlPropertyValidator(const QUrl &url, const QV4::CompiledData::QmlUnit *qmlUnit, - const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes, - const QList<QQmlPropertyCache *> &propertyCaches, const QHash<int, QHash<int, int> > &objectIndexToIdPerComponent, - QHash<int, QByteArray> *customParserData) - : QQmlCompilePass(url, qmlUnit) - , qmlUnit(qmlUnit) - , resolvedTypes(resolvedTypes) - , propertyCaches(propertyCaches) - , objectIndexToIdPerComponent(objectIndexToIdPerComponent) - , customParserData(customParserData) +QQmlPropertyValidator::QQmlPropertyValidator(QQmlTypeCompiler *typeCompiler) + : QQmlCompilePass(typeCompiler) + , qmlUnit(typeCompiler->qmlUnit()) + , resolvedTypes(*typeCompiler->resolvedTypes()) + , propertyCaches(typeCompiler->propertyCaches()) + , objectIndexToIdPerComponent(*typeCompiler->objectIndexToIdPerComponent()) + , customParserData(typeCompiler->customParserData()) { } diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index 796d92a1e6..92f40648d3 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -45,34 +45,19 @@ #include <private/qqmltypenamecache_p.h> #include <private/qv4compileddata_p.h> #include <private/qqmlcompiler_p.h> +#include <private/qqmltypecompiler_p.h> #include <QLinkedList> QT_BEGIN_NAMESPACE class QQmlAbstractBinding; - -struct QQmlCompilePass -{ - QQmlCompilePass(const QUrl &url, const QV4::CompiledData::QmlUnit *unit); - QQmlCompilePass(const QUrl &url, const QStringList &stringTable); - QList<QQmlError> errors; - - QString stringAt(int idx) const { return jsUnit ? jsUnit->stringAt(idx): stringTable.at(idx); } -protected: - void recordError(const QV4::CompiledData::Location &location, const QString &description); - - const QUrl url; - const QV4::CompiledData::Unit *jsUnit; - const QStringList stringTable; -}; +struct QQmlTypeCompiler; class QQmlPropertyCacheCreator : public QQmlCompilePass { Q_DECLARE_TR_FUNCTIONS(QQmlPropertyCacheCreator) public: - QQmlPropertyCacheCreator(QQmlEnginePrivate *enginePrivate, const QStringList &stringTable, - const QUrl &url, const QQmlImports *imports, - QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes); + QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler); bool create(const QtQml::QmlObject *obj, QQmlPropertyCache **cache, QByteArray *vmeMetaObjectData); @@ -86,14 +71,7 @@ class QQmlComponentAndAliasResolver : public QQmlCompilePass { Q_DECLARE_TR_FUNCTIONS(QQmlAnonymousComponentResolver) public: - QQmlComponentAndAliasResolver(const QUrl &url, const QStringList &stringTable, - const QList<QtQml::QmlObject*> &qmlObjects, - int indexOfRootObject, - const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes, - const QList<QQmlPropertyCache *> &propertyCaches, - QList<QByteArray> *vmeMetaObjectData, - QHash<int, int> *objectIndexToIdForRoot, - QHash<int, QHash<int, int> > *objectIndexToIdPerComponent); + QQmlComponentAndAliasResolver(QQmlTypeCompiler *typeCompiler); bool resolve(); @@ -126,11 +104,7 @@ class QQmlPropertyValidator : public QQmlCompilePass { Q_DECLARE_TR_FUNCTIONS(QQmlPropertyValidator) public: - QQmlPropertyValidator(const QUrl &url, const QV4::CompiledData::QmlUnit *qmlUnit, - const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes, - const QList<QQmlPropertyCache *> &propertyCaches, - const QHash<int, QHash<int, int> > &objectIndexToIdPerComponent, - QHash<int, QByteArray> *customParserData); + QQmlPropertyValidator(QQmlTypeCompiler *typeCompiler); bool validate(); @@ -146,7 +120,7 @@ private: QHash<int, QByteArray> *customParserData; }; -class QmlObjectCreator : public QQmlCompilePass +class QmlObjectCreator { Q_DECLARE_TR_FUNCTIONS(QmlObjectCreator) public: @@ -158,6 +132,8 @@ public: QQmlComponentAttached *componentAttached; QList<QQmlEnginePrivate::FinalizeCallback> finalizeCallbacks; + QList<QQmlError> errors; + private: QObject *createInstance(int index, QObject *parent = 0); @@ -169,6 +145,10 @@ private: void setPropertyValue(QQmlPropertyData *property, const QV4::CompiledData::Binding *binding); void setupFunctions(); + QString stringAt(int idx) const { return qmlUnit->header.stringAt(idx); } + void recordError(const QV4::CompiledData::Location &location, const QString &description); + + QUrl url; QQmlEngine *engine; const QV4::CompiledData::QmlUnit *qmlUnit; const QV4::CompiledData::CompilationUnit *jsUnit; diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 9e23b0b1a5..278bb017d0 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2309,7 +2309,7 @@ void QQmlTypeData::compile() if (m_useNewCompiler) { QQmlTypeCompiler compiler(QQmlEnginePrivate::get(typeLoader()->engine()), m_compiledData, this, parsedQML.data()); if (!compiler.compile()) { - setError(compiler.errors); + setError(compiler.compilationErrors()); m_compiledData->release(); m_compiledData = 0; } |