CppEditor: Store typedefed name for anonymous structs

... and use it as the struct display name in some places.

Fixes: QTCREATORBUG-26611
Change-Id: I1b127f5705307a0fabd2441ff871162c882927a5
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2022-09-14 16:16:09 +02:00
parent 2369dcc324
commit 0fab5956ea
5 changed files with 18 additions and 2 deletions

View File

@@ -2022,6 +2022,10 @@ bool Bind::visit(SimpleDeclarationAST *ast)
for (const auto &nameAndLoc : qAsConst(namesAndLocations)) { for (const auto &nameAndLoc : qAsConst(namesAndLocations)) {
const int sourceLocation = nameAndLoc.second; const int sourceLocation = nameAndLoc.second;
Declaration *decl = control()->newDeclaration(sourceLocation, nameAndLoc.first); Declaration *decl = control()->newDeclaration(sourceLocation, nameAndLoc.first);
if (const Type * const t = declTy.type(); t && declTy.isTypedef() && t->asClassType()
&& t->asClassType()->name() && t->asClassType()->name()->asAnonymousNameId()) {
declTy.type()->asClassType()->setCanonicalTypedefName(decl->name());
}
decl->setType(declTy); decl->setType(declTy);
setDeclSpecifiers(decl, type); setDeclSpecifiers(decl, type);

View File

@@ -635,6 +635,11 @@ void Class::addBaseClass(BaseClass *baseClass)
FullySpecifiedType Class::type() const FullySpecifiedType Class::type() const
{ return FullySpecifiedType(const_cast<Class *>(this)); } { return FullySpecifiedType(const_cast<Class *>(this)); }
const Name *Class::prettyName() const
{
return _canonicalTypedefName ? _canonicalTypedefName : name();
}
void Class::visitSymbol0(SymbolVisitor *visitor) void Class::visitSymbol0(SymbolVisitor *visitor)
{ {
if (visitor->visit(this)) { if (visitor->visit(this)) {

View File

@@ -495,6 +495,9 @@ public:
const Class *asClassType() const override { return this; } const Class *asClassType() const override { return this; }
Class *asClassType() override { return this; } Class *asClassType() override { return this; }
void setCanonicalTypedefName(const Name *n) { _canonicalTypedefName = n; }
const Name *prettyName() const;
protected: protected:
void visitSymbol0(SymbolVisitor *visitor) override; void visitSymbol0(SymbolVisitor *visitor) override;
void accept0(TypeVisitor *visitor) override; void accept0(TypeVisitor *visitor) override;
@@ -503,6 +506,7 @@ protected:
private: private:
Key _key; Key _key;
std::vector<BaseClass *> _baseClasses; std::vector<BaseClass *> _baseClasses;
const Name *_canonicalTypedefName = nullptr;
}; };
class CPLUSPLUS_EXPORT QtPropertyDeclaration final : public Symbol class CPLUSPLUS_EXPORT QtPropertyDeclaration final : public Symbol

View File

@@ -53,7 +53,10 @@ static void path_helper(Symbol *symbol,
if (ns && ns->isInline()) if (ns && ns->isInline())
return; return;
} }
addNames(symbol->name(), names); if (symbol->asClass())
addNames(symbol->asClass()->prettyName(), names);
else
addNames(symbol->name(), names);
} else if (symbol->asObjCClass() || symbol->asObjCBaseClass() || symbol->asObjCProtocol() } else if (symbol->asObjCClass() || symbol->asObjCBaseClass() || symbol->asObjCProtocol()
|| symbol->asObjCForwardClassDeclaration() || symbol->asObjCForwardProtocolDeclaration() || symbol->asObjCForwardClassDeclaration() || symbol->asObjCForwardProtocolDeclaration()

View File

@@ -166,7 +166,7 @@ void TypePrettyPrinter::visit(Template *type)
void TypePrettyPrinter::visit(Class *classTy) void TypePrettyPrinter::visit(Class *classTy)
{ {
_text.prepend(overview()->prettyName(classTy->name())); _text.prepend(overview()->prettyName(classTy->prettyName()));
prependCv(_fullySpecifiedType); prependCv(_fullySpecifiedType);
} }