logic: reduce access to filesystem while indexing

* use canonical filepath cache in cxx indexer
* made constructors of FilePath explicit
* use FilePath at more places instead of string
* forward declares FilePath wherever possible
This commit is contained in:
malte_langkabel
2017-05-04 10:55:16 +02:00
parent 55d3f9c189
commit 054b8fab17
156 changed files with 656 additions and 444 deletions
+1
View File
@@ -56,6 +56,7 @@ add_files(
data/parser/cxx/CxxAstVisitorComponentIndexer.h
data/parser/cxx/CxxAstVisitorComponentTypeRefKind.cpp
data/parser/cxx/CxxAstVisitorComponentTypeRefKind.h
data/parser/cxx/cxxCacheTypes.h
data/parser/cxx/CxxCompilationDatabaseSingle.cpp
data/parser/cxx/CxxCompilationDatabaseSingle.h
data/parser/cxx/CxxContext.cpp
+2 -1
View File
@@ -5,7 +5,8 @@
#include <string>
#include "data/indexer/IndexerCommand.h"
#include "utility/file/FilePath.h"
class FilePath;
class IndexerCommandCxx
: public IndexerCommand
@@ -1,6 +1,5 @@
#include "data/indexer/IndexerCommandCxxManual.h"
std::string IndexerCommandCxxManual::getIndexerKindString()
{
return "CxxManual";
@@ -2,7 +2,8 @@
#define INDEXER_COMMAND_CXX_MANUAL_H
#include "data/indexer/IndexerCommandCxx.h"
#include "utility/file/FilePath.h"
class FilePath;
class IndexerCommandCxxManual
: public IndexerCommandCxx
+11 -4
View File
@@ -8,6 +8,7 @@
#include "clang/Lex/Preprocessor.h"
#include "data/parser/cxx/ASTConsumer.h"
#include "data/parser/cxx/cxxCacheTypes.h"
#include "data/parser/cxx/CommentHandler.h"
#include "data/parser/cxx/PreprocessorCallbacks.h"
#include "utility/file/FileRegister.h"
@@ -17,10 +18,15 @@ class ASTAction
: public ASTActionBase
{
public:
explicit ASTAction(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
explicit ASTAction(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
)
: m_client(client)
, m_fileRegister(fileRegister)
, m_commentHandler(client, fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_commentHandler(client, fileRegister, canonicalFilePathCache)
{}
virtual ~ASTAction() {}
@@ -29,14 +35,14 @@ protected:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile)
{
return std::unique_ptr<clang::ASTConsumer>(
new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_fileRegister));
new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_fileRegister, m_canonicalFilePathCache));
}
virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath)
{
clang::Preprocessor& preprocessor = compiler.getPreprocessor();
preprocessor.addPPCallbacks(
llvm::make_unique<PreprocessorCallbacks>(compiler.getSourceManager(), m_client, m_fileRegister));
llvm::make_unique<PreprocessorCallbacks>(compiler.getSourceManager(), m_client, m_fileRegister, m_canonicalFilePathCache));
preprocessor.addCommentHandler(&m_commentHandler);
return true;
}
@@ -44,6 +50,7 @@ protected:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
CommentHandler m_commentHandler;
};
@@ -3,10 +3,14 @@
#include "clang/Frontend/FrontendActions.h"
ASTActionFactory::ASTActionFactory(
std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister, bool preprocessorOnly
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
bool preprocessorOnly
)
: m_client(client)
, m_fileRegister(fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_preprocessorOnly(preprocessorOnly)
{
}
@@ -19,10 +23,10 @@ clang::FrontendAction* ASTActionFactory::create()
{
if (m_preprocessorOnly)
{
return new ASTAction<clang::PreprocessOnlyAction>(m_client, m_fileRegister);
return new ASTAction<clang::PreprocessOnlyAction>(m_client, m_fileRegister, m_canonicalFilePathCache);
}
else
{
return new ASTAction<clang::ASTFrontendAction>(m_client, m_fileRegister);
return new ASTAction<clang::ASTFrontendAction>(m_client, m_fileRegister, m_canonicalFilePathCache);
}
}
@@ -4,6 +4,7 @@
#include "clang/Tooling/Tooling.h"
#include "data/parser/cxx/ASTAction.h"
#include "data/parser/cxx/cxxCacheTypes.h"
#include "utility/file/FileRegister.h"
class ASTActionFactory
@@ -11,7 +12,12 @@ class ASTActionFactory
{
public:
explicit ASTActionFactory(
std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister, bool preprocessorOnly);
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
bool preprocessorOnly
);
virtual ~ASTActionFactory();
virtual clang::FrontendAction* create();
@@ -19,6 +25,7 @@ public:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
bool m_preprocessorOnly;
};
+9 -3
View File
@@ -3,15 +3,21 @@
#include "data/parser/cxx/CxxVerboseAstVisitor.h"
#include "settings/ApplicationSettings.h"
ASTConsumer::ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
ASTConsumer::ASTConsumer(
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
)
{
if (ApplicationSettings::getInstance()->getLoggingEnabled() && ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled())
{
m_visitor = std::make_shared<CxxVerboseAstVisitor>(context, preprocessor, client, fileRegister);
m_visitor = std::make_shared<CxxVerboseAstVisitor>(context, preprocessor, client, fileRegister, canonicalFilePathCache);
}
else
{
m_visitor = std::make_shared<CxxAstVisitor>(context, preprocessor, client, fileRegister);
m_visitor = std::make_shared<CxxAstVisitor>(context, preprocessor, client, fileRegister, canonicalFilePathCache);
}
}
+9 -1
View File
@@ -4,6 +4,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "data/parser/cxx/cxxCacheTypes.h"
class CxxAstVisitor;
class FileRegister;
@@ -13,7 +14,14 @@ class ASTConsumer
: public clang::ASTConsumer
{
public:
explicit ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
explicit ASTConsumer(
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
);
virtual ~ASTConsumer();
virtual void HandleTranslationUnit(clang::ASTContext& context);
@@ -4,9 +4,14 @@
#include "data/parser/ParserClient.h"
#include "utility/file/FileRegister.h"
CommentHandler::CommentHandler(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
CommentHandler::CommentHandler(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
)
: m_client(client)
, m_fileRegister(fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
{
}
@@ -20,11 +25,11 @@ bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::Sou
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
FilePath filePath = FilePath(presumedBegin.getFilename());
FilePath filePath = m_canonicalFilePathCache->getValue(presumedBegin.getFilename());
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsIndexed(filePath))
{
m_client->onCommentParsed(ParseLocation(
presumedBegin.getFilename(),
filePath,
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
+9 -1
View File
@@ -3,6 +3,8 @@
#include "clang/Lex/Preprocessor.h"
#include "data/parser/cxx/cxxCacheTypes.h"
class FileRegister;
class ParserClient;
@@ -10,7 +12,12 @@ class CommentHandler
: public clang::CommentHandler
{
public:
CommentHandler(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
CommentHandler(
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
);
virtual ~CommentHandler();
virtual bool HandleComment(clang::Preprocessor& preprocessor, clang::SourceRange sourceRange);
@@ -18,6 +25,7 @@ public:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
};
#endif // COMMENT_HANDLER_H
+31 -17
View File
@@ -17,36 +17,45 @@
#include "data/parser/ParseLocation.h"
CxxAstVisitor::CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
CxxAstVisitor::CxxAstVisitor(
clang::ASTContext* astContext,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
)
: m_astContext(astContext)
, m_preprocessor(preprocessor)
, m_client(client)
, m_fileRegister(fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
{
m_declNameCache = std::make_shared<DeclNameCache>([](const clang::NamedDecl* decl) -> NameHierarchy
{
if (decl)
{
CxxDeclNameResolver resolver;
if (std::shared_ptr<CxxDeclName> declName = resolver.getName(decl))
if (decl)
{
return declName->toNameHierarchy();
CxxDeclNameResolver resolver;
if (std::shared_ptr<CxxDeclName> declName = resolver.getName(decl))
{
return declName->toNameHierarchy();
}
}
return NameHierarchy("global");
}
return NameHierarchy("global");
});
);
m_typeNameCache = std::make_shared<TypeNameCache>([](const clang::Type* type) -> NameHierarchy
{
if (type)
{
CxxTypeNameResolver resolver;
if (std::shared_ptr<CxxTypeName> typeName = resolver.getName(type))
if (type)
{
return typeName->toNameHierarchy();
CxxTypeNameResolver resolver;
if (std::shared_ptr<CxxTypeName> typeName = resolver.getName(type))
{
return typeName->toNameHierarchy();
}
}
return NameHierarchy("global");
}
return NameHierarchy("global");
});
);
m_contextComponent = std::make_shared<CxxAstVisitorComponentContext>(this);
m_components.push_back(m_contextComponent);
@@ -98,6 +107,11 @@ std::shared_ptr<TypeNameCache> CxxAstVisitor::getTypeNameCache()
return m_typeNameCache;
}
std::shared_ptr<FilePathCache> CxxAstVisitor::getCanonicalFilePathCache()
{
return m_canonicalFilePathCache;
}
void CxxAstVisitor::indexDecl(clang::Decl* d)
{
this->TraverseDecl(d);
@@ -638,7 +652,7 @@ ParseLocation CxxAstVisitor::getParseLocation(const clang::SourceLocation& loc)
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
{
parseLocation.filePath = FilePath(fileEntry->getName()).canonical();
parseLocation.filePath = m_canonicalFilePathCache->getValue(fileEntry->getName());
}
}
@@ -672,7 +686,7 @@ ParseLocation CxxAstVisitor::getParseLocation(const clang::SourceRange& sourceRa
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
parseLocation = ParseLocation(
presumedBegin.getFilename(),
m_canonicalFilePathCache->getValue(presumedBegin.getFilename()),
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
+12 -2
View File
@@ -5,13 +5,14 @@
#include <clang/AST/RecursiveASTVisitor.h>
#include "data/parser/cxx/cxxCacheTypes.h"
#include "data/parser/cxx/CxxContext.h"
#include "utility/messaging/MessageInterruptTasksCounter.h"
#include "utility/Cache.h"
class ParserClient;
struct ParseLocation;
class FileRegister;
class FilePath;
class CxxAstVisitorComponent;
class CxxAstVisitorComponentContext;
@@ -20,6 +21,7 @@ class CxxAstVisitorComponentTypeRefKind;
class CxxAstVisitorComponentImplicitCode;
class CxxAstVisitorComponentIndexer;
// methods are called in this order:
// TraverseDecl()
// `- TraverseFunctionDecl()
@@ -34,7 +36,13 @@ class CxxAstVisitorComponentIndexer;
class CxxAstVisitor: public clang::RecursiveASTVisitor<CxxAstVisitor>
{
public:
CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
CxxAstVisitor(
clang::ASTContext* astContext,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
);
virtual ~CxxAstVisitor();
template <typename T>
@@ -42,6 +50,7 @@ public:
std::shared_ptr<DeclNameCache> getDeclNameCache();
std::shared_ptr<TypeNameCache> getTypeNameCache();
std::shared_ptr<FilePathCache> getCanonicalFilePathCache();
// Indexing entry point
void indexDecl(clang::Decl *d);
@@ -139,6 +148,7 @@ private:
clang::Preprocessor* m_preprocessor;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
MessageInterruptTasksCounter m_interruptCounter;
@@ -767,8 +767,7 @@ bool CxxAstVisitorComponentIndexer::isLocatedInUnparsedProjectFile(clang::Source
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
{
std::string fileName = fileEntry->getName();
FilePath filePath = FilePath(fileName).canonical();
FilePath filePath = getAstVisitor()->getCanonicalFilePathCache()->getValue(fileEntry->getName());
if (m_fileRegister->hasFilePath(filePath))
{
@@ -807,8 +806,8 @@ bool CxxAstVisitorComponentIndexer::isLocatedInProjectFile(clang::SourceLocation
if (fileEntry != NULL)
{
std::string fileName = fileEntry->getName();
FilePath filePath = FilePath(fileName).canonical();
bool ret = m_fileRegister->hasFilePath(filePath.str());
FilePath filePath = getAstVisitor()->getCanonicalFilePathCache()->getValue(fileName);
bool ret = m_fileRegister->hasFilePath(filePath);
m_inProjectFileMap[fileId] = ret;
return ret;
}
@@ -12,11 +12,13 @@ CxxDiagnosticConsumer::CxxDiagnosticConsumer(
clang::DiagnosticOptions *diags,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
bool useLogging
)
: clang::TextDiagnosticPrinter(os, diags)
, m_client(client)
, m_register(fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
, m_isParsingFile(false)
, m_useLogging(useLogging)
{
@@ -79,7 +81,7 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
column = presumedLocation.getColumn();
}
ParseLocation location(filePath, line, column);
ParseLocation location(m_canonicalFilePathCache->getValue(filePath), line, column);
m_client->onErrorParsed(
location,
@@ -3,6 +3,8 @@
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "data/parser/cxx/cxxCacheTypes.h"
class FileRegister;
class ParserClient;
@@ -15,6 +17,7 @@ public:
clang::DiagnosticOptions *diags,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache,
bool useLogging = true
);
@@ -26,6 +29,7 @@ public:
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_register;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
bool m_isParsingFile;
bool m_useLogging;
+27 -8
View File
@@ -2,6 +2,7 @@
#include "clang/Tooling/Tooling.h"
#include "utility/file/FilePath.h"
#include "utility/file/FileRegister.h"
#include "utility/logging/logging.h"
#include "utility/text/TextAccess.h"
@@ -81,10 +82,16 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
CxxCompilationDatabaseSingle compilationDatabase(compileCommand);
clang::tooling::ClangTool tool(compilationDatabase, std::vector<std::string>(1, indexerCommand->getSourceFilePath().str()));
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(true);
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, true);
tool.setDiagnosticConsumer(diagnostics.get());
ASTActionFactory actionFactory(m_client, m_fileRegister, indexerCommand->preprocessorOnly());
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache, indexerCommand->preprocessorOnly());
tool.run(&actionFactory);
}
@@ -94,17 +101,29 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerComma
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, indexerCommand->getSourceFilePath().str()));
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(true);
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, true);
tool.setDiagnosticConsumer(diagnostics.get());
ASTActionFactory actionFactory(m_client, m_fileRegister, indexerCommand->preprocessorOnly());
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache, indexerCommand->preprocessorOnly());
tool.run(&actionFactory);
}
void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent)
{
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(false);
ASTActionFactory actionFactory(m_client, m_fileRegister, false);
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, false);
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache, false);
std::vector<std::string> args = getCommandlineArgumentsEssential(std::vector<std::string>(1, "-std=c++1z"), std::vector<FilePath>(), std::vector<FilePath>());
@@ -201,9 +220,9 @@ std::shared_ptr<clang::tooling::FixedCompilationDatabase> CxxParser::getCompilat
return compilationDatabase;
}
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(bool logErrors) const
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(std::shared_ptr<FilePathCache> canonicalFilePathCache, bool logErrors) const
{
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
return std::make_shared<CxxDiagnosticConsumer>(
llvm::errs(), &*options, m_client, m_fileRegister, logErrors);
llvm::errs(), &*options, m_client, m_fileRegister, canonicalFilePathCache, logErrors);
}
+3 -1
View File
@@ -1,10 +1,12 @@
#ifndef CXX_PARSER_H
#define CXX_PARSER_H
#include "data/parser/cxx/cxxCacheTypes.h"
#include "data/parser/cxx/CxxCompilationDatabaseSingle.h"
#include "data/parser/Parser.h"
class CxxDiagnosticConsumer;
class FilePath;
class FileRegister;
class IndexerCommandCxxCdb;
class IndexerCommandCxxManual;
@@ -29,7 +31,7 @@ private:
std::vector<std::string> getCommandlineArguments(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const;
std::shared_ptr<clang::tooling::FixedCompilationDatabase> getCompilationDatabase(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const;
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(bool logErrors) const;
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(std::shared_ptr<FilePathCache> canonicalFilePathCache, bool logErrors) const;
friend class TaskParseCxx;
@@ -12,8 +12,14 @@
#include "utility/logging/logging.h"
#include "utility/ScopedSwitcher.h"
CxxVerboseAstVisitor::CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: base(context, preprocessor, client, fileRegister)
CxxVerboseAstVisitor::CxxVerboseAstVisitor(
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
)
: base(context, preprocessor, client, fileRegister, canonicalFilePathCache)
, m_currentFilePath("")
, m_indentation(0)
{
@@ -11,7 +11,14 @@ class FileRegister;
class CxxVerboseAstVisitor: public CxxAstVisitor
{
public:
CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
CxxVerboseAstVisitor(
clang::ASTContext* context,
clang::Preprocessor* preprocessor,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
);
virtual ~CxxVerboseAstVisitor();
private:
@@ -11,11 +11,15 @@
#include "data/parser/ParseLocation.h"
PreprocessorCallbacks::PreprocessorCallbacks(
clang::SourceManager& sourceManager, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister
clang::SourceManager& sourceManager,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache
)
: m_sourceManager(sourceManager)
, m_client(client)
, m_fileRegister(fileRegister)
, m_canonicalFilePathCache(canonicalFilePathCache)
{
}
@@ -29,7 +33,7 @@ void PreprocessorCallbacks::FileChanged(
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
if (fileEntry)
{
filePath = FilePath(fileEntry->getName()).canonical();
filePath = m_canonicalFilePathCache->getValue(fileEntry->getName());
}
if (!filePath.empty() && m_fileRegister->hasFilePath(filePath))
@@ -55,7 +59,7 @@ void PreprocessorCallbacks::InclusionDirective(
){
if (!m_currentPath.empty() && fileEntry)
{
FilePath includedFilePath = FilePath(fileEntry->getName()).canonical();
FilePath includedFilePath = m_canonicalFilePathCache->getValue(fileEntry->getName());
if (m_fileRegister->hasFilePath(includedFilePath))
{
const NameHierarchy referencedNameHierarchy(includedFilePath.str());
@@ -148,7 +152,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::Token& macroN
const clang::SourceLocation& endLocation = m_sourceManager.getSpellingLoc(macroNameTok.getEndLoc());
return ParseLocation(
m_sourceManager.getFilename(location).str(),
m_canonicalFilePathCache->getValue(m_sourceManager.getFilename(location).str()),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
@@ -162,7 +166,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::MacroInfo* ma
clang::SourceLocation endLocation = macroInfo->getDefinitionEndLoc();
return ParseLocation(
m_sourceManager.getFilename(location).str(),
m_canonicalFilePathCache->getValue(m_sourceManager.getFilename(location).str()),
m_sourceManager.getSpellingLineNumber(location),
m_sourceManager.getSpellingColumnNumber(location),
m_sourceManager.getSpellingLineNumber(endLocation),
@@ -181,7 +185,7 @@ ParseLocation PreprocessorCallbacks::getParseLocation(const clang::SourceRange&
const clang::PresumedLoc& presumedEnd = m_sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
return ParseLocation(
presumedBegin.getFilename(),
m_canonicalFilePathCache->getValue(presumedBegin.getFilename()),
presumedBegin.getLine(),
presumedBegin.getColumn(),
presumedEnd.getLine(),
@@ -8,6 +8,7 @@
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Token.h"
#include "data/parser/cxx/cxxCacheTypes.h"
#include "utility/file/FilePath.h"
class FileRegister;
@@ -19,7 +20,11 @@ class PreprocessorCallbacks
: public clang::PPCallbacks
{
public:
explicit PreprocessorCallbacks(clang::SourceManager& sourceManager, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
explicit PreprocessorCallbacks(
clang::SourceManager& sourceManager,
std::shared_ptr<ParserClient> client,
std::shared_ptr<FileRegister> fileRegister,
std::shared_ptr<FilePathCache> canonicalFilePathCache);
virtual void FileChanged(
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID);
@@ -54,6 +59,7 @@ private:
const clang::SourceManager& m_sourceManager;
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
FilePath m_currentPath;
};
@@ -0,0 +1,11 @@
#ifndef CXX_CACHE_TYPES_H
#define CXX_CACHE_TYPES_H
#include <string>
#include "utility/Cache.h"
class FilePath;
typedef Cache<std::string, FilePath> FilePathCache;
#endif // CXX_CACHE_TYPES_H
+3 -1
View File
@@ -1,8 +1,10 @@
#include "utility/CompilationDatabase.h"
#include <set>
#include "utility/utility.h"
#include "clang/Tooling/JSONCompilationDatabase.h"
#include "utility/file/FilePath.h"
#include "utility/utility.h"
utility::CompilationDatabase::CompilationDatabase(std::string filename)
: m_filename(filename)
+1 -1
View File
@@ -3,7 +3,7 @@
#include <vector>
#include "utility/file/FilePath.h"
class FilePath;
namespace utility
{