aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-09-30 15:31:43 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-02 15:33:23 +0200
commitb2e1183cb7f4f552bb4409172f82327111f754bb (patch)
treef72311abf4c27dc6dd73acb005f5ceabb074d610 /tools
parent65b6365ffbde369894f7af1ed735ea34a584d357 (diff)
qmllint: Remove member access chains from ScopeTree
What we need there is a proper type inference. This should be added separately. For now, keep the member access chains local in qmllint and don't pollute ScopeTree with them. Change-Id: I9f50aa4e54b285bd93e7bd4cd17797509df0c168 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmllint/checkidentifiers.cpp9
-rw-r--r--tools/qmllint/checkidentifiers.h12
-rw-r--r--tools/qmllint/findwarnings.cpp16
-rw-r--r--tools/qmllint/findwarnings.h2
-rw-r--r--tools/shared/scopetree.cpp12
-rw-r--r--tools/shared/scopetree.h17
6 files changed, 28 insertions, 40 deletions
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 6366cc72ca..c47a3beb36 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -107,7 +107,7 @@ static bool walkViaParentAndAttachedScopes(ScopeTree::ConstPtr rootType,
return false;
}
-bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &members,
+bool CheckIdentifiers::checkMemberAccess(const QVector<FieldMember> &members,
const ScopeTree::ConstPtr &outerScope,
const MetaProperty *prop) const
{
@@ -122,7 +122,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
}
ScopeTree::ConstPtr scope = outerScope;
- for (const ScopeTree::FieldMember &access : members) {
+ for (const FieldMember &access : members) {
if (scope.isNull()) {
writeWarning(m_colorOut);
m_colorOut->write(
@@ -289,6 +289,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
bool CheckIdentifiers::operator()(
const QHash<QString, ScopeTree::ConstPtr> &qmlIDs,
const QHash<QQmlJS::SourceLocation, SignalHandler> &signalHandlers,
+ const MemberAccessChains &memberAccessChains,
const ScopeTree::ConstPtr &root, const QString &rootId) const
{
bool noUnqualifiedIdentifier = true;
@@ -299,8 +300,8 @@ bool CheckIdentifiers::operator()(
while (!workQueue.empty()) {
const ScopeTree::ConstPtr currentScope = workQueue.dequeue();
- const auto memberAccessChains = currentScope->memberAccessChains();
- for (auto memberAccessChain : memberAccessChains) {
+ const auto scopeMemberAccessChains = memberAccessChains[currentScope];
+ for (auto memberAccessChain : scopeMemberAccessChains) {
if (memberAccessChain.isEmpty())
continue;
diff --git a/tools/qmllint/checkidentifiers.h b/tools/qmllint/checkidentifiers.h
index 2056a80f80..f05a227be7 100644
--- a/tools/qmllint/checkidentifiers.h
+++ b/tools/qmllint/checkidentifiers.h
@@ -39,6 +39,15 @@ struct SignalHandler {
bool isMultiline;
};
+struct FieldMember
+{
+ QString m_name;
+ QString m_parentType;
+ QQmlJS::SourceLocation m_location;
+};
+
+using MemberAccessChains = QHash<ScopeTree::ConstPtr, QVector<QVector<FieldMember>>>;
+
class CheckIdentifiers
{
public:
@@ -49,13 +58,14 @@ public:
bool operator ()(const QHash<QString, ScopeTree::ConstPtr> &qmlIDs,
const QHash<QQmlJS::SourceLocation, SignalHandler> &signalHandlers,
+ const MemberAccessChains &memberAccessChains,
const ScopeTree::ConstPtr &root, const QString &rootId) const;
static void printContext(const QString &code, ColorOutput *output,
const QQmlJS::SourceLocation &location);
private:
- bool checkMemberAccess(const QVector<ScopeTree::FieldMember> &members,
+ bool checkMemberAccess(const QVector<FieldMember> &members,
const ScopeTree::ConstPtr &outerScope,
const MetaProperty *prop = nullptr) const;
diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp
index 4ace09756f..e2a5834109 100644
--- a/tools/qmllint/findwarnings.cpp
+++ b/tools/qmllint/findwarnings.cpp
@@ -380,8 +380,8 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiPublicMember *uipm)
bool FindWarningVisitor::visit(QQmlJS::AST::IdentifierExpression *idexp)
{
- auto name = idexp->name;
- m_currentScope->addIdToAccessed(name.toString(), idexp->firstSourceLocation());
+ m_memberAccessChains[m_currentScope].append(
+ {{idexp->name.toString(), QString(), idexp->firstSourceLocation()}});
m_fieldMemberBase = idexp;
return true;
}
@@ -453,7 +453,7 @@ bool FindWarningVisitor::check()
return true;
CheckIdentifiers check(&m_colorOut, m_code, m_rootScopeImports, m_filePath);
- return check(m_qmlid2scope, m_signalHandlers, m_rootScope, m_rootId);
+ return check(m_qmlid2scope, m_signalHandlers, m_memberAccessChains, m_rootScope, m_rootId);
}
bool FindWarningVisitor::visit(QQmlJS::AST::VariableDeclarationList *vdl)
@@ -727,9 +727,13 @@ void FindWarningVisitor::endVisit(QQmlJS::AST::FieldMemberExpression *fieldMembe
type = right->m_type->toString();
}
}
- m_currentScope->accessMember(fieldMember->name.toString(),
- type,
- fieldMember->identifierToken);
+
+
+ auto &chain = m_memberAccessChains[m_currentScope];
+ Q_ASSERT(!chain.last().isEmpty());
+ chain.last().append(FieldMember {
+ fieldMember->name.toString(), type, fieldMember->identifierToken
+ });
m_fieldMemberBase = fieldMember;
} else {
m_fieldMemberBase = nullptr;
diff --git a/tools/qmllint/findwarnings.h b/tools/qmllint/findwarnings.h
index e160e8751c..95d4055cbe 100644
--- a/tools/qmllint/findwarnings.h
+++ b/tools/qmllint/findwarnings.h
@@ -67,6 +67,8 @@ private:
QHash<QQmlJS::SourceLocation, SignalHandler> m_signalHandlers;
QQmlJS::SourceLocation m_pendingSingalHandler;
+ MemberAccessChains m_memberAccessChains;
+
ScopeTree::Ptr m_rootScope;
ScopeTree::Ptr m_currentScope;
QQmlJS::AST::ExpressionNode *m_fieldMemberBase = nullptr;
diff --git a/tools/shared/scopetree.cpp b/tools/shared/scopetree.cpp
index 223dfb92b8..7ebf636b2a 100644
--- a/tools/shared/scopetree.cpp
+++ b/tools/shared/scopetree.cpp
@@ -76,18 +76,6 @@ bool ScopeTree::isIdInCurrentScope(const QString &id) const
return isIdInCurrentQMlScopes(id) || isIdInCurrentJSScopes(id);
}
-void ScopeTree::addIdToAccessed(const QString &id, const QQmlJS::SourceLocation &location) {
- m_memberAccessChains.append(QVector<FieldMember>());
- m_memberAccessChains.last().append(FieldMember {id, QString(), location});
-}
-
-void ScopeTree::accessMember(const QString &name, const QString &parentType,
- const QQmlJS::SourceLocation &location)
-{
- Q_ASSERT(!m_memberAccessChains.last().isEmpty());
- m_memberAccessChains.last().append(FieldMember {name, parentType, location });
-}
-
bool ScopeTree::isIdInCurrentQMlScopes(const QString &id) const
{
if (m_scopeType == ScopeType::QMLScope)
diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h
index 57a346d0d9..1794b45373 100644
--- a/tools/shared/scopetree.h
+++ b/tools/shared/scopetree.h
@@ -129,9 +129,6 @@ public:
void insertPropertyIdentifier(const MetaProperty &prop);
bool isIdInCurrentScope(const QString &id) const;
- void addIdToAccessed(const QString &id, const QQmlJS::SourceLocation &location);
- void accessMember(const QString &name, const QString &parentType,
- const QQmlJS::SourceLocation &location);
ScopeType scopeType() const { return m_scopeType; }
@@ -180,18 +177,6 @@ public:
void setAccessSemantics(AccessSemantics semantics) { m_semantics = semantics; }
AccessSemantics accessSemantics() const { return m_semantics; }
- struct FieldMember
- {
- QString m_name;
- QString m_parentType;
- QQmlJS::SourceLocation m_location;
- };
-
- QVector<QVector<FieldMember>> memberAccessChains() const
- {
- return m_memberAccessChains;
- }
-
bool isIdInCurrentQMlScopes(const QString &id) const;
bool isIdInCurrentJSScopes(const QString &id) const;
bool isIdInjectedFromSignal(const QString &id) const;
@@ -214,8 +199,6 @@ private:
QHash<QString, MetaProperty> m_properties;
QHash<QString, MetaEnum> m_enums;
- QVector<QVector<FieldMember>> m_memberAccessChains;
-
QVector<ScopeTree::Ptr> m_childScopes;
ScopeTree::WeakPtr m_parentScope;