Clang: Clear used macros and file information for symbol collection

We have to clear them too otherwise we will collect them which can lead
to wrong data in the symbol database.

Change-Id: Iad7b87344caec0f27a5f8f24c214573a274db911
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-01-31 12:32:14 +01:00
parent 89b9dfed84
commit b2d3951bde
3 changed files with 44 additions and 2 deletions

View File

@@ -60,9 +60,11 @@ public:
m_sourceFiles = filePathIds;
}
void clearSourceFiles()
void clear()
{
m_sourceFiles.clear();
m_usedMacros.clear();
m_fileInformations.clear();
}
const UsedMacros &usedMacros() const

View File

@@ -48,7 +48,7 @@ void SymbolsCollector::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
void SymbolsCollector::clear()
{
m_collectMacrosSourceFileCallbacks.clearSourceFiles();
m_collectMacrosSourceFileCallbacks.clear();
m_symbolEntries.clear();
m_sourceLocationEntries.clear();
m_clangTool = ClangTool();

View File

@@ -303,6 +303,26 @@ TEST_F(SymbolsCollector, ClearSourceLocations)
ASSERT_THAT(collector.sourceLocations(), IsEmpty());
}
TEST_F(SymbolsCollector, ClearFileInformation)
{
collector.addFiles({filePathId(TESTDATA_DIR "/symbolscollector_main.cpp")}, {"cc"});
collector.collectSymbols();
collector.clear();
ASSERT_THAT(collector.fileInformations(), IsEmpty());
}
TEST_F(SymbolsCollector, ClearUsedMacros)
{
collector.addFiles({filePathId(TESTDATA_DIR "/symbolscollector_defines.h")}, {"cc"});
collector.collectSymbols();
collector.clear();
ASSERT_THAT(collector.usedMacros(), IsEmpty());
}
TEST_F(SymbolsCollector, DontCollectSymbolsAfterFilesAreCleared)
{
collector.addFiles({filePathId(TESTDATA_DIR "/symbolscollector_main.cpp")}, {"cc"});
@@ -323,6 +343,26 @@ TEST_F(SymbolsCollector, DontCollectSourceFilesAfterFilesAreCleared)
ASSERT_THAT(collector.sourceFiles(), IsEmpty());
}
TEST_F(SymbolsCollector, DontCollectFileInformationAfterFilesAreCleared)
{
collector.addFiles({filePathId(TESTDATA_DIR "/symbolscollector_main.cpp")}, {"cc"});
collector.clear();
collector.collectSymbols();
ASSERT_THAT(collector.fileInformations(), IsEmpty());
}
TEST_F(SymbolsCollector, DontCollectUsedMacrosAfterFilesAreCleared)
{
collector.addFiles({filePathId(TESTDATA_DIR "/symbolscollector_main.cpp")}, {"cc"});
collector.clear();
collector.collectSymbols();
ASSERT_THAT(collector.usedMacros(), IsEmpty());
}
TEST_F(SymbolsCollector, CollectUsedMacrosWithExternalDefine)
{
auto fileId = filePathId(TESTDATA_DIR "/symbolscollector_defines.h");