logic: Added compilation database project setup

* Added CDB option to project type selection
* show CDB source files in popup
* define header paths separately
* made generic content summary in wizzard and use it everywhere
* fixed file paths not canonical in analysis
* refactored wizzard content paths to use summary instead of subpaths
* refactored files popup to simpler communication with content

bug id = 35
This commit is contained in:
Eberhard Graether
2016-03-08 13:20:37 +01:00
parent 90c0d15d20
commit 8cc8f5d534
45 changed files with 919 additions and 734 deletions
+7 -10
View File
@@ -10,7 +10,6 @@
#include "data/parser/ParseLocation.h"
#include "utility/file/FileManager.h"
#include "utility/file/FileSystem.h"
#include "utility/ScopedSwitcher.h"
@@ -1004,9 +1003,7 @@ ParseLocation ASTVisitor::getDeclRefRange(clang::NamedDecl *decl, clang::SourceL
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
{
std::string fielName = fileEntry->getName();
std::string filePath = FileSystem::absoluteFilePath(fielName);
parseLocation.filePath = FilePath(filePath);
parseLocation.filePath = FilePath(fileEntry->getName()).canonical();
}
}
@@ -1488,9 +1485,9 @@ bool ASTVisitor::isLocatedInUnparsedProjectFile(clang::SourceLocation loc)
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
{
std::string fielName = fileEntry->getName();
std::string filePath = FileSystem::absoluteFilePath(fielName);
ret = m_fileRegister->includeFileIsParsing(filePath);
std::string fileName = fileEntry->getName();
FilePath filePath = FilePath(fileName).canonical();
ret = m_fileRegister->includeFileIsParsing(filePath.str());
}
}
m_inUnparsedProjectFileMap[fileId] = ret;
@@ -1522,9 +1519,9 @@ bool ASTVisitor::isLocatedInProjectFile(clang::SourceLocation loc)
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != NULL)
{
std::string fielName = fileEntry->getName();
std::string filePath = FileSystem::absoluteFilePath(fielName);
bool ret = m_fileRegister->getFileManager()->hasFilePath(filePath);
std::string fileName = fileEntry->getName();
FilePath filePath = FilePath(fileName).canonical();
bool ret = m_fileRegister->getFileManager()->hasFilePath(filePath.str());
m_inProjectFileMap[fileId] = ret;
return ret;
}
@@ -0,0 +1,22 @@
#include "data/parser/cxx/CxxCompilationDatabaseSingle.h"
CxxCompilationDatabaseSingle::CxxCompilationDatabaseSingle(const clang::tooling::CompileCommand& command)
: m_command(command)
{
}
std::vector<clang::tooling::CompileCommand> CxxCompilationDatabaseSingle::getCompileCommands(
llvm::StringRef FilePath
) const {
return getAllCompileCommands();
}
std::vector<std::string> CxxCompilationDatabaseSingle::getAllFiles() const
{
return std::vector<std::string>(1, m_command.Filename);
}
std::vector<clang::tooling::CompileCommand> CxxCompilationDatabaseSingle::getAllCompileCommands() const
{
return std::vector<clang::tooling::CompileCommand>(1, m_command);
}
@@ -0,0 +1,20 @@
#ifndef CXX_COMPILATION_DATABASE_SINGLE_H
#define CXX_COMPILATION_DATABASE_SINGLE_H
#include "clang/Tooling/CompilationDatabase.h"
class CxxCompilationDatabaseSingle
: public clang::tooling::CompilationDatabase
{
public:
CxxCompilationDatabaseSingle(const clang::tooling::CompileCommand& command);
virtual std::vector<clang::tooling::CompileCommand> getCompileCommands(llvm::StringRef FilePath) const override;
virtual std::vector<std::string> getAllFiles() const override;
virtual std::vector<clang::tooling::CompileCommand> getAllCompileCommands() const override;
private:
clang::tooling::CompileCommand m_command;
};
#endif // CXX_COMPILATION_DATABASE_SINGLE_H
+48 -18
View File
@@ -8,6 +8,7 @@
#include "utility/text/TextAccess.h"
#include "data/parser/cxx/ASTActionFactory.h"
#include "data/parser/cxx/CxxCompilationDatabaseSingle.h"
#include "data/parser/cxx/CxxDiagnosticConsumer.h"
namespace
@@ -51,6 +52,7 @@ namespace
}
}
CxxParser::CxxParser(ParserClient* client, const FileManager* fileManager)
: Parser(client)
, m_fileRegister(std::make_shared<FileRegister>(fileManager))
@@ -94,7 +96,7 @@ void CxxParser::parseFile(const FilePath& filePath, std::shared_ptr<TextAccess>
runToolOnCodeWithArgs(diagnostics.get(), actionFactory.create(), textAccess->getText(), args);
}
std::vector<std::string> CxxParser::getCommandlineArguments(const Arguments& arguments) const
std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(const Arguments& arguments) const
{
std::vector<std::string> args;
@@ -111,6 +113,32 @@ std::vector<std::string> CxxParser::getCommandlineArguments(const Arguments& arg
// The option -c signals that no executable is built.
args.push_back("-c");
args.insert(args.begin(), arguments.compilerFlags.begin(), arguments.compilerFlags.end());
for (const FilePath& path : arguments.headerSearchPaths)
{
args.push_back("-I" + path.str());
}
for (const FilePath& path : arguments.systemHeaderSearchPaths)
{
args.push_back("-isystem");
args.push_back(path.str());
}
for (const FilePath& path : arguments.frameworkSearchPaths)
{
args.push_back("-iframework");
args.push_back(path.str());
}
return args;
}
std::vector<std::string> CxxParser::getCommandlineArguments(const Arguments& arguments) const
{
std::vector<std::string> args = getCommandlineArgumentsEssential(arguments);
// The option '-x c++' treats subsequent input files as C++.
args.push_back("-x");
std::string language = getLanguageArgument(arguments.language);
@@ -122,23 +150,6 @@ std::vector<std::string> CxxParser::getCommandlineArguments(const Arguments& arg
standard += arguments.languageStandard;
args.push_back(standard);
args.insert(args.begin(), arguments.compilerFlags.begin(), arguments.compilerFlags.end());
for (const FilePath& path : arguments.headerSearchPaths)
{
args.push_back("-I" + path.str());
}
for (const FilePath& path : arguments.systemHeaderSearchPaths)
{
args.push_back("-isystem" + path.str());
}
for (const FilePath& path : arguments.frameworkSearchPaths)
{
args.push_back("-iframework" + path.str());
}
return args;
}
@@ -186,6 +197,12 @@ void CxxParser::setupParsing(const std::vector<FilePath>& filePaths, const Argum
m_diagnostics = getDiagnostics(arguments);
}
void CxxParser::setupParsingCDB(const std::vector<FilePath>& filePaths, const Arguments& arguments)
{
m_fileRegister->setFilePaths(filePaths);
m_diagnostics = getDiagnostics(arguments);
}
void CxxParser::runTool(const std::vector<std::string>& files)
{
clang::tooling::ClangTool tool(*m_compilationDatabase, files);
@@ -195,6 +212,19 @@ void CxxParser::runTool(const std::vector<std::string>& files)
tool.run(&actionFactory);
}
void CxxParser::runTool(clang::tooling::CompileCommand command, const Arguments& arguments)
{
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();
+6 -9
View File
@@ -1,16 +1,9 @@
#ifndef CXX_PARSER_H
#define CXX_PARSER_H
#include "data/parser/cxx/CxxCompilationDatabaseSingle.h"
#include "data/parser/Parser.h"
namespace clang
{
namespace tooling
{
class FixedCompilationDatabase;
}
}
class CxxDiagnosticConsumer;
class FileManager;
class FileRegister;
@@ -27,6 +20,7 @@ public:
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments);
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;
@@ -34,7 +28,10 @@ private:
// Accessed by TaskParseCxx
void setupParsing(const std::vector<FilePath>& filePaths, const Arguments& arguments);
void setupParsingCDB(const std::vector<FilePath>& filePaths, const Arguments& arguments);
void runTool(const std::vector<std::string>& files);
void runTool(clang::tooling::CompileCommand command, const Arguments& arguments);
FileRegister* getFileRegister();
ParserClient* getParserClient();
@@ -45,7 +42,7 @@ private:
std::shared_ptr<FileRegister> m_fileRegister;
std::shared_ptr<clang::tooling::FixedCompilationDatabase> m_compilationDatabase;
std::shared_ptr<clang::tooling::CompilationDatabase> m_compilationDatabase;
std::shared_ptr<CxxDiagnosticConsumer> m_diagnostics;
};
@@ -36,6 +36,7 @@ void PreprocessorCallbacks::FileChanged(
}
FilePath filePath(fileEntry->getName());
filePath = filePath.canonical();
if (m_fileRegister->getFileManager()->hasFilePath(filePath.str()))
{