diff options
author | Ulf Hermann <[email protected]> | 2024-10-01 13:16:17 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2024-10-02 08:46:46 +0000 |
commit | e7146cd98700c29802214a39a4cefd9db146c97a (patch) | |
tree | fc7683486e7ae750e26d2e2076a86a4fd271f86e | |
parent | a5a814d26a8d02c0752fab9ec6cc8c2447c10182 (diff) |
QmlCompiler: Allow string lookup of composite metatypes again
We're not guaranteed to get string IDs for those.
Pick-to: 6.8
Change-Id: I5800a1e90589f3a6ae55ce8624fa56968f0f3ec3
Reviewed-by: Fabian Kosmale <[email protected]>
Reviewed-by: Olivier De Cannière <[email protected]>
(cherry picked from commit b8c3cf7192fe5793fdaf56a1203cb2cf76d8c3a2)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r-- | src/qml/compiler/qv4compiler_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqml.cpp | 16 | ||||
-rw-r--r-- | src/qml/qml/qqmlprivate.h | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmltype_p_p.h | 32 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 8 |
5 files changed, 48 insertions, 14 deletions
diff --git a/src/qml/compiler/qv4compiler_p.h b/src/qml/compiler/qv4compiler_p.h index bf2f5c8167..05423b6afb 100644 --- a/src/qml/compiler/qv4compiler_p.h +++ b/src/qml/compiler/qv4compiler_p.h @@ -47,6 +47,7 @@ struct Q_QML_COMPILER_EXPORT StringTableGenerator { int registerString(const QString &str); int getStringId(const QString &string) const; + bool hasStringId(const QString &string) const { return stringToId.contains(string); } QString stringForIndex(int index) const { return strings.at(index); } uint stringCount() const { return strings.size() - backingUnitTableSize; } @@ -83,6 +84,7 @@ struct Q_QML_COMPILER_EXPORT JSUnitGenerator { int registerString(const QString &str) { return stringTable.registerString(str); } int getStringId(const QString &string) const { return stringTable.getStringId(string); } + bool hasStringId(const QString &string) const { return stringTable.hasStringId(string); } QString stringForIndex(int index) const { return stringTable.stringForIndex(index); } int registerGetterLookup(const QString &name, LookupMode mode); diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp index 8479dadd42..63088d2407 100644 --- a/src/qml/qml/qqml.cpp +++ b/src/qml/qml/qqml.cpp @@ -179,12 +179,28 @@ QMetaType QQmlPrivate::compositeMetaType( return QQmlTypePrivate::visibleQmlTypeByName(unit, elementNameId).typeId(); } +QMetaType QQmlPrivate::compositeMetaType( + QV4::ExecutableCompilationUnit *unit, const QString &elementName) +{ + return QQmlTypePrivate::visibleQmlTypeByName( + unit->baseCompilationUnit(), elementName, unit->engine->typeLoader()) + .typeId(); +} + QMetaType QQmlPrivate::compositeListMetaType( QV4::ExecutableCompilationUnit *unit, int elementNameId) { return QQmlTypePrivate::visibleQmlTypeByName(unit, elementNameId).qListTypeId(); } +QMetaType QQmlPrivate::compositeListMetaType( + QV4::ExecutableCompilationUnit *unit, const QString &elementName) +{ + return QQmlTypePrivate::visibleQmlTypeByName( + unit->baseCompilationUnit(), elementName, unit->engine->typeLoader()) + .qListTypeId(); +} + int qmlRegisterUncreatableMetaObject(const QMetaObject &staticMetaObject, const char *uri, int versionMajor, int versionMinor, const char *qmlName, diff --git a/src/qml/qml/qqmlprivate.h b/src/qml/qml/qqmlprivate.h index 71c8c78e31..f86203cfc0 100644 --- a/src/qml/qml/qqmlprivate.h +++ b/src/qml/qml/qqmlprivate.h @@ -1154,8 +1154,12 @@ namespace QQmlPrivate Q_QML_EXPORT QMetaType compositeMetaType( QV4::ExecutableCompilationUnit *unit, int elementNameId); + Q_QML_EXPORT QMetaType compositeMetaType( + QV4::ExecutableCompilationUnit *unit, const QString &elementName); Q_QML_EXPORT QMetaType compositeListMetaType( QV4::ExecutableCompilationUnit *unit, int elementNameId); + Q_QML_EXPORT QMetaType compositeListMetaType( + QV4::ExecutableCompilationUnit *unit, const QString &elementName); } // namespace QQmlPrivate diff --git a/src/qml/qml/qqmltype_p_p.h b/src/qml/qml/qqmltype_p_p.h index a642e2ca27..149f6438c9 100644 --- a/src/qml/qml/qqmltype_p_p.h +++ b/src/qml/qml/qqmltype_p_p.h @@ -236,6 +236,23 @@ public: return nullptr; } + static QQmlType visibleQmlTypeByName( + const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit, + const QString &elementName, QQmlTypeLoader *typeLoader) + { + const QQmlType qmltype = unit->typeNameCache->query<QQmlImport::AllowRecursion>( + elementName, typeLoader).type; + + if (qmltype.isValid() && qmltype.isInlineComponentType() + && !QQmlMetaType::obtainCompilationUnit(qmltype.typeId())) { + // If it seems to be an IC type, make sure there is an actual + // compilation unit for it. We create inline component types speculatively. + return QQmlType(); + } + + return qmltype; + } + // Tries the base unit's resolvedTypes first. If successful, that is cheap // because it's just a hash. Otherwise falls back to typeNameCache. // typeNameCache is slower because it will do a generic type search on all imports. @@ -250,18 +267,9 @@ public: const auto &base = unit->baseCompilationUnit(); const auto it = base->resolvedTypes.constFind(elementNameId); if (it == base->resolvedTypes.constEnd()) { - const QQmlType qmltype = base->typeNameCache->query<QQmlImport::AllowRecursion>( - base->stringAt(elementNameId), - typeLoader ? typeLoader : unit->engine->typeLoader()).type; - - if (qmltype.isValid() && qmltype.isInlineComponentType() - && !QQmlMetaType::obtainCompilationUnit(qmltype.typeId())) { - // If it seems to be an IC type, make sure there is an actual - // compilation unit for it. We create inline component types speculatively. - return QQmlType(); - } - - return qmltype; + return visibleQmlTypeByName( + base, base->stringAt(elementNameId), + typeLoader ? typeLoader : unit->engine->typeLoader()); } if (const QQmlType type = (*it)->type(); type.isValid()) diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index aa872eddfb..50cc0a60a0 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -78,13 +78,17 @@ QString QQmlJSCodeGenerator::metaTypeFromName(const QQmlJSScope::ConstPtr &type) QString QQmlJSCodeGenerator::compositeListMetaType(const QString &elementName) const { return u"QQmlPrivate::compositeListMetaType(aotContext->compilationUnit, "_s - + QString::number(m_jsUnitGenerator->getStringId(elementName)) + u")"_s; + + (m_jsUnitGenerator->hasStringId(elementName) + ? QString::number(m_jsUnitGenerator->getStringId(elementName)) + : u'"' + elementName + u'"') + u")"_s; } QString QQmlJSCodeGenerator::compositeMetaType(const QString &elementName) const { return u"QQmlPrivate::compositeMetaType(aotContext->compilationUnit, "_s - + QString::number(m_jsUnitGenerator->getStringId(elementName)) + u")"_s; + + (m_jsUnitGenerator->hasStringId(elementName) + ? QString::number(m_jsUnitGenerator->getStringId(elementName)) + : u'"' + elementName + u'"') + u")"_s; } QString QQmlJSCodeGenerator::metaObject(const QQmlJSScope::ConstPtr &objectType) |