diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-24 18:21:15 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-25 10:51:47 +0100 |
commit | 3f0c9122c5971090d0256bda4e9fb53da4a76ea0 (patch) | |
tree | ca51902e6fb457e61da574d55ebee72d7a28ca7a /src/qml/jsruntime/qv4executablecompilationunit.cpp | |
parent | d9eeab6e2c699761115d9acbca292c16762eb8f3 (diff) |
Encapsulate QV4::ResolvedTypeReference
It's used all over the place. We need a proper interface.
Change-Id: Iebe254ef3bf35503bf3fdd3639979a5db2b3449e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4executablecompilationunit.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4executablecompilationunit.cpp | 115 |
1 files changed, 27 insertions, 88 deletions
diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp index fb19ac4b66..7f4e35e815 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit.cpp +++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp @@ -54,6 +54,7 @@ #include <private/qml_compile_hash_p.h> #include <private/qqmltypewrapper_p.h> #include <private/inlinecomponentutils_p.h> +#include <private/qv4resolvedtypereference_p.h> #include <QtQml/qqmlfile.h> #include <QtQml/qqmlpropertymap.h> @@ -406,12 +407,13 @@ void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngi const QV4::CompiledData::Object *obj = objectAt(/*root object*/0); auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex); Q_ASSERT(typeRef); - if (typeRef->compilationUnit) { - metaTypeId = typeRef->compilationUnit->metaTypeId; - listMetaTypeId = typeRef->compilationUnit->listMetaTypeId; + if (const auto compilationUnit = typeRef->compilationUnit()) { + metaTypeId = compilationUnit->metaTypeId; + listMetaTypeId = compilationUnit->listMetaTypeId; } else { - metaTypeId = typeRef->type.typeId(); - listMetaTypeId = typeRef->type.qListTypeId(); + const auto type = typeRef->type(); + metaTypeId = type.typeId(); + listMetaTypeId = type.qListTypeId(); } } @@ -449,21 +451,21 @@ void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngi inlineComponentData[lastICRoot].totalBindingCount += obj->nBindings; if (auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex)) { - if (typeRef->type.isValid() && typeRef->type.parserStatusCast() != -1) + const auto type = typeRef->type(); + if (type.isValid() && type.parserStatusCast() != -1) ++inlineComponentData[lastICRoot].totalParserStatusCount; ++inlineComponentData[lastICRoot].totalObjectCount; - if (typeRef->compilationUnit) { + if (const auto compilationUnit = typeRef->compilationUnit()) { // if the type is an inline component type, we have to extract the information from it // This requires that inline components are visited in the correct order - auto icRoot = typeRef->compilationUnit->icRoot; - if (typeRef->type.isInlineComponentType()) { - icRoot = typeRef->type.inlineComponentId(); - } - QScopedValueRollback<int> rollback {typeRef->compilationUnit->icRoot, icRoot}; - inlineComponentData[lastICRoot].totalBindingCount += typeRef->compilationUnit->totalBindingsCount(); - inlineComponentData[lastICRoot].totalParserStatusCount += typeRef->compilationUnit->totalParserStatusCount(); - inlineComponentData[lastICRoot].totalObjectCount += typeRef->compilationUnit->totalObjectCount(); + auto icRoot = compilationUnit->icRoot; + if (type.isInlineComponentType()) + icRoot = type.inlineComponentId(); + QScopedValueRollback<int> rollback {compilationUnit->icRoot, icRoot}; + inlineComponentData[lastICRoot].totalBindingCount += compilationUnit->totalBindingsCount(); + inlineComponentData[lastICRoot].totalParserStatusCount += compilationUnit->totalParserStatusCount(); + inlineComponentData[lastICRoot].totalObjectCount += compilationUnit->totalObjectCount(); } } } @@ -478,18 +480,18 @@ void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngi } bindingCount += obj->nBindings; if (auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex)) { - if (typeRef->type.isValid() && typeRef->type.parserStatusCast() != -1) + const auto type = typeRef->type(); + if (type.isValid() && type.parserStatusCast() != -1) ++parserStatusCount; ++objectCount; - if (typeRef->compilationUnit) { - auto icRoot = typeRef->compilationUnit->icRoot; - if (typeRef->type.isInlineComponentType()) { - icRoot = typeRef->type.inlineComponentId(); - } - QScopedValueRollback<int> rollback {typeRef->compilationUnit->icRoot, icRoot}; - bindingCount += typeRef->compilationUnit->totalBindingsCount(); - parserStatusCount += typeRef->compilationUnit->totalParserStatusCount(); - objectCount += typeRef->compilationUnit->totalObjectCount(); + if (const auto compilationUnit = typeRef->compilationUnit()) { + auto icRoot = compilationUnit->icRoot; + if (type.isInlineComponentType()) + icRoot = type.inlineComponentId(); + QScopedValueRollback<int> rollback {compilationUnit->icRoot, icRoot}; + bindingCount += compilationUnit->totalBindingsCount(); + parserStatusCount += compilationUnit->totalParserStatusCount(); + objectCount += compilationUnit->totalObjectCount(); } } } @@ -798,69 +800,6 @@ bool ExecutableCompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorSt }); } -/*! -Returns the property cache, if one alread exists. The cache is not referenced. -*/ -QQmlRefPointer<QQmlPropertyCache> ResolvedTypeReference::propertyCache() const -{ - if (type.isValid()) - return typePropertyCache; - else - return compilationUnit->rootPropertyCache(); -} - -/*! -Returns the property cache, creating one if it doesn't already exist. The cache is not referenced. -*/ -QQmlRefPointer<QQmlPropertyCache> ResolvedTypeReference::createPropertyCache(QQmlEngine *engine) -{ - if (typePropertyCache) { - return typePropertyCache; - } else if (type.isValid()) { - typePropertyCache = QQmlEnginePrivate::get(engine)->cache(type.metaObject(), version); - return typePropertyCache; - } else { - Q_ASSERT(compilationUnit); - return compilationUnit->rootPropertyCache(); - } -} - -bool ResolvedTypeReference::addToHash(QCryptographicHash *hash, QQmlEngine *engine) -{ - if (type.isValid() && !type.isInlineComponentType()) { - bool ok = false; - hash->addData(createPropertyCache(engine)->checksum(&ok)); - return ok; - } - if (!compilationUnit) - return false; - hash->addData(compilationUnit->data->md5Checksum, - sizeof(compilationUnit->data->md5Checksum)); - return true; -} - -template <typename T> -bool qtTypeInherits(const QMetaObject *mo) { - while (mo) { - if (mo == &T::staticMetaObject) - return true; - mo = mo->superClass(); - } - return false; -} - -void ResolvedTypeReference::doDynamicTypeCheck() -{ - const QMetaObject *mo = nullptr; - if (typePropertyCache) - mo = typePropertyCache->firstCppMetaObject(); - else if (type.isValid()) - mo = type.metaObject(); - else if (compilationUnit) - mo = compilationUnit->rootPropertyCache()->firstCppMetaObject(); - isFullyDynamicType = qtTypeInherits<QQmlPropertyMap>(mo); -} - bool ResolvedTypeReferenceMap::addToHash(QCryptographicHash *hash, QQmlEngine *engine) const { for (auto it = constBegin(), end = constEnd(); it != end; ++it) { |