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:
Marco Bubke
2018-01-17 13:52:33 +01:00
parent aefc8cd693
commit fb0b5d9d9b
8 changed files with 24 additions and 25 deletions

View File

@@ -85,7 +85,7 @@ public:
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);
return FilePath{directoryPath, fileName};

View File

@@ -31,7 +31,7 @@ namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const FilePathId &filePathId)
{
debug.nospace() << "(" << filePathId.directoryId << ", " << filePathId.fileNameId << ")";
debug.nospace() << "(" << filePathId.directoryId << ", " << filePathId.filePathId << ")";
return debug;
}

View File

@@ -39,14 +39,14 @@ class FilePathId
{
public:
FilePathId() = default;
FilePathId(int directoryId, int fileNameId)
FilePathId(int directoryId, int filePathId)
: directoryId(directoryId),
fileNameId(fileNameId)
filePathId(filePathId)
{}
bool isValid() const
{
return directoryId >= 0 && fileNameId >= 0;
return directoryId >= 0 && filePathId >= 0;
}
friend bool operator==(FilePathId first, FilePathId second)
@@ -54,7 +54,7 @@ public:
return first.isValid()
&& second.isValid()
&& first.directoryId == second.directoryId
&& first.fileNameId == second.fileNameId;
&& first.filePathId == second.filePathId;
}
friend bool operator!=(FilePathId first, FilePathId second)
@@ -64,14 +64,14 @@ public:
friend bool operator<(FilePathId first, FilePathId second)
{
return std::tie(first.directoryId, first.fileNameId)
< std::tie(second.directoryId, second.fileNameId);
return std::tie(first.directoryId, first.filePathId)
< std::tie(second.directoryId, second.filePathId);
}
friend QDataStream &operator<<(QDataStream &out, const FilePathId &filePathId)
{
out << filePathId.directoryId;
out << filePathId.fileNameId;
out << filePathId.filePathId;
return out;
}
@@ -79,15 +79,14 @@ public:
friend QDataStream &operator>>(QDataStream &in, FilePathId &filePathId)
{
in >> filePathId.directoryId;
in >> filePathId.fileNameId;
in >> filePathId.filePathId;
return in;
}
public:
int directoryId = -1;
int fileNameId = -1;
int filePathId = -1;
};
using FilePathIds = std::vector<FilePathId>;
@@ -104,7 +103,7 @@ template<> struct hash<ClangBackEnd::FilePathId>
{
long long hash = filePathId.directoryId;
hash = hash << 32;
hash += filePathId.fileNameId;
hash += filePathId.filePathId;
return std::hash<long long>{}(hash);
}

View File

@@ -36,7 +36,7 @@ QDebug operator<<(QDebug debug, const SourceLocationContainer &container)
<< container.line() << ", "
<< container.column() << ", "
<< container.offset() << ", "
<< container.filePathId().fileNameId
<< container.filePathId().filePathId
<< ")";
return debug;
}

View File

@@ -53,7 +53,7 @@ public:
const std::size_t reserveSize = 128;
return locationsStatement.template values<SourceLocation, 4>(reserveSize,
filePathId.fileNameId,
filePathId.filePathId,
line,
utf8Column);
}
@@ -65,7 +65,7 @@ public:
const std::size_t reserveSize = 128;
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
filePathId.fileNameId,
filePathId.filePathId,
line,
utf8Column);
}

View File

@@ -86,7 +86,7 @@ public:
statement.write(locationsEntry.symbolId,
locationsEntry.line,
locationsEntry.column,
locationsEntry.filePathId.fileNameId);
locationsEntry.filePathId.filePathId);
}
}

View File

@@ -68,11 +68,11 @@ TEST_F(FilePathCache, DirectoryIdOfFilePathIdWithOutAnyEntry)
ASSERT_THAT(filePathId.directoryId, 5);
}
TEST_F(FilePathCache, FileNameIdOfFilePathIdWithOutAnyEntry)
TEST_F(FilePathCache, FilePathIdOfFilePathIdWithOutAnyEntry)
{
auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp"));
ASSERT_THAT(filePathId.fileNameId, 42);
ASSERT_THAT(filePathId.filePathId, 42);
}
TEST_F(FilePathCache, IfEntryExistsDontCallInStrorage)
@@ -95,22 +95,22 @@ TEST_F(FilePathCache, IfDirectoryEntryExistsDontCallFetchDirectoryIdButStillCal
cache.filePathId(FilePathView("/path/to/file.cpp"));
}
TEST_F(FilePathCache, GetFileNameIdWithCachedValue)
TEST_F(FilePathCache, GetFilePathIdWithCachedValue)
{
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"));
auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp"));
ASSERT_THAT(filePathId.fileNameId, 63);
ASSERT_THAT(filePathId.filePathId, 63);
}
TEST_F(FilePathCache, GetDirectyIdWithCachedValue)

View File

@@ -130,7 +130,7 @@ namespace ClangBackEnd {
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)
@@ -827,7 +827,7 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &containe
std::ostream &operator<<(std::ostream &os, const SourceLocationContainer &container)
{
os << "(("
<< container.filePathId().directoryId << ", " << container.filePathId().fileNameId << "), "
<< container.filePathId().directoryId << ", " << container.filePathId().filePathId << "), "
<< container.line() << ", "
<< container.column() << ", "
<< container.offset()