From fb0b5d9d9b2b7a342af7f92c2e3eb402e933f767 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 17 Jan 2018 13:52:33 +0100 Subject: [PATCH] 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 --- src/libs/clangsupport/filepathcache.h | 2 +- src/libs/clangsupport/filepathid.cpp | 2 +- src/libs/clangsupport/filepathid.h | 21 +++++++++---------- .../sourcelocationcontainerv2.cpp | 2 +- src/plugins/clangrefactoring/symbolquery.h | 4 ++-- .../source/symbolstorage.h | 2 +- tests/unit/unittest/filepathcache-test.cpp | 12 +++++------ .../unit/unittest/gtest-creator-printing.cpp | 4 ++-- 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/libs/clangsupport/filepathcache.h b/src/libs/clangsupport/filepathcache.h index ebdd2a8aacb..4e2197f0913 100644 --- a/src/libs/clangsupport/filepathcache.h +++ b/src/libs/clangsupport/filepathcache.h @@ -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}; diff --git a/src/libs/clangsupport/filepathid.cpp b/src/libs/clangsupport/filepathid.cpp index 0ed77ef77a1..7d059e0ea27 100644 --- a/src/libs/clangsupport/filepathid.cpp +++ b/src/libs/clangsupport/filepathid.cpp @@ -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; } diff --git a/src/libs/clangsupport/filepathid.h b/src/libs/clangsupport/filepathid.h index 62d73a3004c..95e8fc1b741 100644 --- a/src/libs/clangsupport/filepathid.h +++ b/src/libs/clangsupport/filepathid.h @@ -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; @@ -104,7 +103,7 @@ template<> struct hash { long long hash = filePathId.directoryId; hash = hash << 32; - hash += filePathId.fileNameId; + hash += filePathId.filePathId; return std::hash{}(hash); } diff --git a/src/libs/clangsupport/sourcelocationcontainerv2.cpp b/src/libs/clangsupport/sourcelocationcontainerv2.cpp index 1ddc2d2bd07..ce376b51970 100644 --- a/src/libs/clangsupport/sourcelocationcontainerv2.cpp +++ b/src/libs/clangsupport/sourcelocationcontainerv2.cpp @@ -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; } diff --git a/src/plugins/clangrefactoring/symbolquery.h b/src/plugins/clangrefactoring/symbolquery.h index 9286ca30bb2..7f0b9f33acb 100644 --- a/src/plugins/clangrefactoring/symbolquery.h +++ b/src/plugins/clangrefactoring/symbolquery.h @@ -53,7 +53,7 @@ public: const std::size_t reserveSize = 128; return locationsStatement.template values(reserveSize, - filePathId.fileNameId, + filePathId.filePathId, line, utf8Column); } @@ -65,7 +65,7 @@ public: const std::size_t reserveSize = 128; return locationsStatement.template values(reserveSize, - filePathId.fileNameId, + filePathId.filePathId, line, utf8Column); } diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index b1fdb75d11a..708bf96dfe8 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -86,7 +86,7 @@ public: statement.write(locationsEntry.symbolId, locationsEntry.line, locationsEntry.column, - locationsEntry.filePathId.fileNameId); + locationsEntry.filePathId.filePathId); } } diff --git a/tests/unit/unittest/filepathcache-test.cpp b/tests/unit/unittest/filepathcache-test.cpp index a9cc33ba339..8977ef645c1 100644 --- a/tests/unit/unittest/filepathcache-test.cpp +++ b/tests/unit/unittest/filepathcache-test.cpp @@ -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) diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index dc8edee24b4..f06b6c943b0 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -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()