aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2021-06-08 10:38:20 +0200
committerFawzi Mohamed <fawzi@gmx.ch>2021-09-07 11:28:08 +0200
commit3bb7aa76ca1c70d91e0e0cc7b92a78c69490c6a5 (patch)
tree669e326806ab2dc67d37e927fecd4b9277b44d6a
parentf2e61c50beb92723b789d563a1c50630cdb094d0 (diff)
qmldom: DomItem::makeCopy also for elements of the universe
The universe is the cache where loaded files are stored, so to compare them immediately after load it is useful that the makeCopy method which creates a deep copy, works also on files in the files without environment. Change-Id: I35fc5a769b422d367d07af3374566997dd6b0153 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 42aa1d510214bb51f35c9ab0c798e39558d341cb)
-rw-r--r--src/qmldom/qqmldomelements.cpp10
-rw-r--r--src/qmldom/qqmldomitem.cpp67
-rw-r--r--tests/auto/qmldom/domitem/tst_qmldomitem.h13
3 files changed, 58 insertions, 32 deletions
diff --git a/src/qmldom/qqmldomelements.cpp b/src/qmldom/qqmldomelements.cpp
index 914c72e34f..0b5d36b4a0 100644
--- a/src/qmldom/qqmldomelements.cpp
+++ b/src/qmldom/qqmldomelements.cpp
@@ -1197,9 +1197,10 @@ void EnumDecl::writeOut(DomItem &self, OutWriter &ow) const
QList<Path> ImportScope::allSources(DomItem &self) const
{
- DomItem env = self.environment();
+ DomItem top = self.top();
+ DomItem env = top.environment();
Path selfPath = self.canonicalPath().field(Fields::allSources);
- RefCacheEntry cached = RefCacheEntry::forPath(env, selfPath);
+ RefCacheEntry cached = (env ? RefCacheEntry::forPath(env, selfPath) : RefCacheEntry());
if (cached.cached == RefCacheEntry::Cached::All)
return cached.canonicalPaths;
QList<Path> res;
@@ -1211,7 +1212,7 @@ QList<Path> ImportScope::allSources(DomItem &self) const
continue;
knownPaths.insert(pNow);
res.append(pNow);
- DomItem sourceBase = env.path(pNow);
+ DomItem sourceBase = top.path(pNow);
for (DomItem autoExp : sourceBase.field(Fields::autoExports).values()) {
if (const ModuleAutoExport *autoExpPtr = autoExp.as<ModuleAutoExport>()) {
Path newSource;
@@ -1241,7 +1242,8 @@ QList<Path> ImportScope::allSources(DomItem &self) const
}
}
}
- RefCacheEntry::addForPath(env, selfPath, RefCacheEntry { RefCacheEntry::Cached::All, res });
+ if (env)
+ RefCacheEntry::addForPath(env, selfPath, RefCacheEntry { RefCacheEntry::Cached::All, res });
return res;
}
diff --git a/src/qmldom/qqmldomitem.cpp b/src/qmldom/qqmldomitem.cpp
index 0a52a11121..49fc3fabda 100644
--- a/src/qmldom/qqmldomitem.cpp
+++ b/src/qmldom/qqmldomitem.cpp
@@ -1927,14 +1927,23 @@ MutableDomItem DomItem::makeCopy(DomItem::CopyOption option)
return MutableDomItem(newItem.path(pathFromOwner()));
}
DomItem env = environment();
- std::shared_ptr<DomEnvironment> envPtr = env.ownerAs<DomEnvironment>();
- Q_ASSERT(envPtr);
- std::shared_ptr<DomEnvironment> newEnvPtr(
- new DomEnvironment(envPtr, envPtr->loadPaths(), envPtr->options()));
- DomBase *eBase = envPtr.get();
- if (std::holds_alternative<DomEnvironment *>(m_element) && eBase
- && std::get<DomEnvironment *>(m_element) == eBase)
- return MutableDomItem(DomItem(newEnvPtr));
+ std::shared_ptr<DomEnvironment> newEnvPtr;
+ if (std::shared_ptr<DomEnvironment> envPtr = env.ownerAs<DomEnvironment>()) {
+ newEnvPtr = std::shared_ptr<DomEnvironment>(
+ new DomEnvironment(envPtr, envPtr->loadPaths(), envPtr->options()));
+ DomBase *eBase = envPtr.get();
+ if (std::holds_alternative<DomEnvironment *>(m_element) && eBase
+ && std::get<DomEnvironment *>(m_element) == eBase)
+ return MutableDomItem(DomItem(newEnvPtr));
+ } else if (std::shared_ptr<DomUniverse> univPtr = top().ownerAs<DomUniverse>()) {
+ newEnvPtr = std::shared_ptr<DomEnvironment>(new DomEnvironment(
+ QStringList(),
+ DomEnvironment::Option::SingleThreaded | DomEnvironment::Option::NoDependencies,
+ univPtr));
+ } else {
+ Q_ASSERT(false);
+ return {};
+ }
DomItem newItem = std::visit(
[this, newEnvPtr, &o](auto &&el) {
auto copyPtr = el->makeCopy(o);
@@ -2729,26 +2738,28 @@ DomItem Reference::get(DomItem &self, ErrorHandler h, QList<Path> *visitedRefs)
Path cachedPath;
if (shouldCache()) {
env = self.environment();
- selfPath = self.canonicalPath();
- RefCacheEntry cached = RefCacheEntry::forPath(self, selfPath);
- switch (cached.cached) {
- case RefCacheEntry::Cached::None:
- break;
- case RefCacheEntry::Cached::First:
- case RefCacheEntry::Cached::All:
- if (!cached.canonicalPaths.isEmpty())
- cachedPath = cached.canonicalPaths.first();
- else
- return res;
- break;
- }
- if (cachedPath) {
- res = env.path(cachedPath);
- if (!res)
- qCWarning(refLog) << "referenceCache outdated, reference at " << selfPath
- << " leads to invalid path " << cachedPath;
- else
- return res;
+ if (env) {
+ selfPath = self.canonicalPath();
+ RefCacheEntry cached = RefCacheEntry::forPath(self, selfPath);
+ switch (cached.cached) {
+ case RefCacheEntry::Cached::None:
+ break;
+ case RefCacheEntry::Cached::First:
+ case RefCacheEntry::Cached::All:
+ if (!cached.canonicalPaths.isEmpty())
+ cachedPath = cached.canonicalPaths.first();
+ else
+ return res;
+ break;
+ }
+ if (cachedPath) {
+ res = env.path(cachedPath);
+ if (!res)
+ qCWarning(refLog) << "referenceCache outdated, reference at " << selfPath
+ << " leads to invalid path " << cachedPath;
+ else
+ return res;
+ }
}
}
QList<Path> visitedRefsLocal;
diff --git a/tests/auto/qmldom/domitem/tst_qmldomitem.h b/tests/auto/qmldom/domitem/tst_qmldomitem.h
index 8346649aa0..4b98f467ea 100644
--- a/tests/auto/qmldom/domitem/tst_qmldomitem.h
+++ b/tests/auto/qmldom/domitem/tst_qmldomitem.h
@@ -41,6 +41,8 @@
#include <QtQmlDom/private/qqmldomtop_p.h>
#include <QtQmlDom/private/qqmldomastdumper_p.h>
#include <QtQmlDom/private/qqmldommock_p.h>
+#include <QtQmlDom/private/qqmldomcompare_p.h>
+#include <QtQmlDom/private/qqmldomfieldfilter_p.h>
#include <QtTest/QtTest>
#include <QCborValue>
@@ -531,6 +533,17 @@ private slots:
if (!diff.isEmpty())
qDebug().nospace().noquote() << diff;
QCOMPARE(dump1, dump2);
+ QStringList diffs = domCompareStrList(f, copy, FieldFilter::compareFilter());
+ if (!diffs.isEmpty())
+ qDebug() << "testDeepCopy.diffs:" << diffs;
+ QVERIFY(diffs.isEmpty());
+ DomItem univFile = env.universe().path(f.canonicalPath());
+ MutableDomItem univFileCopy = univFile.makeCopy();
+ QStringList univFileDiffs =
+ domCompareStrList(univFile, univFileCopy, FieldFilter::compareFilter());
+ if (!univFileDiffs.isEmpty())
+ qDebug() << "testDeepCopy.univFileDiffs:" << univFileDiffs;
+ QVERIFY(univFileDiffs.isEmpty());
}
private: