Clang: Helper function to get token IconType

Change-Id: I9de562102eded9391ab0d6b895b8d812e259efd6
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-02-09 13:51:39 +01:00
parent 9a3dff8934
commit 524d3ea28b
3 changed files with 117 additions and 0 deletions

View File

@@ -25,6 +25,7 @@
#pragma once
#include <algorithm>
#include <array>
#include <cstdint>
#include <ostream>
@@ -110,6 +111,13 @@ public:
std::array<T, MaxSize>::fill(T{});
}
bool contains(const T &item) const
{
return std::any_of(begin(), end(), [&item](const T &current) {
return item == current;
});
}
friend std::ostream &operator<<(std::ostream &out, SizedArray array)
{
out << "[";

View File

@@ -28,6 +28,8 @@
#include "clangeditordocumentprocessor.h"
#include "clangmodelmanagersupport.h"
#include <clangsupport/tokeninfocontainer.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cpptools/baseeditordocumentparser.h>
@@ -38,6 +40,8 @@
#include <cpptools/cppcodemodelsettings.h>
#include <cpptools/cpptoolsreuse.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QDir>
@@ -201,5 +205,104 @@ int clangColumn(const QTextBlock &line, int cppEditorColumn)
return line.text().left(cppEditorColumn).toUtf8().size() + 1;
}
CPlusPlus::Icons::IconType iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token)
{
const ClangBackEnd::ExtraInfo &extraInfo = token.extraInfo();
if (extraInfo.signal)
return CPlusPlus::Icons::SignalIconType;
ClangBackEnd::AccessSpecifier access = extraInfo.accessSpecifier;
if (extraInfo.slot) {
switch (access) {
case ClangBackEnd::AccessSpecifier::Public:
case ClangBackEnd::AccessSpecifier::Invalid:
return CPlusPlus::Icons::SlotPublicIconType;
case ClangBackEnd::AccessSpecifier::Protected:
return CPlusPlus::Icons::SlotProtectedIconType;
case ClangBackEnd::AccessSpecifier::Private:
return CPlusPlus::Icons::SlotPrivateIconType;
}
}
ClangBackEnd::HighlightingType mainType = token.types().mainHighlightingType;
if (mainType == ClangBackEnd::HighlightingType::Keyword)
return CPlusPlus::Icons::KeywordIconType;
if (mainType == ClangBackEnd::HighlightingType::QtProperty)
return CPlusPlus::Icons::PropertyIconType;
if (mainType == ClangBackEnd::HighlightingType::PreprocessorExpansion
|| mainType == ClangBackEnd::HighlightingType::PreprocessorDefinition) {
return CPlusPlus::Icons::MacroIconType;
}
if (mainType == ClangBackEnd::HighlightingType::Enumeration)
return CPlusPlus::Icons::EnumeratorIconType;
if (mainType == ClangBackEnd::HighlightingType::Type) {
const ClangBackEnd::MixinHighlightingTypes &types = token.types().mixinHighlightingTypes;
if (types.contains(ClangBackEnd::HighlightingType::Enum))
return CPlusPlus::Icons::EnumIconType;
if (types.contains(ClangBackEnd::HighlightingType::Struct))
return CPlusPlus::Icons::StructIconType;
if (types.contains(ClangBackEnd::HighlightingType::Namespace))
return CPlusPlus::Icons::NamespaceIconType;
return CPlusPlus::Icons::ClassIconType;
}
ClangBackEnd::StorageClass storageClass = extraInfo.storageClass;
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|| mainType == ClangBackEnd::HighlightingType::Function) {
if (storageClass != ClangBackEnd::StorageClass::Static) {
switch (access) {
case ClangBackEnd::AccessSpecifier::Public:
case ClangBackEnd::AccessSpecifier::Invalid:
return CPlusPlus::Icons::FuncPublicIconType;
case ClangBackEnd::AccessSpecifier::Protected:
return CPlusPlus::Icons::FuncProtectedIconType;
case ClangBackEnd::AccessSpecifier::Private:
return CPlusPlus::Icons::FuncPrivateIconType;
}
} else {
switch (access) {
case ClangBackEnd::AccessSpecifier::Public:
case ClangBackEnd::AccessSpecifier::Invalid:
return CPlusPlus::Icons::FuncPublicStaticIconType;
case ClangBackEnd::AccessSpecifier::Protected:
return CPlusPlus::Icons::FuncProtectedStaticIconType;
case ClangBackEnd::AccessSpecifier::Private:
return CPlusPlus::Icons::FuncPrivateStaticIconType;
}
}
}
if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|| mainType == ClangBackEnd::HighlightingType::Field) {
if (storageClass != ClangBackEnd::StorageClass::Static) {
switch (access) {
case ClangBackEnd::AccessSpecifier::Public:
case ClangBackEnd::AccessSpecifier::Invalid:
return CPlusPlus::Icons::VarPublicIconType;
case ClangBackEnd::AccessSpecifier::Protected:
return CPlusPlus::Icons::VarProtectedIconType;
case ClangBackEnd::AccessSpecifier::Private:
return CPlusPlus::Icons::VarPrivateIconType;
}
} else {
switch (access) {
case ClangBackEnd::AccessSpecifier::Public:
case ClangBackEnd::AccessSpecifier::Invalid:
return CPlusPlus::Icons::VarPublicStaticIconType;
case ClangBackEnd::AccessSpecifier::Protected:
return CPlusPlus::Icons::VarProtectedStaticIconType;
case ClangBackEnd::AccessSpecifier::Private:
return CPlusPlus::Icons::VarPrivateStaticIconType;
}
}
}
return CPlusPlus::Icons::UnknownIconType;
}
} // namespace Utils
} // namespace Clang

View File

@@ -25,6 +25,8 @@
#pragma once
#include <cplusplus/Icons.h>
#include <cpptools/projectpart.h>
QT_BEGIN_NAMESPACE
@@ -35,6 +37,8 @@ namespace CppTools {
class CppEditorDocumentHandle;
}
namespace ClangBackEnd { class TokenInfoContainer; }
namespace ClangCodeModel {
namespace Utils {
@@ -52,5 +56,7 @@ bool isProjectPartLoaded(const CppTools::ProjectPart::Ptr projectPart);
QString projectPartIdForFile(const QString &filePath);
int clangColumn(const QTextBlock &lineText, int cppEditorColumn);
CPlusPlus::Icons::IconType iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
} // namespace Utils
} // namespace Clang