aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsimportvisitor.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* qmltc: warn about QML defined types from other modulesSami Shalayel2024-02-191-0/+1
| | | | | | | | | | | | | | | | | | | | Add a warning for QML defined types imported from other modules in qmltcvisitor to avoid qmltc generating invalid C++ code. This requires populating the moduleName member of qqmljsscope where it was ignored: * for qmldir files imported via command line options * for inline components * for the file to be compiled The module name of the QML file to be compiled is passed from CMake to qmltc via a newly introduced command line argument, and is simulated in the tst_qmltc_qprocess tests. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-121592 Change-Id: I965d759a028546c648ccf6c9aa469b84538be446 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: Add warnings to importFromHostDmitrii Akshintsev2023-11-231-0/+11
| | | | | | | | | | | | | | | | When importing, QQmlJSImportVisitor creates a url from the filename. In cases when URL schema is empty and url is not Qrc it tries to import from Host. This commit adds a warning and early exit if file or directory doesn't exist. It also adds a warning if the imported object exists, but it's neither a file nor a directory Task-number: QTBUG-118074 Change-Id: I59cea90d611a68f2e662040a5ee4ba0ae3f0fe5b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* qmlls: add completion for pragmasSami Shalayel2023-09-261-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | To be able to decide how a pragma is completed, one needs to know if we are before or after the ':', for example in 'pragma NativeMethodehavior: AcceptThisObject', one needs to know if we are completing the pragma names or the pragma values. For this, add a sourcelocation for the colon in AST::UiPragma in the parser, and pass it on in the FileLocations so the sourcelocation of the colon, when existing, can be accessed from the DomItem. Once the position of the colon is known, the names or values for the pragmas can be completed. To easily obtain the position of the colon of a DomItem, move some code from the Binding completion into a static helper to reuse it for pragmas. Also fix some typos in the warning messages about invalid pragmas in qqmljsimportvisitor. Task-number: QTBUG-116899 Change-Id: Ib20bb6aa50e9b8dc5830f426d0ca9719693c0a15 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmljsimportvisitor: add warnings for lower caseSami Shalayel2023-09-111-3/+39
| | | | | | | | | | | | Replace an assert with a warning, and warn when qualified import names start with a lower case letter. Add a test for that. Also warn when using a qualified import with a name starting with a lower case, so users can fix their mistake more easily. Pick-to: 6.6 Change-Id: Iff2b9148c5a36625baad70798e2efe006905e2a3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJSImportVisitor: Mark internal documentation as internalFabian Kosmale2023-08-301-0/+1
| | | | | | | Pick-to: 6.6 Change-Id: I12ef1ad0315c609af7059c58e77196eba4f5fd92 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* QQmlSA::ScriptBindingKind: Turn into scoped enumerationFabian Kosmale2023-08-301-7/+7
| | | | | | | | | | | and remove the Script_ prefix from its entries. This is more aligned with Qt's namings conventions. Pick-to: 6.6 Change-Id: Ie97c2ce204b5532ab6bd6b136145f2a537175fbb Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* qmlls: show fix suggestions and enable quick fixesSami Shalayel2023-08-291-17/+14
| | | | | | | | | | | | | | | | | | | | | | | | | Display the fix suggestions from qmllint in qmlls instead of just showing the warning. For example, 'Unqualified access: xxx is accessible in this scope because you are handling a signal at 18:10. Use a function instead.' sounds so much more helpful than the previous 'Unqualified access'. Add an ending '.' in QQmlJSFixSuggestion's messages where missing. Enable quick-fixes in VS Code and QtC by labeling quickfixes as quickfixes. Everything that is not labelled a quickfix might need a special language client implementation to work. Also, add a test for quickfixes: it seems someone broke the quick fix functionality in qmlls by mistake by relabeling a quickfix to 'refactor.rewrite'. Task-number: QTBUG-115213 Change-Id: I350e23901b97d16a60bb39fdb4ab566b0d7fbdfb Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> 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>
* Replace signal name manipulations with QQmlSignalNamesSami Shalayel2023-08-151-6/+6
| | | | | | | | | | | | | | | 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>
* qmlls: find id's, not the item around itSami Shalayel2023-08-091-1/+0
| | | | | | | | | | | | | | | | | | When you use qmlls's 'go to definition' on an id, it jumps to the object around it, instead of the id-binding. For example: ``` Item { id:me } // go to definition for 'me' goes to 'Item' above instead of the 'me' // after the id! function f() { console.log(me)} ``` Retrieve the correct sourcelocation from the Dom, fix the tests, and remove one unused helper method in tst_qmlls_modules. Change-Id: Ic25ceb8399cbc27e65574f2c3c7e71249bcac8f6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSScope: move causesImplicitComponentWrapping helper to its only usage siteFabian Kosmale2023-08-071-2/+43
| | | | | | | | | No point in cluttering the interface if it is only needed in a single place. Change-Id: Iff14f67c56b70cec035ef5d75359295155fef6e3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QQmlJSScope: Decouple ContextualTypesFabian Kosmale2023-08-071-1/+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 <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* QmlCompiler: Check all names against the type location mapUlf Hermann2023-06-271-1/+1
| | | | | | | | | | | | Value type names are lower case. If a value type from a module is used, that also counts as usage. The whole affair is a heuristic with or without this. An identifier can be a number of other things that we cannot find in the imports. Pick-to: 6.6 Change-Id: I55a5d2dfa439d20dcbd9d015cbc2f2efbfaa8b73 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Scan template literals when importingUlf Hermann2023-06-261-0/+4
| | | | | | | | | We want to know whether they contain identifiers we are interested in. Pick-to: 6.5 6.6 Fixes: QTBUG-113855 Change-Id: Icaff280d5babfdd2aae829d5b1b458c3ec76365a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlls: find definitions of function parametersSami Shalayel2023-06-051-2/+2
| | | | | | | | | | | | | | | Function parameter definitions in the QQmlJSScope were lacking their source location, such that asking the definition of a parameter always returned the location of the first parameter. Fix it by writing the proper Location in the QQmlJSScope. This requires adding the location information to BoundName(s). Also added some tests. Task-number: QTBUG-111409 Change-Id: Ieb6155f120ca24e899af4b3824cab561788d008b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* QQmlSA: Create an abstraction layer for static analysisOlivier De Cannière2023-05-301-80/+84
| | | | | | | | | | | | | | | 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 <fabian.kosmale@qt.io>
* qmlls: support find type definition for script identifiersSami Shalayel2023-05-231-9/+27
| | | | | | | | | | | | | | | | | Add QQmlJSScope to JS identifiers in the QQmlJSScope and resolve them in the QQmlJSScope resolving step. Use them to find the type definition of script identifiers. Test the new feature. Todo for after FF: find out why only the part after the "component <name>:" is found (which should be enough for real usage) for JS identifiers. In an ideal world, it would find the "<name">" and just highlight it. Fixes: QTBUG-111410 Change-Id: Id83ec08fd4c66a9c7468e3bec19ba09f4ce8634f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Separate logic by import type in QQmlJSImportVisitor::visitOlivier De Cannière2023-05-121-46/+64
| | | | | | | | | | | | | | 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 <ulf.hermann@qt.io>
* qmllint: Do not crash on invalid aliasFabian Kosmale2023-05-041-1/+3
| | | | | | | | | We handle already multiple invalid alias constructs, but the case where the alias is illegal without being an expression was not handled so far. Pick-to: 6.5 Change-Id: If85bc4b61f645a8f1eff3afa4da394c7373d8d53 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Disallow reading from values affected by side effectsUlf Hermann2023-05-041-2/+2
| | | | | | | | | | | | | | 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>
* QmlCompiler: Do not stop parsing on top-level Component elementsUlf Hermann2023-05-031-1/+0
| | | | | | | | | | | | | 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 169f0f71665a3a5155f8d63a9c11bc2484353561. Pick-to: 6.5 Fixes: QTBUG-112897 Change-Id: Ie8486909f9bea9ee1b87f2857f7b77fb7cc561e8 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Use actual type of enums, rather than intUlf Hermann2023-04-261-1/+0
| | | | | | | | | | 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>
* QML: Add an "Addressable" value to ValueTypeBehaviorUlf Hermann2023-03-021-0/+4
| | | | | | | 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>
* QML: Allow pragmas with multiple valuesUlf Hermann2023-02-221-29/+48
| | | | | | | | | This will be needed in follow-up changes. Task-number: QTBUG-94807 Change-Id: I6243ea31290251c30dd0aceaae878568bc1c0525 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* qmllint: Fix attached property re-use detectionUlf Hermann2023-02-141-2/+2
| | | | | | | | | | | | | | | | | | | | | Move the detection into the QtQuick lint plugin. It's mostly meant for QQC, so let's auto-enable it for attached types derived from QQuickAttachedPropertyPropagator. To this end, two new categories are introduced: The Quick lint plugin gets its own attached-property-reuse category which is synonymous to the default category of the same name. Furthermore, we add a controls-attached-property-reuse category for only checking controls. That one is implied by either of the others. Finally, fix the id vs. scope resolution to actually do something. This way we can give appropriate hints when the outer type has an ID already. Pick-to: 6.5 Fixes: QTBUG-110834 Change-Id: Ib71a9e3bbc10bac77f36db6cc441af88df20fd33 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Uncruftify FixSuggestionUlf Hermann2023-02-081-21/+22
| | | | | | | | | In this form we can expose it in QQmlSA. Pick-to: 6.5 Task-number: QTBUG-110834 Change-Id: Ieb0cf31b6e86379c0d80f89bc6c63b129f269798 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Consider attached types for "unused import" detectionUlf Hermann2023-02-071-1/+8
| | | | | | | | Pick-to: 6.5 Fixes: QTBUG-110833 Change-Id: Ie766c957a9ebeaea808fdc6904a1caea0e4cb849 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: Add warning about PropertyChanges using custom parserUlf Hermann2023-02-031-1/+3
| | | | | | | | | You should use the id-based generalized group form. Pick-to: 6.5 Fixes: QTBUG-105251 Change-Id: I42edfb03059d3e8c92bfb3c311bf1ed1af7cf70e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML DOM: Remove support for Qt < 6.5Fabian Kosmale2023-01-301-22/+0
| | | | | | | | And build standalone DOM against Qt 6.5 (beta) Change-Id: I9395b4932ecdedd28f10d1e791e2abe445516183 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Turn singleton/type mismatch into a run time type errorUlf Hermann2023-01-271-16/+11
| | | | | | | | | | | | | | | | | | | | | | | There are many ways to "hide" the qmldir from the engine at run time, which turns singletons into regular types. While all of this is invalid, we should not assert on it, but rather produce a legible warning. Furthermore, sharpen the importing of extra modules from qrc as implicit imports. We should really only import modules the file in question can ever be part of. Otherwise we needlessly produce the above situation and hide legitimate warning messages. Amends commit 7517c1b3ae9aa92f36b19d74a4b2de5e8531309b. Now we need to teach our tools about the default import paths in the resorurce file system. They cannot guess any type they may find in any resource file anymore. Pick-to: 6.5 Task-number: QTBUG-106929 Change-Id: Ic8c02396d10830a7f461e8a81649bb8c9a1add1f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: Move qmlControlSanity loggers into a pluginSemih Yavuz2023-01-231-9/+0
| | | | | | | | | | | | | | QmlImportVisitor has some log messages that is only used for controls sanity tests. Move these loggers into a QuickControlsSanity plugin. Move the relevant tests from tst_qmllint to tst_sanity as we link the plugin to tst_sanity. Also remove qmlControlsSanity category from the default categories of QQmlJsLogger as it should be only utilised by this plugin. Task-number: QTBUG-103276 Change-Id: Iacc624711a2cd00aeb9d89fbde7c0131896d30ce Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Add a pragma for value type behaviorUlf Hermann2023-01-201-14/+23
| | | | | | | | | | | Unfortunately value types behave differently when compiled to C++. Document the difference and introduce a pragma to make them behave one way or the other. Pick-to: 6.5 Fixes: QTBUG-109221 Change-Id: Ib2685153c0b4ae209bafbea7a01229377fdb47dd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Fix signal checking in import visitorUlf Hermann2022-12-151-160/+168
| | | | | | | | | | | | 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 <fabian.kosmale@qt.io>
* QmlCompiler: Fix recognition of builtin list typesUlf Hermann2022-12-151-2/+11
| | | | | | | | | | | | | Previously all list types used as arguments or return types for methods had to be looked up via the imports. However, builtin types are not part of the imports at run time. Therefore, recognize list types already early on, when generating the IR. This is the same way we do it for property types and it allows us to easily identify lists of builtins. Pick-to: 6.5 Fixes: QTBUG-109147 Change-Id: I91fa9c8fc99c1e0155cc5db5faddd928ca7fabbc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltc: fix handlers for c++-signalsSami Shalayel2022-12-071-2/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow qmltc to generate handlers for c++-defined signals with const parameters by changing the safeguard to avoid type mismatch between slots and signals. First, remove the qOverload in the generated QObject::connect call to be able the connect slots and signals with different types (namely, pass by const references and pass by value should be interchangeable but is not allowed by qOverload). Second, save in QQmlJSMetaParameter when types are passed by pointer. Like this, qqmljsimportvisitor can check if a value type is indeed passed by value or const reference in a C++ signal. The same for reference types that need to be passed by (const and non-const) pointer. Print a message when an type is passed by argument in an incompatible way instead of letting qmltc generate uncompilable code, which makes the compiler print out cryptical messages. Third, add a qqmlcpptypehelpers template that decides if value types should be passed by value or reference, by letting the c++ compiler check if sizeof(T) > 3*sizeof(void*). Fixes: QTBUG-107625 Fixes: QTBUG-107622 Change-Id: I1a00532df591d10f74c1fd00dff5b7fccf40cb22 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJSImportVisitor: Do not deref potentially null typeFabian Kosmale2022-12-051-9/+10
| | | | | | | | | | When checking for default properties, a type may not be resolved (due to a missing import). So check for that first before checking that the type is a list property. Fixes: QTBUG-109197 Change-Id: Idc142588b5d8bc52fdea52d637afc3643e7d9891 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJSMetaParameter: Encapsulate parameter informationSami Shalayel2022-12-021-8/+14
| | | | | | | | | | | | | | | | | | | Previously, there were four lists that contained each one entry for each parameter. There was one list responsible for the names, types, type names and const-qualifiers but this was quite bothersome to use (e.g. they not always had the same length). This commit introduces QQmlJSMetaParameter to encapsulate all the information required when manipulating parameters. This reduce the 4 lists to one, making parameters easier to handle and QQmlJSMetaMethod easier to read. This is a purely refactoring change, no new functionality was added. Task-number: QTBUG-107625 Change-Id: Ia41b823c9e6294ee26e828071b802cac6b4058ce Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJSImportVisitor: warn when uncreatables are createdSami Shalayel2022-11-231-3/+15
| | | | | | | | | | | | | | | | | | | | | | isCreatable in qqmljsscope just returns the value of the flag as it was read from the qmltypes, which is slightly confusing as isCreatable is an opt-out option. Instead, isCreatable should reflect whether the type is creatable or not. A type is uncreatable if and only if it is a singleton, an attached type, a c++ type with QML_UNCREATABLE and types without default constructor. This uncreatibility can also be inherited to composite types. Types without default constructor require QML_UNCREATABLE or QML_ANONYMOUS, and will be handled in another commit. Now that uncreatable types can be detected, emit a warning when a singleton or an uncreatable type is created: up to now no such warning was emitted. This warning can be seen when using qmllint or qmltc. By the way, also fix qmltc to not assert when something goes wrong (e.g. because an uncreatable or singleton type was created). Change-Id: I9a82106a801d14063407eb4e54858b1ca9fd578b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltyperegistrar: add IsConstant for method parametersSami Shalayel2022-11-111-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Mark method parameters with IsConstant instead of including "const " in the typename, which makes type resolution in the qml compilers impossible. This also avoids a crash in qmltc happening when qmltc sees a signal defined in C++ that has a const parameter. When qmltyperegistrar writes out the types in the qmltypes, check if it starts with a const, remove it and add instead IsConstant: true. The name returned by MOC is normalized so no need to check for "volatile const" or "const volatile" (its always the latter) and no need to filter out for extra whitespace. Once the const is read by the qmltypes reader, propagate the const-information around using a newly introduced enum called QQmlJSMetaMethod::PConstness that can currently be Const or NonConst. Also add the isConstant property to the Parameter.qml in the tooling module. Add a test to see if the IsConstant information is written into the qmltypes. This is also required for QTBUG-107625. Fixes: QTBUG-108147 Task-number: QTBUG-107625 Change-Id: I13bda0a27fe83867f259b751468788128fec82ed Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Allow lists as arguments to methodsUlf Hermann2022-11-101-2/+4
| | | | | | | | | | | | | | | | | | | 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: Enforce consistency of ContextualTypesUlf Hermann2022-11-021-35/+30
| | | | | | | | | | | | | | | An instance of ContextualTypes can only either hold QML types or internal types. We always need an integer and an array type, though. Previously, "int" was always added to the used types when it was looked up for potentially resolving enums. This prevented the builtins from being reported as unused import. Since we pass "int" as a separate member now, prevent the builtins from being recorded as import location in the first place. Task-number: QTBUG-107171 Change-Id: I288b6e070c2039d4ac85073886c9929a2eed3998 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmltc: support inline components from different qml filesSami Shalayel2022-10-311-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Make qmltc aware that inline components can be shared between files such that it does not complain about not finding them. Typical usage are `MyOtherFile.MyInlineComponent {}` and `ModuleName.MyOtherFile.MyInlineComponent {}` for an an inline component called MyInlineComponent defined in MyOtherFile.qml, maybe also in a module called ModuleName. Make QQmlJSScope::findType() aware that inline components exists (and potentially that they might also appear in namespaced types). They can also be "imported" or reexported from basetypes and/or deeply nested in some children scopes. Also make it public so that qqmljsimportvisitor can use it when processing property types. Added some tests testing both notations (with and without the qualifed module name). Also add a test to see if there is no confusion between the enums and the inline components (due to their very similar notations). Fixes: QTBUG-106592 Change-Id: I8f2d4790729902ffa664fd0eb1b7c3279af8ddca Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: Warn about duplicated signal/property namesSemih Yavuz2022-10-221-0/+10
| | | | | | | | | | | | | Qmllint does not warn about duplicated property and signal names while qmlengine complains about them. Introduce a new logging category for the duplicated names and log duplicated property/signals. This change breaks one of tst_qmljsscope testcase as it expects no logging within that case, edit it. Fixes: QTBUG-106579 Change-Id: I7732e08778a25e1eb2ba980ae395564b98c665a5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add option to enforce function signaturesUlf Hermann2022-10-141-3/+19
| | | | | | | | | | | | | | | | | | | | | By default, the QML engine does not enforce signatures given as type annotations to functions. By passing different types than the function declares, you can get different behavior between the interpreter/JIT and the AOT-compiled code. In addition, in interpreted or JIT'ed mode, we pass all non-primitive value types as references. This means, if you modify them within the called function, the modifications are propagated back to the place where the value was loaded from. Enforcing the signature prevents all of this, at a run time cost. Since we have to coerce all arguments to the desired types, the function call overhead grows. This change introduces a pragma "FunctionSignatureBehavior" which you can set to "Ignored" or "Enforced" to choose one way or the other as universal way of handling type annotations. Fixes: QTBUG-106819 Change-Id: I50e9b2bd6702907da44974cd9e05b48a96bb609e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlcompiler: refactor ContextualTypes to know its contextSami Shalayel2022-10-141-28/+39
| | | | | | | | | | | | | | | | | | | | | | The code in qmlcompiler working on ContextualTypes is very confusing as it handles internal types (c++ and synthetic jsrootgen type names) and qml types at the same places. Furthermore, some methods like qqmljsscope::findType() have different behaviors when running in different contexts, e.g. in the internal type context it needs to lookup namespaced c++ enums (e.g. QQmlComponent::Status) while in the qml type context it needs to lookup inline components (qmlFileName.MyInlineComponent). Changed ContextualTypes to be a struct with the types QHash and an enum with the context (QML or INTERNAL), Drive-by change: amend the iterations over types.keys() to use an iterator instead of allocating a temporary QList as types is not that small (may contain around 400 items just for the builtins). Fixes: QTBUG-107191 Change-Id: Ib463ec873019ea1e6844c522a090030e9a44d53f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: early return from array bindingsSemih Yavuz2022-10-141-1/+6
| | | | | | | | | | | | | | List in qml should not include an object whose scope types is attached or grouped. In case an attached or grouped type is a member of a list, they don't have a separate scope, but only one scope is created per name. This causes a crash as creating bindings for array members since it is not known if any of the child scope is omitted or not. To prevent this, simply early return if any of the child scopes include an object definition that is attached object or group type. Fixes: QTBUG-107250 Change-Id: I08fdfb43d766569c4dfefc50135f98f74d25bad2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Analyze qsTranslate at compile timeUlf Hermann2022-10-131-3/+9
| | | | | | | | | | We generate translation bindings for all the other translation functions already. We can just as well generate a translation binding for this one, too. Fixes: QTBUG-107536 Change-Id: I851f03c26510b6d450aa78f5d7a1f0142d3a81aa Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qqmljsimportvisitor: rename m_currentInlineComponent to m_currentRootSami Shalayel2022-10-101-5/+5
| | | | | | | | | | | 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 <fabian.kosmale@qt.io>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-071-3/+3
| | | | | | | | | | | | | | 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-10/+10
| | | | | | | | | | | | | | | | | | | | 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>
* qmltc: warn about enums declarations in inline componentsSami Shalayel2022-10-041-0/+4
| | | | | | | | | | | In QQmlJSImportVisitor, emit a warning when enum declarations are detected inside of inline components, as those cannot be used at all with the engine (neither inside nor outside of the inline component they were defined). Fixes: QTBUG-107063 Change-Id: I21329c35d5dd8940e047771416bba04858cb3921 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>