aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data/mathStaticProperties.qml
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2024-04-16 14:36:01 +0200
committerLuca Di Sera <luca.disera@qt.io>2024-04-18 22:30:24 +0200
commitbd6df61c81cbb419514fee0c9fdcfe50b5fca98b (patch)
tree466c7bb7169360b3bc4caf1de2b8b862f439d6d1 /tests/auto/qml/qmlcppcodegen/data/mathStaticProperties.qml
parent217dae934785afb9d754bfe92933111809ab0f24 (diff)
qmlsc: Support Math static properties
The javascript Math object presents some static properties that allow access to some general mathematical constants. Currently, `qmlsc` will refuse to generate optimized code for those properties when used in a binding, for example given: ``` import QtQuick Window { width: 200 * Math.PI } ``` `qmlsc` will report a warning and will not generate code for the "width" binding. To allow `qmlsc` to generate optimized code for such cases, the handling of `Math` related properties lookups is now specialized. `QQmlJSTypePropagator::propagatePropertyLookup`, which is called when dealing with an access such as `Math.PI`, was modified to consider the result type a "double" when dealing with properties on the `Math` object. `QQmlJSCodeGenerator::generate_GetLookupHelper`, which generates the code that provides a value for the property access, was modified to special case lookups on the `Math` object. If a property is being looked up on the `Math` object, `qmlsc` will now generate a direct assignment for the output variable to a constant value that is suitable for the accessed property. A test was added to ensure that the snippet from the bug-report now compiles without warnings. A test was added to ensure that the properties from the Math global object have an approximately correct value. Fixes: QTBUG-113150 Change-Id: I8903794fc8ce2b55532a4706e1bda07a7b73f311 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/data/mathStaticProperties.qml')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/mathStaticProperties.qml17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/mathStaticProperties.qml b/tests/auto/qml/qmlcppcodegen/data/mathStaticProperties.qml
new file mode 100644
index 0000000000..fad74a28bd
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/mathStaticProperties.qml
@@ -0,0 +1,17 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+pragma Strict
+
+import QML
+
+QtObject {
+ property double e: Math.E
+ property double ln10: Math.LN10
+ property double ln2: Math.LN2
+ property double log10e: Math.LOG10E
+ property double log2e: Math.LOG2E
+ property double pi: Math.PI
+ property double sqrt1_2: Math.SQRT1_2
+ property double sqrt2: Math.SQRT2
+}