aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsutils.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QQmlJSUtils::resourceFilesFromBuildFolders: port to QDirListingSami Shalayel2025-09-301-4/+5
| | | | | | | | | | | Use QDirListing instead QDirIterator in resourceFilesFromBuildFolders. QDirIterator is deprecated and shows up a bit in the profiler when investigating why tst_qmlls_modules::qmldirImports timeouts some time on a debug asan build. Pick-to: 6.10 Change-Id: Icc80c39f48ac381828829dc0d4c5eb51ed42abbf Reviewed-by: Fabian Kosmale <fabian.kosmale@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>
* qqmljsutils: improve didYouMean performanceSami Shalayel2025-02-181-2/+2
| | | | | | | | | | | | | | | | | | | | didYouMean eats up a lot of time in the profiler when imports can't be found, so its not really a "performance fix". But it makes qmllint faster on files that have a typo in its imports for example. Swapping QList with QVarLengthArray makes the runtime of tst_qmllint_benchmark:onlyQdsLintPlugin on qtdesign-studio/examples/DesignEffectsDemo/content/Gallery.ui.qml go from 150ms to 125ms when the QtDesign studio modules import paths are missing. It seems that QVarLengthArray does less allocations than QList, probably because of the std::swap. It seemed that std::vector had similar performance to QVarLengthArray, up to some ms. Task-number: QTBUG-133349 Change-Id: I3facc8f194da6eaf1aebbce91292bf9b164b740e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlls: fix go to definition going to build folderSami Shalayel2024-12-121-20/+4
| | | | | | | | | | | | | | | | | | | Amends b1ff6073a7247c921e20cd98b2e3297e7368681b that does not find resource files of QML Modules that are not the main QML Module: use all available .qrc files in the build directory when doing operations like "go to definition". Also search for hidden folders, because .qrc files tend to be nested inside of .qt or .rcc folders. Add a test when going to the defition of a QML file defined in a different module. Pick-to: 6.8 6.9 Fixes: QTCREATORBUG-31881 Fixes: QTBUG-131920 Change-Id: I751e2cd2d1a9867459226e4f884eb1da5c1f9436 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Remove trivial type comparison methodsUlf Hermann2024-11-291-8/+5
| | | | | | | | We can compare types without QQmlJSTypeResovler now. Task-number: QTBUG-124670 Change-Id: Id06c8cd5cc8f03683134ad13e02d54ae4da9fae3 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* add util to map .qml from source to build folderSami Shalayel2024-09-101-0/+93
| | | | | | | | | | | | | | | | | Add a helper method qmlSourcePathFromBuildPath in the QQmlJSUtils static class that maps QML files from the build folder to their source folder, and vice-versa. Uses a heuristic for QML modules that do not use "prefer" qmldirs for each folder that contains QML files. It will be used in a later commit to translate build folder paths, encountered during "go to definiton" in qmlls, to source folder paths. Pick-to: 6.8 6.7 Task-number: QTBUG-127661 Change-Id: I81f4b75a008d773835affb622af7f964b753e5ac Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* qmlls: find and use resource files from .qt/rccSami Shalayel2024-09-101-2/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Search for resource files in .qt/rcc instead of only looking in the .rcc folder, and update the resource file mapper in setLoadPaths to actually use the resource files. Amends d0fcb75aab1b5a91260fb378d761257e1f2e4787 to: a) work on more sophisticated project structures with "prefer"-directives b) use resource files for all qmlls modules (previously only the linting module was using resource files) Also move the methods to find .qrc files into qqmljsutils_p.h and add a new test file. This patch fixes the spurious warning about SettingsData being not found and the missing completion suggestion for the SettingsData type in qml/popups/AdminDialog.qml on Ekke's project attached at QTBUG-126504. The build folder structure was mimicked in sophisticatedBuildFolder for the test. Also change DomEnvironment::semanticAnalysis() to return a value instead of a reference, and rename SemanticAnalysis::setLoadPaths to SemanticAnalysis::updateLoadPaths because it will set the loadpaths on all copies of semanticAnalysis instead of just setting it on the current one. Pick-to: 6.8 6.7 Task-number: QTBUG-127661 Task-number: QTBUG-126680 Change-Id: I47299711ced6cb952c4d3c1893495cb17a8eec7f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Divide scope-name lookup methods into multiple casesUlf Hermann2024-06-151-4/+1
| | | | | | | | | | | | | | | | | * 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: Add generic QVariant-to-typed comparisonUlf Hermann2023-12-071-9/+5
| | | | | | | Since we have a lot more shadowable values now, we need to add this. Change-Id: Ie9f389730bb6f330b1cd28f9229c5dd143727e4f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Remove QQmlJSTypeResolver::scopeForId and idForScopeUlf Hermann2023-11-231-1/+4
| | | | | | | | | | You should always do the full lookup. You might find a property instead of an ID, after all. Task-number: QTBUG-119162 Change-Id: Id96bc19e6fd7e7967382091c7de7bb398bfd311b Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Allow comparison of optional typesUlf Hermann2023-11-091-17/+9
| | | | | | | | | | | | | The only extra case we have to consider is the construction of an optional type from a QObject-derived since that is stored in a QVariant rather than a QObject*. Everything else we can compare is already covered by the generic QJSPrimitiveValue comparison since QJSPrimitiveValue can store undefined. Fixes: QTBUG-117799 Change-Id: Iac89f28497c34d217af156d363b8beeda76174ef Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* qmlsc: Support equality operations for QUrlSemih Yavuz2023-02-161-0/+16
| | | | | | | Task-number: QTBUG-110983 Pick-to: 6.5 Change-Id: I9a664178c91bfa2962e2a5a3bf4bfa174a74a9d0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Uncruftify FixSuggestionUlf Hermann2023-02-081-5/+7
| | | | | | | | | 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>
* qmlcachegen: fix nonstrict equality code generationSemih Yavuz2023-01-311-3/+3
| | | | | | | | | | | | | | We should generate type checking code for only strict comparison of var against null/undefined types or vice versa cases. The non- strict comparison should be handled elsewhere. Removed pragma Strict to allow to add warning emitting tests of non-strict comparison. This amends 6a816a9e0dfc2b41a4f86c721679f2517ec27eb6 Pick-to: 6.5 Fixes: QTBUG-110769 Change-Id: I7f9a457e71a621a005f377216e841bec01667454 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCachegen: Equality comparison ability to QObject *Semih Yavuz2023-01-101-0/+20
| | | | | | | | | | We should be able to compare QObject * with QObject * or a nullptr. Pick-to: 6.5 Fixes: QTBUG-109377 Change-Id: I0e9d6fdc89cbb471774d6382316dfb4813310e1d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCachegen: Equality comparison ability to var and void/null typesSemih Yavuz2023-01-061-0/+29
| | | | | | | | | | | | | | | The code generator currently rejects any comparisons other than primitive types. Add comparison capability for var types against null or undefined types and vice versa. To achieve this, we generate code that fetches the contained object within the variant and comparison is done depending on the stored type. Ideally, we also need to add comparison capability for QObject *, that will be handled with QTBUG-109377. Pick-to: 6.5 Fixes: QTBUG-108632 Change-Id: Ib15450d7922f6025c78def5cc548c74827ad740f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltc: Remove broken alias optimizationSami Shalayel2022-10-111-7/+11
| | | | | | | | | | | | | | | | | | | | Remove the recursive alias resolution mechanism. It tried to resolve aliases recursively but only knew the id's of the current component. This means that an alias pointing to a property defined in another component (e.g. a different qml file) was resolved using the id-to-scope map of the component containing the alias property. This leads to unresolved aliases at best and endless loops when the aliased property was itself an alias pointing to some property also existing in the original component (see QmltcTests/ComponentWithAlias{1..3}.qml for an example). Also added the reproducer in the qmltc tests. Fixes: QTBUG-107533 Fixes: QTBUG-107534 Change-Id: Idbf0cff3e45213bc7fbb4a98a9393c6754b00046 Pick-to: 6.4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-071-1/+1
| | | | | | | | | | | | | | 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-7/+7
| | | | | | | | | | | | | | | | | | | | 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>
* Revise build to source dir mapping for QML toolingAndrei Golubev2022-07-261-0/+44
| | | | | | | | | | | | | | | | Instead of doing build file path to source file path mapping for each QML file, we could store qml module prefix to qml module output directory mapping instead. This reduces the produced qrc size and makes it more convenient to work with Do a clean separation at the QQmlJSImporter level to prevent using resource file mapper for build directory path resolution Amends 7f567e6a424a3919337aad498543d58c1252df62 Change-Id: If984abada1d39c386af5712af778eb29956e0537 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> 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>
* qmltc: Set alias property methods in QmltcVisitorAndrei Golubev2022-06-091-8/+32
| | | | | | | | | We can now sensibly do alias setup in the visitor so no need to keep a special prototype pass around for it Pick-to: 6.4 Change-Id: I29d2d395cfa6d66eabb36d7fdbd9bfa3bc3df988 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJSUtils: Pass non-trivial parameters as const refUlf Hermann2022-05-111-24/+24
| | | | | | Coverity-Id: 392715 Change-Id: I5b38f070511965b1fd10cf286b7727acdb892fcb Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* qmltc: Move alias compilation to qqmltccompilerAndrei Golubev2022-05-031-0/+60
| | | | | | | | | | | Introduce an alias resolution procedure to query the origin property and its owner for a given alias Add alias compilation to the "proper" qmltc code and remove the equivalent one from the prototype Change-Id: I55bc1e3e6206b4cfce259526d1bc2813e8ea7cfb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Replace uses of deprecated _qs with _s/QStringLiteralSona Kurazyan2022-04-291-1/+3
| | | | | | Task-number: QTBUG-101408 Change-Id: Ic925751b73f52d8fa5add5cacc52d6dd6ea2dc27 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Improve consistency of QQmlJSUtils::didYouMean()Andrei Golubev2022-04-251-1/+12
| | | | | | | | | | | | | | We have to either sort the input candidate list or ensure that we always get same-ordered candidates at the call sites. The latter seems rather problematic since we usually use QHash::keys() as candidates so blarantly sort the candidates instead Complexity-wise, this adds an extra O(n * log(n)) procedure (where n is the size of the candidates list) which might or might not be amortized by the main logic (depends on average input/candidate string lengths) Change-Id: Ib528d453e2f4b2d6646f1451f5aefa559a0bdc10 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Offer suggestions for typosMaximilian Goldstein2022-01-171-0/+76
Automatically suggests fixes if a user has a typo in the naming of a component, property or binding. Also now warns about calling undefined functions. [ChangeLog][qmllint][New Feature] qmllint will now automatically suggest fixes if it thinks a component, property or binding was not found due to a typo. Fixes: QTBUG-97693 Change-Id: Ia66c1ba84e187a2eb31bbdf33ca30d7e5141bea9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>