aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsscope.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-14 12:55:08 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-15 10:44:20 +0200
commitf98c961da6d039621ae40ab6c1a79c4b06efb83f (patch)
tree0eca1d6c2e19e54795da143ecb65279acd972572 /src/qmlcompiler/qqmljsscope.cpp
parented9ffa109eb2f242b59443ad430204a90c8028c4 (diff)
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsscope.cpp')
-rw-r--r--src/qmlcompiler/qqmljsscope.cpp25
1 files changed, 23 insertions, 2 deletions
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 <QtCore/qqueue.h>
#include <QtCore/qsharedpointer.h>
+#include <QtCore/qfileinfo.h>
#include <algorithm>
@@ -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<QQmlJSScope> childScope(new QQmlJSScope{type, parentScope});
if (parentScope) {
Q_ASSERT(type != QQmlJSScope::QMLScope
|| !parentScope->m_parentScope
@@ -142,7 +145,7 @@ void QQmlJSScope::resolveTypes(const QHash<QString, QQmlJSScope::ConstPtr> &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<QQmlJSScope::ConstPtr> paramTypes;
+ QList<QSharedPointer<const QQmlJSScope>> paramTypes;
for (const QString &paramName: 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<QQmlJSScope>::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