ui: implemented prefilling indexed header paths for compilation database projects

* fixed header path detection in CompilationDatabase class
This commit is contained in:
mlangkabel
2017-10-11 17:08:13 +02:00
parent 85ab7d1e96
commit f0da5b630b
14 changed files with 153 additions and 71 deletions
+40 -22
View File
@@ -5,15 +5,16 @@
#include "clang/Tooling/JSONCompilationDatabase.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "utility/file/FilePath.h"
#include "utility/utilityString.h"
#include "utility/utility.h"
utility::CompilationDatabase::CompilationDatabase(std::string filename)
: m_filename(filename)
utility::CompilationDatabase::CompilationDatabase(const FilePath& filePath)
: m_filePath(filePath)
{
getHeaders();
init();
}
std::vector<FilePath> utility::CompilationDatabase::getAllHeaderPaths()
std::vector<FilePath> utility::CompilationDatabase::getAllHeaderPaths() const
{
std::vector<FilePath> paths = utility::concat(m_headers, m_systemHeaders);
paths = utility::concat(paths, m_frameworkHeaders);
@@ -21,47 +22,64 @@ std::vector<FilePath> utility::CompilationDatabase::getAllHeaderPaths()
return paths;
}
std::vector<FilePath> utility::CompilationDatabase::getHeaderPaths()
std::vector<FilePath> utility::CompilationDatabase::getHeaderPaths() const
{
return m_headers;
}
std::vector<FilePath> utility::CompilationDatabase::getSystemHeaderPaths()
std::vector<FilePath> utility::CompilationDatabase::getSystemHeaderPaths() const
{
return m_systemHeaders;
}
std::vector<FilePath> utility::CompilationDatabase::getFrameworkHeaderPaths()
std::vector<FilePath> utility::CompilationDatabase::getFrameworkHeaderPaths() const
{
return m_frameworkHeaders;
}
void utility::CompilationDatabase::getHeaders()
void utility::CompilationDatabase::init()
{
std::string error;
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
(clang::tooling::JSONCompilationDatabase::loadFromFile(m_filename, error, clang::tooling::JSONCommandLineSyntax::AutoDetect));
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>(
clang::tooling::JSONCompilationDatabase::loadFromFile(m_filePath.str(), error, clang::tooling::JSONCommandLineSyntax::AutoDetect)
);
std::vector<clang::tooling::CompileCommand> commands = cdb->getAllCompileCommands();
std::set<FilePath> frameworkHeaders;
std::set<FilePath> systemHeaders;
std::set<FilePath> headers;
for (clang::tooling::CompileCommand& command : commands)
{
for( size_t i = 0; i < command.CommandLine.size(); i++)
const std::string frameworkIncludeFlag = "-iframework";
const std::string systemIncludeFlag = "-isystem";
const std::string quoteFlag = "-iquote";
const std::string includeFlag = "-I";
for (clang::tooling::CompileCommand& command : commands)
{
if( command.CommandLine[i] == "-iframework" )
for (size_t i = 0; i < command.CommandLine.size(); i++)
{
frameworkHeaders.insert(FilePath(command.CommandLine[++i], command.Directory));
}
if( command.CommandLine[i] == "-isystem" )
{
systemHeaders.insert(FilePath(command.CommandLine[++i], command.Directory));
}
if( command.CommandLine[i].substr(0,2) == "-I" )
{
headers.insert(FilePath(command.CommandLine[i].substr(2), command.Directory));
std::string argument = command.CommandLine[i];
if (!utility::isPrefix("-", command.CommandLine[i + 1]))
{
argument += command.CommandLine[++i];
}
if (utility::isPrefix(frameworkIncludeFlag, argument))
{
frameworkHeaders.insert(FilePath(utility::trim(argument.substr(frameworkIncludeFlag.size())), command.Directory));
}
else if (utility::isPrefix(systemIncludeFlag, argument))
{
systemHeaders.insert(FilePath(utility::trim(argument.substr(systemIncludeFlag.size())), command.Directory));
}
else if (utility::isPrefix(quoteFlag, argument))
{
headers.insert(FilePath(utility::trim(argument.substr(quoteFlag.size())), command.Directory));
}
else if (utility::isPrefix(includeFlag, argument))
{
headers.insert(FilePath(utility::trim(argument.substr(includeFlag.size())), command.Directory));
}
}
}
}
+9 -9
View File
@@ -4,27 +4,27 @@
#include <string>
#include <vector>
class FilePath;
#include "utility/file/FilePath.h"
namespace utility
{
class CompilationDatabase
{
public:
CompilationDatabase(std::string filename);
CompilationDatabase(const FilePath& filePath);
std::vector<FilePath> getAllHeaderPaths();
std::vector<FilePath> getHeaderPaths();
std::vector<FilePath> getSystemHeaderPaths();
std::vector<FilePath> getFrameworkHeaderPaths();
std::vector<FilePath> getAllHeaderPaths() const;
std::vector<FilePath> getHeaderPaths() const;
std::vector<FilePath> getSystemHeaderPaths() const;
std::vector<FilePath> getFrameworkHeaderPaths() const;
private:
std::string m_filename;
void init();
FilePath m_filePath;
std::vector<FilePath> m_headers;
std::vector<FilePath> m_systemHeaders;
std::vector<FilePath> m_frameworkHeaders;
void getHeaders();
};
}