aboutsummaryrefslogtreecommitdiffstats
path: root/tools/shared/scopetree.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-03-31 15:46:20 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-04-01 10:29:29 +0200
commiteb5aa8d9c18535ecd0aacc42fe3af954faf01c04 (patch)
treeee76e6358c9ae18fcdce6a6ae4fead3173ea6780 /tools/shared/scopetree.h
parenta88e5c1711bbef1af00ca9a9e0db71b8a24223aa (diff)
qmllint: Consistently use shared pointers for ScopeTree
ScopeTree keeps a weak pointer to its parent scope and strong shared pointers to its children. Avoid passing bare pointers around, so that we cannot create multiple shared pointers independently from the same bare pointer. Change-Id: Id0faece550b1878363004d843a8fa5c1164794ae Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/shared/scopetree.h')
-rw-r--r--tools/shared/scopetree.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h
index f28f2fa841..90f772ab98 100644
--- a/tools/shared/scopetree.h
+++ b/tools/shared/scopetree.h
@@ -67,7 +67,9 @@ class ScopeTree
Q_DISABLE_COPY_MOVE(ScopeTree)
public:
using Ptr = QSharedPointer<ScopeTree>;
+ using WeakPtr = QWeakPointer<ScopeTree>;
using ConstPtr = QSharedPointer<const ScopeTree>;
+ using WeakConstPtr = QWeakPointer<const ScopeTree>;
class Export {
public:
@@ -93,11 +95,11 @@ public:
int m_metaObjectRevision = 0;
};
- ScopeTree(ScopeType type, QString name = QString(),
- ScopeTree *parentScope = nullptr);
+ static ScopeTree::Ptr create(ScopeType type = ScopeType::QMLScope, const QString &name = QString(),
+ const ScopeTree::Ptr &parentScope = ScopeTree::Ptr());
+ static ScopeTree::ConstPtr findCurrentQMLScope(const ScopeTree::ConstPtr &scope);
- ScopeTree::Ptr createNewChildScope(ScopeType type, const QString &name);
- ScopeTree *parentScope() const { return m_parentScope; }
+ ScopeTree::Ptr parentScope() const { return m_parentScope.toStrongRef(); }
void insertJSIdentifier(const QString &id, ScopeType scope);
void insertSignalIdentifier(const QString &id, const MetaMethod &method,
@@ -139,7 +141,7 @@ public:
void addProperty(const MetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); }
QHash<QString, MetaProperty> properties() const { return m_properties; }
- void updateParentProperty(const ScopeTree *scope);
+ void updateParentProperty(const ScopeTree::ConstPtr &scope);
QString defaultPropertyName() const { return m_defaultPropertyName; }
void setDefaultPropertyName(const QString &name) { m_defaultPropertyName = name; }
@@ -174,7 +176,6 @@ public:
bool isIdInCurrentQMlScopes(const QString &id) const;
bool isIdInCurrentJSScopes(const QString &id) const;
bool isIdInjectedFromSignal(const QString &id) const;
- const ScopeTree *currentQMLScope() const;
QVector<ScopeTree::Ptr> childScopes() const
{
@@ -187,6 +188,8 @@ public:
}
private:
+ ScopeTree(ScopeType type, const QString &name = QString(),
+ const ScopeTree::Ptr &parentScope = ScopeTree::Ptr());
QSet<QString> m_jsIdentifiers;
QMultiHash<QString, MethodUsage> m_injectedSignalIdentifiers;
@@ -199,7 +202,7 @@ private:
QVector<QPair<QString, QQmlJS::SourceLocation>> m_unmatchedSignalHandlers;
QVector<ScopeTree::Ptr> m_childScopes;
- ScopeTree *m_parentScope;
+ ScopeTree::WeakPtr m_parentScope;
QString m_fileName;
QString m_name;