forked from qt-creator/qt-creator
Clang: Make it more clear that the FilePathId.filePathId is not shared
The name fileNameId could imply that the id shared for the same file name which is not the case. Change-Id: I27310a8994c2d9e9bb0f0aed2094bd988309c710 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -85,7 +85,7 @@ public:
|
|||||||
|
|
||||||
auto fetchSoureName = [&] (int id) { return m_filePathStorage.fetchSourceName(id); };
|
auto fetchSoureName = [&] (int id) { return m_filePathStorage.fetchSourceName(id); };
|
||||||
|
|
||||||
Utils::SmallString fileName = m_fileNameCache.string(filePathId.fileNameId,
|
Utils::SmallString fileName = m_fileNameCache.string(filePathId.filePathId,
|
||||||
fetchSoureName);
|
fetchSoureName);
|
||||||
|
|
||||||
return FilePath{directoryPath, fileName};
|
return FilePath{directoryPath, fileName};
|
||||||
|
@@ -31,7 +31,7 @@ namespace ClangBackEnd {
|
|||||||
|
|
||||||
QDebug operator<<(QDebug debug, const FilePathId &filePathId)
|
QDebug operator<<(QDebug debug, const FilePathId &filePathId)
|
||||||
{
|
{
|
||||||
debug.nospace() << "(" << filePathId.directoryId << ", " << filePathId.fileNameId << ")";
|
debug.nospace() << "(" << filePathId.directoryId << ", " << filePathId.filePathId << ")";
|
||||||
|
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
@@ -39,14 +39,14 @@ class FilePathId
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FilePathId() = default;
|
FilePathId() = default;
|
||||||
FilePathId(int directoryId, int fileNameId)
|
FilePathId(int directoryId, int filePathId)
|
||||||
: directoryId(directoryId),
|
: directoryId(directoryId),
|
||||||
fileNameId(fileNameId)
|
filePathId(filePathId)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool isValid() const
|
bool isValid() const
|
||||||
{
|
{
|
||||||
return directoryId >= 0 && fileNameId >= 0;
|
return directoryId >= 0 && filePathId >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator==(FilePathId first, FilePathId second)
|
friend bool operator==(FilePathId first, FilePathId second)
|
||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
return first.isValid()
|
return first.isValid()
|
||||||
&& second.isValid()
|
&& second.isValid()
|
||||||
&& first.directoryId == second.directoryId
|
&& first.directoryId == second.directoryId
|
||||||
&& first.fileNameId == second.fileNameId;
|
&& first.filePathId == second.filePathId;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator!=(FilePathId first, FilePathId second)
|
friend bool operator!=(FilePathId first, FilePathId second)
|
||||||
@@ -64,14 +64,14 @@ public:
|
|||||||
|
|
||||||
friend bool operator<(FilePathId first, FilePathId second)
|
friend bool operator<(FilePathId first, FilePathId second)
|
||||||
{
|
{
|
||||||
return std::tie(first.directoryId, first.fileNameId)
|
return std::tie(first.directoryId, first.filePathId)
|
||||||
< std::tie(second.directoryId, second.fileNameId);
|
< std::tie(second.directoryId, second.filePathId);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend QDataStream &operator<<(QDataStream &out, const FilePathId &filePathId)
|
friend QDataStream &operator<<(QDataStream &out, const FilePathId &filePathId)
|
||||||
{
|
{
|
||||||
out << filePathId.directoryId;
|
out << filePathId.directoryId;
|
||||||
out << filePathId.fileNameId;
|
out << filePathId.filePathId;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -79,15 +79,14 @@ public:
|
|||||||
friend QDataStream &operator>>(QDataStream &in, FilePathId &filePathId)
|
friend QDataStream &operator>>(QDataStream &in, FilePathId &filePathId)
|
||||||
{
|
{
|
||||||
in >> filePathId.directoryId;
|
in >> filePathId.directoryId;
|
||||||
in >> filePathId.fileNameId;
|
in >> filePathId.filePathId;
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int directoryId = -1;
|
int directoryId = -1;
|
||||||
int fileNameId = -1;
|
int filePathId = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
using FilePathIds = std::vector<FilePathId>;
|
using FilePathIds = std::vector<FilePathId>;
|
||||||
@@ -104,7 +103,7 @@ template<> struct hash<ClangBackEnd::FilePathId>
|
|||||||
{
|
{
|
||||||
long long hash = filePathId.directoryId;
|
long long hash = filePathId.directoryId;
|
||||||
hash = hash << 32;
|
hash = hash << 32;
|
||||||
hash += filePathId.fileNameId;
|
hash += filePathId.filePathId;
|
||||||
|
|
||||||
return std::hash<long long>{}(hash);
|
return std::hash<long long>{}(hash);
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ QDebug operator<<(QDebug debug, const SourceLocationContainer &container)
|
|||||||
<< container.line() << ", "
|
<< container.line() << ", "
|
||||||
<< container.column() << ", "
|
<< container.column() << ", "
|
||||||
<< container.offset() << ", "
|
<< container.offset() << ", "
|
||||||
<< container.filePathId().fileNameId
|
<< container.filePathId().filePathId
|
||||||
<< ")";
|
<< ")";
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
@@ -53,7 +53,7 @@ public:
|
|||||||
const std::size_t reserveSize = 128;
|
const std::size_t reserveSize = 128;
|
||||||
|
|
||||||
return locationsStatement.template values<SourceLocation, 4>(reserveSize,
|
return locationsStatement.template values<SourceLocation, 4>(reserveSize,
|
||||||
filePathId.fileNameId,
|
filePathId.filePathId,
|
||||||
line,
|
line,
|
||||||
utf8Column);
|
utf8Column);
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
const std::size_t reserveSize = 128;
|
const std::size_t reserveSize = 128;
|
||||||
|
|
||||||
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
|
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
|
||||||
filePathId.fileNameId,
|
filePathId.filePathId,
|
||||||
line,
|
line,
|
||||||
utf8Column);
|
utf8Column);
|
||||||
}
|
}
|
||||||
|
@@ -86,7 +86,7 @@ public:
|
|||||||
statement.write(locationsEntry.symbolId,
|
statement.write(locationsEntry.symbolId,
|
||||||
locationsEntry.line,
|
locationsEntry.line,
|
||||||
locationsEntry.column,
|
locationsEntry.column,
|
||||||
locationsEntry.filePathId.fileNameId);
|
locationsEntry.filePathId.filePathId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,11 +68,11 @@ TEST_F(FilePathCache, DirectoryIdOfFilePathIdWithOutAnyEntry)
|
|||||||
ASSERT_THAT(filePathId.directoryId, 5);
|
ASSERT_THAT(filePathId.directoryId, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FilePathCache, FileNameIdOfFilePathIdWithOutAnyEntry)
|
TEST_F(FilePathCache, FilePathIdOfFilePathIdWithOutAnyEntry)
|
||||||
{
|
{
|
||||||
auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp"));
|
auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp"));
|
||||||
|
|
||||||
ASSERT_THAT(filePathId.fileNameId, 42);
|
ASSERT_THAT(filePathId.filePathId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FilePathCache, IfEntryExistsDontCallInStrorage)
|
TEST_F(FilePathCache, IfEntryExistsDontCallInStrorage)
|
||||||
@@ -95,22 +95,22 @@ TEST_F(FilePathCache, IfDirectoryEntryExistsDontCallFetchDirectoryIdButStillCal
|
|||||||
cache.filePathId(FilePathView("/path/to/file.cpp"));
|
cache.filePathId(FilePathView("/path/to/file.cpp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FilePathCache, GetFileNameIdWithCachedValue)
|
TEST_F(FilePathCache, GetFilePathIdWithCachedValue)
|
||||||
{
|
{
|
||||||
cache.filePathId(FilePathView("/path/to/file.cpp"));
|
cache.filePathId(FilePathView("/path/to/file.cpp"));
|
||||||
|
|
||||||
auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp"));
|
auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp"));
|
||||||
|
|
||||||
ASSERT_THAT(filePathId.fileNameId, 42);
|
ASSERT_THAT(filePathId.filePathId, 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FilePathCache, GetFileNameIdWithDirectoryIdCached)
|
TEST_F(FilePathCache, GetFilePathIdWithDirectoryIdCached)
|
||||||
{
|
{
|
||||||
cache.filePathId(FilePathView("/path/to/file.cpp"));
|
cache.filePathId(FilePathView("/path/to/file.cpp"));
|
||||||
|
|
||||||
auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp"));
|
auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp"));
|
||||||
|
|
||||||
ASSERT_THAT(filePathId.fileNameId, 63);
|
ASSERT_THAT(filePathId.filePathId, 63);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FilePathCache, GetDirectyIdWithCachedValue)
|
TEST_F(FilePathCache, GetDirectyIdWithCachedValue)
|
||||||
|
@@ -130,7 +130,7 @@ namespace ClangBackEnd {
|
|||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const FilePathId &id)
|
std::ostream &operator<<(std::ostream &out, const FilePathId &id)
|
||||||
{
|
{
|
||||||
return out << "(" << id.directoryId << ", " << id.fileNameId << ")";
|
return out << "(" << id.directoryId << ", " << id.filePathId << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const FilePathView &filePathView)
|
std::ostream &operator<<(std::ostream &out, const FilePathView &filePathView)
|
||||||
@@ -827,7 +827,7 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &containe
|
|||||||
std::ostream &operator<<(std::ostream &os, const SourceLocationContainer &container)
|
std::ostream &operator<<(std::ostream &os, const SourceLocationContainer &container)
|
||||||
{
|
{
|
||||||
os << "(("
|
os << "(("
|
||||||
<< container.filePathId().directoryId << ", " << container.filePathId().fileNameId << "), "
|
<< container.filePathId().directoryId << ", " << container.filePathId().filePathId << "), "
|
||||||
<< container.line() << ", "
|
<< container.line() << ", "
|
||||||
<< container.column() << ", "
|
<< container.column() << ", "
|
||||||
<< container.offset()
|
<< container.offset()
|
||||||
|
Reference in New Issue
Block a user