Commit 20ff553b authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced LookupContext::canonicalSymbol().

parent e9a5ab1b
......@@ -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);
}
......@@ -54,6 +54,9 @@ public:
Document::Ptr document(const QString &fileName) const;
Snapshot snapshot() const;
static Symbol *canonicalSymbol(Symbol *symbol);
static Symbol *canonicalSymbol(const QList<Symbol *> &candidates);
QList<Symbol *> resolve(Name *name) const
{ return resolve(name, visibleScopes()); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment