From b66cbe011ac843ab0aae3dfec45b313bc3280839 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 4 Oct 2013 03:02:49 +0200 Subject: [new compiler] Add support for parser status callbacks Change-Id: I62ce1fab2537d533d1d2052a7f5edc5061adf75e Reviewed-by: Lars Knoll --- src/qml/qml/qqmlobjectcreator.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/qml/qml/qqmlobjectcreator_p.h | 2 ++ src/qml/qml/qqmlparserstatus.h | 1 + 3 files changed, 41 insertions(+) diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 81862a1429..4746188a8f 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -537,6 +537,10 @@ QObject *QmlObjectCreator::create(int subComponentIndex, QObject *parent) context->importedScripts = parentContext->importedScripts; } + QVector parserStatusCallbacks; + parserStatusCallbacks.resize(qmlUnit->nObjects); + qSwap(_parserStatusCallbacks, parserStatusCallbacks); + QObject *instance = createInstance(objectToCreate, parent); if (instance) { QQmlData *ddata = QQmlData::get(instance); @@ -546,6 +550,10 @@ QObject *QmlObjectCreator::create(int subComponentIndex, QObject *parent) context->contextObject = instance; } + + qSwap(_parserStatusCallbacks, parserStatusCallbacks); + allParserStatusCallbacks.prepend(parserStatusCallbacks); + return instance; } @@ -1242,6 +1250,13 @@ QObject *QmlObjectCreator::createInstance(int index, QObject *parent) recordError(obj->location, tr("Unable to create object of type %1").arg(stringAt(obj->inheritedTypeNameIndex))); return 0; } + const int parserStatusCast = type->parserStatusCast(); + if (parserStatusCast != -1) { + QQmlParserStatus *parserStatus = reinterpret_cast(reinterpret_cast(instance) + parserStatusCast); + parserStatus->classBegin(); + _parserStatusCallbacks[index] = parserStatus; + parserStatus->d = &_parserStatusCallbacks[index]; + } } else { Q_ASSERT(typeRef.component); if (typeRef.component->qmlUnit->isSingleton()) @@ -1258,6 +1273,7 @@ QObject *QmlObjectCreator::createInstance(int index, QObject *parent) if (subCreator.componentAttached) subCreator.componentAttached->add(&componentAttached); allCreatedBindings << subCreator.allCreatedBindings; + allParserStatusCallbacks << subCreator.allParserStatusCallbacks; } // ### use no-event variant if (parent) @@ -1321,6 +1337,28 @@ void QmlObjectCreator::finalize() } } + if (true /* ### componentCompleteEnabled()*/) { // the qml designer does the component complete later + QQmlTrace trace("VME Component Complete"); + for (QLinkedList >::ConstIterator it = allParserStatusCallbacks.constBegin(), end = allParserStatusCallbacks.constEnd(); + it != end; ++it) { + const QVector &parserStatusCallbacks = *it; + for (int i = parserStatusCallbacks.count() - 1; i >= 0; --i) { + QQmlParserStatus *status = parserStatusCallbacks.at(i); + + if (status && status->d) { + status->d = 0; + status->componentComplete(); + } + + #if 0 // ### + if (watcher.hasRecursed() || interrupt.shouldInterrupt()) + return 0; + #endif + } + } + allParserStatusCallbacks.clear(); + } + { QQmlTrace trace("VME Component.onCompleted Callbacks"); while (componentAttached) { diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index ec4b362491..900749a476 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -168,6 +168,7 @@ private: const QList vmeMetaObjectData; QHash objectIndexToId; QLinkedList > allCreatedBindings; + QLinkedList > allParserStatusCallbacks; QQmlCompiledData *compiledData; QObject *_qobject; @@ -180,6 +181,7 @@ private: QVector _createdBindings; QQmlListProperty _currentList; QV4::ExecutionContext *_qmlContext; + QVector _parserStatusCallbacks; }; QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlparserstatus.h b/src/qml/qml/qqmlparserstatus.h index d3447e7752..1d63afd978 100644 --- a/src/qml/qml/qqmlparserstatus.h +++ b/src/qml/qml/qqmlparserstatus.h @@ -62,6 +62,7 @@ private: friend class QQmlComponent; friend class QQmlComponentPrivate; friend class QQmlEnginePrivate; + friend class QmlObjectCreator; QQmlParserStatus **d; }; -- cgit v1.2.3