From b3bc19772daae85fe46d875923d3db8a126809f2 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 12 May 2023 13:46:17 +0200 Subject: V4: Discern between named builtins and optimizations for common types The named builtins include void and regexp. The optimizations for other types are useful, but should be a separate enum. Change-Id: I06220cf4a6d3449deca89a26c4f5db0e41d32765 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/qml/common/qv4compileddata_p.h | 89 +++++++++++++++++------------- src/qml/compiler/qqmlirbuilder.cpp | 46 ++++++++-------- src/qml/compiler/qqmlirbuilder_p.h | 2 +- src/qml/jsruntime/qv4function.cpp | 16 +++--- src/qml/jsruntime/qv4qobjectwrapper_p.h | 13 ++--- src/qml/qml/ftw/qbipointer_p.h | 2 + src/qml/qml/qqmlpropertycachecreator.cpp | 72 +++++++++++++++---------- src/qml/qml/qqmlpropertycachecreator_p.h | 31 +++++------ src/qml/qml/qqmlvmemetaobject.cpp | 93 +++++++++++++++++++++----------- src/qml/qml/qqmlvmemetaobject_p.h | 35 +++++++----- 10 files changed, 239 insertions(+), 160 deletions(-) (limited to 'src') diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h index db2b027bf0..3a30938de4 100644 --- a/src/qml/common/qv4compileddata_p.h +++ b/src/qml/common/qv4compileddata_p.h @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE // Also change the comment behind the number to describe the latest change. This has the added // benefit that if another patch changes the version too, it will result in a merge conflict, and // not get removed silently. -#define QV4_DATA_STRUCTURE_VERSION 0x3B // Add isList flag to method parameters and return types +#define QV4_DATA_STRUCTURE_VERSION 0x3C // Restructured builtin type enums class QIODevice; class QQmlTypeNameCache; @@ -268,31 +268,48 @@ struct Block }; static_assert(sizeof(Block) == 12, "Block structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); -enum class BuiltinType : unsigned int { - Var = 0, Int, Bool, Real, String, Url, - Time, Date, DateTime, Rect, Point, Size, - InvalidBuiltin +enum class NamedBuiltin: unsigned int { + Void, Var, Int, Bool, Real, String, Url, DateTime, RegExp +}; + +enum class CommonType : unsigned int { + // Actual named builtins + Void = uint(NamedBuiltin::Void), + Var = uint(NamedBuiltin::Var), + Int = uint(NamedBuiltin::Int), + Bool = uint(NamedBuiltin::Bool), + Real = uint(NamedBuiltin::Real), + String = uint(NamedBuiltin::String), + Url = uint(NamedBuiltin::Url), + DateTime = uint(NamedBuiltin::DateTime), + RegExp = uint(NamedBuiltin::RegExp), + + // Optimization for very common other types + Time, Date, Rect, Point, Size, + + // No type specified or not recognized + Invalid }; struct ParameterType { enum Flag { NoFlag = 0x0, - Builtin = 0x1, + Common = 0x1, List = 0x2, }; Q_DECLARE_FLAGS(Flags, Flag); - void set(Flags flags, quint32 typeNameIndexOrBuiltinType) + void set(Flags flags, quint32 typeNameIndexOrCommonType) { m_data.set(flags.testFlag(List) ? 1 : 0); - m_data.set(flags.testFlag(Builtin) ? 1 : 0); - m_data.set(typeNameIndexOrBuiltinType); + m_data.set(flags.testFlag(Common) ? 1 : 0); + m_data.set(typeNameIndexOrCommonType); } - bool indexIsBuiltinType() const + bool indexIsCommonType() const { - return m_data.get() != 0; + return m_data.get() != 0; } bool isList() const @@ -300,16 +317,16 @@ struct ParameterType return m_data.get() != 0; } - quint32 typeNameIndexOrBuiltinType() const + quint32 typeNameIndexOrCommonType() const { - return m_data.get(); + return m_data.get(); } private: - using IndexIsBuiltinTypeField = quint32_le_bitfield_member<0, 1>; + using IndexIsCommonTypeField = quint32_le_bitfield_member<0, 1>; using IsListField = quint32_le_bitfield_member<1, 1>; - using TypeNameIndexOrBuiltinTypeField = quint32_le_bitfield_member<2, 30>; - quint32_le_bitfield_union m_data; + using TypeNameIndexOrCommonTypeField = quint32_le_bitfield_member<2, 30>; + quint32_le_bitfield_union m_data; }; static_assert(sizeof(ParameterType) == 4, "ParameterType structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); @@ -748,47 +765,47 @@ static_assert(sizeof(Signal) == 12, "Signal structure needs to have the expected struct Property { private: - using BuiltinTypeOrTypeNameIndexField = quint32_le_bitfield_member<0, 28>; + using CommonTypeOrTypeNameIndexField = quint32_le_bitfield_member<0, 28>; using IsRequiredField = quint32_le_bitfield_member<28, 1>; - using IsBuiltinTypeField = quint32_le_bitfield_member<29, 1>; + using IsCommonTypeField = quint32_le_bitfield_member<29, 1>; using IsListField = quint32_le_bitfield_member<30, 1>; using IsReadOnlyField = quint32_le_bitfield_member<31, 1>; public: quint32_le nameIndex; quint32_le_bitfield_union< - BuiltinTypeOrTypeNameIndexField, + CommonTypeOrTypeNameIndexField, IsRequiredField, - IsBuiltinTypeField, + IsCommonTypeField, IsListField, IsReadOnlyField> data; Location location; - void setBuiltinType(BuiltinType t) + void setCommonType(CommonType t) { - data.set(static_cast(t)); - data.set(true); + data.set(static_cast(t)); + data.set(true); } - BuiltinType builtinType() const { - if (data.get() != 0) - return BuiltinType(data.get()); - return BuiltinType::InvalidBuiltin; + CommonType commonType() const { + if (data.get() != 0) + return CommonType(data.get()); + return CommonType::Invalid; } - void setCustomType(int nameIndex) + void setTypeNameIndex(int nameIndex) { - data.set(nameIndex); - data.set(false); + data.set(nameIndex); + data.set(false); } - int customType() const + int typeNameIndex() const { - return data.get() ? -1 : data.get(); + return data.get() ? -1 : data.get(); } - bool isBuiltinType() const { return data.get(); } - uint builtinTypeOrTypeNameIndex() const { return data.get(); } + bool isCommonType() const { return data.get(); } + uint commonTypeOrTypeNameIndex() const { return data.get(); } bool isList() const { return data.get(); } void setIsList(bool isList) { data.set(isList); } @@ -1357,8 +1374,8 @@ struct TypeReferenceMap : QHash auto prop = obj->propertiesBegin(); auto const propEnd = obj->propertiesEnd(); for ( ; prop != propEnd; ++prop) { - if (!prop->isBuiltinType()) { - TypeReference &r = this->add(prop->builtinTypeOrTypeNameIndex(), prop->location); + if (!prop->isCommonType()) { + TypeReference &r = this->add(prop->commonTypeOrTypeNameIndex(), prop->location); r.errorWhenNotFound = true; } } diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 7bca65bb0a..7a1ea6905a 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -59,7 +59,7 @@ bool Parameter::initType( QV4::CompiledData::ParameterType::Flag listFlag) { auto builtinType = stringToBuiltinType(typeName); - if (builtinType == QV4::CompiledData::BuiltinType::InvalidBuiltin) { + if (builtinType == QV4::CompiledData::CommonType::Invalid) { if (typeName.isEmpty()) { paramType->set(listFlag, 0); return false; @@ -68,31 +68,33 @@ bool Parameter::initType( paramType->set(listFlag, typeNameIndex); } else { Q_ASSERT(quint32(builtinType) < (1u << 31)); - paramType->set(listFlag | QV4::CompiledData::ParameterType::Builtin, + paramType->set(listFlag | QV4::CompiledData::ParameterType::Common, static_cast(builtinType)); } return true; } -QV4::CompiledData::BuiltinType Parameter::stringToBuiltinType(const QString &typeName) +QV4::CompiledData::CommonType Parameter::stringToBuiltinType(const QString &typeName) { static const struct TypeNameToType { const char *name; size_t nameLength; - QV4::CompiledData::BuiltinType type; + QV4::CompiledData::CommonType type; } propTypeNameToTypes[] = { - { "int", strlen("int"), QV4::CompiledData::BuiltinType::Int }, - { "bool", strlen("bool"), QV4::CompiledData::BuiltinType::Bool }, - { "double", strlen("double"), QV4::CompiledData::BuiltinType::Real }, - { "real", strlen("real"), QV4::CompiledData::BuiltinType::Real }, - { "string", strlen("string"), QV4::CompiledData::BuiltinType::String }, - { "url", strlen("url"), QV4::CompiledData::BuiltinType::Url }, - { "date", strlen("date"), QV4::CompiledData::BuiltinType::DateTime }, - { "rect", strlen("rect"), QV4::CompiledData::BuiltinType::Rect }, - { "point", strlen("point"), QV4::CompiledData::BuiltinType::Point }, - { "size", strlen("size"), QV4::CompiledData::BuiltinType::Size }, - { "variant", strlen("variant"), QV4::CompiledData::BuiltinType::Var }, - { "var", strlen("var"), QV4::CompiledData::BuiltinType::Var } + { "void", strlen("void"), QV4::CompiledData::CommonType::Void }, + { "int", strlen("int"), QV4::CompiledData::CommonType::Int }, + { "bool", strlen("bool"), QV4::CompiledData::CommonType::Bool }, + { "double", strlen("double"), QV4::CompiledData::CommonType::Real }, + { "real", strlen("real"), QV4::CompiledData::CommonType::Real }, + { "string", strlen("string"), QV4::CompiledData::CommonType::String }, + { "url", strlen("url"), QV4::CompiledData::CommonType::Url }, + { "date", strlen("date"), QV4::CompiledData::CommonType::DateTime }, + { "regexp", strlen("regexp"), QV4::CompiledData::CommonType::RegExp }, + { "rect", strlen("rect"), QV4::CompiledData::CommonType::Rect }, + { "point", strlen("point"), QV4::CompiledData::CommonType::Point }, + { "size", strlen("size"), QV4::CompiledData::CommonType::Size }, + { "variant", strlen("variant"), QV4::CompiledData::CommonType::Var }, + { "var", strlen("var"), QV4::CompiledData::CommonType::Var } }; static const int propTypeNameToTypesCount = sizeof(propTypeNameToTypes) / sizeof(propTypeNameToTypes[0]); @@ -103,7 +105,7 @@ QV4::CompiledData::BuiltinType Parameter::stringToBuiltinType(const QString &typ return t->type; } } - return QV4::CompiledData::BuiltinType::InvalidBuiltin; + return QV4::CompiledData::CommonType::Invalid; } void Object::init(QQmlJS::MemoryPool *pool, int typeNameIndex, int idIndex, @@ -1091,12 +1093,12 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) property->setIsReadOnly(node->isReadonly()); property->setIsRequired(node->isRequired()); - const QV4::CompiledData::BuiltinType builtinPropertyType + const QV4::CompiledData::CommonType builtinPropertyType = Parameter::stringToBuiltinType(memberType); - if (builtinPropertyType != QV4::CompiledData::BuiltinType::InvalidBuiltin) - property->setBuiltinType(builtinPropertyType); + if (builtinPropertyType != QV4::CompiledData::CommonType::Invalid) + property->setCommonType(builtinPropertyType); else - property->setCustomType(registerString(memberType)); + property->setTypeNameIndex(registerString(memberType)); QStringView typeModifier = node->typeModifier; if (typeModifier == QLatin1String("list")) { @@ -1653,7 +1655,7 @@ bool IRBuilder::isStatementNodeScript(QQmlJS::AST::Statement *statement) bool IRBuilder::isRedundantNullInitializerForPropertyDeclaration(Property *property, QQmlJS::AST::Statement *statement) { - if (property->isBuiltinType() || property->isList()) + if (property->isCommonType() || property->isList()) return false; QQmlJS::AST::ExpressionStatement *exprStmt = QQmlJS::AST::cast(statement); if (!exprStmt) diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index 890c7f088a..4b37f48ab9 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -227,7 +227,7 @@ struct Parameter : public QV4::CompiledData::Parameter return initType(type, annotationString, idGenerator(annotationString), Flag::NoFlag); } - static QV4::CompiledData::BuiltinType stringToBuiltinType(const QString &typeName); + static QV4::CompiledData::CommonType stringToBuiltinType(const QString &typeName); private: static bool initType( diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index 1017ef9cd9..c2f23279ba 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -117,8 +117,8 @@ Function::Function(ExecutionEngine *engine, ExecutableCompilationUnit *unit, ic = ic->addMember(engine->identifierTable->asPropertyKey(compilationUnit->runtimeStrings[formalsIndices[i].nameIndex]), Attr_NotConfigurable); if (enforcesSignature && !hasTypes - && formalsIndices[i].type.typeNameIndexOrBuiltinType() - != quint32(QV4::CompiledData::BuiltinType::InvalidBuiltin)) { + && formalsIndices[i].type.typeNameIndexOrCommonType() + != quint32(QV4::CompiledData::CommonType::Invalid)) { hasTypes = true; } } @@ -130,8 +130,8 @@ Function::Function(ExecutionEngine *engine, ExecutableCompilationUnit *unit, return; if (!hasTypes - && compiledFunction->returnType.typeNameIndexOrBuiltinType() - == quint32(QV4::CompiledData::BuiltinType::InvalidBuiltin)) { + && compiledFunction->returnType.typeNameIndexOrCommonType() + == quint32(QV4::CompiledData::CommonType::Invalid)) { return; } @@ -139,14 +139,14 @@ Function::Function(ExecutionEngine *engine, ExecutableCompilationUnit *unit, QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine->qmlEngine()); auto findMetaType = [&](const CompiledData::ParameterType ¶m) { - const quint32 type = param.typeNameIndexOrBuiltinType(); - if (param.indexIsBuiltinType()) { + const quint32 type = param.typeNameIndexOrCommonType(); + if (param.indexIsCommonType()) { if (param.isList()) { return QQmlPropertyCacheCreatorBase::listTypeForPropertyType( - QV4::CompiledData::BuiltinType(type)); + QV4::CompiledData::CommonType(type)); } return QQmlPropertyCacheCreatorBase::metaTypeForPropertyType( - QV4::CompiledData::BuiltinType(type)); + QV4::CompiledData::CommonType(type)); } if (type == 0) diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 3f94cc7798..a161d31838 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -15,16 +15,17 @@ // We mean it. // +#include +#include +#include +#include +#include +#include + #include #include #include #include -#include -#include - -#include -#include -#include QT_BEGIN_NAMESPACE diff --git a/src/qml/qml/ftw/qbipointer_p.h b/src/qml/qml/ftw/qbipointer_p.h index 4039d6b60d..b06b5bbc01 100644 --- a/src/qml/qml/ftw/qbipointer_p.h +++ b/src/qml/qml/ftw/qbipointer_p.h @@ -17,6 +17,8 @@ #include +#include + QT_BEGIN_NAMESPACE namespace QtPrivate { diff --git a/src/qml/qml/qqmlpropertycachecreator.cpp b/src/qml/qml/qqmlpropertycachecreator.cpp index 4bc903c22e..d71a2d0086 100644 --- a/src/qml/qml/qqmlpropertycachecreator.cpp +++ b/src/qml/qml/qqmlpropertycachecreator.cpp @@ -5,47 +5,63 @@ #include +#if QT_CONFIG(regularexpression) +#include +#endif + QT_BEGIN_NAMESPACE QAtomicInt QQmlPropertyCacheCreatorBase::classIndexCounter(0); -QMetaType QQmlPropertyCacheCreatorBase::metaTypeForPropertyType(QV4::CompiledData::BuiltinType type) +QMetaType QQmlPropertyCacheCreatorBase::metaTypeForPropertyType(QV4::CompiledData::CommonType type) { switch (type) { - case QV4::CompiledData::BuiltinType::Var: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Int: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Bool: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Real: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::String: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Url: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Time: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Date: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::DateTime: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Rect: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Point: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::Size: return QMetaType::fromType(); - case QV4::CompiledData::BuiltinType::InvalidBuiltin: break; + case QV4::CompiledData::CommonType::Void: return QMetaType(); + case QV4::CompiledData::CommonType::Var: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Int: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Bool: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Real: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::String: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Url: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Time: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Date: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::DateTime: return QMetaType::fromType(); +#if QT_CONFIG(regularexpression) + case QV4::CompiledData::CommonType::RegExp: return QMetaType::fromType(); +#else + case QV4::CompiledData::CommonType::RegExp: return QMetaType(); +#endif + case QV4::CompiledData::CommonType::Rect: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Point: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Size: return QMetaType::fromType(); + case QV4::CompiledData::CommonType::Invalid: break; }; return QMetaType {}; } -QMetaType QQmlPropertyCacheCreatorBase::listTypeForPropertyType(QV4::CompiledData::BuiltinType type) +QMetaType QQmlPropertyCacheCreatorBase::listTypeForPropertyType(QV4::CompiledData::CommonType type) { switch (type) { - case QV4::CompiledData::BuiltinType::Var: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Int: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Bool: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Real: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::String: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Url: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Time: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Date: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::DateTime: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Rect: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Point: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::Size: return QMetaType::fromType>(); - case QV4::CompiledData::BuiltinType::InvalidBuiltin: break; + case QV4::CompiledData::CommonType::Void: return QMetaType(); + case QV4::CompiledData::CommonType::Var: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Int: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Bool: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Real: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::String: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Url: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Time: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Date: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::DateTime: return QMetaType::fromType>(); +#if QT_CONFIG(regularexpression) + case QV4::CompiledData::CommonType::RegExp: return QMetaType::fromType>(); +#else + case QV4::CompiledData::CommonType::RegExp: return QMetaType(); +#endif + case QV4::CompiledData::CommonType::Rect: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Point: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Size: return QMetaType::fromType>(); + case QV4::CompiledData::CommonType::Invalid: break; }; return QMetaType {}; } diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index 99a64802c1..1dcf169ecc 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -66,8 +66,8 @@ struct QQmlPropertyCacheCreatorBase public: static QAtomicInt Q_AUTOTEST_EXPORT classIndexCounter; - static QMetaType metaTypeForPropertyType(QV4::CompiledData::BuiltinType type); - static QMetaType listTypeForPropertyType(QV4::CompiledData::BuiltinType type); + static QMetaType metaTypeForPropertyType(QV4::CompiledData::CommonType type); + static QMetaType listTypeForPropertyType(QV4::CompiledData::CommonType type); static QByteArray createClassNameTypeByUrl(const QUrl &url); @@ -592,24 +592,25 @@ inline QQmlError QQmlPropertyCacheCreator::createMetaObject( QTypeRevision propertyTypeVersion = QTypeRevision::zero(); QQmlPropertyData::Flags propertyFlags; - const QV4::CompiledData::BuiltinType type = p->builtinType(); + const QV4::CompiledData::CommonType type = p->commonType(); if (p->isList()) propertyFlags.type = QQmlPropertyData::Flags::QListType; - else if (type == QV4::CompiledData::BuiltinType::Var) + else if (type == QV4::CompiledData::CommonType::Var) propertyFlags.type = QQmlPropertyData::Flags::VarPropertyType; - if (type != QV4::CompiledData::BuiltinType::InvalidBuiltin) { + if (type != QV4::CompiledData::CommonType::Invalid) { propertyType = p->isList() ? listTypeForPropertyType(type) : metaTypeForPropertyType(type); } else { - Q_ASSERT(!p->isBuiltinType()); + Q_ASSERT(!p->isCommonType()); QQmlType qmltype; bool selfReference = false; - if (!imports->resolveType(stringAt(p->builtinTypeOrTypeNameIndex()), &qmltype, nullptr, nullptr, - nullptr, QQmlType::AnyRegistrationType, &selfReference)) { + if (!imports->resolveType( + stringAt(p->commonTypeOrTypeNameIndex()), &qmltype, nullptr, nullptr, + nullptr, QQmlType::AnyRegistrationType, &selfReference)) { return qQmlCompileError(p->location, QQmlPropertyCacheCreatorBase::tr("Invalid property type")); } @@ -679,19 +680,19 @@ inline QQmlError QQmlPropertyCacheCreator::createMetaObject( } template -inline QMetaType QQmlPropertyCacheCreator::metaTypeForParameter(const QV4::CompiledData::ParameterType ¶m, - QString *customTypeName) +inline QMetaType QQmlPropertyCacheCreator::metaTypeForParameter( + const QV4::CompiledData::ParameterType ¶m, QString *customTypeName) { - const quint32 typeId = param.typeNameIndexOrBuiltinType(); - if (param.indexIsBuiltinType()) { + const quint32 typeId = param.typeNameIndexOrCommonType(); + if (param.indexIsCommonType()) { // built-in type if (param.isList()) - return listTypeForPropertyType(QV4::CompiledData::BuiltinType(typeId)); - return metaTypeForPropertyType(QV4::CompiledData::BuiltinType(typeId)); + return listTypeForPropertyType(QV4::CompiledData::CommonType(typeId)); + return metaTypeForPropertyType(QV4::CompiledData::CommonType(typeId)); } // lazily resolved type - const QString typeName = stringAt(param.typeNameIndexOrBuiltinType()); + const QString typeName = stringAt(param.typeNameIndexOrCommonType()); if (customTypeName) *customTypeName = typeName; QQmlType qmltype; diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index c625d2fa20..08e89f7e91 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -588,6 +588,22 @@ QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id) const return v->d()->data().value(); } +#if QT_CONFIG(regularexpression) +QRegularExpression QQmlVMEMetaObject::readPropertyAsRegularExpression(int id) const +{ + QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); + if (!md) + return QRegularExpression(); + + QV4::Scope scope(engine); + QV4::ScopedValue sv(scope, *(md->data() + id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data().userType() != QMetaType::QRegularExpression) + return QRegularExpression(); + return v->d()->data().value(); +} +#endif + QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) const { QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); @@ -683,7 +699,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * // if we reach this point, propertyCount must have been > 0, and thus compiledObject != nullptr Q_ASSERT(compiledObject); const QV4::CompiledData::Property &property = compiledObject->propertyTable()[id]; - const QV4::CompiledData::BuiltinType t = property.builtinType(); + const QV4::CompiledData::CommonType t = property.commonType(); // the context can be null if accessing var properties from cpp after re-parenting an item. QQmlEnginePrivate *ep = (ctxt.isNull() || ctxt->engine() == nullptr) @@ -744,40 +760,48 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * } } else { switch (t) { - case QV4::CompiledData::BuiltinType::Int: + case QV4::CompiledData::CommonType::Void: + break; + case QV4::CompiledData::CommonType::Int: *reinterpret_cast(a[0]) = readPropertyAsInt(id); break; - case QV4::CompiledData::BuiltinType::Bool: + case QV4::CompiledData::CommonType::Bool: *reinterpret_cast(a[0]) = readPropertyAsBool(id); break; - case QV4::CompiledData::BuiltinType::Real: + case QV4::CompiledData::CommonType::Real: *reinterpret_cast(a[0]) = readPropertyAsDouble(id); break; - case QV4::CompiledData::BuiltinType::String: + case QV4::CompiledData::CommonType::String: *reinterpret_cast(a[0]) = readPropertyAsString(id); break; - case QV4::CompiledData::BuiltinType::Url: + case QV4::CompiledData::CommonType::Url: *reinterpret_cast(a[0]) = readPropertyAsUrl(id); break; - case QV4::CompiledData::BuiltinType::Date: + case QV4::CompiledData::CommonType::Date: *reinterpret_cast(a[0]) = readPropertyAsDate(id); break; - case QV4::CompiledData::BuiltinType::DateTime: + case QV4::CompiledData::CommonType::DateTime: *reinterpret_cast(a[0]) = readPropertyAsDateTime(id); break; - case QV4::CompiledData::BuiltinType::Rect: + case QV4::CompiledData::CommonType::RegExp: +#if QT_CONFIG(regularexpression) + *reinterpret_cast(a[0]) + = readPropertyAsRegularExpression(id); +#endif + break; + case QV4::CompiledData::CommonType::Rect: *reinterpret_cast(a[0]) = readPropertyAsRectF(id); break; - case QV4::CompiledData::BuiltinType::Size: + case QV4::CompiledData::CommonType::Size: *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); break; - case QV4::CompiledData::BuiltinType::Point: + case QV4::CompiledData::CommonType::Point: *reinterpret_cast(a[0]) = readPropertyAsPointF(id); break; - case QV4::CompiledData::BuiltinType::Time: + case QV4::CompiledData::CommonType::Time: *reinterpret_cast(a[0]) = readPropertyAsTime(id); break; - case QV4::CompiledData::BuiltinType::Var: + case QV4::CompiledData::CommonType::Var: if (ep) { *reinterpret_cast(a[0]) = readPropertyAsVariant(id); } else { @@ -786,7 +810,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * *reinterpret_cast(a[0]) = QVariant(); } break; - case QV4::CompiledData::BuiltinType::InvalidBuiltin: + case QV4::CompiledData::CommonType::Invalid: if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) { QV4::Scope scope(engine); QV4::ScopedValue sv(scope, *(md->data() + id)); @@ -855,55 +879,64 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * } } else { switch (t) { - case QV4::CompiledData::BuiltinType::Int: + case QV4::CompiledData::CommonType::Void: + break; + case QV4::CompiledData::CommonType::Int: needActivate = *reinterpret_cast(a[0]) != readPropertyAsInt(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Bool: + case QV4::CompiledData::CommonType::Bool: needActivate = *reinterpret_cast(a[0]) != readPropertyAsBool(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Real: + case QV4::CompiledData::CommonType::Real: needActivate = *reinterpret_cast(a[0]) != readPropertyAsDouble(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::String: + case QV4::CompiledData::CommonType::String: needActivate = *reinterpret_cast(a[0]) != readPropertyAsString(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Url: + case QV4::CompiledData::CommonType::Url: needActivate = *reinterpret_cast(a[0]) != readPropertyAsUrl(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Date: + case QV4::CompiledData::CommonType::Date: needActivate = *reinterpret_cast(a[0]) != readPropertyAsDate(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::DateTime: + case QV4::CompiledData::CommonType::DateTime: needActivate = *reinterpret_cast(a[0]) != readPropertyAsDateTime(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Rect: + case QV4::CompiledData::CommonType::RegExp: +#if QT_CONFIG(regularexpression) + needActivate = *reinterpret_cast(a[0]) + != readPropertyAsRegularExpression(id); + writeProperty(id, *reinterpret_cast(a[0])); +#endif + break; + case QV4::CompiledData::CommonType::Rect: needActivate = *reinterpret_cast(a[0]) != readPropertyAsRectF(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Size: + case QV4::CompiledData::CommonType::Size: needActivate = *reinterpret_cast(a[0]) != readPropertyAsSizeF(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Point: + case QV4::CompiledData::CommonType::Point: needActivate = *reinterpret_cast(a[0]) != readPropertyAsPointF(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Time: + case QV4::CompiledData::CommonType::Time: needActivate = *reinterpret_cast(a[0]) != readPropertyAsTime(id); writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::Var: + case QV4::CompiledData::CommonType::Var: if (ep) writeProperty(id, *reinterpret_cast(a[0])); break; - case QV4::CompiledData::BuiltinType::InvalidBuiltin: + case QV4::CompiledData::CommonType::Invalid: if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) { QV4::Scope scope(engine); QV4::ScopedValue sv(scope, *(md->data() + id)); @@ -1118,7 +1151,7 @@ QV4::ReturnedValue QQmlVMEMetaObject::method(int index) const QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) const { - Q_ASSERT(compiledObject && compiledObject->propertyTable()[id].builtinType() == QV4::CompiledData::BuiltinType::Var); + Q_ASSERT(compiledObject && compiledObject->propertyTable()[id].commonType() == QV4::CompiledData::CommonType::Var); QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); if (md) @@ -1143,7 +1176,7 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) const void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) { - Q_ASSERT(compiledObject && compiledObject->propertyTable()[id].builtinType() == QV4::CompiledData::BuiltinType::Var); + Q_ASSERT(compiledObject && compiledObject->propertyTable()[id].commonType() == QV4::CompiledData::CommonType::Var); QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); if (!md) @@ -1204,7 +1237,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) { - if (compiledObject && compiledObject->propertyTable()[id].builtinType() == QV4::CompiledData::BuiltinType::Var) { + if (compiledObject && compiledObject->propertyTable()[id].commonType() == QV4::CompiledData::CommonType::Var) { QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); if (!md) return; diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index f679a2483b..afbe77c4de 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -16,23 +16,25 @@ // We mean it. // -#include -#include -#include -#include -#include -#include - -#include - -#include "qqmlguard_p.h" - -#include #include - +#include +#include +#include #include #include -#include + +#include + +#if QT_CONFIG(regularexpression) +#include +#endif + +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE @@ -201,6 +203,11 @@ public: QDate readPropertyAsDate(int id) const; QTime readPropertyAsTime(int id) const; QDateTime readPropertyAsDateTime(int id) const; + +#if QT_CONFIG(regularexpression) + QRegularExpression readPropertyAsRegularExpression(int id) const; +#endif + QRectF readPropertyAsRectF(int id) const; QObject *readPropertyAsQObject(int id) const; QVector > *readPropertyAsList(int id) const; -- cgit v1.2.1