Commit Graph

163 Commits

Author SHA1 Message Date
Ulf Hermann 8d9dfd3347 QmlCompiler: Fix conversion from/to void
We can convert everything to void, but we can only convert from void if
the result is either void or the invalid type.

Pick-to: 6.6
Fixes: QTBUG-116088
Change-Id: I532055405865c5b1581f79cc5d76c253bce6138d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-08-23 15:30:11 +02:00
Ulf Hermann 2eac7350c0 QmlCompiler: Stabilize test
Loading the implicit import might add extra types that use up indices.
So, make sure the implicit import has already been loaded at that point.

Use a file that only has one type reference so that the ordering of type
references cannot mess up the selection of indices for types.

Change-Id: Ia33979e660e114ef608e1f5e22252c822c7f3d61
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-08-22 20:11:34 +02:00
Ulf Hermann d908d5e57c QmlCompiler: Allow construction of Array objects
Currently, only the constructor form of the Array function is compiled.
We only compile construction of Array objects if we can determine that
they are immediately assigned to a typed list. Consequently, we don't
have to deal with sparse arrays.

Change-Id: I2abd15139eb9a0d530ad49df7313b8dba415ae77
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-22 17:16:53 +02:00
Ulf Hermann 0f23346d2a QmlCompiler: Allow construction of Date objects
We map Date to QDateTime and special-case its constructors.

Task-number: QTBUG-111624
Change-Id: I0496f853613da3ccee9b6f6c4cf0adffa064f9f8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-08-18 14:26:04 +02:00
Sami Shalayel a1ce0596e5 Replace signal name manipulations with QQmlSignalNames
Remove custom implementations found in qqmljs* and use the
static helper methods from qqmlsignalnames_p.h instead. This sometimes
requires to move some code around to avoid bugs with property that do
not have letters in their name.
Add a warning in the JS implementation of the SignalSpy.qml that the
used heuristic might fail on certain signal names.
Add tests in in tst_qqmllanguage to see if the property change handlers
work correctly for weird names.

Change-Id: I4dc73c34df7f77f529511fa04ab5fcc5385b59fc
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-15 12:13:31 +00:00
Ulf Hermann d07744ef5d QmlCompiler: Fix SetLookup on shadowable properties
If we are procedurally setting a shadowable property, the read register
for the value will be converted to var. We can therefore not just
retrieve the property type again in the code generator to determine what
we have to do.

What we actually need is the information on the original scope type of
the lookup. We need to know what exactly the base type was supposed to
be. To that effect, store the scope of the target for each conversion in
QQmlJSRegisterContent.

We need to circumvent the questionable optimization of "deduplicating"
functions that certain compilers exhibit, like we do for the getters.

Pick-to: 6.6
Fixes: QTBUG-115526
Change-Id: I361f2e46e39ece7892df72ae13ec756f9aec4adf
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-08 15:12:46 +02:00
Olivier De Cannière 2cf9aeccdd Compiler: Separate function prolog block and add validation of blocks
The function prolog logic is now separated in its own basic block. The
first "real" block with user code starts at offset 0.

Having the function prolog as a hidden part of the first block caused
some inconsistencies in block generation and would create empty blocks.
This happened for example when a back edge of a loop would target offset
0 in code where a loop condition is the very first set of instructions
that are run. This is because the target block offset didn't exist due
to it being part of the hidden prolog block.

Validation for the basic blocks was also added. This checks for three
things at the moment:
1. That return and throw blocks don't have jump targets.
2. That the basic blocks graph is connected.
3. That jump targets are the first offset of a block.

Test tst_QmlCppCodegen::basicBlocksWithBackJump_infinite() is expected
to fail because it contains an infinite loop and the basic blocks that
are generated for it are inconsistent due to dead-code elimination
happening earlier in compilation.

Debug outputs for dumping basic blocks were also adapted to reflect
these changes.

Change-Id: I513f73856412d488d443c2b47a052b0023d45496
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-04 09:34:09 +02:00
Ulf Hermann fa6aedf7ac QmlCompiler: Allow calling methods on potentially undefined QObjects
We can use the same technique as for GetLookup there. Just check the
variant for validity to see if we can call it.

Change-Id: I1bcf4a5a84f47e0236762827488bc5d03e015efb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-07-28 16:42:45 +02:00
Ulf Hermann 81bab13560 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.

Pick-to: 6.6 6.5 6.2
Change-Id: I533f704a422d0efe8b7b5bb0a170966e9f290b1f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-07-26 16:54:52 +00:00
Ulf Hermann 747c860354 QmlCompiler: Correctly handle lookups in results of method calls
Method calls often return just QVariant because we cannot be sure that
the method hasn't been shadowed. In order to figure out the right lookup
we should look at the type the type propagator assumed as the base of
the lookup. If the type propagator was assuming a list-length lookup we
need to try and generate a list-length lookup. If the base turns out to
be a QVariant after shadow-checking, the code generation will cleanly
fail (and refrain from generating bad code).

Amends commit 46cc70e2aa.

Pick-to: 6.6
Fixes: QTBUG-115278
Change-Id: I24dcd06161eb1af44450fb663d68a16d89efd6ac
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-07-25 16:33:29 +02:00
Ulf Hermann fb4cc245e0 QmlCompiler: Optimize storage for register variables
We don't need nested hashes there. A single hash is enough, and we also
don't need to key it by pointers. Keying it by internalName instead
makes the ordering deterministic. We also don't need to duplicate-track
the variable names when outputting the declarations anymore.

Verify that qmlcachegen's output is actually stable by compiling the
entire test data for tst_qmlcppcodegen twice, packaging the generated
code into the resource file system, and comparing it in a separate test.

Pick-to: 6.5 6.6
Fixes: QTBUG-115159
Change-Id: I659661e58a52ed9ff308c83d6c821cf016f2e94e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-07-24 21:26:57 +02:00
Ulf Hermann ca27c051ab QmlCompiler: Allow creation of structured value types
With this change, qmlcachegen can populate structured value types from
object literals.

Also fix the construction of value types via Q_INVOKABLE ctors. We don't
need to wrap the ctor argument in QVariant if we can store the original
type, and we should always look at the base type for the creatable flag,
not the extension.

Task-number: QTBUG-107469
Task-number: QTBUG-112485
Change-Id: I9f3db13f00466dc9d87237bdf0b380d6eeb58a10
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-07-06 21:29:39 +02:00
Fabian Kosmale f7930126a6 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.

Pick-to: 6.6 6.5
Fixes: QTBUG-114326
Change-Id: If5cb801b3cf2c3bd7986ef0c8fc3664e6ed564b8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-06-29 09:28:52 +02:00
Ulf Hermann c6d599bf60 QmlCompiler: Use int for flag-type enums
The isFlag flag overrides the underlying type as the resulting type is
then a QFlags.

Pick-to: 6.6
Fixes: QTBUG-114815
Change-Id: I9cc3b260a280b784fc8af38fafbc9ffbd7ca3453
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-06-23 21:22:34 +02:00
Ulf Hermann 779f6cf08c QmlCompiler: Add further tests for DTZ
Apparently we had some intermediate state where these ones were broken.
Let's make sure this doesn't happen again.

Pick-to: 6.6
Fixes: QTBUG-113403
Change-Id: If1da8200afe5c7cee417cd755a15251979fb18c5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-06-23 18:49:37 +00:00
Ulf Hermann dae48cf190 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.

Pick-to: 6.5 6.6
Fixes: QTBUG-114476
Change-Id: Ib6e3d6c81aad4c8aaac12accdb3936e4136235fc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-06-21 14:14:39 +02:00
Olivier De Cannière 583e8c8216 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
Pick-to: 6.5 6.6
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>
2023-06-12 13:32:15 +02:00
Ulf Hermann e6dd62ff19 QmlCompiler: Do check specificType on SetLookup
We may have implicitly invalidated it when shadow-checking.

Amends commit b3281f123e.

Change-Id: Ia5c54a3a0fa97c61e947ecb0a5b21d410e1bf19a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-05-15 10:46:27 +02:00
Ulf Hermann 60a34c3393 QmlCompiler: Optimize list manipulations
We should never store a list in a wrapper type that is itself a
different list. Wrapping and unwrapping requires rebuilding the list in
such cases. We can, however, store lists of builtins as-is. There is no
need to transform them. Other lists can still be stored in QVariant.

As a result, we now need to discern between the access semantics of the
stored type and the access semantics of the contained type. They are not
guaranteed to be the same anymore. Furthermore, we need to reject
"internal" manipulation of QVariant-wrapped lists for now. We might
implement them using QMetaSequence, though.

Task-number: QTBUG-113465
Change-Id: If09ea345b2fac39bf2abd62a2fce2d354df85b6b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-10 09:28:59 +02:00
Ulf Hermann 71b4a5e6df QmlCompiler: Re-allow conversion from QObject to QString
It only worked for the console functions in 6.5. There it was suppressed
by the enforcement of type conversions in the basic blocks pass in dev.

We have, however, a good enough way to coerce QObject to QString these
days.

Task-number: QTBUG-112291
Change-Id: I025976cc7fbe430c5cdc607cae3ca48838b24f88
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-09 21:28:07 +02:00
Ulf Hermann 9cead49c0e Properly support lists as method arguments
a, Teach QV4::QObjectWrapper how to convert QQmlListProperty to
   QObjectList.
b, Parse the isList attribute from qmltypes.
c, Resolve lists when resolving QQmlJSScope.

Change-Id: I70c6d40507de990b45a87eb7d8c7bba279d550e8
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-09 21:28:06 +02:00
Ulf Hermann 406a9e1301 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.

Pick-to: 6.5
Fixes: QTBUG-112946
Change-Id: I24dc4008fb7eab38e4d24e70211c22e46f1b72a7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-09 21:28:06 +02:00
Ulf Hermann 1b89c1edca QML: Allow conversion from QV4::Sequence to different iterable
Pick-to: 6.5
Fixes: QTBUG-112291
Change-Id: Idd47ea8daf9c54759af6c1feba68bd52d1163615
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-09 21:28:06 +02:00
Ulf Hermann 96ac9c2599 QmlCompiler: Convert thisObject to correct type
Amends commit 365b781599.

Change-Id: I5775d634ef4e5204cdec2f440b1992b7272866d2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-04 18:59:34 +02:00
Ulf Hermann 4634b6bf54 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.

Pick-to: 6.5
Task-number: QTBUG-109221
Change-Id: Ica832e39838ef732b0d181364630737fd7709b74
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-04 16:44:44 +02:00
Ulf Hermann 44ca1085d6 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.

Pick-to: 6.5
Fixes: QTBUG-112837
Change-Id: Ibf93a28aa6a60d49c5ab63fa7eed5f5a8e58e163
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-04 11:48:09 +02:00
Ulf Hermann b8814dfb36 QmlCompiler: Do not crash when converting number literals to enums
Amends commit 2a21efb5f7.

Change-Id: Id7d739b58c723eed9f165951b51ee2e5e55d7fe2
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-05-04 11:48:09 +02:00
Ulf Hermann 1abfb04fae 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.

Pick-to: 6.5
Fixes: QTBUG-112897
Change-Id: Ie8486909f9bea9ee1b87f2857f7b77fb7cc561e8
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-05-03 14:38:52 +02:00
Ulf Hermann 25b259270d tst_qmlcppcodegen: Sort QML files again
Keeping them sorted reduces the chance of collisions and makes it easier
to find related ones.

Change-Id: Ie05cbfefa5805cd27ec91e566dd922107c70d8e2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-02 19:29:25 +02:00
Ulf Hermann 46cc70e2aa QmlCompiler: Relax shadowing check
If we detect a property or method as potentially shadowed, we don't have
to abandon all hope. We can still retrieve it as untyped var. Since
there are a number of things we can do with untyped var, this may still
be useful.

In the same sense, we need to treat function calls as untyped when the
function in question can be shadowed. Calling functions with var
arguments and return types leads to some more interesting situations in
the call frame setup, so we fix that, too.

Task-number: QTBUG-112480
Change-Id: I238d1cf04951f390c73e14ed9e299f2aa72b68cb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-02 19:29:25 +02:00
Ulf Hermann e846864151 QmlCompiler: Inline some array methods
So far we can only deal with methods that don't change the source array
and don't use iterators or functions as parameters. We also omit
concat() for now. However, indexOf(), lastIndexOf(), includes(),
join(), slice() and toString() are possible already now.

Task-number: QTBUG-112722
Change-Id: Id19c74e8ad25af876bc954c040c767823b7e3259
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-04-28 21:24:17 +02:00
Ulf Hermann f10630aa03 QmlCompiler: Use actual type of enums, rather than int
Now that the type is available from qmltypes we can just use it.

Task-number: QTBUG-112180
Change-Id: I315372da0925f19c209f676226f450863b0d3ea5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-04-26 10:57:27 +02:00
Ulf Hermann 365b781599 QmlCompiler: Implement ConvertThisToObject and basic DTZ
We know that 'this' is a QObject* since the metatypes stack frame
mandates it. Whenever you pass 'this' to anything it's loaded from the
special 'This' stack slot which then triggers a DTZ check. A DTZ check
is a noop if we can prove that the type is statically known, though.

In QmlCompiler, if we have a valid register content, then the register
has been set in all code paths that lead to the instruction in question.

Fixes: QTBUG-111439
Change-Id: I81d1cd140eea63f85628c3bef3a8f6db0a12096d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-04-25 16:53:00 +02:00
Ulf Hermann 653a6ff82a QmlCompiler: Recognize QStringList and QVariantList as special lists
They are equal to QList<QString> and QList<QVariant>, respectively. We
cannot express this fact in qmltypes, but since those are builtin, we
can just hardcode it.

Task-number: QTBUG-112227
Change-Id: Iebeb5f6a5350d1c7184b1d9e6a38647e048c3806
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-04-24 22:22:14 +02:00
Ulf Hermann fa259ed4ff QmlCompiler: Allow conversion from QQmlListProperty to QList
In the happy case this just retrieves the internal QList from the list
property. In the sad case it produces a deep copy. That's not worse than
what the interpreter does, though.

Fixes: QTBUG-112227
Change-Id: I8b2b0ac74c90b6dcee876e83a64502756733c1c5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-04-24 22:22:14 +02:00
Ulf Hermann 7c2e31c34f QmlCompiler: Don't crash on bad list type in signature
Pick-to: 6.5
Change-Id: I2c4a4ffa810258134a29b87aff46e8eb544b6a55
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-04-19 20:01:09 +02:00
Ulf Hermann 1ceaeab982 QmlCompiler: Don't crash when checking for enum problems
When checking for CallProperty we want the call base, not the
accumulator.

Pick-to: 6.5
Change-Id: I24ac066dd440bde459e20b3cf962af04ca531629
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-04-19 20:01:09 +02:00
Ulf Hermann b3281f123e Fix content pointer check for QObject*
It can actually be null rather than undefined. We need to generate a
separate check for that and output the correct error messages.

Amends commit 05f56d7c78

Change-Id: Ia795e31805181640cd5be19359af51067d3fc8d6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-04-19 09:30:58 +02:00
Ulf Hermann f27cb5e3c1 QmlCompiler: Merge bool and any pointer type into the pointer type
A pointer type can hold bool as either nullptr or some value. We don't
need to produce a QVariant for that.

Change-Id: I368c3fa703d08ff396a5b4702ba7d1f2614b1467
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-04-15 20:14:42 +02:00
Ulf Hermann 03ff348b49 QmlCompiler: Support more integer types
This adds support for 8- and 16-bit signed and unsigned integer types.
The test exposes that the engine fails to correctly convert out of range
values when assigning to a 32-bit int property. Fix that as drive-by.

Fixes: QTBUG-101634
Change-Id: I0a4177f49ffc062a1f444e30424e94c1f293e70c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-30 15:46:55 +02:00
Ulf Hermann 55cb484934 QmlCompiler: Do not generate invalid code on generate_As
Pick-to: 6.5 6.5.0 6.2
Task-number: QTBUG-111986
Change-Id: Ib6e7179c20e6c7a4d6fc3a1a17eac550d2bbfa56
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-17 20:57:14 +01:00
Ulf Hermann ec410555ad QmlCompiler: Allow coercing anything to bool
JavaScript can coerce anything to bool, so should we.

Change-Id: Id560e4c1dc10b5432c0cedf3110ad3377bbc5f59
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-10 23:42:49 +01:00
Ulf Hermann 2a21efb5f7 QmlCompiler: Use value type ctors
This allows us to do the relevant conversions in a more civilized way,
dropping the outputVariantConversion() method. The latter is brittle
because you have to manually add it to each instruction, and it uses
QMetaType::convert() which is actually not guaranteed to give the same
results as a QML type coercion.

Task-number: QTBUG-94807
Change-Id: I4d6d05a60beb3b4dfc3da6f0142de25667510904
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-09 21:36:30 +01:00
Ulf Hermann 05f56d7c78 QML: Allow as-casting to value types
If the "Addressable" option to ValueTypeBehavior is set, you can use the
"as" operator to cast a previously unknown type into either undefined
or the given type. We can use this in qmlcachegen to generate efficient
code for further operations on the same type.

In the generated C++ it in fact only works for GetLookup because:
a, We generally don't do SetLookup on value types, yet.
b, We generally don't call methods on value types, yet.
c, We cannot store a union of undefined and a sequence type, yet.

However, getting properties of value types is the most important
application of the new casts so this is well worth it.

As a side effect we can also look up things in potentially undefined
results of other operations now. For example list lookups.

Task-number: QTBUG-94807
Change-Id: Ifdf34f1f3f67b7a0a8953b9ed0e947b74638a28c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-03 12:02:00 +01:00
Ulf Hermann 35152b432e QML: Add an "Addressable" value to ValueTypeBehavior
Task-number: QTBUG-94807
Change-Id: I8c78faa99fc4c4b2ffd8c89f1037fc7569212c73
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-02 17:54:30 +01:00
Ulf Hermann fc1d258069 QmlCompiler: Improve method overload selection
If we have an exact match we should definitely use that.

Change-Id: I2846ecf6f9963a978b84b70fbe18acdfe6eb45e6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-02 13:17:47 +01:00
Ulf Hermann 8cbb30a650 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.

Pick-to: 6.5 6.4 6.2
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>
2023-03-01 11:56:19 +01:00
Olivier De Cannière 98849309a2 QmlCompiler: Implement multi-argument Math.{min,max}()
This patch extends the logic for the 2-argument Math.min() and
Math.max() functions by reutilizing the same logic to compare two
elements and evaluate all arguments with the current max or min.

Fixes: QTBUG-108741
Change-Id: I993a26a1d44d66226c751272dfc2dc63330d115d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-02-23 09:51:22 +01:00
Olivier De Cannière a142873d1c 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().

Pick-to: 6.5
Fixes: QTBUG-105545
Change-Id: I653ee4e7de1fb1514e1e563a92cfc28633268a7e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-02-22 16:21:09 +01:00
Amir Masoud Abdol 8f7080fd09 Replace AUTO_RESOURCE_PREFIX with Qt CMake Policy in examples, tests
Every instance of AUTO_RESOURCE_PREFIX has been replaced by either
qt_standard_project_setup(REQUIRES 6.5) or with
qt_policy(SET QTP0001 NEW), mainly in tests.

In addition, I added a warning message for the case where
AUTO_RESOURCE_PREFIX is used.

Pick-to: 6.5
Task-number: QTBUG-96233
Change-Id: I323a15e9d0bb5fe6ba649365314af9fc2ad67bda
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
2023-02-21 19:45:44 +01:00