diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 6c10f88c571..f79ebfd701e 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -126,6 +126,61 @@ bool LookupContext::maybeValidSymbol(Symbol *symbol, return false; } +QList LookupContext::resolveQualifiedNameId(QualifiedNameId *q, + const QList &visibleScopes, + ResolveMode mode) const +{ + QList scopes = visibleScopes; + QList candidates; + + for (unsigned i = 0; i < q->nameCount(); ++i) { + Name *name = q->nameAt(i); + + if (i + 1 == q->nameCount()) + candidates = resolve(name, scopes, mode); + else + candidates = resolveClassOrNamespace(name, 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; +} + QList LookupContext::resolve(Name *name, const QList &visibleScopes, ResolveMode mode) const { @@ -134,55 +189,8 @@ QList LookupContext::resolve(Name *name, const QList &visible if (!name) return candidates; - if (QualifiedNameId *q = name->asQualifiedNameId()) { - QList scopes = visibleScopes; - for (unsigned i = 0; i < q->nameCount(); ++i) { - Name *name = q->nameAt(i); - - if (i + 1 == q->nameCount()) - candidates = resolve(name, scopes, mode); - else - candidates = resolveClassOrNamespace(name, 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 = identifier(name); - 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; - } + if (QualifiedNameId *q = name->asQualifiedNameId()) + return resolveQualifiedNameId(q, visibleScopes, mode); if (Identifier *id = identifier(name)) { for (int scopeIndex = 0; scopeIndex < visibleScopes.size(); ++scopeIndex) { diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 9ba268fe1af..d9be051a77f 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -115,6 +115,10 @@ public: QList *expandedScopes) const; private: + QList resolveQualifiedNameId(QualifiedNameId *q, + const QList &visibleScopes, + ResolveMode mode) const; + Identifier *identifier(const Name *name) const; QList buildVisibleScopes();