Commit Graph

25 Commits

Author SHA1 Message Date
Semih Yavuz feca8417f6 qmldom: Add more literals
Dom construction fails before this commit if it encounters one of
null expression, true and false literals. Add dom representation for
them.

Change-Id: I2dbb2ebfce83b32426eb5e159fe9e4f0f68c56c3
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-05 19:56:42 +02:00
Semih Yavuz 1700675731 tst_qmldomitem: Add more tests
Add test for null statements inside blocks. Also, add tests for const and
var variable declarations.

Change-Id: I7eacb74a848e3ee7a4c0b2053de72c902330ce2b
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-05-04 18:59:34 +02:00
Semih Yavuz c17226bf98 tst_qmldomitem: Refactor scriptExpressions test
Divide scriptExpressions test into smaller testable units

Change-Id: Ib8a3b58e43bfe9a22ae72f35600f67bef163d855
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-05-03 10:59:08 +02:00
Sami Shalayel eba8eb2305 Qml: Add script element for return statements
Implement and test the DOM representation of a JS return statement.

Task-number: QTBUG-100084
Task-number: QTBUG-111415
Change-Id: I2c11c0b9be3c93cf5be2bd9db5575335d4be19c1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-02 09:08:30 +02:00
Sami Shalayel 7d8ac7c2d3 qqmldomastcreator: set qqmljsscope in DOM script elements
Rename the getter from {setQ,q}QmlJSScope() to {setS,s}emanticScope().
Set the semantic scope in the script elements where needed.
Test that BlockStatements contain their semantic scope.

Task-number: QTBUG-100084
Task-number: QTBUG-111415
Change-Id: If8b34c7edaac6aaf42a1cb2c47b12820358709e5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-02 09:08:29 +02:00
Sami Shalayel 447fbe9186 tst_qmldomitem:domContructionTime for scriptexpression
Add a benchmark for DomConstruction using the scriptexpressions.

Task-number: QTBUG-92876
Change-Id: Ieab942a194d82933601424247d6ab71bce0540e2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-02 09:08:29 +02:00
Sami Shalayel 4a15598628 Dom: Introduce scriptelements in the DOM representation
Implement the Dom representation for some constructs, like:
* Literals (string and numbers)
* IdentifierExpressions (variableNames appearing in expressions)
* VariableDeclarations and VariableDeclarationEntries
* ForStatements
* BlockStatements
* IfStatements

Introduce the namespace QQmlJS::Dom::ScriptElements that will contain
the Dom representation of javascript statements and expressions.

To incorporate the new DomItem wrappers in the Dom, extend the
qqmldomastcreator to also visit the corresponding javascript AST parts.
Like this, it can create the new Dom script elements using its stack:
visit() pushes new elements on the stack while endVisit() collects the
children of the current element from the stack (note: in the reverse
order they were pushed on the stack). The implementation uses two stacks
to avoid having to check every time if the top of the stack is a
QmlStackElement or a ScriptStackElement, but logically both stacks work
as one stack, containing first all QmlStackElements and then all
ScriptStackElements.

In case non-implemented script elements are encountered by
QQmlDomAstCreator, it will disable the script expression
construction and print a warning, instead of asserting and making a lot
of unrelated tests fail. This mechanism can be removed once all script
elements are implemented in the DOM.

Wrap script element pointers into a ScriptElementVariant variant that
can be used to contain any script element.

Added a flag to enable script element construction during DOM
construction.

Task-number: QTBUG-92876
Change-Id: I24b070ca3ff6ce916036842280cf91a21d049f30
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-02 09:08:29 +02:00
Sami Shalayel 89b0960418 Dom: add QQmlJSScope to QmlObject
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 <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-04-12 13:07:06 +02:00
Sami Shalayel 6913084b0d Remove DomItem::loadFile code-duplication and use correct environments
The loadFile overload (in DomItem, DomEnvironment and DomUnivers) for
different files (in-memory files and files that needs to be loaded from
disk) are either copypasted or just calling the other overload.

Encapsulate the file-related arguments of all loadFile overloads into a
new struct called FileToLoad, such that the copypasted overloads can be
removed. Use the static factory function FileToLoad::fromMemory and
FileToLoad::fromFileSystem to create the FileToLoad struct.

In addition, FileToLoad allows to specify the environment in which a
file should be loaded. Prior this commit, myEnv.loadFile() was creating
a new environment for each loaded file.

Change-Id: I3b6acb681cb77faefdaa447d985bdfbe4f6a9ce2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-29 19:07:25 +02:00
Sami Shalayel f68d30cf25 Dom: fix for inline objects/components
Inline objects were missing information about their prototype in their
Dom representation. Add the prototype information and test that the
information really is in the Dom representation.

On the other hand, types defined by inline components cannot be found
using the DomItem::lookup() method, so fix the visitLookup1 method by
removing a broken shortcut and making sure that visitScopeChain also
visits inline component scopes. Also, make sure to not add component
maps multiple times, as else the visit runtime might grow squarely in
the number of inline components.

Task-number: QTBUG-110309
Change-Id: I39d0e408c9fd956b72be4d27f830f7cf0d231520
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-02-13 21:18:06 +01:00
Marc Mutz 958cd3ee10 Port from container::count() and length() to size()
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>
2022-10-07 23:38:48 +02:00
Fawzi Mohamed 8e6dcc04fc qmlls: fix import as resolution
Import as resolution (i.e. finding a type that was imported with an import as)
was broken in two ways: the shortcut looking for types did look only to types
imported without as, and the normal lookup for symbols declared the ImportScope
as visited (to avoid loops) too early in one case and would skip it.
This was visible in qmlls completions of Controls.

Pick-to: 6.4
Change-Id: Ifc1e777973ddc251bd0685290e8d28bfb025f269
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-08-12 15:10:01 +00:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
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>
2022-06-11 08:05:15 +02:00
Fawzi Mohamed b42b2e2ab8 qmldom: fix filterUp of two owners
finding the qmlObject from a script value (owner) did fail due to a
bug in filterUp.

Change-Id: I924ae5cb5db0548332594a0b36081da620d661a3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-05-19 15:47:45 +02:00
Sona Kurazyan 2c9c1590e6 Replace uses of deprecated _qs with _s/QStringLiteral
Task-number: QTBUG-101408
Change-Id: Ic925751b73f52d8fa5add5cacc52d6dd6ea2dc27
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-04-29 09:47:43 +02:00
Andreas Buhr f6c3767677 Fix warning about unused variable
Fixes "warning: unused variable ‘objPtr’"

Change-Id: Ia25a687c65fd6b647036263907ce7355750a9fa6
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2022-04-22 15:19:57 +02:00
Fawzi Mohamed 8d63fab2c9 qmldom: fix Map::fromMultiMapRef, and QmlDirectory dependencies
fromMultiMapRef had an elWrapper argument that was not really used.
Remove it, and fix QmlDirectory where it was expected to be used,
and it lead to not loading its dependencies.

Change-Id: I40998bc30ee22fd356cabce311f9428550d81b90
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-03-31 15:49:47 +02:00
Fawzi Mohamed b8f0516ab2 qmldom: fix lookup of qmltypes types
* correct type reference in qmltypes export
* fix filterUp: owner matching filter was skipped

Change-Id: I86a9be74b108c83f6024551616a929f5e9a487e8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-03-31 15:49:47 +02:00
Fawzi Mohamed bd89928c7f qmldom: resolve local alias properties
alias properties are resolved, until they refer to a property of an
imported type, or to a local type.
Alias of aliased properties are not officially supported, but works
in most cases. Set LocallyResolvedAlias::nAliases to non zero if such
an access happens to be able to warn about it.

Fixes: QTBUG-98276
Change-Id: I7c123d0a49d3ae283fc4c06e449f67b1d89e72c9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-03-21 20:12:12 +01:00
Assam Boudjelthia f22d884faf Disable failing declarative tests on Android
This allows us to enable testing on declarative for the module
as a whole and have some sort of test verification for the mean
time, and fix the fails over time.

Pick-to: 6.2 6.3
Task-number: QTBUG-100003
Task-number: QTBUG-100014
Task-number: QTBUG-100016
Task-number: QTBUG-100018
Task-number: QTBUG-100020
Task-number: QTBUG-100021
Task-number: QTBUG-100164
Task-number: QTBUG-100166
Task-number: QTBUG-100167
Task-number: QTBUG-100169
Task-number: QTBUG-100171
Task-number: QTBUG-100173
Task-number: QTBUG-100175
Task-number: QTBUG-100176
Task-number: QTBUG-100177
Task-number: QTBUG-100191
Task-number: QTBUG-100253
Task-number: QTBUG-100254
Task-number: QTBUG-100256
Task-number: QTBUG-100257
Task-number: QTBUG-100258
Change-Id: I85bf1501b94f04853a1ca715e35df0a56041308a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-01-31 14:41:39 +02:00
Fawzi Mohamed ee136c40cf qmldom: do not modify imports paths
Store imports of urls or directories as QmlUri objects.
Uri and path imports are kept distinguished, relative
path are not resolved before storing the import.
This allows one to always recover the original import.
Relative paths are resolved when imported if required.

Fixes: QTBUG-98275
Change-Id: Id91c739dc95ae9aed0b169a0e503be0658687d1c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-18 17:12:26 +01:00
Fawzi Mohamed 6bfaea84d3 qmldom: remove path
Support to remove a whole path and its sub files/directories.
This is needed by the code model, relying a re-scan of the directory
to removes files is not reliable, as some might have been deleted
in the meantime.

Change-Id: Ia2009bca66a68bd55b3cdf4b07d8323c973ba23a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-09 23:16:36 +01:00
Fawzi Mohamed 9e23d109f3 qmldom: improve handling of memory qmldocuments without paths
* fromCode convenince method to load a file having only a memory
representation
* avoid adding implicit directory import if the directory is not
defined.
* add test for this functionality (used by tests in Design Studio)

Change-Id: I4b5604988a64f59b103c0cf5bf323bd5b5b6a711
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2021-10-07 14:56:13 +02:00
Fawzi Mohamed 42aa1d5102 qmldom: DomItem::makeCopy also for elements of the universe
The universe is the cache where loaded files are stored, so to compare
them immediately after load it is useful that the makeCopy method which
creates a deep copy, works also on files in the files without
environment.

Change-Id: I35fc5a769b422d367d07af3374566997dd6b0153
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-08-27 08:48:37 +02:00
Fawzi Mohamed 52d61e705e qmldom: representation and load of Qml Files
- qqmldomitem: main API for generic access to the Dom
 - qqmldomtop: represent top level elements: DomEnvironment and Universe
 - qqmldomelements: definition of the classes representing Qml
 - qqmldomastcreator: instatiate Dom elements from AST
 - qqmldomcomments: represent comments in Qml
 - qqmldomexternalitems: represent files
 - qqmldommoduleindex: represent types in a module
 - tst_dom_all: combined test running all dom tests

Change-Id: If2320722bc3e6eaab9669ecec6962d5473184f29
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-05 00:06:52 +02:00