From f98b937b8c26380dcf3155d973932f7ac2fe522a Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Thu, 4 Jun 2009 16:15:27 +0200 Subject: [PATCH] Expand enum and anonymous scoped symbols when resolving qualified name ids. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Thorbjørn Lindeijer --- src/libs/cplusplus/LookupContext.cpp | 39 ++++++++++++++++++++++++++-- src/libs/cplusplus/LookupContext.h | 3 +++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index d686e14fd91..a00b45263b4 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -136,9 +136,19 @@ QList<Symbol *> LookupContext::resolveQualifiedNameId(QualifiedNameId *q, else scopes = resolveNestedNameSpecifier(q, visibleScopes); - // ### expand the scopes. + QList<Scope *> expanded; + foreach (Scope *scope, scopes) { + expanded.append(scope); + + for (unsigned i = 0; i < scope->symbolCount(); ++i) { + Symbol *member = scope->symbolAt(i); + + if (ScopedSymbol *scopedSymbol = member->asScopedSymbol()) + expandEnumOrAnonymousSymbol(scopedSymbol, &expanded); + } + } - return resolve(q->unqualifiedNameId(), scopes, mode); + return resolve(q->unqualifiedNameId(), expanded, mode); } QList<Symbol *> LookupContext::resolveOperatorNameId(OperatorNameId *opId, @@ -301,6 +311,31 @@ QList<Scope *> LookupContext::visibleScopes(const QPair<FullySpecifiedType, Symb return scopes; } +void LookupContext::expandEnumOrAnonymousSymbol(ScopedSymbol *scopedSymbol, + QList<Scope *> *expandedScopes) const +{ + if (! scopedSymbol || expandedScopes->contains(scopedSymbol->members())) + return; + + Scope *members = scopedSymbol->members(); + + if (scopedSymbol->isEnum()) + expandedScopes->append(members); + else if (! scopedSymbol->name() && (scopedSymbol->isClass() || scopedSymbol->isNamespace())) { + // anonymous class or namespace + + expandedScopes->append(members); + + for (unsigned i = 0; i < members->symbolCount(); ++i) { + Symbol *member = members->symbolAt(i); + + if (ScopedSymbol *nested = member->asScopedSymbol()) { + expandEnumOrAnonymousSymbol(nested, expandedScopes); + } + } + } +} + QList<Scope *> LookupContext::expand(const QList<Scope *> &scopes) const { QList<Scope *> expanded; diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 0fb7371e5eb..568725da56d 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -114,6 +114,9 @@ public: const QList<Scope *> &visibleScopes, QList<Scope *> *expandedScopes) const; + void expandEnumOrAnonymousSymbol(ScopedSymbol *scopedSymbol, + QList<Scope *> *expandedScopes) const; + private: QList<Symbol *> resolveQualifiedNameId(QualifiedNameId *q, const QList<Scope *> &visibleScopes, -- GitLab