diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-04-04 16:54:32 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-04-05 16:09:26 +0200 |
commit | fe9d9b22f20ecfd119c4dcaf1d05f5b27906a49e (patch) | |
tree | f22b510908c9bc919375d495f738e4a3d01221d3 | |
parent | 929e3d080d5cf3eaf314262d6cae6f0f2b913a67 (diff) |
QmlCompiler: Define variables also for conversion registers
The previous code relies on any jump-induced conversion types to also
show up somewhere else. This does not apply to dev because the register
variables have been re-organized there.
Pick-to: 6.2 6.3
Fixes: QTBUG-102273
Change-Id: I7723ff3b4992cecc38ce531e76494874910dfaea
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 37 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/fromBoolValue.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 17 |
4 files changed, 47 insertions, 14 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 34bb402f7e..fb7bdd8d0b 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -104,26 +104,35 @@ QQmlJSAotFunction QQmlJSCodeGenerator::run( m_error = error; QSet<QString> registerNames; + const auto defineRegisterVariable = [&]( + int registerIndex, const QQmlJSScope::ConstPtr &seenType) { + // Don't generate any variables for registers that are initialized with undefined. + if (seenType.isNull() || seenType == m_typeResolver->voidType()) + return; + + auto &typesForRegisters = m_registerVariables[registerIndex]; + if (!typesForRegisters.contains(seenType)) { + QString variableName = u"r%1"_qs.arg(registerIndex); + if (registerNames.contains(variableName)) + variableName += u'_' + QString::number(typesForRegisters.count()); + registerNames.insert(variableName); + typesForRegisters[seenType] = variableName; + } + }; + for (const InstructionAnnotation &annotation : *m_annotations) { for (auto regIt = annotation.registers.constBegin(), regEnd = annotation.registers.constEnd(); regIt != regEnd; ++regIt) { - int registerIndex = regIt.key(); - - const QQmlJSScope::ConstPtr seenType = regIt.value().storedType(); - // Don't generate any variables for registers that are initialized with undefined. - if (seenType.isNull() || seenType == m_typeResolver->voidType()) - continue; + defineRegisterVariable(regIt.key(), regIt.value().storedType()); + } - auto &typesForRegisters = m_registerVariables[registerIndex]; - if (!typesForRegisters.contains(seenType)) { - QString variableName = u"r%1"_qs.arg(registerIndex); - if (registerNames.contains(variableName)) - variableName += u'_' + QString::number(typesForRegisters.count()); - registerNames.insert(variableName); - typesForRegisters[seenType] = variableName; - } + for (auto regIt = annotation.expectedTargetTypesBeforeJump.constBegin(), + regEnd = annotation.expectedTargetTypesBeforeJump.constEnd(); + regIt != regEnd; + ++regIt) { + defineRegisterVariable(regIt.key(), regIt.value().storedType()); } } diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 36741105af..038557bd22 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -66,6 +66,7 @@ set(qml_files failures.qml fallbacklookups.qml fileDialog.qml + fromBoolValue.qml functionLookup.qml funcWithParams.qml functionReturningVoid.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/fromBoolValue.qml b/tests/auto/qml/qmlcppcodegen/data/fromBoolValue.qml new file mode 100644 index 0000000000..f56a75ecea --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/fromBoolValue.qml @@ -0,0 +1,6 @@ +pragma Strict +import QtQuick 6 + +Item { + height: !(parent && parent.visible) ? 100 : 0 +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index bc6fa5a106..e088556f0f 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -126,6 +126,7 @@ private slots: void testIsnan(); void fallbackLookups(); void prefixedMetaType(); + void fromBoolValue(); }; void tst_QmlCppCodegen::simpleBinding() @@ -1906,6 +1907,22 @@ void tst_QmlCppCodegen::prefixedMetaType() QVERIFY(qvariant_cast<QObject *>(o->property("f")) == nullptr); } +void tst_QmlCppCodegen::fromBoolValue() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/fromBoolValue.qml"_qs)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QCOMPARE(o->property("height").toInt(), 100); + + QScopedPointer<QObject> parent(c.create()); + o->setProperty("parent", QVariant::fromValue(parent.data())); + QCOMPARE(o->property("height").toInt(), 0); + + parent->setProperty("visible", QVariant::fromValue(false)); + QCOMPARE(o->property("height").toInt(), 100); +} + void tst_QmlCppCodegen::runInterpreted() { if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER")) |