forked from qt-creator/qt-creator
Clang: Add clang query
Clang query is mechanism to use AST matcher to search for code. Think about regular expression but in the context of AST. So you get a semantic search tool for C++. Change-Id: I72e882c5b53a0c52f352a3664847c4c3e4f6fc2e Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -27,15 +27,31 @@
|
||||
|
||||
#include "clangbackendipc_global.h"
|
||||
|
||||
#include <utils/smallstring.h>
|
||||
#include <utils/smallstringio.h>
|
||||
|
||||
#include <QDataStream>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
struct FilePath
|
||||
class FilePath
|
||||
{
|
||||
public:
|
||||
FilePath() = default;
|
||||
explicit FilePath(const QString &filePath)
|
||||
{
|
||||
Utils::SmallString utf8FilePath = filePath;
|
||||
|
||||
auto foundReverse = std::find(utf8FilePath.rbegin(), utf8FilePath.rend(), '/');
|
||||
auto found = foundReverse.base();
|
||||
|
||||
Utils::SmallString fileName(found, utf8FilePath.end());
|
||||
if (foundReverse != utf8FilePath.rend())
|
||||
utf8FilePath.resize(std::size_t(std::distance(utf8FilePath.begin(), --found)));
|
||||
|
||||
directory_ = std::move(utf8FilePath);
|
||||
name_ = std::move(fileName);
|
||||
}
|
||||
|
||||
FilePath(Utils::SmallString &&directory, Utils::SmallString &&name)
|
||||
: directory_(std::move(directory)),
|
||||
name_(std::move(name))
|
||||
@@ -46,11 +62,21 @@ public:
|
||||
return directory_;
|
||||
}
|
||||
|
||||
Utils::SmallString takeDirectory()
|
||||
{
|
||||
return std::move(directory_);
|
||||
}
|
||||
|
||||
const Utils::SmallString &name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
Utils::SmallString takeName()
|
||||
{
|
||||
return std::move(name_);
|
||||
}
|
||||
|
||||
friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath)
|
||||
{
|
||||
out << filePath.directory_;
|
||||
@@ -67,6 +93,13 @@ public:
|
||||
return in;
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &out, const FilePath &filePath)
|
||||
{
|
||||
out << filePath.directory() << "/" << filePath.name();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
friend bool operator==(const FilePath &first, const FilePath &second)
|
||||
{
|
||||
return first.directory_ == second.directory_
|
||||
|
||||
Reference in New Issue
Block a user