diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index ed2afed6eddbbf000cd6e41e3597d4abe6de479f..d686e14fd91ec0ffba82bc0b451dffd25a348ec2 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -42,35 +42,6 @@ using namespace CPlusPlus; -bool LookupContext::isNameCompatibleWithIdentifier(Name *name, Identifier *id) -{ - if (! name) { - return false; - } else if (NameId *nameId = name->asNameId()) { - Identifier *identifier = nameId->identifier(); - return identifier->isEqualTo(id); - } else if (DestructorNameId *nameId = name->asDestructorNameId()) { - Identifier *identifier = nameId->identifier(); - return identifier->isEqualTo(id); - } else if (TemplateNameId *templNameId = name->asTemplateNameId()) { - Identifier *identifier = templNameId->identifier(); - return identifier->isEqualTo(id); - } - - return false; -} - -#ifndef CPLUSPLUS_WITH_NO_DEBUG -static void printScopes(const QList<Scope *> &scopes) -{ - qDebug() << "==========="; - foreach (Scope *scope, scopes) { - qDebug() << "scope:" << scope << scope->owner()->name() << scope->owner()->fileName() - << scope->owner()->line() << scope->owner()->column(); - } -} -#endif - ///////////////////////////////////////////////////////////////////// // LookupContext ///////////////////////////////////////////////////////////////////// @@ -205,20 +176,30 @@ QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visible else if (OperatorNameId *opId = name->asOperatorNameId()) return resolveOperatorNameId(opId, visibleScopes, mode); - else if (Identifier *id = identifier(name)) { + else if (Identifier *id = name->identifier()) { for (int scopeIndex = 0; scopeIndex < visibleScopes.size(); ++scopeIndex) { Scope *scope = visibleScopes.at(scopeIndex); for (Symbol *symbol = scope->lookat(id); symbol; symbol = symbol->next()) { - if (! symbol->name()) { - continue; - } else if (! maybeValidSymbol(symbol, mode, candidates)) { - continue; - } else if (QualifiedNameId *q = symbol->name()->asQualifiedNameId()) { - if (! q->unqualifiedNameId()->isEqualTo(name)) + if (! symbol->name()) + continue; // nothing to do, the symbol is anonymous. + + else if (! maybeValidSymbol(symbol, mode, candidates)) + continue; // skip it, we're not looking for this kind of symbols + + + else if (Identifier *symbolId = symbol->identifier()) { + if (! symbolId->isEqualTo(id)) + continue; // skip it, the symbol's id is not compatible with this lookup. + } + + + if (QualifiedNameId *q = symbol->name()->asQualifiedNameId()) { + + if (name->isDestructorNameId() != q->unqualifiedNameId()->isDestructorNameId()) continue; - if (q->nameCount() > 1) { + else if (q->nameCount() > 1) { Name *classOrNamespaceName = control()->qualifiedNameId(q->names(), q->nameCount() - 1); @@ -242,13 +223,13 @@ QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visible if (! good) continue; } - } else if (! isNameCompatibleWithIdentifier(symbol->name(), id)) { - continue; } else if (symbol->name()->isDestructorNameId() != name->isDestructorNameId()) { + // ### FIXME: this is wrong! continue; } - candidates.append(symbol); + if (! candidates.contains(symbol)) + candidates.append(symbol); } } } diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index fcfac57826246ce65d09bd9370a15e34e953dc3b..0fb7371e5eb7bb27e80638b146d594d64f934872 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -133,8 +133,6 @@ private: void buildVisibleScopes_helper(Document::Ptr doc, QList<Scope *> *scopes, QSet<QString> *processed); - static bool isNameCompatibleWithIdentifier(Name *name, Identifier *id); - static bool maybeValidSymbol(Symbol *symbol, ResolveMode mode, const QList<Symbol *> &candidates);