diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 5723433aca0..ed2afed6edd 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -126,59 +126,48 @@ bool LookupContext::maybeValidSymbol(Symbol *symbol, return false; } +QList LookupContext::resolveNestedNameSpecifier(QualifiedNameId *q, + const QList &visibleScopes) const +{ + QList candidates; + QList scopes = visibleScopes; + + for (unsigned i = 0; i < q->nameCount() - 1; ++i) { + Name *name = q->nameAt(i); + + candidates = resolveClassOrNamespace(name, scopes); + + if (candidates.isEmpty()) + break; + + scopes.clear(); + + foreach (Symbol *candidate, candidates) { + ScopedSymbol *scoped = candidate->asScopedSymbol(); + Scope *members = scoped->members(); + + if (! scopes.contains(members)) + scopes.append(members); + } + } + + return scopes; +} + QList LookupContext::resolveQualifiedNameId(QualifiedNameId *q, const QList &visibleScopes, ResolveMode mode) const { - QList scopes = visibleScopes; - QList candidates; + QList scopes; - for (unsigned i = 0; i < q->nameCount(); ++i) { - Name *name = q->nameAt(i); + if (q->nameCount() == 1) + scopes = visibleScopes; // ### handle global scope lookup + else + scopes = resolveNestedNameSpecifier(q, visibleScopes); - if (i + 1 == q->nameCount()) - candidates = resolve(name, scopes, mode); - else - candidates = resolveClassOrNamespace(name, scopes); + // ### expand the scopes. - if (candidates.isEmpty() || i + 1 == q->nameCount()) - break; - - scopes.clear(); - foreach (Symbol *candidate, candidates) { - if (ScopedSymbol *scoped = candidate->asScopedSymbol()) { - scopes.append(scoped->members()); - } - } - } - - Identifier *id = q->identifier(); - foreach (Scope *scope, visibleScopes) { - Symbol *symbol = scope->lookat(id); - for (; symbol; symbol = symbol->next()) { - if (! symbol->name()) - continue; - else if (! maybeValidSymbol(symbol, mode, candidates)) - continue; - QualifiedNameId *qq = symbol->name()->asQualifiedNameId(); - if (! qq) - continue; - if (q->nameCount() > qq->nameCount()) - continue; - - for (int i = q->nameCount() - 1; i != -1; --i) { - Name *a = q->nameAt(i); - Name *b = qq->nameAt(i); - - if (! a->isEqualTo(b)) - break; - else if (i == 0) - candidates.append(symbol); - } - } - } - - return candidates; + return resolve(q->unqualifiedNameId(), scopes, mode); } QList LookupContext::resolveOperatorNameId(OperatorNameId *opId, diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 4985e11f741..fcfac578262 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -123,6 +123,9 @@ private: const QList &visibleScopes, ResolveMode mode) const; + QList resolveNestedNameSpecifier(QualifiedNameId *q, + const QList &visibleScopes) const; + Identifier *identifier(const Name *name) const; QList buildVisibleScopes();