From cdbc76360ae4c12b25923a7cb392355a6485fc70 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 27 Feb 2024 19:20:10 -0800 Subject: [PATCH] Bootstrap: remove QVariant I added QT_NO_VARIANT to qconfig-bootstrapped.h to be clearer on what the #ifs are, but there's no testing of that feature outside of QT_BOOTSTRAPPED. Change-Id: I01ec3c774d9943adb903fffd17b7e8ac4340fb89 Reviewed-by: Fabian Kosmale --- src/corelib/global/qconfig-bootstrapped.h | 1 + src/corelib/kernel/qmetatype.cpp | 22 +++++++++------- src/corelib/kernel/qmetatype.h | 29 ++++++++++++++++++--- src/corelib/kernel/qvariant.h | 4 ++- src/corelib/serialization/qjsonarray.cpp | 2 ++ src/corelib/serialization/qjsoncbor.cpp | 8 ++++++ src/corelib/serialization/qjsondocument.cpp | 2 ++ src/corelib/serialization/qjsonobject.cpp | 3 ++- src/corelib/serialization/qjsonvalue.cpp | 4 +++ src/tools/bootstrap/CMakeLists.txt | 1 - 10 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index 681f379ed10..57f4b9eb6a0 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -92,6 +92,7 @@ #define QT_FEATURE_topleveldomain -1 #define QT_NO_TRANSLATION #define QT_FEATURE_translation -1 +#define QT_NO_VARIANT -1 #define QT_NO_COMPRESS diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 3ccff5ae5f8..ae56de118c8 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -21,7 +21,6 @@ #include "qeasingcurve.h" #endif #include "quuid.h" -#include "qvariant.h" #if QT_CONFIG(regularexpression) # include "qregularexpression.h" @@ -1271,8 +1270,11 @@ static constexpr struct : QMetaTypeModuleHelper QMETATYPE_CONVERTER_ASSIGN(QRectF, QRect); QMETATYPE_CONVERTER(QPoint, QPointF, result = source.toPoint(); return true;); QMETATYPE_CONVERTER_ASSIGN(QPointF, QPoint); - #endif +#endif + QMETATYPE_CONVERTER(QStringList, QString, result = QStringList() << source; return true;); + +#ifndef QT_NO_VARIANT QMETATYPE_CONVERTER(QByteArrayList, QVariantList, result.reserve(source.size()); for (const auto &v: source) @@ -1298,7 +1300,6 @@ static constexpr struct : QMetaTypeModuleHelper result.append(QVariant(v)); return true; ); - QMETATYPE_CONVERTER(QStringList, QString, result = QStringList() << source; return true;); QMETATYPE_CONVERTER(QVariantHash, QVariantMap, for (auto it = source.begin(); it != source.end(); ++it) @@ -1310,7 +1311,7 @@ static constexpr struct : QMetaTypeModuleHelper result.insert(it.key(), it.value()); return true; ); - +#endif // !QT_NO_VARIANT #ifndef QT_BOOTSTRAPPED QMETATYPE_CONVERTER_ASSIGN(QCborValue, QString); QMETATYPE_CONVERTER(QString, QCborValue, @@ -2092,7 +2093,6 @@ static bool convertIterableToVariantHash(QMetaType fromType, const void *from, v h.insert(it.key().toString(), it.value()); return true; } -#endif static bool convertIterableToVariantPair(QMetaType fromType, const void *from, void *to) { @@ -2124,7 +2124,6 @@ static bool convertIterableToVariantPair(QMetaType fromType, const void *from, v return true; } -#ifndef QT_BOOTSTRAPPED static bool convertToSequentialIterable(QMetaType fromType, const void *from, void *to) { using namespace QtMetaTypePrivate; @@ -2335,7 +2334,7 @@ static bool convertMetaObject(QMetaType fromType, const void *from, QMetaType to } return false; } -#endif +#endif // !QT_BOOTSTRAPPED /*! \fn bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId) @@ -2392,10 +2391,11 @@ bool QMetaType::convert(QMetaType fromType, const void *from, QMetaType toType, } } +#ifndef QT_BOOTSTRAPPED +# ifndef QT_NO_VARIANT if (toTypeId == QVariantPair && convertIterableToVariantPair(fromType, from, to)) return true; -#ifndef QT_BOOTSTRAPPED // handle iterables if (toTypeId == QVariantList && convertIterableToVariantList(fromType, from, to)) return true; @@ -2405,6 +2405,7 @@ bool QMetaType::convert(QMetaType fromType, const void *from, QMetaType toType, if (toTypeId == QVariantHash && convertIterableToVariantHash(fromType, from, to)) return true; +# endif if (toTypeId == qMetaTypeId()) return convertToSequentialIterable(fromType, from, to); @@ -2588,7 +2589,8 @@ bool QMetaType::canConvert(QMetaType fromType, QMetaType toType) if (toTypeId == qMetaTypeId()) return canConvertToAssociativeIterable(fromType); - +#endif +#ifndef QT_NO_VARIANT if (toTypeId == QVariantList && canConvert(fromType, QMetaType::fromType())) { return true; @@ -2598,11 +2600,11 @@ bool QMetaType::canConvert(QMetaType fromType, QMetaType toType) && canConvert(fromType, QMetaType::fromType())) { return true; } -#endif if (toTypeId == QVariantPair && hasRegisteredConverterFunction( fromType, QMetaType::fromType())) return true; +#endif if (fromType.flags() & IsEnumeration) { if (toTypeId == QString || toTypeId == QByteArray) diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 9c1fdeecdd4..e3ef1474dac 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -92,6 +92,12 @@ inline constexpr int qMetaTypeId(); #else # define QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F) #endif +#ifndef QT_NO_VARIANT +# define QT_FOR_EACH_STATIC_QVARIANT(F) \ + F(QVariant, 41, QVariant) +#else +# define QT_FOR_EACH_STATIC_QVARIANT(F) +#endif #define QT_FOR_EACH_STATIC_CORE_CLASS(F)\ F(QChar, 7, QChar) \ @@ -113,7 +119,7 @@ inline constexpr int qMetaTypeId(); F(QPointF, 26, QPointF) \ QT_FOR_EACH_STATIC_EASINGCURVE(F) \ F(QUuid, 30, QUuid) \ - F(QVariant, 41, QVariant) \ + QT_FOR_EACH_STATIC_QVARIANT(F) \ QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F) \ F(QJsonValue, 45, QJsonValue) \ F(QJsonObject, 46, QJsonObject) \ @@ -128,13 +134,20 @@ inline constexpr int qMetaTypeId(); #define QT_FOR_EACH_STATIC_CORE_POINTER(F)\ F(QObjectStar, 39, QObject*) -#define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\ +#ifndef QT_NO_VARIANT +# define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\ F(QVariantMap, 8, QVariantMap) \ F(QVariantList, 9, QVariantList) \ F(QVariantHash, 28, QVariantHash) \ F(QVariantPair, 58, QVariantPair) \ F(QByteArrayList, 49, QByteArrayList) \ F(QStringList, 11, QStringList) \ + /**/ +#else +# define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\ + F(QByteArrayList, 49, QByteArrayList) \ + F(QStringList, 11, QStringList) +#endif #if QT_CONFIG(shortcut) #define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F)\ @@ -188,12 +201,20 @@ inline constexpr int qMetaTypeId(); F(UInt, -1, uint, "quint32") \ F(LongLong, -1, qlonglong, "qint64") \ F(ULongLong, -1, qulonglong, "quint64") \ + F(QByteArrayList, -1, QByteArrayList, "QList") \ + F(QStringList, -1, QStringList, "QList") \ + QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F) + +#ifndef QT_NO_VARIANT +#define QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F) \ F(QVariantList, -1, QVariantList, "QList") \ F(QVariantMap, -1, QVariantMap, "QMap") \ F(QVariantHash, -1, QVariantHash, "QHash") \ F(QVariantPair, -1, QVariantPair, "QPair") \ - F(QByteArrayList, -1, QByteArrayList, "QList") \ - F(QStringList, -1, QStringList, "QList") \ + /**/ +#else +#define QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F) +#endif #define QT_FOR_EACH_STATIC_TYPE(F)\ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\ diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 9f0edf4233b..d567bcbb7c5 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -796,14 +796,16 @@ template inline T qvariant_cast(QVariant &&v) return t; } +# ifndef QT_NO_VARIANT template<> inline QVariant qvariant_cast(const QVariant &v) { if (v.metaType().id() == QMetaType::QVariant) return *reinterpret_cast(v.constData()); return v; } +# endif -#endif +#endif // QT_MOC #ifndef QT_NO_DEBUG_STREAM #if QT_DEPRECATED_SINCE(6, 0) diff --git a/src/corelib/serialization/qjsonarray.cpp b/src/corelib/serialization/qjsonarray.cpp index 517ac116a6d..2a660680b94 100644 --- a/src/corelib/serialization/qjsonarray.cpp +++ b/src/corelib/serialization/qjsonarray.cpp @@ -211,6 +211,7 @@ QJsonArray QJsonArray::fromStringList(const QStringList &list) return array; } +#ifndef QT_NO_VARIANT /*! Converts the variant list \a list to a QJsonArray. @@ -235,6 +236,7 @@ QVariantList QJsonArray::toVariantList() const { return QCborArray::fromJsonArray(*this).toVariantList(); } +#endif // !QT_NO_VARIANT /*! diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp index ad0e95061c8..da07eca8a7f 100644 --- a/src/corelib/serialization/qjsoncbor.cpp +++ b/src/corelib/serialization/qjsoncbor.cpp @@ -421,11 +421,13 @@ QJsonArray QCborArray::toJsonArray() const return convertToJsonArray(d.data()); } +#ifndef QT_NO_VARIANT QJsonArray QJsonPrivate::Variant::toJsonArray(const QVariantList &list) { const auto cborArray = QCborArray::fromVariantList(list); return convertToJsonArray(cborArray.d.data(), ConversionMode::FromVariantToJson); } +#endif // !QT_NO_VARIANT /*! Recursively converts every \l QCborValue value in this map to JSON using @@ -469,6 +471,7 @@ QJsonObject QCborMap::toJsonObject() const return convertToJsonObject(d.data()); } +#ifndef QT_NO_VARIANT QJsonObject QJsonPrivate::Variant::toJsonObject(const QVariantMap &map) { const auto cborMap = QCborMap::fromVariantMap(map); @@ -578,6 +581,7 @@ QVariant QCborValue::toVariant() const Q_UNREACHABLE_RETURN(QVariant()); } +#endif // !QT_NO_VARIANT /*! Converts the JSON value contained in \a v into its corresponding CBOR value @@ -631,6 +635,7 @@ QCborValue QCborValue::fromJsonValue(const QJsonValue &v) return QCborValue(); } +#ifndef QT_NO_VARIANT static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) { // Handle strings and byte arrays directly, to avoid creating a temporary @@ -831,6 +836,7 @@ QCborArray QCborArray::fromVariantList(const QVariantList &list) appendVariant(a.d.data(), v); return a; } +#endif // !QT_NO_VARIANT /*! Converts all JSON items found in the \a array array to CBOR using @@ -862,6 +868,7 @@ QCborArray QCborArray::fromJsonArray(QJsonArray &&array) noexcept } +#ifndef QT_NO_VARIANT /*! Converts the CBOR values to QVariant using QCborValue::toVariant() and "stringifies" all the CBOR keys in this map, returning the QVariantMap that @@ -958,6 +965,7 @@ QCborMap QCborMap::fromVariantHash(const QVariantHash &hash) } return m; } +#endif // !QT_NO_VARIANT /*! Converts all JSON items found in the \a obj object to CBOR using diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp index ac4ae4876d7..ae0197bd2a4 100644 --- a/src/corelib/serialization/qjsondocument.cpp +++ b/src/corelib/serialization/qjsondocument.cpp @@ -181,6 +181,7 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other) Swaps the document \a other with this. This operation is very fast and never fails. */ +#ifndef QT_NO_VARIANT /*! Creates a QJsonDocument from the QVariant \a variant. @@ -231,6 +232,7 @@ QVariant QJsonDocument::toVariant() const return QJsonArray(container).toVariantList(); return QJsonObject(container).toVariantMap(); } +#endif // !QT_NO_VARIANT /*! \enum QJsonDocument::JsonFormat diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index 77bcba01f8c..fb81599e33a 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -156,7 +156,7 @@ QJsonObject &QJsonObject::operator =(const QJsonObject &other) noexcept = defaul Swaps the object \a other with this. This operation is very fast and never fails. */ - +#ifndef QT_NO_VARIANT /*! Converts the variant map \a map to a QJsonObject. @@ -219,6 +219,7 @@ QVariantHash QJsonObject::toVariantHash() const { return QCborMap::fromJsonObject(*this).toVariantHash(); } +#endif // !QT_NO_VARIANT /*! Returns a list of all keys in this object. diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp index 29da9058f20..2d114b90721 100644 --- a/src/corelib/serialization/qjsonvalue.cpp +++ b/src/corelib/serialization/qjsonvalue.cpp @@ -345,6 +345,7 @@ void QJsonValue::swap(QJsonValue &other) noexcept error cases as e.g. accessing a non existing key in a QJsonObject. */ +#ifndef QT_NO_VARIANT /*! Converts \a variant to a QJsonValue and returns it. @@ -587,6 +588,7 @@ QVariant QJsonValue::toVariant() const error condition, when trying to read an out of bounds value in an array or a non existent key in an object. */ +#endif // !QT_NO_VARIANT /*! Returns the type of the value. @@ -936,10 +938,12 @@ QJsonValueRef &QJsonValueRef::operator =(const QJsonValueRef &ref) return assignToRef(*this, d->valueAt(index), is_object); } +#ifndef QT_NO_VARIANT QVariant QJsonValueConstRef::toVariant() const { return concrete(*this).toVariant(); } +#endif // !QT_NO_VARIANT QJsonArray QJsonValueConstRef::toArray() const { diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt index a3babd89aa8..673c1f70bfb 100644 --- a/src/tools/bootstrap/CMakeLists.txt +++ b/src/tools/bootstrap/CMakeLists.txt @@ -46,7 +46,6 @@ qt_internal_extend_target(Bootstrap ../../corelib/kernel/qmetacontainer.cpp ../../corelib/kernel/qmetatype.cpp ../../corelib/kernel/qsystemerror.cpp - ../../corelib/kernel/qvariant.cpp ../../corelib/plugin/quuid.cpp ../../corelib/serialization/qcborcommon.cpp ../../corelib/serialization/qcborstreamwriter.cpp