diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-04 16:14:29 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-17 11:15:34 +0200 |
commit | da06d6ca852254c4e24b6e69923f5d9dd4b87c8d (patch) | |
tree | 79755ec59220a8a295c61cbf23ec8b7edb6e3ee2 | |
parent | c4c06953a7382033aee55ee1db2bdeb43d6532c8 (diff) |
QML: Port QV4::CompiledData::Property to new special integer bitfield
Task-number: QTBUG-99545
Change-Id: I46f9151536ba09417d117d690d7347bd91c13e75
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit 6be0db416b867d432a826556dfc00929ecd77aba)
-rw-r--r-- | src/qml/common/qv4compileddata_p.h | 54 | ||||
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 14 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertycachecreator_p.h | 12 | ||||
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject.cpp | 4 |
5 files changed, 53 insertions, 33 deletions
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h index 97b4d8466d..0ce4532cab 100644 --- a/src/qml/common/qv4compileddata_p.h +++ b/src/qml/common/qv4compileddata_p.h @@ -726,37 +726,57 @@ static_assert(sizeof(Signal) == 12, "Signal structure needs to have the expected struct Property { - quint32_le nameIndex; - union { - quint32_le_bitfield<0, 28> builtinTypeOrTypeNameIndex; - quint32_le_bitfield<28, 1> isRequired; - quint32_le_bitfield<29, 1> isBuiltinType; - quint32_le_bitfield<30, 1> isList; - quint32_le_bitfield<31, 1> isReadOnly; - }; +private: + using BuiltinTypeOrTypeNameIndexField = quint32_le_bitfield_member<0, 28>; + using IsRequiredField = quint32_le_bitfield_member<28, 1>; + using IsBuiltinTypeField = 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, + IsRequiredField, + IsBuiltinTypeField, + IsListField, + IsReadOnlyField> data; Location location; void setBuiltinType(BuiltinType t) { - builtinTypeOrTypeNameIndex = static_cast<quint32>(t); - isBuiltinType = true; + data.set<BuiltinTypeOrTypeNameIndexField>(static_cast<quint32>(t)); + data.set<IsBuiltinTypeField>(true); } + BuiltinType builtinType() const { - if (isBuiltinType) - return static_cast<BuiltinType>(quint32(builtinTypeOrTypeNameIndex)); + if (data.get<IsBuiltinTypeField>() != 0) + return BuiltinType(data.get<BuiltinTypeOrTypeNameIndexField>()); return BuiltinType::InvalidBuiltin; } + void setCustomType(int nameIndex) { - builtinTypeOrTypeNameIndex = nameIndex; - isBuiltinType = false; + data.set<BuiltinTypeOrTypeNameIndexField>(nameIndex); + data.set<IsBuiltinTypeField>(false); } int customType() const { - return isBuiltinType ? -1 : builtinTypeOrTypeNameIndex; + return data.get<IsBuiltinTypeField>() ? -1 : data.get<BuiltinTypeOrTypeNameIndexField>(); } + + bool isBuiltinType() const { return data.get<IsBuiltinTypeField>(); } + uint builtinTypeOrTypeNameIndex() const { return data.get<BuiltinTypeOrTypeNameIndexField>(); } + + bool isList() const { return data.get<IsListField>(); } + void setIsList(bool isList) { data.set<IsListField>(isList); } + + bool isRequired() const { return data.get<IsRequiredField>(); } + void setIsRequired(bool isRequired) { data.set<IsRequiredField>(isRequired); } + + bool isReadOnly() const { return data.get<IsReadOnlyField>(); } + void setIsReadOnly(bool isReadOnly) { data.set<IsReadOnlyField>(isReadOnly); } }; static_assert(sizeof(Property) == 12, "Property structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); @@ -1302,8 +1322,8 @@ struct TypeReferenceMap : QHash<int, TypeReference> 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->isBuiltinType()) { + TypeReference &r = this->add(prop->builtinTypeOrTypeNameIndex(), prop->location); r.errorWhenNotFound = true; } } diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index ed5f3032d5..5ab7ffd3ff 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -76,7 +76,7 @@ void Object::simplifyRequiredProperties() { for (auto it = this->propertiesBegin(); it != this->propertiesEnd(); ++it) { auto requiredIt = required.find(it->nameIndex); if (requiredIt != required.end()) { - it->isRequired = true; + it->setIsRequired(true); required.erase(requiredIt); } } @@ -986,8 +986,8 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) const QStringView &name = node->name; Property *property = New<Property>(); - property->isReadOnly = node->isReadonly(); - property->isRequired = node->isRequired(); + property->setIsReadOnly(node->isReadonly()); + property->setIsRequired(node->isRequired()); QV4::CompiledData::BuiltinType builtinPropertyType = Parameter::stringToBuiltinType(memberType); bool typeFound = builtinPropertyType != QV4::CompiledData::BuiltinType::InvalidBuiltin; @@ -999,7 +999,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) property->setCustomType(registerString(memberType)); if (typeModifier == QLatin1String("list")) { - property->isList = true; + property->setIsList(true); } else if (!typeModifier.isEmpty()) { recordError(node->typeModifierToken, QCoreApplication::translate("QQmlParser","Invalid property type modifier")); return false; @@ -1141,7 +1141,7 @@ void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST binding->valueLocation.line = loc.startLine; binding->valueLocation.column = loc.startColumn; binding->setType(QV4::CompiledData::Binding::Type_Invalid); - if (_propertyDeclaration && _propertyDeclaration->isReadOnly) + if (_propertyDeclaration && _propertyDeclaration->isReadOnly()) binding->setFlag(QV4::CompiledData::Binding::InitializerForReadOnlyDeclaration); QQmlJS::AST::ExpressionStatement *exprStmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(statement); @@ -1284,7 +1284,7 @@ void IRBuilder::appendBinding(const QQmlJS::SourceLocation &qualifiedNameLocatio binding->clearFlags(); - if (_propertyDeclaration && _propertyDeclaration->isReadOnly) + if (_propertyDeclaration && _propertyDeclaration->isReadOnly()) binding->setFlag(Binding::InitializerForReadOnlyDeclaration); // No type name on the initializer means it must be a group property @@ -1547,7 +1547,7 @@ bool IRBuilder::isStatementNodeScript(QQmlJS::AST::Statement *statement) bool IRBuilder::isRedundantNullInitializerForPropertyDeclaration(Property *property, QQmlJS::AST::Statement *statement) { - if (property->isBuiltinType || property->isList) + if (property->isBuiltinType() || property->isList()) return false; QQmlJS::AST::ExpressionStatement *exprStmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(statement); if (!exprStmt) diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index cb7c15c678..5ced4bcbd5 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -1556,7 +1556,7 @@ bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QObject * QQmlPropertyData *propertyData = _propertyCache->property(_propertyCache->propertyOffset() + propertyIndex); // only compute stringAt if there's a chance for the lookup to succeed auto postHocIt = postHocRequired.isEmpty() ? postHocRequired.end() : postHocRequired.find(stringAt(property->nameIndex)); - if (!property->isRequired && postHocRequired.end() == postHocIt) + if (!property->isRequired() && postHocRequired.end() == postHocIt) continue; if (postHocIt != postHocRequired.end()) postHocRequired.erase(postHocIt); diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index 044c01f203..7f4fae95aa 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -658,11 +658,11 @@ inline QQmlError QQmlPropertyCacheCreator<ObjectContainer>::createMetaObject(int if (type != QV4::CompiledData::BuiltinType::InvalidBuiltin) { propertyType = metaTypeForPropertyType(type); } else { - Q_ASSERT(!p->isBuiltinType); + Q_ASSERT(!p->isBuiltinType()); QQmlType qmltype; bool selfReference = false; - if (!imports->resolveType(stringAt(p->builtinTypeOrTypeNameIndex), &qmltype, nullptr, nullptr, + if (!imports->resolveType(stringAt(p->builtinTypeOrTypeNameIndex()), &qmltype, nullptr, nullptr, nullptr, QQmlType::AnyRegistrationType, &selfReference)) { return qQmlCompileError(p->location, QQmlPropertyCacheCreatorBase::tr("Invalid property type")); } @@ -694,13 +694,13 @@ inline QQmlError QQmlPropertyCacheCreator<ObjectContainer>::createMetaObject(int typeIds = compilationUnit->typeIdsForComponent(); } - if (p->isList) { + if (p->isList()) { propertyType = typeIds.listId; } else { propertyType = typeIds.id; } } else { - if (p->isList) { + if (p->isList()) { propertyType = qmltype.qListTypeId(); } else { propertyType = qmltype.typeId(); @@ -708,13 +708,13 @@ inline QQmlError QQmlPropertyCacheCreator<ObjectContainer>::createMetaObject(int } } - if (p->isList) + if (p->isList()) propertyFlags.type = QQmlPropertyData::Flags::QListType; else propertyFlags.type = QQmlPropertyData::Flags::QObjectDerivedType; } - if (!p->isReadOnly && !p->isList) + if (!p->isReadOnly() && !p->isList()) propertyFlags.setIsWritable(true); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 9988294f29..39c9e9037b 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -760,7 +760,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * } break; case QV4::CompiledData::BuiltinType::InvalidBuiltin: - if (property.isList) { + if (property.isList()) { // when reading from the list, we need to find the correct MetaObject, // namely this. However, obejct->metaObject might point to any MetaObject // down the inheritance hierarchy, so we need to store how far we have @@ -866,7 +866,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * writeProperty(id, *reinterpret_cast<QVariant *>(a[0])); break; case QV4::CompiledData::BuiltinType::InvalidBuiltin: - if (property.isList) { + if (property.isList()) { // Writing such a property is not supported. Content is added through the list property // methods. } else { |