logic: indexer commands
* replaced parser arguments by project specific IndexerCommands that know everything the indexer needs to know to do its job * added different language and project specific indexers that know how to handle a certain kind of indexer command * refactored FileManager and FileRegister to have less overhead * removed no-rtti restriction for clang files in lib cxx * uncommented deprecated interprocess code. fortune cookie message = Happiness will bring you good luck.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "data/parser/cxx/CommentHandler.h"
|
||||
#include "data/parser/cxx/PreprocessorCallbacks.h"
|
||||
|
||||
ASTAction::ASTAction(ParserClient* client, FileRegister* fileRegister)
|
||||
ASTAction::ASTAction(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: m_client(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_commentHandler(client, fileRegister)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef AST_ACTION_H
|
||||
#define AST_ACTION_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
#include "clang/Frontend/FrontendAction.h"
|
||||
|
||||
@@ -11,7 +13,7 @@
|
||||
class ASTAction : public clang::ASTFrontendAction
|
||||
{
|
||||
public:
|
||||
explicit ASTAction(ParserClient* client, FileRegister* fileRegister);
|
||||
explicit ASTAction(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~ASTAction();
|
||||
|
||||
protected:
|
||||
@@ -20,8 +22,8 @@ protected:
|
||||
virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath);
|
||||
|
||||
private:
|
||||
ParserClient* m_client;
|
||||
FileRegister* m_fileRegister;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
CommentHandler m_commentHandler;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "data/parser/cxx/ASTActionFactory.h"
|
||||
|
||||
ASTActionFactory::ASTActionFactory(ParserClient* client, FileRegister* fileRegister)
|
||||
ASTActionFactory::ASTActionFactory(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: m_client(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
{
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
class ASTActionFactory : public clang::tooling::FrontendActionFactory
|
||||
{
|
||||
public:
|
||||
explicit ASTActionFactory(ParserClient* client, FileRegister* fileRegister);
|
||||
explicit ASTActionFactory(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~ASTActionFactory();
|
||||
|
||||
virtual clang::FrontendAction* create();
|
||||
|
||||
private:
|
||||
ParserClient* m_client;
|
||||
FileRegister* m_fileRegister;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
};
|
||||
|
||||
#endif // AST_ACTION_FACTORY
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "data/parser/cxx/CxxVerboseAstVisitor.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
|
||||
ASTConsumer::ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister)
|
||||
ASTConsumer::ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
{
|
||||
if (ApplicationSettings::getInstance()->getLoggingEnabled() && ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled())
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ class ASTConsumer
|
||||
: public clang::ASTConsumer
|
||||
{
|
||||
public:
|
||||
explicit ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister);
|
||||
explicit ASTConsumer(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~ASTConsumer();
|
||||
|
||||
virtual void HandleTranslationUnit(clang::ASTContext& context);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
CommentHandler::CommentHandler(ParserClient* client, FileRegister* fileRegister)
|
||||
CommentHandler::CommentHandler(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: m_client(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
{
|
||||
@@ -21,7 +21,7 @@ bool CommentHandler::HandleComment(clang::Preprocessor& preprocessor, clang::Sou
|
||||
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
|
||||
|
||||
FilePath filePath = FilePath(presumedBegin.getFilename());
|
||||
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsParsed(filePath))
|
||||
if (m_fileRegister->hasFilePath(filePath) && !m_fileRegister->fileIsIndexed(filePath))
|
||||
{
|
||||
m_client->onCommentParsed(ParseLocation(
|
||||
presumedBegin.getFilename(),
|
||||
|
||||
@@ -10,14 +10,14 @@ class CommentHandler
|
||||
: public clang::CommentHandler
|
||||
{
|
||||
public:
|
||||
CommentHandler(ParserClient* client, FileRegister* fileRegister);
|
||||
CommentHandler(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~CommentHandler();
|
||||
|
||||
virtual bool HandleComment(clang::Preprocessor& preprocessor, clang::SourceRange sourceRange);
|
||||
|
||||
private:
|
||||
ParserClient* m_client;
|
||||
FileRegister* m_fileRegister;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
};
|
||||
|
||||
#endif // COMMENT_HANDLER_H
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "data/parser/ParseLocation.h"
|
||||
|
||||
CxxAstVisitor::CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister)
|
||||
CxxAstVisitor::CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: m_astContext(astContext)
|
||||
, m_preprocessor(preprocessor)
|
||||
, m_client(client)
|
||||
|
||||
@@ -33,7 +33,7 @@ class CxxAstVisitorComponentIndexer;
|
||||
class CxxAstVisitor: public clang::RecursiveASTVisitor<CxxAstVisitor>
|
||||
{
|
||||
public:
|
||||
CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister);
|
||||
CxxAstVisitor(clang::ASTContext* astContext, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~CxxAstVisitor();
|
||||
|
||||
template <typename T>
|
||||
@@ -134,8 +134,8 @@ private:
|
||||
|
||||
clang::ASTContext* m_astContext;
|
||||
clang::Preprocessor* m_preprocessor;
|
||||
ParserClient* m_client;
|
||||
FileRegister* m_fileRegister;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
MessageInterruptTasksCounter m_interruptCounter;
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
CxxAstVisitorComponentIndexer::CxxAstVisitorComponentIndexer(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, ParserClient* client, FileRegister* fileRegister)
|
||||
CxxAstVisitorComponentIndexer::CxxAstVisitorComponentIndexer(
|
||||
CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister
|
||||
)
|
||||
: CxxAstVisitorComponent(astVisitor)
|
||||
, m_astContext(astContext)
|
||||
, m_client(client)
|
||||
@@ -768,9 +770,9 @@ bool CxxAstVisitorComponentIndexer::isLocatedInUnparsedProjectFile(clang::Source
|
||||
std::string fileName = fileEntry->getName();
|
||||
FilePath filePath = FilePath(fileName).canonical();
|
||||
|
||||
if (m_fileRegister->hasIncludeFile(filePath))
|
||||
if (m_fileRegister->hasFilePath(filePath))
|
||||
{
|
||||
ret = !(m_fileRegister->includeFileIsParsed(filePath));
|
||||
ret = !(m_fileRegister->fileIsIndexed(filePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
class CxxAstVisitorComponentIndexer: public CxxAstVisitorComponent
|
||||
{
|
||||
public:
|
||||
CxxAstVisitorComponentIndexer(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, ParserClient* client, FileRegister* fileRegister);
|
||||
CxxAstVisitorComponentIndexer(CxxAstVisitor* astVisitor, clang::ASTContext* astContext, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~CxxAstVisitorComponentIndexer();
|
||||
|
||||
virtual void beginTraverseNestedNameSpecifierLoc(const clang::NestedNameSpecifierLoc& loc);
|
||||
@@ -68,8 +68,8 @@ private:
|
||||
bool isLocatedInProjectFile(clang::SourceLocation loc);
|
||||
|
||||
clang::ASTContext* m_astContext;
|
||||
ParserClient* m_client;
|
||||
FileRegister* m_fileRegister;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inUnparsedProjectFileMap;
|
||||
std::unordered_map<const clang::FileID, bool, FileIdHash> m_inProjectFileMap;
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
CxxDiagnosticConsumer::CxxDiagnosticConsumer(
|
||||
clang::raw_ostream &os,
|
||||
clang::DiagnosticOptions *diags,
|
||||
ParserClient* client,
|
||||
FileRegister* fileRegister,
|
||||
std::shared_ptr<ParserClient> client,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
bool useLogging
|
||||
)
|
||||
: clang::TextDiagnosticPrinter(os, diags)
|
||||
|
||||
@@ -13,8 +13,8 @@ public:
|
||||
CxxDiagnosticConsumer(
|
||||
clang::raw_ostream &os,
|
||||
clang::DiagnosticOptions *diags,
|
||||
ParserClient* client,
|
||||
FileRegister* fileRegister,
|
||||
std::shared_ptr<ParserClient> client,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
bool useLogging = true
|
||||
);
|
||||
|
||||
@@ -24,8 +24,8 @@ public:
|
||||
void HandleDiagnostic(clang::DiagnosticsEngine::Level level, const clang::Diagnostic& info);
|
||||
|
||||
private:
|
||||
ParserClient* m_client;
|
||||
FileRegister* m_register;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_register;
|
||||
|
||||
bool m_isParsingFile;
|
||||
bool m_useLogging;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/tracing.h"
|
||||
|
||||
#include "data/indexer/IndexerCommandCxxCdb.h"
|
||||
#include "data/indexer/IndexerCommandCxxManual.h"
|
||||
#include "data/parser/cxx/ASTActionFactory.h"
|
||||
#include "data/parser/cxx/CxxCompilationDatabaseSingle.h"
|
||||
#include "data/parser/cxx/CxxDiagnosticConsumer.h"
|
||||
@@ -52,8 +54,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CxxParser::CxxParser(ParserClient* client, std::shared_ptr<FileRegister> fileRegister)
|
||||
CxxParser::CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: Parser(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
{
|
||||
@@ -63,34 +64,62 @@ CxxParser::~CxxParser()
|
||||
{
|
||||
}
|
||||
|
||||
void CxxParser::parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments)
|
||||
void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
|
||||
{
|
||||
m_fileRegister->setFilePaths(filePaths);
|
||||
setupParsing(arguments);
|
||||
clang::tooling::CompileCommand compileCommand;
|
||||
compileCommand.Filename = indexerCommand->getSourceFilePath().str();
|
||||
compileCommand.Directory = indexerCommand->getWorkingDirectory().str();
|
||||
compileCommand.CommandLine = indexerCommand->getCompilerFlags();
|
||||
|
||||
std::vector<std::string> sourcePaths;
|
||||
for (const FilePath& path : m_fileRegister->getUnparsedSourceFilePaths()) // filter headers
|
||||
{
|
||||
sourcePaths.push_back(path.absolute().str());
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(
|
||||
std::vector<std::string>(), indexerCommand->getSystemHeaderSearchPaths(), indexerCommand->getFrameworkSearchPaths()
|
||||
);
|
||||
compileCommand.CommandLine.insert(compileCommand.CommandLine.end(), args.begin(), args.end());
|
||||
}
|
||||
|
||||
runTool(sourcePaths);
|
||||
CxxCompilationDatabaseSingle compilationDatabase(compileCommand);
|
||||
clang::tooling::ClangTool tool(compilationDatabase, std::vector<std::string>(1, indexerCommand->getSourceFilePath().str()));
|
||||
|
||||
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(true);
|
||||
tool.setDiagnosticConsumer(diagnostics.get());
|
||||
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister);
|
||||
tool.run(&actionFactory);
|
||||
}
|
||||
|
||||
void CxxParser::parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments)
|
||||
void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerCommand)
|
||||
{
|
||||
m_fileRegister->setFilePaths(std::vector<FilePath>(1, filePath));
|
||||
setupParsing(arguments);
|
||||
std::shared_ptr<clang::tooling::CompilationDatabase> compilationDatabase = getCompilationDatabase(indexerCommand);
|
||||
|
||||
std::vector<std::string> args = getCommandlineArguments(arguments);
|
||||
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(arguments);
|
||||
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, indexerCommand->getSourceFilePath().str()));
|
||||
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister.get());
|
||||
runToolOnCodeWithArgs(diagnostics.get(), actionFactory.create(), textAccess->getText(), args);
|
||||
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(true);
|
||||
tool.setDiagnosticConsumer(diagnostics.get());
|
||||
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister);
|
||||
tool.run(&actionFactory);
|
||||
}
|
||||
|
||||
std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(const Arguments& arguments) const
|
||||
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);
|
||||
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(std::vector<std::string>(1, "-std=c++1z"), std::vector<FilePath>(), std::vector<FilePath>());
|
||||
|
||||
runToolOnCodeWithArgs(
|
||||
diagnostics.get(),
|
||||
actionFactory.create(),
|
||||
fileContent->getText(),
|
||||
args,
|
||||
fileName
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(
|
||||
const std::vector<std::string>& compilerFlags, const std::vector<FilePath>& systemHeaderSearchPaths, const std::vector<FilePath>& frameworkSearchPaths
|
||||
) const {
|
||||
std::vector<std::string> args;
|
||||
|
||||
// verbose
|
||||
@@ -108,24 +137,19 @@ std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(const Argum
|
||||
|
||||
// The option -w disables all warnings.
|
||||
args.push_back("-w");
|
||||
|
||||
|
||||
// This option tells clang just to continue parsing no matter how manny errors have been thrown.
|
||||
args.push_back("-ferror-limit=0");
|
||||
|
||||
args.insert(args.end(), arguments.compilerFlags.begin(), arguments.compilerFlags.end());
|
||||
args.insert(args.end(), compilerFlags.begin(), compilerFlags.end());
|
||||
|
||||
for (const FilePath& path : arguments.headerSearchPaths)
|
||||
{
|
||||
args.push_back("-I" + path.str());
|
||||
}
|
||||
|
||||
for (const FilePath& path : arguments.systemHeaderSearchPaths)
|
||||
for (const FilePath& path: systemHeaderSearchPaths)
|
||||
{
|
||||
args.push_back("-isystem");
|
||||
args.push_back(path.str());
|
||||
}
|
||||
|
||||
for (const FilePath& path : arguments.frameworkSearchPaths)
|
||||
for (const FilePath& path: frameworkSearchPaths)
|
||||
{
|
||||
args.push_back("-iframework");
|
||||
args.push_back(path.str());
|
||||
@@ -134,22 +158,24 @@ std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(const Argum
|
||||
return args;
|
||||
}
|
||||
|
||||
std::vector<std::string> CxxParser::getCommandlineArguments(const Arguments& arguments) const
|
||||
std::vector<std::string> CxxParser::getCommandlineArguments(std::shared_ptr<IndexerCommandCxxManual> indexerCommand) const
|
||||
{
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(arguments);
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(
|
||||
indexerCommand->getCompilerFlags(), indexerCommand->getSystemHeaderSearchPaths(), indexerCommand->getFrameworkSearchPaths()
|
||||
);
|
||||
|
||||
// Set language standard
|
||||
std::string standard = "-std=" + arguments.languageStandard;
|
||||
std::string standard = "-std=" + indexerCommand->getLanguageStandard();
|
||||
args.push_back(standard);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
std::shared_ptr<clang::tooling::FixedCompilationDatabase> CxxParser::getCompilationDatabase(
|
||||
const Arguments& arguments
|
||||
std::shared_ptr<IndexerCommandCxxManual> indexerCommand
|
||||
) const {
|
||||
// Commandline flags passed to the programm. Everything after '--' will be interpreted by the ClangTool.
|
||||
std::vector<std::string> args = getCommandlineArguments(arguments);
|
||||
std::vector<std::string> args = getCommandlineArguments(indexerCommand);
|
||||
args.insert(args.begin(), "app");
|
||||
args.insert(args.begin() + 1, "--");
|
||||
|
||||
@@ -175,56 +201,9 @@ std::shared_ptr<clang::tooling::FixedCompilationDatabase> CxxParser::getCompilat
|
||||
return compilationDatabase;
|
||||
}
|
||||
|
||||
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(const Arguments& arguments) const
|
||||
std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(bool logErrors) const
|
||||
{
|
||||
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> options = new clang::DiagnosticOptions();
|
||||
return std::make_shared<CxxDiagnosticConsumer>(
|
||||
llvm::errs(), &*options, m_client, m_fileRegister.get(), arguments.logErrors);
|
||||
}
|
||||
|
||||
void CxxParser::setupParsing(const Arguments& arguments)
|
||||
{
|
||||
m_compilationDatabase = getCompilationDatabase(arguments);
|
||||
m_diagnostics = getDiagnostics(arguments);
|
||||
}
|
||||
|
||||
void CxxParser::setupParsingCDB(const Arguments& arguments)
|
||||
{
|
||||
m_diagnostics = getDiagnostics(arguments);
|
||||
}
|
||||
|
||||
void CxxParser::runTool(const std::vector<std::string>& files)
|
||||
{
|
||||
TRACE();
|
||||
|
||||
clang::tooling::ClangTool tool(*m_compilationDatabase, files);
|
||||
tool.setDiagnosticConsumer(m_diagnostics.get());
|
||||
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister.get());
|
||||
tool.run(&actionFactory);
|
||||
}
|
||||
|
||||
void CxxParser::runTool(clang::tooling::CompileCommand command, const Arguments& arguments)
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(arguments);
|
||||
command.CommandLine.insert(command.CommandLine.end(), args.begin(), args.end());
|
||||
|
||||
CxxCompilationDatabaseSingle compilationDatabase(command);
|
||||
clang::tooling::ClangTool tool(compilationDatabase, std::vector<std::string>(1, command.Filename));
|
||||
tool.setDiagnosticConsumer(m_diagnostics.get());
|
||||
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister.get());
|
||||
tool.run(&actionFactory);
|
||||
}
|
||||
|
||||
FileRegister* CxxParser::getFileRegister()
|
||||
{
|
||||
return m_fileRegister.get();
|
||||
}
|
||||
|
||||
ParserClient* CxxParser::getParserClient()
|
||||
{
|
||||
return m_client;
|
||||
llvm::errs(), &*options, m_client, m_fileRegister, logErrors);
|
||||
}
|
||||
|
||||
@@ -6,42 +6,35 @@
|
||||
|
||||
class CxxDiagnosticConsumer;
|
||||
class FileRegister;
|
||||
class FileRegister;
|
||||
class IndexerCommandCxxCdb;
|
||||
class IndexerCommandCxxManual;
|
||||
class TaskParseCxx;
|
||||
|
||||
class CxxParser: public Parser
|
||||
{
|
||||
public:
|
||||
CxxParser(ParserClient* client, std::shared_ptr<FileRegister> fileRegister);
|
||||
CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
~CxxParser();
|
||||
|
||||
// ParserClient implementation
|
||||
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments);
|
||||
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments);
|
||||
void buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand);
|
||||
void buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerCommand);
|
||||
void buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent);
|
||||
|
||||
|
||||
private:
|
||||
std::vector<std::string> getCommandlineArgumentsEssential(const Arguments& arguments) const;
|
||||
std::vector<std::string> getCommandlineArguments(const Arguments& arguments) const;
|
||||
std::shared_ptr<clang::tooling::FixedCompilationDatabase> getCompilationDatabase(const Arguments& arguments) const;
|
||||
std::vector<std::string> getCommandlineArgumentsEssential(
|
||||
const std::vector<std::string>& compilerFlags,
|
||||
const std::vector<FilePath>& systemHeaderSearchPaths,
|
||||
const std::vector<FilePath>& frameworkSearchPaths) const;
|
||||
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(const Arguments& arguments) const;
|
||||
|
||||
// Accessed by TaskParseCxx
|
||||
void setupParsing(const Arguments& arguments);
|
||||
void setupParsingCDB(const Arguments& arguments);
|
||||
|
||||
void runTool(const std::vector<std::string>& files);
|
||||
void runTool(clang::tooling::CompileCommand command, const Arguments& arguments);
|
||||
|
||||
FileRegister* getFileRegister();
|
||||
ParserClient* getParserClient();
|
||||
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(bool logErrors) const;
|
||||
|
||||
friend class TaskParseCxx;
|
||||
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
std::shared_ptr<clang::tooling::CompilationDatabase> m_compilationDatabase;
|
||||
std::shared_ptr<CxxDiagnosticConsumer> m_diagnostics;
|
||||
};
|
||||
|
||||
#endif // CXX_PARSER_H
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/ScopedSwitcher.h"
|
||||
|
||||
CxxVerboseAstVisitor::CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister)
|
||||
CxxVerboseAstVisitor::CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: base(context, preprocessor, client, fileRegister)
|
||||
, m_currentFilePath("")
|
||||
, m_indentation(0)
|
||||
|
||||
@@ -11,7 +11,7 @@ class FileRegister;
|
||||
class CxxVerboseAstVisitor: public CxxAstVisitor
|
||||
{
|
||||
public:
|
||||
CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister);
|
||||
CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~CxxVerboseAstVisitor();
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
#include "clang/Basic/IdentifierTable.h"
|
||||
#include "clang/Lex/MacroArgs.h"
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
|
||||
PreprocessorCallbacks::PreprocessorCallbacks(
|
||||
clang::SourceManager& sourceManager, ParserClient* client, FileRegister* fileRegister
|
||||
clang::SourceManager& sourceManager, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister
|
||||
)
|
||||
: m_sourceManager(sourceManager)
|
||||
, m_client(client)
|
||||
@@ -32,14 +33,14 @@ void PreprocessorCallbacks::FileChanged(
|
||||
const bool fileIsInProject = m_fileRegister->hasFilePath(filePath);
|
||||
if (!filePath.empty() && fileIsInProject)
|
||||
{
|
||||
m_client->onFileParsed(m_fileRegister->getFileInfo(filePath));
|
||||
if (reason == EnterFile && !m_fileRegister->includeFileIsParsed(filePath))
|
||||
m_client->onFileParsed(FileSystem::getFileInfoForPath(filePath)); // todo: fix for tests
|
||||
if (reason == EnterFile && !m_fileRegister->fileIsIndexed(filePath))
|
||||
{
|
||||
m_fileRegister->markIncludeFileParsing(filePath);
|
||||
m_fileRegister->markFileIndexing(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
if (!filePath.empty() && fileIsInProject && !m_fileRegister->fileIsParsed(filePath))
|
||||
if (!filePath.empty() && fileIsInProject && !m_fileRegister->fileIsIndexed(filePath))
|
||||
{
|
||||
m_currentPath = filePath;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef PREPROCESSOR_CALLBACKS_H
|
||||
#define PREPROCESSOR_CALLBACKS_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Lex/MacroInfo.h"
|
||||
#include "clang/Lex/PPCallbacks.h"
|
||||
@@ -17,7 +19,7 @@ class PreprocessorCallbacks
|
||||
: public clang::PPCallbacks
|
||||
{
|
||||
public:
|
||||
explicit PreprocessorCallbacks(clang::SourceManager& sourceManager, ParserClient* client, FileRegister* fileRegister);
|
||||
explicit PreprocessorCallbacks(clang::SourceManager& sourceManager, std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
|
||||
virtual void FileChanged(
|
||||
clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID);
|
||||
@@ -50,8 +52,8 @@ private:
|
||||
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
|
||||
|
||||
const clang::SourceManager& m_sourceManager;
|
||||
ParserClient* m_client;
|
||||
FileRegister* m_fileRegister;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
FilePath m_currentPath;
|
||||
};
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
#include "data/parser/cxx/TaskParseCxx.h"
|
||||
|
||||
#include "clang/Tooling/JSONCompilationDatabase.h"
|
||||
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
#include "data/parser/ParserClientImpl.h"
|
||||
#include "data/StorageProvider.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
|
||||
std::vector<FilePath> TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath)
|
||||
{
|
||||
std::string error;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
|
||||
(clang::tooling::JSONCompilationDatabase::loadFromFile(compilationDatabasePath.str(), error));
|
||||
|
||||
std::vector<FilePath> filePaths;
|
||||
if (cdb)
|
||||
{
|
||||
std::vector<std::string> files = cdb->getAllFiles();
|
||||
for (const std::string& file : files)
|
||||
{
|
||||
filePaths.push_back(FilePath(file));
|
||||
}
|
||||
}
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
TaskParseCxx::TaskParseCxx(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
const Parser::Arguments& arguments,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: TaskParse(storageProvider, fileRegister, arguments, dialogView)
|
||||
, m_isCDB(false)
|
||||
{
|
||||
if (arguments.compilationDatabasePath.exists())
|
||||
{
|
||||
m_isCDB = true;
|
||||
}
|
||||
m_parserClient = std::make_shared<ParserClientImpl>(); // todo: create one parserclient per file
|
||||
m_parser = std::make_shared<CxxParser>(m_parserClient.get(), fileRegister);
|
||||
}
|
||||
|
||||
void TaskParseCxx::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
TaskParse::doEnter(blackboard);
|
||||
|
||||
if (m_isCDB)
|
||||
{
|
||||
std::string error;
|
||||
m_cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
|
||||
(clang::tooling::JSONCompilationDatabase::loadFromFile(m_arguments.compilationDatabasePath.str(), error));
|
||||
|
||||
m_parser->setupParsingCDB(m_arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_parser->setupParsing(m_arguments);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskParseCxx::indexFile(FilePath sourcePath)
|
||||
{
|
||||
FileRegister* fileRegister = m_parser->getFileRegister();
|
||||
|
||||
std::shared_ptr<IntermediateStorage> storage = m_storageProvider->popIndexerTarget();
|
||||
m_parserClient->setStorage(storage);
|
||||
m_parserClient->startParsingFile();
|
||||
|
||||
if (m_isCDB)
|
||||
{
|
||||
std::vector<clang::tooling::CompileCommand> commands = m_cdb->getCompileCommands(sourcePath.str());
|
||||
if (commands.size() > 0)
|
||||
{
|
||||
m_parser->runTool(commands[0], m_arguments);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_parser->runTool(std::vector<std::string>(1, sourcePath.str()));
|
||||
}
|
||||
|
||||
m_parserClient->finishParsingFile();
|
||||
m_parserClient->resetStorage();
|
||||
|
||||
if (!m_interrupted)
|
||||
{
|
||||
fileRegister->markThreadFilesParsed();
|
||||
m_storageProvider->pushIndexerTarget(storage);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifndef TASK_PARSE_CXX_H
|
||||
#define TASK_PARSE_CXX_H
|
||||
|
||||
#include "data/parser/TaskParse.h"
|
||||
|
||||
class CxxParser;
|
||||
class ParserClientImpl;
|
||||
|
||||
namespace clang
|
||||
{
|
||||
namespace tooling
|
||||
{
|
||||
class JSONCompilationDatabase;
|
||||
}
|
||||
}
|
||||
|
||||
class TaskParseCxx
|
||||
: public TaskParse
|
||||
{
|
||||
public:
|
||||
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
|
||||
|
||||
TaskParseCxx(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
const Parser::Arguments& arguments,
|
||||
DialogView* dialogView
|
||||
);
|
||||
|
||||
private:
|
||||
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||
|
||||
virtual void indexFile(FilePath sourcePath);
|
||||
|
||||
std::shared_ptr<CxxParser> m_parser;
|
||||
std::shared_ptr<ParserClientImpl> m_parserClient;
|
||||
|
||||
bool m_isCDB;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> m_cdb;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_CXX_H
|
||||
Reference in New Issue
Block a user