logic: getframeworkpaths to compilationdatabase

* getframeworkpaths added
* typename for iterator in cache added(fix)
This commit is contained in:
Andreas Stallinger
2016-02-23 10:38:34 +01:00
parent a7975b4428
commit 0cbf1ad1bb
4 changed files with 50 additions and 7 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ Cache<KeyType, ValType>::Cache(std::function<ValType(KeyType)> calculator)
template <typename KeyType, typename ValType>
ValType Cache<KeyType, ValType>::getValue(KeyType key)
{
std::map<KeyType, ValType>::const_iterator it = m_map.find(key);
typename std::map<KeyType, ValType>::const_iterator it = m_map.find(key);
if (it != m_map.end())
{
return it->second;
@@ -31,10 +31,30 @@ std::vector<std::string> SolutionParserCompilationDatabase::getProjectItems()
std::vector<std::string> SolutionParserCompilationDatabase::getIncludePaths()
{
std::vector<clang::tooling::CompileCommand> commands = getDatabase()->getAllCompileCommands();
if(m_searchPaths.empty())
{
parseDatabase();
}
return m_searchPaths;
}
std::vector<std::string> SolutionParserCompilationDatabase::getFrameworkPaths()
{
if(m_searchPaths.empty())
{
parseDatabase();
}
return m_frameworkPaths;
}
void SolutionParserCompilationDatabase::parseDatabase()
{
std::vector<clang::tooling::CompileCommand> commands = getDatabase()->getAllCompileCommands();
std::set<std::string> searchPaths;
std::set<std::string> frameworkPaths;
bool insertNext = false;
bool insertFramework = false;
for(clang::tooling::CompileCommand command : commands)
{
std::string dir = command.Directory;
@@ -45,26 +65,33 @@ std::vector<std::string> SolutionParserCompilationDatabase::getIncludePaths()
searchPaths.insert(getIncludePath(argument, command.Directory));
insertNext = false;
}
if(insertFramework)
{
frameworkPaths.insert(getIncludePath(argument,command.Directory));
insertFramework = false;
}
if(argument.substr(0,2) == "-I")
{
searchPaths.insert(getIncludePath(argument.substr(2), command.Directory));
}
if(argument == "-isystem" || argument == "-iframework")
if(argument == "-isystem")
{
insertNext = true;
}
if (argument == "-iframework")
{
insertFramework = true;
}
}
}
std::vector<std::string> paths;
for(std::string p : searchPaths)
{
paths.push_back(p);
m_searchPaths.push_back(p);
}
return paths;
}
std::vector<std::string> SolutionParserCompilationDatabase::getProjectFiles()
{
return std::vector<std::string>();
@@ -26,10 +26,15 @@ public:
virtual std::vector<std::string> getProjectFiles();
virtual std::vector<std::string> getProjectItems();
virtual std::vector<std::string> getIncludePaths();
std::vector<std::string> getFrameworkPaths();
private:
std::shared_ptr<clang::tooling::JSONCompilationDatabase> m_database;
void parseDatabase();
bool m_parsed;
clang::tooling::JSONCompilationDatabase* getDatabase();
std::vector<std::string> m_searchPaths;
std::vector<std::string> m_frameworkPaths;
std::string getIncludePath(const std::string& argument, const std::string& dir);
};