diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-12-03 15:17:34 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-12-03 15:36:22 +0100 |
commit | 5e491b77b91f835801d6520f3c5c4ecbb33ef9e5 (patch) | |
tree | c21847f7dc13c97ba1a7c969250a21de7f56aa84 /src/qmlcompiler/qqmljsscope_p.h | |
parent | 7a4ac2060f878cf1b48e88d901c671523cbe06e9 (diff) |
QmlCompiler: Make QQmlJSScope const-correct
You should not be able to retrieve a non-const parent or child scope
from a const scope. That defeats the whole point of keeping the scopes
const after loading.
Change-Id: If3734c65ee902c32939a54a67193d5f6276cd016
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsscope_p.h')
-rw-r--r-- | src/qmlcompiler/qqmljsscope_p.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h index 711d24c7aa..f0833a18a0 100644 --- a/src/qmlcompiler/qqmljsscope_p.h +++ b/src/qmlcompiler/qqmljsscope_p.h @@ -148,7 +148,15 @@ public: const QQmlJSScope::Ptr &parentScope = QQmlJSScope::Ptr()); static QQmlJSScope::ConstPtr findCurrentQMLScope(const QQmlJSScope::ConstPtr &scope); - QQmlJSScope::Ptr parentScope() const { return m_parentScope.toStrongRef(); } + QQmlJSScope::Ptr parentScope() + { + return m_parentScope.toStrongRef(); + } + + QQmlJSScope::ConstPtr parentScope() const + { + return QQmlJSScope::WeakConstPtr(m_parentScope).toStrongRef(); + } void insertJSIdentifier(const QString &name, const JavaScriptIdentifier &identifier); @@ -232,11 +240,20 @@ public: std::optional<JavaScriptIdentifier> findJSIdentifier(const QString &id) const; - QVector<QQmlJSScope::Ptr> childScopes() const + QVector<QQmlJSScope::Ptr> childScopes() { return m_childScopes; } + QVector<QQmlJSScope::ConstPtr> childScopes() const + { + QVector<QQmlJSScope::ConstPtr> result; + result.reserve(m_childScopes.size()); + for (const auto &child : m_childScopes) + result.append(child); + return result; + } + void resolveTypes(const QHash<QString, ConstPtr> &contextualTypes); void resolveGroupedScopes(); |