data: ClangTool gets invoked for cpp files only, headers are parsed on-the-fly

This change adds the class FileRegister, that splits cpp and h files for the Parser and keeps track which headers have
been parsed yet. TranslationUnits get only created for cpp files now, and headers are parsed on the fly. This reduces
parse time by around half.
This commit is contained in:
Eberhard Graether
2015-03-09 01:32:51 +01:00
parent abddf57004
commit 7014c8ac4c
22 changed files with 290 additions and 115 deletions
@@ -1,18 +1,35 @@
#include "data/parser/cxx/PreprocessorCallbacks.h"
#include "utility/file/FileManager.h"
#include "utility/file/FileRegister.h"
#include "data/parser/ParserClient.h"
#include "data/parser/ParseLocation.h"
PreprocessorCallbacks::PreprocessorCallbacks(
clang::SourceManager& sourceManager, ParserClient* client, FileManager* fileManager
clang::SourceManager& sourceManager, ParserClient* client, FileRegister* fileRegister
)
: m_sourceManager(sourceManager)
, m_client(client)
, m_fileManager(fileManager)
, m_fileRegister(fileRegister)
{
}
void PreprocessorCallbacks::FileChanged(
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID)
{
if (reason != EnterFile)
{
return;
}
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry && m_fileRegister->getFileManager()->hasFilePath(fileEntry->getName()))
{
m_fileRegister->markIncludeFileParsing(fileEntry->getName());
}
}
void PreprocessorCallbacks::InclusionDirective(
clang::SourceLocation hashLocation, const clang::Token& includeToken, llvm::StringRef fileName, bool isAngled,
clang::CharSourceRange fileNameRange, const clang::FileEntry* fileEntry, llvm::StringRef searchPath,
@@ -24,10 +41,10 @@ void PreprocessorCallbacks::InclusionDirective(
std::string baseFilePath = baseFileEntry->getName();
std::string filePath = fileEntry->getName();
if (m_fileManager->hasFilePath(baseFilePath) && m_fileManager->hasFilePath(filePath))
if (m_fileRegister->getFileManager()->hasFilePath(baseFilePath) &&
m_fileRegister->getFileManager()->hasFilePath(filePath))
{
m_client->onFileIncludeParsed(
getParseLocation(fileNameRange.getAsRange()), baseFileEntry->getName(), fileEntry->getName());
m_client->onFileIncludeParsed(getParseLocation(fileNameRange.getAsRange()), baseFilePath, filePath);
}
}
}