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:
Eberhard Graether
2017-04-18 22:11:20 +02:00
parent 2b24b88745
commit 63087913bd
31 changed files with 373 additions and 231 deletions
+2 -1
View File
@@ -2,6 +2,8 @@
add_files(
LIB_CXX_FILES
data/indexer/IndexerCommandCxx.cpp
data/indexer/IndexerCommandCxx.h
data/indexer/IndexerCommandCxxCdb.cpp
data/indexer/IndexerCommandCxxCdb.h
data/indexer/IndexerCommandCxxManual.cpp
@@ -33,7 +35,6 @@ add_files(
data/parser/cxx/name_resolver/CxxTypeNameResolver.cpp
data/parser/cxx/name_resolver/CxxTypeNameResolver.h
data/parser/cxx/ASTAction.cpp
data/parser/cxx/ASTAction.h
data/parser/cxx/ASTActionFactory.cpp
data/parser/cxx/ASTActionFactory.h
@@ -0,0 +1,46 @@
#include "data/indexer/IndexerCommandCxx.h"
IndexerCommandCxx::IndexerCommandCxx(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags
)
: IndexerCommand(sourceFilePath, indexedPaths, excludedPaths)
, m_systemHeaderSearchPaths(systemHeaderSearchPaths)
, m_frameworkSearchPaths(frameworkSearchPaths)
, m_compilerFlags(compilerFlags)
, m_preprocessorOnly(false)
{
}
IndexerCommandCxx::~IndexerCommandCxx()
{
}
std::vector<FilePath> IndexerCommandCxx::getSystemHeaderSearchPaths() const
{
return m_systemHeaderSearchPaths;
}
std::vector<FilePath> IndexerCommandCxx::getFrameworkSearchPaths() const
{
return m_frameworkSearchPaths;
}
std::vector<std::string> IndexerCommandCxx::getCompilerFlags() const
{
return m_compilerFlags;
}
bool IndexerCommandCxx::preprocessorOnly() const
{
return m_preprocessorOnly;
}
void IndexerCommandCxx::setPreprocessorOnly(bool preprocessorOnly)
{
m_preprocessorOnly = preprocessorOnly;
}
@@ -0,0 +1,39 @@
#ifndef INDEXER_COMMAND_CXX_H
#define INDEXER_COMMAND_CXX_H
#include <vector>
#include <string>
#include "data/indexer/IndexerCommand.h"
#include "utility/file/FilePath.h"
class IndexerCommandCxx
: public IndexerCommand
{
public:
IndexerCommandCxx(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePath>& excludedPaths,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags);
virtual ~IndexerCommandCxx();
std::vector<FilePath> getSystemHeaderSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<std::string> getCompilerFlags() const;
bool preprocessorOnly() const override;
void setPreprocessorOnly(bool preprocessorOnly) override;
private:
std::vector<FilePath> m_systemHeaderSearchPaths;
std::vector<FilePath> m_frameworkSearchPaths;
std::vector<std::string> m_compilerFlags;
bool m_preprocessorOnly;
};
#endif // INDEXER_COMMAND_CXXL_H
@@ -35,11 +35,8 @@ IndexerCommandCxxCdb::IndexerCommandCxxCdb(
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths
)
: IndexerCommand(sourceFilePath, indexedPaths, excludedPaths)
: IndexerCommandCxx(sourceFilePath, indexedPaths, excludedPaths, systemHeaderSearchPaths, frameworkSearchPaths, compilerFlags)
, m_workingDirectory(workingDirectory)
, m_compilerFlags(compilerFlags)
, m_systemHeaderSearchPaths(systemHeaderSearchPaths)
, m_frameworkSearchPaths(frameworkSearchPaths)
{
}
@@ -56,18 +53,3 @@ FilePath IndexerCommandCxxCdb::getWorkingDirectory() const
{
return m_workingDirectory;
}
std::vector<std::string> IndexerCommandCxxCdb::getCompilerFlags() const
{
return m_compilerFlags;
}
std::vector<FilePath> IndexerCommandCxxCdb::getSystemHeaderSearchPaths() const
{
return m_systemHeaderSearchPaths;
}
std::vector<FilePath> IndexerCommandCxxCdb::getFrameworkSearchPaths() const
{
return m_frameworkSearchPaths;
}
@@ -1,9 +1,7 @@
#ifndef INDEXER_COMMAND_CXX_CDB_H
#define INDEXER_COMMAND_CXX_CDB_H
#include <vector>
#include "data/indexer/IndexerCommand.h"
#include "data/indexer/IndexerCommandCxx.h"
#include "utility/file/FilePath.h"
namespace clang
@@ -14,7 +12,8 @@ namespace clang
}
}
class IndexerCommandCxxCdb: public IndexerCommand
class IndexerCommandCxxCdb
: public IndexerCommandCxx
{
public:
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
@@ -34,15 +33,9 @@ public:
virtual std::string getKindString() const;
FilePath getWorkingDirectory() const;
std::vector<std::string> getCompilerFlags() const;
std::vector<FilePath> getSystemHeaderSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPaths() const;
private:
FilePath m_workingDirectory;
std::vector<std::string> m_compilerFlags;
std::vector<FilePath> m_systemHeaderSearchPaths;
std::vector<FilePath> m_frameworkSearchPaths;
};
#endif // INDEXER_COMMAND_CXX_CDB_H
@@ -15,11 +15,8 @@ IndexerCommandCxxManual::IndexerCommandCxxManual(
const std::vector<FilePath>& frameworkSearchPaths,
const std::vector<std::string>& compilerFlags
)
: IndexerCommand(sourceFilePath, indexedPaths, excludedPaths)
: IndexerCommandCxx(sourceFilePath, indexedPaths, excludedPaths, systemHeaderSearchPaths, frameworkSearchPaths, compilerFlags)
, m_languageStandard(languageStandard)
, m_systemHeaderSearchPaths(systemHeaderSearchPaths)
, m_frameworkSearchPaths(frameworkSearchPaths)
, m_compilerFlags(compilerFlags)
{
}
@@ -36,18 +33,3 @@ std::string IndexerCommandCxxManual::getLanguageStandard() const
{
return m_languageStandard;
}
std::vector<FilePath> IndexerCommandCxxManual::getSystemHeaderSearchPaths() const
{
return m_systemHeaderSearchPaths;
}
std::vector<FilePath> IndexerCommandCxxManual::getFrameworkSearchPaths() const
{
return m_frameworkSearchPaths;
}
std::vector<std::string> IndexerCommandCxxManual::getCompilerFlags() const
{
return m_compilerFlags;
}
@@ -1,13 +1,11 @@
#ifndef INDEXER_COMMAND_CXX_MANUAL_H
#define INDEXER_COMMAND_CXX_MANUAL_H
#include <vector>
#include <string>
#include "data/indexer/IndexerCommand.h"
#include "data/indexer/IndexerCommandCxx.h"
#include "utility/file/FilePath.h"
class IndexerCommandCxxManual: public IndexerCommand
class IndexerCommandCxxManual
: public IndexerCommandCxx
{
public:
static std::string getIndexerKindString();
@@ -25,15 +23,9 @@ public:
virtual std::string getKindString() const;
std::string getLanguageStandard() const;
std::vector<FilePath> getSystemHeaderSearchPaths() const;
std::vector<FilePath> getFrameworkSearchPaths() const;
std::vector<std::string> getCompilerFlags() const;
private:
std::string m_languageStandard;
std::vector<FilePath> m_systemHeaderSearchPaths;
std::vector<FilePath> m_frameworkSearchPaths;
std::vector<std::string> m_compilerFlags;
};
#endif // INDEXER_COMMAND_CXX_MANUAL_H
-31
View File
@@ -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;
}
+25 -6
View File
@@ -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
+3 -3
View File
@@ -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>());