Commit Graph

139 Commits

Author SHA1 Message Date
Olivier De Cannière dd865c1a62 Compiler: Handle method list return types from qmltypes file
When parsing methods details from qmltypes files, the `isList` value
was ignored. It indicates that the return type of the method is a list
of the type specified in the `type` value.

Add the isList flag to QQmlJSMetaParameter and make the return value a
QQmlJSMetaParameter, too, so that we can pass the flag to the type
resolution.

Fixes: QTBUG-122106
Change-Id: I6ea07c02fbeb6cb07d9fe9184205ff7f3274fd73
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit e303d12827)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 411f6cce09)
(cherry picked from commit 7d3204ff06)
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
2024-02-16 19:33:15 +00:00
Ulf Hermann 53eb9f12bb QmlCompiler: In debug mode, set instruction pointer before each lookup
This produces some overhead, but helps with debugging. Without the
instruction pointer we cannot determine the line numbers for
console.trace().

Fixes: QTBUG-119459
Change-Id: I75a6bb1fcedd8514e2ba46d02dd2904ce222f0e4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 28340bdeb0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 166915d89b)
(cherry picked from commit 40e58e3ff7)
2024-02-14 13:26:48 +01:00
Ulf Hermann 6872342167 QmlCompiler: Prohibit non-resettable undefined assignment
If you assign undefined to a property that cannot hold undefined an
exception should be generated. We cannot handle this, yet. Therefore we
prohibit such assignments.

Pick-to: 6.2
Change-Id: I0a034032f4522f017b452690d93319eb4bfedb1c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit afbf7b6990)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit ed50111eeb)
(cherry picked from commit 1b0a03639c)
2024-02-05 14:32:16 +01:00
Ulf Hermann 2658ce4829 QmlCompiler: Prohibit resetting of properties
We cannot assign potential undefined values to resettable properties,
yet.

Pick-to: 6.2
Fixes: QTBUG-120512
Change-Id: I9bca4940256c82bdcf5540b956600eb420be363e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit da6680cb2e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 104c90e883)
(cherry picked from commit 49a62c4102)
2024-02-05 14:32:11 +01:00
Ulf Hermann 4641284889 QmlCompiler: Do not adjust renames
A rename always produces a register with exactly one tracked type, but
we do not want to use it as base for the type adjustments. We want to
adjust based on the original location and its readers (which includes
any renames).

Change-Id: Iaefdf56992c7c101a35a056fb93c49ade5ccf393
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 9f8193b65b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 9b89a021c3)
2023-12-18 16:06:25 +01:00
Ulf Hermann 08e62e3ebe QML: Don't crash when calling coerceAndCall() with null thisObject
Fixes: QTBUG-119395
Change-Id: I5877beef9a53d358a6f58f9ce5029688bd9dcedb
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 87d27d0654)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit d8555a9706)
2023-12-15 12:12:07 +01:00
Ulf Hermann 06c3f86d29 QML: Let IDs in outer context override bound components' properties
This is necessary to make the usage of such IDs actually safe. If we let
local properties override outer IDs, then adding local properties in
later versions invalidates the ID lookups.

[ChangeLog][QtQml][Important Behavior Changes] In QML documents with
bound components, IDs defined in outer contexts override properties
defined in inner contexts now. This is how qmlcachegen has always
interpreted bound components when generating C++ code, and it is
required to make access to outer IDs actually safe. The interpreter and
JIT have previously preferred inner properties over outer IDs.

Fixes: QTBUG-119162
Change-Id: Ic5d3cc3342b4518d3fde1b800efe1b95d8e8b210
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 84d950bc32)
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 852067de0c)
2023-12-06 11:45:31 +01:00
Ulf Hermann 2a23634b21 QmlCompiler: Don't generate invalid code for argument conversion
We need an additional pair of parentheses here.

Pick-to: 6.2
Fixes: QTBUG-119165
Change-Id: I0d8e810ebb5baad35e2cc1bc5c6581d1ba180dc8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 1a8911a13d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit e899a765bf)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-27 11:46:24 +01:00
Ulf Hermann 69257e46ac QmlCompiler: Don't access unavailable input accumulator on 'as'
We only read it if the target type is composite. Therefore, check for
composite first, before looking for the accumulator.

Pick-to: 6.2
Fixes: QTBUG-119122
Change-Id: I2a50214f76ee4ffe2f877dc690704e7475b8bd77
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 096f3c3097)
(cherry picked from commit 23af49f749)
2023-11-21 13:57:45 +01:00
Ulf Hermann 51c99ab3ad QmlCompiler: Do not generate lookups for bare meta enums
Such code is necessarily dead or uncompilable.

Pick-to: 6.2
Fixes: QTBUG-119090
Change-Id: I7319f7ceeb0b4994d5e974bbe8a9c3ba3bf72fc5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 73f66c8f94)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 3896fb0dc6)
2023-11-20 10:16:03 +01:00
Ulf Hermann bd6891b062 QmlCompiler: Always record original types for equality comparison
The shadow check may adjust the types later on and cause a different
comparison to happen than what we've expected when propagating. We can
only see this at code generation time.

Pick-to: 6.2
Task-number: QTBUG-117795
Change-Id: I04f1dd9902385f87114e48b0994e0f243f0c2c84
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
(cherry picked from commit 674dc3f73d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit d827bed6b2)
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
2023-11-13 23:57:27 +01:00
Ulf Hermann 047cd2fcef QmlCompiler: Extend shadow-checking
Method return values as well as whatever we hide behind "unknown" can
contain shadowable properties. We need to check it.

Pick-to: 6.2
Task-number: QTBUG-117800
Change-Id: I518bc11fd0c9c69340bf621198eeaf4c95d17dae
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
(cherry picked from commit 048c8f226a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 590a47bc0c)
2023-11-06 15:51:36 +01:00
Ulf Hermann dadf8a78cd QmlCompiler: Generate jump code also when skipping an instruction
The next instruction may still need the type conversions even if we
don't need to generate any code for the current instruction.

Amends commit 2c410317b6.

Fixes: QTBUG-118514
Change-Id: I70ad3691486176de2177e9d5f538f7c99d121bfa
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit c662ae7cbf)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 1d428b22f7)
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-11-06 09:40:59 +01:00
Ulf Hermann c9f7ba0f2e QmlCompiler: Reject calls to one of multiple fuzzy overloads
If we cannot statically determine the right overload better don't call
any of them for now. Also, allow attempts to pass arguments as derived
types during type propagation.

The test shows that we don't properly pass the thisObject when calling
with metatypes. Fix that, too.

Pick-to: 6.2
Fixes: QTBUG-117922
Change-Id: I02e70ffb9a05f3cfedccafde6e16170b0efbcd29
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 22eaa614ea)
(cherry picked from commit 6c8cf863b8)
2023-10-26 10:56:49 +02:00
Ulf Hermann 68774c8d7b QmlCompiler: Disallow reading enums from instances
Pick-to: 6.2
Fixes: QTBUG-118089
Change-Id: Ib98bb84159847439614341a3cbd4d34d6eabfc8a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 1ba14d58eb)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 89a3cca1ee)
2023-10-26 10:56:33 +02:00
Fabian Kosmale 9be1da7635 qml compiler: Detect if user confuses flags and enums
If you pass the enumeration type to the Q_FLAG macro, you'll get an
qmltypes entry where the type is marked as a flag, but where aliasName
is empty. For backwards compatibility reasons, we cannot static_assert
that the type passed into QFlags is actually a flag type.
When using the interpreter, this does not cause any issues, because the
code there does not need to distinguish flags and enums.
When compilation is enabled, we do however generate bogus code, which
either leads to a wrong result, or to a crash if ASAN is enabled.

Avoid the issue by detecting that the enum is missing, and by rejecting
that case.

Fixes: QTBUG-114326
Change-Id: If5cb801b3cf2c3bd7986ef0c8fc3664e6ed564b8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit f7930126a6)
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-30 17:53:59 +02:00
Ulf Hermann a67e0a6e51 QmlCompiler: Fix console logging
Store a copy of the UTF-8 data for file and function so that we don't
run into heap-use-after-free.

Set the instruction pointer before calling the log function so that we
get a correct line number.

Fixes: QTBUG-114655
Change-Id: I38249fe52719ddad620033716ff22b2087ab8382
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit f6735dba95)
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-08-16 10:47:35 +02:00
Ulf Hermann 8aeef636ba QmlCompiler: Force QObject* for LoadElement on list properties
In the presence of incomplete type information we may otherwise conclude
that the value type is QJSValue and generate broken code.

Change-Id: I533f704a422d0efe8b7b5bb0a170966e9f290b1f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 81bab13560)
2023-07-27 10:18:55 +02:00
Ulf Hermann bb08f1e5af QmlCompiler: Properly reset before re-running basic blocks pass
If we were within dead code at the end of the previous run we need to
reset the "skip until next label" flag. Otherwise we still assume we're
in dead code at the beginning of the function, with interesting effects.

Fixes: QTBUG-114476
Change-Id: Ib6e3d6c81aad4c8aaac12accdb3936e4136235fc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit dae48cf190)
2023-06-22 08:50:02 +02:00
Olivier De Cannière e4ec9a5b79 QmlCompiler: Add missing conversion for equality with null or undefined
The result of the equality check is a bool. However, the expression
using that value may expect another type. It therefore needs to be
converted to that type. This was done implicitly until now because of
the missing explicit conversions. This is a problem because introducing
more conversion options causes an ambiguity in the choice of the
conversion to use. Leading to a compilation error.

For this reason the test is run in a Window because this includes
enough other code to make the implicit conversion ambiguous.

Fixes: QTBUG-114418
Change-Id: I1c3f9ee21f9719cdfbce748a4fd0a687def9d1bf
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 583e8c8216)
2023-06-15 09:38:22 +02:00
Ulf Hermann 8d7facdce7 QML: Allow conversion from QV4::Sequence to different iterable
Fixes: QTBUG-112291
Change-Id: Idd47ea8daf9c54759af6c1feba68bd52d1163615
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 1b89c1edca)
2023-05-11 09:24:36 +02:00
Ulf Hermann 348a539da7 QML: Encode "missing" line number as negated address of stack frame
This way we can identify which entry in a stack frame to amend when
processing an exception in generated code. However, negative line
numbers are also used to signal the position of "Ret" instructions.
Since you cannot throw an exception from a "Ret" instruction, those
cannot collide, but we cannot qAbs() the line number anymore when saving
it in the stack trace. We have to qAbs() it in all the places where it's
read.

Fixes: QTBUG-112946
Change-Id: I24dc4008fb7eab38e4d24e70211c22e46f1b72a7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 406a9e1301)
2023-05-11 09:24:36 +02:00
Ulf Hermann 70f2ef3788 QmlCompiler: Improve method overload selection
If we have an exact match we should definitely use that.

Fixes: QTBUG-113389
Change-Id: I2846ecf6f9963a978b84b70fbe18acdfe6eb45e6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit fc1d258069)
2023-05-08 16:02:12 +02:00
Ulf Hermann a401d523fb QmlCompiler: Disallow reading from values affected by side effects
Instead of accepting the inconsistency between interpreter and compiled
code here, we can just detect whether a value can be affected by side
effects and refrain from reading it then. Since you can always
explicitly reload a value that may have been changed, the resulting
compile warnings are easily worked around in user code. Refactoring user
code this way also makes it much clearer what is actually going on.

Task-number: QTBUG-109221
Change-Id: Ica832e39838ef732b0d181364630737fd7709b74
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 4634b6bf54)
2023-05-05 13:51:51 +02:00
Ulf Hermann c83dd11ebd QML: Fix call frame conversion for QVariant return types
The function may return a QVariant in place of the actual type because
it cannot express the actual type as-is. This case needs special care
because QMetaType::convert() doesn't know what to do with it.

Fixes: QTBUG-112837
Change-Id: Ibf93a28aa6a60d49c5ab63fa7eed5f5a8e58e163
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 44ca1085d6)
2023-05-05 10:39:34 +02:00
Ulf Hermann 8e675e0768 QmlCompiler: Do not stop parsing on top-level Component elements
This just creates an inconsistent state where some of the document has
been parsed and some hasn't. The only thing we actually need is the log
message. Also, fix the warning message.

Amends commit 169f0f7166.

Fixes: QTBUG-112897
Change-Id: Ie8486909f9bea9ee1b87f2857f7b77fb7cc561e8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 1abfb04fae)
2023-05-04 16:51:47 +02:00
Ulf Hermann 3254cf394f QmlCompiler: Do not generate invalid code on generate_As
Task-number: QTBUG-111986
Change-Id: Ib6e7179c20e6c7a4d6fc3a1a17eac550d2bbfa56
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 55cb484934)
2023-03-21 13:46:06 +01:00
Ulf Hermann 56c652f001 QtQml: Always throw when requesting an enum from an invalid singleton
The interpreter does this and so should the enum lookup adapter for
generated C++ code.

Fixes: QTBUG-109816
Change-Id: I576480c3ca808743ddc0ceaf2f0bd8a1de776a41
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 8cbb30a650)
2023-03-02 12:35:51 +01:00
Olivier De Cannière 01cb70002d QmlCompiler: Implement get lookup of variantMap properties
This patch adds support for get lookups of QVariantMap properties.
Setting or modifying is not supported and will reject.

Also, QQmlJSRegisterContent::JavaScriptObjectProperty was
renamed to QQmlJSRegisterContent::GenericObjectProperty

Tests were added to TestQmllint::cleanQmlCode() and
tst_QmlCppCodegen::variantMapLookup().

Fixes: QTBUG-105545
Change-Id: I653ee4e7de1fb1514e1e563a92cfc28633268a7e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit a142873d1c)
2023-02-25 06:43:50 +01:00
Ulf Hermann ecf96e3388 QmlCompiler: Fix coercion of undefined to float and double
It should result in NaN, not in 0. The typedArray() test exposes that
ExecutionEngine::toVariant() also gets this wrong. Fix that, too.

[ChangeLog][QtQml][Important Behavior Changes] Converting a JavaScript
value to a double or float, for example by inserting it into a typed
array, now assumes JavaScript type coercion semantics. In particular,
converting a value that is not actually a number now results in NaN
where it previously sometimes resulted in 0.

Fixes: QTBUG-111179
Change-Id: If24444ae9014c8972761c565a6920f06699e485c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b9834e0ee9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-02-21 14:36:14 +00:00
Semih Yavuz 3eb726a498 qmlsc: Support equality operations for QUrl
Task-number: QTBUG-110983
Change-Id: I9a664178c91bfa2962e2a5a3bf4bfa174a74a9d0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 95228f0e66)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-02-16 12:45:01 +00:00
Ulf Hermann 1367891824 Controls: Use PlatformDialogHelper for enums in DialogButtonBox
Since we're already using 3 of the 4 enums in PlatformDialogHelper, we
can just as well declare PlatformDialogHelper as extended namespace and
avoid all the fiddling with Q_ENUMS and QFLAGS.

As an additional upside, we get code using those enums to compile to
C++ this way.

Fixes: QTBUG-110933
Change-Id: I60bfc15c94133be368fa98ee1b3a0ab7a2bc53ef
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit 82cda71298)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-02-15 15:33:35 +00:00
Semih Yavuz 5fe6501fa3 qmlcachegen: Improve QObject comparison code generation test
The code generated for QObject comparisons holds for both weak and
strong comparisons. Improve tst_qmlcppcodegen by adding missing weak
comparison tests.

Amends afc7928d1a.

Change-Id: Ib6176a39b329e792b81b3d8e8a288dcea074320b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit db71a35b1e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-31 22:01:42 +00:00
Semih Yavuz 4e61da2a00 qmlcachegen: fix nonstrict equality code generation
We should generate type checking code for only strict comparison
of var against null/undefined types or vice versa cases. The non-
strict comparison should be handled elsewhere. Removed pragma Strict to
allow to add warning emitting tests of non-strict comparison.

This amends 6a816a9e0d

Fixes: QTBUG-110769
Change-Id: I7f9a457e71a621a005f377216e841bec01667454
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 66bc001968)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-31 22:01:42 +00:00
Ulf Hermann d7a52f560e QML: Turn singleton/type mismatch into a run time type error
There are many ways to "hide" the qmldir from the engine at run time,
which turns singletons into regular types. While all of this is invalid,
we should not assert on it, but rather produce a legible warning.

Furthermore, sharpen the importing of extra modules from qrc as implicit
imports. We should really only import modules the file in question can
ever be part of. Otherwise we needlessly produce the above situation and
hide legitimate warning messages.

Amends commit 7517c1b3ae.

Now we need to teach our tools about the default import paths in the
resorurce file system. They cannot guess any type they may find in any
resource file anymore.

Task-number: QTBUG-106929
Change-Id: Ic8c02396d10830a7f461e8a81649bb8c9a1add1f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit ddba87612d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-27 12:11:09 +00:00
Ulf Hermann 173da2c34f QML: Allow more conversions between different lists
You should be able to assign any list of QObjects to any other list of
QObjects.

Fixes: QTBUG-108155
Change-Id: I6ddf0b49f7248ad56cc9560d217f3ea316c648a8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 5f3b8bd08c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-26 13:38:24 +00:00
Ulf Hermann 588f9fc17c QML: Allow converting any object list to QQmlListProperty
We can use QSequentialIterable for this.

Fixes: QTBUG-110438
Change-Id: I7e82d0f089c9bb9eab46be46dedc2db3726e64b0
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 6d181fc043)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-25 20:24:26 +00:00
Ulf Hermann ddac1d5d66 qmltyperegistrar: Strip '*' from list value types
We do this for function return types, property types, and function
argument types already. Formally, we would have to store some
"isPointer" somewhere, but considering that we never read it anyway,
let's not go there.

This allows the compilers to recognize lists of QObject-derived types as
proper lists. This way we can generate better code for moving them
around or getting their length.

Task-number: QTBUG-110438
Change-Id: I35e0fc21d574afc18799e9c3cef402f05b60a3ed
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 518509297f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-25 20:24:26 +00:00
Fabian Kosmale 71eeeb9e45 tst_qmlcppcodegen: Add QML dependency for Android
qmlimportscanner is rather limited in how it works,
and does not pick up the Qt.labs.folderlistmodel
dependency for Dialogs.

Fixes: QTBUG-103044
Change-Id: I778f5c8981f1a2603bc3a5d2fd249a83de6c9bd8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit aa551eebb5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-25 20:24:26 +00:00
Ulf Hermann 20374ccf7d QML: Add a pragma for value type behavior
Unfortunately value types behave differently when compiled to C++.
Document the difference and introduce a pragma to make them behave one
way or the other.

Fixes: QTBUG-109221
Change-Id: Ib2685153c0b4ae209bafbea7a01229377fdb47dd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit ec58c0ddb7)
2023-01-24 10:52:07 +01:00
Ulf Hermann b3f81380bd QmlCompiler: Wrap sequences with unknown elemnts in QVariantList
Otherwise we later try to perform value type lookups on them. That won't
work.

Task-number: QTBUG-110438
Change-Id: I1690a3375841ba5a1ff1a471a7f88bd2023ab4c4
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit c9b8b06117)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-24 00:04:25 +00:00
Ulf Hermann b0a681e084 Allow extraction of V4 values from QJSPrimitiveValue
Since we can produce QJSPrimitiveValue in metaTypeFromJS, we should also
handle the other direction.

Fixes: QTBUG-109867
Change-Id: I2c7598d19eba3e78d071ca3eceb32deda4d0ead8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit e070b5aa39)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-17 03:50:51 +00:00
Semih Yavuz cc056ed368 QmlCachegen: Equality comparison ability to QObject *
We should be able to compare QObject * with QObject * or a
nullptr.

Fixes: QTBUG-109377
Change-Id: I0e9d6fdc89cbb471774d6382316dfb4813310e1d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit afc7928d1a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2023-01-10 15:14:29 +00:00
Semih Yavuz 7f3c8b7dd1 QmlCachegen: Equality comparison ability to var and void/null types
The code generator currently rejects any comparisons other than
primitive types. Add comparison capability for var types against
null or undefined types and vice versa. To achieve this, we generate
code that fetches the contained object within the variant and
comparison is done depending on the stored type.

Ideally, we also need to add comparison capability for QObject *, that will be handled with QTBUG-109377.

Fixes: QTBUG-108632
Change-Id: Ib15450d7922f6025c78def5cc548c74827ad740f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 6a816a9e0d)
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-01-10 10:59:53 +03:00
Ulf Hermann 925d60291b QmlCompiler: Fix recognition of builtin list types
Previously all list types used as arguments or return types for methods
had to be looked up via the imports. However, builtin types are not part
of the imports at run time. Therefore, recognize list types already
early on, when generating the IR. This is the same way we do it for
property types and it allows us to easily identify lists of builtins.

Fixes: QTBUG-109147
Change-Id: I91fa9c8fc99c1e0155cc5db5faddd928ca7fabbc
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit c4fc116718)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2022-12-16 12:09:24 +01:00
Ulf Hermann 2b7c811844 QmlCompiler: Fix wrapping of numbers in QJSPrimitiveValue
We need to explicitly cast to double if we are wrapping a number type
that's not natively accepted by the ctors.

As a side effect, correctly run conversions from generic QVariant to
QJSPrimitiveValue through the engine now. For that we need another
clause in metaTypeFromJS().

Since we are calling methods that return list types in the test, we need
to add another clause that converts JS arrays to list types. Otherwise
we cannot run that test in interpreted mode.

Task-number: QTBUG-109111
Change-Id: I87f7aafd24371d2c1ffe85569e1f2cd3a1979742
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b13e22f274)
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2022-12-16 12:09:24 +01:00
Ulf Hermann a521216b71 QmlCompiler: Mark StoreElement on JS values has having side effects
A StoreElement on a JS value can do pretty much anything you can
imagine, after all.

Fixes: QTBUG-109196
Change-Id: Ic638d94b55e6340eb9fe56abc663a6f0f2277f5e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 07d2a80d01)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2022-12-16 12:09:24 +01:00
Fabian Kosmale aa4a1e96b8 QQmlJSCodeGenerator: fix nullptr dereference
If we try to lookup the length of a generic QVariant, we fail, and so
far crashed. We should ideally detect that we are dealing with an array
(and thus length is a known, available property), but for now simply
reject compilation to C++.

Pick-to: 6.4
Fixes: QTBUG-109164
Change-Id: I9d4149ac09a351754d012dbc829774413d6b32eb
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2022-12-12 15:33:18 +01:00
Ulf Hermann ce005eae58 QML: Unify postprocessing of imports
We want to always import dependencies, always import qualified scripts,
and always try to load C++-based types from the binary. Furthermore,
directory imports should be imported with their qmldir URI where
possible, so that we can find them when loading local C++-based types.

Fixes: QTBUG-109109
Change-Id: I58f08f479623a886c802035b41f5f604338468b5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-12-07 16:48:35 +01:00
Ulf Hermann a354d91b88 QmlCompiler: Ignore cloned signals when analyzing signal handlers
We obviously want to see the defaulted parameters when generating the
handlers.

Fixes: QTBUG-108762
Change-Id: I33a52bac305238467d45650bf8a2ad59d40e366f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-12-07 13:50:01 +01:00