diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-04-25 16:19:02 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-06-04 08:25:52 +0200 |
commit | 52e07d564b65ed6ce26955a676c7692ad67686c1 (patch) | |
tree | 04354cdf1d56776e9b52819f4329b70c57e235dc /src/qml/compiler/qqmltypecompiler.cpp | |
parent | 481447ae664fa2998cb03f93f0c066caa2782bf0 (diff) |
Rework custom parser integration
The custom parser design used to be so that the custom parser operates on the "AST",
creates its own binary representation of the data it needs, stores it in a QByteArray
and gets that at object instantiation time. That meant serializing everything necessary.
With the introduction of the "binary" QML data structure, that process of serialization
becomes obsolete and would require extra work in the custom parsers for example for QQuickStates
to store the translation parameters.
The clean solution is to eliminate this unnecessary serialization process and
instead let the custom parsers do a verification pass at type compile time and
then simply operate directly on the QV4::CompiledData::Bindings at object
instantiation time. That simplifies the code, and allows for support of
translations throughout all list model properties.
Additionally this speeds up the creation of state objects and reduces memory
consumption. Previously a text: qsTr("foo") binding in states would result in
an actual java script binding. After this patch it is merely stored as a string
and translated at object instantiation time.
Change-Id: I7550274513f54abb09a0ab4de51c4c0bcdb23cae
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler/qqmltypecompiler.cpp')
-rw-r--r-- | src/qml/compiler/qqmltypecompiler.cpp | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index ede150c67b..45fdab3fd1 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -378,9 +378,9 @@ QHash<int, QHash<int, int> > *QQmlTypeCompiler::objectIndexToIdPerComponent() return &compiledData->objectIndexToIdPerComponent; } -QHash<int, QQmlCompiledData::CustomParserData> *QQmlTypeCompiler::customParserData() +QHash<int, QBitArray> *QQmlTypeCompiler::customParserBindings() { - return &compiledData->customParserData; + return &compiledData->customParserBindings; } QQmlJS::MemoryPool *QQmlTypeCompiler::memoryPool() @@ -398,11 +398,6 @@ const QV4::Compiler::StringTableGenerator *QQmlTypeCompiler::stringPool() const return &document->jsGenerator.stringTable; } -void QQmlTypeCompiler::setCustomParserBindings(const QVector<int> &bindings) -{ - compiledData->customParserBindings = bindings; -} - void QQmlTypeCompiler::setDeferredBindingsPerObject(const QHash<int, QBitArray> &deferredBindingsPerObject) { compiledData->deferredBindingsPerObject = deferredBindingsPerObject; @@ -1720,7 +1715,7 @@ QQmlPropertyValidator::QQmlPropertyValidator(QQmlTypeCompiler *typeCompiler) , customParsers(typeCompiler->customParserCache()) , propertyCaches(typeCompiler->propertyCaches()) , objectIndexToIdPerComponent(*typeCompiler->objectIndexToIdPerComponent()) - , customParserData(typeCompiler->customParserData()) + , customParserBindingsPerObject(typeCompiler->customParserBindings()) , _seenObjectWithId(false) { } @@ -1729,7 +1724,6 @@ bool QQmlPropertyValidator::validate() { if (!validateObject(qmlUnit->indexOfRootObject, /*instantiatingBinding*/0)) return false; - compiler->setCustomParserBindings(customParserBindings); compiler->setDeferredBindingsPerObject(deferredBindingsPerObject); return true; } @@ -1739,13 +1733,6 @@ const QQmlImports &QQmlPropertyValidator::imports() const return *compiler->imports(); } -QQmlBinding::Identifier QQmlPropertyValidator::bindingIdentifier(const QV4::CompiledData::Binding *binding, QQmlCustomParser *) -{ - const int id = customParserBindings.count(); - customParserBindings.append(binding->value.compiledScriptIndex); - return id; -} - QString QQmlPropertyValidator::bindingAsString(int objectIndex, const QV4::CompiledData::Binding *binding) const { const QmlIR::Object *object = compiler->qmlObjects()->value(objectIndex); @@ -2005,11 +1992,11 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD if (customParser && !customBindings.isEmpty()) { customParser->clearErrors(); customParser->compiler = this; - QQmlCompiledData::CustomParserData data; - data.bindings = customParserBindings; - data.compilationArtifact = customParser->compile(qmlUnit, customBindings); + customParser->imports = compiler->imports(); + customParser->verifyBindings(qmlUnit, customBindings); customParser->compiler = 0; - customParserData->insert(objectIndex, data); + customParser->imports = (QQmlImports*)0; + customParserBindingsPerObject->insert(objectIndex, customParserBindings); const QList<QQmlError> parserErrors = customParser->errors(); if (!parserErrors.isEmpty()) { foreach (QQmlError error, parserErrors) |