diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-11-19 17:27:09 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-11-28 13:16:01 +0100 |
| commit | 4a563051b0b7edb895780b409bc8895cd7e67def (patch) | |
| tree | c925bb6aef3d4c648e7419832fb97be1c45488c2 /src/qmlcompiler/qqmljsregistercontent.cpp | |
| parent | f2920663dcd35cadcd1dad2f25eed620acedda72 (diff) | |
QmlCompiler: Move type adjustment into QQmlJSRegisterContent
This is the central piece of the refactoring. Instead of re-writing the
QQmlJSScopes on adjustment we now rewrite the QQmlJSRegisterContents.
The main benefit of this is that we can locally link
QQmlJSRegisterContents together without invoking QQmlJSTypeResolver. The
other benefit is that we gain more control over where the re-written
types show up. QQmlJSScope is stored in many places that should really
not be re-written. QQmlJSRegisterContent is only used locally when
analyzing a binding or function. Finally, we can now chain the type
adjustments with other operations on QQmlJSRegisterContents, without
restrictions.
This makes a few methods of QQmlJSTypeResolver obsolete. Those will be
removed in a separate step.
In order to get this right, we need to deviate from the notion that
every read register is either a rename or a conversion. Rather, we must
pass any "as-is" read of a register through that way. We rely on those
to be re-written when the original register is.
Task-number: QTBUG-124670
Change-Id: I0d968dfe495b82d9d9f67d598447bd2ad5bdcd04
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsregistercontent.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljsregistercontent.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljsregistercontent.cpp b/src/qmlcompiler/qqmljsregistercontent.cpp index efb99b17b5..6f4e893ef8 100644 --- a/src/qmlcompiler/qqmljsregistercontent.cpp +++ b/src/qmlcompiler/qqmljsregistercontent.cpp @@ -124,6 +124,9 @@ public: Content m_content; ContentVariant m_variant = ContentVariant::Unknown; + QQmlJSRegisterContent m_original; + QQmlJSRegisterContent m_shadowed; + int resultLookupIndex() const { switch (Kind(m_content.index())) { @@ -136,6 +139,36 @@ public: } } + void setType(const QQmlJSScope::ConstPtr &type) + { + switch (Kind(m_content.index())) { + case Kind::Type: + std::get<std::pair<QQmlJSScope::ConstPtr, int>>(m_content).first = type; + return; + case Kind::Property: + std::get<PropertyLookup>(m_content).property.setType(type); + return; + case Kind::Enum: + std::get<std::pair<QQmlJSMetaEnum, QString>>(m_content).first.setType(type); + return; + case Kind::Method: + std::get<std::pair<QList<QQmlJSMetaMethod>, QQmlJSScope::ConstPtr>>(m_content) + .second = type; + return; + case Kind::ImportNamespace: + std::get<std::pair<uint, QQmlJSScope::ConstPtr>>(m_content).second = type; + return; + case Kind::Conversion: + std::get<ConvertedTypes>(m_content).result = type; + return; + case Kind::MethodCall: + std::get<QQmlJSMetaMethod>(m_content).setReturnType({ type }); + return; + } + + Q_UNREACHABLE_RETURN(); + } + private: friend class QQmlJSRegisterContentPool; @@ -479,6 +512,21 @@ QQmlJSRegisterContent::ContentVariant QQmlJSRegisterContent::variant() const return d ? d->m_variant : Unknown; } +QQmlJSRegisterContent QQmlJSRegisterContent::storage() const +{ + return d ? d->m_storage : QQmlJSRegisterContent(); +} + +QQmlJSRegisterContent QQmlJSRegisterContent::original() const +{ + return d ? d->m_original : QQmlJSRegisterContent(); +} + +QQmlJSRegisterContent QQmlJSRegisterContent::shadowed() const +{ + return d ? d->m_shadowed : QQmlJSRegisterContent(); +} + QQmlJSRegisterContentPool::QQmlJSRegisterContentPool() = default; QQmlJSRegisterContentPool::~QQmlJSRegisterContentPool() = default; @@ -582,6 +630,28 @@ QQmlJSRegisterContent QQmlJSRegisterContentPool::castTo( return result; } +void QQmlJSRegisterContentPool::adjustType( + const QQmlJSRegisterContent &content, const QQmlJSScope::ConstPtr &adjusted) +{ + QQmlJSRegisterContentPrivate *d = content.d; + + Q_ASSERT(d); + Q_ASSERT(d->m_original.isNull()); + d->m_original = clone(d); + d->setType(adjusted); +} + +void QQmlJSRegisterContentPool::generalizeType( + const QQmlJSRegisterContent &content, const QQmlJSScope::ConstPtr &generalized) +{ + QQmlJSRegisterContentPrivate *d = content.d; + + Q_ASSERT(d); + Q_ASSERT(d->m_shadowed.isNull()); + d->m_shadowed = clone(d); + d->setType(generalized); +} + QQmlJSRegisterContentPrivate *QQmlJSRegisterContentPool::clone( const QQmlJSRegisterContentPrivate *from) { |
