diff options
| author | Olivier De Cannière <olivier.decanniere@qt.io> | 2025-03-05 11:16:59 +0100 |
|---|---|---|
| committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2025-03-06 19:23:04 +0100 |
| commit | 321a05e10bb0d1548f49f8dd077cae41ca490e44 (patch) | |
| tree | 77a12d4e262d55232374e541b5bbbeb363079127 /src | |
| parent | 25e1f9b8999d748dc959e29519fa9671487bc346 (diff) | |
QV4: Reserve a bit in CompiledData::Property
The bit is taken from nameIndex. It should have more than enough
capacity with 31 bits. The reserved bit will be used as a flag in
subsequent commits.
A more typed and centrally enforced aproach to the indexes will be
necessary in the future.
Change-Id: Ia7c686affba6d5320e674dd3f32b7c59b6321e22
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/qml/common/qv4compileddata_p.h | 11 | ||||
| -rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 12 | ||||
| -rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 4 | ||||
| -rw-r--r-- | src/qml/qml/qqmlpropertycachecreator_p.h | 6 | ||||
| -rw-r--r-- | src/qml/qml/qqmltypecompiler.cpp | 2 |
5 files changed, 20 insertions, 15 deletions
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h index 95aaf01707..392a52568c 100644 --- a/src/qml/common/qv4compileddata_p.h +++ b/src/qml/common/qv4compileddata_p.h @@ -51,7 +51,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 0x42 // Change metatype computation of AOT-compiled functions +#define QV4_DATA_STRUCTURE_VERSION 0x43 // Reserved bit for to-be-introduced final flag class QIODevice; class QQmlTypeNameCache; @@ -790,14 +790,16 @@ static_assert(sizeof(Signal) == 12, "Signal structure needs to have the expected struct Property { private: + using NameIndexField = quint32_le_bitfield_member<0, 31>; + using ReservedField = quint32_le_bitfield_member<31, 1>; + using CommonTypeOrTypeNameIndexField = quint32_le_bitfield_member<0, 28>; using IsRequiredField = quint32_le_bitfield_member<28, 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<NameIndexField, ReservedField> nameIndexAndReserved; quint32_le_bitfield_union< CommonTypeOrTypeNameIndexField, IsRequiredField, @@ -806,6 +808,9 @@ public: IsReadOnlyField> data; Location location; + quint32 nameIndex() const { return nameIndexAndReserved.get<NameIndexField>(); } + void setNameIndex(int nameIndex) { nameIndexAndReserved.set<NameIndexField>(nameIndex); } + void setCommonType(CommonType t) { data.set<CommonTypeOrTypeNameIndexField>(static_cast<quint32>(t)); diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 0afe8a2eb9..a706285bcf 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -36,7 +36,7 @@ void Object::simplifyRequiredProperties() { if (required.isEmpty()) return; for (auto it = this->propertiesBegin(); it != this->propertiesEnd(); ++it) { - auto requiredIt = required.find(it->nameIndex); + auto requiredIt = required.find(it->nameIndex()); if (requiredIt != required.end()) { it->setIsRequired(true); required.erase(requiredIt); @@ -194,11 +194,11 @@ QString Object::appendProperty(Property *prop, const QString &propertyName, bool target = this; for (Property *p = target->properties->first; p; p = p->next) - if (p->nameIndex == prop->nameIndex) + if (p->nameIndex() == prop->nameIndex()) return tr("Duplicate property name"); for (Alias *a = target->aliases->first; a; a = a->next) - if (a->nameIndex() == prop->nameIndex) + if (a->nameIndex() == prop->nameIndex()) return tr("Property duplicates alias name"); if (propertyName.constData()->isUpper()) @@ -228,7 +228,7 @@ QString Object::appendAlias(Alias *alias, const QString &aliasName, bool isDefau return tr("Duplicate alias name"); const auto aliasSameAsProperty = std::find_if(target->properties->begin(), target->properties->end(), [&alias](const Property &targetProp){ - return targetProp.nameIndex == alias->nameIndex(); + return targetProp.nameIndex() == alias->nameIndex(); }); if (aliasSameAsProperty != target->properties->end()) @@ -1089,7 +1089,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) } const QString propName = name.toString(); - property->nameIndex = registerString(propName); + property->setNameIndex(registerString(propName)); QQmlJS::SourceLocation loc = node->firstSourceLocation(); property->location.set(loc.startLine, loc.startColumn); @@ -1116,7 +1116,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) QQmlJS::AST::Node::accept(node->binding, this); } else if (node->statement) { if (!isRedundantNullInitializerForPropertyDeclaration(_propertyDeclaration, node->statement)) - appendBinding(node->identifierToken, node->identifierToken, _propertyDeclaration->nameIndex, node->statement, node); + appendBinding(node->identifierToken, node->identifierToken, _propertyDeclaration->nameIndex(), node->statement, node); } qSwap(_propertyDeclaration, property); } diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 908b112c36..6a082dbbf6 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -1716,7 +1716,7 @@ bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QObject * const QV4::CompiledData::Property* property = _compiledObject->propertiesBegin() + propertyIndex; const 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)); + auto postHocIt = postHocRequired.isEmpty() ? postHocRequired.end() : postHocRequired.find(stringAt(property->nameIndex())); if (!property->isRequired() && postHocRequired.end() == postHocIt) continue; if (postHocIt != postHocRequired.end()) @@ -1724,7 +1724,7 @@ bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QObject * if (isContextObject) sharedState->hadTopLevelRequiredProperties = true; sharedState->requiredProperties.insert({_qobject, propertyData}, - RequiredPropertyInfo {compilationUnit->stringAt(property->nameIndex), compilationUnit->finalUrl(), property->location, {}}); + RequiredPropertyInfo {compilationUnit->stringAt(property->nameIndex()), compilationUnit->finalUrl(), property->location, {}}); } diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h index a8f861c515..319816591d 100644 --- a/src/qml/qml/qqmlpropertycachecreator_p.h +++ b/src/qml/qml/qqmlpropertycachecreator_p.h @@ -524,7 +524,7 @@ inline QQmlError QQmlPropertyCacheCreator<ObjectContainer>::createMetaObject( auto pend = obj->propertiesEnd(); for ( ; p != pend; ++p) { bool notInRevision = false; - const QQmlPropertyData *d = resolver.property(stringAt(p->nameIndex), ¬InRevision); + const QQmlPropertyData *d = resolver.property(stringAt(p->nameIndex()), ¬InRevision); if (d && d->isFinal()) return qQmlCompileError(p->location, QQmlPropertyCacheCreatorBase::tr("Cannot override FINAL property")); } @@ -584,7 +584,7 @@ inline QQmlError QQmlPropertyCacheCreator<ObjectContainer>::createMetaObject( auto flags = QQmlPropertyData::defaultSignalFlags(); const QString changedSigName = - QQmlSignalNames::propertyNameToChangedSignalName(stringAt(p->nameIndex)); + QQmlSignalNames::propertyNameToChangedSignalName(stringAt(p->nameIndex())); seenSignals[changedSigName] = AllowOverride::No; cache->appendSignal(changedSigName, flags, effectiveMethodIndex++); @@ -797,7 +797,7 @@ inline QQmlError QQmlPropertyCacheCreator<ObjectContainer>::createMetaObject( propertyFlags.setIsWritable(true); - QString propertyName = stringAt(p->nameIndex); + QString propertyName = stringAt(p->nameIndex()); if (!obj->hasAliasAsDefaultProperty() && propertyIdx == obj->indexOfDefaultPropertyOrAlias) cache->_defaultPropertyName = propertyName; cache->appendProperty(propertyName, propertyFlags, effectivePropertyIndex++, diff --git a/src/qml/qml/qqmltypecompiler.cpp b/src/qml/qml/qqmltypecompiler.cpp index a20eb4a890..2de47b7d3e 100644 --- a/src/qml/qml/qqmltypecompiler.cpp +++ b/src/qml/qml/qqmltypecompiler.cpp @@ -404,7 +404,7 @@ bool SignalHandlerResolver::resolveSignalHandlerExpressions( } for (const QmlIR::Property *property = obj->firstProperty(); property; property = property->next) { - const QString propName = stringAt(property->nameIndex); + const QString propName = stringAt(property->nameIndex()); customSignals.insert(propName, QStringList()); } } |
