diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h index 98e93ad70a4..fabd231395c 100644 --- a/src/libs/clangsupport/refactoringdatabaseinitializer.h +++ b/src/libs/clangsupport/refactoringdatabaseinitializer.h @@ -157,7 +157,7 @@ public: table.addColumn("sourceId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); table.addColumn("size", Sqlite::ColumnType::Integer); table.addColumn("lastModified", Sqlite::ColumnType::Integer); - + table.addColumn("isInPrecompiledHeader", Sqlite::ColumnType::Integer); table.initialize(database); } diff --git a/src/plugins/clangpchmanager/pchmanagernotifierinterface.h b/src/plugins/clangpchmanager/pchmanagernotifierinterface.h index b10ceaab9de..2c6cf4618ce 100644 --- a/src/plugins/clangpchmanager/pchmanagernotifierinterface.h +++ b/src/plugins/clangpchmanager/pchmanagernotifierinterface.h @@ -36,7 +36,7 @@ class PchManagerClient; class PchManagerNotifierInterface { public: - PchManagerNotifierInterface(PchManagerClient &pchManagerClient); + PchManagerNotifierInterface(PchManagerClient &pchManagerClientso); virtual ~PchManagerNotifierInterface(); virtual void precompiledHeaderUpdated(const QString &projectPartId, diff --git a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h index 147da30b357..1defbd11c91 100644 --- a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h +++ b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h @@ -76,9 +76,7 @@ public: const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID( m_sourceManager.getFileID(sourceLocation)); if (fileEntry) { - m_fileStatuses.emplace_back(filePathId(fileEntry), - fileEntry->getSize(), - fileEntry->getModificationTime()); + addFileStatus(fileEntry); addSourceFile(fileEntry); } } @@ -258,16 +256,36 @@ public: } } - void addSourceFile(const clang::FileEntry *file) + void addSourceFile(const clang::FileEntry *fileEntry) { - auto id = filePathId(file); + auto id = filePathId(fileEntry); - auto found = std::find(m_sourceFiles.begin(), m_sourceFiles.end(), id); + auto found = std::lower_bound(m_sourceFiles.begin(), m_sourceFiles.end(), id); if (found == m_sourceFiles.end() || *found != id) m_sourceFiles.insert(found, id); } + void addFileStatus(const clang::FileEntry *fileEntry) + { + auto id = filePathId(fileEntry); + + auto found = std::lower_bound(m_fileStatuses.begin(), + m_fileStatuses.end(), + id, + [] (const auto &first, const auto &second) { + return first.filePathId < second; + }); + + if (found == m_fileStatuses.end() || found->filePathId != id) { + m_fileStatuses.emplace(found, + id, + fileEntry->getSize(), + fileEntry->getModificationTime(), + fileEntry->isInPCH()); + } + } + void addSourceDependency(const clang::FileEntry *file, clang::SourceLocation includeLocation) { auto includeFilePathId = filePathId(includeLocation); diff --git a/src/tools/clangrefactoringbackend/source/filestatus.h b/src/tools/clangrefactoringbackend/source/filestatus.h index ddb8152a52a..d926879f657 100644 --- a/src/tools/clangrefactoringbackend/source/filestatus.h +++ b/src/tools/clangrefactoringbackend/source/filestatus.h @@ -37,11 +37,13 @@ class FileStatus { public: FileStatus(FilePathId filePathId, - off_t size, - std::time_t lastModified) + off_t size, + std::time_t lastModified, + bool isInPrecompiledHeader) : filePathId(filePathId), size(size), - lastModified(lastModified) + lastModified(lastModified), + isInPrecompiledHeader(isInPrecompiledHeader) {} friend @@ -56,6 +58,7 @@ public: FilePathId filePathId; off_t size; std::time_t lastModified; + bool isInPrecompiledHeader; }; using FileStatuses = std::vector; diff --git a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h index 13f1db490fe..c2d2e98f3d4 100644 --- a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h +++ b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h @@ -198,7 +198,7 @@ public: database }; WriteStatement insertFileStatuses{ - "INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified) VALUES (?,?,?)", + "INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)", database }; WriteStatement insertIntoNewSourceDependenciesStatement{ diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index d1870c19988..3da4f9d77fb 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -156,7 +156,8 @@ public: for (const FileStatus &fileStatus : fileStatuses) statement.write(fileStatus.filePathId.filePathId, fileStatus.size, - fileStatus.lastModified); + fileStatus.lastModified, + fileStatus.isInPrecompiledHeader); } static Utils::SmallString toJson(const Utils::SmallStringVector &strings) diff --git a/tests/unit/unittest/mocksqlitewritestatement.h b/tests/unit/unittest/mocksqlitewritestatement.h index c308e19f449..3a823e89677 100644 --- a/tests/unit/unittest/mocksqlitewritestatement.h +++ b/tests/unit/unittest/mocksqlitewritestatement.h @@ -52,6 +52,9 @@ public: MOCK_METHOD4(write, void (uint, uint, uint, uint)); + MOCK_METHOD4(write, + void (long long, int, int, int)); + MOCK_METHOD2(write, void (uint, Utils::SmallStringView)); @@ -82,6 +85,9 @@ public: MOCK_METHOD3(write, void (uint, uint, uint)); + MOCK_METHOD4(write, + void (int, off_t, time_t, bool)); + MOCK_METHOD2(write, void (uint, uint)); diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp index 26a9b7b1a77..adc98c37fed 100644 --- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp +++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp @@ -118,7 +118,7 @@ TEST_F(RefactoringDatabaseInitializer, AddFileStatusesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))); initializer.createFileStatusesTable(); } @@ -154,7 +154,7 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))); EXPECT_CALL(mockDatabase, commit()); diff --git a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp index d3cf655d6bf..c342e90a110 100644 --- a/tests/unit/unittest/storagesqlitestatementfactory-test.cpp +++ b/tests/unit/unittest/storagesqlitestatementfactory-test.cpp @@ -229,7 +229,7 @@ TEST_F(StorageSqliteStatementFactory, DeleteAllInNewUnusedMacros) TEST_F(StorageSqliteStatementFactory, InsertFileStatuses) { ASSERT_THAT(factory.insertFileStatuses.sqlStatement, - Eq("INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified) VALUES (?,?,?)")); + Eq("INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)")); } TEST_F(StorageSqliteStatementFactory, InsertIntoNewSourceDependencies) diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index 02d7b90f57a..239bc04847c 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -100,7 +100,7 @@ protected: SourceLocationEntries sourceLocations{{1, {1, 1}, {42, 23}, SymbolType::Declaration}}; FilePathIds sourceFileIds{{1, 1}, {42, 23}}; UsedMacros usedMacros{{"Foo", {1, 1}}}; - FileStatuses fileStatus{{{1, 2}, 3, 4}}; + FileStatuses fileStatus{{{1, 2}, 3, 4, false}}; SourceDependencies sourceDependencies{{{1, 1}, {1, 2}}, {{1, 1}, {1, 3}}}; ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\",\"BAR\":\"1\"}", "[\"/includes\"]", 74}; NiceMock mockSqliteTransactionBackend; diff --git a/tests/unit/unittest/symbolscollector-test.cpp b/tests/unit/unittest/symbolscollector-test.cpp index 62cafbc37d9..c010940ac34 100644 --- a/tests/unit/unittest/symbolscollector-test.cpp +++ b/tests/unit/unittest/symbolscollector-test.cpp @@ -117,7 +117,7 @@ protected: ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const { - return {filePathId(filePath), fileSize(filePath), lastModified(filePath)}; + return {filePathId(filePath), fileSize(filePath), lastModified(filePath), false}; } SymbolIndex symbolId(const Utils::SmallString &symbolName) diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp index 1e56b98844a..8bdc44c23cf 100644 --- a/tests/unit/unittest/symbolstorage-test.cpp +++ b/tests/unit/unittest/symbolstorage-test.cpp @@ -40,12 +40,14 @@ namespace { using Utils::PathString; +using ClangBackEnd::FilePathId; using ClangBackEnd::FilePathCachingInterface; using ClangBackEnd::SymbolEntries; using ClangBackEnd::SymbolEntry; using ClangBackEnd::SourceLocationEntries; using ClangBackEnd::SourceLocationEntry; using ClangBackEnd::StorageSqliteStatementFactory; +using ClangBackEnd::SymbolIndex; using ClangBackEnd::SymbolType; using Sqlite::Database; using Sqlite::Table; @@ -99,8 +101,8 @@ TEST_F(SymbolStorage, CreateAndFillTemporaryLocationsTable) { InSequence sequence; - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(1, 42, 23, 3)); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(2, 7, 11, 4)); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3))); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4))); storage.fillTemporaryLocationsTable(sourceLocations); } @@ -159,8 +161,8 @@ TEST_F(SymbolStorage, AddSymbolsAndSourceLocationsCallsWrite) InSequence sequence; EXPECT_CALL(insertSymbolsToNewSymbolsStatement, write(An(), An(), _)).Times(2); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(1, 42, 23, 3)); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(2, 7, 11, 4)); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3))); + EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4))); EXPECT_CALL(addNewSymbolsToSymbolsStatement, execute()); EXPECT_CALL(syncNewSymbolsFromSymbolsStatement, execute()); EXPECT_CALL(syncSymbolsIntoNewLocationsStatement, execute()); @@ -245,10 +247,10 @@ TEST_F(SymbolStorage, InsertOrUpdateUsedMacros) TEST_F(SymbolStorage, InsertFileStatuses) { - EXPECT_CALL(insertFileStatuses, write(TypedEq(42), TypedEq(1), TypedEq(2))); - EXPECT_CALL(insertFileStatuses, write(TypedEq(43), TypedEq(4), TypedEq(5))); + EXPECT_CALL(insertFileStatuses, write(TypedEq(42), TypedEq(1), TypedEq(2), TypedEq(false))); + EXPECT_CALL(insertFileStatuses, write(TypedEq(43), TypedEq(4), TypedEq(5), TypedEq(true))); - storage.insertFileStatuses({{{1, 42}, 1, 2}, {{1, 43}, 4, 5}}); + storage.insertFileStatuses({{{1, 42}, 1, 2, false}, {{1, 43}, 4, 5, true}}); } TEST_F(SymbolStorage, InsertOrUpdateSourceDependencies)