Clang: Process SymbolKind and SymbolTags with the indexer

We add the infrastructure to compute the SymbolKind and SymbolTags in the
indexer. Later we have to add more for templates, virtual functions etc..

Change-Id: I9203c5cfbfffed3065337292010de5fce5736453
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-03-22 17:46:43 +01:00
parent a8b11cb2c5
commit de4f6301e6
12 changed files with 294 additions and 55 deletions

View File

@@ -65,7 +65,6 @@ HEADERS += \
SOURCES += \
$$PWD/sourcerangefilter.cpp \
$$PWD/symbolindexer.cpp \
$$PWD/symbolentry.cpp \
$$PWD/projectpartartefact.cpp \
$$PWD/filestatuscache.cpp \
$$PWD/indexdataconsumer.cpp

View File

@@ -243,7 +243,9 @@ public:
if (usr) {
m_symbolEntries.emplace(std::piecewise_construct,
std::forward_as_tuple(globalId),
std::forward_as_tuple(std::move(usr.value()), macroName));
std::forward_as_tuple(std::move(usr.value()),
macroName,
SymbolKind::Macro));
}
}

View File

@@ -28,6 +28,7 @@
#include <clang/Basic/SourceLocation.h>
#include <clang/Index/IndexSymbol.h>
#include <clang/AST/Decl.h>
#include <clang/AST/DeclVisitor.h>
#include <llvm/ADT/ArrayRef.h>
@@ -56,6 +57,41 @@ SymbolType symbolType(clang::index::SymbolRoleSet roles)
return SymbolType::None;
}
using SymbolKindAndTags = std::pair<SymbolKind, SymbolTags>;
class IndexingDeclVisitor : public clang::ConstDeclVisitor<IndexingDeclVisitor, SymbolKindAndTags>
{
public:
SymbolKindAndTags VisitTagDecl(const clang::TagDecl *declaration)
{
SymbolKindAndTags result = {SymbolKind::Tag, {}};
switch (declaration->getTagKind()) {
case clang::TTK_Struct: result.second.push_back(SymbolTag::Struct); break;
case clang::TTK_Interface: result.second.push_back(SymbolTag::MsvcInterface); break;
case clang::TTK_Union: result.second.push_back(SymbolTag::Union); break;
case clang::TTK_Class: result.second.push_back(SymbolTag::Class); break;
case clang::TTK_Enum: result.second.push_back(SymbolTag::Enumeration); break;
}
return result;
}
SymbolKindAndTags VisitFunctionDecl(const clang::FunctionDecl*)
{
return {SymbolKind::Function, {}};
}
SymbolKindAndTags VisitVarDecl(const clang::VarDecl*)
{
return {SymbolKind::Variable, {}};
}
};
SymbolKindAndTags symbolKindAndTags(const clang::Decl *declaration)
{
static IndexingDeclVisitor visitor;
return visitor.Visit(declaration);
}
}
bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration,
@@ -78,9 +114,13 @@ bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration,
if (found == m_symbolEntries.end()) {
Utils::optional<Utils::PathString> usr = generateUSR(namedDeclaration);
if (usr) {
auto kindAndTags = symbolKindAndTags(declaration);
m_symbolEntries.emplace(std::piecewise_construct,
std::forward_as_tuple(globalId),
std::forward_as_tuple(std::move(usr.value()), symbolName(namedDeclaration)));
std::forward_as_tuple(std::move(usr.value()),
symbolName(namedDeclaration),
kindAndTags.first,
kindAndTags.second));
}
}

View File

@@ -1,41 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "symbolentry.h"
#include <utils/smallstringio.h>
namespace ClangBackEnd {
std::ostream &operator<<(std::ostream &out, const SymbolEntry &entry)
{
out << "("
<< entry.symbolName << ", "
<< entry.usr <<")";
return out;
}
} // namespace ClangBackEnd

View File

@@ -28,6 +28,7 @@
#include <stringcachefwd.h>
#include <utils/smallstring.h>
#include <utils/sizedarray.h>
#include <limits>
#include <unordered_map>
@@ -37,26 +38,53 @@ namespace ClangBackEnd {
using SymbolIndex = long long;
enum class SymbolKind : uchar
{
None = 0,
Tag,
Function,
Variable,
Macro
};
enum class SymbolTag : uchar
{
None = 0,
Class,
Struct,
Enumeration,
Union,
MsvcInterface
};
using SymbolTags = Utils::SizedArray<SymbolTag, 7>;
class SymbolEntry
{
public:
SymbolEntry(Utils::PathString &&usr,
Utils::SmallString &&symbolName)
Utils::SmallString &&symbolName,
SymbolKind symbolKind,
SymbolTags symbolTags={})
: usr(std::move(usr)),
symbolName(std::move(symbolName))
symbolName(std::move(symbolName)),
symbolKind(symbolKind),
symbolTags(symbolTags)
{}
Utils::PathString usr;
Utils::SmallString symbolName;
SymbolKind symbolKind;
SymbolTags symbolTags;
friend bool operator==(const SymbolEntry &first, const SymbolEntry &second)
{
return first.usr == second.usr && first.symbolName == second.symbolName;
return first.usr == second.usr
&& first.symbolName == second.symbolName
&& first.symbolKind == second.symbolKind;
}
};
using SymbolEntries = std::unordered_map<SymbolIndex, SymbolEntry>;
std::ostream &operator<<(std::ostream &out, const SymbolEntry &entry);
} // namespace ClangBackEnd