aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljscompiler.cpp
Commit message (Collapse)AuthorAgeFilesLines
* qmllint: Also lint inner functionsOlivier De Cannière2025-11-051-3/+9
| | | | | | | | | | | | | | | | | | | We were only collecting the 'QML' functions that would be passed to the AOT compiler. Other function types were ignored. Also collect those and pass them to the compiler but only use them when linting. Defer invistigating whether it is a good idea to try to compile JS functions as well to a later point. Logic in a few places was adapted with this changing assumption. [ChangeLog][QML][qmllint] qmllint will now lint inner functions, defined in javascript, in addition to top-level functions and bindings. Fixes: QTBUG-138845 Pick-to: 6.10 6.8 6.5 Change-Id: If6f62aeace8739442b6a1f355fad95ce19c0643c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add security header for src/qmlcompilerOlivier De Cannière2025-09-171-0/+1
| | | | | | | | | | | | | | | | | | We assume that QML or JS code comes from a trusted source. Therefore, most files are deemed to be significant even if they parse data. This includes the source code itself but also the associated metadata or cache files. However, the QML compiler also generates C++ code. Extra care needs to be taken with the generator as a vulnerability there could propagate and have a disproportionate effect on the program's security. It is marked as critical. QUIP: 23 Fixes: QTBUG-136195 Pick-to: 6.10 6.9 6.8 Change-Id: I70630361ec8e9cb3969f78a3fdf36a41334a33b3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Pass QQmlJSSaveFunction as const refUlf Hermann2025-08-071-4/+4
| | | | | | | | std::function is quite heavy-weight. Coverity-Id: 486648 Change-Id: Ia7c61a726bde9c9d6a02412b9aa5f683bb4d355a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSImportVisitor: Add constructor without targetFabian Kosmale2025-06-161-2/+1
| | | | | | | | | | | In many cases, we were passing a fresh scope to the QQmlJSImportVisitor as the target. Add a new constructor whih takes care of this, and use it wherever possilbe. This allows disambiguating between call-sites that update an existing scope, and those which will create a new one. Change-Id: I140c349ac2f17371b7916d38225170420053a718 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML compiler: Fix Unity build on WindowsFriedemann Kleint2025-06-041-4/+4
| | | | | | | | | | Somehow, qt_windows.h gets in the mix which has the 'interface' define. Rename the variable. Pick-to: 6.10 6.9 Task-number: QTBUG-115140 Change-Id: I6d46d66d0db3350a975984bcc6c4858214615c8b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Compiler: Adapt AotStats to skipping functionsOlivier De Cannière2025-04-171-3/+9
| | | | | | | | | | | A revision was also added to the aotstats json format. Print a message asking the user to try again with a clean build if a missmatch in revision is found. Task-number: QTBUG-134790 Pick-to: 6.9 6.8 Change-Id: I0961bf841db17f280492ec787f404d9fe9b563f4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Compiler: Add infrastructure to skip functionsOlivier De Cannière2025-04-171-10/+18
| | | | | | | | | | | | | | When trying to compile a function in the compiler, sometimes, the outcome is neither successful compilation nor an error. Introduce skiping functions for those cases. When a function is skipped its compilation has not failed. Skipping is therefore allowed in strict mode. Task-number: QTBUG-134790 Pick-to: 6.9 6.8 Change-Id: I0f1ca85404db8dd4c87cd5eb9b96c9dc8cc8d290 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Rename "unit" argument to the signature generatorUlf Hermann2025-04-111-1/+1
| | | | | | | | | | It clashes with another "unit" in the same namespace. Pick-to: 6.9 6.8 Fixes: QTBUG-134911 Change-Id: I4a6eca75fe688f1cf08633af6a68c4481178608d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Make UsesArgumentsObject a scoped enumerationLuca Di Sera2025-04-101-1/+1
| | | | | Change-Id: I766dc99b8daaeaa64da9075dcfde5dff507c27f2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Compiler: Fix various clazy warningsOlivier De Cannière2025-03-211-2/+2
| | | | | Change-Id: Ib83c8d3452d5a0521295750f068f429b414da6ff Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Fix assignment of fileName and URL during compilationUlf Hermann2025-02-041-7/+12
| | | | | | | | | | | We need to assign them right away when creating the module. If we do it later on, there are a lot of different code paths to cover and in fact we were missing some. Pick-to: 6.9 6.8 Task-number: QTBUG-133053 Change-Id: I57e381c787f504eb9bcd8c2041e41b4f1d1f8b53 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Clean up error handlingUlf Hermann2025-02-021-43/+49
| | | | | | | | | | | | | | | | We should only have one way to handle diagnostic messages: The QQmlJSLogger. In addition each compile pass may result in an error that prevents the running of further passes. But that error should not rely on the selection of messages posted earlier. For this to work we need to introduce a further state transition into the logger. The logger now "archives" messages after compiling each function, so that only the current function's compile errors are taken into account as result of the current function's compilation. Task-number: QTBUG-124913 Change-Id: I4b6d9910b80527cefb1aba02598114d1fe5ba172 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* QmlCompiler: Do not post-process compile errorsUlf Hermann2025-01-241-26/+12
| | | | | | | | | | We can determine the correct QtMsgLevel and prefix early on and set that right away. Doing so will allow us to use the logger also for compiler errors and remove the extra list of messages in a second step. Task-number: QTBUG-124913 Change-Id: I145be21d0a210f07245aa19e3124634cdd4800b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Further reduce duplication of warnings about missing propertiesUlf Hermann2025-01-231-7/+5
| | | | | | | | | | If a function's signature cannot be resolved, we don't need to compile it. Amends commit 746f38bf56027c29a72bd8a3c3a5f9aad73b9bd3 Pick-to: 6.9 6.8 Task-number: QTBUG-124913 Change-Id: I25707dbb5118b1cfc39adade4bf78603dee38608 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Reduce duplication of warnings about missing propertiesUlf Hermann2025-01-171-2/+7
| | | | | | | | | | | | If a property cannot be found, we don't need to check its type or even try to compile a binding for it. We also shouldn't claim a property doesn't exist if we cannot find it. We may have failed to resolve the type after all. Pick-to: 6.9 6.8 Task-number: QTBUG-124913 Change-Id: I93ef12e888762ae03f8fa6b1bef2e8d04ba3d4b2 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QtQml: Generalize the global/illegal namesUlf Hermann2024-12-171-14/+3
| | | | | | | | | Instead of passing them around everywhere, use the ones we statically know and only validate them when creating a new engine. Task-number: QTBUG-131721 Change-Id: I7fb93d15eb6e4194c46249727bcf7a48f5dce730 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Compiler: Make qqmljsscope::filePath hold the source location more oftenOlivier De Cannière2024-10-311-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Previously, it would hold the location of the copy in the build directory or in the resource file system. This should improve the accuracy of the information that we can report back. For example, the file location of files reported in aotstats will now be those in the source folder. The changes necessary for this patch were found through trial and error by asserting that the filePath respect a certain form and fixing what I could. There remain cases where the filePath still contains a location in the build directory. We would need some other change to report those accurately as well. Finally, sometimes the filePath is empty or does not contain a valid path at all but instead what seems to be the location of an included file. It can have the form "private/..._p.h" for example. Pick-to: 6.8 Change-Id: I77a2596f6c4a179580d924a6e9324e43dbb86c0c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Rename QQmlJSLogger's fileName to filePathOlivier De Cannière2024-10-311-1/+1
| | | | | | | | | This is done in prepartion for the following patch in the chain. Pick-to: 6.8 Change-Id: If8ce75be8ba00e7e4cdd5a0f5e66319ab0d36755 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix various coverity warningsUlf Hermann2024-09-031-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | Pass values by const ref or move them, but don't pass them as copies. Coverity-Id: 467911 Coverity-Id: 467912 Coverity-Id: 467913 Coverity-Id: 467914 Coverity-Id: 467915 Coverity-Id: 467916 Coverity-Id: 467917 Coverity-Id: 467918 Coverity-Id: 467919 Coverity-Id: 467920 Coverity-Id: 467921 Coverity-Id: 467922 Coverity-Id: 467923 Coverity-Id: 467924 Coverity-Id: 467925 Coverity-Id: 467926 Coverity-Id: 467927 Coverity-Id: 467928 Change-Id: I1549e1f3365c6becc330603959a71b2058e1b1fa Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Compiler: Create infrastructure to support multiple warningsOlivier De Cannière2024-08-211-56/+66
| | | | | | | | | | | | | | | | | Currently only one DiagnosticMessage can be stored at a time when using the compiler. However, we want to be able to show more than one to the user. Therefore, use a list that gets passed inside the compiler instead of a pointer to the sole error. This also means that the error is valid by its very existence. There is no need to check validity explicitly anymore. Task-number: QTBUG-127624 Change-Id: I356db917b86703b508dc1ad52de7825d82eafd71 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Remove QQmlJSTypeResolver::containedType()Ulf Hermann2024-06-161-1/+1
| | | | | | | | | We don't need the type resolver anymore to determine the contained type. QQmlJSRegisterContent can do it by itself. Change-Id: I395dc76cff751f6ac1afdfcd4ef7f80f05fcc36f Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Create QQmlJSRegisterContent unstoredUlf Hermann2024-06-161-1/+7
| | | | | | | | | | Add a separate pass to populate the stored types and only run that after we're done with all the type propagation and optimization. Task-number: QTBUG-124670 Change-Id: I740063908b22684f5d2c72d6261fad98850d8636 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Divide scope-name lookup methods into multiple casesUlf Hermann2024-06-151-1/+2
| | | | | | | | | | | | | | | | | * One method for IDs only, since that seems to be common * One method operating on QQmlJSRegisterContent all the way * One method operating on QQmlJSScope::ConstPtr all the way This way we can return a QQmlJSScope::ConstPtr where we are not interested in register contents, and in a next step, link the register contents together in case we are interested. We need to store the function's QML scope as QQmlJSRegisterContent now. Task-number: QTBUG-124670 Change-Id: I01699aaa5f645657d9faf23b12e270cf09679499 Reviewed-by: Alexei Cazacov <alexei.cazacov@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix various style issuesUlf Hermann2024-06-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Don't copy QQmlJSScope::ConstPtr where it can be avoided, keep things const where we can, pass values as const ref and return them as value, std::move where possible and easily visible. Coverity-Id: 462267 Coverity-Id: 462268 Coverity-Id: 462269 Coverity-Id: 462271 Coverity-Id: 462272 Coverity-Id: 462273 Coverity-Id: 462275 Coverity-Id: 462276 Coverity-Id: 462277 Coverity-Id: 462278 Coverity-Id: 462279 Coverity-Id: 462281 Coverity-Id: 462283 Coverity-Id: 462284 Coverity-Id: 462285 Change-Id: I2c8f2267d5ab521145111f7b56eaad6cf0234a77 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Compiler: Record statistics about aot compilationOlivier De Cannière2024-05-281-2/+27
| | | | | | | | | | | | | This patch introduces the collection of statistics about the ahead-of-time compilation of functions and bindings to Cpp by qmlcachegen. This is done by having qmlcachegen save an aotstats file for every qml file it compiles. This file contains, for every function and binding, whether the Cpp codegen was successful, its duration and a potential error message Task-number: QTBUG-124667 Change-Id: Iba9a72be04f6642688533a3ae12ea687296c85e1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Properly enforce signatures of AOT-compiled functionsUlf Hermann2024-04-261-14/+7
| | | | | | | | | | | | | Pass the metatypes of the contained types rather than the stored types. [ChangeLog][QtQml][Important Behavior Changes] The AOT compiled code for type-annotated JavaScript functions does not let you pass or return values of the wrong type anymore. Fixes: QTBUG-119885 Change-Id: I685d398c0745d32a999a3abd76c622a2c0d6651f Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Perform return value assignment inside generated codeUlf Hermann2024-04-241-24/+4
| | | | | | | | | | | | This is in preparation for using exact types and actually enforcing them. We shouldn't wrap the return value into a QVariant in order to then painstakingly unwrap it again. The generated code can already do the right thing. Task-number: QTBUG-119885 Change-Id: I13e517967ee982be717024a9abb74d5e02a185d6 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Compiler: Extract Basic blocks generation into its own compiler passOlivier De Cannière2024-04-191-13/+20
| | | | | | | | | | | | | | | The old basic blocks pass was responsible for two things: the basic blocks generation and dead code analysis/type adjustments based on those blocks and the type propagation performed earlier. Now the basic blocks get generated first, even before the type propagation and the dead code analysis and type adjustments are now grouped in a pass called QQmlJSOptimizations. The rest of the passes remain unchanged. Change-Id: I7b4303eaf67c761a49b82ab194e5d035d24d2615 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Make base CU a member of ExecutableCompilationUnitUlf Hermann2024-01-101-5/+6
| | | | | | | | | | | | We want to re-use the base compilation unit across engines. For that to work it cannot be a slice of the engine-specific ExecutableCompilationUnit. Since CompiledData::CompilationUnit is refcounted on its own now, make it unmovable. Change-Id: I8418c9754d7a07e5210c1e7a7fc69355e1d57807 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Fix return type constructions when calling methodsUlf Hermann2023-10-071-1/+1
| | | | | | | | | | | | | | | We now expect the return type to be initialized in all cases. This is in line with what the various metacall() methods expect. Unifying this behavior makes it much easier to reason about and avoids complicated bugs and memory leaks. The code generated by QmlCompiler always passes initialized values for the return type anyway. Amends commit 4f1b9156a48e44cf1f127a4563d0ac69ab436f12 Amends commit 02c4c817fe1cfa4766c56759be99fb081382a586 Change-Id: I26c016676dd82c91d6ef81762b5c4b599f6f7f72 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Replace signal name manipulations with QQmlSignalNamesSami Shalayel2023-08-151-3/+3
| | | | | | | | | | | | | | | 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>
* Compiler: Separate function prolog block and add validation of blocksOlivier De Cannière2023-08-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Compiler: Allow dumping the basic blocks for visualization and debuggingOlivier De Cannière2023-07-101-1/+1
| | | | | | | | | | | | | | | | | | | | If the QV4_DUMP_BASIC_BLOCKS environment variable is set, the compiler will output the details of the basic blocks of the compiled functions to the console. It will also generate a control flow graph containing the byte code in DOT format for easier visualization and debugging of the program execution and of the structure of the generated code. The value of QV4_DUMP_BASIC_BLOCKS will be used as the path to the folder in which to output the DOT files. If the path is any of ["-", "1", "true"] or if files can't be opened, it will be dumped to stdout instead. The logic in dumpByteCode has been adapted to use a QTextStream. This way it can continue to be used to dump the byte code of the whole program as before and also to construct the CFG. Change-Id: If398d795e4fc0950b5fa8ee1349e80b1ae262deb Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Do not generate code that shadows argumentsUlf Hermann2023-07-061-2/+2
| | | | | | | | Pick-to: 6.5 6.6 Fixes: QTBUG-114897 Change-Id: I23bc913a86ee90764735c1661cd5036f7d177a22 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Undeprecate AOTCompiledFunctionUlf Hermann2023-05-231-4/+4
| | | | | | | We're going to call the JavaScript-typed functions a different name. Change-Id: If92c3fb1b16b1b0bd7d009e7dd712ae6405e1232 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Relax shadowing checkUlf Hermann2023-05-021-4/+4
| | | | | | | | | | | | | | | | | 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>
* QmlCompiler: Enforce sanity of type adjustments in basic blocks passUlf Hermann2023-03-111-1/+3
| | | | | | | | | | | | If we cannot properly adjust the types, the result will probably be garbage and we should not try to generate any code. We are double checking the actually received type in the code generator, but if we get a different type at code generation time than we "ordered" at type propagation time, that's not great. The type propagator should already have checked that the types are convertible, after all. Change-Id: I9c20dbd6b4cc8214e780dad9eb4302ca6ef81bac Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Drop broken line comments in generated C++Ulf Hermann2023-02-231-3/+1
| | | | | | | | | | | | | | | | | | They didn't work because the ordering of instructions is not the same as the ordering of lines. They also weren't very helpful because a single line may result in multiple instructions and vice versa. On top of everything, they also introduced UB via the std::upper_bound call. Rather, just print the name of the function and the place in the file at the beginning of each C++ function. That is much more helpful since we can then just correlate it to the original QML code. For instruction-by-instruction mapping we have to consult the byte code trace anyway. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-111340 Change-Id: I599ce384cfaf88a7347583a55976a3b98080435d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Handle various date and time conversions correctlyUlf Hermann2023-01-171-0/+1
| | | | | | | | | | | | | We can coerce QDateTime, QDate and QTime into each other because they would all be represented by a Date object in JavaScript. Furthermore we can coerce them all to QString. Technically, we could also coerce strings to all of them, but we don't want to because that is terrible. Fixes: QTBUG-109380 Change-Id: I176bfb5b715a6a6750cb5918c44261fa23fb8832 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* tooling: silence -Wmissing-variable-declarationsTim Blechmann2022-11-161-3/+6
| | | | | | | | | silence clang's -Wmissing-variable-declarations Pick-to: 6.4 Change-Id: I40189c219bfeaeba103a56a08e489b019e2905bd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* tooling: silence -Wextra-semi-stmtTim Blechmann2022-11-161-3/+3
| | | | | | | | silence clang's -Wextra-semi-stmt Pick-to: 6.4 Change-Id: I5dee9ec46b44076f0fc0590399131b1b267e1ad2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Allow lists as arguments to methodsUlf Hermann2022-11-101-0/+1
| | | | | | | | | | | | | | | | | | | Since lists are allowed as property types, you should be able to pass them as arguments to methods, too. For now we only handle QML-defined methods, implemented by adding JavaScript functions to your QML elements. The usual type coercion rules apply if you pass JavaScript arrays to such methods. That is, it usually works. We now resolve properties with the "list" flag to their actual types (QQmlListProperty or QList) already when populating the QQmlJSScope, and store the list types as members of QQmlJSScope rather than as a special map in QQmlJSTypeResolver. This allows us to do the same to lists passed as arguments and simplifies some of the type analysis. Fixes: QTBUG-107171 Change-Id: Idf71ccdc1d59f472c17084a36b5d7879c4d959c0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Add a separate flag for the "pragma Strict" checkUlf Hermann2022-10-201-3/+2
| | | | | | | | | | | | | We want to trigger the qFatal() when running qmlcachegen or qmlsc, but we don't want to trigger it in qmllint, even if we are using the same QtMsgType for the severity of the messages. In turn, demote qmlCompiler messages to QtWarningMsg in qmlcachegen. Pick-to: 6.4 Task-number: QTBUG-107168 Change-Id: Ib660df41742b2d426241eb29ac4c91f4933c5ba1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-071-4/+4
| | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace. Task-number: QTBUG-99313 Change-Id: I601bf70f020f511019ed28731ba53b14b765dbf0 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-071-3/+3
| | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8: auto QtContainerClass = anyOf( expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o), expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)); makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container', with the extended set of container classes recognized. Change-Id: Idb1f75dfe2323bd1d9e8b4d58d54f1b4b80c7ed7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Use an enum to categorize functions and rename aotFunctionUlf Hermann2022-09-291-2/+2
| | | | | | | | We want to use the aotFunction member also for typed JavaScript functions. Change-Id: Iad6d12ebed3ad3069832484137ed8e4d9e7a7cf4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qqmltypecompiler: align runtime function table order to qmlcachegenAndrei Golubev2022-07-221-10/+11
| | | | | | | | | | | | | | | | When we write runtime functions to compilation unit at run time, the order of the functions in the unit (often) differs from the order of functions in the unit produced ahead of time by qmlcachegen and friends. Additionally, the order also differs from what qmltc expects (and qmlcompiler library in general) Fix the order by simplifying the procedure of JS code generation when we create the compilation unit at run time: new logic just goes over the objects in the document linearly, instead of relying on bindings (which are known to be out of order w.r.t. AST) Change-Id: I4070b9d061f03c4c76d03120654ad3f30725493a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Handle trivial signal handler constructionsUlf Hermann2022-07-071-21/+49
| | | | | | | | | | | | | | If the signal handler does nothing but return a closure, we have to compile the closure using the same signature as the outer signal handler. In order for this to work, we also have to detect unresolved argument types for signal handlers. Those are just as bad as unresolved argument types for other functions. Fixes: QTBUG-101531 Change-Id: Idb5b3994809d91a4b4ce936282685435eb75e670 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSLogger: Switch to an ID based systemMaximilian Goldstein2022-06-301-3/+3
| | | | | | | | | | | | | | | | This change makes qmljslogger use an ID based system for categorizing logging entries instead of using an enum. This allows plugins to register their own logging categories after the fact. It's also necessary for us to later show the warning ID when printing warnings and for creating documentation for each ID entry. Currently not every ID maps cleanly to only one type of warning, this has to be cleaned up in a follow-up change. Task-number: QTBUG-103453 Change-Id: I4cac6be7ca165b938e0ea032d077823bf17baf75 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-111-27/+2
| | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>