aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsimportvisitor_p.h
Commit message (Collapse)AuthorAgeFilesLines
* qmltc: Cleanly reject custom parsed propertiesUlf Hermann2025-04-151-1/+3
| | | | | | | | | | | | Process all properties of custom parsed types and generate errors if the custom parsed properties are actually used. Then print an extra error stating that qmltc does not support custom parsers. Pick-to: 6.9 6.8 Fixes: QTBUG-134206 Change-Id: I37e4f3f8d0ee4e0926c0d64c99a4a521b093a1ab Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* qmllint: implement WarnAssignmentInConditionSami Shalayel2025-03-251-0/+2
| | | | | | | | Warn for assignments inside of if-statement conditions. Task-number: QTBUG-129307 Change-Id: If1e4d85b6cdbf4f076d91dcf8d7600988f51d6a1 Reviewed-by: Ulf Hermann <[email protected]>
* qmllint: Implement ErrInvalidEnumValueSami Shalayel2025-03-211-0/+2
| | | | | | | | | | Implement the ErrInvalidEnumValue complaining about enum keys being lowercased or duplicated. Change the warning message as the Qt Creator code has a comment indicating that the message should be changed. Task-number: QTBUG-129307 Change-Id: If0b72eab38124453f90eb9a52e126bf9f24c83b7 Reviewed-by: Olivier De Cannière <[email protected]>
* Revert "Compiler: Mark move constructor and operator= noexpect"Marc Mutz2025-03-201-2/+2
| | | | | | | | | | | | | | This reverts commit 85f80766ea7a1f068a3b6c4806f0192324e278e5. Reason for revert: The change is wrong, Clang is producing False Positives: - https://github.com/llvm/llvm-project/issues/126041 See https://eel.is/c++draft/except.spec#6, which clearly states that a defaulted SMF is "noexcept(auto)". Pick-to: 6.9 6.8 6.5 Change-Id: Icca3a4be990215ef80e5595d7b84e25ec3051f53 Reviewed-by: Fabian Kosmale <[email protected]>
* qmlls: don't mix up the in-memory and on-disk fileSami Shalayel2025-03-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Fix QQmlJSImportVisitor to register the scope into its QQmlJSImporter. This is important to avoid scope duplication. Before this patch, the implicit directory import that QQmlJSImportVisitor processes via QQmlJSImporter would create a duplicate "lazy" scope that reads from the file on disk during population. With this patch, QQmlJSImporter will know the current scope and therefore won't duplicate it during the implicit directory import. Add a test to qmlls to make sure that it can lint enums correctly, even if the enum declaration does not exist on the on-disk version. Avoid warnings while resolving scopes by marking the currently to be populated scope with the '$InProcess$' baseTypeName. It will be populated (including with its real base type name) after the import were processed. Pick-to: 6.9 6.8 Fixes: QTBUG-134781 Change-Id: I05cc8f8cab9279ee07c4a48a1b467738354e11dd Reviewed-by: Fabian Kosmale <[email protected]>
* Compiler: Mark move constructor and operator= noexpectOlivier De Cannière2025-03-051-2/+2
| | | | | | | | | Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 Pick-to: 6.9 6.8 6.5 Change-Id: Icfaf1d894f5625d101a6d5bdece4519f30bc99c9 Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* Compiler: Don't make aliases to required properties required themselvesOlivier De Cannière2025-03-041-11/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a property is declared as required, it needs to be bound when creating the component containing that type. Required properties can be aliased just like any other property. Before this patch, aliases targeting required properties would themselves be marked as required. This is incorrect as this forces the aliased required property to be set through the alias. It should be legal to alias a required property and not set required value through the alias. Therefore, stop marking the alias as required and instead check directly that the required property is bound in some scope for each object creation or that it is forwarded through a root-level alias. A required property will now also be satisfied if it is set through an alias. For this to work, a property alias now also stores its target scope and target property name. This change also adds checking for object definition bindings of the following form. These weren't checked before but really should be. ``` QtObject { property QtObject o: QtObject { required property int i // was not checked } } ``` These changes affect the way qmltc enforces setting required properties. Because it relied on aliases to required properties to be required themselves, it will now fail to enforce certain required properties. Created QTBUG-131777 and marked affected tests as QEXPECT_FAIL. Fixes: QTBUG-127098 Pick-to: 6.9 6.8 6.5 Change-Id: Ib36a43fbf3cc9c79eba6db39cbaf8769f85e2b31 Reviewed-by: Ulf Hermann <[email protected]>
* QmlCompiler: Don't warn about problematic imports being unusedUlf Hermann2025-01-231-1/+2
| | | | | | | | | | | If we've warned about an import before, we probably can't properly analyze its types and therefore won't find any usages for it. We should then not warn about it being "unused". Pick-to: 6.9 6.8 Task-number: QTBUG-124913 Change-Id: I83fd0b325e362b4f85f6fd22a86fb7c91ae54cf0 Reviewed-by: Sami Shalayel <[email protected]>
* QmlCompiler: Reduce duplication of warnings about missing propertiesUlf Hermann2025-01-171-0/+3
| | | | | | | | | | | | 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 <[email protected]>
* QmlCompiler: Reduce duplication of "not found" messagesUlf Hermann2025-01-171-19/+24
| | | | | | | | | | | | | | | | Track the unresolved types in a central place and only warn once for each of them. Make sure that we still mark them as wrapped in implicit components even if we don't warn, though. Realize that custom parser parents potentially obfuscate any types defined inside their scope, not only the ones we look for when setting bindings. Pick-to: 6.9 6.8 Task-number: QTBUG-124913 Change-Id: I30d911dc92d1e4359db66671bf62393f2f852b6c Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Sami Shalayel <[email protected]>
* QmlCompiler: Resolve regular group properties like generalized onesUlf Hermann2024-11-041-1/+2
| | | | | | | | | | | | | They are mostly the same. We only need to search the local properties rather than the IDs for the regular group properties. This allows us to resolve group properties on aliases since aliases get resolved before group properties. Pick-to: 6.8 Fixes: QTBUG-128632 Change-Id: I6f77a65499dd6bec29269f7b0974180fa76a749e Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Sami Shalayel <[email protected]>
* QmlCompiler: Refactor handling of warnings in import visitorUlf Hermann2024-09-191-5/+5
| | | | | | | | | | | We want to replay the warnings when we import the same module again. This happens if we lint multiple files with different imports, some direct and some indirect. Pick-to: 6.8 Fixes: QTBUG-118588 Change-Id: I75da4e62acea675342ce8f86f9609f1786ffbdd0 Reviewed-by: Sami Shalayel <[email protected]>
* ImportVisitor: Properly handle unresolved type annotationsOlivier De Cannière2024-07-301-3/+5
| | | | | | | | | | | | | | | | | | | | The change introducing the checking of unresolved type annotations had a problem where the annotation and its corresponding argument could be mismatched. This would lead to warnings for unresolved type annotations being correct but being shown in the wrong location. This patch keeps an array of source locations for annotations for argument and the return type. These are kept in order. If an argument doesn't have a type annotation, its corresponding source location is invalid. This ensures a consistent mapping between arguments/return type and their annotation. Amends 4aa1deee1be966a6491ab5a1c1de09707a5e8215 Fixes: QTBUG-125146 Pick-to: 6.7 6.8 Change-Id: I012d2cb261244d625b6b9126e0d362e6a4e5cb7b Reviewed-by: Fabian Kosmale <[email protected]>
* qmlls: don't resolve component types as attached typesSami Shalayel2024-07-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Don't resolve component names as attached types. Instead, check whether the component name has a field member access to a property name, that is, whether the type name is followed by a dot and a lowercase name, like in "MyApplicationWindow.header" where MyApplicationWindow is an attached type because header starts with a lower case letter, or in "MyApplicationWindow.Kitty" and "MyApplicationWindow.Hello.World" where MyApplicationWindow is a component because "Hello" and "World" start with an upper-case letter, for example. With the improved handling in resolveExpressionType, fix the findDefinitionFromLocation logic to also work on attached types. Implement support for qualified module names in resolveExpressionType and ignore unqualified modules names for now, so that component types from qualified module names can be resolved correctly too. Collect the used qualified module names in the qqmljsimportvisitor and pass them on via the typeresolver to resolveExpressionType to recognize qualified module names. Those do not have a qqmljsscope but still can be resolved when used in a fieldmemberexpression. Pick-to: 6.8 Fixes: QTBUG-126711 Change-Id: I274c644d25cd6f9728bc56f19ec96983ad217df8 Reviewed-by: Semih Yavuz <[email protected]>
* qmltc/importvisitor: warn about type annotations on methodsSami Shalayel2024-02-291-0/+9
| | | | | | | | | | | | | | | | Warn when the types in method type annotations can't be resolved. This hinders qmltc from crashing when trying to compile a QML file with an invalid type annotation like `Qt.point`. To avoid copying and replacing lists, add helpers like mutableOwnMethodsRange() or mutableParametersRange() to obtain mutable iterators to the ownMethods of QQmlJSScope or the parameters of QQmlJSMetaMethod. Pick-to: 6.6 6.7 Fixes: QTBUG-122251 Change-Id: Iffc6ff712fbeaa2fe8b83f94b0bc5a8c278d186c Reviewed-by: Fabian Kosmale <[email protected]>
* Remove the use of Q_QMLCOMPILER_PRIVATE_EXPORTAlexey Edelev2024-01-091-2/+2
| | | | | | Task-number: QTBUG-117983 Change-Id: I893ba2a6c83af92d65d843b6a37bb14c6c1e45bf Reviewed-by: Ulf Hermann <[email protected]>
* QQmlJSScope: Decouple ContextualTypesFabian Kosmale2023-08-071-0/+1
| | | | | | | | | | ContextualTypes are required in the import visitor logic, but they aren't actually used directly inside QQmlJSScope. Change-Id: I5cd49076687ef97c1077678c8dc757cde3b94c51 Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Semih Yavuz <[email protected]>
* QQmlSA: Create an abstraction layer for static analysisOlivier De Cannière2023-05-301-1/+4
| | | | | | | | | | | | | | | 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]>
* qmllint: Separate logic by import type in QQmlJSImportVisitor::visitOlivier De Cannière2023-05-121-0/+5
| | | | | | | | | | | | | | This patch reorganizes the logic of the import visitor to deal with each import type (paths, qrc: urls, file: urls) separately. This reorganisation fixes QTBUG-108803 which happened because "qrc:" imports were being treated as paths leading to things like ":/untitled/qrc:/untitled/components". Fixes: QTBUG-108803 Pick-to: 6.5 Change-Id: I5af20d10c533455215895be66b5cd98a977fd18a Reviewed-by: Ulf Hermann <[email protected]>
* Dom: add QQmlJSScope to QmlObjectSami Shalayel2023-04-121-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | Add a flag that allows to construct the Dom with the QQmlJSScopes obtained by semantic analysis. Added a new AST visitor called QQmlDomAstCreatorWithQQmlJSScope. This visitor synchronizes the qqmldomastcreator and the qqmljsimportvisitor to construct the Dom and the QQmlJSScope from the AST at the same time. It mainly does keeping track which subvisitor (dom creator or scope creator) is active, as one subvisitor may visit AST nodes that the other does not. Using both visitors at the same time allows to insert the newly-generated QQmlJSScope::Ptr directly into the correct Dom structure. The actual implementation of QQmlDomAstCreatorWithQQmlJSScope is in its visitT and endVisitT methods. Both are called in the AST-visitor-overloads. Added a benchmark on two big generated qml files to see how fast/slow does the qqmljsccope semantic analysis runs, compared to the QmlDom creation runtime. Task-number: QTBUG-92876 Change-Id: Ia05b6fdd59a637fef9c14b6ab284f4550414f908 Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
* QmlCompiler: Fix signal checking in import visitorUlf Hermann2022-12-151-2/+3
| | | | | | | | | | | | We can determine that a binding that looks like a signal handler on first glance is not a signal handler after all. In that case we should not warn about it. Furthermore, we don't need to store all the signal handlers several times over. Pick-to: 6.5 Fixes: QTBUG-109021 Change-Id: I4b90254faa7644df047f29c98f126977a90f6662 Reviewed-by: Fabian Kosmale <[email protected]>
* qqmljsimportvisitor: rename m_currentInlineComponent to m_currentRootSami Shalayel2022-10-101-1/+1
| | | | | | | | | | | Small refactor to improve readability: rename qqmljsimportvisitor::m_currentInlineComponentName to m_currentRootName as it denotes the current inline component OR the document root. The previous naming implied wrongly that it was useless when outside an inline component. Change-Id: Ie3c9aa10182f0c9e50650cecaa3e3eb1e37e90eb Reviewed-by: Fabian Kosmale <[email protected]>
* qqmljsscope: track inline component namesSami Shalayel2022-09-081-1/+5
| | | | | | | | | | | | | | | | | | | | | This patch tracks inline component names to qqmljsscope, which will be useful in a later patch in qmltc to support inline components. Also adds a hashable type representing either the document root or the inline component name that will serve later in qmltcvisitor to separate types by inline components/document root. Implementation details: * Extend qqmljsscope + qqmljsimportvisitor ** keep track of inline component names in visitor and qqmljsscope ** types know (through their parent) if they are inside an inline component and their inline component name * added tests: ** see if QQmlJSScope can detect implicitly wrapped components inside of inline components Change-Id: I9b8b4eefe147f8f826820c3e9dabf3733b0f2d6f Task-Id: QTBUG-105946 Reviewed-by: Ulf Hermann <[email protected]>
* qqmljsimportvisitor: Fix bindings on prefixed attached propertiesMaximilian Goldstein2022-06-201-0/+1
| | | | | | | | | | Previously these would have not been created properly. This change fixes this and adds some tests. Fixes: QTBUG-104197 Pick-to: 6.2 6.4 Change-Id: I3d2d7d5a0e4019d9f7bd3496ea5762d4b7d680cd Reviewed-by: Ulf Hermann <[email protected]>
* 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 <[email protected]>
* QQmlJSImportVisitor: make ctor-initialized member stand outAndrei Golubev2022-06-091-6/+6
| | | | | | | | | Looking at this class without IDEs is slowly becoming a pure pain. Make it a little better by grouping "main" members together and moving them Pick-to: 6.4 Change-Id: I3a4451a89d66ac0dbd3572dbae1cba9a628dbf60 Reviewed-by: Maximilian Goldstein <[email protected]>
* QQmlJSImportVisitor: rename parseLiteralOrScriptBinding()Andrei Golubev2022-06-091-3/+3
| | | | | | | | It also handles translations for a while now, a generic name is better Pick-to: 6.4 Change-Id: I469eb141d877e822a17a4c4e66a00039b4558442 Reviewed-by: Maximilian Goldstein <[email protected]>
* QmlCompiler: Fix script indices calculationAndrei Golubev2022-06-091-6/+30
| | | | | | | | | | | | | | | | | | The logic is misbehaving on multiple occasions. For instance, same-named signal handlers in different scopes and script bindings inside array scopes were wrongly handled. Fix that by revising the mechanism of inner function computation As a drive by, fix parseLiteralOrScriptBinding() to distinguish translation bindings from script bindings (they are vitally different now) Extend the script calculation test in tst_qqmljsscope to cover the findings Pick-to: 6.4 Change-Id: Ic4cf0a4539f0d714a416b61f4635eb6494e89922 Reviewed-by: Maximilian Goldstein <[email protected]>
* Set bindings on QQmlJSScope after AST traversalAndrei Golubev2022-06-021-0/+11
| | | | | | | | | | | | | | | | | | We can get into situations when binding creation is problematic due to the relevant scopes being yet unresolved. In particular, this happens when processing attached/group properties script bindings Avoid having this situation by postponing the actual binding setting until after the relavant scopes are resolved (mainly, the binding owner). However, do relevant AST order dependent operations beforehand to avoid accidental errors This commit amends 25098b7a4fdb8920874a817956f659e6393548d2 Fixes: QTBUG-103897 Change-Id: I671955dbe321d03e5f1ab9891cc79dc0a936deda Reviewed-by: Ulf Hermann <[email protected]>
* qmlcompiler: Add absolute runtime function indicesAndrei Golubev2022-04-281-0/+7
| | | | | | | | | | | | | | | | We can transition to absolute indices (within the compilation unit) from the relative indices we already have in each method and script binding. Together with absolute indices, we also need to acknowledge nested closures that some AST elements might have and so also store nested runtime function indices along with the absolute ones Absolute runtime function indices (and the nested ones) map to the indices we store and use within the compilation unit at run time, which are used to dispatch to correct JavaScript call during e.g. binding evaluation - see QQmlEnginePrivate::executeRuntimeFunction() Change-Id: Ieec58fbc36563511bd9763e358cda46c67757fa9 Reviewed-by: Ulf Hermann <[email protected]>
* QQmlJSImportVisitor: always create JSFunctionScope for script bindingsAndrei Golubev2022-04-261-0/+1
| | | | | | | | | | | | | Remove dubious if-statement guarding the environment creation for script bindings Address that script bindings might also exist in the case of: `property var p: ...` which is not a UiScriptBinding but rather a UiPublicMember AST element, thus making `property var p: ...` and `p: ...` equivalent script-binding-wise Change-Id: Ie9dc40e9387a61b40445be5683049c2f3590a061 Reviewed-by: Ulf Hermann <[email protected]>
* qmlcompiler: Add relative index for scripts and JS functionsAndrei Golubev2022-04-261-0/+6
| | | | | | | | | | | | | | | | Store relative (to scope) index for every Script binding and JavaScript function into the corresponding data structure within QQmlJSScope. We need this at a later phase in qmltc when code generating JavaScript calls into the engine For now, ignore the logic that converts the relative indices stored into the indices pointing to the runtime function table While testing the addition, observe missing cases where we do not record bindings as such and fix that Change-Id: I85030b7937c97f83183f88ae242af3a5f223443c Reviewed-by: Ulf Hermann <[email protected]>
* Avoid copying QQmlJSScopeUlf Hermann2022-04-041-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | The factory should populate the pre-existing scope rather than copy it into place. This way we can detect inheritance cycles involving the pre-existing scope. However, now we may detect the inheritance cycles earlier, when resolving the types inside the lazy loading. We have the right pointers available there now, after all. Therefore, add a way to propagate base type errors out of the factory. When clearing the base type, we can now give a reason for that. When checking the inheritance cycles we retrieve that reason and log it. We also remove the special casing of the ScopeType property of QQmlJSScope. There is no real reason to set it in the ctor. As we delay the population of QQmlJSScope now, we have to set it later. Pick-to: 6.2 6.3 Task-number: QTBUG-102153 Change-Id: I49cf6e20f59fbdb6ed98a82040b3b159676f5975 Reviewed-by: Andrei Golubev <[email protected]> Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* qmltc: Migrate to new object creation/querying mechanismAndrei Golubev2022-03-301-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Serves two things: a) Provides faster/more correct object creation model (long-term) b) Eliminates (more of) prototype's code generation (short-term) The whole object querying now works implicitly through the std::array<QObject *> that QQmltcObjectCreationBase provides. The creation logic is still rather recursive with regards to QML base types processing - unfortunately, we cannot simplify this part now as qmltc requires deeper introspection into the imported types (this in turn requires fiddling with QQmlJSTypeReader and QDeferredFactory<QQmlJSScope>::create()) Since we now use the new object creation pattern, prototype/codegenerator no longer needs high-level compilation methods. So replace prototype's code accordingly with qmltccompiler bits. We can also de-duplicate enum and property compilation (aliases are not touched for simplification) from prototype. Methods and bindings have to rely on prototype and QmlIR at present, their compilation is moved more-or-less unchanged Task-number: QTBUG-84368 Change-Id: I584ceb8f2e3c9f3f79530b02d1c88a4f6c2d06c9 Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* QmlCompiler: Clean up exportsUlf Hermann2022-03-301-2/+2
| | | | | | | | We need to export all the classes used by qmlsc, and we need to use the private export macro for private symbols. Change-Id: I91d59611e864621dc2c49b9383596e706529bd42 Reviewed-by: Fabian Kosmale <[email protected]>
* qmlcompiler: Implement structured QML static analysisMaximilian Goldstein2022-03-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds the qqmlsa "framework", which is meant as a starting point for a more structured, extendible static analysis for QML. While qmllint (or rather, the QQmlJSImportVisitor used by it) can already do quite a few checks internally, it is hard to extend. Moreover, the checks there are interspersed with parsing code, and might run before all types are resolved. We also do not want to add check that are specific to QtQuick, Controls, Quick3D... into the core QtQml module. This poses quite a few challenges: For instance, the color in QML resolver depends on QtQuick/QtGui to check whether a string is actually a color. To overcome the issues mentioned above, we introduce the concept of analysis passes, and a PassManger class. Passes can come in two shapes currently: - PropertyPasses run on each property that has a binding assigned to it - ElementPasses run on each (sub-)object instantiated in the file A property can have multiple bindings assigned to it (due to e.g. Interceptors, but also for list properties). Therefore we pass a list of them to the ElementPass. Passes which only want to handle the "normal" case of one binding per property can use SimpleElementPass, which for now just takes the first property in the list. Passes have a pure virtual run function, in which the actual work is done. They also have a filter function, which in the default implementation simply returns true, which means that the pass will run. The filter function is there to make writing passes a bit more structured, by separating the "do I need to analyze this" question from the actual analysis part. To solve the issue of library dependencies, we expose a plugin interface that then returns passes to be run based on the root component. Then, user can create a plugin implementing the interface, which we will load the plugins from a known location, and register all of them. This will be implemented in the next patch in this set. Limitations: - The current passes cannot touch the IR, and thus cannot really analyze what happens in script binding. - (inline) components are currently badly handled - QQmlJSScope has various issuse with grouped properties Fixes: QTBUG-101604 Original-patch-by: Fabian Kosmale <[email protected]> Change-Id: Ic96259a947fbb17f79aa58ca613c8d0905a9a74c Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Andrei Golubev <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* QQmlJSScope: Rework type resolution checksAndrei Golubev2022-03-281-0/+21
| | | | | | | | | | | | | | Extend QQmlJSScope::isFullyResolved() with an extra check for non composite base. Rearrange existing conditions so that it easier to see where we consider the type to be resolved Go over the QQmlJSImportVisitor logic that uses isFullyResolved() and make sure it behaves properly. Introduce a new function that guarantees that we report an unresolved type when we see one (where necessary) and that this is done only once Change-Id: Ie3c0e9da70fd9e6b2da0075aade8d1d4730bf704 Reviewed-by: Ulf Hermann <[email protected]>
* Turn qmlcompiler into a shared libraryMaximilian Goldstein2022-03-251-1/+3
| | | | | | | | | Converts qmlcompiler into a shared library so it isn't duplicated when statically linked in tools and so that plugins can link against it. Change-Id: I91e13cc588796f71a5463dbdce21e42a74120565 Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
* QQmlJSImportVisitor: rename public qmlScopes() to qmlTypes()Andrei Golubev2022-03-191-1/+1
| | | | | | | | | | | QML types constitute a fraction of QML scopes. Since we only store QML types internally, provide them publicly under "qmlTypes" name to avoid potential confusion Pick-to: 6.3 Change-Id: I7fb348324d7e807fe4e3b9c9b6b6ae4cf1f331ed Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* Refactor QQmlJSMetaPropertyBindingFabian Kosmale2022-03-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | - Store the "binding content", i.e. the literal, object, interceptor or value source in a std::variant. This saves space compared to the previous approach (where we had individual fields), and also helps with type-safety. We also get rid of m_bindingType, which can now be obtained via BindingType(m_bindingContent.index()), as long as we keep the types in the variant in the correct order. - Remove a few methods that were not used anywhere. Those can be brought back once we actually need them. - Removed the setLiteral method in lieu of type-safe setX methods where X is one of the literal types. QQmlJSImportVisitor has been refactored to make use of this, and its parseLiteralBinding method has been changed into a parseLiteralOrScriptBinding method. This simplifies the control flow, and ensures that we always add the parsed binding. - Literals no longer store the literal type (as in, the actual QQmlJSScope pointer) themselves. Instead, literalType takes a pointer to a QQmlJSTypeResolver, and we use that one to resolve the type on demand. Change-Id: I0612d49f2f46fec0fa90f0f5047d8c9f831214ef Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Andrei Golubev <[email protected]>
* qmllint: Warn about missing singleton pragmas/qmldir entriesMaximilian Goldstein2022-02-031-0/+1
| | | | | | | | | | | | | This change adds a warning if we encounter a component marked as a singleton in a qmldir file which does not contain a pragma Singleton entry and vice versa. Note that the warning only gets triggered if the singleton is actually used. Fixes: QTBUG-98558 Change-Id: Id7c63f48ba49759c15dffcaee0270c7caab2eb7d Reviewed-by: Andrei Golubev <[email protected]>
* QmlCompiler: Respect revisionsUlf Hermann2022-01-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | The only place where revisions matter is at the boundary between composite and non-composite types. The revision of the first composite type inherited from determines which members of all composite ancestors are available. Therefore, store the revision together with the base type and pass it through the imports to have it available. Then use it to check availability of methods and properties. The test exposes two further problems, which are fixed, too: 1. If no method is found to call, we need to generate an error in the type propagator. We don't know what the call will result in, after all, and the code generator should reject it. 2. We need to check the right scopes for hasOwnMethod(). Otherwise we might not find methods that are available. Pick-to: 6.2 6.3 Fixes: QTBUG-99128 Change-Id: I4c320b8dfb490b140d7b8c16e6b638b32f156faa Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Enable compiler warnings for pragma StrictMaximilian Goldstein2022-01-171-0/+1
| | | | | | | | | | If a file sets pragma Strict, it expects to be fully compiler compliant, so let's enable the warnings for that by default. Fixes: QTBUG-97081 Change-Id: I0b388f64d99846ee0c03e24397b3a997d4b0173b Reviewed-by: Andrei Golubev <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>
* Move QObject and QQmlComponent into builtinsMaximilian Goldstein2021-12-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | Previously we had two versions of QObject and QQmlComponent: a hand-written version in bultins and one that is generated from QtQml. We now move the QtQml version into builtins in order to allow for representing the JavaScript extensions that are present in these types. We also add some logic so that unused types will still react properly despite the fact that those components are no longer in QtQml. This is done by introducing the concept of static modules. These are modules that have side effects beyond simply provinding components. This applies both to when some components are in builtins instead of QtQml or when the global object is modified in some way (i.e. by adding an image provider). This is a tooling-only concept and does not affect how these modules are handled at runtime. Fixes: QTBUG-99025 Change-Id: Ifacaa836e4d2eef0521494f5a41363e053c90007 Reviewed-by: Ulf Hermann <[email protected]>
* Warn about duplicated idsFabian Kosmale2021-12-161-0/+1
| | | | | | | | | | | | | | | | Besides emitting a warning in case of duplicated ids, this commit also refactors the id handling by moving it out of the generic visit function, into a dedicated method. Moreover, internal documentation is added to various functions in QQmlJSScopesById, and a new function to quickly check for duplicated ids in a file is added. While those conflicts do not necessiate an id duplication (they could be in different components), this allows for a quick pre-check, and might be later used to print a non-fatal warning about the potentially confusing id reuse. Fixes: QTBUG-99179 Change-Id: Ia99ebd17491d91d6f7747d65b3a8d15fa1f84e07 Reviewed-by: Ulf Hermann <[email protected]>
* Pass qmldir to qmlcachegen, qmllint and qmltc, not the qmltypes fileUlf Hermann2021-12-131-2/+2
| | | | | | | | | | | | | | | | | | The tools will still grudgingly accept qmltypes files being passed via the -i option. We generally expect qmldir files, though. Ignoring the qmldir file and importing the qmltypes directly, ignores qmldir imports, dependencies and other component entries. This leads to unresolvable types. [ChangeLog][QML Tooling] qmllint expects qmldir files, not qmltypes files to be passed via the -i option now. This enables it to see the imports and dependencies of the module being imported. For backwards compatibility it still accepts qmltypes files, with a warning. Pick-to: 6.3 Fixes: QTBUG-99043 Change-Id: I5ed32d7e78df1e604aaf1bfa2ebda09d5d57b628 Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlJSImportsVisitor: Break inheritance cyclesUlf Hermann2021-12-121-3/+2
| | | | | | | | | | | | | If we keep them around, later passes on the same data may run into infinite loops. We cannot fully prevent any further processing of the data because the import can happen from deep within a hierarchy of components and modules. Also, separate the deprecation check from the inheritance check. Pick-to: 6.2 Change-Id: I62ce7cd15be83f60cd72b63ab858632fbc7dea66 Reviewed-by: Fabian Kosmale <[email protected]>
* QQmlJSImportVisitor: Add bindings as soon as they are encounteredAndrei Golubev2021-12-081-1/+1
| | | | | | | | | | | We should be able to do it, period. This can also simplify the semantic analysis logic (which is for now untouched). But the main benefit is that now we should add bindings in the same order the IRBuilder sees them in Change-Id: I377b709c37770ea48e6b0b3a6962810a3b1f454a Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
* QmlCompiler: Disallow access to IDs in other componentsUlf Hermann2021-12-031-4/+7
| | | | | | | | | There is no guarantee that this works. Fixes: QTBUG-98830 Pick-to: 6.2 Change-Id: Id205170a41caa4bed264864a1ff35a57303641e9 Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Re-enable warning about automatched signal handlerUlf Hermann2021-11-261-10/+0
| | | | | | | | ... and give a hint on what to do about it. In order to not duplicate all the warnings from the importer, make sure it runs only once. Change-Id: Ie2b314ff659664f7c84c20cc7971c094e15c59cf Reviewed-by: Maximilian Goldstein <[email protected]>