Clang: Add usage functions to symbol query

Change-Id: If68a5119c863e616fea40275136d028abcf441f3
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-10-18 13:38:58 +02:00
committed by Tim Jenssen
parent 0a3df84533
commit b9d268977e
10 changed files with 169 additions and 27 deletions

View File

@@ -44,6 +44,11 @@ public:
" (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?) "
"ORDER BY sourceId, line, column",
database};
ReadStatement selectSourceUsagesForSymbolLocation{
"SELECT directoryPath || '/' || sourceName, line, column "
"FROM locations NATURAL JOIN sources NATURAL JOIN directories "
"WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?)",
database};
};
} // namespace ClangRefactoring

View File

@@ -43,6 +43,14 @@ public:
: filePathId{directoryId, sourceId}, line(line), column(column)
{}
friend bool operator==(SourceLocation first, SourceLocation second)
{
return first.filePathId == second.filePathId
&& first.line == second.line
&& first.column == second.column;
}
public:
ClangBackEnd::FilePathId filePathId;
int line;
int column;

View File

@@ -30,6 +30,8 @@
#include <filepathid.h>
#include <sourcelocations.h>
#include <cpptools/usages.h>
#include <algorithm>
namespace ClangRefactoring {
@@ -56,6 +58,18 @@ public:
utf8Column);
}
CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)
{
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation;
const std::size_t reserveSize = 128;
return locationsStatement.template values<CppTools::Usage, 3>(reserveSize,
filePathId.fileNameId,
line,
utf8Column);
}
private:
StatementFactory &m_statementFactory;
};