aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmlsa.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QQmlSA: Fix doc typoOlivier De Cannière2025-07-161-2/+2
| | | | | | | Amends cca050c3d4a3d1c053390e44cc174bea2c54f41d Change-Id: I39738939343045e3534074a5525aa85cef78feb5 Reviewed-by: Luca Di Sera <[email protected]>
* QQmlSA/compiler: Introduce new scope typesFabian Kosmale2025-07-101-0/+15
| | | | | | | | | Instead of doing string comparisons, encode the information in the scope type for bindings and signal handler functions. Add a helper function to check whether a scope represents any kind of functions. Change-Id: I41ad1316852dd484ac54c02f99bb25e618099e62 Reviewed-by: Sami Shalayel <[email protected]>
* QQmlSA: extend ScriptBindingValueType for function bindingsSami Shalayel2025-05-201-0/+13
| | | | | | | | | | | | | | | | | In QtC, ErrBlocksNotSupportedInQmlUi is supposed to warn about function blocks when used in bindings. We can't detect function blocks with the QQmlSA infrastructure because we don't have access to the AST, but we still can actually detect bindings to function blocks. Extend ScriptBindingValueType to be able to recognize bindings that contain functions (JS blocks, arrow functions and lambdas). Extend the QQmlSA interface to find out if a binding contains a function so that qdslintplugin can use it in a later commit. Task-number: QTBUG-129308 Change-Id: Ic46ad6faf7a04d805084db2d9353b009e881d4dd Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* qqmljsscope: rename ConstPtrWrapperIterator to ChildScopesIteratorSami Shalayel2025-05-201-2/+2
| | | | | | | Its not a wrapper anymore, its just an alias to a QList iterator. Change-Id: I15006f288a3a225e7bda9905c685e1050c70a265 Reviewed-by: Olivier De Cannière <[email protected]>
* Docs: Fix doc warningsAlexei Cazacov2025-04-301-1/+1
| | | | | | | | This commit fixes several broken links in \nativetype. Pick-to: 6.9 6.8 Change-Id: I45c599eb165b062b2a9eddea3fd13b90d2d7fd74 Reviewed-by: Ulf Hermann <[email protected]>
* ImportVisitor: Fix nonsensical code for checking required propertiesOlivier De Cannière2025-04-251-0/+5
| | | | | | | | | | | We create and increment an iterator and then don't use it... Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 Task-number: QTBUG-135244 Pick-to: 6.9 6.8 6.5 Change-Id: Ia92df8e7dc337786eba43980364ad03c747ec11b Reviewed-by: Fabian Kosmale <[email protected]>
* Port away from QPairZhao Yuhang2025-04-121-1/+1
| | | | | | | | QPair is just an alias of std::pair anyway. Task-number: QTBUG-115841 Change-Id: I26fc90adcc775aac9955ad57304af914dc4ed48f Reviewed-by: Ulf Hermann <[email protected]>
* qmllint: add helpers to create small PropertyPassesSami Shalayel2025-04-041-0/+21
| | | | | | | | | | | | | | | | | | This commit should make implementing small PropertyPasses easier: instead of having to create a new class and registering the PropertyPass into the PassManager, create a Builder that creates a PropertyPass from lambdas and registers it into the pass manager. This avoids having to create a new class inheriting from PropertyPass for each check that will be added with QTBUG-129307. Also add a method to PassManagerPrivate to be able to register propertypasses on builtin objects. This is needed to warn about usages of 'eval()' in a later commit. Task-number: QTBUG-129307 Change-Id: If3ea8d092acae4733aacd62ca7769011f0a7633c Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: add private helper for optional fix suggestionsSami Shalayel2025-03-311-0/+16
| | | | | | | | | Add a private helper method emitWarningWithOptionalFix to emit warnings with optional fix suggestions. Task-number: QTBUG-129307 Change-Id: Ifdcb3ccac8c857f06d3ccb658042b8376283fb26 Reviewed-by: Ulf Hermann <[email protected]>
* Doc: Fix issues with \fn signaturesTopi Reinio2025-03-061-3/+3
| | | | | | | | | | | | | | Move QQmlSA::LoggerWarningId function documentation out of the QQmlJS namespace, as that causes match failures with QDoc. Qualify QQmlSA::Method and Element \fn signatures with the correct scope to help QDoc match them. Task-number: QTBUG-134250 Pick-to: 6.9 6.8 Change-Id: I89407afe251158d99a93f44c25bb6db1a83a6024 Reviewed-by: Paul Wicking <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* QQmlSA: Rename PropertyPassInfo and store the pass property as a QStringOlivier De Cannière2025-02-281-7/+3
| | | | | | | | | The pass invocation only ever holds one property. Change it from a list to a simple QString. Pick-to: 6.9 Change-Id: Id9c367ec427474f03e58427659484e7656fa39fe Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: Remove PassManager::{element|property}Passes() from public APIOlivier De Cannière2025-02-281-18/+0
| | | | | | | | | | | | | | | | It complicates things internally and doesn't add much value to the user. They can still keep track of which passes they have created manually. QQmlSA is still in technical preview. [ChangeLog][QML][QQmlSA] PassManager will no longer expose the element and property passes that it holds. They are only meant to be used inside the PassManager itself. elementPasses() and propertyPasses() were removed. Pick-to: 6.9 Change-Id: Ibc748309f142794a27266e68ad9d0ce302b51213 Reviewed-by: Ulf Hermann <[email protected]>
* QQmlSA: Drop BindingInfoOlivier De Cannière2025-02-281-18/+44
| | | | | | | | | This was exposed publicly but couldn't be used. Store its information on Binding instead. Pick-to: 6.9 Change-Id: I134221e7263eafe523c4db6ce77c00a0ea14dd23 Reviewed-by: Ulf Hermann <[email protected]>
* Doc: Add more documentation for QQmlSAOlivier De Cannière2025-02-281-8/+354
| | | | | | | | | | | Some documentation may not provide a lot of extra information but is there mainly so that the function appears in the final documentation and is discoverable by the user. Fixes: QTBUG-116682 Pick-to: 6.9 6.8 Change-Id: I68e531663a25ea9aaba9dfd4ec0c8b842023f673 Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: CleanupOlivier De Cannière2025-02-281-6/+8
| | | | | | | | | -Remove unused headers and predeclarations -Avoid potential detaches -Default initialize some members Change-Id: Ifc0e125db8536db3e2b4b0016fab7b3c32f48972 Reviewed-by: Ulf Hermann <[email protected]>
* QmlCompiler: Only import hardcoded builtins by defaultUlf Hermann2025-02-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | At run time, not all the builtins are always available, but only those hardcoded into the parser. If we always import all the builtins at compile time, we introduce subtle errors when they shadow parts of the JavaScript global object. Now the builtins need to be actually imported. We cannot rely on the magic that adds them to the root scope of each document anymore. To this end, they need to become a regular module. The builtins are now loaded using a qmldir, just like any other module. The only thing special about is its "system" attribute which we now take to mean "read jsroot.qmltypes". Furthermore, the builtins get a "static" attribute so that we don't warn about them being unused. Even though they can now technically be unused, we really want people to still import them. Pick-to: 6.9 6.8 Fixes: QTBUG-133461 Change-Id: I322e14ba85c939773d36143ca24e88a7c9db23f5 Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* qqmljsscope: add id source locationSami Shalayel2025-02-181-0/+9
| | | | | | | | | Add the sourcelocation of the id to the qqmljsscope such that qmllint plugins can emit warnings on the id of an QQmlSA::Element. Task-number: QTBUG-129308 Change-Id: I166cf6dd63cec6bc59f29936ed65ad6ebf0505e3 Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: make findPropertyUsage a bit fasterSami Shalayel2025-01-311-9/+4
| | | | | | | | | | | | | | | | | | Extensions can't add base types to some QML Element, so ignore them when trying to collect type name in findPropertyUsage(). This slightly reduces the runtime for propertyStressTestItems in tst_qmllint_benchmark. Times in milliseconds on my laptop, on a release build, mean over 3 executions before and after this commit: noPlugins:propertyStressTestItems.ui.qml,710 -> 612 allPlugins:propertyStressTestItems.ui.qml,730 -> 630 onlyQdsLintPlugin:propertyStressTestItems.ui.qml,710 -> 625 Task-number: QTBUG-133349 Change-Id: Ia6b761a404a678259febccef593100d9443ca3c8 Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Do not call the same pass twice for the same bindingUlf Hermann2024-12-191-3/+7
| | | | | | | | | | A pass may register itself for multiple kinds of elements. It still wants to be notified about each binding only once. Pick-to: 6.9 6.8 Task-number: QTBUG-127691 Change-Id: I5328d548cae30979da6c9f1c2fccebdf89997236 Reviewed-by: Fabian Kosmale <[email protected]>
* QmlCompiler: Rename attachingType() to attachedType()Ulf Hermann2024-11-111-2/+15
| | | | | | | | That's what it actually is. It doesn't return the attacher but rather the attachment! Change-Id: I05e391d9d56ec0b8f56811eba491654dfa386bd9 Reviewed-by: Olivier De Cannière <[email protected]>
* QQmlSA: do analyzeCall on translation bindings tooSami Shalayel2024-10-281-7/+18
| | | | | | | | | | | | | Call analyzeCall also on translation bindings occurring either in translation bindings or inside of script expressions. Current limitations of QQmlJSMetaPropertyBinding means that we can't differentiate between qsTranslate and qsTr calls in translation bindings. Also, there is no need (for now) to distinguish both. Fixes: QTBUG-126798 Change-Id: If7d3d0df36b5aa4baf51d2c33225e6b034d465f1 Reviewed-by: Olivier De Cannière <[email protected]>
* QQmlSA: add onCall method to PropertyPassSami Shalayel2024-10-281-0/+29
| | | | | | | | | | | | | | | | Allow PropertyPass to check calls on properties by adding a new onCall virtual method. It is called whenever a property is being called, by using QQmlJSTypeProgator::propagateCall() and generate_callProperty(). Do not change the behavior of onRead that was also checking calls: instead, override onCall() if you are only interested about function calls. Document the current limitations of onCall. Fixes: QTBUG-126798 Change-Id: I261796bdaedaef6074a4ff8d4e5f547157e9ea19 Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* Add missing const refs in QQmlSA private methodsSami Shalayel2024-10-281-5/+5
| | | | | | | | | | Add missing const& when passing strings and sourcelocations in QQmlSA private methods. Task-number: QTBUG-126798 Change-Id: I5c5a556922dc73e859f666e1bac914899f2034fa Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* QQmlJSScope: add isRootFileComponent flagSami Shalayel2024-10-281-0/+8
| | | | | | | | | | | | Add a flag to tell whether the QQmlJSScope is the root QML scope. This can be then used in user-written QQmlSA passes to apply special checks on root items, which is needed in the QDS warnings for .ui.qml file, for example. Task-number: QTBUG-129308 Change-Id: Ie67294b0ee2b813da3a80a0bd8002ebae618ee1c Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* QQmlJS: Store method's source location and expose it in QQmlSAOlivier De Cannière2024-04-171-0/+14
| | | | | | | | | This is useful for tooling like Axivion and can help with better error messages. Change-Id: Ic63afd2eeb4ee3627d05303c2518fa90282fb7ab Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
* QQmlSA: Fix minor mistakes in the docsOlivier De Cannière2024-04-171-14/+15
| | | | | | | Change-Id: I1614557b66f94685b3388c651d084531b6b13775 Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Leena Miettinen <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* QmlSA: Extend Property and Element by isReadonly, type, hasOwnPropertySami Shalayel2023-10-311-0/+40
| | | | | | | | | Those methods are required to make qqmljsliteralbindingcheck a PropertyPass. Change-Id: I3b9d4fceee1cfdff0e5d21adc63b7762384f69c1 Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Semih Yavuz <[email protected]>
* QQmlSA: Remove cruft from public APIUlf Hermann2023-10-231-32/+17
| | | | | | | | | | Methods you can't use should not be visible, and PassManager needs to be Q_DISABLE_COPY_MOVE. Task-number: QTBUG-116682 Change-Id: Ib308bf3a5bac3dd78b52b82b01bc8f2bc13835b3 Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: Don't expose QQmlJS namespaceFabian Kosmale2023-09-211-4/+4
| | | | | | | | | | | | | QQmlSA is meant as the public namespace, QQmlJS is (at least currently) completely internal. However, LoggerWarningID currently only existed in QQmlJS. Move it into QQmlSA, add some minimal class documentation and add a typedef in QQmlJS (inside a private header) to avoid the need to modify all users. Pick-to: 6.6.0 6.6 Change-Id: Icff860c92054ac810c6e15eb26090d38fbc2c965 Reviewed-by: Ulf Hermann <[email protected]>
* Doc: Fix minor documentation issuesTopi Reinio2023-09-151-2/+2
| | | | | | | | | | | | | | | | * src/qmlcompiler/qqmlsa.cpp:925: Fix linking to global Qt object * src/quick/handlers/qquickpointerhandler.cpp:881: Mark a member of QQuickPointerHandlerPrivate as \internal * src/quick/items/qquickrendercontrol.cpp:636: Fix malformed link to QRhi::[begin|end]OffscreenFrame(). In passing, replace unnecessary usage of \badcode with \code. Pick-to: 6.6 Change-Id: I8fd333929fb082215ccac16cca351afcf0e00696 Reviewed-by: Paul Wicking <[email protected]>
* QQmlSA: Turn BindingType into a enum classFabian Kosmale2023-08-301-1/+1
| | | | | | | | | This avoids future conflicts between different "Invalid" values. Pick-to: 6.6 Change-Id: I42f3d6e5b6d1b46931999dc2c72177872a104be9 Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* QQmlSA::PropertyPass: Clarify documentationFabian Kosmale2023-08-161-4/+4
| | | | | | | | | onWrite has no idea which _value_ is written; the only thing it knows is the type of it. Pick-to: 6.6 Change-Id: I7ef4a245253dff5e1218a1705cf90d6fc17e8584 Reviewed-by: Ulf Hermann <[email protected]>
* QQmlSA::ElementPass: Improve documentationFabian Kosmale2023-08-091-1/+49
| | | | | | | | | | Mention common use cases, provide some snippets and add a note about the gotcha with attached types. Pick-to: 6.6 Change-Id: Ibc6425c57d5b40bf7768e9714b802e25fb331914 Reviewed-by: Andreas Eliasson <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* UndefinedBehavior: fix some things found with -sanitize undefinedOlivier De Cannière2023-08-011-0/+4
| | | | | | | | | | | | | | | | | | Here are the sorts of things that were found: - Uninitialized variables containing garbage. - Calling member function through nullptr (where this is not actually used inside the function because that would trigger a segfault). - static_cast'ing double to int where the double is either +/-infinity or is outside the range of min and max values for int. Additionally, the uses of QJSNumberCoercion::isInteger() in the code generator have been replaced by QJSNumberCoercion::isArrayIndex() and the former was deprecated as it is no longer being used. Pick-to: 6.5 6.6 Change-Id: I9318671ccbda37e5519f4fcb84a1537585c2103f Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* Revert "QQmlSA: mark module as TP"Kai Köhne2023-07-181-2/+0
| | | | | | | | | | | | | This reverts commit ebec92cc5c0e1e11c226924e1093125b0b58a5d4. This fixes warning: src/qmlcompiler/qqmlsa.cpp:28: (qdoc) warning: Command '\modulestate' is only meaningful in '\module' and '\qmlmodule'. The \module the namespace is in is already marked as 'Technical Preview'. Change-Id: I72b5828e86b7ca2ffa9c05ed785840d24216cc96 Pick-to: 6.6 Reviewed-by: Fabian Kosmale <[email protected]>
* FixSuggestion: Remove default ctorFabian Kosmale2023-07-111-1/+0
| | | | | | | | | | | It doesn't make sense to create a FixSuggestion without a source location, and it is not possible to set the source location at a later point. Pick-to: 6.6 Change-Id: I158dcb0adff0c3ff07a86f63960eadaa983343c7 Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* GenericPass docs: Fix typos and add additional descriptionsFabian Kosmale2023-07-071-9/+23
| | | | | | | | | As a drive-by, mark documentation for private class as internal. Pick-to: 6.6 Change-Id: Ie24140233dccdad832fa637330f2f175bfd52477 Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* QQmlSA: Improve registerPropertyPass docsFabian Kosmale2023-07-071-0/+14
| | | | | | | | | | | - explain why we need std::shared_ptr - mention under which condition false is returned - add code example Pick-to: 6.6 Change-Id: Ieac7a7ecf00976f7962b37e6ca2a294877eb61fc Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* Clarify PassManager::hasImportedModule docsFabian Kosmale2023-07-071-1/+13
| | | | | | | | | | The concept of an import visitor is not public; so don't refer to it. Instead, give a hint on why you'd use the function, and provide a code snippet. Pick-to: 6.6 Change-Id: Iceb628d70829b40ea46e1f939b4652cee96ca63f Reviewed-by: Ulf Hermann <[email protected]>
* PassManager: Remove setter for category enabledFabian Kosmale2023-07-061-8/+0
| | | | | | | | | | | | | | | | | There's a use case for querying whether a logging category is enabled - a plugin might not want to register a pass at all if it detects that a category is not enabled. The PassManager should however not be allowed to en- or disable categories by itself - that should solely be handled by qmllint (or the LSP) based on the configuration and command line arguments. Additional clean-up: Remove the function unused and unimplemented function prototypes in PassManagerPrivate. Pick-to: 6.6 Change-Id: I2c9354e6ad5988070390279b217bab862b806d82 Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Sami Shalayel <[email protected]>
* QQmlSA::Element: Rename internalName to internalIdFabian Kosmale2023-07-041-1/+4
| | | | | | | | | | | | We don't really want to expose the internal name as anything but an opaque unique id for a type. Port some usages of internalName to the normal name() function, and leave a few todo comments in places where we cannot migrate away from it yet. Pick-to: 6.6 Change-Id: Id66a0e2d2dcdad7b54899c67abe8252b9ef2aed9 Reviewed-by: Sami Shalayel <[email protected]>
* QQmlSA::Element: Make prettyName a member functionFabian Kosmale2023-07-041-3/+8
| | | | | | | | | | ...and rename it to name. There shouldn't be any other name for users of the API to worry about. Additionally, print baseTypeName using prettyName, too. Pick-to: 6.6 Change-Id: Ifba2a737b6e915de059cadf097c4a07e6a4104ca Reviewed-by: Sami Shalayel <[email protected]>
* QQmlSA: Remove Element ctor taking a name, add resolveBuiltinTypeFabian Kosmale2023-07-041-5/+22
| | | | | | | | | | | | | | | | | | | | | | | | The Element constructor taking a name would internally create a QQmlJSScope with a matching internal name – without doing any validation that such an internal name would be sensible. Additionally, you could create an Element with it, but you coudln't do anything sensible with it as Element only has a read-only API, and the constructed QQmlJSScope only contains a name. Lastly, we do not really want to expose the internalName as anything more than a transparent id at most. Checking users of the constructor, one quickly finds that the only usage was inside the quick plugin, which needed it to get access to the "function" type; it also relied on "inherits" only checking the internalName. As an alternative, we can provide a resolveBuiltinType which can be used for further checking, and actually returns the correct type with all its methods and attributens, instead of a mock type which happens to work in equality checks. Pick-to: 6.6 Change-Id: I212532053d1b5c898776a564f2011ba17b074079 Reviewed-by: Ulf Hermann <[email protected]>
* QQmlSA: mark module as TPFabian Kosmale2023-07-031-0/+2
| | | | | | | Pick-to: 6.6 Change-Id: I22ed887ff1ee146f1cf14f75cb986658f9dad079 Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* qqmlsa: Fix warning about empty namesUlf Hermann2023-06-201-2/+3
| | | | | | | | | | | | Registering "wildcard" passes is fine. We do so ourselves with the attached property re-use pass. We don't want to trigger the warning on every occurrence of QtQuick.Controls. If only one of the names is set, the pass manager will indeed produce junk. Pick-to: 6.6 Change-Id: Ib8ad749e88f7dc83fa57341bc5b192a011bddf6a Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* Doc: QtQmlCompiler: Fix documentation warningsTopi Reinio2023-06-021-7/+6
| | | | | | | | | | * Mark functions of QColorOutput \internal to avoid QDoc warnings as the (private) class is not included in the module's master header. * Fix undocumented parameters and typos. Change-Id: Iaf744372fd573d481fb8dd744bf44709b7ae8878 Reviewed-by: Ulf Hermann <[email protected]>
* QQmlSA: Change API for accessing attached typesOlivier De Cannière2023-06-011-16/+16
| | | | | | | | | | | An Element no longer exposes its attached type directly. Instead, the function resolveAttached() was added as an analog to resolveType(). Also, added a test documenting the current attached type resolution behavior. Change-Id: Ib8d6713790f9ce2e2fe36b8620bbbbe36cb23705 Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: Mark move SMF noexcept and specify alignment for fast-PIMPLsOlivier De Cannière2023-05-311-8/+12
| | | | | Change-Id: Ia3dc17a31856047b9fd7c5da89320c7234847a59 Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: Create an abstraction layer for static analysisOlivier De Cannière2023-05-301-98/+1349
| | | | | | | | | | | | | | | This patch adds abstractions for QML Elements, Bindings, Methods and Properties. This abstraction layer avoids exposing internal details and should be more suited for static analysis tasks. It is now possible to write qmllint plugins without including private headers. As a drive-by, change tst_qmllint:verifyJsRoot to open files in text mode instead of binary. This fixes an issue where line endings cause issues on Windows. Fixes: QTBUG-102276 Change-Id: I6b6e53f1e0078734a18f3aa51807fbe875b375f0 Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlSA: Remove dead codeFabian Kosmale2023-04-141-1/+0
| | | | | Change-Id: Iec9f607ead6ee32cc9bb1d40c5cd9967e86c7772 Reviewed-by: Sami Shalayel <[email protected]>