Introduced LookupContext::canonicalSymbol().

This commit is contained in:
Roberto Raggi
2009-09-25 14:00:58 +02:00
parent e9a5ab1b0d
commit 20ff553b59
2 changed files with 41 additions and 0 deletions

View File

@@ -495,3 +495,41 @@ void LookupContext::expand(Scope *scope,
expandObjCMethod(meth, visibleScopes, expandedScopes);
}
}
Symbol *LookupContext::canonicalSymbol(Symbol *symbol)
{
Symbol *canonical = symbol;
for (; symbol; symbol = symbol->next()) {
if (symbol->name() == canonical->name())
canonical = symbol;
}
return canonical;
}
Symbol *LookupContext::canonicalSymbol(const QList<Symbol *> &candidates)
{
if (candidates.isEmpty())
return 0;
Symbol *candidate = candidates.first();
if (candidate->scope()->isClassScope() && candidate->type()->isFunctionType()) {
Function *function = 0;
for (int i = 0; i < candidates.size(); ++i) {
Symbol *c = candidates.at(i);
if (! c->scope()->isClassScope())
continue; // ### or break?
else if (Function *f = c->type()->asFunctionType()) {
if (f->isVirtual())
function = f;
}
}
if (function)
return canonicalSymbol(function);
}
return canonicalSymbol(candidate);
}