aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsscope_p.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-03-31 11:26:09 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-04-05 21:57:19 +0200
commit9c91b35c076b5c7d16fe7499bbe490291d1a6bcf (patch)
treef721f95127677d4d76431d9e12aafb41934bbca6 /src/qmlcompiler/qqmljsscope_p.h
parent3414e8ab16a42c8fd9e7c640a1e4787e4b3cb49c (diff)
Avoid copying QQmlJSScope
The factory should populate the pre-existing scope rather than copy it into place. This way we can detect inheritance cycles involving the pre-existing scope. However, now we may detect the inheritance cycles earlier, when resolving the types inside the lazy loading. We have the right pointers available there now, after all. Therefore, add a way to propagate base type errors out of the factory. When clearing the base type, we can now give a reason for that. When checking the inheritance cycles we retrieve that reason and log it. We also remove the special casing of the ScopeType property of QQmlJSScope. There is no real reason to set it in the ctor. As we delay the population of QQmlJSScope now, we have to set it later. Task-number: QTBUG-102153 Change-Id: I49cf6e20f59fbdb6ed98a82040b3b159676f5975 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit aea732d607dbcc7ba2c86244ca1ab9086bb28ca6)
Diffstat (limited to 'src/qmlcompiler/qqmljsscope_p.h')
-rw-r--r--src/qmlcompiler/qqmljsscope_p.h35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h
index be278a6c7b..475cc50f3f 100644
--- a/src/qmlcompiler/qqmljsscope_p.h
+++ b/src/qmlcompiler/qqmljsscope_p.h
@@ -59,7 +59,6 @@ class QQmlJSImporter;
class QQmlJSScope
{
- Q_DISABLE_COPY(QQmlJSScope)
public:
QQmlJSScope(QQmlJSScope &&) = default;
QQmlJSScope &operator=(QQmlJSScope &&) = default;
@@ -94,7 +93,8 @@ public:
CustomParser = 0x10,
Array = 0x20,
InlineComponent = 0x40,
- WrappedInImplicitComponent = 0x80
+ WrappedInImplicitComponent = 0x80,
+ HasBaseTypeError = 0x100
};
Q_DECLARE_FLAGS(Flags, Flag)
Q_FLAGS(Flags);
@@ -179,8 +179,8 @@ public:
QQmlJS::SourceLocation location;
};
- static QQmlJSScope::Ptr create(ScopeType type = QQmlJSScope::QMLScope,
- const QQmlJSScope::Ptr &parentScope = QQmlJSScope::Ptr());
+ static QQmlJSScope::Ptr create() { return QSharedPointer<QQmlJSScope>(new QQmlJSScope); }
+ static QQmlJSScope::Ptr clone(const QQmlJSScope::ConstPtr &origin);
static QQmlJSScope::ConstPtr findCurrentQMLScope(const QQmlJSScope::ConstPtr &scope);
QQmlJSScope::Ptr parentScope()
@@ -193,6 +193,8 @@ public:
return QQmlJSScope::WeakConstPtr(m_parentScope).toStrongRef();
}
+ static void reparent(const QQmlJSScope::Ptr &parentScope, const QQmlJSScope::Ptr &childScope);
+
void insertJSIdentifier(const QString &name, const JavaScriptIdentifier &identifier);
// inserts property as qml identifier as well as the corresponding
@@ -201,6 +203,7 @@ public:
bool isIdInCurrentScope(const QString &id) const;
ScopeType scopeType() const { return m_scopeType; }
+ void setScopeType(ScopeType type) { m_scopeType = type; }
void addOwnMethod(const QQmlJSMetaMethod &method) { m_methods.insert(method.methodName(), method); }
QMultiHash<QString, QQmlJSMetaMethod> ownMethods() const { return m_methods; }
@@ -256,11 +259,15 @@ public:
// If isComposite(), this is the QML/JS name of the prototype. Otherwise it's the
// relevant base class (in the hierarchy starting from QObject) of a C++ type.
- void setBaseTypeName(const QString &baseTypeName) { m_baseTypeName = baseTypeName; }
- QString baseTypeName() const { return m_baseTypeName; }
+ void setBaseTypeName(const QString &baseTypeName);
+ QString baseTypeName() const;
+
QQmlJSScope::ConstPtr baseType() const { return m_baseType.scope; }
QTypeRevision baseTypeRevision() const { return m_baseType.revision; }
+
void clearBaseType() { m_baseType = {}; }
+ void setBaseTypeError(const QString &baseTypeError);
+ QString baseTypeError() const;
void addOwnProperty(const QQmlJSMetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); }
QHash<QString, QQmlJSMetaProperty> ownProperties() const { return m_properties; }
@@ -460,7 +467,9 @@ public:
bool isInCustomParserParent() const;
private:
- QQmlJSScope(ScopeType type, const QQmlJSScope::Ptr &parentScope = QQmlJSScope::Ptr());
+ QQmlJSScope() = default;
+ QQmlJSScope(const QQmlJSScope &) = default;
+ QQmlJSScope &operator=(const QQmlJSScope &) = default;
static ImportedScope<QQmlJSScope::ConstPtr> findType(
const QString &name, const ContextualTypes &contextualTypes,
@@ -485,7 +494,7 @@ private:
QString m_fileName;
QString m_internalName;
- QString m_baseTypeName;
+ QString m_baseTypeNameOrError;
// We only need the revision for the base type as inheritance is
// the only relation between two types where the revisions matter.
@@ -525,8 +534,6 @@ public:
m_filePath(filePath), m_importer(importer)
{}
- QQmlJSScope create() const;
-
bool isValid() const
{
return !m_filePath.isEmpty() && m_importer != nullptr;
@@ -543,6 +550,14 @@ public:
}
private:
+ friend class QDeferredSharedPointer<QQmlJSScope>;
+ friend class QDeferredSharedPointer<const QQmlJSScope>;
+ friend class QDeferredWeakPointer<QQmlJSScope>;
+ friend class QDeferredWeakPointer<const QQmlJSScope>;
+
+ // Should only be called when lazy-loading the type in a deferred pointer.
+ void populate(const QSharedPointer<QQmlJSScope> &scope) const;
+
QString m_filePath;
QQmlJSImporter *m_importer = nullptr;
bool m_isSingleton = false;