forked from qt-creator/qt-creator
Clang: Helper function to get token IconType
Change-Id: I9de562102eded9391ab0d6b895b8d812e259efd6 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@@ -110,6 +111,13 @@ public:
|
|||||||
std::array<T, MaxSize>::fill(T{});
|
std::array<T, MaxSize>::fill(T{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool contains(const T &item) const
|
||||||
|
{
|
||||||
|
return std::any_of(begin(), end(), [&item](const T ¤t) {
|
||||||
|
return item == current;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
friend std::ostream &operator<<(std::ostream &out, SizedArray array)
|
friend std::ostream &operator<<(std::ostream &out, SizedArray array)
|
||||||
{
|
{
|
||||||
out << "[";
|
out << "[";
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
#include "clangeditordocumentprocessor.h"
|
#include "clangeditordocumentprocessor.h"
|
||||||
#include "clangmodelmanagersupport.h"
|
#include "clangmodelmanagersupport.h"
|
||||||
|
|
||||||
|
#include <clangsupport/tokeninfocontainer.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
#include <cpptools/baseeditordocumentparser.h>
|
#include <cpptools/baseeditordocumentparser.h>
|
||||||
@@ -38,6 +40,8 @@
|
|||||||
#include <cpptools/cppcodemodelsettings.h>
|
#include <cpptools/cppcodemodelsettings.h>
|
||||||
#include <cpptools/cpptoolsreuse.h>
|
#include <cpptools/cpptoolsreuse.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -201,5 +205,104 @@ int clangColumn(const QTextBlock &line, int cppEditorColumn)
|
|||||||
return line.text().left(cppEditorColumn).toUtf8().size() + 1;
|
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 Utils
|
||||||
} // namespace Clang
|
} // namespace Clang
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cplusplus/Icons.h>
|
||||||
|
|
||||||
#include <cpptools/projectpart.h>
|
#include <cpptools/projectpart.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@@ -35,6 +37,8 @@ namespace CppTools {
|
|||||||
class CppEditorDocumentHandle;
|
class CppEditorDocumentHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace ClangBackEnd { class TokenInfoContainer; }
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
@@ -52,5 +56,7 @@ bool isProjectPartLoaded(const CppTools::ProjectPart::Ptr projectPart);
|
|||||||
QString projectPartIdForFile(const QString &filePath);
|
QString projectPartIdForFile(const QString &filePath);
|
||||||
int clangColumn(const QTextBlock &lineText, int cppEditorColumn);
|
int clangColumn(const QTextBlock &lineText, int cppEditorColumn);
|
||||||
|
|
||||||
|
CPlusPlus::Icons::IconType iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
} // namespace Clang
|
} // namespace Clang
|
||||||
|
|||||||
Reference in New Issue
Block a user