data: Option to run only C/C++ preprocessor when indexing (issue 297)
* Added as checkbox to indexing start dialog * Only shown for C/C++ projects * Files will be marked incomplete
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
#include "data/parser/cxx/ASTAction.h"
|
||||
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
|
||||
#include "data/parser/cxx/CommentHandler.h"
|
||||
#include "data/parser/cxx/PreprocessorCallbacks.h"
|
||||
|
||||
ASTAction::ASTAction(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: m_client(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_commentHandler(client, fileRegister)
|
||||
{
|
||||
}
|
||||
|
||||
ASTAction::~ASTAction()
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<clang::ASTConsumer> ASTAction::CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile)
|
||||
{
|
||||
return std::unique_ptr<clang::ASTConsumer>(new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_fileRegister));
|
||||
}
|
||||
|
||||
bool ASTAction::BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath)
|
||||
{
|
||||
clang::Preprocessor& preprocessor = compiler.getPreprocessor();
|
||||
preprocessor.addPPCallbacks(
|
||||
llvm::make_unique<PreprocessorCallbacks>(compiler.getSourceManager(), m_client, m_fileRegister));
|
||||
preprocessor.addCommentHandler(&m_commentHandler);
|
||||
return true;
|
||||
}
|
||||
@@ -5,27 +5,46 @@
|
||||
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
#include "clang/Frontend/FrontendAction.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
|
||||
#include "data/parser/cxx/ASTConsumer.h"
|
||||
#include "data/parser/cxx/CommentHandler.h"
|
||||
#include "data/parser/cxx/PreprocessorCallbacks.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
class ASTAction : public clang::ASTFrontendAction
|
||||
template <typename ASTActionBase>
|
||||
class ASTAction
|
||||
: public ASTActionBase
|
||||
{
|
||||
public:
|
||||
explicit ASTAction(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
virtual ~ASTAction();
|
||||
explicit ASTAction(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
: m_client(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_commentHandler(client, fileRegister)
|
||||
{}
|
||||
|
||||
virtual ~ASTAction() {}
|
||||
|
||||
protected:
|
||||
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile);
|
||||
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));
|
||||
}
|
||||
|
||||
virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath);
|
||||
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));
|
||||
preprocessor.addCommentHandler(&m_commentHandler);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
CommentHandler m_commentHandler;
|
||||
|
||||
};
|
||||
|
||||
#endif // AST_ACTION_H
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
#include "data/parser/cxx/ASTActionFactory.h"
|
||||
|
||||
ASTActionFactory::ASTActionFactory(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
|
||||
#include "clang/Frontend/FrontendActions.h"
|
||||
|
||||
ASTActionFactory::ASTActionFactory(
|
||||
std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister, bool preprocessorOnly
|
||||
)
|
||||
: m_client(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_preprocessorOnly(preprocessorOnly)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -12,5 +17,12 @@ ASTActionFactory::~ASTActionFactory()
|
||||
|
||||
clang::FrontendAction* ASTActionFactory::create()
|
||||
{
|
||||
return new ASTAction(m_client, m_fileRegister);
|
||||
if (m_preprocessorOnly)
|
||||
{
|
||||
return new ASTAction<clang::PreprocessOnlyAction>(m_client, m_fileRegister);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ASTAction<clang::ASTFrontendAction>(m_client, m_fileRegister);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
#include "data/parser/cxx/ASTAction.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
class ASTActionFactory : public clang::tooling::FrontendActionFactory
|
||||
class ASTActionFactory
|
||||
: public clang::tooling::FrontendActionFactory
|
||||
{
|
||||
public:
|
||||
explicit ASTActionFactory(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
explicit ASTActionFactory(
|
||||
std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister, bool preprocessorOnly);
|
||||
virtual ~ASTActionFactory();
|
||||
|
||||
virtual clang::FrontendAction* create();
|
||||
@@ -17,6 +19,8 @@ public:
|
||||
private:
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
bool m_preprocessorOnly;
|
||||
};
|
||||
|
||||
#endif // AST_ACTION_FACTORY
|
||||
|
||||
@@ -84,7 +84,7 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
|
||||
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(true);
|
||||
tool.setDiagnosticConsumer(diagnostics.get());
|
||||
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister);
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister, indexerCommand->preprocessorOnly());
|
||||
tool.run(&actionFactory);
|
||||
}
|
||||
|
||||
@@ -97,14 +97,14 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerComma
|
||||
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(true);
|
||||
tool.setDiagnosticConsumer(diagnostics.get());
|
||||
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister);
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister, 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);
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister, false);
|
||||
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(std::vector<std::string>(1, "-std=c++1z"), std::vector<FilePath>(), std::vector<FilePath>());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user