forked from qt-creator/qt-creator
Clang: Simplify name and type in FullTokenInfo for functions
Take Cursor displayName instead of token name. From now on type spelling can serve the return type role for functions because together with 'token' member they form the full type. Change-Id: Ic8eec533f4a11458f99f070b6a6aa80714097b4d Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -77,7 +77,6 @@ QDebug operator<<(QDebug debug, const ExtraInfo &extraInfo)
|
||||
debug.nospace() << "ExtraInfo("
|
||||
<< extraInfo.token << ", "
|
||||
<< extraInfo.typeSpelling << ", "
|
||||
<< extraInfo.resultTypeSpelling << ", "
|
||||
<< extraInfo.semanticParentTypeSpelling << ", "
|
||||
<< extraInfo.cursorRange << ", "
|
||||
<< extraInfo.lexicalParentIndex << ", "
|
||||
|
||||
@@ -60,14 +60,13 @@ struct ExtraInfo
|
||||
, slot(false)
|
||||
{
|
||||
}
|
||||
ExtraInfo(Utf8String token, Utf8String typeSpelling, Utf8String resultTypeSpelling,
|
||||
ExtraInfo(Utf8String token, Utf8String typeSpelling,
|
||||
Utf8String semanticParentTypeSpelling, SourceRangeContainer cursorRange,
|
||||
int lexicalParentIndex, AccessSpecifier accessSpecifier, StorageClass storageClass,
|
||||
bool isIdentifier, bool isInclusion, bool isDeclaration, bool isDefinition,
|
||||
bool isSignal, bool isSlot)
|
||||
: token(token)
|
||||
, typeSpelling(typeSpelling)
|
||||
, resultTypeSpelling(resultTypeSpelling)
|
||||
, semanticParentTypeSpelling(semanticParentTypeSpelling)
|
||||
, cursorRange(cursorRange)
|
||||
, lexicalParentIndex(lexicalParentIndex)
|
||||
@@ -83,7 +82,6 @@ struct ExtraInfo
|
||||
}
|
||||
Utf8String token;
|
||||
Utf8String typeSpelling;
|
||||
Utf8String resultTypeSpelling;
|
||||
Utf8String semanticParentTypeSpelling;
|
||||
SourceRangeContainer cursorRange;
|
||||
int lexicalParentIndex = -1;
|
||||
@@ -183,7 +181,6 @@ inline QDataStream &operator<<(QDataStream &out, const ExtraInfo &extraInfo)
|
||||
{
|
||||
out << extraInfo.token;
|
||||
out << extraInfo.typeSpelling;
|
||||
out << extraInfo.resultTypeSpelling;
|
||||
out << extraInfo.semanticParentTypeSpelling;
|
||||
out << extraInfo.cursorRange;
|
||||
out << extraInfo.lexicalParentIndex;
|
||||
@@ -202,7 +199,6 @@ inline QDataStream &operator>>(QDataStream &in, ExtraInfo &extraInfo)
|
||||
{
|
||||
in >> extraInfo.token;
|
||||
in >> extraInfo.typeSpelling;
|
||||
in >> extraInfo.resultTypeSpelling;
|
||||
in >> extraInfo.semanticParentTypeSpelling;
|
||||
in >> extraInfo.cursorRange;
|
||||
in >> extraInfo.lexicalParentIndex;
|
||||
@@ -240,7 +236,6 @@ inline bool operator==(const ExtraInfo &first, const ExtraInfo &second)
|
||||
{
|
||||
return first.token == second.token
|
||||
&& first.typeSpelling == second.typeSpelling
|
||||
&& first.resultTypeSpelling == second.resultTypeSpelling
|
||||
&& first.semanticParentTypeSpelling == second.semanticParentTypeSpelling
|
||||
&& first.cursorRange == second.cursorRange
|
||||
&& first.lexicalParentIndex == second.lexicalParentIndex
|
||||
|
||||
@@ -66,11 +66,9 @@ ClangCurrentDocumentFilter::ClangCurrentDocumentFilter()
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
static QString addResultTypeToFunctionSignature(const QString &signature,
|
||||
const ClangBackEnd::ExtraInfo &extraInfo)
|
||||
static QString addType(const QString &signature, const ClangBackEnd::ExtraInfo &extraInfo)
|
||||
{
|
||||
return signature + extraInfo.typeSpelling.toString() + QLatin1String(" -> ", 4)
|
||||
+ extraInfo.resultTypeSpelling.toString();
|
||||
return signature + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString();
|
||||
}
|
||||
|
||||
static QString addTypeToVariableName(const QString &name, const ClangBackEnd::ExtraInfo &extraInfo)
|
||||
@@ -89,7 +87,7 @@ static Core::LocatorFilterEntry makeEntry(Core::ILocatorFilter *filter,
|
||||
ClangBackEnd::HighlightingType mainType = info.types.mainHighlightingType;
|
||||
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|
||||
|| mainType == ClangBackEnd::HighlightingType::Function) {
|
||||
displayName = addResultTypeToFunctionSignature(displayName, extraInfo);
|
||||
displayName = addType(displayName, extraInfo);
|
||||
extra = extraInfo.semanticParentTypeSpelling.toString();
|
||||
} else if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|
||||
|| mainType == ClangBackEnd::HighlightingType::Field
|
||||
|
||||
@@ -86,14 +86,7 @@ void buildTree(const TokenContainers &containers,
|
||||
addFirstItem(root);
|
||||
}
|
||||
|
||||
static QString addResultTypeToFunctionSignature(const QString &signature,
|
||||
const ClangBackEnd::ExtraInfo &extraInfo)
|
||||
{
|
||||
return signature + extraInfo.typeSpelling.toString() + QLatin1String(" -> ", 4)
|
||||
+ extraInfo.resultTypeSpelling.toString();
|
||||
}
|
||||
|
||||
static QString addTypeToVariableName(const QString &name, const ClangBackEnd::ExtraInfo &extraInfo)
|
||||
static QString addType(const QString &name, const ClangBackEnd::ExtraInfo &extraInfo)
|
||||
{
|
||||
return name + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString();
|
||||
}
|
||||
@@ -116,11 +109,11 @@ QVariant TokenTreeItem::data(int column, int role) const
|
||||
|
||||
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|
||||
|| mainType == ClangBackEnd::HighlightingType::Function) {
|
||||
name = addResultTypeToFunctionSignature(name, token.extraInfo);
|
||||
name = addType(name, token.extraInfo);
|
||||
} else if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|
||||
|| mainType == ClangBackEnd::HighlightingType::Field
|
||||
|| mainType == ClangBackEnd::HighlightingType::QtProperty) {
|
||||
name = addTypeToVariableName(name, token.extraInfo);
|
||||
name = addType(name, token.extraInfo);
|
||||
if (token.types.mixinHighlightingTypes.contains(
|
||||
ClangBackEnd::HighlightingType::ObjectiveCProperty)) {
|
||||
name = QLatin1String("@property ") + name;
|
||||
|
||||
@@ -66,15 +66,9 @@ void FullTokenInfo::updateTypeSpelling(const Cursor &cursor, bool functionLike)
|
||||
if (!functionLike)
|
||||
return;
|
||||
Type type = cursor.type().canonical();
|
||||
m_extraInfo.resultTypeSpelling = type.resultType().utf8Spelling();
|
||||
bool hasSpaceAfterReturnType = false;
|
||||
if (m_extraInfo.resultTypeSpelling.byteSize() < m_extraInfo.typeSpelling.byteSize()) {
|
||||
const char *data = m_extraInfo.typeSpelling.constData();
|
||||
hasSpaceAfterReturnType = (data[m_extraInfo.resultTypeSpelling.byteSize()] == ' ');
|
||||
}
|
||||
m_extraInfo.typeSpelling
|
||||
= m_extraInfo.typeSpelling.mid(m_extraInfo.resultTypeSpelling.byteSize()
|
||||
+ (hasSpaceAfterReturnType ? 1 : 0));
|
||||
m_extraInfo.token = cursor.displayName();
|
||||
// On the client side full type is typeSpelling + token.
|
||||
m_extraInfo.typeSpelling = type.resultType().utf8Spelling();
|
||||
}
|
||||
|
||||
static Utf8String propertyParentSpelling(CXTranslationUnit cxTranslationUnit,
|
||||
|
||||
@@ -556,7 +556,6 @@ std::ostream &operator<<(std::ostream &os, const ExtraInfo &extraInfo)
|
||||
os << "("
|
||||
<< extraInfo.token << ", "
|
||||
<< extraInfo.typeSpelling << ", "
|
||||
<< extraInfo.resultTypeSpelling << ", "
|
||||
<< extraInfo.semanticParentTypeSpelling << ", "
|
||||
<< static_cast<uint>(extraInfo.accessSpecifier) << ", "
|
||||
<< static_cast<uint>(extraInfo.storageClass) << ", "
|
||||
|
||||
Reference in New Issue
Block a user