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("
|
debug.nospace() << "ExtraInfo("
|
||||||
<< extraInfo.token << ", "
|
<< extraInfo.token << ", "
|
||||||
<< extraInfo.typeSpelling << ", "
|
<< extraInfo.typeSpelling << ", "
|
||||||
<< extraInfo.resultTypeSpelling << ", "
|
|
||||||
<< extraInfo.semanticParentTypeSpelling << ", "
|
<< extraInfo.semanticParentTypeSpelling << ", "
|
||||||
<< extraInfo.cursorRange << ", "
|
<< extraInfo.cursorRange << ", "
|
||||||
<< extraInfo.lexicalParentIndex << ", "
|
<< extraInfo.lexicalParentIndex << ", "
|
||||||
|
|||||||
@@ -60,14 +60,13 @@ struct ExtraInfo
|
|||||||
, slot(false)
|
, slot(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
ExtraInfo(Utf8String token, Utf8String typeSpelling, Utf8String resultTypeSpelling,
|
ExtraInfo(Utf8String token, Utf8String typeSpelling,
|
||||||
Utf8String semanticParentTypeSpelling, SourceRangeContainer cursorRange,
|
Utf8String semanticParentTypeSpelling, SourceRangeContainer cursorRange,
|
||||||
int lexicalParentIndex, AccessSpecifier accessSpecifier, StorageClass storageClass,
|
int lexicalParentIndex, AccessSpecifier accessSpecifier, StorageClass storageClass,
|
||||||
bool isIdentifier, bool isInclusion, bool isDeclaration, bool isDefinition,
|
bool isIdentifier, bool isInclusion, bool isDeclaration, bool isDefinition,
|
||||||
bool isSignal, bool isSlot)
|
bool isSignal, bool isSlot)
|
||||||
: token(token)
|
: token(token)
|
||||||
, typeSpelling(typeSpelling)
|
, typeSpelling(typeSpelling)
|
||||||
, resultTypeSpelling(resultTypeSpelling)
|
|
||||||
, semanticParentTypeSpelling(semanticParentTypeSpelling)
|
, semanticParentTypeSpelling(semanticParentTypeSpelling)
|
||||||
, cursorRange(cursorRange)
|
, cursorRange(cursorRange)
|
||||||
, lexicalParentIndex(lexicalParentIndex)
|
, lexicalParentIndex(lexicalParentIndex)
|
||||||
@@ -83,7 +82,6 @@ struct ExtraInfo
|
|||||||
}
|
}
|
||||||
Utf8String token;
|
Utf8String token;
|
||||||
Utf8String typeSpelling;
|
Utf8String typeSpelling;
|
||||||
Utf8String resultTypeSpelling;
|
|
||||||
Utf8String semanticParentTypeSpelling;
|
Utf8String semanticParentTypeSpelling;
|
||||||
SourceRangeContainer cursorRange;
|
SourceRangeContainer cursorRange;
|
||||||
int lexicalParentIndex = -1;
|
int lexicalParentIndex = -1;
|
||||||
@@ -183,7 +181,6 @@ inline QDataStream &operator<<(QDataStream &out, const ExtraInfo &extraInfo)
|
|||||||
{
|
{
|
||||||
out << extraInfo.token;
|
out << extraInfo.token;
|
||||||
out << extraInfo.typeSpelling;
|
out << extraInfo.typeSpelling;
|
||||||
out << extraInfo.resultTypeSpelling;
|
|
||||||
out << extraInfo.semanticParentTypeSpelling;
|
out << extraInfo.semanticParentTypeSpelling;
|
||||||
out << extraInfo.cursorRange;
|
out << extraInfo.cursorRange;
|
||||||
out << extraInfo.lexicalParentIndex;
|
out << extraInfo.lexicalParentIndex;
|
||||||
@@ -202,7 +199,6 @@ inline QDataStream &operator>>(QDataStream &in, ExtraInfo &extraInfo)
|
|||||||
{
|
{
|
||||||
in >> extraInfo.token;
|
in >> extraInfo.token;
|
||||||
in >> extraInfo.typeSpelling;
|
in >> extraInfo.typeSpelling;
|
||||||
in >> extraInfo.resultTypeSpelling;
|
|
||||||
in >> extraInfo.semanticParentTypeSpelling;
|
in >> extraInfo.semanticParentTypeSpelling;
|
||||||
in >> extraInfo.cursorRange;
|
in >> extraInfo.cursorRange;
|
||||||
in >> extraInfo.lexicalParentIndex;
|
in >> extraInfo.lexicalParentIndex;
|
||||||
@@ -240,7 +236,6 @@ inline bool operator==(const ExtraInfo &first, const ExtraInfo &second)
|
|||||||
{
|
{
|
||||||
return first.token == second.token
|
return first.token == second.token
|
||||||
&& first.typeSpelling == second.typeSpelling
|
&& first.typeSpelling == second.typeSpelling
|
||||||
&& first.resultTypeSpelling == second.resultTypeSpelling
|
|
||||||
&& first.semanticParentTypeSpelling == second.semanticParentTypeSpelling
|
&& first.semanticParentTypeSpelling == second.semanticParentTypeSpelling
|
||||||
&& first.cursorRange == second.cursorRange
|
&& first.cursorRange == second.cursorRange
|
||||||
&& first.lexicalParentIndex == second.lexicalParentIndex
|
&& first.lexicalParentIndex == second.lexicalParentIndex
|
||||||
|
|||||||
@@ -66,11 +66,9 @@ ClangCurrentDocumentFilter::ClangCurrentDocumentFilter()
|
|||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString addResultTypeToFunctionSignature(const QString &signature,
|
static QString addType(const QString &signature, const ClangBackEnd::ExtraInfo &extraInfo)
|
||||||
const ClangBackEnd::ExtraInfo &extraInfo)
|
|
||||||
{
|
{
|
||||||
return signature + extraInfo.typeSpelling.toString() + QLatin1String(" -> ", 4)
|
return signature + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString();
|
||||||
+ extraInfo.resultTypeSpelling.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString addTypeToVariableName(const QString &name, const ClangBackEnd::ExtraInfo &extraInfo)
|
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;
|
ClangBackEnd::HighlightingType mainType = info.types.mainHighlightingType;
|
||||||
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|
||||||
|| mainType == ClangBackEnd::HighlightingType::Function) {
|
|| mainType == ClangBackEnd::HighlightingType::Function) {
|
||||||
displayName = addResultTypeToFunctionSignature(displayName, extraInfo);
|
displayName = addType(displayName, extraInfo);
|
||||||
extra = extraInfo.semanticParentTypeSpelling.toString();
|
extra = extraInfo.semanticParentTypeSpelling.toString();
|
||||||
} else if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|
} else if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|
||||||
|| mainType == ClangBackEnd::HighlightingType::Field
|
|| mainType == ClangBackEnd::HighlightingType::Field
|
||||||
|
|||||||
@@ -86,14 +86,7 @@ void buildTree(const TokenContainers &containers,
|
|||||||
addFirstItem(root);
|
addFirstItem(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString addResultTypeToFunctionSignature(const QString &signature,
|
static QString addType(const QString &name, const ClangBackEnd::ExtraInfo &extraInfo)
|
||||||
const ClangBackEnd::ExtraInfo &extraInfo)
|
|
||||||
{
|
|
||||||
return signature + extraInfo.typeSpelling.toString() + QLatin1String(" -> ", 4)
|
|
||||||
+ extraInfo.resultTypeSpelling.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString addTypeToVariableName(const QString &name, const ClangBackEnd::ExtraInfo &extraInfo)
|
|
||||||
{
|
{
|
||||||
return name + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString();
|
return name + QLatin1String(" -> ", 4) + extraInfo.typeSpelling.toString();
|
||||||
}
|
}
|
||||||
@@ -116,11 +109,11 @@ QVariant TokenTreeItem::data(int column, int role) const
|
|||||||
|
|
||||||
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|
if (mainType == ClangBackEnd::HighlightingType::VirtualFunction
|
||||||
|| mainType == ClangBackEnd::HighlightingType::Function) {
|
|| mainType == ClangBackEnd::HighlightingType::Function) {
|
||||||
name = addResultTypeToFunctionSignature(name, token.extraInfo);
|
name = addType(name, token.extraInfo);
|
||||||
} else if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|
} else if (mainType == ClangBackEnd::HighlightingType::GlobalVariable
|
||||||
|| mainType == ClangBackEnd::HighlightingType::Field
|
|| mainType == ClangBackEnd::HighlightingType::Field
|
||||||
|| mainType == ClangBackEnd::HighlightingType::QtProperty) {
|
|| mainType == ClangBackEnd::HighlightingType::QtProperty) {
|
||||||
name = addTypeToVariableName(name, token.extraInfo);
|
name = addType(name, token.extraInfo);
|
||||||
if (token.types.mixinHighlightingTypes.contains(
|
if (token.types.mixinHighlightingTypes.contains(
|
||||||
ClangBackEnd::HighlightingType::ObjectiveCProperty)) {
|
ClangBackEnd::HighlightingType::ObjectiveCProperty)) {
|
||||||
name = QLatin1String("@property ") + name;
|
name = QLatin1String("@property ") + name;
|
||||||
|
|||||||
@@ -66,15 +66,9 @@ void FullTokenInfo::updateTypeSpelling(const Cursor &cursor, bool functionLike)
|
|||||||
if (!functionLike)
|
if (!functionLike)
|
||||||
return;
|
return;
|
||||||
Type type = cursor.type().canonical();
|
Type type = cursor.type().canonical();
|
||||||
m_extraInfo.resultTypeSpelling = type.resultType().utf8Spelling();
|
m_extraInfo.token = cursor.displayName();
|
||||||
bool hasSpaceAfterReturnType = false;
|
// On the client side full type is typeSpelling + token.
|
||||||
if (m_extraInfo.resultTypeSpelling.byteSize() < m_extraInfo.typeSpelling.byteSize()) {
|
m_extraInfo.typeSpelling = type.resultType().utf8Spelling();
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utf8String propertyParentSpelling(CXTranslationUnit cxTranslationUnit,
|
static Utf8String propertyParentSpelling(CXTranslationUnit cxTranslationUnit,
|
||||||
|
|||||||
@@ -556,7 +556,6 @@ std::ostream &operator<<(std::ostream &os, const ExtraInfo &extraInfo)
|
|||||||
os << "("
|
os << "("
|
||||||
<< extraInfo.token << ", "
|
<< extraInfo.token << ", "
|
||||||
<< extraInfo.typeSpelling << ", "
|
<< extraInfo.typeSpelling << ", "
|
||||||
<< extraInfo.resultTypeSpelling << ", "
|
|
||||||
<< extraInfo.semanticParentTypeSpelling << ", "
|
<< extraInfo.semanticParentTypeSpelling << ", "
|
||||||
<< static_cast<uint>(extraInfo.accessSpecifier) << ", "
|
<< static_cast<uint>(extraInfo.accessSpecifier) << ", "
|
||||||
<< static_cast<uint>(extraInfo.storageClass) << ", "
|
<< static_cast<uint>(extraInfo.storageClass) << ", "
|
||||||
|
|||||||
Reference in New Issue
Block a user