logic: improved include detection
* also search for include paths of include directives extracted from header search paths * extracted logic to gather unsolved includes * extracted some code to filetree class
This commit is contained in:
@@ -356,6 +356,8 @@ add_files(
|
||||
utility/file/FileRegisterStateData.h
|
||||
utility/file/FileSystem.cpp
|
||||
utility/file/FileSystem.h
|
||||
utility/file/FileTree.cpp
|
||||
utility/file/FileTree.h
|
||||
|
||||
utility/interprocess/SharedMemory.cpp
|
||||
utility/interprocess/SharedMemory.h
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#include "utility/file/FileTree.h"
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
|
||||
FileTree::FileTree(const FilePath& rootPath)
|
||||
: m_rootPath(rootPath.getAbsolute().makeCanonical())
|
||||
{
|
||||
if (m_rootPath.exists())
|
||||
{
|
||||
if (m_rootPath.isDirectory())
|
||||
{
|
||||
for (const FilePath& filePath : FileSystem::getFilePathsFromDirectory(m_rootPath))
|
||||
{
|
||||
m_files[filePath.fileName()].insert(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_files[m_rootPath.fileName()].insert(m_rootPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilePath FileTree::getAbsoluteRootPathForRelativeFilePath(const FilePath& relativeFilePath)
|
||||
{
|
||||
std::vector<FilePath> rootPaths = doGetAbsoluteRootPathsForRelativeFilePath(relativeFilePath, false);
|
||||
if (!rootPaths.empty())
|
||||
{
|
||||
return rootPaths.front();
|
||||
}
|
||||
return FilePath();
|
||||
}
|
||||
|
||||
std::vector<FilePath> FileTree::getAbsoluteRootPathsForRelativeFilePath(const FilePath& relativeFilePath)
|
||||
{
|
||||
return doGetAbsoluteRootPathsForRelativeFilePath(relativeFilePath, true);
|
||||
}
|
||||
|
||||
std::vector<FilePath> FileTree::doGetAbsoluteRootPathsForRelativeFilePath(const FilePath& relativeFilePath, bool allowMultipleResults)
|
||||
{
|
||||
std::vector<FilePath> rootPaths;
|
||||
|
||||
std::unordered_map<std::string, std::set<FilePath>>::const_iterator it = m_files.find(relativeFilePath.fileName());
|
||||
if (it != m_files.end())
|
||||
{
|
||||
for (FilePath existingFilePath : it->second)
|
||||
{
|
||||
existingFilePath = existingFilePath.getParentDirectory();
|
||||
bool ok = true;
|
||||
{
|
||||
FilePath temp = relativeFilePath.getParentDirectory();
|
||||
while (!temp.empty())
|
||||
{
|
||||
if (temp.fileName() == "..")
|
||||
{
|
||||
std::vector<FilePath> subDirectories = FileSystem::getDirectSubDirectories(existingFilePath);
|
||||
if (!subDirectories.empty())
|
||||
{
|
||||
existingFilePath = subDirectories.front();
|
||||
}
|
||||
else
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
existingFilePath = existingFilePath.getParentDirectory();
|
||||
}
|
||||
temp = temp.getParentDirectory();
|
||||
}
|
||||
}
|
||||
if (ok)
|
||||
{
|
||||
rootPaths.push_back(existingFilePath);
|
||||
if (!allowMultipleResults)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rootPaths;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef FILE_TREE_H
|
||||
#define FILE_TREE_H
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class FileTree
|
||||
{
|
||||
public:
|
||||
FileTree(const FilePath& rootPath);
|
||||
|
||||
FilePath getAbsoluteRootPathForRelativeFilePath(const FilePath& relativeFilePath);
|
||||
std::vector<FilePath> getAbsoluteRootPathsForRelativeFilePath(const FilePath& relativeFilePath);
|
||||
|
||||
private:
|
||||
std::vector<FilePath> doGetAbsoluteRootPathsForRelativeFilePath(const FilePath& relativeFilePath, bool allowMultipleResults);
|
||||
|
||||
FilePath m_rootPath;
|
||||
std::unordered_map<std::string, std::set<FilePath>> m_files;
|
||||
};
|
||||
|
||||
#endif // FILE_TREE_H
|
||||
Reference in New Issue
Block a user