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)) {
const int sourceLocation = nameAndLoc.second;
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);
setDeclSpecifiers(decl, type);

View File

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

View File

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

View File

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

View File

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