data: Cache current file path in PreprocessorCallbacks to avoid lookup for every macro directive
This commit is contained in:
@@ -19,25 +19,29 @@ PreprocessorCallbacks::PreprocessorCallbacks(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PreprocessorCallbacks::FileChanged(
|
void PreprocessorCallbacks::FileChanged(
|
||||||
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID)
|
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID prevID)
|
||||||
{
|
{
|
||||||
if (reason != EnterFile)
|
FilePath filePath;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
|
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
|
||||||
if (!fileEntry)
|
if (fileEntry)
|
||||||
{
|
{
|
||||||
return;
|
filePath = FilePath(fileEntry->getName()).canonical();
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath filePath = FilePath(fileEntry->getName()).canonical();
|
if (!filePath.empty() && m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsParsed(filePath))
|
||||||
|
|
||||||
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->includeFileIsParsed(filePath))
|
|
||||||
{
|
{
|
||||||
m_client->onFileParsed(m_fileRegister->getFileInfo(filePath));
|
m_currentPath = filePath;
|
||||||
m_fileRegister->markIncludeFileParsing(filePath);
|
|
||||||
|
if (reason == EnterFile && !m_fileRegister->includeFileIsParsed(filePath))
|
||||||
|
{
|
||||||
|
m_client->onFileParsed(m_fileRegister->getFileInfo(filePath));
|
||||||
|
m_fileRegister->markIncludeFileParsing(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_currentPath = FilePath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,14 +73,7 @@ void PreprocessorCallbacks::InclusionDirective(
|
|||||||
|
|
||||||
void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, const clang::MacroDirective* macroDirective)
|
void PreprocessorCallbacks::MacroDefined(const clang::Token& macroNameToken, const clang::MacroDirective* macroDirective)
|
||||||
{
|
{
|
||||||
const std::string& fileStr = m_sourceManager.getFilename(macroNameToken.getLocation());
|
if (!m_currentPath.empty())
|
||||||
if (!fileStr.size())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePath filePath = FilePath(fileStr);
|
|
||||||
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsParsed(filePath))
|
|
||||||
{
|
{
|
||||||
// ignore builtin macros
|
// ignore builtin macros
|
||||||
if (m_sourceManager.getSpellingLoc(macroNameToken.getLocation()).printToString(m_sourceManager)[0] == '<')
|
if (m_sourceManager.getSpellingLoc(macroNameToken.getLocation()).printToString(m_sourceManager)[0] == '<')
|
||||||
@@ -124,14 +121,7 @@ void PreprocessorCallbacks::MacroExpands(
|
|||||||
|
|
||||||
void PreprocessorCallbacks::onMacroUsage(const clang::Token& macroNameToken)
|
void PreprocessorCallbacks::onMacroUsage(const clang::Token& macroNameToken)
|
||||||
{
|
{
|
||||||
const std::string& fileStr = m_sourceManager.getFilename(m_sourceManager.getFileLoc(macroNameToken.getLocation()));
|
if (!m_currentPath.empty())
|
||||||
if (!fileStr.size())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePath filePath = FilePath(fileStr);
|
|
||||||
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsParsed(filePath))
|
|
||||||
{
|
{
|
||||||
NameHierarchy nameHierarchy;
|
NameHierarchy nameHierarchy;
|
||||||
nameHierarchy.push(std::make_shared<NameElement>(macroNameToken.getIdentifierInfo()->getName().str()));
|
nameHierarchy.push(std::make_shared<NameElement>(macroNameToken.getIdentifierInfo()->getName().str()));
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "clang/Lex/PPCallbacks.h"
|
#include "clang/Lex/PPCallbacks.h"
|
||||||
#include "clang/Lex/Token.h"
|
#include "clang/Lex/Token.h"
|
||||||
|
|
||||||
|
#include "utility/file/FilePath.h"
|
||||||
|
|
||||||
class FileRegister;
|
class FileRegister;
|
||||||
class ParserClient;
|
class ParserClient;
|
||||||
|
|
||||||
@@ -50,6 +52,8 @@ private:
|
|||||||
const clang::SourceManager& m_sourceManager;
|
const clang::SourceManager& m_sourceManager;
|
||||||
ParserClient* m_client;
|
ParserClient* m_client;
|
||||||
FileRegister* m_fileRegister;
|
FileRegister* m_fileRegister;
|
||||||
|
|
||||||
|
FilePath m_currentPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PREPROCESSOR_CALLBACKS_H
|
#endif // PREPROCESSOR_CALLBACKS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user