QmlDesigner: Move source cache types to their own header

The namespace is now Cache for that types.

Task-number: QDS-4306
Change-Id: I479f1ca534455a41de9dc1d6a1fd891e1d8973eb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2021-05-06 12:26:39 +02:00
parent b3bed53c4f
commit 494469641a
12 changed files with 214 additions and 176 deletions

View File

@@ -28,6 +28,7 @@
#include "projectstorageexceptions.h"
#include "projectstorageids.h"
#include "projectstoragetypes.h"
#include "sourcepathcachetypes.h"
#include <sqlitetable.h>
#include <sqlitetransaction.h>
@@ -152,7 +153,7 @@ public:
auto fetchAllSourceContexts() const
{
return selectAllSourceContextsStatement.template valuesWithTransaction<Sources::SourceContext>(
return selectAllSourceContextsStatement.template valuesWithTransaction<Cache::SourceContext>(
128);
}
@@ -167,11 +168,10 @@ public:
return sourceId;
}
Sources::SourceNameAndSourceContextId fetchSourceNameAndSourceContextId(SourceId sourceId) const
auto fetchSourceNameAndSourceContextId(SourceId sourceId) const
{
auto value = selectSourceNameAndSourceContextIdFromSourcesBySourceIdStatement
.template valueWithTransaction<Sources::SourceNameAndSourceContextId>(
&sourceId);
.template valueWithTransaction<Cache::SourceNameAndSourceContextId>(&sourceId);
if (!value.sourceContextId)
throw SourceIdDoesNotExists();
@@ -192,7 +192,7 @@ public:
auto fetchAllSources() const
{
return selectAllSourcesStatement.template valuesWithTransaction<Sources::Source>(1024);
return selectAllSourcesStatement.template valuesWithTransaction<Cache::Source>(1024);
}
SourceId fetchSourceIdUnguarded(SourceContextId sourceContextId, Utils::SmallStringView sourceName)

View File

@@ -26,141 +26,9 @@
#pragma once
#include "projectstorageids.h"
#include "storagecacheentry.h"
#include <utils/smallstring.h>
#include <cstdint>
#include <vector>
#include <tuple>
#include <unordered_map>
namespace QmlDesigner {
class SourceNameView
{
public:
friend bool operator==(const SourceNameView &first, const SourceNameView &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator<(SourceNameView first, SourceNameView second) noexcept
{
return std::tie(first.sourceContextId, first.sourceName)
< std::tie(second.sourceContextId, second.sourceName);
}
public:
Utils::SmallStringView sourceName;
SourceContextId sourceContextId;
};
class SourceNameEntry
{
public:
SourceNameEntry(Utils::SmallStringView sourceName, int sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameEntry(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameEntry(SourceNameView view)
: sourceName(view.sourceName)
, sourceContextId(view.sourceContextId)
{}
friend bool operator==(const SourceNameEntry &first, const SourceNameEntry &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator!=(const SourceNameEntry &first, const SourceNameEntry &second) noexcept
{
return !(first == second);
}
friend bool operator==(const SourceNameEntry &first, const SourceNameView &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator!=(const SourceNameEntry &first, const SourceNameView &second) noexcept
{
return !(first == second);
}
operator SourceNameView() const noexcept { return {sourceName, sourceContextId}; }
operator Utils::SmallString() &&noexcept { return std::move(sourceName); }
public:
Utils::SmallString sourceName;
SourceContextId sourceContextId;
};
namespace Sources {
class SourceContext
: public StorageCacheEntry<Utils::PathString, Utils::SmallStringView, SourceContextId>
{
using Base = StorageCacheEntry<Utils::PathString, Utils::SmallStringView, SourceContextId>;
public:
using Base::Base;
friend bool operator==(const SourceContext &first, const SourceContext &second)
{
return first.id == second.id && first.value == second.value;
}
};
using SourceContexts = std::vector<SourceContext>;
class Source : public StorageCacheEntry<SourceNameEntry, SourceNameView, SourceId>
{
using Base = StorageCacheEntry<SourceNameEntry, SourceNameView, SourceId>;
public:
using Base::Base;
Source(Utils::SmallStringView sourceName, SourceContextId sourceContextId, SourceId sourceId)
: Base{{sourceName, sourceContextId}, sourceId}
{}
Source(Utils::SmallStringView sourceName, int sourceContextId, int sourceId)
: Base{{sourceName, SourceContextId{sourceContextId}}, SourceId{sourceId}}
{}
friend bool operator==(const Source &first, const Source &second)
{
return first.id == second.id && first.value == second.value;
}
};
using Sources = std::vector<Source>;
class SourceNameAndSourceContextId
{
public:
constexpr SourceNameAndSourceContextId() = default;
SourceNameAndSourceContextId(Utils::SmallStringView sourceName, int sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameAndSourceContextId(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName{sourceName}
, sourceContextId{sourceContextId}
{}
Utils::SmallString sourceName;
SourceContextId sourceContextId;
};
} // namespace ClangBackEnd
} // namespace QmlDesigner
namespace QmlDesigner::Storage {} // namespace QmlDesigner::Storage

View File

@@ -27,8 +27,8 @@
#include "projectstorageexceptions.h"
#include "projectstorageids.h"
#include "projectstoragetypes.h"
#include "sourcepath.h"
#include "sourcepathcachetypes.h"
#include "sourcepathview.h"
#include "storagecache.h"
@@ -134,7 +134,7 @@ private:
class SourceStorageAdapter
{
public:
auto fetchId(SourceNameView sourceNameView)
auto fetchId(Cache::SourceNameView sourceNameView)
{
return storage.fetchSourceId(sourceNameView.sourceContextId, sourceNameView.sourceName);
}
@@ -143,7 +143,7 @@ private:
{
auto entry = storage.fetchSourceNameAndSourceContextId(id);
return SourceNameEntry{std::move(entry.sourceName), entry.sourceContextId};
return Cache::SourceNameEntry{std::move(entry.sourceName), entry.sourceContextId};
}
auto fetchAll() { return storage.fetchAllSources(); }
@@ -156,7 +156,7 @@ private:
return Utils::reverseCompare(first, second) < 0;
}
static bool sourceLess(SourceNameView first, SourceNameView second) noexcept
static bool sourceLess(Cache::SourceNameView first, Cache::SourceNameView second) noexcept
{
return first < second;
}
@@ -167,9 +167,14 @@ private:
SourceContextStorageAdapter,
Mutex,
sourceContextLess,
Sources::SourceContext>;
using SourceNameCache
= StorageCache<SourceNameEntry, SourceNameView, SourceId, SourceStorageAdapter, Mutex, sourceLess, Sources::Source>;
Cache::SourceContext>;
using SourceNameCache = StorageCache<Cache::SourceNameEntry,
Cache::SourceNameView,
SourceId,
SourceStorageAdapter,
Mutex,
sourceLess,
Cache::Source>;
private:
SourceContextStorageAdapter m_sourceContextStorageAdapter;

View File

@@ -0,0 +1,161 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "projectstorageids.h"
#include "storagecacheentry.h"
#include <utils/smallstring.h>
#include <vector>
namespace QmlDesigner::Cache {
class SourceNameView
{
public:
friend bool operator==(const SourceNameView &first, const SourceNameView &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator<(SourceNameView first, SourceNameView second) noexcept
{
return std::tie(first.sourceContextId, first.sourceName)
< std::tie(second.sourceContextId, second.sourceName);
}
public:
Utils::SmallStringView sourceName;
SourceContextId sourceContextId;
};
class SourceNameEntry
{
public:
SourceNameEntry(Utils::SmallStringView sourceName, int sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameEntry(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameEntry(SourceNameView view)
: sourceName(view.sourceName)
, sourceContextId(view.sourceContextId)
{}
friend bool operator==(const SourceNameEntry &first, const SourceNameEntry &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator!=(const SourceNameEntry &first, const SourceNameEntry &second) noexcept
{
return !(first == second);
}
friend bool operator==(const SourceNameEntry &first, const SourceNameView &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator!=(const SourceNameEntry &first, const SourceNameView &second) noexcept
{
return !(first == second);
}
operator SourceNameView() const noexcept { return {sourceName, sourceContextId}; }
operator Utils::SmallString() &&noexcept { return std::move(sourceName); }
public:
Utils::SmallString sourceName;
SourceContextId sourceContextId;
};
class SourceContext
: public StorageCacheEntry<Utils::PathString, Utils::SmallStringView, SourceContextId>
{
using Base = StorageCacheEntry<Utils::PathString, Utils::SmallStringView, SourceContextId>;
public:
using Base::Base;
friend bool operator==(const SourceContext &first, const SourceContext &second)
{
return first.id == second.id && first.value == second.value;
}
};
using SourceContexts = std::vector<SourceContext>;
class Source : public StorageCacheEntry<SourceNameEntry, SourceNameView, SourceId>
{
using Base = StorageCacheEntry<SourceNameEntry, SourceNameView, SourceId>;
public:
using Base::Base;
Source(Utils::SmallStringView sourceName, SourceContextId sourceContextId, SourceId sourceId)
: Base{{sourceName, sourceContextId}, sourceId}
{}
Source(Utils::SmallStringView sourceName, int sourceContextId, int sourceId)
: Base{{sourceName, SourceContextId{sourceContextId}}, SourceId{sourceId}}
{}
friend bool operator==(const Source &first, const Source &second)
{
return first.id == second.id && first.value == second.value;
}
};
using Sources = std::vector<Source>;
class SourceNameAndSourceContextId
{
public:
constexpr SourceNameAndSourceContextId() = default;
SourceNameAndSourceContextId(Utils::SmallStringView sourceName, int sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameAndSourceContextId(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName{sourceName}
, sourceContextId{sourceContextId}
{}
Utils::SmallString sourceName;
SourceContextId sourceContextId;
};
} // namespace QmlDesigner::Cache

View File

@@ -82,4 +82,5 @@ HEADERS += \
$$PWD/designercore/include/projectstorageids.h \
$$PWD/designercore/projectstorage/projectstoragetypes.h \
$$PWD/designercore/projectstorage/projectstoragesqlitefunctionregistry.h \
$$PWD/designercore/projectstorage/sourcepathcache.h
$$PWD/designercore/projectstorage/sourcepathcache.h \
$$PWD/designercore/projectstorage/sourcepathcachetypes.h

View File

@@ -58,6 +58,7 @@
#include <projectpartentry.h>
#include <projectpartpch.h>
#include <projectstorage/projectstoragetypes.h>
#include <projectstorage/sourcepathcachetypes.h>
#include <sourcedependency.h>
#include <sourcelocationentry.h>
#include <sourcelocationscontainer.h>
@@ -1571,13 +1572,13 @@ std::ostream &operator<<(std::ostream &out, const VariantProperty &property)
return out << "(" << property.parentModelNode() << ", " << property.name() << ", "
<< property.value() << ")";
}
namespace Sources {
namespace Cache {
std::ostream &operator<<(std::ostream &out, const SourceContext &sourceContext)
{
return out << "(" << sourceContext.id << ", " << sourceContext.value << ")";
}
} // namespace Sources
} // namespace Cache
namespace Internal {
std::ostream &operator<<(std::ostream &out, const ImageCacheStorageImageEntry &entry)

View File

@@ -386,11 +386,11 @@ std::ostream &operator<<(std::ostream &out, const BasicId<Type, InternalInterger
return out << "(" << &id << ")";
}
namespace Sources {
namespace Cache {
class SourceContext;
std::ostream &operator<<(std::ostream &out, const SourceContext &sourceContext);
} // namespace Sources
} // namespace Cache
namespace Internal {
class ImageCacheStorageImageEntry;

View File

@@ -40,8 +40,8 @@ using QmlDesigner::SourceContextId;
using QmlDesigner::SourceId;
using QmlDesigner::TypeAccessSemantics;
using QmlDesigner::TypeId;
using QmlDesigner::Sources::Source;
using QmlDesigner::Sources::SourceContext;
using QmlDesigner::Cache::Source;
using QmlDesigner::Cache::SourceContext;
MATCHER_P2(IsSourceContext,
id,
@@ -57,9 +57,9 @@ MATCHER_P2(IsSourceNameAndSourceContextId,
name,
id,
std::string(negation ? "isn't " : "is ")
+ PrintToString(QmlDesigner::Sources::SourceNameAndSourceContextId{name, id}))
+ PrintToString(QmlDesigner::Cache::SourceNameAndSourceContextId{name, id}))
{
const QmlDesigner::Sources::SourceNameAndSourceContextId &sourceNameAndSourceContextId = arg;
const QmlDesigner::Cache::SourceNameAndSourceContextId &sourceNameAndSourceContextId = arg;
return sourceNameAndSourceContextId.sourceName == name
&& sourceNameAndSourceContextId.sourceContextId == id;
@@ -89,15 +89,15 @@ public:
ON_CALL(selectSourceIdFromSourcesBySourceContextIdAndSourceNameStatment,
valueReturnInt32(5, Utils::SmallStringView("file.h")))
.WillByDefault(Return(Utils::optional<int>(42)));
ON_CALL(selectAllSourcesStatement, valuesReturnSourcesSources(_))
ON_CALL(selectAllSourcesStatement, valuesReturnCacheSources(_))
.WillByDefault(Return(std::vector<Source>{{"file.h", SourceContextId{1}, SourceId{1}},
{"file.cpp", SourceContextId{2}, SourceId{4}}}));
ON_CALL(selectSourceContextPathFromSourceContextsBySourceContextIdStatement,
valueReturnPathString(5))
.WillByDefault(Return(Utils::optional<Utils::PathString>("/path/to")));
ON_CALL(selectSourceNameAndSourceContextIdFromSourcesBySourceIdStatement,
valueReturnSourcesSourceNameAndSourceContextId(42))
.WillByDefault(Return(QmlDesigner::Sources::SourceNameAndSourceContextId{"file.cpp", 5}));
valueReturnCacheSourceNameAndSourceContextId(42))
.WillByDefault(Return(QmlDesigner::Cache::SourceNameAndSourceContextId{"file.cpp", 5}));
ON_CALL(selectSourceContextIdFromSourcesBySourceIdStatement,
valueReturnInt32(TypedEq<int>(42)))
.WillByDefault(Return(Utils::optional<int>(5)));

View File

@@ -30,6 +30,7 @@
#include "sqlitedatabasemock.h"
#include <projectstorage/projectstoragetypes.h>
#include <projectstorage/sourcepathcache.h>
#include <projectstorageids.h>
class ProjectStorageMock
@@ -52,9 +53,9 @@ public:
MOCK_METHOD1(fetchSourceContextPath,
Utils::PathString(QmlDesigner::SourceContextId sourceContextId));
MOCK_METHOD1(fetchSourceNameAndSourceContextId,
QmlDesigner::Sources::SourceNameAndSourceContextId(QmlDesigner::SourceId sourceId));
MOCK_METHOD0(fetchAllSourceContexts, std::vector<QmlDesigner::Sources::SourceContext>());
MOCK_METHOD0(fetchAllSources, std::vector<QmlDesigner::Sources::Source>());
QmlDesigner::Cache::SourceNameAndSourceContextId(QmlDesigner::SourceId sourceId));
MOCK_METHOD0(fetchAllSourceContexts, std::vector<QmlDesigner::Cache::SourceContext>());
MOCK_METHOD0(fetchAllSources, std::vector<QmlDesigner::Cache::Source>());
SqliteDatabaseMock &database() { return databaseMock; }

View File

@@ -39,7 +39,7 @@ using Cache = QmlDesigner::SourcePathCache<NiceMock<ProjectStorageMock>>;
using NFP = QmlDesigner::SourcePath;
using QmlDesigner::SourcePathView;
using QmlDesigner::SourcePathViews;
using QmlDesigner::Sources::SourceNameAndSourceContextId;
using QmlDesigner::Cache::SourceNameAndSourceContextId;
class SourcePathCache : public testing::Test
{
@@ -61,13 +61,13 @@ protected:
ON_CALL(storageMock, fetchSourceNameAndSourceContextId(SourceId{42}))
.WillByDefault(Return(SourceNameAndSourceContextId("file.cpp", SourceContextId{5})));
ON_CALL(storageMockFilled, fetchAllSources())
.WillByDefault(Return(std::vector<QmlDesigner::Sources::Source>({
.WillByDefault(Return(std::vector<QmlDesigner::Cache::Source>({
{"file.cpp", SourceContextId{6}, SourceId{72}},
{"file2.cpp", SourceContextId{5}, SourceId{63}},
{"file.cpp", SourceContextId{5}, SourceId{42}},
})));
ON_CALL(storageMockFilled, fetchAllSourceContexts())
.WillByDefault(Return(std::vector<QmlDesigner::Sources::SourceContext>(
.WillByDefault(Return(std::vector<QmlDesigner::Cache::SourceContext>(
{{"/path2/to", SourceContextId{6}}, {"/path/to", SourceContextId{5}}})));
ON_CALL(storageMockFilled, fetchSourceContextId(Eq("/path/to")))
.WillByDefault(Return(SourceContextId{5}));

View File

@@ -35,6 +35,7 @@
#include <projectpartpch.h>
#include <projectpartstoragestructs.h>
#include <projectstorage/projectstoragetypes.h>
#include <projectstorage/sourcepathcachetypes.h>
#include <projectstorageids.h>
#include <sourceentry.h>
#include <sourcelocations.h>
@@ -173,15 +174,15 @@ public:
(long long, Utils::SmallStringView),
());
MOCK_METHOD(std::vector<QmlDesigner::Sources::SourceContext>,
valuesReturnSourcesSourceContexts,
MOCK_METHOD(std::vector<QmlDesigner::Cache::SourceContext>,
valuesReturnCacheSourceContexts,
(std::size_t),
());
MOCK_METHOD(std::vector<QmlDesigner::Sources::Source>, valuesReturnSourcesSources, (std::size_t), ());
MOCK_METHOD(std::vector<QmlDesigner::Cache::Source>, valuesReturnCacheSources, (std::size_t), ());
MOCK_METHOD(QmlDesigner::Sources::SourceNameAndSourceContextId,
valueReturnSourcesSourceNameAndSourceContextId,
MOCK_METHOD(QmlDesigner::Cache::SourceNameAndSourceContextId,
valueReturnCacheSourceNameAndSourceContextId,
(int) );
MOCK_METHOD(QmlDesigner::SourceContextId, valueReturnsSourceContextId, (Utils::SmallStringView), ());
@@ -235,8 +236,8 @@ public:
else if constexpr (std::is_same_v<ResultType,
std::tuple<QmlDesigner::PropertyDeclarationId, QmlDesigner::TypeId>>)
return valueReturnsPropertyDeclaration(queryValues...);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::Sources::SourceNameAndSourceContextId>)
return valueReturnSourcesSourceNameAndSourceContextId(queryValues...);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::Cache::SourceNameAndSourceContextId>)
return valueReturnCacheSourceNameAndSourceContextId(queryValues...);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::SourceContextId>)
return valueReturnsSourceContextId(queryValues...);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::SourceId>)
@@ -299,10 +300,10 @@ public:
return valuesReturnSourceEntries(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, SourceTimeStamp>)
return valuesReturnSourceTimeStamps(reserveSize, queryValues...);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::Sources::SourceContext>)
return valuesReturnSourcesSourceContexts(reserveSize);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::Sources::Source>)
return valuesReturnSourcesSources(reserveSize);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::Cache::SourceContext>)
return valuesReturnCacheSourceContexts(reserveSize);
else if constexpr (std::is_same_v<ResultType, QmlDesigner::Cache::Source>)
return valuesReturnCacheSources(reserveSize);
else
static_assert(!std::is_same_v<ResultType, ResultType>,
"SqliteReadStatementMock::values does not handle result type!");

View File

@@ -64,7 +64,7 @@ using CacheWithMockLocking = QmlDesigner::StorageCache<Utils::PathString,
StorageAdapter,
NiceMock<MockMutex>,
less,
QmlDesigner::Sources::SourceContext>;
QmlDesigner::Cache::SourceContext>;
using CacheWithoutLocking = QmlDesigner::StorageCache<Utils::PathString,
Utils::SmallStringView,
@@ -72,7 +72,7 @@ using CacheWithoutLocking = QmlDesigner::StorageCache<Utils::PathString,
StorageAdapter,
NiceMock<MockMutexNonLocking>,
less,
QmlDesigner::Sources::SourceContext>;
QmlDesigner::Cache::SourceContext>;
template<typename Cache>
class StorageCache : public testing::Test