Commit Graph

45 Commits

Author SHA1 Message Date
Marc Mutz 8edbcdbeb4 Mark the module as free of Q_FOREACH, except where it isn't
The density of Q_FOREACH uses is high here, too high for this author,
unfamiliar with this code, to tackle in a short amount of time. But
they're concentrated in just a few TUs, so pick a different strategy:

Mark the whole module with QT_NO_FOREACH, to prevent new uses from
creeping in, and whitelist the affected TUs by #undef'ing
QT_NO_FOREACH locally, at the top of each file. For TUs that are part
of a larger executable, this requires these files to be compiled
separately, so add them to NO_PCH_SOURCES (which implies
NO_UNITY_BUILD_SOURCES, too). Created QTBUG-115808 to keep track of
this.

Task-number: QTBUG-115808
Change-Id: I29c377f939e3d747e3ce72c224c4ee722df7a95d
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-17 18:04:35 +02:00
Marc Mutz c2d490a238 Port from qAsConst() to std::as_const()
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>
2022-10-07 23:38:56 +02: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
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
Fabian Kosmale d7c2c884cf Purge old AST dumper and use the functionality provided by the QML DOM
This reduces the number of AST visitors we need to maintain.

Change-Id: I9b55706092b4b285816fe6680c94116694bd1f05
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-11-13 09:13:00 +01:00
Mitch Curtis e310dadef7 Consolidate test helpers into private libraries
Previously each test would include and build sources from the shared
folder. Now we make those sources a library, build it once, then have
each test link to it instead.

We also take the opportunity to move some helpers that qtquickcontrols2
had added into the quicktestutils library where it makes sense, and
for the helpers that don't make sense to be there, move them into
quickcontrolstestutils.

We add the libraries to src/ so that they are internal modules built as
part of Qt, rather than tests. That way we can use them in a standalone
test outside of qtdeclarative.

Task-number: QTBUG-95621
Pick-to: 6.2
Change-Id: I0a2ab3976fdbff2e4414df7bdc0808f16453b80a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-09-13 21:17:04 +02:00
Ulf Hermann 0472a7a432 Evaluate type assertions in QML
Type assertions actually check whether the expression matches the type,
and return null if it doesn't.

[ChangeLog][QtQml] You can use TypeScript-like type assertions using
"as" now. In contrast to TypeScript, QML's type assertions are enforced
at runtime. If the type doesn't match, null is returned for object
types. Also, type assertions can only cast to object types. There is no
way to create a value type or primitive type reference. As value types
and primitives cannot be polymorphic, this doesn't matter, though.
There are other ways of converting those.

Task-number: QTBUG-93662
Change-Id: I00fce3d4ea7a8c6b4631c580eaf6c113ac485813
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2021-05-26 14:46:39 +02:00
Volker Hilsheimer 832e3ab949 Fix warnings from int type mismatches
Cast explicitly to silence MSVC.

Change-Id: Ib5ba5cfad3f110d0203c46d817cb958445354204
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-27 17:11:57 +02:00
Volker Hilsheimer 8e0b6630b7 Fix warning from signed/unsigned mismatch
Pick-to: 6.1
Change-Id: I6a36118da7e4b1ee0c9b04218901d20760026d98
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-12 10:39:02 +02:00
Volker Hilsheimer 4a77e2593f Mark overrides in tests, fix compiler warnings
Change-Id: If753558d911e50a73e351a93eed2e4df3e6592c7
Reviewed-by: David Skoland <david.skoland@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-01 10:14:16 +02:00
Fawzi Mohamed ac5332091f Ensure that empty tokens in the AST are empty
Arrow functions introduce a virtual functions and return statements to
simplify code generation (arrow function look like normal function
definitions), but to have correct firstSourceLocation /
lastSourcelocation other tokens were reused.
Use an empty SourceLocation at the correct position instead, so code
that expects the correct location (for error messages,...) works and
code that expects the correct token content (rewriter in QtCreator for
example) also works.
Introduce helper SourceLocation::startZeroLengthLocation/
endZeroLengthLocation to simplify such code.

Change-Id: I1c5df16e1704df2df9b7cbd1a039ce56be3727d3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-26 17:48:46 +01:00
Volker Hilsheimer 799495cb7d Add override keyword in tests to silence compiler warnings
Pick-to: 6.1
Change-Id: Ib18e8aa7acf2c5abd68578f4f4405a977d19d286
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2021-03-17 18:20:49 +01:00
Andreas Buhr 7e029878c0 Fix some "can be marked override" warnings
Change-Id: I13da0d085901314950c4fa0afb5853e183652e67
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2021-02-23 16:50:07 +01:00
Karsten Heimrich 1b10ce6a08 Port QtDeclarative from QStringRef to QStringView
Task-number: QTBUG-84319
Change-Id: I2dcfb8a2db98282c7a1acdad1e6f4f949f26df15
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2020-06-16 22:46:16 +02:00
Christian Stenger 0be8c5ae21 Fix lexer line number if code contains continuation strings
Follow-up lines of continuations strings that directly end
with an unescaped line feed still broke the line numbers of
code following the string. Fix by explicitly handling the
first character inside a string differently.
Amends 126ee5c901.

Change-Id: Ia945546d35db844114064ae34d6189704ceefe3b
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2020-06-12 07:57:42 +02:00
Christian Stenger 126ee5c901 Fix line number for follow-up lines in strings
If a string ends with a line terminator follow-up lines had a
wrong line number.

Change-Id: I98a8f69cbc876e07b3fe83490d517bf7771c59b5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-05-01 22:56:34 +02:00
Christian Stenger dc56e57cc5 Fix lexer handling of escape sequences in string
The lexer handled escape sequences inside string literals
wrongly which could led to follow-up problems like wrong
offsets or even lines of tokens.

Change-Id: Ief14dda77f9079931a7d19ea549017a1d59c2d0b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-05-01 20:56:26 +00:00
Ulf Hermann c5b48c735e Also support partly specified versions in JS .imports
Task-number: QTBUG-71278
Change-Id: Ie3167d44780a192b5010052eea5192eee8c21c32
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-18 11:00:31 +01:00
Qt Forward Merge Bot 3e758800b4 Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
	src/imports/qtqml/plugin.cpp
	src/qml/qml/qqml.h
	src/qml/qml/qqmlmetatype.cpp
	src/qml/qml/qqmlmetatype_p.h
	src/qml/qml/qqmltypeloader.cpp
	src/qml/types/qqmlbind.cpp
	src/quick/items/qquickitemsmodule.cpp
	tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

Change-Id: I52548938a582cb6510271ed4bc3a9aa0c3c11df6
2020-02-17 10:21:59 +01:00
Fawzi Mohamed 8791fc19f0 Added AstDumper: better describe and compare AST trees
This is just added to the test sources (via
tests/auto/shared/astdump.pri)

Fixes: QTBUG-81819
Change-Id: Icc70e6f7a6ded9e9957c6d4151f696be34c942e6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-02-12 17:51:29 +01:00
Ulf Hermann e192874c6c Guard against invalid version specifiers in import statements
Check that the version parsed is in the valid range for QTypeRevision
and produce a compile error if not.

Task-number: QTBUG-71278
Change-Id: I9a957a10f4254387f9868a8f3f1e231440bc2cd2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-02-12 15:40:07 +01:00
Fawzi Mohamed a87ad432a0 add annotations to QML
A QML Annotation is a Qml Object declaration prepended with @.
The name of the annotation is restricted to a dot separated list of
non keyword identifiers.
Annotations can be put before an Object definition, or any object
member declaration: bindings, property declarations, function
declarations.
This patch, aside parsing the annotations does absolutely nothing, the
list of annotations is discarded and never touches the AST.

[ChangeLog][QML] Add Qml Annotations

Task-number: QTBUG-81714
Change-Id: I4d79559a0d1fb23acaf482d0ef8f7d106dbf099d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-01-31 14:33:12 +01:00
Ulf Hermann f6e90ba533 Add (and ignore for now) type assertions to QML
You can write "(something as Foo)" to give hints to any tools that you
expect something to be a Foo at this place. This is not a conversion and
ignored at runtime for now. Eventually the compiler will verify that the
type assertions are plausible and error out if they aren't.

Change-Id: I21c8705bb387f7ab2cbc153293dbf477663afe87
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-11-27 18:50:14 +01:00
Ulf Hermann 41bbf7e376 QML: Consider the semicolon as part of expression statements
When asked for lastSourceLocation() we should always return the
semicolon token. In order for that to work, the semicolon token needs to
be valid in all cases. In the case of object literals as expressions for
properties we neither accepted nor synthesized a semicolon as delimiter.
Add an optional semicolon that we can then also use as end of the
expression statement.

Furthermore, this triggered a silent rule conflict for ImportSpecifier, which
for some reason did not arise before:
IdentifierReference could resolve to both ImpordBinding and IdentifierName,
causing ambiguity in the grammar, and ultimately caused parse failues
when parsing an import statement.
This is now resolved by explicitly telling the parser to prefer
shifting.

Initial-patch-by: Ulf Hermann <ulf.hermann@qt.io>
Change-Id: Iaec29c452b577312248a17cb48f005f4fc0bd8c4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-11-18 14:01:44 +01:00
Simon Hausmann a06736cab7 Add basic type annotation support for QML functions to the grammar
Inspired by TypeScript syntax, allow optional type annotations in the
style of ": <name of type>" in for the parameters of functions and their
return type.

These annotations are not used at the moment, so by default we produce
an error message when encountering them in the AST.

In addition their usage is limited to functions declared in the QML
scope. All other uses attempt to produce readable syntax errors. So for
example this is okay:

    Item {
        function blah(param: string) string { ... }
    }

And this is not okay:

    // some file.js
    function blah(param: string) : string { ... }

Change-Id: I12d20b4e2ce92e01108132975a06cfd13ba4a254
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-07-09 16:52:01 +02:00
Fabian Kosmale 9b1f2a7d0e extend grammar for better version parsing support
Be more strict in parsing version numbers
This also makes it easier to access the version number in other places
using the Visitor interface, like (soon) the linter and avoids reparsing
the text twice.

Potential disadvantages: previously allowed import statements will
rejected at parse time, e.g.
import QtQuick 0b10

Potential further advantage: Weird import statements like
import QtQuick 0b10
will be rejected earlier

Change-Id: Ifcd187b79a90952bc964c688afa4ea9b158e5109
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-04 12:41:09 +02:00
Qt Forward Merge Bot 369f3e57b8 Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I59cb196ab17ed8504b33db01d827052eb6891efa
2019-06-06 01:00:05 +02:00
Ulf Hermann 51696d5e8d Parser: Accept templated readonly properties
Change-Id: I37d313e3156a44eb4487b1be007aa93ace18d882
Fixes: QTBUG-76018
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-31 16:30:09 +02:00
Friedemann Kleint 59410dd2f5 Tests: Fix warnings about comparing signed/unsigned
Fix warnings like:
qtestcase.h: In instantiation of 'bool QTest::qCompare(const T1&, const T2&, const char*, const char*, const char*, int) [with T1 = unsigned int; T2 = int]':
tst_qquickrectangle.cpp:137:1559:   required from here
qtestcase.h:423:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Change-Id: I1039e70a2933f196266512a1f5880ee409c1548b
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-04-08 08:39:30 +00:00
Ulf Hermann 73231fe953 Unify the JavaScript parsing recursion checks
We only need to check in one central location and we can allow for more
recursion. 4k recursions seem tolerable. A common default for stack
sizes is 8MB. Each recursion step takes up to 1k stack space in debug
mode. So, exhausting this would burn about half of the available stack
size. We don't report the exact source location in this case as finding
the source location may itself trigger a deep recursion.

Fixes: QTBUG-74087
Change-Id: I43e6e20b322f6035c7136a6f381230ec285c30ae
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-03-15 11:53:22 +00:00
Ulf Hermann 885e4af1f4 QML: Don't crash the parser on certain kinds of bad input
Fixes: QTBUG-72734
Change-Id: I92146ec517c6a26a67e13830618e137f2a3021c2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-02-18 07:24:08 +00:00
Lars Knoll c68dc99c92 Add support for arrow functions
Arrow parameter lists are tricky and require some reparsing
by the standard to avoid conflicts in the parser with
expression statements.

Add an IsArrowFunction flag to the CompiledData::Function. This
information is required in the runtime, when creating Function
objects, as it does influence their behaviour in subtle ways.

Change-Id: I298801b091f98e30a9269d3c77d9ff94e519dabc
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-26 20:26:51 +00:00
Lars Knoll 19d3b7eb4c Don't try to verify the AST after parse errors
In preparation for the ES6 changes, where one or two files
won't parse correctly anymore.

Change-Id: Ie83e684761b2d7dcdec1d44f67006f60fb6e500c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-25 17:50:05 +00:00
Lars Knoll dad5d1cc82 Add support for ES6 template strings
This requires a bit of bookeeping in the lexer, as we can have
arbitrary expressions inside the ${...}. To make this work, keep
a stack of template states, in which we count the unclosed braces
to match up with the correct closing brace.

Implements support for `...`. Expressions of the type Foo`...`
and Foo()`...` will come in follow-up commits.

Change-Id: Ia332796cfb77895583d0093732e6f56c8b0662c9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-25 17:48:56 +00:00
Peter Hartmann 30dbe57521 QQmlComponent: Fix heap buffer overflow with bogus input
Change-Id: I8a725018a5aeb39df370f856cd77d887faa511e3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-05-03 14:49:55 +00:00
Jani Heikkinen 38ec3bd755 Updated license headers
From Qt 5.7 -> tools & applications are lisenced under GPL v3 with some
exceptions, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/

Updated license headers to use new GPL-EXCEPT header instead of LGPL21 one
(in those files which will be under GPL 3 with exceptions)

Change-Id: I04760a0801837cfc516d1c7c02d4f503f6bb70b6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-20 11:46:25 +00:00
Jani Heikkinen c5796292ad Update copyright headers
Qt copyrights are now in The Qt Company, so we could update the source
code headers accordingly. In the same go we should also fix the links to
point to qt.io.

Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9
Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
2015-02-12 10:28:11 +00:00
Jani Heikkinen e7ceacda70 Update license headers and add new licenses
- Renamed LICENSE.LGPL to LICENSE.LGPLv21
- Added LICENSE.LGPLv3 & LICENSE.GPLv2
- Removed LICENSE.GPL

Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0
Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
2014-08-25 11:28:46 +02:00
Erik Verbruggen 0f4617f9fb Remove unused field in test class.
Change-Id: Id9bfbd1c84acb59a669908e933ed1f63a4987526
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-03-19 01:57:45 +01:00
Sergio Ahumada 83deab8d1b Update copyright year in Digia's license headers
Change-Id: I6c3bd7bebe3d62d1cfd0fa6334544c9db8398c76
Reviewed-by: Akseli Salovaara <akseli.salovaara@digia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
2013-01-10 19:52:37 +01:00
Iikka Eklund 46010aa7a2 Change copyrights from Nokia to Digia
Change copyrights and license headers from Nokia to Digia

Change-Id: Ie7f5d49ed8235d7a7845ab68f99ad1c220e64d5c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2012-09-23 08:22:24 +02:00
J-P Nurmi 31d5249ae1 QtQml tests: remove QSKIP -> wrap within !QTEST_CROSS_COMPILED guards
Change-Id: I200bf6feb137e39061f144bdabd825dea70bd539
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2012-09-07 15:55:36 +02:00
Kurt Korbatits 5de103291d Fixed unittests skipping for cross_compile option
- qmlmin, qqmlparser, examples unittests to skip source dependent
  tests when cross_compile option used as content not available.

Change-Id: Ieaadeff0c303f0a633b8a3cc506a764ea995cf42
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2012-03-29 00:35:32 +02:00
Kurt Korbatits 65764c0334 Changed qml tests to work from install directory
- Changed tests to use TESTDATA
- moved qqmlcontext to private test as it contains private header
- added check for cross_compile option to skip when sources not available

Change-Id: I0f68f58ffcb1b41b8e40a9851e3e003fe72ee2f9
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-03-07 06:24:18 +01:00
Matthew Vogt b855240b78 Rename QDeclarative symbols to QQuick and QQml
Symbols beginning with QDeclarative are already exported
by the quick1 module.

Users can apply the bin/rename-qtdeclarative-symbols.sh
script to modify client code using the previous names of the
renamed symbols.

Task-number: QTBUG-23737
Change-Id: Ifaa482663767634931e8711a8e9bf6e404859e66
Reviewed-by: Martin Jones <martin.jones@nokia.com>
2012-02-24 04:51:31 +01:00