Clang: Locator filter for the symbol database

There are no symbol queries for the locator filters. The signature
generation is still not implemented but for simple cases it should work.

Change-Id: Ic6b04fbe1e7e057892f194ac139615c47d6ec33f
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-04-09 13:30:30 +02:00
parent 18de1e3fcf
commit 4b0bcbdcb6
57 changed files with 649 additions and 1118 deletions

View File

@@ -112,7 +112,7 @@ public:
addUsedMacro(macroNameToken, macroDefinition);
addMacroAsSymbol(macroNameToken,
firstMacroInfo(macroDefinition.getLocalDirective()),
SymbolType::MacroUsage);
SourceLocationKind::MacroUsage);
}
void Ifdef(clang::SourceLocation,
@@ -122,7 +122,7 @@ public:
addUsedMacro( macroNameToken, macroDefinition);
addMacroAsSymbol(macroNameToken,
firstMacroInfo(macroDefinition.getLocalDirective()),
SymbolType::MacroUsage);
SourceLocationKind::MacroUsage);
}
void Defined(const clang::Token &macroNameToken,
@@ -132,13 +132,13 @@ public:
addUsedMacro(macroNameToken, macroDefinition);
addMacroAsSymbol(macroNameToken,
firstMacroInfo(macroDefinition.getLocalDirective()),
SymbolType::MacroUsage);
SourceLocationKind::MacroUsage);
}
void MacroDefined(const clang::Token &macroNameToken,
const clang::MacroDirective *macroDirective) override
{
addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDirective), SymbolType::MacroDefinition);
addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDirective), SourceLocationKind::MacroDefinition);
}
void MacroUndefined(const clang::Token &macroNameToken,
@@ -147,7 +147,7 @@ public:
{
addMacroAsSymbol(macroNameToken,
firstMacroInfo(macroDefinition.getLocalDirective()),
SymbolType::MacroUndefinition);
SourceLocationKind::MacroUndefinition);
}
void MacroExpands(const clang::Token &macroNameToken,
@@ -158,7 +158,7 @@ public:
addUsedMacro(macroNameToken, macroDefinition);
addMacroAsSymbol(macroNameToken,
firstMacroInfo(macroDefinition.getLocalDirective()),
SymbolType::MacroUsage);
SourceLocationKind::MacroUsage);
}
void EndOfMainFile() override
@@ -228,7 +228,7 @@ public:
void addMacroAsSymbol(const clang::Token &macroNameToken,
const clang::MacroInfo *macroInfo,
SymbolType symbolType)
SourceLocationKind symbolType)
{
clang::SourceLocation sourceLocation = macroNameToken.getLocation();
if (macroInfo && sourceLocation.isFileID()) {

View File

@@ -47,16 +47,16 @@ Utils::SmallString symbolName(const clang::NamedDecl *declaration)
return declarationName.getAsString();
}
SymbolType symbolType(clang::index::SymbolRoleSet roles)
SourceLocationKind sourceLocationKind(clang::index::SymbolRoleSet roles)
{
if (hasSymbolRole(clang::index::SymbolRole::Reference, roles))
return SymbolType::DeclarationReference;
return SourceLocationKind::DeclarationReference;
else if (hasSymbolRole(clang::index::SymbolRole::Declaration, roles))
return SymbolType::Declaration;
return SourceLocationKind::Declaration;
else if (hasSymbolRole(clang::index::SymbolRole::Definition, roles))
return SymbolType::Definition;
return SourceLocationKind::Definition;
return SymbolType::None;
return SourceLocationKind::None;
}
using SymbolKindAndTags = std::pair<SymbolKind, SymbolTags>;
@@ -133,7 +133,7 @@ bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration,
m_sourceLocationEntries.emplace_back(globalId,
filePathId(sourceLocation),
lineColum(sourceLocation),
symbolType(symbolRoles));
sourceLocationKind(symbolRoles));
}
return true;

View File

@@ -36,17 +36,6 @@ using uint = unsigned int;
namespace ClangBackEnd {
enum class SymbolType
{
None = 0,
Declaration,
DeclarationReference,
Definition,
MacroDefinition = 1024,
MacroUsage,
MacroUndefinition
};
using SymbolIndex = long long;
class SourceLocationEntry
@@ -55,24 +44,24 @@ public:
SourceLocationEntry(SymbolIndex symbolId,
FilePathId filePathId,
Utils::LineColumn lineColumn,
SymbolType symbolType)
SourceLocationKind kind)
: symbolId(symbolId),
filePathId(filePathId),
lineColumn(lineColumn),
symbolType(symbolType)
kind(kind)
{}
SymbolIndex symbolId = 0;
FilePathId filePathId;
Utils::LineColumn lineColumn;
SymbolType symbolType;
SourceLocationKind kind;
friend bool operator==(const SourceLocationEntry &first, const SourceLocationEntry &second)
{
return first.symbolId == second.symbolId
&& first.filePathId == second.filePathId
&& first.lineColumn == second.lineColumn
&& first.symbolType == second.symbolType;
&& first.kind == second.kind;
}
};

View File

@@ -73,6 +73,7 @@ public:
const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer);
const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer);
const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer);
table.addColumn("locationKind", Sqlite::ColumnType::Integer);
table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn});
table.initialize(database);
@@ -119,7 +120,7 @@ public:
"INSERT INTO newSymbols(temporarySymbolId, usr, symbolName, symbolKind) VALUES(?,?,?,?)",
database};
WriteStatement insertLocationsToNewLocationsStatement{
"INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)",
"INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, locationKind) VALUES(?,?,?,?,?)",
database
};
ReadStatement selectNewSourceIdsStatement{
@@ -145,7 +146,7 @@ public:
database
};
WriteStatement insertNewLocationsInLocationsStatement{
"INSERT INTO locations(symbolId, line, column, sourceId) SELECT symbolId, line, column, sourceId FROM newLocations",
"INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, line, column, sourceId, locationKind FROM newLocations",
database
};
WriteStatement deleteNewSymbolsTableStatement{

View File

@@ -210,11 +210,12 @@ public:
{
WriteStatement &statement = m_statementFactory.insertLocationsToNewLocationsStatement;
for (const auto &locationsEntry : sourceLocations) {
statement.write(locationsEntry.symbolId,
locationsEntry.lineColumn.line,
locationsEntry.lineColumn.column,
locationsEntry.filePathId.filePathId);
for (const auto &locationEntry : sourceLocations) {
statement.write(locationEntry.symbolId,
locationEntry.lineColumn.line,
locationEntry.lineColumn.column,
locationEntry.filePathId.filePathId,
int(locationEntry.kind));
}
}