From ed8127cf41951a9ff1d6032c2158e49fdebe51c3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 21 Oct 2020 16:06:20 +0200 Subject: QmlCompiler: Introduce grouped scopes This way we can analyze the left hand part of things like "anchors.fill: parent" in qmllint. Change-Id: I0f58312566c3d5062e0fb301c2bad908ab8b8cbb Reviewed-by: Fabian Kosmale --- tools/qmllint/findwarnings.cpp | 33 +++++++++++++++++++++++++++++++++ tools/qmllint/findwarnings.h | 2 ++ 2 files changed, 35 insertions(+) (limited to 'tools') diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 06e647dcd5..d7880b0506 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -90,6 +90,28 @@ void FindWarningVisitor::checkInheritanceCycle(QQmlJSScope::ConstPtr scope) } } +void FindWarningVisitor::checkGroupedScopes(QQmlJSScope::ConstPtr scope) +{ + auto children = scope->childScopes(); + while (!children.isEmpty()) { + auto childScope = children.takeFirst(); + if (childScope->scopeType() != QQmlJSScope::GroupedPropertyScope) + continue; + + if (!childScope->baseType()) { + m_errors.append({ + QStringLiteral("unknown grouped property scope %1.") + .arg(childScope->internalName()), + QtWarningMsg, + childScope->sourceLocation() + }); + m_visitFailed = true; + } + + children.append(childScope->childScopes()); + } +} + void FindWarningVisitor::flushPendingSignalParameters() { const SignalHandler handler = m_signalHandlers[m_pendingSingalHandler]; @@ -349,6 +371,14 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob) return true; } +void FindWarningVisitor::endVisit(QQmlJS::AST::UiObjectBinding *uiob) +{ + QQmlJSImportVisitor::endVisit(uiob); + + if (m_warnUnqualified) + checkGroupedScopes(m_currentScope); +} + bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectDefinition *uiod) { using namespace QQmlJS::AST; @@ -433,6 +463,9 @@ void FindWarningVisitor::endVisit(QQmlJS::AST::UiObjectDefinition *uiod) auto childScope = m_currentScope; QQmlJSImportVisitor::endVisit(uiod); + if (m_warnUnqualified) + checkGroupedScopes(childScope); + if (m_currentScope == m_globalScope || m_currentScope->baseTypeName() == QStringLiteral("Component")) { return; diff --git a/tools/qmllint/findwarnings.h b/tools/qmllint/findwarnings.h index 7ce8b569e8..96cd0c3897 100644 --- a/tools/qmllint/findwarnings.h +++ b/tools/qmllint/findwarnings.h @@ -91,6 +91,7 @@ private: QVarLengthArray m_outstandingConnections; // Connections whose target we have not encountered void checkInheritanceCycle(QQmlJSScope::ConstPtr scope); + void checkGroupedScopes(QQmlJSScope::ConstPtr scope); void flushPendingSignalParameters(); void throwRecursionDepthError() override; @@ -108,6 +109,7 @@ private: /* --- end block handling --- */ bool visit(QQmlJS::AST::UiObjectBinding *uiob) override; + void endVisit(QQmlJS::AST::UiObjectBinding *uiob) override; bool visit(QQmlJS::AST::UiObjectDefinition *uiod) override; void endVisit(QQmlJS::AST::UiObjectDefinition *) override; bool visit(QQmlJS::AST::UiScriptBinding *uisb) override; -- cgit v1.2.3