diff options
author | Fawzi Mohamed <fawzi.mohamed@qt.io> | 2021-06-08 10:38:20 +0200 |
---|---|---|
committer | Fawzi Mohamed <fawzi@gmx.ch> | 2021-09-07 11:28:08 +0200 |
commit | 3bb7aa76ca1c70d91e0e0cc7b92a78c69490c6a5 (patch) | |
tree | 669e326806ab2dc67d37e927fecd4b9277b44d6a /src | |
parent | f2e61c50beb92723b789d563a1c50630cdb094d0 (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)
Diffstat (limited to 'src')
-rw-r--r-- | src/qmldom/qqmldomelements.cpp | 10 | ||||
-rw-r--r-- | src/qmldom/qqmldomitem.cpp | 67 |
2 files changed, 45 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; |