From f98c961da6d039621ae40ab6c1a79c4b06efb83f Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 14 Oct 2020 12:55:08 +0200 Subject: qmllint: Defer resolution of types read from QML files When importing a directory we most likely don't need all of the files in the directory. Therefore we now parse them only when they are accessed. This speeds up the execution and will allow us to process imports recursively without running into infinite recursion. Change-Id: I0c79313de792249e6bb86144b5014a7787dbdc5b Reviewed-by: Fabian Kosmale --- src/qmlcompiler/qqmljsscope.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/qmlcompiler/qqmljsscope.cpp') diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp index b2b9443fc6..e515431758 100644 --- a/src/qmlcompiler/qqmljsscope.cpp +++ b/src/qmlcompiler/qqmljsscope.cpp @@ -27,9 +27,12 @@ ****************************************************************************/ #include "qqmljsscope_p.h" +#include "qqmljstypereader_p.h" +#include "qqmljsimporter_p.h" #include #include +#include #include @@ -40,7 +43,7 @@ QQmlJSScope::QQmlJSScope(ScopeType type, const QQmlJSScope::Ptr &parentScope) QQmlJSScope::Ptr QQmlJSScope::create(ScopeType type, const QQmlJSScope::Ptr &parentScope) { - QQmlJSScope::Ptr childScope(new QQmlJSScope{type, parentScope}); + QSharedPointer childScope(new QQmlJSScope{type, parentScope}); if (parentScope) { Q_ASSERT(type != QQmlJSScope::QMLScope || !parentScope->m_parentScope @@ -142,7 +145,7 @@ void QQmlJSScope::resolveTypes(const QHash &cont for (auto it = m_methods.begin(), end = m_methods.end(); it != end; ++it) { it->setReturnType(findType(it->returnTypeName())); const auto paramNames = it->parameterTypeNames(); - QList paramTypes; + QList> paramTypes; for (const QString ¶mName: paramNames) paramTypes.append(findType(paramName)); @@ -183,4 +186,22 @@ bool QQmlJSScope::Export::isValid() const return m_version.isValid() || !m_package.isEmpty() || !m_type.isEmpty(); } +QQmlJSScope QDeferredFactory::create() const +{ + QQmlJSTypeReader typeReader(m_filePath); + QQmlJSScope::Ptr result = typeReader(); + + m_importer->m_warnings.append(typeReader.errors()); + + QQmlJSImporter::AvailableTypes types; + types.qmlNames.insert(m_importer->importDirectory(QFileInfo(m_filePath).canonicalPath())); + + const auto imports = typeReader.imports(); + for (const auto &import : imports) + m_importer->importHelper(import.module, &types, import.prefix, import.version); + + result->resolveTypes(types.qmlNames); + return std::move(*result); +} + QT_END_NAMESPACE -- cgit v1.2.3