diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-03-19 11:41:00 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-04-26 07:13:44 +0200 |
commit | 372db480cda5899148629d8edad76405bc1b98de (patch) | |
tree | b5e3a5269b878439ee09368bd1a4f735387de16a | |
parent | e163a407ce70a66d3fc7b8fdcfaea92e4655d70d (diff) |
QmlCompiler: Add qsizetype and make 64bit integers integral
We don't really want to make 64bit integers integral since converting
them to double is lossy. However, the engine does it, too, and we need
some way to perform arithmetics on qsizetype.
Task-number: QTBUG-122582
Change-Id: Id7f432fb4f98ba675f2c66763f576d994f51444a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 7 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstyperesolver.cpp | 14 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljstyperesolver_p.h | 2 |
3 files changed, 18 insertions, 5 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 376e7e2e60..ce2334b935 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -3972,6 +3972,10 @@ QString QQmlJSCodeGenerator::convertStored( return variable + u".toDouble()"_s; if (m_typeResolver->equals(to, boolType)) return variable + u".toBoolean()"_s; + if (m_typeResolver->equals(to, m_typeResolver->int64Type()) + || m_typeResolver->equals(to, m_typeResolver->uint64Type())) { + return u"%1(%2.toDouble())"_s.arg(to->internalName(), variable); + } if (m_typeResolver->isIntegral(to)) return u"%1(%2.toInteger())"_s.arg(to->internalName(), variable); if (m_typeResolver->equals(to, m_typeResolver->stringType())) @@ -4002,7 +4006,8 @@ QString QQmlJSCodeGenerator::convertStored( || m_typeResolver->equals(from, m_typeResolver->realType()) || m_typeResolver->equals(from, m_typeResolver->stringType())) { return u"QJSPrimitiveValue("_s + variable + u')'; - } else if (m_typeResolver->isSignedInteger(from) + } else if (m_typeResolver->equals(from, m_typeResolver->int16Type()) + || m_typeResolver->equals(from, m_typeResolver->int8Type()) || m_typeResolver->equals(from, m_typeResolver->uint16Type()) || m_typeResolver->equals(from, m_typeResolver->uint8Type())) { return u"QJSPrimitiveValue(int("_s + variable + u"))"_s; diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp index 41198a716b..f136120f75 100644 --- a/src/qmlcompiler/qqmljstyperesolver.cpp +++ b/src/qmlcompiler/qqmljstyperesolver.cpp @@ -68,6 +68,12 @@ QQmlJSTypeResolver::QQmlJSTypeResolver(QQmlJSImporter *importer) m_uint64Type = builtinTypes.type(u"qulonglong"_s).scope; Q_ASSERT(m_uint64Type); + m_sizeType = builtinTypes.type(u"qsizetype"_s).scope; + assertExtension(m_sizeType, "Number"_L1); + + // qsizetype is either a 32bit or a 64bit signed integer. We don't want to special-case it. + Q_ASSERT(m_sizeType == m_int32Type || m_sizeType == m_int64Type); + m_boolType = builtinTypes.type(u"bool"_s).scope; assertExtension(m_boolType, "Boolean"_L1); @@ -356,18 +362,18 @@ bool QQmlJSTypeResolver::isNumeric(const QQmlJSScope::ConstPtr &type) const bool QQmlJSTypeResolver::isSignedInteger(const QQmlJSScope::ConstPtr &type) const { - // Only types of length <= 32bit count as integral return equals(type, m_int8Type) || equals(type, m_int16Type) - || equals(type, m_int32Type); + || equals(type, m_int32Type) + || equals(type, m_int64Type); } bool QQmlJSTypeResolver::isUnsignedInteger(const QQmlJSScope::ConstPtr &type) const { - // Only types of length <= 32bit count as integral return equals(type, m_uint8Type) || equals(type, m_uint16Type) - || equals(type, m_uint32Type); + || equals(type, m_uint32Type) + || equals(type, m_uint64Type); } QQmlJSScope::ConstPtr diff --git a/src/qmlcompiler/qqmljstyperesolver_p.h b/src/qmlcompiler/qqmljstyperesolver_p.h index 4ddc4e468a..e72e7e78f0 100644 --- a/src/qmlcompiler/qqmljstyperesolver_p.h +++ b/src/qmlcompiler/qqmljstyperesolver_p.h @@ -54,6 +54,7 @@ public: QQmlJSScope::ConstPtr uint32Type() const { return m_uint32Type; } QQmlJSScope::ConstPtr int64Type() const { return m_int64Type; } QQmlJSScope::ConstPtr uint64Type() const { return m_uint64Type; } + QQmlJSScope::ConstPtr sizeType() const { return m_sizeType; } QQmlJSScope::ConstPtr boolType() const { return m_boolType; } QQmlJSScope::ConstPtr stringType() const { return m_stringType; } QQmlJSScope::ConstPtr stringListType() const { return m_stringListType; } @@ -255,6 +256,7 @@ protected: QQmlJSScope::ConstPtr m_uint32Type; QQmlJSScope::ConstPtr m_int64Type; QQmlJSScope::ConstPtr m_uint64Type; + QQmlJSScope::ConstPtr m_sizeType; QQmlJSScope::ConstPtr m_boolType; QQmlJSScope::ConstPtr m_stringType; QQmlJSScope::ConstPtr m_stringListType; |