aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-21 14:11:10 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-22 09:57:57 +0200
commit826b7c3b18b2104cd0ff2c4b90892e72e149a88d (patch)
treeec337d2708e9944216b62c3c002c3765ed1dfa6f /src/qmlcompiler
parentec9d125f553c073ec7a431114a568eaeb6534b63 (diff)
qmllint: Resolve aliases in nested objects
So far we've just ignored them. Change-Id: I2ca522ef825a341a3f4bf1c2a42fb0376180cdda Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp47
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor_p.h4
2 files changed, 30 insertions, 21 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index 5ff9accd97..6595b1d8d7 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -30,6 +30,7 @@
#include <QtCore/qfileinfo.h>
#include <QtCore/qdir.h>
+#include <QtCore/qqueue.h>
QT_BEGIN_NAMESPACE
@@ -60,32 +61,33 @@ void QQmlJSImportVisitor::leaveEnvironment()
m_currentScope = m_currentScope->parentScope();
}
-QQmlJSScope::Ptr QQmlJSImportVisitor::result() const
+void QQmlJSImportVisitor::resolveAliases()
{
- QQmlJSScope::Ptr result = QQmlJSScope::create();
- result->setIsComposite(true);
- result->setBaseTypeName(m_qmlRootScope->baseTypeName());
- const auto properties = m_qmlRootScope->properties();
- for (auto property : properties) {
- if (property.isAlias()) {
+ QQueue<QQmlJSScope::Ptr> objects;
+ objects.enqueue(m_qmlRootScope);
+
+ while (!objects.isEmpty()) {
+ const QQmlJSScope::Ptr object = objects.dequeue();
+ const auto properties = object->properties();
+ for (auto property : properties) {
+ if (!property.isAlias())
+ continue;
const auto it = m_scopesById.find(property.typeName());
- if (it != m_scopesById.end())
+ if (it != m_scopesById.end()) {
property.setType(QQmlJSScope::ConstPtr(*it));
- result->addProperty(property);
- } else {
- result->addProperty(property);
+ object->addProperty(property);
+ }
}
- }
-
- for (const auto &method : m_qmlRootScope->methods())
- result->addMethod(method);
- for (const auto &enumerator : m_qmlRootScope->enums())
- result->addEnum(enumerator);
+ const auto childScopes = object->childScopes();
+ for (const auto &childScope : childScopes)
+ objects.enqueue(childScope);
+ }
+}
- result->resolveTypes(m_rootScopeImports);
- result->setSourceLocation(m_qmlRootScope->sourceLocation());
- return result;
+QQmlJSScope::Ptr QQmlJSImportVisitor::result() const
+{
+ return m_qmlRootScope;
}
void QQmlJSImportVisitor::importExportedNames(QQmlJSScope::ConstPtr scope)
@@ -126,6 +128,11 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiProgram *)
return true;
}
+void QQmlJSImportVisitor::endVisit(UiProgram *)
+{
+ resolveAliases();
+}
+
bool QQmlJSImportVisitor::visit(UiObjectDefinition *definition)
{
QString superType;
diff --git a/src/qmlcompiler/qqmljsimportvisitor_p.h b/src/qmlcompiler/qqmljsimportvisitor_p.h
index 0255450c68..eef5889263 100644
--- a/src/qmlcompiler/qqmljsimportvisitor_p.h
+++ b/src/qmlcompiler/qqmljsimportvisitor_p.h
@@ -59,6 +59,7 @@ public:
protected:
bool visit(QQmlJS::AST::UiProgram *) override;
+ void endVisit(QQmlJS::AST::UiProgram *) override;
bool visit(QQmlJS::AST::UiObjectDefinition *) override;
void endVisit(QQmlJS::AST::UiObjectDefinition *) override;
bool visit(QQmlJS::AST::UiPublicMember *) override;
@@ -97,7 +98,7 @@ protected:
QString m_implicitImportDirectory;
QStringList m_qmltypesFiles;
QQmlJSScope::Ptr m_currentScope;
- QQmlJSScope::ConstPtr m_qmlRootScope;
+ QQmlJSScope::Ptr m_qmlRootScope;
QQmlJSScope::ConstPtr m_globalScope;
QHash<QString, QQmlJSScope::ConstPtr> m_scopesById;
QHash<QString, QQmlJSScope::ConstPtr> m_rootScopeImports;
@@ -110,6 +111,7 @@ protected:
void leaveEnvironment();
private:
+ void resolveAliases();
void visitFunctionExpressionHelper(QQmlJS::AST::FunctionExpression *fexpr);
void importExportedNames(QQmlJSScope::ConstPtr scope);
};