logic: skip recording macro usages in non-indexed files

This commit is contained in:
mlangkabel
2017-11-03 16:20:31 +01:00
parent 8baf8cd49b
commit 09694409f1
59 changed files with 255050 additions and 1102 deletions
@@ -131,7 +131,7 @@ void PreprocessorCallbacks::MacroExpands(
void PreprocessorCallbacks::onMacroUsage(const clang::Token& macroNameToken)
{
if (!m_currentPath.empty())
if (!m_currentPath.empty() && isLocatedInProjectFile(macroNameToken.getLocation()))
{
const ParseLocation loc = getParseLocation(macroNameToken);
@@ -208,3 +208,36 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::SourceRange&
}
return ParseLocation();
}
bool PreprocessorCallbacks::isLocatedInProjectFile(const clang::SourceLocation loc)
{
clang::SourceLocation spellingLoc = m_sourceManager.getSpellingLoc(loc);
clang::FileID fileId;
if (spellingLoc.isValid())
{
fileId = m_sourceManager.getFileID(spellingLoc);
}
if (!fileId.isInvalid())
{
auto it = m_inProjectFileMap.find(fileId);
if (it != m_inProjectFileMap.end())
{
return it->second;
}
const clang::FileEntry* fileEntry = m_sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
{
FilePath filePath =
m_canonicalFilePathCache->getValue(utility::getFileNameOfFileEntry(fileEntry));
bool ret = m_fileRegister->hasFilePath(filePath);
m_inProjectFileMap[fileId] = ret;
return ret;
}
}
return false;
}
@@ -53,16 +53,26 @@ public:
) override;
private:
struct FileIdHash
{
size_t operator()(clang::FileID fileID) const
{
return fileID.getHashValue();
}
};
void onMacroUsage(const clang::Token& macroNameToken);
ParseLocation getParseLocation(const clang::Token& macroNameToc) const;
ParseLocation getParseLocation(const clang::MacroInfo* macroNameToc) const;
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
bool isLocatedInProjectFile(const clang::SourceLocation loc);
const clang::SourceManager& m_sourceManager;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inProjectFileMap;
FilePath m_currentPath;
};
+1 -1
View File
@@ -90,7 +90,7 @@ public:
private:
void processSourceFile(const std::string& projectName, const FilePath& sourceFilePath, const bool updateExpectedOutput)
{
const FilePath projectDataRoot = FilePath("data/CxxIndexSampleProjectsTestSuite/" + projectName);
const FilePath projectDataRoot = FilePath("data/CxxIndexSampleProjectsTestSuite/" + projectName).absolute();
const FilePath projectDataSrcRoot = projectDataRoot.concat(FilePath("src"));
const FilePath projectDataExpectedOutputRoot = projectDataRoot.concat(FilePath("expected_output"));